Shaders: gathers from the first level take the console's footprint #3613
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3613"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T21:16:06Z.
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 #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.Fixes #3261: under
VICTORY_WARP=1,gathers_at_a_level_match_the_hardwarefails one texel off on main + #2323 and passes with this PR on top (upipibi's RTX 3070 run).AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T21:55:44Z.
@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,
f0191dfselected the previous footprint in all 512 readbacks.bbe216cselected the expected footprint in all 512, and the other four controls matched their expected footprints.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 [email protected]
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T00:24:28Z.
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
bbe216con63bcca4.gathers_take_the_footprint_at_the_coordinateandpoint_samples_take_the_texel_at_the_coordinatepass on the card, including the offsets closest to the texel boundary:victory-shader --lib --features host: 306 passed, 0 failed, 3 ignored.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by akimfomin on 2026-11-28T01:31:33Z.
For the open question about NVIDIA near the 1/256-texel footprint boundary, I published a PortBridge Lab task pinned to
bbe216c3and invited separate native D3D12 and Proton testers with public NVIDIA results. The receipt asks for selected texels and matched offsets, with the software and physical runs separated. No new result is available yet. Participants can give their agents just that issue link, and any result will be credited here.Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T04:12:49Z.
The NVIDIA row, as asked: RTX 3070 8 GB, driver 616.56, Windows 11, the hardware adapter and WARP in the same run.
emit::gather_tests::at #3583 headf0191df(before) and this headbbe216c(after), each 3 times with identical output. Pixels out of 256: "below" is the texel atx - 1, "at x" is the texel atx.d"—": 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
x, while 1/512 + 1/65536 and 3/1024 stay atx - 1. Point samples are unchanged. Both tests pass on both heads (2 passed, 3 runs each).AI-assisted (Claude Code, Claude Opus 5.5 built both heads and ran the tests on this card).
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T14:33:56Z.
Thanks all. @andrewpozdnakov7-jpg's test commit is now on this branch as-is, with his authorship (head
4fb5462).780M (RDNA3) + WARP on
4fb5462, with the tests run against the oldlower.rs(before) and this PR (after, 5 of 5 runs):gathers_take_the_footprint_at_the_coordinate(16×16, wrap)gathers_round_npot_wrapped_tile_edges(13×13)gathers_round_npot_border_edges(13×13)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
(first + 1) / sizekeeps the right texels at a non-power-of-two size, across a wrapped tile edge and in border mode.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).
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T14:37:47Z.
NVIDIA row for
4fb5462(with @andrewpozdnakov7-jpg's tests). RTX 3070, driver 616.56, Windows 11 Pro 10.0.26100, debug.cargo test --locked -p victory-shader --lib gather_tests::gathers, 3 runs each, hardware adapter and WARP in each run:63bcca4'slower.rs)4fb5462)gathers_take_the_footprint_at_the_coordinate(16x16, wrap)gathers_round_npot_wrapped_tile_edges(13x13)gathers_round_npot_border_edges(13x13)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 (
kept below 0, at x 256), and WARP doesn't (kept below 256, at x 0). With this PR both reportkept below 0, at x 256at those offsets, and from -0.001968 on both reportkept below 256. So on this card the PR changes WARP's result and leaves the hardware's as it was, and the two new 13x13 tests agree on both. This matches the boundary in my earlier report above.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T16:17:55Z.
@upipibi @JurajSimicevic one more NVIDIA check that may be worth a minute, since you both reported
synthetic_tests::gathers_at_a_level_match_the_hardwarefailing on main (RTX 3070 in #3749, RTX 5080 in #3584).That test does three gathers per lane: two
image_gather4_l(emulated withgather_first, the console's rounding) and oneimage_gather4_lz, which on main goes straight to the host'stextureGather. On lanes 0-15 it asserts, on hardware only, that the host's own gather equals the emulated one, at the coordinates where rounding decides: f32 products just across a texel threshold, the 1/512 ties, NaN, ±inf, zeros. The 780M rounds like the console there and passes; my guess is NVIDIA doesn't on some of those lanes.This PR moves the
_lzcoordinate to the middle of the console's footprint with the samegather_first, so all three gathers should agree on any GPU. If you can, please run at4fb5462:cargo test -p victory-shader --lib -- gathers_at_a_level_match_the_hardware --nocaptureIf 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).
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T16:36:14Z.
@kilolimaVI it still fails at
4fb5462on its own, the same as onmain. The cause on NVIDIA is the record read that #2323 (Bullet18x) fixes, not gather rounding. With #2323's one line, NVIDIA's own gather matches the emulated one. RTX 3070, driver 616.56, Windows 11 Pro 10.0.26100, debug.cargo test --locked -p victory-shader --lib -- gathers_at_a_level_match_the_hardware --nocapture, 3 runs per row:VICTORY_WARP=1(every device WARP)main63bcca4hardware: lane 0, left[0.0, 1.0, 0.0, 0.0], right[0.0, 0.0, 0.0, 0.0]4fb5462(this PR)main+ #2323's9c6e0942hardware: lane 4 against its gather, left[66.0, 67.0, 35.0, 34.0], right[65.0, 66.0, 34.0, 33.0]4fb5462+ #2323's9c6e0942assert_eq!s turned into prints (local change, restored after). On hardware, every one of the 32 lanes read the footprint of u = v = 0 at level 0,[0, 1, 0, 0], or at level 3 on lanes 5-7, from the emulated gathers and the host's alike. That is #2323's description: a raw load through the structured records view multiplies the offset by the stride on NVIDIA (#2178), so the records read as zeros. Its RTX 5090 shows the same[0, 1, 0, 0]on every lane.main+ #2323), thelane < 16check of the 3070's owntextureGatherpasses in 3 of 3 runs. So on this card the host gather already rounds like the console at those coordinates, and this PR's_lzchange isn't needed here.VICTORY_WARP=1, the "hardware" leg is WARP too, so its!warpguard doesn't skip the host-gather check. Onmain+ #2323 that check fails at lane 4, one texel off (#3261). With this PR on top it passes. So this PR is what makes the test pass on a WARP-only run.AI use: Claude Code (Claude Opus 5.5) ran the tests and the probe and wrote this.
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T18:00:37Z.
@upipibi thanks, that corrects my guess: on NVIDIA it is #2323's record read, and with it the 3070's own gather already rounds like the console.
Your last row is the useful one: under
VICTORY_WARP=1, main + #2323 fails at lane 4 one texel off, and this PR on top passes. That is #3261 (WARP one texel off in every channel), so this PR fixes #3261 on the translator side. #3267 takes the test-side route (skipping the host-gather check on WARP); the two don't conflict.AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T18:11:57Z.
I checked the #3261 result on Windows with app-local WARP 1.0.22 and Agility 1.620.2. Every tree used the original structured-buffer fixture and
VICTORY_WARP=1.gathers_at_a_level_match_the_hardware63bcca4[66, 67, 35, 34]versus[65, 66, 34, 33]4fb5462010381cThe three footprint regressions also passed on #3613 alone and on the combined tree, including the non-power-of-two wrap and border cases. All rows replicated with the D3D12 debug layer off and on. This run checks the WARP rounding result. The RTX 3070 fixture evidence remains in the earlier hardware report.
AI-assisted with OpenAI Codex. Synthetic tests only.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.