Shaders: support image_sample_d_cl and image_gather4_l lowering (#293, #653) #694

Closed
LAKSHYA-cmd-tech wants to merge 1 commit from upstream-pr/694 into main
LAKSHYA-cmd-tech commented 2026-11-24 06:57:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:57:54Z.


## What

Resolves two frequent shader conversion failures during world load identified in #293 (~103 dropped draws/dispatches per frame) and #653:

  1. image_sample_d_cl:

    • Explicit gradient sampling with LOD clamp (_cl).
    • Mapped to DXIL opcode 63 (sampleGrad.f32), reading the clamp operand at irst + grads + coords and passing it as minLODClamped (operand 16 of SampleGrad).
    • Also added image_sample_cl and image_sample_b_cl clamp handling.
  2. image_gather4_l and image_gather4_l_o:

    • Texture gather with explicit level (_l), which console compute and pixel shaders emit.
    • Lowers to DXIL opcode 73 ( extureGather.f32), extracting texel coordinates (and programmable offsets for _o) and gathering at the base mip level.

Tests

  • Added synthetic unit test image_sample_d_cl_and_gather4_l_translate in crates/victory-shader/src/emit/lower.rs.
  • cargo test -p victory-shader: 70 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean (0 warnings).
  • cargo xtask policy: ok (151 files verified).

No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6576429645 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T06:57:54Z. --- ## What Resolves two frequent shader conversion failures during world load identified in #293 (~103 dropped draws/dispatches per frame) and #653: 1. **image_sample_d_cl**: - Explicit gradient sampling with LOD clamp (_cl). - Mapped to DXIL opcode 63 (sampleGrad.f32), reading the clamp operand at irst + grads + coords and passing it as minLODClamped (operand 16 of SampleGrad). - Also added image_sample_cl and image_sample_b_cl clamp handling. 2. **image_gather4_l and image_gather4_l_o**: - Texture gather with explicit level (_l), which console compute and pixel shaders emit. - Lowers to DXIL opcode 73 ( extureGather.f32), extracting texel coordinates (and programmable offsets for _o) and gathering at the base mip level. ## Tests - Added synthetic unit test image_sample_d_cl_and_gather4_l_translate in crates/victory-shader/src/emit/lower.rs. - cargo test -p victory-shader: 70 passed, 0 failed. - cargo clippy -p victory-shader --all-targets -- -D warnings: clean (0 warnings). - cargo xtask policy: ok (151 files verified). No game data used.
catminou4 commented 2026-11-24 07:01:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T06:58:42Z.

Review: APPROVED


cargo test -p victory-shader --locked on macOS 26 arm64, rustc 1.98.1, head c169328: 57 passed, 0 failed (+1 vs main — the new lowering coverage runs ungated). Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6034959948 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#pullrequestreview-6034959948). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T06:58:42Z. **Review:** APPROVED --- `cargo test -p victory-shader --locked` on macOS 26 arm64, rustc 1.98.1, head `c169328`: **57 passed, 0 failed** (+1 vs main — the new lowering coverage runs ungated). Approving.
r4tedx commented 2026-11-24 07:08:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T07:03:30Z.


A review note from reading the diff at c169328, with two facts about the title's shaders that testers measured for #160, which lowers the same two instructions. I have not built or run this PR.

1. image_gather4_l reads level 0. The change adds image_gather4_l and image_gather4_l_o to the arm that emits textureGather (opcode 73), next to the _lz forms. textureGather has no level operand, and I see nothing in the diff that uses the level, so a gather at level 2 would return level 0's texels. That matters here: over the retail shaders, none of the 12 image_gather4_l programs has a level the translator can prove is 0 (EduAzevedo on #160). #360 had the same gap and its author deferred it. In #160 a gather at a run-time level becomes four samples at the footprint's texel centres at that level, so the sampler's address mode and level range still apply; a level known to be 0 stays a real gather.

2. image_sample_d_cl on a cube. The clamp is read at first + grads + coords, and the gradient count is not changed. Every image_sample_d_cl in the title is on a cube, with eight address registers and no a16: two gradients per direction (the face coordinates'), then the three coordinates and the clamp (EduAzevedo). main expects three gradients per direction on a cube and runs past the operand list. #318 lowered _d_cl without that cube rule and the count of refused programs did not move: 27 at image_sample_d_cl became 27 at an image address (nullmarsh on #318). From reading only, I expect the same here.

A smaller point: the new test checks that the two programs lower, not what they compute. A GPU test with a mipmapped texture whose levels hold different values would have caught the first point.

Where #160 stands, for whoever decides between them: on the title's shaders 23 of the 27 image_sample_d_cl programs and all 12 image_gather4_l programs translate and validate, nothing that translated on main is lost, and in the title #293's top G-buffer pixel shader 7bdefdfde461f6e3 runs with it (nullmarsh). Those are the linked testers' measurements, not mine.

Nothing was run for this note; the title was not used. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124568947 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7124568947). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-24T07:03:30Z. --- A review note from reading the diff at `c169328`, with two facts about the title's shaders that testers measured for #160, which lowers the same two instructions. I have not built or run this PR. **1. `image_gather4_l` reads level 0.** The change adds `image_gather4_l` and `image_gather4_l_o` to the arm that emits `textureGather` (opcode 73), next to the `_lz` forms. `textureGather` has no level operand, and I see nothing in the diff that uses the level, so a gather at level 2 would return level 0's texels. That matters here: over the retail shaders, none of the 12 `image_gather4_l` programs has a level the translator can prove is 0 ([EduAzevedo on #160](https://github.com/Marvisak/VIctory/pull/160#issuecomment-7121615299)). #360 had the same gap and its author deferred it. In #160 a gather at a run-time level becomes four samples at the footprint's texel centres at that level, so the sampler's address mode and level range still apply; a level known to be 0 stays a real gather. **2. `image_sample_d_cl` on a cube.** The clamp is read at `first + grads + coords`, and the gradient count is not changed. Every `image_sample_d_cl` in the title is on a cube, with eight address registers and no a16: two gradients per direction (the face coordinates'), then the three coordinates and the clamp ([EduAzevedo](https://github.com/Marvisak/VIctory/pull/160#issuecomment-7120988076)). `main` expects three gradients per direction on a cube and runs past the operand list. #318 lowered `_d_cl` without that cube rule and the count of refused programs did not move: 27 at `image_sample_d_cl` became 27 at `an image address` ([nullmarsh on #318](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7122079475)). From reading only, I expect the same here. A smaller point: the new test checks that the two programs lower, not what they compute. A GPU test with a mipmapped texture whose levels hold different values would have caught the first point. Where #160 stands, for whoever decides between them: on the title's shaders 23 of the 27 `image_sample_d_cl` programs and all 12 `image_gather4_l` programs translate and validate, nothing that translated on `main` is lost, and in the title #293's top G-buffer pixel shader `7bdefdfde461f6e3` runs with it ([nullmarsh](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7124408758)). Those are the linked testers' measurements, not mine. Nothing was run for this note; the title was not used. AI-assisted.
fuzeofficlal commented 2026-11-24 08:02:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T07:23:06Z.


I ran the same generated mip texture on c169328 and #160 at 25e917b, on the default D3D12 adapter and WARP.

With 32 lanes requesting mip 0, 1 or 2, image_gather4_l on this PR matched 11/32 lanes on each backend. All 21 requests for mips 1 and 2 missed, and the representative lanes for both returned the mip-0 tuple. Both controls (image_sample_l and image_gather4_lz) matched 32/32. The same gather matched 32/32 on #160 on each backend.

The 2D image_sample_d_cl case on this PR correctly selected minimum LODs 0, 1 and 2 per lane. The eight-address cube case from #160's synthetic test stopped at an image address on this PR. On #160 it ran and matched the expected face and mip on both backends.

I also checked image_sample_b_cl with a zero bias and minimum LOD 2. The plain _b control matched 32/32, while _b_cl matched 0/32. Counting the bias address for both SampleBias forms in first (usize::from(op == 61) in place of the exact image_sample_b name check) restored 32/32 on both. #160 already passed that case as well.

These results favor using #160 for the overlapping gather and cube paths. If the sampling clamp changes are split out here, the bias-address fix above preserves the coordinate and clamp operand positions.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124930044 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7124930044). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T07:23:06Z. --- I ran the same generated mip texture on `c169328` and #160 at `25e917b`, on the default D3D12 adapter and WARP. With 32 lanes requesting mip 0, 1 or 2, `image_gather4_l` on this PR matched 11/32 lanes on each backend. All 21 requests for mips 1 and 2 missed, and the representative lanes for both returned the mip-0 tuple. Both controls (`image_sample_l` and `image_gather4_lz`) matched 32/32. The same gather matched 32/32 on #160 on each backend. The 2D `image_sample_d_cl` case on this PR correctly selected minimum LODs 0, 1 and 2 per lane. The eight-address cube case from #160's synthetic test stopped at `an image address` on this PR. On #160 it ran and matched the expected face and mip on both backends. I also checked `image_sample_b_cl` with a zero bias and minimum LOD 2. The plain `_b` control matched 32/32, while `_b_cl` matched 0/32. Counting the bias address for both SampleBias forms in `first` (`usize::from(op == 61)` in place of the exact `image_sample_b` name check) restored 32/32 on both. #160 already passed that case as well. These results favor using #160 for the overlapping gather and cube paths. If the sampling clamp changes are split out here, the bias-address fix above preserves the coordinate and clamp operand positions.
slint6614-dev commented 2026-11-24 08:02:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T07:32:12Z.


Measured on the full retail shader pack (26,503 containers) with victory translate --validate, against main d2a4bae (emitted / validated):

VS/PS CS MS cargo test -p victory-shader
main 12272 / 12172 1693 / 1670 8191 / 8129 ok
#694 12272 / 12172 1705 / 1682 8191 / 8129 ok
#563 12297 / 12197 1693 / 1670 8191 / 8129 ok
#160 12345 / 12237 1705 / 1682 8191 / 8129 ok
#136 12619 / 12619 1796 / 1697 8355 / 8302 ok
  • image_gather4_l (12 refusals, all compute): cleared by #694, #160 and #136; the 12 programs then validate.
  • image_sample_d_cl (27 refusals): cleared by #694, #563 and #160, but only #563 (cube gradients) turns 25 of them into validated pixel programs; with #694 they stop on another reason.
  • #160 also clears the 108 biased 16-bit samples, but adds 8 "Program Input Signature does not match" validator failures (21 → 29).
  • #136 gains the most (+447 VS/PS, +27 CS, +173 MS validated), but the compute "operation incompatible with the shader stage" validator failure goes from 23 to 99: of its 103 newly emitted compute programs, 76 fail validation.

Windows 11, dxil.dll from SDK 10.0.26100.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125098303 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7125098303). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T07:32:12Z. --- Measured on the full retail shader pack (26,503 containers) with `victory translate --validate`, against main d2a4bae (emitted / validated): | | VS/PS | CS | MS | `cargo test -p victory-shader` | |---|---|---|---|---| | main | 12272 / 12172 | 1693 / 1670 | 8191 / 8129 | ok | | #694 | 12272 / 12172 | 1705 / 1682 | 8191 / 8129 | ok | | #563 | 12297 / 12197 | 1693 / 1670 | 8191 / 8129 | ok | | #160 | 12345 / 12237 | 1705 / 1682 | 8191 / 8129 | ok | | #136 | 12619 / 12619 | 1796 / 1697 | 8355 / 8302 | ok | - `image_gather4_l` (12 refusals, all compute): cleared by #694, #160 and #136; the 12 programs then validate. - `image_sample_d_cl` (27 refusals): cleared by #694, #563 and #160, but only #563 (cube gradients) turns 25 of them into validated pixel programs; with #694 they stop on another reason. - #160 also clears the 108 biased 16-bit samples, but adds 8 "Program Input Signature does not match" validator failures (21 → 29). - #136 gains the most (+447 VS/PS, +27 CS, +173 MS validated), but the compute "operation incompatible with the shader stage" validator failure goes from 23 to 99: of its 103 newly emitted compute programs, 76 fail validation. Windows 11, dxil.dll from SDK 10.0.26100.
iurysf commented 2026-11-24 09:06:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T08:27:44Z.


Measured offline against main c2e7254 with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17, comparing outcomes program by program: failures 3,734 -> 3,722 (−12). All 12 "image_gather4_l" refusals now emit and validate, and there are no regressions. On this corpus, the 27 "image_sample_d_cl" refusals are not among those fixed here; #563 clears those (27 -> 0, see my comment there).

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7126162911 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7126162911). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-24T08:27:44Z. --- Measured offline against main `c2e7254` with `victory translate --list --validate` over the title's `shaders.rpf` + executable (26,096 programs), dxil.dll 1.9.2602.17, comparing outcomes program by program: failures 3,734 -> 3,722 (−12). All 12 "image_gather4_l" refusals now emit and validate, and there are no regressions. On this corpus, the 27 "image_sample_d_cl" refusals are not among those fixed here; #563 clears those (27 -> 0, see my comment there). AI-assisted.
Halfect commented 2026-11-24 14:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Halfect on 2026-11-24T13:29:19Z.

Review: COMMENTED


A merge-compile note on current head 0beec4d, verified locally. The correctness questions raised above (gather level, cube gradients, _b_cl bias operand) are separate and still stand; this is only about building against current main.

main commit 6638098 (merged with #566) changed victory_shader::resource::track to take a fourth argument, lanes: Option<&Structured> — tracked for open PRs in #801, which lists this PR among the mergeable ones affected. GitHub shows no text conflict, so nothing looks wrong until CI or a merger runs the tests:

git merge --no-edit 0beec4d   # onto main ffe310e — merges cleanly
cargo check --locked -p victory-shader --tests
error[E0061]: this function takes 4 arguments but 3 arguments were supplied
  --> crates/victory-shader/src/emit/lower.rs:7471
   | let res = resource::track(&p, &native.layout, native.stage).unwrap();
  --> crates/victory-shader/src/emit/lower.rs:7516
   | let res = resource::track(&p, &native_cs.layout, native_cs.stage).unwrap();

Both are the new calls in image_sample_d_cl_and_gather4_l_translate. Since the test computes st after track and exercises no per-lane descriptors, passing None keeps the old behavior:

let res = resource::track(&p, &native.layout, native.stage, None).unwrap();

With that one change at both call sites, the merged tree compiles and the new test passes (cargo test --locked -p victory-shader --lib image_sample_d_cl_and_gather4_l_translate: 1 passed, Windows, rustc 1.98.1). Same fix two of my own PRs needed today (#655, #683).

Verified CPU-only; no game files, no GPU run.

<!-- greyfinch-sync:Marvisak/VIctory:review:6040043595 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#pullrequestreview-6040043595). Originally posted by [Halfect](https://github.com/Halfect) on 2026-11-24T13:29:19Z. **Review:** COMMENTED --- A merge-compile note on current head `0beec4d`, verified locally. The correctness questions raised above (gather level, cube gradients, `_b_cl` bias operand) are separate and still stand; this is only about building against current `main`. `main` commit `6638098` (merged with #566) changed `victory_shader::resource::track` to take a fourth argument, `lanes: Option<&Structured>` — tracked for open PRs in #801, which lists this PR among the mergeable ones affected. GitHub shows no text conflict, so nothing looks wrong until CI or a merger runs the tests: ``` git merge --no-edit 0beec4d # onto main ffe310e — merges cleanly cargo check --locked -p victory-shader --tests ``` ``` error[E0061]: this function takes 4 arguments but 3 arguments were supplied --> crates/victory-shader/src/emit/lower.rs:7471 | let res = resource::track(&p, &native.layout, native.stage).unwrap(); --> crates/victory-shader/src/emit/lower.rs:7516 | let res = resource::track(&p, &native_cs.layout, native_cs.stage).unwrap(); ``` Both are the new calls in `image_sample_d_cl_and_gather4_l_translate`. Since the test computes `st` after `track` and exercises no per-lane descriptors, passing `None` keeps the old behavior: ```rust let res = resource::track(&p, &native.layout, native.stage, None).unwrap(); ``` With that one change at both call sites, the merged tree compiles and the new test passes (`cargo test --locked -p victory-shader --lib image_sample_d_cl_and_gather4_l_translate`: 1 passed, Windows, rustc 1.98.1). Same fix two of my own PRs needed today (#655, #683). Verified CPU-only; no game files, no GPU run.
bittertea0323 commented 2026-11-24 15:04:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by bittertea0323 on 2026-11-24T14:22:28Z.


Verified offline against the whole shader corpus (26,084 programs, 4070 SUPER / Windows 10)

Applied 0beec4d cleanly on ffe310e + local diag changes, then ran the offline batch over the
title's shader container dump (26,503 containers, 26,084 programs, same file both runs):

failure class / metric before after
emit: image_sample_d_cl 29 0
emit: image_gather4_l 16 0
emit: a cross-lane operation outside compute 46 48
compute programs emitting DXIL 1443 / 2582 1459 / 2582
vertex+pixel programs emitting DXIL 12252 / 14027 12252 / 14027
mesh programs emitting DXIL 8214 / 8713 8214 / 8713

Both target classes are gone and 16 more compute programs reach DXIL. Two things worth knowing
before merge:

  1. The 29 sample_d_cl programs did not become emittable — the VS+PS count is unchanged — so
    they carry a second failure class as well. The counter dropping is not the same as those
    programs emitting.
  2. a cross-lane operation outside compute went 46 → 48: a new failure rather than a
    reshuffle of the existing ones. Small, but worth a look.

Repro: cargo build --release -p victory then victory translate <container dump>; both runs
used the same container file on the same host. The rest of the failure table is unchanged from
baseline (translate-baseline in our notes), so nothing else moved.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134269478 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7134269478). Originally posted by [bittertea0323](https://github.com/bittertea0323) on 2026-11-24T14:22:28Z. --- ## Verified offline against the whole shader corpus (26,084 programs, 4070 SUPER / Windows 10) Applied `0beec4d` cleanly on `ffe310e` + local diag changes, then ran the offline batch over the title's shader container dump (26,503 containers, 26,084 programs, same file both runs): | failure class / metric | before | after | |---|---|---| | `emit: image_sample_d_cl` | 29 | **0** | | `emit: image_gather4_l` | 16 | **0** | | `emit: a cross-lane operation outside compute` | 46 | **48** | | compute programs emitting DXIL | 1443 / 2582 | **1459 / 2582** | | vertex+pixel programs emitting DXIL | 12252 / 14027 | 12252 / 14027 | | mesh programs emitting DXIL | 8214 / 8713 | 8214 / 8713 | Both target classes are gone and 16 more compute programs reach DXIL. Two things worth knowing before merge: 1. The 29 `sample_d_cl` programs did not become emittable — the VS+PS count is unchanged — so they carry a second failure class as well. The counter dropping is not the same as those programs emitting. 2. `a cross-lane operation outside compute` went **46 → 48**: a new failure rather than a reshuffle of the existing ones. Small, but worth a look. Repro: `cargo build --release -p victory` then `victory translate <container dump>`; both runs used the same container file on the same host. The rest of the failure table is unchanged from baseline (`translate-baseline` in our notes), so nothing else moved.
alexdeliu commented 2026-11-24 18:05:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:47:10Z.


Merged onto main @ ffe310eb, this PR (efd02d56) no longer compiles its tests. crates/victory-shader/src/emit/lower.rs:7471 (and lower.rs:7516) calls resource::track with 3 arguments. Since 6638098c it takes a 4th, lanes: Option<&Structured>; main's tests pass Some(&st) with let st = structure::structure(&p).unwrap();.

Checked with CI's steps (both clippy runs with -D warnings, cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139701429 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7139701429). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T17:47:10Z. --- Merged onto `main` @ `ffe310eb`, this PR (`efd02d56`) no longer compiles its tests. `crates/victory-shader/src/emit/lower.rs:7471` (and `lower.rs:7516`) calls `resource::track` with 3 arguments. Since 6638098c it takes a 4th, `lanes: Option<&Structured>`; main's tests pass `Some(&st)` with `let st = structure::structure(&p).unwrap();`. <sub>Checked with CI's steps (both clippy runs with `-D warnings`, `cargo test --workspace`) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87</sub>
MoonYueya commented 2026-11-24 19:04:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MoonYueya on 2026-11-24T18:20:29Z.


This PR covers the two instructions our own 303-failure window flagged most often in class E, so we are not going to re-describe them — you have the lowering. Two things from our side that the PR description does not mention, in case they are useful for the follow-on cases:

Parse the modifiers as a set, not as part of the opcode name. l, lz, o and cl are orthogonal to the gather/sample family, which is what makes image_gather4_l and image_sample_d_cl fall out of the opcode table in the first place — they are not missing opcodes, they are unparsed suffixes. Structuring the check as "family + modifier set" also picks up image_gather4_l_o (level and offset) and image_sample_cl / image_sample_b_cl for free, which the PR body does not name.

Gather picks one channel per instruction. The dmask names which one, so the call is GatherRed / GatherGreen / GatherBlue / GatherAlpha, and GatherCmp* when a comparison sampler is bound. A dmask that does not name exactly one channel is worth refusing explicitly rather than picking one.

For reference on the second point, our own lowering's shaping: has_cl / has_o / has_l / has_lz come out of a single mods split, and the LOD is 0u when lz is present, the address when l is present, and computed from derivatives otherwise (pixel stage only). That ordering matters — lz has to win over l, and both have to win over the implicit-derivative path.

(AI-assisted write-up, checked against our own lowering.)

Context: failure measurements in #1481.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140506007 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7140506007). Originally posted by [MoonYueya](https://github.com/MoonYueya) on 2026-11-24T18:20:29Z. --- This PR covers the two instructions our own 303-failure window flagged most often in class E, so we are not going to re-describe them — you have the lowering. Two things from our side that the PR description does not mention, in case they are useful for the follow-on cases: **Parse the modifiers as a set, not as part of the opcode name.** `l`, `lz`, `o` and `cl` are orthogonal to the gather/sample family, which is what makes `image_gather4_l` and `image_sample_d_cl` fall out of the opcode table in the first place — they are not missing opcodes, they are unparsed suffixes. Structuring the check as "family + modifier set" also picks up `image_gather4_l_o` (level *and* offset) and `image_sample_cl` / `image_sample_b_cl` for free, which the PR body does not name. **Gather picks one channel per instruction.** The dmask names which one, so the call is `GatherRed` / `GatherGreen` / `GatherBlue` / `GatherAlpha`, and `GatherCmp*` when a comparison sampler is bound. A dmask that does not name exactly one channel is worth refusing explicitly rather than picking one. For reference on the second point, our own lowering's shaping: `has_cl / has_o / has_l / has_lz` come out of a single `mods` split, and the LOD is `0u` when `lz` is present, the address when `l` is present, and computed from derivatives otherwise (pixel stage only). That ordering matters — `lz` has to win over `l`, and both have to win over the implicit-derivative path. *(AI-assisted write-up, checked against our own lowering.)* Context: failure measurements in #1481.
MrEjecutor commented 2026-11-24 21:28:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MrEjecutor on 2026-11-24T21:10:23Z.


image_gather4_l here gathers at level 0, but the title names a level; a version that reads it, with a GPU test, is on a branch

DXIL TextureGather (opcode 73) has no level operand: it always reads mip 0. With this PR, image_gather4_l / image_gather4_l_o translate, but they read level 0 wherever the console program asks for level n.

Which programs use them, on the retail shaders (victory translate --list on main ffe310e): 17 compute programs are refused on image_gather4_l today, 11 in meshlet_culling (CS_BatchCullMeshlets, CS_BatchCullPreSkinnedMeshlets, CS_BatchCullBatchCSMeshlets and their _Prev / _ParaboloidShadows variants) and 6 in water_micro_geom_renderer (patch generation and culling). According to the fxceless/victory-gta6 fork (the one that renders the lit world on NVIDIA, #1528), the meshlet culling reads its depth pyramid this way: a 4x4 block at the meshlet's level, as one image_gather4_l and three image_gather4_l_o. Read at level 0, "most of the world was culled against the wrong depths", in the fork's words.

A version that reads the named level, written from scratch on main: https://github.com/MrEjecutor/VIctory/tree/gather4-l-level (one commit, 4f44097, on ffe310e). For 2D textures it reads the 2x2 footprint at the named level with four textureLoads in gather order, the offset in texels of that level; cube, array and 16-bit forms stay refused. Shortcuts, marked in the code: the level is rounded and clamped to the texture's levels, and texels past the edge are clamped whatever the sampler says.

Measured:

  • translate --validate over the retail shaders: no program refused on image_gather4_l any more; all of meshlet_culling validates; compute validated 1,417 → 1,433 of 2,582.
  • A GPU test (gather_level_tests.rs, on an RTX 5060 Ti and on WARP): six gathers at levels 1 and 2 of an 8x8 texture, with and without offsets and at the edge, return the expected texels. With the level forced to 0 the test fails on its first case.
  • cargo test -p victory-shader: 122 passed (Rust 1.100). cargo xtask policy: ok. Clippy with warnings denied is clean on the change (1.100 flags one existing loop in lower.rs:678, unrelated).

Not tested: the title with this branch (on this card main alone still hangs in the world, see #747); AMD; the water programs' output.

If it is useful, it can replace the two gather arms here, or be cherry-picked on its own.

AI use: written with Codex (gpt-6-luna) and Claude Code (Claude Opus 5.5); checked and measured by mrejecutor. The analysis that pointed at the level is fxceless's; no code was taken from their fork.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144573890 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7144573890). Originally posted by [MrEjecutor](https://github.com/MrEjecutor) on 2026-11-24T21:10:23Z. --- **`image_gather4_l` here gathers at level 0, but the title names a level; a version that reads it, with a GPU test, is on a branch** DXIL `TextureGather` (opcode 73) has no level operand: it always reads mip 0. With this PR, `image_gather4_l` / `image_gather4_l_o` translate, but they read level 0 wherever the console program asks for level *n*. Which programs use them, on the retail shaders (`victory translate --list` on `main` `ffe310e`): 17 compute programs are refused on `image_gather4_l` today, 11 in `meshlet_culling` (`CS_BatchCullMeshlets`, `CS_BatchCullPreSkinnedMeshlets`, `CS_BatchCullBatchCSMeshlets` and their `_Prev` / `_ParaboloidShadows` variants) and 6 in `water_micro_geom_renderer` (patch generation and culling). According to the `fxceless/victory-gta6` fork (the one that renders the lit world on NVIDIA, #1528), the meshlet culling reads its depth pyramid this way: a 4x4 block at the meshlet's level, as one `image_gather4_l` and three `image_gather4_l_o`. Read at level 0, "most of the world was culled against the wrong depths", in the fork's words. A version that reads the named level, written from scratch on `main`: https://github.com/MrEjecutor/VIctory/tree/gather4-l-level (one commit, `4f44097`, on `ffe310e`). For 2D textures it reads the 2x2 footprint at the named level with four `textureLoad`s in gather order, the offset in texels of that level; cube, array and 16-bit forms stay refused. Shortcuts, marked in the code: the level is rounded and clamped to the texture's levels, and texels past the edge are clamped whatever the sampler says. Measured: - `translate --validate` over the retail shaders: no program refused on `image_gather4_l` any more; all of `meshlet_culling` validates; compute validated 1,417 → 1,433 of 2,582. - A GPU test (`gather_level_tests.rs`, on an RTX 5060 Ti and on WARP): six gathers at levels 1 and 2 of an 8x8 texture, with and without offsets and at the edge, return the expected texels. With the level forced to 0 the test fails on its first case. - `cargo test -p victory-shader`: 122 passed (Rust 1.100). `cargo xtask policy`: ok. Clippy with warnings denied is clean on the change (1.100 flags one existing loop in `lower.rs:678`, unrelated). **Not tested:** the title with this branch (on this card `main` alone still hangs in the world, see #747); AMD; the water programs' output. If it is useful, it can replace the two gather arms here, or be cherry-picked on its own. **AI use:** written with Codex (gpt-6-luna) and Claude Code (Claude Opus 5.5); checked and measured by mrejecutor. The analysis that pointed at the level is fxceless's; no code was taken from their fork.
upstream-sync closed this pull request 2026-11-25 01:04:49 +00:00
Marvisak commented 2026-11-25 01:07:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:27:35Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

image_sample_d_cl and image_gather4_l/_l_o are both lowered in main (emit/lower.rs image(), gather_at_level).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148531606 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7148531606). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:27:35Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. image_sample_d_cl and image_gather4_l/_l_o are both lowered in main (emit/lower.rs image(), gather_at_level). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
MrEjecutor commented 2026-11-25 01:08:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MrEjecutor on 2026-11-25T00:43:00Z.


Follow-up to my comment above: main at 70564ae now lowers image_gather4_l / image_gather4_l_o itself and loads the four texels from the named level (gather_at_level in emit/lower.rs, with the sampler's border and a level proven whole, which my version did not handle). So the gather4-l-level branch I pointed to is superseded and I am not proposing it.

AI use: Claude Code; checked by mrejecutor.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148801176 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7148801176). Originally posted by [MrEjecutor](https://github.com/MrEjecutor) on 2026-11-25T00:43:00Z. --- Follow-up to my comment above: `main` at `70564ae` now lowers `image_gather4_l` / `image_gather4_l_o` itself and loads the four texels from the named level (`gather_at_level` in `emit/lower.rs`, with the sampler's border and a level proven whole, which my version did not handle). So the `gather4-l-level` branch I pointed to is superseded and I am not proposing it. **AI use:** Claude Code; checked by mrejecutor.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!694
No description provided.