Shaders: lower image_gather4_c_lz(_o) and offset sample variants #1687
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1687
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Calvix2k on GitHub · 2026-11-24 20:45 UTC · original
Calvix2k:codex/shader-image-offsets-1535→main· +469 −40 · 3 files · 10 commits · openSummary
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.DXIL gathers exist for 2D, 2D array and cube textures only, and a cube gather takes its offset as undef. A console comparison gather of a 1D, 1D array or 3D image, or a cube gather with texel offsets, therefore emitted a module the validator rejects ("the declared resource kind", "out of bound offset must be undef"), which is a device removal on drivers that enforce it. Return the translator's usual refusal for those four cases. The gather test helper now returns its error so a refusal can be asserted without a device, and gathers_of_a_1d_3d_or_offset_cube_image_are_refused covers them. Reported by Dathinel on this pull request.@Calvix2k on GitHub · 2026-11-24 21:39 UTC · original
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.
@steven-seagull27 on GitHub · 2026-11-24 22:03 UTC · original
@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.
@Calvix2k on GitHub · 2026-11-24 22:16 UTC · original
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.
@Calvix2k on GitHub · 2026-11-24 22:33 UTC · original
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.@AlanQiang0418 on GitHub · 2026-11-24 23:03 UTC · original
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.
@Calvix2k on GitHub · 2026-11-25 02:16 UTC · original
@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?@Dathinel on GitHub · 2026-11-25 02:28 UTC · original
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.
@Calvix2k on GitHub · 2026-11-25 02:32 UTC · original
@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.
@Marvisak on GitHub · 2026-11-25 03:33 UTC · original · edited 2026-11-25 22:24 UTC
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
@Calvix2k on GitHub · 2026-11-25 08:16 UTC · original
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.
@steven-seagull27 on GitHub · 2026-11-25 09:45 UTC · original
@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.
@Calvix2k on GitHub · 2026-11-25 09:56 UTC · original
@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.
@Calvix2k on GitHub · 2026-11-25 10:07 UTC · original
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.
@steven-seagull27 on GitHub · 2026-11-26 01:37 UTC · original
@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.
@steven-seagull27 on GitHub · 2026-11-26 02:30 UTC · original
@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.
f08c8e4573to401e940156@catminou4 on GitHub · 2026-11-24 21:40 UTC · original · approved these changes
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.
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.