Skip to content

Borrow one int array for all alpha model sorted faces - #1171

Closed
RuffledPlume wants to merge 37 commits into
117HD:masterfrom
RuffledPlume:StaticAlphaModelTempFaceOptimization
Closed

RuffledPlume wants to merge 37 commits into
117HD:masterfrom
RuffledPlume:StaticAlphaModelTempFaceOptimization

Conversation

@RuffledPlume

@RuffledPlume RuffledPlume commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Instead of borrowing an Int array for each AlphaModel which needs sorting, we calculate the total sorted faces then borrow a Int array for the whole zone.

Each AlphaModel now has a offset into the Zone Array

EboAlphaWriterJob finds continuous ranges before flushing the indicies to the eboBuffer

Before:
image

After (3x improvement):
image

Before:
image

After (1.6x improvement):
image

Instead of borrowing an Int array for each AlphaModel which needs sorting, we calculate the total sorted faces then borrow a Int array for the whole zone.

Each AlphaModel now has a offset into the Zone Array

EboAlphaWriterJob finds continuous ranges before flushing the indicies to the eboBuffer
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch from f168c99 to e6d70ca Compare August 14, 2026 13:04
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch from f0c5e90 to 345b23c Compare August 14, 2026 22:57
@RuffledPlume
RuffledPlume marked this pull request as draft August 17, 2026 09:42
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch from 524da49 to 713ccc2 Compare August 17, 2026 12:09
@RuffledPlume
RuffledPlume marked this pull request as ready for review August 17, 2026 12:09
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch from 713ccc2 to b6a7304 Compare August 17, 2026 12:34
Added EboAlpha Upload Timer

Tweaks

Fix MultiLocs

Calculate AlphaModel Distance once

QuickSort Accessor Implementation

Added Keyed List QuickSort

Combine Accessors into a single class

JIT was struggling to optimise the internal Quick Sort function resulting in VTable invocations which was hampering the sorting perf

Tweaks
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch from b6a7304 to 2a69243 Compare August 17, 2026 12:37
If there is only two AlphaModels we can avoid the Key QuickSort by just comparing the distances

@aHooder aHooder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helps a lot with performance north or Prifddinas 🙂

I still need to review this more thoroughly, but at first glance I just have one question.

@Mark7625
Mark7625 force-pushed the StaticAlphaModelTempFaceOptimization branch from f7f5c14 to 5bdc09e Compare October 11, 2026 21:13
@Mark7625
Mark7625 force-pushed the StaticAlphaModelTempFaceOptimization branch from 5eda2bd to de69b72 Compare October 11, 2026 21:28
 * Combine `drawOff` & `drawEnd` into a single array
 * Remove the `copyTo` instead write the offset & length directly
 * calculate the vertSizeInts once outside of the loop
Alpha Shadows are drawn on first call to `drawZoneAlpha` instead of per level, improve shadow GPU performance & reducing draw calls

Also fixed bug where `bufLen` & `bufLenA` was incorrect
@RuffledPlume

Copy link
Copy Markdown
Contributor Author

Last two changes help gain an extra 10 FPS for me at Mor Ul Rek
Master VS PR VS PR + Minor Changes
image

Checks if the Bounds of all AlphaModels combined straddle the Frustum, meaning that there is a chance a AlphaModel might not be visible before checking per alpha model visibility
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch from 2a22611 to ba90764 Compare October 12, 2026 05:31
Also Always trigger sorting job, visibility will be determined within the job which avoid stale visibility due to the setup using the previous frames visibility
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch 3 times, most recently from e1da095 to b745c0d Compare October 12, 2026 08:22
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch from b745c0d to d503db0 Compare October 12, 2026 08:22
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch from 7b1cc7d to 262b429 Compare October 12, 2026 12:55
This version implements a Per-type accessor interface over the shared Kind version which allows for better JIT Optimisation
@RuffledPlume
RuffledPlume force-pushed the StaticAlphaModelTempFaceOptimization branch from fa9192c to 9619062 Compare October 13, 2026 11:05
@RuffledPlume

Copy link
Copy Markdown
Contributor Author

Closing in Favor of #1179 since it would make all of these optimizations redundant and offloads the Alpha cost fully onto the GPU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants