Shaders: gradient samples on cube images #138

Closed
LaunchDoesntCode wants to merge 4 commits from upstream-pr/138 into main
LaunchDoesntCode commented 2026-11-24 00:51:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LaunchDoesntCode on 2026-11-24T00:51:23Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572065431 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/138). Originally posted by [LaunchDoesntCode](https://github.com/LaunchDoesntCode) on 2026-11-24T00:51:23Z. --- **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)
DaviTostes commented 2026-11-24 06:54:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:53:49Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118547445 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7118547445). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:53:49Z. --- 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).
ifBars commented 2026-11-24 06:54:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ifBars on 2026-11-24T00:59:37Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118644304 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7118644304). Originally posted by [ifBars](https://github.com/ifBars) on 2026-11-24T00:59:37Z. --- 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.
LaunchDoesntCode commented 2026-11-24 06:54:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LaunchDoesntCode on 2026-11-24T01:01:27Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118674723 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7118674723). Originally posted by [LaunchDoesntCode](https://github.com/LaunchDoesntCode) on 2026-11-24T01:01:27Z. --- 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).
r4tedx commented 2026-11-24 06:55:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T03:14:24Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120902648 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7120902648). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-24T03:14:24Z. --- 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.
fuzeofficlal commented 2026-11-24 12:04:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T11:07:07Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129679192 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/138#issuecomment-7129679192). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T11:07:07Z. --- 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.
upstream-sync closed this pull request 2026-11-24 23:03:55 +00:00

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