Shaders: cube samples with gradients, and image_sample_d_cl #563

Closed
SAitken91 wants to merge 1 commit from upstream-pr/563 into main
SAitken91 commented 2026-11-24 04:57:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SAitken91 on 2026-11-24T04:57:31Z.


image_sample_d_cl was refused by name (27 programs in shaders.rpf, including PS_DeferredTextured). Behind it, every one of those programs also hit a cube sample with explicit gradients, refused as "a cube sample with texel coordinates, gradients or a level query". Both now translate to sampleGrad.

Change

  • Cube gradients. On GFX10, a cube's gradients are of the face coordinates (s, t): four addresses rather than six, so the coordinates start at index 4. The old count of six read past the address registers. The new cube_gradient turns the face gradients into the direction's gradients through the face's linear part of cube_direction (u = 2s − 3, v = 2t − 3; the major axis doesn't move). This mirrors the existing table term by term.
  • _cl. The level-of-detail clamp follows the coordinates and is passed as sampleGrad's clamp, which was undef before.
  • Cube samples with texel coordinates or a level query are still refused, as before.

Results

victory translate --validate shaders.rpf: vertex/pixel validated 12172 → 12197. Both errors are gone from the list. The other 2 of the 27 stop at unrelated cases.

Testing

  • cargo test -p victory-shader: 69 passed. Clippy and rustfmt are clean.
  • Not compared against the console's sampling at runtime. The gradient conversion follows from cube_direction being affine per face, but no draw has been checked. A differential test (needs VICTORY_CONSOLE_DXC) would confirm it.

This is independent of #539 and #554.

Written with the help of Claude (AI).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574949134 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/563). Originally posted by [SAitken91](https://github.com/SAitken91) on 2026-11-24T04:57:31Z. --- `image_sample_d_cl` was refused by name (27 programs in shaders.rpf, including `PS_DeferredTextured`). Behind it, every one of those programs also hit a cube sample with explicit gradients, refused as "a cube sample with texel coordinates, gradients or a level query". Both now translate to `sampleGrad`. ## Change - **Cube gradients.** On GFX10, a cube's gradients are of the face coordinates (s, t): four addresses rather than six, so the coordinates start at index 4. The old count of six read past the address registers. The new `cube_gradient` turns the face gradients into the direction's gradients through the face's linear part of `cube_direction` (u = 2s − 3, v = 2t − 3; the major axis doesn't move). This mirrors the existing table term by term. - **`_cl`.** The level-of-detail clamp follows the coordinates and is passed as `sampleGrad`'s clamp, which was undef before. - Cube samples with texel coordinates or a level query are still refused, as before. ## Results `victory translate --validate shaders.rpf`: vertex/pixel validated 12172 → 12197. Both errors are gone from the list. The other 2 of the 27 stop at unrelated cases. ## Testing - `cargo test -p victory-shader`: 69 passed. Clippy and rustfmt are clean. - **Not compared against the console's sampling at runtime.** The gradient conversion follows from `cube_direction` being affine per face, but no draw has been checked. A differential test (needs `VICTORY_CONSOLE_DXC`) would confirm it. This is independent of #539 and #554. Written with the help of Claude (AI). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KoLolX3 commented 2026-11-24 06:56:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KoLolX3 on 2026-11-24T05:32:31Z.


Check on Linux, not Windows: pass. Head 10ac6ceac merged onto main d2a4bae1f (clean merge).

  • Native tests of the seven crates that build on Linux (core, formats, game, loader, pe, pipeline, shader): PR 92 passed, 7 failed, main 92 passed, 7 failed.
  • Windows cross type-check of the whole workspace (cargo xwin check --workspace --target x86_64-pc-windows-msvc, covers victory-gpu, victory-hle and the app): PR ok, main ok.
  • Tests this PR adds: 0 (so the native result only shows the existing tests still pass; the change itself is not covered by a test here).
  • rustfmt: unformatted hunks, PR 168, main 168.
  • Failing on main here as well (not this PR): 7 tests in victory-loader and victory-pe that parse their own test binary as a PE image, which is an ELF file on Linux.
  • Not run: victory-gpu / victory-hle tests and the game itself.

On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123044536 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/563#issuecomment-7123044536). Originally posted by [KoLolX3](https://github.com/KoLolX3) on 2026-11-24T05:32:31Z. --- Check on Linux, not Windows: **pass**. Head `10ac6ceac` merged onto `main` `d2a4bae1f` (clean merge). - Native tests of the seven crates that build on Linux (`core`, `formats`, `game`, `loader`, `pe`, `pipeline`, `shader`): PR `92 passed, 7 failed`, `main` `92 passed, 7 failed`. - Windows cross type-check of the whole workspace (`cargo xwin check --workspace --target x86_64-pc-windows-msvc`, covers `victory-gpu`, `victory-hle` and the app): PR ok, `main` ok. - Tests this PR adds: 0 (so the native result only shows the existing tests still pass; the change itself is not covered by a test here). - rustfmt: unformatted hunks, PR 168, `main` 168. - Failing on `main` here as well (not this PR): 7 tests in `victory-loader` and `victory-pe` that parse their own test binary as a PE image, which is an ELF file on Linux. - Not run: `victory-gpu` / `victory-hle` tests and the game itself. On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.
iurysf commented 2026-11-24 06:56:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T06:17:12Z.


Tested offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17:

  • Translation failures: 3,733 on main -> 3,708 with this PR (-25, all pixel). "image_sample_d_cl" disappears (27 -> 0), and so does "an image address" (2 -> 0).
  • Emitted: vertex+pixel 12,284 -> 12,309 (+25, all validated), matching your count. 185 modules rejected on both; no program that validated on main fails now.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123776552 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/563#issuecomment-7123776552). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-24T06:17:12Z. --- Tested offline against main `d2a4bae` with `victory translate --list --validate` over the title's `shaders.rpf` + executable (26,096 programs), dxil.dll 1.9.2602.17: - Translation failures: 3,733 on main -> 3,708 with this PR (-25, all pixel). "image_sample_d_cl" disappears (27 -> 0), and so does "an image address" (2 -> 0). - Emitted: vertex+pixel 12,284 -> 12,309 (+25, all validated), matching your count. 185 modules rejected on both; no program that validated on main fails now. AI-assisted.
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:14Z.


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:7125098842 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/563#issuecomment-7125098842). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T07:32:14Z. --- 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.
mercuryVM commented 2026-11-24 10:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T09:37:26Z.

Review: APPROVED


Tested 10ac6ce on Windows 11, RTX 5070, MSVC: the workspace passes (195 outside victory-shader; victory-shader --lib with --test-threads=1: 69). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. None of the 12 has cube gradients or _cl.

  • I checked cube_gradient against cube_direction term by term. Each u = 2s − 3 / v = 2t − 3 entry becomes 2·ds / 2·dt with the same sign, and the ±1 major-axis entries become 0. That is the Jacobian of the face-to-direction map.
  • Four gradient addresses for a cube on GFX10 (ds/dx, dt/dx, ds/dy, dt/dy) is right. The old six read two coordinate registers as gradients.
  • _cl reads the clamp right after the coordinates, which matches the MIMG address order (gradients, coordinates, clamp), and is passed as sampleGrad's clamp.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6036816631 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/563#pullrequestreview-6036816631). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T09:37:26Z. **Review:** APPROVED --- Tested 10ac6ce on Windows 11, RTX 5070, MSVC: the workspace passes (195 outside `victory-shader`; `victory-shader --lib` with `--test-threads=1`: 69). `victory translate <title exe> --validate --pipelines` gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. None of the 12 has cube gradients or `_cl`. - I checked `cube_gradient` against `cube_direction` term by term. Each `u = 2s − 3` / `v = 2t − 3` entry becomes `2·ds` / `2·dt` with the same sign, and the ±1 major-axis entries become 0. That is the Jacobian of the face-to-direction map. - Four gradient addresses for a cube on GFX10 (ds/dx, dt/dx, ds/dy, dt/dy) is right. The old six read two coordinate registers as gradients. - `_cl` reads the clamp right after the coordinates, which matches the MIMG address order (gradients, coordinates, clamp), and is passed as `sampleGrad`'s clamp. No issues found. AI-assisted (Claude Code).
upipibi commented 2026-11-24 11:04:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T10:19:31Z.


Independent check of head 10ac6ce, read on its own base and built merged onto main ffe310e (clean merge). I read the comments above first; @mercuryVM already checked cube_gradient against cube_direction term by term and I get the same. This adds the references for the two hardware claims and what is still untested.

References

  • Four gradient addresses on a cube. LLVM IntrinsicsAMDGPU.td (release/18.x, line 640): AMDGPUDimCube : AMDGPUDimProps<0x3, "cube", "CUBE", ["s", "t"], ["face"]>. Gradients are per coordinate name, not per slice name, so a cube has two per direction and the coordinates start at address 4, as the PR has it. With the clamp that is 4 + 3 + 1 = 8 addresses, the count reported for the title's samples on #318.
  • What the gradients are of. Mesa ac_nir_lower_tex.c (mesa-24.0.0, prepare_cube_coords, lines 107-147): with derivatives, sc and tc are multiplied by 1 / |ma| first, the derivatives are converted "to 2D derivatives" of those same quotients, and only then is 1.5 added. So the hardware's gradients are of the face coordinates s and t in [1, 2], and u = 2s - 3 gives du = 2 ds. The PR's factor of two and its zero for the major axis are the exact inverse for a direction whose major component is +-1, which is what cube_direction produces.
  • The clamp. It follows the coordinates in the address list (same file, AMDGPUDimProfile.AddrArgs, lines 739-746: the extra arguments, the gradients, the coordinates and slice, then LodClampMip, which is clamp for the _cl samples), and sampleGrad's last operand is the minimum-LOD clamp, so passing it there is the same quantity.

Limits I see, none new defects of this PR

  • a16. image_sample_d_cl takes the path image_sample_d has on main, where with a16 the gradients are read as packed 16-bit halves. @r4tedx's note on #318 (LLVM's gfx10_asm_mimg.s: gradients stay 32-bit unless the opcode is a _g16 one) applies to both names. The title's _cl samples are reported as not a16, so this is latent, but _cl with a16 now translates where it was refused by name.
  • Cube arrays. cube_gradient compares the face to 0..5 as cube_direction does, so the existing shortcut (the face operand of a cube array adds 8 x the slice) covers gradients too.
  • image_sample_d_cl_o and the comparison forms are still refused by name.

Not tested by anything in this PR. It adds no test, and no test on main samples a cube with gradients, so the suite result below only says nothing else moved. #160 has the same rule (also called cube_gradient) with a GPU test for it, cube_gradients_are_the_face_coordinates in its image_tests.rs, on a cube whose faces and levels each hold their own value. The two PRs edit the same match arm and cannot both land as they are; if this one goes first, that test is the one to carry over. I did not port it: it needs #160's fixture.

Suite. NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, SDK 10.0.26100 dxil.dll validating, cargo test -p victory-shader -- --test-threads=1: main ffe310e + this PR, 120 passed, 0 failed, 1 ignored (the bitcode benchmark).

Not checked: the title (no game files here), AMD hardware, any sampled result.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7128621590 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/563#issuecomment-7128621590). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T10:19:31Z. --- Independent check of head `10ac6ce`, read on its own base and built merged onto `main` `ffe310e` (clean merge). I read the comments above first; @mercuryVM already checked `cube_gradient` against `cube_direction` term by term and I get the same. This adds the references for the two hardware claims and what is still untested. **References** - *Four gradient addresses on a cube.* LLVM `IntrinsicsAMDGPU.td` (release/18.x, line 640): `AMDGPUDimCube : AMDGPUDimProps<0x3, "cube", "CUBE", ["s", "t"], ["face"]>`. Gradients are per coordinate name, not per slice name, so a cube has two per direction and the coordinates start at address 4, as the PR has it. With the clamp that is 4 + 3 + 1 = 8 addresses, the count reported for the title's samples on #318. - *What the gradients are of.* Mesa `ac_nir_lower_tex.c` (`mesa-24.0.0`, `prepare_cube_coords`, lines 107-147): with derivatives, `sc` and `tc` are multiplied by `1 / |ma|` first, the derivatives are converted "to 2D derivatives" of those same quotients, and only then is 1.5 added. So the hardware's gradients are of the face coordinates s and t in [1, 2], and `u = 2s - 3` gives `du = 2 ds`. The PR's factor of two and its zero for the major axis are the exact inverse for a direction whose major component is +-1, which is what `cube_direction` produces. - *The clamp.* It follows the coordinates in the address list (same file, `AMDGPUDimProfile.AddrArgs`, lines 739-746: the extra arguments, the gradients, the coordinates and slice, then `LodClampMip`, which is `clamp` for the `_cl` samples), and `sampleGrad`'s last operand is the minimum-LOD clamp, so passing it there is the same quantity. **Limits I see, none new defects of this PR** - *a16.* `image_sample_d_cl` takes the path `image_sample_d` has on `main`, where with `a16` the gradients are read as packed 16-bit halves. @r4tedx's note on #318 (LLVM's `gfx10_asm_mimg.s`: gradients stay 32-bit unless the opcode is a `_g16` one) applies to both names. The title's `_cl` samples are reported as not a16, so this is latent, but `_cl` with `a16` now translates where it was refused by name. - *Cube arrays.* `cube_gradient` compares the face to 0..5 as `cube_direction` does, so the existing shortcut (the face operand of a cube array adds 8 x the slice) covers gradients too. - `image_sample_d_cl_o` and the comparison forms are still refused by name. **Not tested by anything in this PR.** It adds no test, and no test on `main` samples a cube with gradients, so the suite result below only says nothing else moved. #160 has the same rule (also called `cube_gradient`) with a GPU test for it, `cube_gradients_are_the_face_coordinates` in its `image_tests.rs`, on a cube whose faces and levels each hold their own value. The two PRs edit the same `match` arm and cannot both land as they are; if this one goes first, that test is the one to carry over. I did not port it: it needs #160's fixture. **Suite.** NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, SDK 10.0.26100 `dxil.dll` validating, `cargo test -p victory-shader -- --test-threads=1`: `main` `ffe310e` + this PR, **120 passed, 0 failed, 1 ignored** (the bitcode benchmark). Not checked: the title (no game files here), AMD hardware, any sampled result. AI-assisted (Claude Code).
MamaLeVrai commented 2026-11-24 18:05:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-24T17:23:52Z.


Heads-up: this PR and #1004 both edit the cube-sample refusal in emit/lower.rs and conflict with each other. Merged together only texel coordinates are still refused; that resolution is in the bundle #1319 (clippy and tests pass). AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139132208 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/563#issuecomment-7139132208). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-24T17:23:52Z. --- Heads-up: this PR and #1004 both edit the cube-sample refusal in `emit/lower.rs` and conflict with each other. Merged together only texel coordinates are still refused; that resolution is in the bundle #1319 (clippy and tests pass). AI-assisted (Claude Code); no game data.
upstream-sync closed this pull request 2026-11-25 01:04:15 +00:00
Marvisak commented 2026-11-25 01:07:45 +00:00 (Migrated from github.com)

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


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 cube samples with gradients are in main (0b35b7fe, 4f57f46f), the cube case done as SampleLevel from the face-space gradients because SampleGrad on a cube cannot reproduce them (diff_tests::cube_gradients_pick_the_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:7148486899 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/563#issuecomment-7148486899). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:25:01Z. --- 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 cube samples with gradients are in main (0b35b7fe, 4f57f46f), the cube case done as SampleLevel from the face-space gradients because SampleGrad on a cube cannot reproduce them (diff_tests::cube_gradients_pick_the_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.

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!563
No description provided.