Skip to content

perf(GL4): batch ghost-building rendering#3110

Open
bruno-dasilva wants to merge 3 commits into
bruno/refactor-extract-emplace-instancefrom
bruno/batch-ghost-buildings-2
Open

perf(GL4): batch ghost-building rendering#3110
bruno-dasilva wants to merge 3 commits into
bruno/refactor-extract-emplace-instancefrom
bruno/batch-ghost-buildings-2

Conversation

@bruno-dasilva

@bruno-dasilva bruno-dasilva commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Context

POC here: #3001
When looking at large numbers of ghost buildings, performance massively drops waiting on the GPU.

eg. I spawn 600 winds, those 600 ghosts take me from 500 fps -> 120 fps. In other cases we saw dropping from ~100+fps -> 20fps in a real game/replay.

Work done

Ghost buildings are drawn batched through a new draw mode ARRAY_MATMODE. One multidraw per (color bucket x texture type) instead of one immediate draw per ghost.

Screenshots

Performance:
Before:
image
After:
image

building ghosts:
Before:
screen_2026-07-15_05-10-34-222

After:
screen_2026-07-15_05-11-50-567

radar'd + live ghost buildings:
Before:
After:
screen_2026-07-15_05-03-56-567

dead ghost buildings:
Before:
After:
screen_2026-07-15_05-05-16-943

AI Disclosure

Claude code. Claude did most of the code writing but I iterated a lot to get somewhere that's easy to review and easy to maintain.

@bruno-dasilva

Copy link
Copy Markdown
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@bruno-dasilva bruno-dasilva changed the title refactor(GL4): replace matrix modes magic number with an enum perf(GL4): batch ghost-building rendering Jul 14, 2026
@bruno-dasilva
bruno-dasilva marked this pull request as ready for review July 15, 2026 05:12
Comment on lines +1844 to +1852
if (anyNormal) {
modelDrawerState->SetColorMultiplier(0.6f, 0.6f, 0.6f, IModelDrawerState::alphaValues.y);
modelDrawerState->SetTeamColor(0, IModelDrawerState::alphaValues.y);
flushGhosts(byTexNormal);
}
if (anyContradar) {
modelDrawerState->SetColorMultiplier(0.9f, 0.9f, 0.9f, IModelDrawerState::alphaValues.z);
modelDrawerState->SetTeamColor(0, IModelDrawerState::alphaValues.z);
flushGhosts(byTexContradar);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I honestly CANNOT tell the difference between these two greys in the screenshots...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didnt even realize these looked different (or should have looked different)

Add SetFlag("MATMODE_XXX", ...) alongside the existing GBUFFER_*_IDX flags so
the GL4 model shaders can reference the matrix-mode enum value by name instead
of hardcoding a literal.

Intended as a precursor for the ghost draw perf fixes, which add a third mode in the shader.
Ghost buildings are static (no animation, never move), so each gets a single
world-transform slot in the transforms SSBO, and is drawn batched through
ARRAY_MATMODE. One multidraw per (color bucket x texture type) instead of one
immediate draw per ghost.
@bruno-dasilva
bruno-dasilva force-pushed the bruno/refactor-extract-emplace-instance branch from 6783f8b to b1c4e01 Compare July 15, 2026 05:25
@bruno-dasilva
bruno-dasilva force-pushed the bruno/batch-ghost-buildings-2 branch from 55c66e8 to 05bce7c Compare July 15, 2026 05:25
@sprunk sprunk added area: Graphics/Rendering Graphics pipeline, shaders, water rendering, reflections, OpenGL code, etc. area: perf Performance improvements. labels Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Graphics/Rendering Graphics pipeline, shaders, water rendering, reflections, OpenGL code, etc. area: perf Performance improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants