Executes queued commands immediately (forces GPU completion, synchronous wait, use for RT capture).
Takes no parameters.
Returns nothing.
2D Overlay
Parameters & Returns
Parameters
This function takes no parameters.
Returns
Void
Quick Summary
Executes queued commands immediately (forces GPU completion, synchronous wait, use for RT capture).
Takes no parameters.
Returns nothing.
Technical Exegesis...
Executes queued commands immediately (forces GPU completion, synchronous wait, use for RT capture). Takes no parameters. Returns nothing.
Executes queued commands immediately (forces GPU completion, synchronous wait, use for RT capture). Takes no parameters. Returns nothing. Processes g_overlayCommands buffer (all queued b2dDrawImage, b2dSetRenderTarget, etc commands executed immediately), allocates command list (gets D3D12 command context from g_commandListManager), handles RT transitions (automatic RENDER_TARGET <-> PIXEL_SHADER_RESOURCE barriers for render targets), executes and waits (WaitForFence blocks until GPU completes all commands), clears command buffer (g_overlayCommands.clear() after execution). Use to force immediate execution (normally commands deferred until b3dRenderWorld), complete RT rendering (ensure RT finished before b2dGrabImage or using RT as texture), synchronize GPU (ensure operations complete before continuing), or debug rendering (isolate command execution for testing). Synchronous execution: blocks CPU (waits for GPU to finish all commands before returning), GPU sync (WaitForFence ensures command completion), immediate (all queued commands executed now, not deferred to b3dRenderWorld). Use cases: (1) RT capture workflow (b2dSetRenderTarget(rt): draw to RT: b2dFlush(): img=b2dGrabImage(0,0,0,0) ensure RT finished before capture), (2) RT as texture (b2dSetRenderTarget(rt): draw content: b2dFlush(): b2dDrawImage(rt,x,y) ensure RT ready to use as texture), (3) Multiple RT passes (b2dSetRenderTarget(rt1): draw: b2dFlush(): b2dSetRenderTarget(rt2): draw: b2dFlush() ensure each pass completes), (4) Debug rendering (draw commands: b2dFlush() see immediate results without full frame), (5) Measure timing (start=timer: draw: b2dFlush(): elapsed=timer-start measure GPU time). Common patterns: RT workflow = b2dSetRenderTarget(rt): draw: b2dFlush(): use RT ensure complete; debug = draw: b2dFlush() immediate execution. Command processing: executes all commands (processes entire g_overlayCommands buffer in order), RT transitions manual (manually inserts resource barriers for render targets RENDER_TARGET -> PIXEL_SHADER_RESOURCE), removes default RT commands (CMD_SET_DEFAULT_RENDER_TARGET filtered out during standalone execution, would bind invalid RT), preserves RT state (g_2D_currentRenderTarget preserved after flush, RT stays active for b2dGrabImage). RT state handling: active RT transitioned (if RT active, transitioned to PIXEL_SHADER_RESOURCE for use as texture), RT stays active (g_2D_currentRenderTarget not reset, RT remains active until b2dSetDefaultRenderTarget), hasBeenUsedAsTexture flag (set on RT after transition, tracks resource state). GPU synchronization: WaitForFence (blocks CPU until GPU fence value reached, ensures commands complete), command list execution (ExecuteCommandList submits to GPU, returns fence value), safe for capture (b2dGrabImage safe after flush, pixels guaranteed available). Performance: execution cost varies (depends on queued command count and complexity, ~0.1-10ms typical), GPU sync cost high (WaitForFence blocks CPU until GPU completes, creates CPU-GPU bubble), overhead significant (use sparingly, not every frame, only when necessary for RT capture or sync), breaks pipelining (forces CPU-GPU sync, prevents parallelism, impacts frame time). When to use: RT capture required (b2dGrabImage needs flush first), RT as texture (ensure RT complete before drawing as texture), multiple RT passes (synchronize between render target operations), debugging (isolate command execution), NOT for normal rendering (b3dRenderWorld handles command execution efficiently without sync). Alternative workflow: without flush (queue commands, b3dRenderWorld executes automatically during frame, no CPU-GPU sync, better performance), with flush (explicit sync for RT capture or debugging, necessary for b2dGrabImage, CPU waits for GPU). Validation: returns early if not initialized (g_initialized or g_commandListManager null, silently skips), returns early if empty (g_overlayCommands empty, no commands to execute, fast path), no error on invalid commands (processes commands, invalid commands handled individually). Related: b2dSetRenderTarget queues RT switch (command executed by this function), b2dSetDefaultRenderTarget resets RT (state update, not executed by this function), b2dGrabImage captures from RT (requires flush first to ensure RT complete), b2dDrawImage queues draw (command executed by this function), b3dRenderWorld automatic execution (executes commands without sync, preferred for normal rendering).