Shaders: lower gradient samples with an offset and LOD clamp #3493

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3493 into main
andrewpozdnakov7-jpg commented 2026-11-27 09:47:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T09:47:56Z.


image_sample_d_cl_o already decodes, but main refuses it during lowering. Route it to DXIL sampleGrad, use the existing immediate-offset encoding, and take the LOD clamp after the gradient and coordinate operands. The current SM 6.6 path uses immediate offsets from -8 through 7. Cube gradient samples with an offset report an unsupported operation. Texture2D SampleGrad

The synthetic regression samples a texture whose texels encode mip, row and column. Four dispatch cases combine mip 0 or mip 2 with zero offset or (+1, -1). All 32 lanes write to their own output dword. On 63bcca4 the test stops at the unsupported opcode. On the patch, WARP reads the expected values 294, 263, 2066 and 2035 respectively.

All 36 VALU tests and all 33 lowerer tests passed on the final commit. Strict shader Clippy passed with default and all features. Asset policy and git diff checks passed.

Independent testing on RTX 4090 Laptop (driver 621.14) and WARP passed all 32 lanes in each of ten dispatches on 48e796a, including offsets −8 and +7 and additional LOD clamps. The RX 5700 XT run on the combined follow-up 102b5c2 also passed all 16 cases. RTX and WARP report · RX 5700 XT report

Related work on other sample and gather offset forms is in #1687. Synthetic textures and shaders only. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5524544666 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3493). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T09:47:56Z. --- `image_sample_d_cl_o` already decodes, but `main` refuses it during lowering. Route it to DXIL `sampleGrad`, use the existing immediate-offset encoding, and take the LOD clamp after the gradient and coordinate operands. The current SM 6.6 path uses immediate offsets from -8 through 7. Cube gradient samples with an offset report an unsupported operation. [Texture2D SampleGrad](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/texture2d-samplegrad) The synthetic regression samples a texture whose texels encode mip, row and column. Four dispatch cases combine mip 0 or mip 2 with zero offset or (+1, -1). All 32 lanes write to their own output dword. On `63bcca4` the test stops at the unsupported opcode. On the patch, WARP reads the expected values 294, 263, 2066 and 2035 respectively. All 36 VALU tests and all 33 lowerer tests passed on the final commit. Strict shader Clippy passed with default and all features. Asset policy and git diff checks passed. Independent testing on RTX 4090 Laptop (driver 621.14) and WARP passed all 32 lanes in each of ten dispatches on `48e796a`, including offsets −8 and +7 and additional LOD clamps. The RX 5700 XT run on the combined follow-up `102b5c2` also passed all 16 cases. [RTX and WARP report](https://github.com/Marvisak/VIctory/pull/3493#issuecomment-7226033582) · [RX 5700 XT report](https://github.com/Marvisak/VIctory/pull/3493#issuecomment-7222302414) Related work on other sample and gather offset forms is in #1687. Synthetic textures and shaders only. AI-assisted with Codex.
oddmaniv commented 2026-11-27 10:09:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oddmaniv on 2026-11-27T10:09:04Z.


Independent verification of the PR author's concurrent WARP pipeline/draw test at 48e796ad3672d629050fba765e73baef68dc9e8c.

cargo test --locked -p victory-shader --lib emit::host::tests::parallel_warp_pipelines_and_draws -- --exact --nocapture

Tree Result
Unmodified PR head 1 passed, 0 failed, 0 ignored; native exit 0
Unmodified main 1 passed, 0 failed, 0 ignored; native exit 0
PR patch applied to pinned main 1 passed, 0 failed, 0 ignored; native exit 0

Main baseline pin: 63bcca43c6a00a758510398fa43096ce7e4f7df0.

Windows x86_64 MSVC native runs. Local and remote source snapshots matched before and after each check. The adaptation applies the PR diff without additional source edits.
This is focused regression coverage, not the full workspace suite, a gameplay test, or an independent validation of every behavior in the PR. No new fix is claimed.

AI-assisted verification.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7215535040 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3493#issuecomment-7215535040). Originally posted by [oddmaniv](https://github.com/oddmaniv) on 2026-11-27T10:09:04Z. --- Independent verification of the PR author's concurrent WARP pipeline/draw test at `48e796ad3672d629050fba765e73baef68dc9e8c`. `cargo test --locked -p victory-shader --lib emit::host::tests::parallel_warp_pipelines_and_draws -- --exact --nocapture` | Tree | Result | | --- | --- | | Unmodified PR head | 1 passed, 0 failed, 0 ignored; native exit 0 | | Unmodified main | 1 passed, 0 failed, 0 ignored; native exit 0 | | PR patch applied to pinned main | 1 passed, 0 failed, 0 ignored; native exit 0 | Main baseline pin: `63bcca43c6a00a758510398fa43096ce7e4f7df0`. Windows x86_64 MSVC native runs. Local and remote source snapshots matched before and after each check. The adaptation applies the PR diff without additional source edits. This is focused regression coverage, not the full workspace suite, a gameplay test, or an independent validation of every behavior in the PR. No new fix is claimed. AI-assisted verification.
andrewpozdnakov7-jpg commented 2026-11-27 12:52:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T12:52:47Z.


I tested #3493 together with #1687, #1256 and #2372 on current main (63bcca4). The merge resolution at 102b5c2 preserves all four PR heads. It reads the offset from a whole VGPR and locates the LOD clamp after the independently packed gradients and coordinates. Both cube and cube-array gradient samples with an offset stop during translation.

The expanded 2D fixture fails on main with image_sample_d_cl_o unsupported. On the combined tree, app-local WARP 1.0.22 passed all 16 cases, checking all 32 lane writes per case. The matrix covers a16 and _g16 independently, offsets (0, 0) and (1, -1), and minimum LODs 0 and 2. The #1687 comparison-gather checks and #1256/#2372 cube readbacks also passed.

Full shader suite on the combined tree: 333 passed, 4 failed, 3 ignored. Each of those four failures also occurs on main in the same WARP setup. All-target/all-feature shader Clippy with warnings denied and the asset policy passed.

If folding the added regression or the merge resolution into another commit, please retain Git authorship or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted with Codex. All shaders and textures were synthetic.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218785421 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3493#issuecomment-7218785421). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T12:52:47Z. --- I tested #3493 together with #1687, #1256 and #2372 on current main (63bcca4). [The merge resolution at 102b5c2](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/packed-gradient-offset-composition) preserves all four PR heads. It reads the offset from a whole VGPR and locates the LOD clamp after the independently packed gradients and coordinates. Both cube and cube-array gradient samples with an offset stop during translation. The expanded 2D fixture fails on main with `image_sample_d_cl_o` unsupported. On the combined tree, app-local WARP 1.0.22 passed all 16 cases, checking all 32 lane writes per case. The matrix covers `a16` and `_g16` independently, offsets (0, 0) and (1, -1), and minimum LODs 0 and 2. The #1687 comparison-gather checks and #1256/#2372 cube readbacks also passed. Full shader suite on the combined tree: 333 passed, 4 failed, 3 ignored. Each of those four failures also occurs on main in the same WARP setup. All-target/all-feature shader Clippy with warnings denied and the asset policy passed. If folding the added regression or the merge resolution into another commit, please retain Git authorship or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted with Codex. All shaders and textures were synthetic.
ColorMeBoom commented 2026-11-27 15:07:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T15:07:00Z.


AMD hardware run: RX 5700 XT (RDNA1), driver 32.0.21045.29003, Windows 11 26200, Rust 1.98.1. Head 48e796a merged onto main 63bcca4, no game files. So far this PR has only WARP reports.

  • gradient_samples_apply_the_offset_at_the_clamped_mip passes on the hardware adapter and on WARP. Neither printed a skip, so both ran the per-clamp assert_eq! over all 32 lanes.
  • Full victory-shader suite (--features host): 303 passed, 0 failed, 3 ignored. cargo clippy -p victory-shader --all-targets --features host -- -D warnings: clean.

This is the PR alone. @andrewpozdnakov7-jpg's combined branch with #1687, #1256 and #2372 wasn't run here.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7221644940 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3493#issuecomment-7221644940). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T15:07:00Z. --- **AMD hardware run: RX 5700 XT** (RDNA1), driver 32.0.21045.29003, Windows 11 26200, Rust 1.98.1. Head `48e796a` merged onto `main` `63bcca4`, no game files. So far this PR has only WARP reports. - `gradient_samples_apply_the_offset_at_the_clamped_mip` **passes on the hardware adapter and on WARP**. Neither printed a skip, so both ran the per-clamp `assert_eq!` over all 32 lanes. - Full `victory-shader` suite (`--features host`): **303 passed, 0 failed, 3 ignored**. `cargo clippy -p victory-shader --all-targets --features host -- -D warnings`: clean. This is the PR alone. @andrewpozdnakov7-jpg's combined branch with #1687, #1256 and #2372 wasn't run here. AI use: Claude Code (Claude Opus 5.5).
andrewpozdnakov7-jpg commented 2026-11-27 15:31:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T15:31:44Z.


Thanks @ColorMeBoom for checking 48e796a on the RX 5700 XT. The expanded case is in 102b5c2 under the same test name. If you have time for one more synthetic run on that card, please try cargo test --locked -p victory-shader --lib --features host gradient_samples_apply_the_offset_at_the_clamped_mip -- --nocapture. It checks all four coordinate/gradient packing combinations at two offsets and two clamped mip levels. Those 16 cases have passed on WARP here. Your run above covers the original PR fixture.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7222166966 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3493#issuecomment-7222166966). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T15:31:44Z. --- Thanks @ColorMeBoom for checking `48e796a` on the RX 5700 XT. The expanded case is in [`102b5c2`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/102b5c2fd805a062c9227e799fa357b6da2f6f0e) under the same test name. If you have time for one more synthetic run on that card, please try `cargo test --locked -p victory-shader --lib --features host gradient_samples_apply_the_offset_at_the_clamped_mip -- --nocapture`. It checks all four coordinate/gradient packing combinations at two offsets and two clamped mip levels. Those 16 cases have passed on WARP here. Your run above covers the original PR fixture.
ColorMeBoom commented 2026-11-27 15:38:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T15:38:23Z.


@andrewpozdnakov7-jpg ran it: 102b5c2 as is (it already contains main 63bcca4), on the same RX 5700 XT, with VICTORY_WARP unset.

  • cargo test --locked -p victory-shader --lib --features host gradient_samples_apply_the_offset_at_the_clamped_mip -- --nocapture: passed. Neither adapter printed a skip, so all 16 cases (4 coordinate/gradient packings × 2 offsets × 2 clamped mips) were checked on the hardware adapter and on WARP.
  • Full victory-shader suite on that tree (--features host): 337 passed, 0 failed, 3 ignored. cargo clippy -p victory-shader --all-targets --features host -- -D warnings: clean.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7222302414 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3493#issuecomment-7222302414). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T15:38:23Z. --- @andrewpozdnakov7-jpg ran it: [`102b5c2`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/102b5c2fd805a062c9227e799fa357b6da2f6f0e) as is (it already contains `main` `63bcca4`), on the same RX 5700 XT, with `VICTORY_WARP` unset. - `cargo test --locked -p victory-shader --lib --features host gradient_samples_apply_the_offset_at_the_clamped_mip -- --nocapture`: **passed**. Neither adapter printed a skip, so all 16 cases (4 coordinate/gradient packings × 2 offsets × 2 clamped mips) were checked on the hardware adapter and on WARP. - Full `victory-shader` suite on that tree (`--features host`): **337 passed, 0 failed, 3 ignored**. `cargo clippy -p victory-shader --all-targets --features host -- -D warnings`: clean. AI use: Claude Code (Claude Opus 5.5).
passerbyyhx commented 2026-11-27 18:56:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-27T18:56:53Z.


Windows synthetic verification at 48e796ad3672d629050fba765e73baef68dc9e8c.

On RTX 4090 Laptop (621.14) and WARP I read every lane of ten dispatches using the production shader lowering. All 32 lanes in each dispatch matched. The original four words were 294, 263, 2066 and 2035. On an interior coordinate the independent cases held the gradients fixed, changed the LOD clamp and exercised both immediate offset endpoints (−8 and +7). The three LOD pairs returned 4762/12317, 5650/13205 and 3745/11300 on both adapters. No debug-layer errors in the measured dispatches. Parent 63bcca43c6a00a758510398fa43096ce7e4f7df0 declined this opcode during lowering at guest offset 104.

Reproducible fixture. GTA-VI-3/EIGHT-20261127. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226033582 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3493#issuecomment-7226033582). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-27T18:56:53Z. --- Windows synthetic verification at `48e796ad3672d629050fba765e73baef68dc9e8c`. On RTX 4090 Laptop (621.14) and WARP I read every lane of ten dispatches using the production shader lowering. All 32 lanes in each dispatch matched. The original four words were 294, 263, 2066 and 2035. On an interior coordinate the independent cases held the gradients fixed, changed the LOD clamp and exercised both immediate offset endpoints (−8 and +7). The three LOD pairs returned 4762/12317, 5650/13205 and 3745/11300 on both adapters. No debug-layer errors in the measured dispatches. Parent `63bcca43c6a00a758510398fa43096ce7e4f7df0` declined this opcode during lowering at guest offset 104. [Reproducible fixture](https://github.com/passerbyyhx/VIctory/commit/86a23c08e44c6da0e722e74d2018a8672a54d6d5). GTA-VI-3/EIGHT-20261127. AI-assisted with Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3493:upstream-pr/3493'
git switch 'upstream-pr/3493'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3493'
git switch 'upstream-pr/3493'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3493'
git switch 'upstream-pr/3493'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3493'
git switch 'main'
git merge --squash 'upstream-pr/3493'
git switch 'main'
git merge --ff-only 'upstream-pr/3493'
git switch 'main'
git merge 'upstream-pr/3493'
git push origin 'main'
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!3493
No description provided.