Skip to content

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

Open
kilolimaVI wants to merge 4 commits into
Marvisak:mainfrom
kilolimaVI:tests/quad-reads-without-console-dxc
Open

kilolimaVI wants to merge 4 commits into
Marvisak:mainfrom
kilolimaVI:tests/quad-reads-without-console-dxc

Conversation

@kilolimaVI

@kilolimaVI kilolimaVI commented Nov 27, 2026 •

Copy link
Copy Markdown

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

kilolimaVI and others added 2 commits November 27, 2026 21:02
flow_tests draws the derivative and quad-read cases from console-compiled
HLSL, so it needs the console SDK's dxc.exe and most machines skip it.
quad_read_tests hand-assembles the same shapes: each pixel computes a key
from its position and reads its x, y and diagonal neighbours' keys with
DPP quad_perm, on a triangle whose edge crosses quads (helper lanes), and
again after the console's form of a discard (v_cmpx, s_andn2 of the live
mask, s_cbranch_scc0 to a null export, s_wqm), whose killed pixels stay
helpers and must not be written. wave32 and wave64, hardware and WARP.

Radeon 780M (RDNA3) and WARP at 63bcca4: edge 136 pixels, discard 104,
0 wrong in all eight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lod_tests takes image_get_lod of coordinates linear in the pixel position
(u = 0.3 x, v = 0.11 y of a 16x16 texture, so log2(4.8) at every pixel)
next to a triangle edge and next to pixels the console's form of a discard
killed: their helper lanes must compute the coordinates the derivatives
take. wave32 and wave64, hardware and WARP, tolerance 0.02 of a level.

Radeon 780M (RDNA3): 2.2617 at all 136 / 104 pixels (the level in 1/256
steps); WARP 2.2630; 0 wrong in all eight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pickles976

Copy link
Copy Markdown

Verified exact production/test head c7661dd 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.

A NaN compares false with the tolerance, so it passed; the levels must also
be finite (pointed out by pickles976).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kilolimaVI

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Author

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

gather_tests looks up at t = x + d texels in u and v over a 16x16 texture
whose texels hold their index, with image_gather4_lz (footprint at
floor(t), half a texel back) 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) it reports, without failing, whether
the host rounds t up to x or keeps it below.

Radeon 780M (RDNA3): gathers 256 of 256 round up, point samples 256 of 256
stay below; WARP: both stay below. Exact cases 0 wrong everywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kilolimaVI

Copy link
Copy Markdown
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants