fix: drop the runtime division from the buffer_store_format index bound #2793
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2793
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2793/head"
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?
@tedin7 on GitHub · 2026-11-26 09:53 UTC · original
tedin7:x2w-store-format-no-div→main· +10 −4 · 1 files · 1 commits · closed without mergingPart of #1723
What this unblocks:
buffer_store_format_*shaders (the packed D16 and xyzw store helpers) now create a compute pipeline on NVIDIA GPUs instead of failing withNVVM compilation failed: 3.What changed
The two store helpers in
tools/startup/gfx2hlsl.py(d16_x and format_xyzw) boundedidx * stride + rec_offagainst 32-bit overflow withidx > (0xffffffffu - rec_off) / stride, a divide by the runtime stride. The NVIDIA driver rejects the format_xyzw helper that holds this divide. The same bound is now checked without a division:idxis split into 16-bit halves, each partial product is range checked, thenrec_offis added with a carry check. The stride is already limited to 0x3fff just above, so every partial product fits in 32 bits.Why it is correct
The new test is the same predicate:
idx*stride + rec_off > 0xffffffff. A 2,000,000-case randomized comparison against the old division form, with strides 1..0x3fff and indices at and around the overflow boundary, showed 0 differences. The bound is only an overflow guard; the in-range checks before it are unchanged.Source: Microsoft DirectX-Specs, HLSL integer arithmetic (32-bit
uintwraps modulo 2^32, so the guard has to be explicit); the failure itself is the driver's own compile error, seen only on the NVIDIA adapter.Verification
Isolation on the RTX 3090 (vkd3d-proton, Linux): one X-f32 dispatch with only that line removed created the pipeline and ran; variants that removed the GetDimensions call, the unorm packing, the f16 packing or
preciseall still failed withNVVM compilation failed: 3.python3 -B tests/startup_compute_store_format_xyzw_check.pypasses.python3 -B tests/startup_compute_store_d16_x_check.pypasses.python3 -B tests/startup_compute_store_format_xyzw_check.py dispatch <dxc> <offscreen_check> warpon the RTX 3090 (vkd3d-proton, Linux): every case matches (before the change:NVVM compilation failed: 3on the first case).python3 -B tests/startup_compute_store_d16_x_check.py dispatch <dxc> <offscreen_check> warpon the RTX 3090: passes.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-26 10:13 UTC · original
Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.
Pull request closed