Repository navigation
Shaders: gathers from the first level take the console's footprint - #3613
kilolimaVI wants to merge 6 commits into
Conversation
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>
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>
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>
image_gather4_lz(_o) went to DXIL textureGather with the program's coordinate, so which four texels a gather took near a texel's edge was the host's choice. The console rounds u x size to 1/256 of a texel, half up, before taking floor(u x size - 0.5), the rule gather_first already implements for gathers at a level. Hosts differ: 1/1024 of a texel below an edge, the Radeon 780M rounds up as the console does and WARP stays below, taking the footprint one texel back. The coordinate along each axis is now moved to (first + 1) / size, the middle of the console's footprint, with first from gather_first: half a texel from either edge, so every host takes the same four texels in any address mode. NaN takes the footprint at 0, as on the console; beyond +-2 (where gather_first clamps) and at infinities the coordinate is kept. Cubes are left as they were. The helper lives in lower/gather.rs to keep lower.rs under the file size limit. gather_tests now requires the console's footprint on every host: 1/1024 and the tie of 1/512 below an edge round up, 1/512 + 1/65536 and 3/1024 stay below. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@kilolimaVI I reproduced the 16×16 case on app-local WARP, with the loaded SDK and WARP modules verified. At the two offsets closest to the texel boundary, I also checked a 13×13 texture with two wrapped tile edges and three border-mode cases. All 845 readbacks matched on both revisions with this WARP runtime. I put those two checks in a test-only commit on top of your exact head. Both strict shader Clippy configurations and the asset policy check passed. Test commit If reusing the tests, please retain the Git author when cherry-picking or rebasing. If folding them into another commit, please add the trailer below. Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com |
|
Hardware run on AMD RDNA1, to go with the 780M and RTX 4060 runs on #3583: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head
AI use: Claude Code (Claude Opus 5.5). |
|
For the open question about NVIDIA near the 1/256-texel footprint boundary, I published a PortBridge Lab task pinned to |
|
The NVIDIA row, as asked: RTX 3070 8 GB, driver 616.56, Windows 11, the hardware adapter and WARP in the same run.
"—": that offset is not in the test at #3583's head. So before this PR, NVIDIA's own gather rounds up at -1/1024 like the 780M, and WARP doesn't. With this PR, the RTX 3070 and WARP agree at every offset and follow the rule in the test: 1/1024 and the 1/512 tie round up to AI-assisted (Claude Code, Claude Opus 5.5 built both heads and ran the tests on this card). |
|
Thanks all. @andrewpozdnakov7-jpg's test commit is now on this branch as-is, with his authorship (head 780M (RDNA3) + WARP on
Full suite 557 passed, clippy clean. Like Andrew saw, WARP already lands on the console's footprint at 13×13 (the 1/13 coordinate is not exact), so these two tests don't catch the old behaviour. What they guard is that All results so far:
So every hardware adapter tested so far already rounds like the console. The change makes WARP agree, and it removes the dependency on the host's sampler precision for anything not tested yet. AI-assisted (Claude). |
|
NVIDIA row for
The "before" failure here comes from WARP. At offsets -0.000977 and -0.001953 the 3070 already gives the console's footprint with main's code ( AI-assisted (Claude Code, Claude Opus 5.5). |
|
@upipibi @JurajSimicevic one more NVIDIA check that may be worth a minute, since you both reported That test does three gathers per lane: two This PR moves the
If it passes there and fails on main, that's an existing test fixed on NVIDIA. If it still fails, the panic line (which lane, which assertion) would tell me what's left. AI-assisted (Claude). |
|
@kilolimaVI it still fails at
AI use: Claude Code (Claude Opus 5.5) ran the tests and the probe and wrote this. |
image_gather4_lz(_o)goes to DXILtextureGatherwith the program's coordinate, so near a texel's edge the host decides which four texels a gather takes. The console roundsu × sizeto 1/256 of a texel, half up, before takingfloor(u × size − 0.5).Lower::gather_firstalready implements this rule for gathers at a level (gather_at_level), but the first-level path never used it.Hosts differ here. At 1/1024 of a texel below an edge, the Radeon 780M rounds up like the console, while WARP stays below and takes the footprint one texel back.
Change
lower/gather.rs:gather_console_coordinatemoves each axis to(first + 1) / size, withfirstfromgather_first. That is the middle of the console's footprint, half a texel from either edge, so every host takes the same four texels in any address mode or border.gather_firstclamps) and at infinities the coordinate is left unchanged. Cubes are left as they were.lower.rsgains 15 lines (521,359 / 524,288 bytes).gather_tests(from Shaders: quad reads at a triangle edge without the console's compiler #3583) now requires the console's footprint on every host. It used to only report the boundary case.Builds on #3583. The first four commits are #3583's; the change itself is the last commit.
Results, AMD Radeon 780M (RDNA3) + WARP, Windows 11:
256/256 pixels per case per host after the change. 5 of 5 runs, full suite (
victory-shader+victory-gpu --features diagnostics) 555 passed, clippy clean.Side note: on the 780M, a point sample (
image_sample_lz) at −1/1024 stays below while a gather rounds up, so even one host resolves coordinates differently per path. NVIDIA numbers would be welcome.AI-assisted (Claude).