Repository navigation
Shaders: implicit-level samples in compute follow the console's lane quads (#2027, on #1237) - #2999
wwwwwwww3333333 wants to merge 6 commits into
Conversation
…the quad A console compute program may sample with an implicit level of detail (image_sample, image_sample_b): the hardware takes the coordinates' coarse derivatives across each quad of lanes. As DXIL `sample` and `sampleBias`, these programs failed validation with "Function uses features incompatible with the shader stage (cs) of the entry function". The gradients are now read from the quad (lane 1 less lane 0, lane 2 less lane 0, through waveReadLaneAt) and passed to `sampleGrad`; a bias scales them by 2^bias. Pixel and mesh shaders are unchanged. `victory translate --validate` over the title's shaders on Windows (dxil.dll 10.0.26100), on top of Marvisak#439: compute programs validated go from 1,658 to 2,193 of 2,193 emitted; no other count changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SDn5GupcrERtCYPyoztdtG
…quads The console takes an image_sample's implicit level from quads of lanes, and its compute lanes hold threads in x-major order: in a group of more than one row, a quad is four threads of one row. A host places two-dimensional groups its own way. On an RX 6750 XT an [8, 8, 1] group put 2x2 tiles of threads in a quad, so the quad gradients of Marvisak#1237 (and the host's own derivatives, and main) took the y step across rows. A compute program with such a sample in a group of more than one row, and no other cross-lane code (which already relabels threads to console lanes), now runs as one host row of as many threads; the thread ids are taken back from the flat id. Every host keeps the order of a one-row group, and the console's wave size is not required, so 32-lane hosts run these too. The bias of a sample with 16-bit addresses is the low half's f16, as on the sampleBias path (Marvisak#1237 read the register as f32: image_addresses_of_16_bits_and_clamps failed with it). Test compute_samples_take_derivatives_from_lane_quads: an [8, 8, 1] group whose lane quads give level 1 and whose 2x2 tiles give level 3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
kotekompotek
left a comment
There was a problem hiding this comment.
LGTM — verified the mechanism end to end. implicit_level excludes only _l/_lz/_d/_cd (bias/_cl stay implicit). The row flattening to [xyz,1,1] forces x-major lane quads on every host, with thread_id reconstructing console (x,y,z) from flattenedThreadIdInGroup via URem/UDiv — decomposition is exact. quad_gradients uses lane base|1 and base|2 deltas (hardware coarse-derivative semantics), bias scales by 2^bias through exp2, and the sampleGrad arg order (offsets, ddx3, ddy3, undef clamp) matches DXIL op 63. The test discriminates the two orderings: lane quads give level 1, 2x2 tiles give 3.
|
The compute LOD change matched all 16,416 expected samples per adapter on an RTX 5080 and Microsoft WARP at The original For the wider test I dispatched 2 × 3 × 2 groups and used the guest XYZ local and group IDs to address the UV and output buffers. Each consecutive four guest lanes shared a prescribed footprint of 2, 4, 8 or 16 texels. Each mip had a distinct constant color, with point filtering and clamp-to-edge. I ran plain
Both adapters returned the same counts for guest wave32 and wave64. Across all cases, including 3 × 5 × 4, the predecessor missed 7,844 of 16,416 values on each adapter. These are synthetic texture readbacks. I haven't measured a game frame with this change. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Code review on 1d7472f7 (static source inspection; no runtime GPU/DXIL validation executed):
- P2 — Regression on compute shaders with constant sample offsets (
crates/victory-shader/src/emit/lower.rs:8880-8920):let quad_grads = matches!(op, 60 | 61) && self.s.threads.is_some() && self.s.mesh.is_none() && kind != 5;intercepts non-cube computeimage_sample_o(op == 60) andimage_sample_b_o(op == 61) before the existing60 =>offset decoder, and immediately returnsErr("a sample offset outside a pixel shader")wheneveroffset_wordis set.- Previously, compute
image_sample_owith valid immediate offsets (-8..=7) reached the offset decoder in60 =>. Since DXILsampleGrad(op 63) already accepts the sameosimmediate offset arguments right below (args.extend(&os)), decoding and validatingoffset_wordbefore selectingsampleGradvssamplefixes the regression cleanly. Adding a computeimage_sample_ooffset test case would lock this in.
|
The census you hadn't rerun. Measured offline on the title's shaders (the method in #1247), head
Offline counts and unit tests only; no program names or data. |
…w on Marvisak#2999) image_sample_o in compute was refused on the quad path (fuzeofficlal). The offset word is now decoded once, before the sample, sampleBias and sampleGrad paths, and the quad path passes it to sampleGrad. The lane-quad test binds its coordinates as a raw view, as the program reads them (steven-seagull27), and runs image_sample_o in wave32 and wave64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
|
Both fixed in 7b5a3fc. @fuzeofficlal: the offset word is now decoded once, before the sample, sampleBias and sampleGrad paths, so |
|
@wwwwwwww3333333 I retested At mip 1, lane 0 read AI-assisted with Codex. Synthetic tagged textures. |
|
Automated triage for the maintainers. Thanks, the size issue is fixed. In Merge candidate. A compute program that samples with an implicit level runs its multi-row groups as one host row. The thread ids are rebuilt from the flat id, so quads are four lanes of one row, as on the console. The thread backs this with GPU readbacks on RTX 5080, WARP and two AMD cards, covering the texel-offset path, and with a census of +748 validating programs and none lost. For the maintainers:
CI: passing. Recommending a look, not approving. Generated by Claude Code |
lower.rs was 525,457 bytes on this branch, over the repository's 512 KiB file limit (policy::tests::repository_passes_policy). implicit_level, the one-row thread ids, quad_gradients (which now takes the bias scale) and the decoding of a sample's offset word move to a submodule, as lower/bvh.rs does; lower.rs is 522,621 bytes. No change in behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
|
CI fix in 86f801c: the lane-quad code ( |
Dukestar69
left a comment
There was a problem hiding this comment.
Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + dxil.dll):
cargo test -p victory-shader compute_samples_take_derivatives_from_lane_quads -- --test-threads=1(RTX 5090 & WARP): 1 passed, 0 failed on both.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal
left a comment
There was a problem hiding this comment.
86f801cf moves the quad helpers cleanly into emit/lower/quads.rs (bringing emit/lower.rs down to 522,621 bytes), fixes the compute image_sample_o regression by decoding offset_word ahead of the 60 | 61 if quad_grads branch, and binds the coordinate SRV as Stride::Raw.
A few issues still need attention:
image_sample_b_ois unreachable despite matchingimplicit_level:quads::implicit_levelmatchesimage_sample_b_o(triggering group reshaping), and lines 8837-8854 already handleoffset_wordalongsideop == 61, yetemit/lower.rslines 8664-8677 only dispatchimage_sample_b(image_sample_b_ohitsErr(name)), and lines 8748-8749 only skip the bias address word for exactname == "image_sample_b". Please either wire up and testimage_sample_b_oor explicitly scope it out.- Partial / divergent quad edge cases:
quad_gradientsreads quad lanesbase,base | 1, andbase | 2viawaveReadLaneAt.i32without checking source-lane activity. Please add test coverage for a partial tail quad or divergent control flow. - In-tree offset verification & formatting: Because each mip in
compute_samples_take_derivatives_from_lane_quadshas a uniform color, the in-tree test only checks mip selection rather than texel offset forwarding; a tagged-texel assertion would pin that down in CI. Alsorustfmt --edition 2024 --checkreports line-wrapping diffs inquads.rsandsynthetic_tests.rs.
Verified locally on Windows 11 x64 (RTX 5090 + WARP + dxil.dll, 86f801cf):
cargo run --locked -p xtask -- policy: passed (192 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanemit::lower::tests: 33 passed, 0 failedcompute_samples_take_derivatives_from_lane_quadsandimage_addresses_of_16_bits_and_clamps(RTX 5090 andVICTORY_WARP=1): 1 passed, 0 failed each
…d test - image_sample_b_o takes the same path as image_sample_b (offset, bias, then coordinates). - An implicit-level sample in a group whose size is not a multiple of 4 is refused: the last quad would read lanes that are not threads. Quads that diverge before the sample are undefined, as on hardware. - The lane-quad test tags each texel with its x, so it checks the level and the texel read; it covers image_sample_b_o with a bias of 1. - rustfmt on quads.rs and the test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
|
Thanks @fuzeofficlal. All three are addressed in 9833d58.
Tests (RX 6750 XT and WARP, Windows 11, Rust 1.98.1 MSVC): the lane-quad test passes in wave32 and wave64 for all three forms, twice in a row. victory-shader 303 passed, 0 failed, 3 ignored. clippy -D warnings clean, cargo xtask policy 192 files ok, lower.rs 523,244 bytes. Not covered: quads that diverge before a sample, and any title. |
|
@wwwwwwww3333333 Confirmed The tag encodes mip, X and Y independently. Holding lane 0's offset at
At bias +1, changing just the offset to AI-assisted synthetic test. Divergence within a quad and title behavior remain untested here. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified 9833d580 on RTX 5090 and WARP: image_sample_b_o is now wired into the sampleGrad path, partial-quad thread groups are rejected (product % 4 != 0), emit/lower.rs stays under the policy cap at 523,244 bytes, and compute_samples_take_derivatives_from_lane_quads passes all three forms (Plain, Offset, BiasOffset) in Wave32 and Wave64 on both hardware and WARP with tagged texel checks.
One remaining blocker prevents merging:
- Multi-row groups that also set
console_lanes(emit/lower.rs:620-626, 2936-2976):if !console_lanesskips flattening[X, Y, Z]to[X*Y*Z, 1, 1], leaving the 2D/3D group intact and falling back tothread_id'salign_down(waveReadLaneFirst(flattenedThreadIdInGroup), wave) + lane_index. On hosts that assign 2D groups in 2×2 tiles rather than x-major order (e.g.,[6, 8, 1]at Wave32), two waves can start at flat IDs0and28, both rounding down to0and producing duplicate guest thread IDs and corrupted quad gradients.
Two smaller notes:
- Divergent branches within a quad call
waveReadLaneAt.i32unconditionally onbase,base | 1, andbase | 2(quads.rs:45-70), where inactive lanes yield undefined values (potentially propagating intosampleGradderivatives); keeping that boundary explicit and/or adding divergent-quad coverage is worth considering. quads::implicit_level(quads.rs:8-15) matchesimage_get_lod,image_sample_c,image_sample_cl, and cube (kind == 5) ops even though computequad_gradsonly lowers non-cubeop60/61.
Please make multi-row implicit-level compute groups with console_lanes independent of host tile ordering and add a multi-wave test covering that combination.
Verified locally on Windows 11 x64 (RTX 5090 + WARP + dxil.dll, 9833d580):
cargo run --locked -p xtask -- policy(192 files ok) andcargo clippy --workspace --all-targets -- -D warnings(default and--all-features): clean.emit::lower::tests(33 passed),compute_samples_take_derivatives_from_lane_quads(Wave32 & Wave64, all 3 forms),image_addresses_of_16_bits_and_clamps, andemit::tests(17/17): all passed on both RTX 5090 and WARP.
Reverts f21df5c. Upstream Marvisak#2999 (wwwwwwww3333333, on Marvisak#1237) carries the same bias fix and also lays the lanes of a group with more than one row out as the console's quads (four threads of one row), which Marvisak#1237 got wrong for groups such as [8, 8, 1]. Its commits follow.
…w on Marvisak#2999) image_sample_o in compute was refused on the quad path (fuzeofficlal). The offset word is now decoded once, before the sample, sampleBias and sampleGrad paths, and the quad path passes it to sampleGrad. The lane-quad test binds its coordinates as a raw view, as the program reads them (steven-seagull27), and runs image_sample_o in wave32 and wave64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1 (cherry picked from commit 7b5a3fc)
…IDIA device removals The table row for upstream Marvisak#2999 (lane quads and the f16 bias of compute samples); the NVIDIA note names Marvisak#2118, with which lhnizdo saw no reset on an RTX 2080.
|
@fuzeofficlal I reproduced the multi-row failure from your review on
A native HLSL probe on both adapters read first flat IDs 0 and 28 for the two 6 × 8 waves. Both round down to base 0. Sixteen IDs get assigned twice and IDs 32–47 are missing. The native 48 × 1 control read 0 and 32. An independent CPU model enumerating 2 × 2 tiles gives the same collisions. The fix uses one host row for implicit-level sampling even when another instruction requires console lanes. It retains the wave lane index and reconstructs x/y/z with the original guest dimensions. Across the three shapes the RTX matched 208/208 Wave32 pairs. WARP 1.0.22 matched 208/208 at each of Wave32 and Wave64. Windows inbox WARP skipped both fixed widths. The regression also checks the emitted group dimensions without a working GPU. These measurements cover the converged sampling path. Commit and regression git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2999-multirow-guest-ids
git cherry-pick eec90086e8cd9d350addb5d00d12c633c525ea63
cargo test --locked -p victory-shader --lib multirow_samples_and_console_wave_reads_keep_each_guest_thread -- --nocaptureThe original quad sampling test, strict all-feature shader Clippy, and asset policy passed. AI-assisted with Codex. Synthetic inputs on native Windows. |
|
Thanks @fuzeofficlal for the review and @steven-seagull27 for the reproduction and the fix. I took steven's commit (eec9008, now 3f6b205 on this branch, author kept) as it is: a multi-row group that also needs console lanes is flattened to one host row for implicit-level sampling too, and the thread ids are rebuilt from the guest dimensions. On an RX 6750 XT (RDNA2, driver 32.0.21045.29003, Windows 11, Rust 1.98.1), with the commit on top of 9833d58:
Not addressed in this push: quads that diverge before a sample (still undefined, as on the hardware), and the cube and image_get_lod cases where implicit_level matches more than compute lowers (I haven't added coverage for them). |
Builds on #1237 by @felicienradio (its commit is kept as is, rebased onto main 63bcca4) and adds what makes it match the console in groups of more than one row. It is for the 735 compute programs of #2027 ("Function uses features incompatible with the shader stage (cs)"), which #1237 was measured to validate without a newer validator (@wildheathen's census on #1237; my changes here do not touch validation, and I have not rerun the census). Among them are the fog/lighting apply pass (
CS_ApplyCombinedDeferred, #2045) and the density shadow blur.The problem the earlier comparisons did not reach. The console takes an implicit level from quads of lanes, and its compute lanes hold threads in x-major order: in an
[8, 8, 1]group a quad is four threads of one row. Hosts place two-dimensional groups their own way. On an RX 6750 XT the host put 2x2 tiles of threads in a quad, so main, #1065 and #1237 all took the "y" derivative across rows. The 1D tests on #1237 could not show this, since a one-row group keeps its order everywhere. @ElSeba0811 saw a 2D case pick a different mip on #1237 and fixed it locally the same way (a one-row host group); the test below says which answer is the console's.What changes (second commit)
image_samplewithout_l/_lz/_d/_cd, orimage_get_lod) in a group of more than one row, and no other cross-lane code, runs as one host row of as many threads. Thread ids are taken back from the flat id. Programs that already use cross-lane code keep main's relabelling to console lanes, which also makes the quads right. No wave size is forced, so 32-lane hosts run wave64 programs as before.a16) the bias is the low half's f16, as on main'ssampleBiaspath. Shaders: implicit-level samples in compute take their gradients from the quad #1237 read it as f32, andimage_addresses_of_16_bits_and_clampsfailed with it.Test
compute_samples_take_derivatives_from_lane_quads: an[8, 8, 1]group, coordinates from the thread ids, chosen so that each derivative pair has one nonzero vector (the result does not depend on how the sampler combines them). Lane quads give level 1; 2x2 tiles give level 3. Each level of the texture holds its own number. RX 6750 XT (driver 32.0.21045.29003) and WARP, wave32 and wave64:(The first three rows are wave32 on the hardware adapter, from a first version of the test whose u also stepped along x, which read 3 on every tree; they are the 2x2-tile answer either way.)
Suites (Windows 11, Rust 1.98.1 MSVC): victory-shader 303 passed (main alone: 302; the difference is the new test).
cargo clippy -p victory-shader --all-targets -- -D warnings: clean.Not measured: how the lit world looks with it. That needs a run in the title.
Unit tests only, no game files.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1