Shaders: quad reads at a triangle edge without the console's compiler #3583

Open
kilolimaVI wants to merge 4 commits from upstream-pr/3583 into main
kilolimaVI commented 2026-11-27 19:02:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T19:02:31Z.


flow_tests and diff_tests draw the derivative, quad-read and level-of-detail cases (including the triangle-edge ones from 4015a18) from console-compiled HLSL, so they need the console SDK's dxc.exe, and most contributors' machines skip them silently. This adds hand-assembled versions that run anywhere.

Quad reads (emit/quad_read_tests.rs)

quad_reads_at_a_triangle_edge_reach_helpers_and_killed_pixels: each pixel computes a key from its position and reads its x, y and diagonal neighbours' keys with DPP quad_perm ([1,0,3,2], [2,3,0,1], [3,2,1,0]), as the console compiler takes ddx_fine/ddy_fine and QuadReadAcross*. Drawn as a triangle whose edge crosses quads (16x16):

  • edge: neighbours outside the triangle are helper lanes and must give their key.
  • discard: the console's form (v_cmpx of the killed lanes, s_andn2 of the live mask, s_cbranch_scc0 to a null export, s_wqm of the live mask). Killed pixels stay helpers: their neighbours read their keys, and they must not be written.

Levels of detail (emit/lod_tests.rs)

levels_of_detail_at_a_triangle_edge_and_after_a_discard: image_get_lod of coordinates linear in the pixel position (u = 0.3 x, v = 0.11 y on a 16x16 texture, so log2(4.8) = 2.2630 everywhere), next to the same edge and after the same discard, so the helper lanes must compute the coordinates the derivatives take. Tolerance 0.02 of a level.

Results at main 63bcca4

Both in wave32 and wave64, on the hardware adapter and WARP:

Radeon 780M (RDNA3) WARP
quad reads, edge (136 px) / discard (104 px) 0 wrong / 0 wrong 0 wrong / 0 wrong
level of detail, edge / discard 2.2617 at every pixel (1/256 steps), 0 wrong 2.2630, 0 wrong

(Before 4015a18 the edge case is where an RX 6700 XT read 0 from helpers.)

Only the two new files and their mod lines; no change in behaviour. Clippy clean with default and all features.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:issue:5531761185 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3583). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T19:02:31Z. --- `flow_tests` and `diff_tests` draw the derivative, quad-read and level-of-detail cases (including the triangle-edge ones from 4015a18) from console-compiled HLSL, so they need the console SDK's `dxc.exe`, and most contributors' machines skip them silently. This adds hand-assembled versions that run anywhere. ## Quad reads (`emit/quad_read_tests.rs`) `quad_reads_at_a_triangle_edge_reach_helpers_and_killed_pixels`: each pixel computes a key from its position and reads its x, y and diagonal neighbours' keys with DPP `quad_perm` (`[1,0,3,2]`, `[2,3,0,1]`, `[3,2,1,0]`), as the console compiler takes `ddx_fine`/`ddy_fine` and `QuadReadAcross*`. Drawn as a triangle whose edge crosses quads (16x16): - **edge**: neighbours outside the triangle are helper lanes and must give their key. - **discard**: the console's form (`v_cmpx` of the killed lanes, `s_andn2` of the live mask, `s_cbranch_scc0` to a null export, `s_wqm` of the live mask). Killed pixels stay helpers: their neighbours read their keys, and they must not be written. ## Levels of detail (`emit/lod_tests.rs`) `levels_of_detail_at_a_triangle_edge_and_after_a_discard`: `image_get_lod` of coordinates linear in the pixel position (`u = 0.3 x`, `v = 0.11 y` on a 16x16 texture, so log2(4.8) = 2.2630 everywhere), next to the same edge and after the same discard, so the helper lanes must compute the coordinates the derivatives take. Tolerance 0.02 of a level. ## Results at main 63bcca4 Both in wave32 and wave64, on the hardware adapter and WARP: | | Radeon 780M (RDNA3) | WARP | |---|---|---| | quad reads, edge (136 px) / discard (104 px) | 0 wrong / 0 wrong | 0 wrong / 0 wrong | | level of detail, edge / discard | 2.2617 at every pixel (1/256 steps), 0 wrong | 2.2630, 0 wrong | (Before 4015a18 the edge case is where an RX 6700 XT read 0 from helpers.) Only the two new files and their `mod` lines; no change in behaviour. Clippy clean with default and all features. AI-assisted (Claude).
pickles976 commented 2026-11-27 19:31:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-27T19:31:31Z.


Verified exact production/test head c7661dd85c on a physical RTX 4060 Laptop under Linux/Wine. This is the updated triangle-edge LOD head, not earlier 2169264.

Linux 6.17, i7-13620H/16 GiB, RTX 4060 Laptop 8 GiB/NVIDIA 590.48.1, Wine 11.0, diagnostic-relaxed-vtable vkd3d-proton 2576c0b4adfae4a+ (not stock certification), DXVK NVIDIA masking disabled. Local edits are test-only: mandatory SDK DXIL validator and non-software NVIDIA/dedicated-VRAM checks, removal of duplicate Wine-WARP legs, full coverage counters, and explicit finite-value checks for both LOD outputs (NaN must not pass tolerance comparisons). Owner instructions and expected values unchanged.

cargo-victory-wine.sh test -p victory-shader --features host --lib triangle_edge -- --nocapture --test-threads=1

2/2 pass, zero ignored, 1.39 s after fresh intended-worktree compilation 5.90 s. Both quad-neighbour and LOD tests execute wave32/wave64 x edge/discard: 8 hardware draws, 10 mandatory shader validations, 2048 pixel slots inspected. Each test has 136 drawn pixels per edge case and 104 per discard case, 480 drawn pixels total, zero wrong. Quad checks 2464 scalar components; LOD checks 1984 (4448 combined). LOD expected unclamped 2.2630, actual 2.2656 in all four cases within the owner's 0.02 tolerance; clamped output 0.

Evidence: .compat-runtime/logs/verify-verify-victory3583-triangle-edge-20261127T192814Z/{console.log,result.json,command.json,resources.jsonl}. Sampled GPU peak147 MiB, available RAM minimum11227 MiB, disk minimum12.145 GiB; guards unchanged.

These are synthetic helper/discard/derivative pixel oracles, not native 64-lane hardware, WARP coverage, a matched-parent regression result, or retail rendering/FPS proof. No production lowering modified and no title launched.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226612703 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3583#issuecomment-7226612703). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-27T19:31:31Z. --- Verified exact production/test head c7661dd85c22dde106147c3bc22b0ed37a9b97b5 on a physical RTX 4060 Laptop under Linux/Wine. This is the updated triangle-edge LOD head, not earlier 2169264. Linux 6.17, i7-13620H/16 GiB, RTX 4060 Laptop 8 GiB/NVIDIA 590.48.1, Wine 11.0, diagnostic-relaxed-vtable vkd3d-proton 2576c0b4adfae4a+ (not stock certification), DXVK NVIDIA masking disabled. Local edits are test-only: mandatory SDK DXIL validator and non-software NVIDIA/dedicated-VRAM checks, removal of duplicate Wine-WARP legs, full coverage counters, and explicit finite-value checks for both LOD outputs (NaN must not pass tolerance comparisons). Owner instructions and expected values unchanged. cargo-victory-wine.sh test -p victory-shader --features host --lib triangle_edge -- --nocapture --test-threads=1 2/2 pass, zero ignored, 1.39 s after fresh intended-worktree compilation 5.90 s. Both quad-neighbour and LOD tests execute wave32/wave64 x edge/discard: 8 hardware draws, 10 mandatory shader validations, 2048 pixel slots inspected. Each test has 136 drawn pixels per edge case and 104 per discard case, 480 drawn pixels total, zero wrong. Quad checks 2464 scalar components; LOD checks 1984 (4448 combined). LOD expected unclamped 2.2630, actual 2.2656 in all four cases within the owner's 0.02 tolerance; clamped output 0. Evidence: .compat-runtime/logs/verify-verify-victory3583-triangle-edge-20261127T192814Z/{console.log,result.json,command.json,resources.jsonl}. Sampled GPU peak147 MiB, available RAM minimum11227 MiB, disk minimum12.145 GiB; guards unchanged. These are synthetic helper/discard/derivative pixel oracles, not native 64-lane hardware, WARP coverage, a matched-parent regression result, or retail rendering/FPS proof. No production lowering modified and no title launched.
kilolimaVI commented 2026-11-27 19:40:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T19:40:45Z.


Thanks, the RTX 4060 numbers are a useful pair with the 780M: NVIDIA rounds the level up to 580/256 (2.2656), RDNA3 down to 579/256 (2.2617), both inside the 0.02 tolerance. And you're right that a NaN compared false and passed; the LOD test now also requires both levels to be finite.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226763759 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3583#issuecomment-7226763759). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T19:40:45Z. --- Thanks, the RTX 4060 numbers are a useful pair with the 780M: NVIDIA rounds the level up to 580/256 (2.2656), RDNA3 down to 579/256 (2.2617), both inside the 0.02 tolerance. And you're right that a NaN compared false and passed; the LOD test now also requires both levels to be finite. AI-assisted (Claude).
kilolimaVI commented 2026-11-27 19:48:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T19:48:25Z.


Added a third test, gather_tests::gathers_take_the_footprint_at_the_coordinate: image_gather4_lz at t = x + d texels over a 16x16 texture whose texels hold their index. At d 0.25 and 0.75 the footprint must start at floor(t); just below a boundary (d = -1/1024) it only reports which way the host rounds.

d Radeon 780M (RDNA3) WARP
+0.25, +0.75 256/256 at floor(t) 256/256 at floor(t)
-1/1024 256/256 rounded up to x 256/256 kept below (x - 1)

So RDNA3 snaps the coordinate to 8 fractional bits as the console's hardware does, and WARP doesn't: near texel boundaries a gather (GatherRed, GatherCmp for PCF) takes different texels on the two. @pickles976 if you have a minute, the NVIDIA number for the -1/1024 row would complete the picture:
cargo test -p victory-shader --lib gathers_take_the_footprint -- --nocapture

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226889199 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3583#issuecomment-7226889199). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T19:48:25Z. --- Added a third test, `gather_tests::gathers_take_the_footprint_at_the_coordinate`: `image_gather4_lz` at `t = x + d` texels over a 16x16 texture whose texels hold their index. At d 0.25 and 0.75 the footprint must start at `floor(t)`; just below a boundary (d = -1/1024) it only reports which way the host rounds. | d | Radeon 780M (RDNA3) | WARP | |---|---|---| | +0.25, +0.75 | 256/256 at floor(t) | 256/256 at floor(t) | | -1/1024 | 256/256 rounded up to x | 256/256 kept below (x - 1) | So RDNA3 snaps the coordinate to 8 fractional bits as the console's hardware does, and WARP doesn't: near texel boundaries a gather (`GatherRed`, `GatherCmp` for PCF) takes different texels on the two. @pickles976 if you have a minute, the NVIDIA number for the -1/1024 row would complete the picture: `cargo test -p victory-shader --lib gathers_take_the_footprint -- --nocapture` AI-assisted (Claude).
kilolimaVI commented 2026-11-27 19:51:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T19:51:43Z.


Added gather_tests: lookups at t = x + d texels over a 16x16 texture whose texels hold their index, with image_gather4_lz (footprint at floor(t)) and image_sample_lz with a point sampler (texel at floor(t)). At d 0.25 and 0.75 every host must take floor(t); just below a boundary (d = -1/1024) the test only reports which way the host rounds.

d = -1/1024 Radeon 780M (RDNA3) WARP
gather 256/256 rounded up to x 256/256 kept below (x - 1)
point sample 256/256 kept below 256/256 kept below

The exact cases are 0 wrong on both. So RDNA3 snaps a gather's coordinate more coarsely than a point sample's (it rounds up from 1/1024 below), and WARP doesn't: near texel boundaries a gather (GatherRed, GatherCmp for PCF) takes different texels on the two, while point samples agree. @pickles976 if you have a minute, the NVIDIA row would complete the picture:
cargo test -p victory-shader --lib -- gathers_take_the_footprint point_samples_take_the_texel --nocapture --test-threads=1

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226941625 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3583#issuecomment-7226941625). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T19:51:43Z. --- Added `gather_tests`: lookups at `t = x + d` texels over a 16x16 texture whose texels hold their index, with `image_gather4_lz` (footprint at floor(t)) and `image_sample_lz` with a point sampler (texel at floor(t)). At d 0.25 and 0.75 every host must take floor(t); just below a boundary (d = -1/1024) the test only reports which way the host rounds. | d = -1/1024 | Radeon 780M (RDNA3) | WARP | |---|---|---| | gather | 256/256 rounded up to x | 256/256 kept below (x - 1) | | point sample | 256/256 kept below | 256/256 kept below | The exact cases are 0 wrong on both. So RDNA3 snaps a gather's coordinate more coarsely than a point sample's (it rounds up from 1/1024 below), and WARP doesn't: near texel boundaries a gather (`GatherRed`, `GatherCmp` for PCF) takes different texels on the two, while point samples agree. @pickles976 if you have a minute, the NVIDIA row would complete the picture: `cargo test -p victory-shader --lib -- gathers_take_the_footprint point_samples_take_the_texel --nocapture --test-threads=1` AI-assisted (Claude).
kilolimaVI commented 2026-11-27 21:17:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T21:17:35Z.


Follow-up for the gather numbers: #3613 fixes the boundary case this PR's gather_tests reports. It moves the first-level gather coordinate to the middle of the console's footprint (same rule as gather_first), and the test now requires the console's result on every host.

On the 780M + WARP: before, WARP took the footprint one texel back at 1/1024 and at the 1/512 tie below an edge; after, both hosts are 256/256 in all six cases.

@pickles976 if you still have the 4060 set up, the most useful run is on #3613's branch:
cargo test -p victory-shader --lib -- gather_tests --nocapture
The gather d ... lines show which way NVIDIA goes before and after.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7228312154 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3583#issuecomment-7228312154). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T21:17:35Z. --- Follow-up for the gather numbers: #3613 fixes the boundary case this PR's `gather_tests` reports. It moves the first-level gather coordinate to the middle of the console's footprint (same rule as `gather_first`), and the test now requires the console's result on every host. On the 780M + WARP: before, WARP took the footprint one texel back at 1/1024 and at the 1/512 tie below an edge; after, both hosts are 256/256 in all six cases. @pickles976 if you still have the 4060 set up, the most useful run is on #3613's branch: `cargo test -p victory-shader --lib -- gather_tests --nocapture` The `gather d ...` lines show which way NVIDIA goes before and after. AI-assisted (Claude).
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/3583:upstream-pr/3583'
git switch 'upstream-pr/3583'

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