Repository navigation
Conversation
|
In-game data point on an RX 7800 XT (Windows 11 26200, 31.6 GB),
Both runs end the same way: a page fault inside freed textures (#135's remaining case). The world stays black behind the cutscene subtitles in both, at about 1–1.6 fps. So I can only say this build got further, not that this PR alone did; #230 is in the second build too. On top of #135 the merge had one conflict, the |
…-aware and non-destructive) into the integration All guards are kept. The clamp writes into the list's scratch buffer, the budget saturates, and its CAS loop stays bounded to 256 tries (the branch's hang guard). A record that cannot settle runs empty. The branch's indirect rectangle-list expansion now reads the clamped scratch records, not the title's buffer. The null-UAV dispatch skip and the dispatch group-limit drop are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
|
Tested this change in a local Windows integration with the rectangle expansion and buffer-state tracking changes. All five indirect tests passed, including the WARP checks for preserving input records, ignoring the tail after the active count, and saturating the budget. Some title draws also place the count in the same shader-writable buffer as the arguments. In the integration I snapshot the bounded count into the scratch allocation and use it for ExecuteIndirect as well. I have not verified a fully presented world frame with this change. |
|
Review note (built on One gap, on resource states. The clamp binds the title's argument and count buffers as root SRVs ( I could not check this with the debug layer (not installed here); someone who has it could run this PR's own tests with a UAV producer in the same list. From reading and synthetic tests only; I have no copy of the title. |
artor410
left a comment
There was a problem hiding this comment.
Review and test of head 1f7f7d2, on top of main d2a4bae. Windows 11, hardware GPU, plus a WARP run with the D3D12 debug layer and GPU-based validation.
Tests: cargo test -p victory-gpu --lib gives 47 passed, 1 ignored. Clippy's only warning is in host.rs:267, which is already on main.
The design: I agree with r4tedx. A count-aware clamp that writes into a scratch buffer and leaves the title's records alone is the right shape.
Resource states (confirms r4tedx's note): I added a local probe to this PR's tests. It is not pushed. It uses WarpHarness, with the debug layer and GPU-based validation on:
- A buffer
tgoes from COMMON to UNORDERED_ACCESS. TheWORKER_CSwrites to it, standing in for the title's argument pass. - Then it runs
record_clamp(src = (t, 64), count = (t, 0)), thenExecuteIndirect(..., Some(&t), 0).
The debug layer reports three errors:
- twice,
SetComputeRootShaderResourceView: state UNORDERED_ACCESS "is invalid for use as a root shader resource" (the source and the count); - once,
ExecuteIndirect: state UNORDERED_ACCESS "is invalid for use as a count buffer". It expects INDIRECT_ARGUMENT.
GPU-based validation also reports "Uninitialized root argument accessed" for root parameters 1 and 2 of the clamp dispatch. That is probably a follow-on of the rejected bindings. The dispatch still ran (hits 1).
The count-buffer error is a regression from main when the count sits in the same buffer as the arguments, the case Raxstreams describes. main transitions that buffer UNORDERED_ACCESS → INDIRECT_ARGUMENT around the execution. This PR leaves the title's buffers untransitioned.
A count in a separate buffer that a shader wrote is wrong on main too.
Suggested fix: Before the clamp, transition the source and count buffers from UNORDERED_ACCESS to NON_PIXEL_SHADER_RESOURCE | INDIRECT_ARGUMENT, and back after ExecuteIndirect, the way main's bound / done do. Alternatively, route them through whichever state tracker lands (#334 / #367). A test like the probe above, with the debug layer's info queue checked for errors, would catch it.
Smaller notes:
- The scratch buffer is one buffer per list at offset 0. Each execution therefore waits on the previous one through the INDIRECT_ARGUMENT → COMMON → UNORDERED_ACCESS transitions. That is correct but serial. A bump allocation per execution, like #282's
argument_space, would let executions overlap if it shows up in profiles. - Merging with #282: I'll rebase #282's rectangle pass to read from your scratch copy if this lands first.
Synthetic tests only; untested against the title.
🤖 Generated with Claude Code
|
Thanks @r4tedx, good catch. Pushed 1711205:
This only sees writes declared through |
The rewrite pass read the title's records after the clamp and relied on the clamp having written its bounds back in place. It now applies the same bounds itself (2^24 vertices, 2^26 vertex instances), so a clamp that writes elsewhere (Marvisak#242) cannot bring back unbounded counts. f32_to_half in the expand shader or-ed the rounded mantissa into the exponent, losing a rounding carry when the exponent is odd (1.99995 became 1.0); it now adds it, as Marvisak#260 does for primitive.rs. The module notes also say that, with vertex inputs, the vertex id is the expanded one, from an allocated start whose order between records may change from run to run. Reported by marquezinii on Marvisak#346. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @artor410 and @r4tedx for the thorough review and debug-layer probe! Pushed a follow-up commit:
Full gate: |
The rewrite pass read the title's records after the clamp and relied on the clamp having written its bounds back in place. It now applies the same bounds itself (2^24 vertices, 2^26 vertex instances), so a clamp that writes elsewhere (Marvisak#242) cannot bring back unbounded counts. f32_to_half in the expand shader or-ed the rounded mantissa into the exponent, losing a rounding carry when the exponent is odd (1.99995 became 1.0); it now adds it, as Marvisak#260 does for primitive.rs. The module notes also say that, with vertex inputs, the vertex id is the expanded one, from an allocated start whose order between records may change from run to run. Reported by marquezinii on Marvisak#346. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hardware data point on the budget loop, RTX 4080, Windows 11. I added one test to this branch: N draw records of one vertex instance each (kind 0, stride 16, no count buffer), which all fit the budget, clamp alone, timing
When many records fit, each successful compare-exchange makes the other threads retry, so the work grows roughly with the square of the record count. 4,096 small records already sit at the host's 2 s time-out. Each device loss came with an nvlddmkm event 153. WARP does not show this (no time-out), and the garbage-record tests don't either, because the budget saturates after a few reservations and everything else exits early. main does not have the problem but still wraps. A single thread walking the records with a saturating count avoids both (27 ms for 65,536 records here): https://github.com/rouges78/VIctory/tree/fix/indirect-budget-wrap, test AI-assisted; the numbers are from real runs on the card. |
The rewrite pass read the title's records after the clamp and relied on the clamp having written its bounds back in place. It now applies the same bounds itself (2^24 vertices, 2^26 vertex instances), so a clamp that writes elsewhere (Marvisak#242) cannot bring back unbounded counts. f32_to_half in the expand shader or-ed the rounded mantissa into the exponent, losing a rounding carry when the exponent is odd (1.99995 became 1.0); it now adds it, as Marvisak#260 does for primitive.rs. The module notes also say that, with vertex inputs, the vertex id is the expanded one, from an allocated start whose order between records may change from run to run. Reported by marquezinii on Marvisak#346. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I tested #242 on WARP and an RTX 2060 SUPER. It preserved the source buffer and passed all five raster cases I tested. One edge case I found involves four 16-byte DRAW records at a 24-byte stride. The last payload fits in 88 bytes, but the buffer lookup requested 96. I included a regression test for that case in Pin0d1#1, along with the ordered work-budget changes. |
Proposed mitigation for CAS contention: group-aggregated budget reservationFollowing the hardware contention results reported by @rouges78 in #242 and #583, I investigated an alternative to both per-record atomic reservations and fully sequential processing. The proposed approach uses a saturating parallel prefix scan within each 64-thread group, followed by a single successful global CAS reservation per admitted group. The prototype:
For 65,536 positive-cost records that all fit within the budget, this reduces successful global reservations from 65,536 to 1,024 (98.4375%). CAS retries and synchronization overhead remain additional costs. CPU-side validationBoth test suites passed, covering 16 automated tests and 71,536 combinatorial and randomized cases across the two models. The grouped implementation matches the scalar saturation policy for the corresponding group-ordered linearization. It does not necessarily admit identical records under different concurrent scheduling orders. LimitationsThe HLSL prototype has not yet been compiled with Microsoft's D3DCompiler_47 or executed on a GPU. The reduction in successful reservations is theoretical, not a measured performance improvement. Global CAS contention is reduced in scope but not necessarily eliminated. The patch targets #242 rather than introducing another independent overflow fix. A useful next step would be to compare this prototype against main, #242, and the sequential implementation using the existing 1,024–65,536-record synthetic workload. This contribution was developed with AI assistance. No proprietary game assets were used. Feedback and independent GPU validation would be appreci |
|
@FunWithFlagsDev I measured the scheme on the RTX 4080. Short version: with 64-thread groups and this PR's retry loop it is about a thousand times faster than this PR at 1,024 records, but still not linear. A back-off between retries, or 1,024-thread groups, removes the quadratic growth in what I measured, and the 1,024-thread version stays within twice a plain add up to a million records. I did not open the zip: I don't open archives attached to comments, from anyone. Instead I had three implementations written independently from your description, all with this PR's root signature and bindings, so each replaces its All of them compile as Clamp alone, N draw records of one vertex instance each, all fitting, in ms. Each run is the median of 3; a range covers the variants and sessions I ran for that cell.
What I take from it:
So the 1,024-thread version of your scheme and the tile walk are both fast enough here. They differ in which records survive when the budget runs out, and in what the result rests on: the tile walk has no contention by construction, while the 1,024-thread version still runs the retry loop between groups, and its scaling is what this card did in two sessions, not something I can explain yet. Both beat the single-thread walk I suggested above (31 ms at 65,536), so I would take either over mine. Method: a private device and queue on the hardware adapter, one submission holding only the clamp, timed around All records fitting is the worst case for a compare-exchange loop: every contender has to win once. With a spent budget or zero-cost records this PR and the grouped variants issue no exchange at all (read from the shaders, not timed). Not measured: other vendors, dispatch and mesh records, mixed costs, and the title. AI-assisted (Claude wrote the shaders and the harness); the numbers are from real runs on the card. |
|
Thank you, @rouges78. This is an excellent independent evaluation of the proposed group-aggregated reservation scheme. Your measurements confirm both the expected reduction in contention and its remaining limitation: aggregation moves contention from individual records to groups, but does not eliminate it. The 1,024-thread variant is particularly interesting, especially its measured performance within roughly twice the plain-add baseline at one million records. I also agree that the ordered tile walk has an important advantage: contention is eliminated by construction, and admission order is deterministic. Following our original group-aggregated proposal, I developed a separate hierarchical saturated-prefix-scan prototype that eliminates global CAS reservations entirely while preserving record order. It uses multiple dispatches rather than a single-dispatch retry loop. CPU-side validation passed, but its GPU performance remains unmeasured. Thank you for the extensive hardware testing and for clearly distinguishing the independent implementations from the original attachment. |
The rewrite pass read the title's records after the clamp and relied on the clamp having written its bounds back in place. It now applies the same bounds itself (2^24 vertices, 2^26 vertex instances), so a clamp that writes elsewhere (Marvisak#242) cannot bring back unbounded counts. f32_to_half in the expand shader or-ed the rounded mantissa into the exponent, losing a rounding carry when the exponent is odd (1.99995 became 1.0); it now adds it, as Marvisak#260 does for primitive.rs. The module notes also say that, with vertex inputs, the vertex id is the expanded one, from an allocated start whose order between records may change from run to run. Reported by marquezinii on Marvisak#346. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 6ff6c88)
The rewrite pass read the title's records after the clamp and relied on the clamp having written its bounds back in place. It now applies the same bounds itself (2^24 vertices, 2^26 vertex instances), so a clamp that writes elsewhere (#242) cannot bring back unbounded counts. f32_to_half in the expand shader or-ed the rounded mantissa into the exponent, losing a rounding carry when the exponent is odd (1.99995 became 1.0); it now adds it, as #260 does for primitive.rs. The module notes also say that, with vertex inputs, the vertex id is the expanded one, from an allocated start whose order between records may change from run to run. Reported by marquezinii on #346. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Read indirect arguments and optional countBuffer via read-only ByteAddressBuffer SRVs and write clamped active records (0..min(max, count)) into a reusable per-HostList DEFAULT-heap scratch buffer at offset 0. Prevents inactive tail slots from exhausting the per-list budget, avoids 32-bit unsigned budget wraparound, preserves full record strides, and leaves shared Shadow buffers untouched in COMMON/GENERIC_READ.
…he clamp
The ExecuteIndirect clamp reads the title's argument and count buffers in
place (root SRVs, and the count again by ExecuteIndirect) and relied on
implicit promotion from COMMON. When a compute pass earlier in the same
list wrote them through unordered access, implicit promotion has already
left the host copy in UNORDERED_ACCESS, from which a buffer cannot be
promoted to a read state.
`HostList::gpu_written` reports whether the list declared shader writes
to a buffer's host copy; `indirect::bound` transitions each such buffer
(once, as the count may live in the argument buffer) from
UNORDERED_ACCESS to NON_PIXEL_SHADER_RESOURCE | INDIRECT_ARGUMENT before
the clamp dispatch, and `indirect::done` moves it back after
ExecuteIndirect so the list's later writers still find it in
UNORDERED_ACCESS. Buffers the list has not written keep using promotion.
`bound` now returns `Bounded { scratch, .. }`.
Adds a WARP test with a UAV producer writing the arguments (and holding
the count) in the same list before the clamp, and a second writer after.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@rouges78, @Pin0d1, @FunWithFlagsDev: thank you for the measurements and the sizing repro. Both are addressed in the latest push.
The branch is rebased onto upstream ffe310e (now 6cb8fbe). Verified with clippy (-D warnings, including the diagnostics build), AI-assisted (Claude Code); checked on Windows 11 / RTX 5090. |
e5ec341 to
6cb8fbe
Compare
|
@wbkepler confirmed at 6cb8fbe on the RTX 4080 where the compare-exchange loop timed out (Windows 11):
The test glue is local; I can push it to a branch if useful. AI-assisted (Claude wrote the harness and ran it with me; the numbers are from real runs). |
|
@wbkepler I prepared a separate logical-resource-span control against 70564ae. A 64-byte native shadow covers a request the 28-byte guest argument resource must reject. The test passed on AMD and WARP and checks payload-only final records and count offsets. The candidate changes the list entry guard only and gives credit to raffclar's final-record review on #40. Your native count-resource and non-destructive clamp work at 6cb8fbe stays separate. The fixture does not exercise native barriers. If you see an overlap at the list boundary, I'd welcome the exact case. AI-assisted using Codex. |
The rewrite pass read the title's records after the clamp and relied on the clamp having written its bounds back in place. It now applies the same bounds itself (2^24 vertices, 2^26 vertex instances), so a clamp that writes elsewhere (Marvisak#242) cannot bring back unbounded counts. f32_to_half in the expand shader or-ed the rounded mantissa into the exponent, losing a rounding carry when the exponent is odd (1.99995 became 1.0); it now adds it, as Marvisak#260 does for primitive.rs. The module notes also say that, with vertex inputs, the vertex id is the expanded one, from an allocated start whose order between records may change from run to run. Reported by marquezinii on Marvisak#346.
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
… chunk buffer Port of RVZO6 Marvisak#2168 onto the hoisted bound_chunk model (our always-hoist chunk-hoist is already landed; Marvisak#2168 targets the old per-call bound() and does not apply). Picks the small clamp PR over Marvisak#2472 (1.1k-line prelude batch pass, no hardware A/B available) and Marvisak#242 (conflicting branch). - bound_chunk: leading global NULL-resource UAV flush becomes targeted barriers on each clamp's argument copy (deduplicated) and any distinct count buffer; per-request trailing global barrier becomes a barrier on the shared budget only. Same order, same transitions. - Zero-record requests run no dispatch and need no barriers; their slice is never read. execute_indirect with max == 0 skips refresh, clamp and execution entirely, counting the draw/dispatch. - HostList::budget now hands out the budget buffer with its address, for the targeted budget barrier. - The chunk clamps into slices of one argument buffer at increasing 16-byte offsets (was: every request at offset 0 of the same cached buffer, so every execution of a multi-request chunk read the last clamp's records, and transitions mismatched under the debug layer). run_pending executes at the request's offset; done_chunk reverts once. - Test: chunk_scopes_uav_barriers_and_zero_records (barrier scope, slice offsets, transition balance via replay).
Summary
Fixes
ExecuteIndirectargument clamping to respect optionalcountBufferand avoid mutating shared titleShadowbuffers in-place:indirect.rsclamp compute shader:src_args(atargs_offset) and optionalcount_buf(has_count+count_offset) via read-onlyByteAddressBufferSRVs (rebasing >4 GiB offsets safely).min(records, count_buf.Load(count_offset))so uninitialized tail slots never consume the per-list budget.BUDGETvia CAS without 32-bit unsigned wraparound, and copies fullstridebytes of active records into a dedicatedRWByteAddressBufferdst_argsscratch buffer at offset0.host.rs,indirect.rs):HostList::indirect_scratchandHost::uav_buffermanage a growable, reusable per-HostListDEFAULT-heap UAV scratch buffer (keeping replaced buffers alive untilreset()), bracketed byCOMMON -> UNORDERED_ACCESS -> INDIRECT_ARGUMENT -> COMMONbarriers while leavingShadowbuffers inCOMMON.draw.rs:0while preserving the original counter buffer and offset.indirect.rsincluding live D3D12 WARPExecuteIndirecttests (countBuffer=3with 4,093 garbage tail slots, back-to-back calls, non-destructive source,stride=24preservation, and 128-recordBUDGETsaturation without wraparound) plusHostListscratch reuse/growth/reset and layout validation tests.Verification
cargo clippy --workspace --all-targets— passed (zero new warnings)cargo clippy -p victory --features diagnostics --all-targets— passedcargo test --workspace— passed (46/46 default, 49/49 diagnostics invictory-gpu)cargo xtask policy— passed (151 files ok)