Shaders: gradient samples on cube images #138

Closed
github-bot wants to merge 4 commits from gh-pr/138/head into gh-pr/138/base
Owner

@⁠LaunchDoesntCode on GitHub · 2026-11-24 00:51 UTC · original
shader/cube-gradient-samples → main · +213 −42 · 1 files · 4 commits · closed without merging

Depends on: #73. This branch is built on #73's head, so until that merges the diff shows its commit too. Only the last commit, 492e948, is new here.

What

image_sample_d and image_sample_d_cl on cube images were refused ("a cube sample with texel coordinates, gradients or a level query"). They now translate. Texel coordinates and level queries on cubes are still refused.

How

  • A cube's explicit gradients are those of its two face coordinates, so there are two per direction, not three. The gradient count (and with it where the coordinates and the clamp start) now uses that for cubes.
  • cube_direction is linear in the face coordinates, so the new cube_gradient returns its derivative for the host's sampleGrad: twice each face gradient, signed per face, zero along the face's own axis. Both share a small cube_face helper for the per-face select.

Measured

victory translate over the Xbox 1.0.2.1 shader containers (26,503 containers, 26,084 programs), #73's head against this branch:

#73 this branch
Vertex and pixel programs emitted (of 14,001) 12,316 12,341
"a cube sample with texel coordinates, gradients or a level query" 27 0

No other category got worse; "a cross-lane operation outside compute" goes 48 → 50 because two programs now get further. The corpus has 52 image_sample_d and 248 image_sample_d_cl on cubes, none with a16.

Tested

  • Cross-built for x86_64-pc-windows-msvc on Linux and run under Proton 10 (vkd3d-proton), RTX 5090.
  • cargo test -p victory-shader: all pass except stub_pipeline_is_created, which also fails on unmodified main under Proton (vkd3d-proton accepts the zero digest).
  • Current main + #73 + this commit merges cleanly, builds, and passes the same tests.
  • A host pipeline was created from 14 of the newly emitted programs, one at a time, under vkd3d-proton.

Not tested: a Windows run, please

I have no Windows build of this yet, so two things are unchecked:

  1. victory translate --validate with dxil.dll on the newly emitted programs.
  2. The picture. The gradient conversion is derived from cube_direction, not confirmed against the console's output. If someone on Windows can look at a cube-lit surface or reflection in the title with this branch, that would settle it. A wrong sign or scale would show as the wrong mip level (too blurry or too sharp) rather than a crash.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠LaunchDoesntCode** on GitHub · 2026-11-24 00:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/138) `shader/cube-gradient-samples` → `main` · +213 −42 · 1 files · 4 commits · closed without merging **Depends on: #73.** This branch is built on #73's head, so until that merges the diff shows its commit too. Only the last commit, `492e948`, is new here. ## What `image_sample_d` and `image_sample_d_cl` on cube images were refused ("a cube sample with texel coordinates, gradients or a level query"). They now translate. Texel coordinates and level queries on cubes are still refused. ## How - A cube's explicit gradients are those of its two face coordinates, so there are two per direction, not three. The gradient count (and with it where the coordinates and the clamp start) now uses that for cubes. - `cube_direction` is linear in the face coordinates, so the new `cube_gradient` returns its derivative for the host's `sampleGrad`: twice each face gradient, signed per face, zero along the face's own axis. Both share a small `cube_face` helper for the per-face select. ## Measured `victory translate` over the Xbox 1.0.2.1 shader containers (26,503 containers, 26,084 programs), #73's head against this branch: | | #73 | this branch | |---|---|---| | Vertex and pixel programs emitted (of 14,001) | 12,316 | 12,341 | | "a cube sample with texel coordinates, gradients or a level query" | 27 | 0 | No other category got worse; "a cross-lane operation outside compute" goes 48 → 50 because two programs now get further. The corpus has 52 `image_sample_d` and 248 `image_sample_d_cl` on cubes, none with `a16`. ## Tested - Cross-built for `x86_64-pc-windows-msvc` on Linux and run under Proton 10 (vkd3d-proton), RTX 5090. - `cargo test -p victory-shader`: all pass except `stub_pipeline_is_created`, which also fails on unmodified `main` under Proton (vkd3d-proton accepts the zero digest). - Current `main` + #73 + this commit merges cleanly, builds, and passes the same tests. - A host pipeline was created from 14 of the newly emitted programs, one at a time, under vkd3d-proton. ## Not tested: a Windows run, please I have no Windows build of this yet, so two things are unchecked: 1. `victory translate --validate` with `dxil.dll` on the newly emitted programs. 2. **The picture.** The gradient conversion is derived from `cube_direction`, not confirmed against the console's output. If someone on Windows can look at a cube-lit surface or reflection in the title with this branch, that would settle it. A wrong sign or scale would show as the wrong mip level (too blurry or too sharp) rather than a crash. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
In GFX10/RDNA2 MIMG instructions with a16=1, offset (_o), bias (_b) and z-compare (_c) remain full 32-bit VGPRs at the start of vaddr, while gradients, coordinates, LOD and clamp are packed in 16-bit pairs starting after them (matching gfx10::fields::image_addr_dwords).

- Split address reading into full 32-bit prefix VGPRs and a16-packed trailing components, removing the a16+image_sample_b bailout.
- Support _cl LOD-clamp variants (image_sample_cl, image_sample_b_cl, image_sample_d_cl, image_sample_c_cl) by passing the trailing clamp component to DXIL's clamp parameter.
- Check unsupported cube sample modes before reading coordinates so cube gradient samples report the right error instead of an out-of-bounds address.
A cube image's explicit gradients are those of its two face coordinates,
so image_sample_d and image_sample_d_cl carry two per direction there,
not three. cube_direction is linear in the face coordinates, so the
gradients of the direction the host wants are twice each, signed per
face, and zero along the face's own axis.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A hand-built pixel program (two table descriptors, one MIMG, an export)
goes through every stage to DXIL for image_sample_d and
image_sample_d_cl on a 2D image and on a cube. Without the cube support
it stops at the cube case with the old refusal.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:48 +00:00
github-bot closed this pull request 2026-11-26 03:51:48 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:53 UTC · original

Tested 492e948 on Arch Linux x86_64, rustc 1.98.1: cargo test -p victory-shader: 51 passed, 0 failed (2 test binaries). The full workspace still needs #112 for the victory-gpu E0425.

The diff adds no test for the cube gradient samples, so this only shows the existing shader suite stays green; a synthetic image_sample_d/gradient case on a cube would cover the new path.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7118547445) Tested `492e948` on **Arch Linux x86_64, rustc 1.98.1**: **`cargo test -p victory-shader`: 51 passed, 0 failed** (2 test binaries). The full workspace still needs #112 for the `victory-gpu` E0425. The diff adds no test for the cube gradient samples, so this only shows the existing shader suite stays green; a synthetic `image_sample_d`/gradient case on a cube would cover the new path. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠ifBars on GitHub · 2026-11-24 00:59 UTC · original

Confirmed the Windows validation and pipeline creation for three pixel shaders seen during first-story rendering on Windows 10 22H2, RTX 3060 Ti, driver 610.88, Agility SDK 620. On our downstream build with #73, all three reached the unsupported cube-gradient case. Adding only 492e948 let all three pass Microsoft dxil.dll (Windows SDK 10.0.26100.0) and create D3D12 pipelines with the translate command's generated vertex shader.

The shader hashes were 2deec721a63fe8a5, 7bdefdfde461f6e3, and ee41ebc3eb3fbbdc. This check covers shader translation and host PSO creation. Visual correctness and frame time were outside the test. AI-assisted with Codex.

**@⁠ifBars** on GitHub · 2026-11-24 00:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7118644304) Confirmed the Windows validation and pipeline creation for three pixel shaders seen during first-story rendering on Windows 10 22H2, RTX 3060 Ti, driver 610.88, Agility SDK 620. On our downstream build with #73, all three reached the unsupported cube-gradient case. Adding only 492e948 let all three pass Microsoft dxil.dll (Windows SDK 10.0.26100.0) and create D3D12 pipelines with the translate command's generated vertex shader. The shader hashes were `2deec721a63fe8a5`, `7bdefdfde461f6e3`, and `ee41ebc3eb3fbbdc`. This check covers shader translation and host PSO creation. Visual correctness and frame time were outside the test. AI-assisted with Codex.
Author
Owner

@⁠LaunchDoesntCode on GitHub · 2026-11-24 01:01 UTC · original

Thanks for the run. Added the synthetic case in ff95daf: gradient_samples_lower_on_planes_and_cubes hand-builds a pixel program (two table descriptors, one MIMG, an export) and takes it through every stage to DXIL for image_sample_d and image_sample_d_cl, each on a 2D image and on a cube.

  • Against #73's head without the cube commit it fails at the cube case with the old refusal ("a cube sample with texel coordinates, gradients or a level query"); with it, all four pass.
  • 800227d merges current main (the lowering tests gained a second helper there; both are kept).
  • cargo test -p victory-shader under Proton 10: 69 passed; the one failure is stub_pipeline_is_created, which fails the same way on main there.

What the test does not show is that the gradients are right, only that the path lowers. The request for a look at a cube-lit surface on Windows still stands.

No game data used. AI-assisted (Claude Code).

**@⁠LaunchDoesntCode** on GitHub · 2026-11-24 01:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7118674723) Thanks for the run. Added the synthetic case in `ff95daf`: `gradient_samples_lower_on_planes_and_cubes` hand-builds a pixel program (two table descriptors, one MIMG, an export) and takes it through every stage to DXIL for `image_sample_d` and `image_sample_d_cl`, each on a 2D image and on a cube. - Against #73's head without the cube commit it fails at the cube case with the old refusal ("a cube sample with texel coordinates, gradients or a level query"); with it, all four pass. - `800227d` merges current `main` (the lowering tests gained a second helper there; both are kept). - `cargo test -p victory-shader` under Proton 10: 69 passed; the one failure is `stub_pipeline_is_created`, which fails the same way on `main` there. What the test does not show is that the gradients are *right*, only that the path lowers. The request for a look at a cube-lit surface on Windows still stands. No game data used. AI-assisted (Claude Code).
Author
Owner

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

Review note on the a16 layout in this PR ("With a16, sampling coordinates, gradients, LOD and clamp are f16"). On GFX10.3 a16 does not make the derivatives 16-bit; only the _g16 opcodes do. LLVM's MC test gfx10_asm_mimg.s has

image_sample_d v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16    ; 5 address dwords

which is four 32-bit derivatives and one dword of packed coordinates. With the derivatives read as packed halves, the coordinates come from the wrong dword. Also, with a16 the bias is an f16 in the low half of its dword (SITargetLowering::lowerImage: "Bias is of type half but occupies full 32-bit"), not an f32.

The decoder on main counts a16 derivatives as packed too (gfx10/fields.rs), so this is easy to inherit; I did in #160 and fixed it there (7265593).

From the documents and synthetic tests only; I have no copy of the title and have not run this on console hardware.

**@⁠r4tedx** on GitHub · 2026-11-24 03:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7120902648) Review note on the a16 layout in this PR ("With a16, sampling coordinates, gradients, LOD and clamp are f16"). On GFX10.3 a16 does not make the derivatives 16-bit; only the `_g16` opcodes do. LLVM's MC test `gfx10_asm_mimg.s` has ``` image_sample_d v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16 ; 5 address dwords ``` which is four 32-bit derivatives and one dword of packed coordinates. With the derivatives read as packed halves, the coordinates come from the wrong dword. Also, with a16 the bias is an f16 in the low half of its dword (`SITargetLowering::lowerImage`: "Bias is of type half but occupies full 32-bit"), not an f32. The decoder on `main` counts a16 derivatives as packed too (`gfx10/fields.rs`), so this is easy to inherit; I did in #160 and fixed it there (`7265593`). From the documents and synthetic tests only; I have no copy of the title and have not run this on console hardware.
Author
Owner

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

I ran a Windows pixel readback on exact head 800227d, with an original six-face cube and four mip levels. On both RTX 5090 and WARP, all 32 lanes for image_sample_d and all 32 for image_sample_d_cl matched native HLSL TextureCube.SampleGrad. The native outputs also matched an independent expected face/mip selection for every lane.

The probe covers ordinary-precision face-center samples, both in-face gradient axes, and several minimum-LOD values. It validates face and mip selection in this fixture.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 11:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7129679192) I ran a Windows pixel readback on exact head `800227d`, with an original six-face cube and four mip levels. On both RTX 5090 and WARP, all 32 lanes for `image_sample_d` and all 32 for `image_sample_d_cl` matched native HLSL `TextureCube.SampleGrad`. The native outputs also matched an independent expected face/mip selection for every lane. The probe covers ordinary-precision face-center samples, both in-face gradient axes, and several minimum-LOD values. It validates face and mip selection in this fixture.

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