Retry failed GPU scratch chunks with a smaller upload #257

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

@⁠loyodea on GitHub · 2026-11-26 13:28 UTC · original
loyodea:victory-loose-window-pressure → main · +216 −33 · 1 files · 2 commits · open

Related to #147. When the scratch pool has no free chunk and allocating a new 512 KiB chunk returns E_OUTOFMEMORY, retry with a dedicated upload if the request fits a smaller D3D12 allocation. Round the retry size to D3D12 placement alignment for the upload budget and memory accounting. Keep the buffer alive through GPU completion and command-list reset using the existing dedicated-upload path.

Validation

  • On Windows with an RX 9060 XT, a synthetic test injected the failed chunk allocation, uploaded 333 generated bytes through a 64 KiB allocation, and verified the data after a D3D12 copy and readback. The test also checked that reset released the list's buffer reference.
  • A second test verifies that a non-memory error skips the retry, a request that would still cost 512 KiB skips it, and a failed retry propagates its error.
  • The full victory-gpu library suite passed with 115 tests and four ignored. With the diagnostics feature, 118 passed and four were ignored. The serial run had 114 passes, four ignored, and the same write-watch failure as clean upstream 4f62c2a.
  • The staged asset policy check passed. The repository-wide check still flags the pre-existing size of crates/victory-shader/src/emit/lower.rs.

This change covers one scratch-allocation failure path. The reported in-game hang remains unverified. Codex contributed the implementation and verification.

Review follow-up for requests above the scratch chunk

A 524,289-byte request made one 524,544-byte dedicated upload buffer at offset zero. The test checked that the pooled list stayed empty, that the dedicated buffer was retained through submission until reset, and that D3D12 readback matched every byte. All three scratch tests passed on the RX 9060 XT, including an independent rerun. The GPU library suite passed 116 tests with four ignored. Review thread

**@⁠loyodea** on GitHub · 2026-11-26 13:28 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/257) `loyodea:victory-loose-window-pressure` → `main` · +216 −33 · 1 files · 2 commits · open Related to #147. When the scratch pool has no free chunk and allocating a new 512 KiB chunk returns `E_OUTOFMEMORY`, retry with a dedicated upload if the request fits a smaller D3D12 allocation. Round the retry size to D3D12 placement alignment for the upload budget and memory accounting. Keep the buffer alive through GPU completion and command-list reset using the existing dedicated-upload path. **Validation** - On Windows with an RX 9060 XT, a synthetic test injected the failed chunk allocation, uploaded 333 generated bytes through a 64 KiB allocation, and verified the data after a D3D12 copy and readback. The test also checked that reset released the list's buffer reference. - A second test verifies that a non-memory error skips the retry, a request that would still cost 512 KiB skips it, and a failed retry propagates its error. - The full `victory-gpu` library suite passed with 115 tests and four ignored. With the `diagnostics` feature, 118 passed and four were ignored. The serial run had 114 passes, four ignored, and the same write-watch failure as clean upstream `4f62c2a`. - The staged asset policy check passed. The repository-wide check still flags the pre-existing size of `crates/victory-shader/src/emit/lower.rs`. This change covers one scratch-allocation failure path. The reported in-game hang remains unverified. Codex contributed the implementation and verification. ### Review follow-up for requests above the scratch chunk A 524,289-byte request made one 524,544-byte dedicated upload buffer at offset zero. The test checked that the pooled list stayed empty, that the dedicated buffer was retained through submission until reset, and that D3D12 readback matched every byte. All three scratch tests passed on the RX 9060 XT, including an independent rerun. The GPU library suite passed 116 tests with four ignored. [Review thread](https://git.gtahub.st/github/Belobug--VIctory-Belobug-AMD/pulls/257)
After a scratch pool allocation runs out of memory, try a dedicated allocation when the request fits in fewer D3D12 placement units. Test bounded allocation failures and verify a GPU round trip through the retry. Related to #147.

Co-authored-by: Codex <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:32:32 +00:00
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:21 UTC · original · reviewed

AI-assisted review. I inspected the scratch allocation branches and the new retry tests statically; I did not run tests or a GPU/game build. This review suggests one boundary case for the refactored dedicated path.

**@⁠gut0to** on GitHub · 2026-11-26 16:21 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/257#pullrequestreview-6077464630) · **reviewed** AI-assisted review. I inspected the scratch allocation branches and the new retry tests statically; I did not run tests or a GPU/game build. This review suggests one boundary case for the refactored dedicated path.
@ -2580,3 +2681,1 @@
let made = f(&buffer, 0, gpu, data);
self.deferred().uploads.push(buffer);
return Some(made);
return self.dedicated_scratch(len, make, f);
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:21 UTC · original

AI-assisted review; I did not run tests. Could the focused tests also cover a request just over SCRATCH_CHUNK? This branch now routes large requests through dedicated_scratch; asserting one exact-size allocation, no pooled chunk, and retention until list reset would protect that existing behavior while testing the helper extraction.

**@⁠gut0to** on GitHub · 2026-11-26 16:21 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/257#discussion_r4711036860) AI-assisted review; I did not run tests. Could the focused tests also cover a request just over `SCRATCH_CHUNK`? This branch now routes large requests through `dedicated_scratch`; asserting one exact-size allocation, no pooled chunk, and retention until list reset would protect that existing behavior while testing the helper extraction.
@ -2580,3 +2681,1 @@
let made = f(&buffer, 0, gpu, data);
self.deferred().uploads.push(buffer);
return Some(made);
return self.dedicated_scratch(len, make, f);
Author
Owner

@⁠loyodea on GitHub · 2026-11-26 18:53 UTC · original

Agreed. The current tests cover requests below SCRATCH_CHUNK. A request of SCRATCH_CHUNK + 1 should make one upload-buffer allocation of SCRATCH_CHUNK + 256 after alignment. A regression could also verify offset zero, an untouched pool, and retention until the list resets.

**@⁠loyodea** on GitHub · 2026-11-26 18:53 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/257#discussion_r4712406674) Agreed. The current tests cover requests below `SCRATCH_CHUNK`. A request of `SCRATCH_CHUNK + 1` should make one upload-buffer allocation of `SCRATCH_CHUNK + 256` after alignment. A regression could also verify offset zero, an untouched pool, and retention until the list resets.
Verify the allocation request, deferred lifetime, reset, and exact GPU readback for a request one byte over the scratch chunk size. Follow-up to PR #257.

Co-authored-by: Codex <[email protected]>
This pull request can be merged automatically.
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/257/head:github-bot/gh-257'
git switch 'github-bot/gh-257'

Merge

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