Repository navigation
Integrate GPU stability, shader correctness, and submission improvements - #933
Draft
tototomate123 wants to merge 44 commits into
Draft
tototomate123 wants to merge 44 commits into
tototomate123 wants to merge 44 commits into
Conversation
…ate on 32-lane GPUs 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 <noreply@anthropic.com>
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 fxceless#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 fxceless#173 are synthetic. docs/fork-ray-tracing.md lists it with the other assumptions. Reproducer and patch: @Bennet0k, fxceless#173. Co-Authored-By: GLM <noreply@z.ai>
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 <noreply@anthropic.com>
…E_TEXTURES=1) 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 <noreply@anthropic.com>
… calls and sanitize committed aliasing barriers 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 `fxceless#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.
…es the texture (fxceless#776) 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 <noreply@anthropic.com>
…ke, and raw zeroing 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 <noreply@anthropic.com>
…eclare early depth 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 <noreply@anthropic.com> (cherry picked from commit 291bdc4ff1df5694c3dec9a7801ea0b3da3a045a)
… (VICTORY_AMBIENT, off by default) 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.
…for a larger one) 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#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.
…s groups 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)
…s its copies as written 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#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.
Author
|
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 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.
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
0b0074eand 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
cargo test --profile diag -p victory-shader -p victory-gpu --lib --features victory-gpu/diagnostics -- --test-threads=1gave 417 passed and 10 ignored. The final tree also built withcargo build --profile diag -p victory --features diagnostics.VICTORY_BVH_BUILDER=1,VICTORY_BVH_QUARANTINE=0,VICTORY_COPY_PLAIN=1,VICTORY_ASYNC_SUBMIT=1,VICTORY_QUEUE2=1andVICTORY_WIDE_TEXTURES=1created all 53 builder pipelines, then crashed during 3D entry.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.