Integrate GPU stability, shader correctness, and submission improvements #933

Open
github-bot wants to merge 44 commits from github-bot/gh-933 into main AGit
Owner

@⁠tototomate123 on GitHub · 2026-11-25 13:09 UTC · original
tototomate123:integration/rendering-stability-perf → main · +3589 −960 · 30 files · 44 commits · draft

Early review request

Should this land as one integration PR, or would a smaller D3D12 stability and shader correctness batch be easier to review? The draft includes 19 source PRs with their original commits preserved. The latest build passed, and 426 tests passed on retry with 10 ignored. Broader performance validation and the live ray-tracing crash remain open. The ambient approximation stays off by default.

Scope

This integrates 14 open PR heads on top of 0b0074e and retains their original commits for review and attribution. #770 and #905 overlap parts of this work and were useful references.

The integration follow-up uses the descriptor snapshot approach from #792 in both scan paths, clamps CBVs before rounding, retains reserved resources named by alias barriers, and carries coherent compute store waits through IR. The lowering tests moved into a child module to keep the parent source within the repository file-size limit.

Validation

  • AMD Ryzen 7 5800X3D, RTX 4070 SUPER, Windows, Xbox Series X profile
  • cargo test --profile diag -p victory-shader -p victory-gpu --lib --features victory-gpu/diagnostics -- --test-threads=1 gave 417 passed and 10 ignored. The final tree also built with cargo build --profile diag -p victory --features diagnostics.
  • The baseline and integrated defaults reached the opening 3D cutscene. In intervals with 2,500–4,500 draws/frame, the median frame time was 455.7 ms on upstream (17 intervals) and 376.5 ms on the integration (10 intervals). Median copy-back was 162.7 and 175.7 ms respectively. These are draw-band comparisons across single runs with different scenes and cache warmth.
  • Experimental builder run with VICTORY_BVH_BUILDER=1, VICTORY_BVH_QUARANTINE=0, VICTORY_COPY_PLAIN=1, VICTORY_ASYNC_SUBMIT=1, VICTORY_QUEUE2=1 and VICTORY_WIDE_TEXTURES=1 created all 53 builder pipelines, then crashed during 3D entry.
  • The builder-only run reproduced the access violation after all 53 pipelines were created. The builder remains opt-in. A working first-room lighting comparison and controlled switch benchmarks remain open, so this is a draft.

Follow-up batch

Added #925 (exact copy-back scanning and scratch reuse), #919 and #934 (shader correctness), #871 (oversized mesh-pair specialization and device-removal handling), and #917 (opt-in ambient approximation). The PR now incorporates 19 source PRs.

The diagnostics build and asset policy passed. The serial GPU and shader suites passed on retry with 426 passed and 10 ignored. The initial run exited with an access violation in the profiler stack-walk test.

Both ambient configurations reached the opening 3D cutscene. The log confirmed the approximation at 0.6. In the nighttime arrest sequence, the override produced blown-out skin and retained black facial shadows. With the override off on the same build, the skin retained detail and one face was visibly lit, while the other still had dark shadows. Ambient stays off by default. This was a visual smoke test of nearby shots, and it establishes neither a first-room lighting fix nor a performance gain.

**@⁠tototomate123** on GitHub · 2026-11-25 13:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/933) `tototomate123:integration/rendering-stability-perf` → `main` · +3589 −960 · 30 files · 44 commits · draft ## Early review request Should this land as one integration PR, or would a smaller D3D12 stability and shader correctness batch be easier to review? The draft includes 19 source PRs with their original commits preserved. The latest build passed, and 426 tests passed on retry with 10 ignored. Broader performance validation and the live ray-tracing crash remain open. The ambient approximation stays off by default. ## Scope This integrates 14 open PR heads on top of `0b0074e` and retains their original commits for review and attribution. #770 and #905 overlap parts of this work and were useful references. - Ray tracing and shader correctness · #156, #213, #858, #907, #914, #916 - D3D12 stability and descriptor/texture freshness · #787, #795, #807, #896, #899, #908, #911 - Opt-in parallel submission texture checks · #768 The integration follow-up uses the descriptor snapshot approach from #792 in both scan paths, clamps CBVs before rounding, retains reserved resources named by alias barriers, and carries coherent compute store waits through IR. The lowering tests moved into a child module to keep the parent source within the repository file-size limit. ## Validation - AMD Ryzen 7 5800X3D, RTX 4070 SUPER, Windows, Xbox Series X profile - `cargo test --profile diag -p victory-shader -p victory-gpu --lib --features victory-gpu/diagnostics -- --test-threads=1` gave 417 passed and 10 ignored. The final tree also built with `cargo build --profile diag -p victory --features diagnostics`. - The baseline and integrated defaults reached the opening 3D cutscene. In intervals with 2,500–4,500 draws/frame, the median frame time was 455.7 ms on upstream (17 intervals) and 376.5 ms on the integration (10 intervals). Median copy-back was 162.7 and 175.7 ms respectively. These are draw-band comparisons across single runs with different scenes and cache warmth. - Experimental builder run with `VICTORY_BVH_BUILDER=1`, `VICTORY_BVH_QUARANTINE=0`, `VICTORY_COPY_PLAIN=1`, `VICTORY_ASYNC_SUBMIT=1`, `VICTORY_QUEUE2=1` and `VICTORY_WIDE_TEXTURES=1` created all 53 builder pipelines, then crashed during 3D entry. - The builder-only run reproduced the access violation after all 53 pipelines were created. The builder remains opt-in. A working first-room lighting comparison and controlled switch benchmarks remain open, so this is a draft. ## Follow-up batch Added #925 (exact copy-back scanning and scratch reuse), #919 and #934 (shader correctness), #871 (oversized mesh-pair specialization and device-removal handling), and #917 (opt-in ambient approximation). The PR now incorporates 19 source PRs. The diagnostics build and asset policy passed. The serial GPU and shader suites passed on retry with 426 passed and 10 ignored. The initial run exited with an access violation in the profiler stack-walk test. Both ambient configurations reached the opening 3D cutscene. The log confirmed the approximation at 0.6. In the nighttime arrest sequence, the override produced blown-out skin and retained black facial shadows. With the override off on the same build, the skin retained detail and one face was visibly lit, while the other still had dark shadows. Ambient stays off by default. This was a visual smoke test of nearby shots, and it establishes neither a first-room lighting fix nor a performance gain.
Two gaps kept the ray-tracing programs off on a host whose waves are 32 lanes.

1. Buffer views picked from the view heap at a computed index. The shadow-ray
   trace programs read the address of their structure out of a heap descriptor
   they choose with a per-wave index, and walk the memory behind it. The
   translator could only take such an address from a fixed table position.
   The host now keeps, after the strides of `SLOT_STRIDES`, two more dwords
   per heap slot (low and high of the title address of the buffer view
   there), written where the strides are written, and the shader reads them
   by heap slot (`SLOT_ADDRESSES`). No new root parameter; the table grows
   from 8 MB to 24 MB per view heap.

2. `lane_uniform` proves three more things where no lane of a wave can part
   from the others: `tid >> 6` of the entry thread number (in a group whose x
   size is a multiple of 64) is the same in all lanes of a console wave; an
   `ds_read_b32` at such an address is; and a value joined by a phi, also at
   a loop header, is when its arguments are and every predecessor is entered
   by all the arriving lanes or none (a greatest fixed point over the loop's
   carried values and lane masks). The structure builder's block-scan
   programs fetch a wave-uniform running total with `v_readfirstlane` in
   such a loop; without the proof they asked for an exchange between the two
   host waves where not every lane runs.

Effect, with `VICTORY_HOST_WAVE=32` on a 32-lane card:
- 4 of the 5 shadow-ray trace programs (and their screen-space variants) now
  translate and validate; the adaptive one still stops at a lane mask read
  as data.
- 52 of the 52 structure-builder programs now translate, validate and
  create a host pipeline (3 did not).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The node test's reference (bvh.rs) and its emitter (emit/intersect.rs)
took a child whose pointer is 0xffff_ffff for a hit whenever the ray
entered its box. Its result dword was "none" either way, but sorted it
came with a finite distance, so it could stand before a child that is
there; a traversal that stops at the first "none" would then miss that
child.

Both now test the pointer too: a child that is not there is a miss, as
the reference's description of the result already said. The box test's
emitted code grows by two integer instructions per child (a compare and
an and): the parity tests' program (the 64-bit form) goes from 519 to
527 instructions.

The reference's new test is the reproducer of #173: a child that is not
there whose box is entered first, one child behind it, and two that are
not there with their boxes at the ray's origin, in both node widths. The
card tests run the same node and ray. With the reference corrected and
the emitter not, the four parity tests fail on the card; corrected, they
pass on the card and on WARP.

Not known: what the console returns for such a child, and whether the
title's builder ever leaves a box under one. The cases of #173 are
synthetic. docs/fork-ray-tracing.md lists it with the other assumptions.

Reproducer and patch: @Bennet0k, #173.

Co-Authored-By: GLM <[email protected]>
Keep both export lists in emit/mod.rs: main's view_heap_limit and this branch's SLOT_ADDRESSES and SLOT_STRIDES_DWORDS.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
While the world streams in, a submission checks hundreds of textures one
after another on the submitting thread: each is read, hashed whole and,
when it changed, detiled into its staging buffer. With the switch the
checks that come due in a batch are queued (Batch::textures_due) and run
at its next flush, before a step that writes title memory and before the
lists run, so their order against those steps is unchanged, on the
threads kept for the snapshots (shadow::wide_run). Each check reads its
texture's title memory and writes its own staging buffer and notes under
its own lock, and a texture is queued once per batch (texture_due), so no
two threads check the same texture. The frame line's "textures" counts
the time it took, not the threads' sum.

Measured on the opening cutscene and the first world minutes (RTX 3090
Ti, 8dd30ab, same binary, one launch each):

  default                        frame ~1,030 ms, textures ~330 ms
  VICTORY_WIDE_TEXTURES=1         frame   ~826 ms, textures ~120 ms
  VICTORY_TEXTURE_NO_WAIT=1       frame   ~654 ms, textures  ~44 ms
  both                           frame   ~518 ms, textures  ~16 ms

Steady state after streaming: 4.0-4.3 fps in all four.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fix two Direct3D 12 barrier validation bugs in `crates/victory-gpu/src/list.rs`:

1. Duplicate `ALL_SUBRESOURCES` transitions in a single `ResourceBarrier` call
   (D3D12 error `#524`): `host_barrier()` flattens per-subresource transition
   barriers to `D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES`. When a title passes
   two barriers transitioning different subresources of the same texture to
   different states in one `ResourceBarrier(count, barriers)` call, `barrier()`
   previously submitted both whole-resource transitions together in a single
   `ResourceBarrier` slice. Split the translated barriers via
   `for_barrier_batches()` so no single `ResourceBarrier` call repeats a
   `Transition` (`kind == 0`) barrier for the same host `ID3D12Resource`.

2. Committed resources in `D3D12_RESOURCE_BARRIER_TYPE_ALIASING` barriers:
   `host_barrier()` previously passed raw `ID3D12Resource*` pointers for host
   textures created via `CreateCommittedResource` directly into aliasing
   barriers (and forwarded `flags`). D3D12 forbids committed resources and
   non-zero barrier flags on aliasing barriers (only placed/reserved resources
   or `NULL` are allowed). Resolve each non-null endpoint via
   `resource::host_copy()` and `aliasing_barrier()`, preserving reserved
   (`host.tiled.is_some()`) resource pointers while downgrading committed
   resources to `NULL` (yielding a valid half-open or global aliasing barrier)
   and zeroing `flags`.

Add unit tests covering batch splitting, aliasing normalization, and a real
D3D12 device test exercising committed aliasing and multi-subresource
transitions in a single `barrier()` call.
The tiles of a texture made level by level (VICTORY_LEVELS_ON_DEMAND=1) are
in heaps of ours, not in the texture. A list recorded or in the air keeps
the texture it names (`HostList::keep`), not its host copy, so the host
copy could be let go (the sweep, the title's release) while a list still to
run read through the texture's mappings: the tiles went back to the pool,
were given to other textures, and a heap with all of its tiles free went
back to the card.

On an RTX 3080 Ti, Series X, levels on demand with room for buffers: the
device was removed (0x887A0006) in 1 run of 3, about ten seconds into the
world, 6.4 s after a sweep let go 610 host copies of textures, with one
heap given back to the card; in the runs that went on none was. With this
change: 0 removals in 4 runs (292, 274, 279 and 272 ms a frame), two of
them with a heap given back.

A host copy let go now hands its texture and tiles to a list
(`tiles::let_go`); the tiles go back when nothing but that list names the
texture (`tiles::give_back_let_go`, at every sweep), at once if nothing
does already. Step 8 of the levels-on-demand test lets go of a texture a
list still keeps and checks that its tiles wait until the list is reset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fix two cache-invalidation bugs in `HostHeap::mirror_copied` / `HostHeap::mirror` / `HostHeap::texture_slot_gone`
(`crates/victory-gpu/src/descriptor/host.rs`):

1. Stale `self.copied` fingerprint across API writes and `unmake`:
   `self.copied[index]` was updated only by `mirror_copied()` and never cleared
   when `mirror()` (via `Create*View`/`CopyDescriptors`), `texture_slot_gone()`,
   or stale placed-texture `unmake()` overwrote or nulled a slot. Copying
   record A -> API write B -> raw-copy A (or raw-copy A -> `unmake` -> raw-copy A)
   hit `*last == print` and left the host slot permanently stuck on B or NULL.
   Invalidate `self.copied[index]` (outside the `self.made` lock to preserve
   lock order) whenever `mirror()` or `unmake()` modifies or clears a slot.

2. Raw zeroing of an API-created slot skipped:
   When a slot was written via API (`made[index] != 0`, `copied[index] == 0`)
   and later cleared by raw zeroing, `*last == 0 && all_zero` returned `false`
   without checking `made[index]`, leaving the old host descriptor alive and
   pinning its `Kept` GPU resource. Check `made[index]` before skipping.

Add `descriptor::tests::copied_fingerprint_invalidates_across_api_writes_unmake_and_zeroing`.
(cherry picked from commit 5c0073ce5ffc8d753d69390b9aa425a8941dbfd5)
Specialize only the selected mesh and pixel stages when whole unread varyings bring the mesh output under the D3D12 size limit. Preserve binding metadata, other signature elements, and independent shader translations.

(cherry picked from commit 1e0ce45f2b8e95074459d4ccf10589083e9669c5)
Merge overlapping changes before looking up placed views. If the whole pending buffer is disjoint, fold neighboring intervals to preserve coverage within the existing cap.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A pixel program's DB_SHADER_CONTROL (in its native record) says whether the
console runs the depth and stencil tests before the shader: bit 12,
DEPTH_BEFORE_SHADER, which the console compiler sets for HLSL
[earlydepthstencil]. The translation never said so, so the host tested
after the shader, and a program that writes unordered views wrote them for
pixels the depth test then rejected. The title's glass prepass
(PS_AlphaPrepass, DB_SHADER_CONTROL 0x1450) writes the glass's depth and
motion to a view: with late tests it wrote them for every pixel of a
window pane, the character standing in front of it too, and
PS_AlphaVelocityDepthResolve then copied those over the character's depth
and motion vectors. Inside each pane the character lost her depth and
motion (rectangles cut out of the depth and velocity targets), and moved
with ghosted, staircase-edged smears where the pane was.

Such programs now get ShaderFlags ForceEarlyDepthStencil (bit 3), unless
they export depth, stencil or coverage. 3,023 of the pack's 12,101 pixel
programs have the bit (DB_SHADER_CONTROL 0x1050 1,718, 0x1450 705, 0x1010
380, 0x1410 220; counted with shader-info, which now prints a pixel
program's DB_SHADER_CONTROL).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 291bdc4ff1df5694c3dec9a7801ea0b3da3a045a)
The title's indirect diffuse light comes from probes it fills by tracing
rays, which do not run yet: the program that resolves them leaves next
to nothing, and whatever the sun does not reach directly is black.

With VICTORY_AMBIENT=<level> the image that program wrote is replaced,
right after its dispatch, by one constant; the title's own lighting
applies it with the surfaces' colors. Off by default: nothing changes
without the switch.

The pass is Belobug's (VIctory-Belobug-AMD, crates/victory-gpu/src/
ambient.rs, on by default there), fitted to this tree.
The title names constant buffer views of more than 4,096 vectors (one of
1,306,368 bytes, in the world). CreateConstantBufferView with a size over
65,536 bytes is an invalid call; NVIDIA removes the device for it
(DXGI_ERROR_INVALID_CALL, 0x887A0001) in the frame the view is made. Both
places that make constant views (make, HostHeap::constant_at) now cap the
size at 64 KiB, the most a shader can read through one.
Carry the host texture through the asynchronous present queue and transition it in the command-list prelude. Based on the fix by AscilCH in fxceless/victory-fork#564.
Merging just one overlap at capacity meant a producer could sort the entire queue again for each following notification. Free one eighth of the queue when exact coalescing leaves less room, joining only enough pairs to reach that target.
The console keeps memory coherent between the groups of a dispatch only
where a program asks: cache-control bits (GLC, DLC, SLC) on a memory or
scalar access, a memory atomic, or a cache invalidation. Such a program
(the title's BVH builder: atomics, then reads of what other groups wrote)
now has every UAV globally coherent (resource properties bit 14, and the
root UAVs' metadata), and a device-wide memory fence (barrier mode 2, no
group sync) where it waits for its stores (s_waitcnt_vscnt) or drops its
caches (buffer_gl0_inv, buffer_gl1_inv, s_gl1_inv, s_dcache_inv): the
host orders a thread's accesses for other groups only at a fence. Every
other program keeps plain views and no fences. Written anew from the
mechanism; no other project's code.

Tests:
- unit (coherent_views_follow_cache_bits_atomics_and_invalidations):
  plain buffer accesses and LDS atomics keep plain views; glc, dlc, slc,
  a buffer atomic, buffer_gl0_inv and s_load glc get coherent ones;
- GPU (in our tree; its harness is not in this fork):
  group 0 waits, stores 42, waits for the store and sets a flag atomically;
  group 1 reads the data (0), spins on the flag, invalidates and rereads:
  42 in every lane on the RTX 5070 Ti and the Radeon iGPU. The same with
  the rule switched off also gives 42 on both (their drivers keep no
  stale copy there), so the test checks the coherent form rather than
  showing the plain one fail. What did fail on the Radeon: loads through a
  read-only view of the written buffer, which a program gets when the
  metadata names no UAV.

XboxBvhBuilder.dll: 52 of 52 programs translate, validate and get host
pipelines as before; 14 of them now have coherent views.

(cherry picked from commit 369f26f, without the GPU test, whose harness this
fork lacks)
A shader that reads title memory by address had every numbered copy of
that memory declared written whenever it could store anything at all:
snapshotted before its submission and compared on the CPU after. The
programs that walk the ray-tracing structures read them by address and
store their results through views, so each of their dispatches declared
all of the copies. With the structure builder running (quarantined) that
was 12 GB snapshotted and compared a frame, 3030 ranges of 4 MiB, and a
frame took 3.5 s (1.3 s of it copying back; run rt-4).

Now only a program that can store by address (a flat, global or
scalar-memory store or atomic, or code not all known) declares them;
stores through root views are declared as before. Run rt-5, same
switches: about 490 ms a frame in the world, 60 ms copying back.

(cherry picked from commit 30ee710008c9bda3ce5b32f360cc0c61c32792fd)
Adapt the snapshot approach from yualk in fxceless/victory-fork#792 to the batched descriptor path. Retain reserved resources named by alias barriers, clamp oversized constant views before alignment, and keep coherent compute store waits through IR. Move lowering tests to a child module to keep the source file within the repository size limit.
Keep one scratch buffer for the page scan, fold configured gaps as runs are found, and update diagnostic counters once per page.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:54:07 +00:00
Author
Owner

@⁠tototomate123 on GitHub · 2026-11-25 13:31 UTC · original

Hey @⁠fxceless, would you be open to an early scope review of this draft? It integrates 19 source PRs, and I’d like your take on whether a combined PR is useful or whether you’d rather see a smaller first batch focused on D3D12 stability and shader correctness.

The build passed and 426 tests passed on retry, with 10 ignored. The performance result is still preliminary. Live ray tracing still crashes on our Series X test, and the ambient approximation looked worse in the tested cutscene, so it stays off by default. Feedback on the shape of the PR would be especially helpful before I mark it ready.

**@⁠tototomate123** on GitHub · 2026-11-25 13:31 UTC · [original](https://github.com/fxceless/victory-fork/pull/933#issuecomment-7163905787) Hey @⁠fxceless, would you be open to an early scope review of this draft? It integrates 19 source PRs, and I’d like your take on whether a combined PR is useful or whether you’d rather see a smaller first batch focused on D3D12 stability and shader correctness. The build passed and 426 tests passed on retry, with 10 ignored. The performance result is still preliminary. Live ray tracing still crashes on our Series X test, and the ambient approximation looked worse in the tested cutscene, so it stays off by default. Feedback on the shape of the PR would be especially helpful before I mark it ready.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/indirect.rs
  • crates/victory-gpu/src/pipeline.rs
  • crates/victory-gpu/src/shadow.rs
  • crates/victory-gpu/src/tiles.rs
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/mod.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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