Shaders: lower image_gather4_c_lz(_o) and offset sample variants #1686
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1687"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T20:45:38Z.
Summary
Reworked on
70564ae. Upstream already has the general _o address/offset machinery, so this now implements the actual gaps:image_gather4_c_lz(_o)lower totextureGatherCmpwith a comparison sampler and the reference value; gather offsets keep their bit positions._osample names are accepted:image_sample_lz_o,l_o,b_o,d_o,c_o,c_lz_o; the offset word is read before bias/coordinates/LOD.Tests
comparison_gathers_and_offset_samples_lower_and_validatebuilds synthetic compute shaders for the comparison gathers andimage_sample_lz/lz_o/l_o/c_lz_o, lowers them and validates every container withdxil.dll. Validation-only: it does not use the AMD sample-execution harness (which currently reads zeros for a control sample on a discrete AMD GPU). Bias/implicit-derivative sample forms are pixel-only and are not exercised by this compute test.Validation
--all-targets --all-features -D warningsandcargo xtask policy(174 files) passed.cargo check -p victory-shader --testspassed.Value tests (this revision)
comparison_gathers_return_their_four_comparisons(by steven-seagull27): a compute dispatch over a 4x4R32_FLOATdepth view with a point, clamp, less-equal sampler. Plain gather,_owith offset 0 and_owith offset (1, 0) must return the comparison of the four footprint texels; RTX 5080 and WARP agree on all three. The earlier fixture used an RGBA32F view, which D3D12 does not support for comparison gathers — the result there depended on the driver.gathers_of_a_1d_3d_or_offset_cube_image_are_refused: the four forms DXIL cannot declare (1D, 1D array, 3D, cube with offsets) are refused at translation.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:40:08Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.TFE image loads/samples/gathers lowered via CheckAccessFullyMapped (s_load_dwords/mimg_sample const encoders, run_sample_cases across formats); 767-line diff with hardware/WARP SM 6.6 coverage.
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T21:39:14Z.
Hardware check on an AMD RDNA3 machine found a problem in the new sample harness, not obviously in the opcode lowering:
image_gather4_c_lz_and_offset_match_d3d12— failed:case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 1.0, 0.0, 0.0].image_sample_offset_variants_match_d3d12— failed:case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 0.0, 0.0, 0.0].image_sample_lzbuilt with the samebuild_sample_csand run throughrun_sample_casesalso returns[0,0,0,0]on this GPU (expected texel[0,100,0,0]). That opcode already worked before this PR, so the zeros point at the test harness's SRV/sampler/root-signature binding on AMD hardware rather than at the new gather/offset lowering.Since the author's runs were on WARP (and WARP doesn't exist at SM 6.6 here), the new tests currently cannot validate the AMD hardware path. Before merging, the harness should be checked on a discrete AMD GPU (descriptor table/sampler binding), or the tests should say they are WARP-only. I can re-run once that is adjusted.
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-24T22:03:10Z.
@Calvix2k, I ran the two new tests at
df9c423on an RTX 5080 (driver 621.24) and built-in Windows WARP, on Windows 11 build 26300.10075. Here are the compute readbacks that matched the expected four-component value:All six RTX mismatches came from the comparison operations. For example, the first red gather returned the raw texels
[4, 5, 1, 0]with the RGBA fixture. With anR32_FLOATdepth view it returned the expected[1, 1, 0, 0]. The three ordinary sampling cases continued to use RGBA. I counted all nine cases with temporary logging so the first failed assertion wouldn’t hide the later readbacks.I also ran the plain
image_sample_lzcontrol from your RX 7800 XT report. Both local adapters returned[0, 100, 0, 0]. That extra control is outside the nine counts.Rerun on the Radeon. The depth fixture commit is directly on top of
df9c423and is also available as a downloadable patch. Since your WARP reports SM 6.2, I included a separate rerun commit that lets the two pipeline-only checks use your hardware adapter.From your existing PR checkout with the same Agility SDK setup:
Could you share whether both tests pass on the RX 7800 XT? If either still returns zeros, the failing case and the result of your plain-sample control would help narrow it down.
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T22:16:13Z.
Marking this as draft rather than forcing the rebase: upstream
70564aerewrote the image-address/a16 and opcode machinery this patch was built on, so it needs a real rework against the new image() code. On top of that, the AMD hardware run showed the newun_sample_cases harness returns zeros even for a control image_sample_lz, so the tests cannot validate the lowering on a discrete AMD GPU yet. I will rework and re-run both once the harness is fixed.
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T22:33:55Z.
Reworked on
70564ae: upstream already handles the general _o address/offset machinery, so this now implements only the real gap —image_gather4_c_lz(_o)astextureGatherCmpwith a comparison sampler and reference value, plus the missing_osample names (lz/l/b/d/c/c_lz) and their bias/LOD address order.cargo check -p victory-shader --tests, clippy-D warningsandcargo xtask policypass.Still draft because the test story is not finished: the original sample harness returns zeros on a discrete AMD GPU (even for a control
image_sample_lz), so I am porting the coverage to a validation/structure check that does not depend on that harness before marking it ready.Imported from Marvisak/VIctory. Originally posted by AlanQiang0418 on 2026-11-24T23:03:01Z.
Pixel readback on
3089d4c:image_sample_b_oselects the wrong texel even with a zero offset. The address operands are offset, bias, X, Y. The current coordinate index counts the bias only for the exact nameimage_sample_b. With the offset form it therefore uses (bias, X) as the sampling coordinates. The existingextravalue already counts both leading words. I tested the one-line changelet first = extra;on top of this PR. Cherry-pickable fixI drew to a 2×2 target with a translated GFX10 pixel shader, a single-mip 4×4 RGBA32F texture, and a point/clamp sampler. Each source texel’s red value was
10*y+x+1. The shader used bias 0 and UV (0.375, 0.875). The four output pixels agreed in each draw, both on an RTX 5080 (621.14) and on WARP.image_sample_bimage_sample_b_o, offset (0, 0)image_sample_b_o, offset (+1, 0)Both versions passed DXIL validation and created the graphics pipelines. The PR’s existing compute validation test also passes with the fix. An asymmetric texture and nonzero, distinct X and Y make this case visible in readback. These measurements use synthetic shaders and textures.
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T02:16:21Z.
@AlanQiang0418 Thank you — the analysis is right and the fix is in
f9979c8on this branch.What I changed: the coordinate base was
offset_word + (name == "image_sample_b") + cmp, which counts the bias forimage_sample_bbut not forimage_sample_b_o, so the offset form sampled at (bias, X). It now usesextra, the same count the packed (a16) address path already splits on — it sums the leading whole VGPRs by name (o,b,c), so both forms land on the same coordinate index.offset_wordis still there for the texel-offset parse and the bias read.I could not reproduce your readback here: my host is Windows 10, where this adapter reports SM 6.5 and WARP SM 6.2, so the GPU probe suites (
emit::*_tests) skip or fail to create a device at all — the CPU emission tests andclippy -D warningspass on the new head. Your 2×2 readback on the RTX 5080 and WARP is the evidence for the fix.We should also keep your harness: a translated pixel shader, a 4×4 RGBA32F with
10*y+x+1, bias 0, UV (0.375, 0.875), offset (0,0) and (+1,0). Do you want to add it as a test in this PR, or shall I take that as a follow-up so this stays a one-line change?Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T02:28:44Z.
Four synthetic comparison-gather cases reach DXIL emission on
b62d2e3and then fail Windows SDK validation. This is separate from the bias-coordinate fix. The dimension checks in #1489 are relevant to this branch too.image_gather4_c_lzimage_gather4_c_lz_oimage_gather4_c_lztextureGatherCmpimage_gather4_c_lz_oout of bound offset must be undefTo reproduce with the PR’s
build_sample_cs, initialize v1–v5 to zero, appendmimg_sample(op, 1, dim, 8, 1, 16, 12), and requiredxil.dllvalidation. Useop=0x04ffor the plain form and0x05ffor the offset form. DIM 0–5 here are 1D, 2D, 3D, cube, 1D array and 2D array, respectively.I tried early refusals in the comparison-gather arm for the unsupported dimensions and for the cube offset form. All four then returned
Unsupportedduring lowering, and the other five still validated. With those local guards, the fullemit::valu_testsmodule passed on Windows/MSVC (38 tests including the nine probes). These are compiler/validator results for synthetic encodings. I did not measure game coverage or texel values for these cases.AI-assisted.
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T02:32:16Z.
@Dathinel Thank you — both rejections were real, and they are refused at translation now instead of reaching the validator (
f9979c8→ new commit on this branch):image_gather4_c_lz/_oof a 1D, 1D array or 3D image: DXIL gathers are 2D, 2D array and cube only, so the lowering now returnsa gather of a 1D or 3D imageforkind1, 4 and 6 instead of declaring a 2D resource over them.image_gather4_c_lz_oon a cube: DXIL wants the offsetundeffor a cube gather (your "out of bound offset must be undef"), and the console's texel offset has no cube equivalent to remap it to, so it returnsa cube gather with texel offsets.New CPU test
gathers_of_a_1d_3d_or_offset_cube_image_are_refusedinvalu_tests.rscovers the four cases (1D, 1D array, 3D, cube+offset) with the samemimg_sampleencoding your harness uses, so they no longer depend on the validator to be caught. The 2D / 2D array / cube and the_o2D forms still lower, and the existingcomparison_gathers_and_offset_samples_lower_and_validatestill validates on the SDKdxil.dllhere.If you re-run your table on the new head: the four rows should now be refusals, like other unsupported image dimensions, and the passing rows unchanged. Thank you for checking the cube offset case — that one would have been a runtime device removal on drivers that enforce it.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:33:47Z.
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main:mainhas moved since the last triage, and the branch now conflicts incrates/victory-shader/src/emit/valu_tests.rs. It will be reviewed again once it is rebased onto currentmain.Previous verdict for this head: merge candidate.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T08:16:12Z.
On the tests the triage asks for, the two halves are different sizes of work, so here is what is possible and what I propose.
Comparison-gather readback.
textureGatherCmphas no derivatives, so a compute dispatch could run it. But the crate has no dispatched image-SRV test at all:build_sample_cs+ the valu helpers only lower and validate, and the binding convention there is the title-memorys_loadpath, not theViewheap thatHost::dispatchfills. The one dispatched gather test,synthetic_tests::gathers_at_a_level_match_the_hardware, hand-builds its whole program because of that. So a value test is a new harness, not a case in an existing one.image_sample_b_oreadback. This one cannot run in compute:sampleBiastakes implicit derivatives, which a compute shader has not — the same reason #2027 exists forsample. It needs a pixel pipeline that samples a texture. The repo's pixel harnesses (rect.rs,emit/mod.rs::edge_flagged_triangles…) draw interpolated colour and bind no textures;diff_testsis the only texture-sampling pixel path and it requires the console SDK'sdxc.exe.Both are therefore test-infrastructure work of a follow-up's size, and I cannot run either here: this host has no SM 6.6 device (the reason #1991 exists), so I would be writing them blind and iterating on CI.
What I propose, in order of preference:
be2e1d2, and track the value readbacks in a separate issue/PR.Which do you prefer? I am happy to do (3) if it is the answer, but I would rather not claim value coverage I cannot execute.
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-25T09:45:15Z.
@Calvix2k, I ported the depth fixture to
ca9bf9fand tested the compute gather that is already on this head. There was a second issue in the fixture: the_ocase put zero in the packed offset register but expected the footprint one texel to the right. With only the depth-view change, the RTX 5080 correctly returned the unshifted comparison for that input.The test now uses an
R32_FLOATview and checks three cases independently. Each row is a four-component result read back from a separate dispatch. Windows 11 build 26300.10075, RTX driver 621.40, built-in WARP 10.0.26100.10068.[0, 1, 0, 0][0, 1, 0, 0][0, 1, 0, 0][0, 1, 0, 0][1, 1, 0, 0][1, 1, 0, 0]All six matched. On the original RGBA fixture the RTX returned raw texels
[13, 14, 10, 9]for both original cases. The commit changes only the test host and the test fixture. The lowering/validation test, the unsupported-dimension test, and shader Clippy also passed. Cherry-pickable commitFrom the PR branch at
ca9bf9f:Could you or another RX 7800 XT tester rerun this with the same SM 6.6 setup and confirm a hardware readback for all three cases? That would close the remaining Radeon question for this compute fixture.
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T09:56:50Z.
@steven-seagull27 thank you — I took your commit as
f08c8e4, authorship kept:View::Depthwith theR32_FLOATSRV, and the three cases (plain, offset 0, offset +1) replacing my fixture.You also found a real hole in mine: the
_ocase put zero in the offset register but expected the footprint one texel right, and because I had skipped WARP for that case while CI has no hardware device, that case never actually ran anywhere. On WARP it returns the shifted block for a zero offset, which made my expectation look right in the runs that did happen. With your fixture all three cases execute and agree ([0,1,0,0],[0,1,0,0],[1,1,0,0]on your RTX 5080 and WARP).On the Radeon readback: I cannot provide it. This machine (Windows 10, RX 7800 XT) has no SM 6.6 device for the test binaries — the in-box runtime stops at 6.5 and the Agility runtime is not loaded for
cargo test, which is the same reason #1991 exists — so the suite skips here rather than comparing anything. The CI runner executes WARP, so the hardware half stays open until someone with an Agility-enabled Radeon test setup runs it. If nobody has one, I would land it on your RTX + WARP evidence and say so in the body.Locally: the test compiles, skips, and the lowering/refusal tests plus clippy pass. CI is running on the new head.
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T10:07:49Z.
Radeon hardware readback for your three cases, on the depth fixture you sent (
f08c8e4): all three match on an RX 7800 XT (RDNA3), Windows 10 19045, driver 32.0.32029.2010, with SM 6.6 provided by Agility SDK 1.620.2 (D3D12Core.dllfrom theD3D12\folder; the opt-in of #486 applied to the test binaries).cargo test -p victory-shader --lib --locked comparison_gathers_return_their_four_comparisons -- --nocapture— 1 passed, 0 failed: plain[0,1,0,0], offset 0[0,1,0,0], offset (+1, 0)[1,1,0,0], as on your RTX 5080 and WARP. The WARP half skipped on this run (this host's WARP still reports SM 6.2 under the factory), so your WARP numbers stay the reference there.That is the Radeon question closed for the compute fixture from my side; the lowering, the refusals and the shader suite also pass on the same setup.
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T01:37:15Z.
@Calvix2k, I resolved the conflict with upstream
63bcca43in a fast-forwardable branch for this PR. The merge retains your original headf08c8e4, the depth-fixture commit, and upstream'sv_mul_legacy_f32test. The conflict was between tests appended at the same spot. Tested mergeThe three gather readbacks still match on RTX 5080 and Windows built-in WARP on that merge. I ran each three times, with the D3D12 adapter identified and all four comparisons read back for each case.
[0, 1, 0, 0][0, 1, 0, 0][1, 1, 0, 0]The DXIL lowering/validation test, invalid-dimension refusal test, and upstream legacy-multiply test also passed. Strict all-target, all-feature shader Clippy and the asset-policy check passed.
With your PR branch checked out, these commands apply the tested resolution while keeping all existing commit IDs:
AI-assisted with Codex. The RX 7800 XT result remains your earlier independent run.
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T02:30:34Z.
@Calvix2k I found a case where this branch and #1489 differ. With a 4×4 R32_FLOAT depth view, reference 7.5, and the same four neighbors, the red comparison gather returned
[1,1,0,0]as expected. Asking for green, blue or alpha returned the same red pattern on both RTX 5080 and Windows WARP in three fresh processes. I ran this on the current-main integration of your head (de67d6f). Microsoft's instruction reference describes the comparison against the red component, and #1489 already guards that case. Microsoft’s gather comparison referenceI merged the two branches on my fork. It keeps both authors’ histories, your extra offset sample opcodes, and #1489’s signed-offset depth fixture and red-only guard. The joint regression explicitly checks masks 2, 4 and 8 for both plain and offset comparison gather. Your red gather cases and the six signed-offset/threshold cases from #1489 still passed on both adapters. The cube validator and refusal fixtures, strict shader Clippy and asset policy passed. Joint commit
To try this on your PR branch:
The broad
gatherfilter also runs the existing explicit-LOD control. It diverges on RTX lane 0 with[0,1,0,0]vs[0,0,0,0]on unmodified main, on both PR branches and on the combination. That control passes on built-in WARP. The measurements here used driver 621.40 and WARP 10.0.26100.10068.AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-26T18:49:49Z.
Good catch, and thank you for doing the rebase as well.
The green/blue/alpha result matches what the lowering does not do yet: it compares against the red component of the depth view and never selects the channel the gather asks for. There is no test with a non-red channel on this branch, which is why the three readbacks have been passing - they all read red.
I will add a case to this PR with a 4x4 R32_FLOAT depth view and green/blue/alpha gathers, expecting the comparison of that channel, so the behaviour is pinned before this lands. If #1489 already covers the semantics, I am happy to follow its shape rather than invent a second one - a pointer to the exact hunk would help.
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-27T00:15:27Z.
@Calvix2k The hunk is lower.rs lines 6029–6035 on the #1489 head. After checking that exactly one dmask bit is set, the comparison-gather path returns an unsupported-channel error for any mask other than red. Its regression test exercises green (
0x2). #1489 only provides that rejection path; it has no implementation of green, blue, or alpha comparisons.For #1687 I'd keep the successful red readbacks for both the plain and offset forms, then test that masks
0x2,0x4, and0x8each report unsupported for both forms. That would catch the silent red result we saw on RTX 5080 and WARP without enshrining it as expected behavior.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T02:09:38Z.
Review: APPROVED
LGTM — verified on Windows (RTX 5090 + WARP):
cargo test -p victory-shader --lib comparison_gathers(2/2:comparison_gathers_return_their_four_comparisonsandcomparison_gathers_and_offset_samples_lower_and_validate) passed on RTX 5090 and underVICTORY_WARP=1cargo test -p victory-shader --lib gathers_of_a_1d_3d_or_offset_cube_image_are_refusedpassedcargo clippy -p victory-shader --all-targets -- -D warningspassed with 0 warningscargo xtask policypassed (191 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T10:08:04Z.
Calvix2k, I applied the red-channel guard suggested in the review thread as e83cac4, directly on
401e940. The new regression fails on that head when a green comparison gather lowers. With the follow-up, both forms reject green, blue and alpha. The two red controls and the ordinary green gather validate. The red comparison readbacks passed on WARP, and all 39 VALU tests passed.I also resolved the overlap with #3493 on this combined branch. It uses #1687's shared address and offset handling and supplies the clamp operand for the offset gradient variant. The 40 VALU tests passed together on app-local WARP 1.0.22. This includes the red comparison readbacks, the non-red checks and the 128 readbacks across the two clamped mip levels and offsets. Strict shader Clippy and asset policy passed on both versions.
e83cac4is ready to cherry-pick. Please retain Git authorship if taking it. If folding it into another commit, please addCo-authored-by: andrewpozdnakov7-jpg <[email protected]>.AI-assisted with Codex. Synthetic textures and shaders only.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.