Repository navigation
GPU: overlap CPU preparation with GPU execution via per-submission fences - #3219
Closed
danielibabet wants to merge 2 commits into
Closed
danielibabet wants to merge 2 commits into
danielibabet wants to merge 2 commits into
Conversation
Move texture::recycle() from bindless::uploads() (start of execute) into Host::copy_back() immediately after wait_for(): staging chunk memory and upload buffers from submission N are recycled as soon as the GPU fence for N fires, while the submission lock is held. This guarantees two things: 1. Post-fence texture invalidation: refresh_all() / hash comparison for submission N+1 always runs after copy_back(N) has completed and after the GPU's writes are fully committed to title memory. The staging pool is in a known-clean state before each new execute() builds its upload list, so the hash sees the final post-GPU state of title memory. 2. Back-pressure (depth-1 in-flight): within a pump pass, run() calls copy_back(previous) -- which now includes recycle() -- before every execute(next). Staging is never recycled while the GPU is still reading it. Between passes the between-pass flush waits for the last in-flight submission before a new pass begins. The queue depth is capped at 1 at all points. cargo test --workspace: 233 passed, 2 pre-existing failures unchanged cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: ok cargo run -p xtask -- policy: 192 files ok cargo build --release -p victory --locked: ok
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Overlap CPU preparation with GPU execution by splitting
Host::executeinto a non-blocking submit and a deferredcopy_back. This addresses theshortcutnoted inhost.rs: "every submission is waited for, so CPU and GPU never overlap".Problem
Host::executecalledExecuteCommandLists, then immediately signalled the fence and blocked withWaitForSingleObject(INFINITE)before returning. At ~1.5 fps with ~500 ms of GPU work per frame, the CPU spent essentially the entire frame idle waiting for the GPU.Solution
Two-phase submit:
Host::execute— submits the command lists, signals the fence, returns immediately with aSubmissionDatatoken (fence value + batch data). CPU continues preparing the next submission.Host::copy_back— waits for the fence, then performs all shadow/BOP writes back to title memory. Called at the start of the next submission, so the GPU runs frame N while the CPU prepares frame N+1.A new
COPY_BACK_WAIT_USatomic exposes the residual fence wait time as awaiting GPUfield in the fps log line.The texture
recycle()call was moved frombindless::uploads()(before execute) intocopy_back()(after fence wait), so staging chunk memory is released strictly post-GPU and hash comparison always sees the final post-GPU state of title memory — preventing spurious full-texture invalidations.Measured results (i9-14900KF + RTX 4070, GTA VI world)
The
waiting GPUfield replaceson the GPUas the measure of GPU execution time. The overlap benefit is currently limited by the GPU execution time (~450 ms) dominating CPU preparation (~90 ms); the CPU finishes preparing before the GPU finishes executing, so the overlap window is not fully exploited. Further gains require reducing GPU execution time (more pipelines compiled, indirect dispatch fixes).Tests
cargo test --workspace: 233 passed, 2 pre-existing failures onmainunrelated to this changecargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warningscargo run -p xtask -- policy: 192 files OKcargo build --release -p victory --locked: clean