xshader: tighten mesh/ray-query bounds and descriptor size tracking #515
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/515"
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 brcly/TuxBox. Originally posted by glovepost on 2026-11-29T18:44:35Z.
Summary
Tightens bounds and operand-tracking checks in
tuxbox-xshader:tools/shader-compiler/src/hlsl/mesh.rs): Marksfirst.dropPrimitivewhen any output index meets or exceeds the group-wide emitted vertex countsizes.x, avoiding out-of-range vertex reads when wave-local evaluate counts exceed the group count.tools/shader-compiler/src/hlsl/mesh.rs): Skips leadings_mov_b32 null, ...instructions at loop headers when matchingsampler_waterfalls.tools/shader-compiler/src/hlsl/operand_fields.rs): Treatssrc[0](the interpolation attribute index) ofv_interp_p1ll_f16,v_interp_p1lv_f16, andv_interp_p2_f16as a non-register field inunused_field.clear_sizetracking (tools/shader-compiler/src/hlsl/descriptor_size.rs): Usesself.one_word_vector_mask()inclear_sizeso wave32 compares and VOP3 carry-outs (_co_,v_mad_u64_u32,v_mad_i64_i32,v_div_scale_f32,v_div_scale_f64) do not treat the next SGPR as clobbered when every lane mask is proven one word (while continuing to treat it as clobbered whenvcc_hi/exec_hiis touched, e.g.s_mov_b32 vcc_hi, 0).tools/shader-compiler/src/tests/hlsl/): Adds coverage inmesh.rs,operand_fields.rs,descriptor_size.rs(including wave32 compare +s_mov_b32 vcc_hi, 0regression test), andray_query.rs(a_first_hit_walk_bounds_its_proceed_loop).Prepared with AI assistance; all changes were reviewed and verified by the contributor.
Tested
Run the checks relevant to this change.
ProjectScarlett was not run with this updated commit (
ccc82ec2). Earlier revision (fcc3649d) passed GPU checks (65/65check_translator_gpu.pyand126/126tuxbox.py verifyon NVIDIA10de:1e84and AMD1002:13c0), and GPU checks were not re-run after droppingnarrow_saveexecand the guessed-stride hunk.Host verification on rebased
origin/main(97f21fad):Checks
CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of
tuxbox-d3d12.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T19:51:07Z.
I was looking at three ProjectScarlett programs (
CS_SSSResolve,CS_SSSResolve_MaterialClassification,CS_SSSResolveVarianceReduction) refused on main with "texture size field … used outside its size computation". Your wave32clear_sizechange lets all three translate onfcc3649d, and the output passes DXC and DXV. That's CPU only; I haven't run them on a GPU or in game.One problem:
clear_sizeusesone_word_vector_mask() || narrow_saveexec, while the emitter leaves the next register alone only underone_word_vector_mask(). A 32-lane program that usesvcc_hias a scratch register has the second without the first. Addings_mov_b32 vcc_hi, 0(0xbeeb0380) before the saveexec in youra_wave32_compare_does_not_clobber_adjacent_size_registermakes it translate withs3 = 0u;after the compare, so the tracked width is overwritten and the size is wrong, where main refuses.Using
one_word_vector_mask()alone should fix it (I haven't run that edit on your branch). With only that condition added to main, forv_cmp*, the three programs translate to the same HLSL as yours.Could the guessed-stride count be a separate change, or come with a test on a view whose stride differs from the guess? #315 refused it because a host may divide the view's size by the declared element.
Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-29T22:04:29Z.
@NickStallman Thanks for checking those ProjectScarlett shaders and catching the
narrow_saveexec/vcc_hibug!I've updated #515 and rebased onto
main:clear_size(tools/shader-compiler/src/hlsl/descriptor_size.rs): Droppednarrow_saveexec(and removed it fromEmitter/setup.rs, keepingnarrow_masksprivate) soclear_sizeusesself.one_word_vector_mask()alone.tools/shader-compiler/src/tests/hlsl/descriptor_size.rs): Extendeda_wave32_compare_does_not_clobber_adjacent_size_registerwith your exact reproducer (s_mov_b32 vcc_hi, 0/0xbeeb_0380beforesaveexec32) confirmingone_word_masksstays false and the shader is refused instead of silently clobberings3.emit_buffer_countchange per #315 so only descriptors with a reflected stride return their element count.Host checks (
tuxbox.py check --no-gpu) passed9/9. ProjectScarlett was not re-run with this updated branch yet.Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-30T00:19:04Z.
Rebased onto
main(f482572a, commit41441f38ed06) with no functional changes fromccc82ec2, and ran the changed GPU checks on NVIDIA:TUXBOX_CHECK_JOBS=4 DXC=<dxc> python3 tuxbox.py check --changed --adapter 10de:1e84 --proton <proton> --prefix <prefix> --windows-dxc <windows-dxc>10de:1e84), driver620.73.04,GE-Proton11-14Lanes and fixtures on the GPU(lanes-bindless-compute,lanes-compute-root,lanes-compute-root-recovery,lanes-raster-tables,lanes-shader-cache) andShader translator on the GPUall passed (13 passed, 0 failed, 0 not run).Evidence: TuxBox check of 41441f38ed06, no uncommitted changes, GPU 10de:1e84: 13 passed, 0 failed, 0 not runImported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T00:48:48Z.
The AMD check you were missing, on the head you pushed: AMD iGPU (
1002:13c0, RADV, Mesa 26.0.8, GE-Proton11-14, Linux), fullpython tuxbox.py checkof41441f38: 199 pass, 0 fail. ProjectScarlett wasn't run on it.Evidence: TuxBox check of
41441f38ed, no uncommitted changes, GPU 1002:13c0: 14 passed, 0 failed, 0 not runImported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:25Z.
Heads-up: main just landed a large cleanup (up to
e5d2e913), so this PR needs a rebase.rustfmt.toml).unwrap(), lossyascasts and undocumentedunsafeoutside tests.cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.The least painful way is to format your branch first, so the rebase only shows real changes:
Then run
python tuxbox.py check --no-gpu, which now includes the format step.If clippy flags something new:
Fromfor widening,TryFromfor narrowing, and a mask for bit fields.unwrap(): use?, orexpectwith the reason it can't fail.unsafeblock: it needs a// SAFETY:comment.CONTRIBUTING's "Code checks" section lists the commands. Thanks!