GPU: create texture staging outside the global table lock #1157

Open
github-bot wants to merge 2 commits from github-bot/gh-1157 into main AGit
Owner

@⁠fladit123 on GitHub · 2026-11-25 22:02 UTC · original
fladit123:fix/texture-staging-reservations → main · +486 −33 · 2 files · 2 commits · draft

Motivation

The conventional texture staging path holds the global staging table lock through footprint preparation, pool checkout, buffer clearing, and D3D12 upload-buffer creation. Cached lookups for unrelated textures can therefore wait behind expensive creation work.

This change narrows the scope of the global lock without allowing duplicate creation for the same resource identity.

Implementation

  • Reserve staging misses by resource identity.
  • Create staging outside the global table lock.
  • Share the result of each reservation through a OnceLock.
  • Release failed or unwinding reservations and wake waiters.
  • Preserve pending reservations during idle eviction.
  • Match completed generations during removal, preventing an older remover from deleting a newer staging entry.
  • Preserve existing command-list ownership of staging buffers.

Three permanent, deadline-bounded concurrency tests cover independent progress and single creation, failure and panic recovery, and concurrent removal across generations.

Test hooks are compiled only in test builds.

Synthetic performance measurements

The following measurements were obtained on the original pinned base (d510ee4) and original runtime candidate (ca56ec0), before rebasing. They have not been repeated on the current base.

Synchronized mixed workload

RTX 4060, two threads:

Metric Main Candidate
Independent-hit p95 688.55 µs 0.70 µs
Uncontended-hit p95 0.20 µs 0.20 µs

Fixed producer with free-running readers

Eight threads:

Adapter Main independent-hit p99 Candidate independent-hit p99
RTX 4060 1,365.25 µs 16.45 µs
WARP 808.60 µs 16.50 µs

These latency reductions come with trade-offs. At eight threads, independent-hit p95 increased on both adapters, and producer throughput decreased by 10.90% on RTX 4060 and 15.12% on WARP.

Repeated paired throughput measurements

Twelve independent pairs per configuration, alternating execution order:

Workload Median paired throughput change
WARP, single-thread churn -1.99%
RTX 4060, two-thread same identity -4.88%
WARP, two-thread same identity -5.50%

Churn showed substantial run-to-run variability, with buffer clearing dominating the instrumented time.

These results suggest that the main benefit is reducing interference between independent resources, rather than universally improving staging throughput.

No real-game FPS or frame-time improvement is claimed.

Validation on the current base

Base: 9c184b35b43de3455b74ac1770e1c8734a047810

Candidate: 7f1685dd6a77b65983d6bebefb5ab7603dcc2592

The two original patches were cherry-picked onto the current base. git range-diff confirmed patch equivalence.

Environment:

  • Windows 11 Pro 26H2.
  • Intel Core i5-12400F.
  • 32 GB RAM.
  • NVIDIA GeForce RTX 4060, 8 GB.
  • NVIDIA driver 610.88.
  • WARP.
  • Rust 1.98.1 MSVC.

Build:

cargo test --offline --locked -p victory-gpu --lib --release --features diagnostics --no-run -j 2

Results:

Validation RTX 4060 WARP
Three permanent concurrency tests, parallel harness 3/3 passed 3/3 passed
Complete selected texture group, sequential harness 5/5 passed 5/5 passed

Total: 16 successful test executions, including repeated execution of the three permanent tests. Zero failures, zero timeouts, and no reported hardware skips in these runs.

The injected creator panic is intentional and is handled by the recovery test.

Test executable SHA256:

48BBAE0E86F29F830EEAE5E0A0D9BABE838B7C0FDF92677D3D98D55545F491B5

Additional checks:

  • git diff --check: passed.
  • Asset policy: 186 files ok, exit code 0, in the available sparse checkout.
  • Clean working tree.

The test executable was compiled from a disposable source-only copy with the BCPack module declaration omitted. This exclusion is not part of the PR. A full unmodified workspace build has not been validated.

Previous validation

On the original runtime candidate, a graphical confirmation test read back 174,080 exact bytes per adapter with zero D3D12 debug-layer errors.

The existing WARP indirect-budget test failed at the same draw-order assertion in 19 of 30 independent baseline processes and 17 of 30 candidate processes. This test does not exercise texture staging.

Related issue: #888.

Interaction with other work

PR #995 introduces additional staging preparation, adoption, and pool changes. Its conventional staging path still retains the table lock in the inspected revision. Pending reservations would need to be considered when combining the two approaches.

PR #1078 addresses a complementary lock-holding problem during texture refresh.

The current proposal does not incorporate either PR.

Limitations and draft status

  • No real-game FPS or frame-time improvement has been demonstrated.
  • The synthetic performance measurements use the original pinned base.
  • Same-identity contention and producer throughput regressions remain documented.
  • Full workspace validation is incomplete due to the local BCPack exclusion.
  • Interactions with other unmerged staging and refresh changes require further review.
  • Additional hardware and integrated workload validation would be valuable.

Opening as a draft to gather feedback on the concurrency design and the measured latency/throughput trade-offs.

AI disclosure

AI-assisted with OpenAI Codex for the original implementation and test development, and ChatGPT (GPT-6.2) for subsequent review, validation planning, integration guidance, and documentation.

All reported local builds and tests were executed on my Windows machine. Test fixtures use synthetic data.

**@⁠fladit123** on GitHub · 2026-11-25 22:02 UTC · [original](https://github.com/fxceless/victory-fork/pull/1157) `fladit123:fix/texture-staging-reservations` → `main` · +486 −33 · 2 files · 2 commits · draft ## Motivation The conventional texture staging path holds the global staging table lock through footprint preparation, pool checkout, buffer clearing, and D3D12 upload-buffer creation. Cached lookups for unrelated textures can therefore wait behind expensive creation work. This change narrows the scope of the global lock without allowing duplicate creation for the same resource identity. ## Implementation - Reserve staging misses by resource identity. - Create staging outside the global table lock. - Share the result of each reservation through a `OnceLock`. - Release failed or unwinding reservations and wake waiters. - Preserve pending reservations during idle eviction. - Match completed generations during removal, preventing an older remover from deleting a newer staging entry. - Preserve existing command-list ownership of staging buffers. Three permanent, deadline-bounded concurrency tests cover independent progress and single creation, failure and panic recovery, and concurrent removal across generations. Test hooks are compiled only in test builds. ## Synthetic performance measurements The following measurements were obtained on the original pinned base (`d510ee4`) and original runtime candidate (`ca56ec0`), before rebasing. They have not been repeated on the current base. ### Synchronized mixed workload RTX 4060, two threads: | Metric | Main | Candidate | |---|---:|---:| | Independent-hit p95 | 688.55 µs | 0.70 µs | | Uncontended-hit p95 | 0.20 µs | 0.20 µs | ### Fixed producer with free-running readers Eight threads: | Adapter | Main independent-hit p99 | Candidate independent-hit p99 | |---|---:|---:| | RTX 4060 | 1,365.25 µs | 16.45 µs | | WARP | 808.60 µs | 16.50 µs | These latency reductions come with trade-offs. At eight threads, independent-hit p95 increased on both adapters, and producer throughput decreased by 10.90% on RTX 4060 and 15.12% on WARP. ### Repeated paired throughput measurements Twelve independent pairs per configuration, alternating execution order: | Workload | Median paired throughput change | |---|---:| | WARP, single-thread churn | -1.99% | | RTX 4060, two-thread same identity | -4.88% | | WARP, two-thread same identity | -5.50% | Churn showed substantial run-to-run variability, with buffer clearing dominating the instrumented time. These results suggest that the main benefit is reducing interference between independent resources, rather than universally improving staging throughput. No real-game FPS or frame-time improvement is claimed. ## Validation on the current base Base: `9c184b35b43de3455b74ac1770e1c8734a047810` Candidate: `7f1685dd6a77b65983d6bebefb5ab7603dcc2592` The two original patches were cherry-picked onto the current base. `git range-diff` confirmed patch equivalence. Environment: - Windows 11 Pro 26H2. - Intel Core i5-12400F. - 32 GB RAM. - NVIDIA GeForce RTX 4060, 8 GB. - NVIDIA driver 610.88. - WARP. - Rust 1.98.1 MSVC. Build: `cargo test --offline --locked -p victory-gpu --lib --release --features diagnostics --no-run -j 2` Results: | Validation | RTX 4060 | WARP | |---|---:|---:| | Three permanent concurrency tests, parallel harness | 3/3 passed | 3/3 passed | | Complete selected texture group, sequential harness | 5/5 passed | 5/5 passed | Total: 16 successful test executions, including repeated execution of the three permanent tests. Zero failures, zero timeouts, and no reported hardware skips in these runs. The injected creator panic is intentional and is handled by the recovery test. Test executable SHA256: `48BBAE0E86F29F830EEAE5E0A0D9BABE838B7C0FDF92677D3D98D55545F491B5` Additional checks: - `git diff --check`: passed. - Asset policy: `186 files ok`, exit code 0, in the available sparse checkout. - Clean working tree. The test executable was compiled from a disposable source-only copy with the BCPack module declaration omitted. This exclusion is not part of the PR. A full unmodified workspace build has not been validated. ## Previous validation On the original runtime candidate, a graphical confirmation test read back 174,080 exact bytes per adapter with zero D3D12 debug-layer errors. The existing WARP indirect-budget test failed at the same draw-order assertion in 19 of 30 independent baseline processes and 17 of 30 candidate processes. This test does not exercise texture staging. Related issue: #888. ## Interaction with other work PR #995 introduces additional staging preparation, adoption, and pool changes. Its conventional staging path still retains the table lock in the inspected revision. Pending reservations would need to be considered when combining the two approaches. PR #1078 addresses a complementary lock-holding problem during texture refresh. The current proposal does not incorporate either PR. ## Limitations and draft status - No real-game FPS or frame-time improvement has been demonstrated. - The synthetic performance measurements use the original pinned base. - Same-identity contention and producer throughput regressions remain documented. - Full workspace validation is incomplete due to the local BCPack exclusion. - Interactions with other unmerged staging and refresh changes require further review. - Additional hardware and integrated workload validation would be valuable. Opening as a draft to gather feedback on the concurrency design and the measured latency/throughput trade-offs. ## AI disclosure AI-assisted with OpenAI Codex for the original implementation and test development, and ChatGPT (GPT-6.2) for subsequent review, validation planning, integration guidance, and documentation. All reported local builds and tests were executed on my Windows machine. Test fixtures use synthetic data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:37 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1157/head:github-bot/gh-1157'
git switch 'github-bot/gh-1157'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1157'
git switch 'github-bot/gh-1157'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1157'
git switch 'github-bot/gh-1157'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1157'
git switch 'main'
git merge --squash 'github-bot/gh-1157'
git switch 'main'
git merge --ff-only 'github-bot/gh-1157'
git switch 'main'
git merge 'github-bot/gh-1157'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.