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

Closed
github-bot wants to merge 1 commit from gh-pr/694/head into gh-pr/694/base
Owner

@⁠LAKSHYA-cmd-tech on GitHub · 2026-11-24 06:57 UTC · original
LAKSHYA-cmd-tech:fix/image-sample-d-cl-and-gather4-l → main · +118 −7 · 1 files · 1 commits · closed without merging

## 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.

**@⁠LAKSHYA-cmd-tech** on GitHub · 2026-11-24 06:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/694) `LAKSHYA-cmd-tech:fix/image-sample-d-cl-and-gather4-l` → `main` · +118 −7 · 1 files · 1 commits · closed without merging ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:17 +00:00
github-bot closed this pull request 2026-11-26 04:13:17 +00:00
Author
Owner

@⁠r4tedx on GitHub · 2026-11-24 07:03 UTC · original

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.

**@⁠r4tedx** on GitHub · 2026-11-24 07:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7124568947) 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://git.gtahub.st/github/Marvisak--VIctory/pulls/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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/160)). `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://git.gtahub.st/github/Marvisak--VIctory/pulls/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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/318)). Those are the linked testers' measurements, not mine. Nothing was run for this note; the title was not used. AI-assisted.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 07:23 UTC · original

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 07:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7124930044) 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.
Author
Owner

@⁠slint6614-dev on GitHub · 2026-11-24 07:32 UTC · original

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.

**@⁠slint6614-dev** on GitHub · 2026-11-24 07:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7125098303) 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.
Author
Owner

@⁠iurysf on GitHub · 2026-11-24 08:27 UTC · original

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.

**@⁠iurysf** on GitHub · 2026-11-24 08:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7126162911) 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.
Author
Owner

@⁠bittertea0323 on GitHub · 2026-11-24 14:22 UTC · original

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.

**@⁠bittertea0323** on GitHub · 2026-11-24 14:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7134269478) ## 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.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:47 UTC · original

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

**@⁠alexdeliu** on GitHub · 2026-11-24 17:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7139701429) 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>
Author
Owner

@⁠MoonYueya on GitHub · 2026-11-24 18:20 UTC · original

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.

**@⁠MoonYueya** on GitHub · 2026-11-24 18:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7140506007) 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.
Author
Owner

@⁠MrEjecutor on GitHub · 2026-11-24 21:10 UTC · original

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.

**@⁠MrEjecutor** on GitHub · 2026-11-24 21:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7144573890) **`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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:27 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7148531606) 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.
Author
Owner

@⁠MrEjecutor on GitHub · 2026-11-25 00:43 UTC · original

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.

**@⁠MrEjecutor** on GitHub · 2026-11-25 00:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/694#issuecomment-7148801176) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!694
No description provided.