perf(gui): implement batched UI rendering#2514
perf(gui): implement batched UI rendering#2514githubawn wants to merge 21 commits intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp | Wraps drawablePostDraw iteration in beginBatch/endBatch for the 3D-world post-draw pass |
| Generals/Code/GameEngine/Include/GameClient/Display.h | Adds beginBatch/endBatch/flush public API and onBeginBatch/onEndBatch/onFlush protected hooks with m_isBatching field |
| Generals/Code/GameEngine/Source/GameClient/Display.cpp | Implements base batch control with re-entrancy guards; m_isBatching initialized to FALSE |
| Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h | Declares setup2DRenderState, overrides batch hooks, adds m_batchTexture/m_batchMode/m_batchGrayscale/m_batchNeedsInit fields |
| Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp | Core batching engine: setup2DRenderState centralises state transitions with correct ref counting; clipping early-exit bug fix included |
| Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp | Adds TheDisplay->flush() before text render to commit pending batched 2D geometry in correct draw order |
| Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp | Wraps entire UI draw pass in beginBatch/endBatch to batch all HUD draw calls together |
| GeneralsMD/Code/GameEngine/Include/GameClient/Display.h | Zero Hour mirror of Generals Display.h batch API additions |
| GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp | Zero Hour mirror of Generals Display.cpp batch implementation |
| GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h | Zero Hour mirror: same setup2DRenderState declaration and batch member fields |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp | Zero Hour mirror of Generals implementation with identical batching logic and ref counting |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp | Zero Hour mirror: flush before text renderer |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp | Zero Hour mirror: wraps UI draw pass in beginBatch/endBatch |
Sequence Diagram
sequenceDiagram
participant G as Game Loop
participant D as Display
participant S as setup2DRenderState
participant R2D as Render2DClass
G->>D: beginBatch()
D->>D: m_isBatching=TRUE
D->>R2D: Reset(), m_batchNeedsInit=TRUE
G->>S: drawImage(texA, ALPHA)
S->>S: onFlush() — no-op (batchNeedsInit=TRUE)
S->>R2D: Add_Ref(texA), Set_Texture(texA), Enable_Alpha(TRUE)
S->>R2D: Add_Quad(...)
G->>S: drawImage(texA, ALPHA) [same state]
S->>S: fast-path return — state unchanged
S->>R2D: Add_Quad(...)
G->>S: drawImage(texB, ALPHA) [texture change]
S->>R2D: Render() — flush texA batch
S->>R2D: Reset(), m_batchNeedsInit=TRUE
S->>S: Release_Ref(texA), Add_Ref(texB)
S->>R2D: Set_Texture(texB)
S->>R2D: Add_Quad(...)
G->>D: TheDisplay->flush() [before text render]
D->>R2D: Render() — flush texB batch
D->>R2D: Reset()
G->>D: endBatch()
D->>D: onFlush() — no-op (batchNeedsInit=TRUE after last flush)
D->>D: Release_Ref(texB), m_isBatching=FALSE
Reviews (17): Last reviewed commit: "fix generals replication" | Re-trigger Greptile
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Outdated
Show resolved
Hide resolved
split single line IF
|
Significantly improves #109 |
optimize clipping check
remove obsolete else
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Outdated
Show resolved
Hide resolved
return statement on seperate line
centralized flush
|
"One P1 render-state initialization bug in onBeginBatch() should be fixed before merging to avoid potential cross-frame visual corruption." The P1 finding could be a false positive based on a local variable analysis that omits the downstream hardware synchronization in Render2DClass::Render() (render2d.cpp:601). Render2DClass is a self-synchronizing state machine. Its Render() call (line 628 for textures, line 694 for shaders) explicitly pushes its internal members to the DX8Wrapper on every execution. The tracking variables in W3DDisplay (m_batchTexture, etc.) are mirror-images of Render2DClass's internal members. happy? |
|
No, the P1 finding stands. Your argument about Render2DClass being self-synchronizing addresses hardware state consistency, but not the C++ undefined behavior in W3DDisplay. The issue:
Even if Render2DClass correctly synchronizes hardware state on every
An uninitialized bool means these decisions are based on garbage. The fact that the hardware might recover downstream doesn't make reading uninitialized memory defined behavior. The fix is one line. Keep it. |
endBatch() is re-entrant-safe Clipping fast-path in drawImage remove Redundant m_isBatching = FALSE
…sGameCode into perf/gui-batch
|
I see greptile woke up on the sassy side of the motherboard. |
Another test would be to get a lot of units on screen then select them all so their unit info is being drawn. The health bars make use of the line drawing classes which i believe are inherently affected by this change. |
|
Compile errors need to be fixed before this can be reviewed |
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Outdated
Show resolved
Hide resolved
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Show resolved
Hide resolved
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Outdated
Show resolved
Hide resolved
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Outdated
Show resolved
Hide resolved
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Outdated
Show resolved
Hide resolved
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp
Outdated
Show resolved
Hide resolved
33ccf35 to
5dd0e6e
Compare
5dd0e6e to
667d24d
Compare


Reduces draw calls by batching 2D elements by texture state in setup2DRenderState.