Shaders: cube samples with gradients, and image_sample_d_cl #563

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

@⁠SAitken91 on GitHub · 2026-11-24 04:57 UTC · original
SAitken91:shader/cube-gradients-and-sample-d-cl → main · +57 −7 · 1 files · 1 commits · closed without merging

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

**@⁠SAitken91** on GitHub · 2026-11-24 04:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/563) `SAitken91:shader/cube-gradients-and-sample-d-cl` → `main` · +57 −7 · 1 files · 1 commits · closed without merging `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)
image_sample_d_cl was refused by name, and behind it every program hit
a cube sample with explicit gradients, refused as "a cube sample with
... gradients". Both now translate to sampleGrad:

- A cube's gradients on GFX10 are of the face coordinates (s, t), four
  addresses rather than six, so the coordinates follow at 4. They become
  the direction's gradients through the face's linear part of
  cube_direction (u = 2s - 3, v = 2t - 3; the major axis does not move),
  in the new cube_gradient.
- `_cl`: the level-of-detail clamp follows the coordinates and is passed
  as sampleGrad's clamp.

translate --validate on shaders.rpf: vertex/pixel 12172 -> 12197
validated; both errors are gone from the list. Not yet compared against
the console's sampling at runtime.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:08:27 +00:00
github-bot closed this pull request 2026-11-26 04:08:27 +00:00
Author
Owner

@⁠KoLolX3 on GitHub · 2026-11-24 05:32 UTC · original

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.

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

@⁠iurysf on GitHub · 2026-11-24 06:17 UTC · original

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.

**@⁠iurysf** on GitHub · 2026-11-24 06:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/563#issuecomment-7123776552) 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.
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/563#issuecomment-7125098842) 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

@⁠upipibi on GitHub · 2026-11-24 10:19 UTC · original

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

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

@⁠MamaLeVrai on GitHub · 2026-11-24 17:23 UTC · original

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.

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

@⁠Marvisak on GitHub · 2026-11-25 00:25 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 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.

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

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