shader: read attr0.z/w as plain values in sampled pixel programs #1905
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1912"
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 R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-24T20:57:21Z.
Refs #730.
Change
Limit 1 from my #730 comment of 24/11 12:14Z, as reserved there at 18:42Z: when a pixel program is translated with a sampler,
tools/pixel_aot.pynow acceptsv_interp_p1/p2_f32forattr0.zandattr0.win the entry mask, as plain interpolated values. It is independent of #1779 (limit 3); limit 2 was covered by #1702.float aluN = uv.z;(oruv.w), and the entry declares afloat4TEXCOORD0, exactly as the unsampled path from #484 already does. The values can feed arithmetic and exports like any other entry value.v_mov_b32) or a value computed from it, is refused withA sampled program that reads attr0.z/w must take sample coordinates from attr0.x/y, in either order: a computed coordinate sampled before z/w are interpolated is refused at the interpolation. This is deliberately narrower than "does not depend on z/w": in such a program a constant coordinate, an entry-mask copy of a whole-quad value or the result of an earlier sample are refused too. The rule applies to plain, comparison and gather samples. z as the reference ofimage_sample_c_lz, the use that motivated limit 1 (an interpolated light-space depth), is not a coordinate: it is accepted and checked by translation; it is not drawn. Sampled programs without z/w are unchanged; there, computed coordinates for explicit-LOD samples stay accepted as before.tools/pixel_aot.pychanges by 29 lines: one helper, two flags, and one check at each of the three sample sites. Also included:tests/pixel_attribute_sampled_check.py, one CMake test (pixel_aot_attribute_sampled_{hardware,warp}), one line in the Ubuntu LLVM 15 job and one paragraph indocs/experiments.mdafter thetools/pixel_aot.pyoverview. No C++ change: the draw uses the existing--check-pixel-gathercase format (one RGBA32F level, point sampler, one reference color per pixel of an 8×8 target).Verification
Commit
bbf8977onmain94dbdbf. The repeated runs of the new test below were made one rebase earlier, onmain3ad0069; the only upstream change in between to files this branch touches is inCMakeLists.txtanddocs/experiments.md, and the wide run (which includes the new test on both adapters) is onbbf8977. Windows 11 build 26200.9974, D3D12 debug layer enabled, NVIDIA GeForce RTX 3070 (driver 32.0.16.2101) and WARP (10.0.26100.9818), DXC 1.9.2602.17 from SDK 10.0.26100.0, MSVC 19.44.The test draws three source-built gfx1013 programs. Each samples the texture at attr0.xy and scales red by z, green by w and blue by z·w; alpha is the texel's:
whole_quad: x/y interpolated in whole-quad mode, implicit-LODimage_sample, z/w interpolated in the entry mask after the exec restore;whole_quad_bias: the same withimage_sample_band a zero bias ahead of the coordinates (single mip, so the result is unchanged);entry_lz: everything in the entry mask,image_sample_lz.The test vertex shader from #484 gives each vertex its own z and w (z = 0.25 + 0.5u, w = 1 − v), so both vary across the target. The reference is plain Python with
Fraction: texel (x, y) at each pixel center, the z and w of that center, and the three products. Texels, attributes and products are short binary fractions, checked to be exact binary32 values, so every pixel must match bit for bit.On both adapters, in every run, each of the three programs gives
pixels=64 channels=256 max_absolute_error=0withdebug_errors=0 debug_warnings=0. No capability skip on this machine.Negative controls
pixel_mismatch x=1 y=0, all three programsentry_lz,whole_quad)v_mov_b32copy of z, or z + w, as the v coordinateimage_sample_c_lz, w as its uimage_gather4: a copy of z as v; a constant coordinate gathered before z/w are interpolatedUnsupported instructionUnknown interpolation contextv_add_f32on an entry zOperand lacks a helper-lane definitionWith
main's translator the test fails at the first translation withValueError: Unknown interpolation context.Translator mutants. Six single-edit mutants of
tools/pixel_aot.py, each run against the new test without arguments and on both adapters (on the same change, one rebase earlier), are all killed: z still refused, z and w read from each other's channel (only the draw sees it, at the first program), coordinates not checked, the order check dropped, z/w accepted in whole-quad mode, and the first two address registers taken as u, v for every sample form. The last one changes nothing forimage_sampleandimage_sample_lz; it is killed only by thewhole_quad_biasprogram, which is in the test for that reason. A seventh, removing the check at the gather site, is killed by the two gather refusals above.Binary check (LLVM 15).
python3 -B tests/pixel_attribute_sampled_check.py binary ...assembles the three programs, decodes the machine code withdisassemble, and requires the same HLSL as the source text, both throughlowerand through thetools/pixel_aot.pycommand line (120, 124 and 108 bytes). As for #749 and #773, I ran it on Windows with the LLVM 15.0.7 release: the clang 15 integrated assembler stood in forllvm-mc, withllvm-objcopyandLLVM-C.dllfrom the same release. With the same setup the binary modes ofsampled_coverage_check,depth_mask_check,pixel_sample_offset_check,pixel_compare_sample_check,pixel_compare_check,mesh_lit_check,mesh_shadow_check,pixel_gather_checkandpixel_compare_gather_checkpass.pixel_aot_check.py binarypasses its fixture loop and stops at its wave32 fixture, andpixel_get_lod_check.py binaryat a gfx1030 fixture, because the local stand-in only accepts the wave64 feature string; that is the stand-in, not this change.python -B tests/pixel_aot_check.py(no arguments),tests/docs_links_check.py,tests/bidi_controls_check.pyandgit diff --check: all pass.Overlap.
git merge-treeagainst each of the 100 open PRs that touchtools/pixel_aot.py,docs/experiments.md,CMakeLists.txtor the workflow: this branch adds no conflicted file thatmaindoes not already have. The docs paragraph sits away from the one #713 edits. No open PR or issue other than #730 works on attr0.z/w in sampled programs.Evidence and follow-up
image_sample_dgradient or a comparison reference follow the existing rules for entry values and are not drawn here (the comparison reference is checked by translation). The comparison and gather rules are checked by translation only; no gather or comparison program is drawn. Perspective-correct interpolation with a varying position w is not exercised: the test vertex shader keeps w = 1.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:11:05Z.
Review: COMMENTED
Review of #1912 at exact head
bbf897794364692ab1a9b54072f152ff99491240(fetched frompull/1912/head, HEAD equals currentheadRefOid;git merge-treeagainst currentmainshows no conflicts).Verdict: no P1/P2 found. Comment only, not an approval.
What I checked
tools/pixel_aot.py(+28/-1), newtests/pixel_attribute_sampled_check.py, a ctest registration (SKIP_RETURN_CODE 77), one line inwindows.yml, one paragraph indocs/experiments.md.attr0.z/ware now accepted as plain entry-mask values (tools/pixel_aot.py,entry_interpline). The newattribute_scales/free_coordinatesflags make the order of "interpolate z/w" and "sample with a non-xy coordinate" irrelevant (both orders raise). I read the coordinate-slice choice per opcode:image_sample_lz/_ltake the first two address registers, others (_b, plain,_d/_cd) take the last two, which matches the address layout (bias/derivatives precede, LOD follows). Comparison and gather paths get the same rule.Commands run locally
git diff --check origin/main...HEAD-> exit 0python -B tests/pixel_attribute_sampled_check.py->3 sampled attr0.z/w translations and their refusals checkedpixel_aot_check.py,pixel_sample_offset_check.py(Four 2D sample offset forms checked),pixel_compare_sample_check.py(Three gfx1030 2D comparison sample forms and a two-tap PCF checked),pixel_compare_check.py(pixel_compare controls passed),pixel_gather_check.py-> all exit 0bidi_controls_check.py->no bidirectional controls;docs_links_check.py->Checked 18 Markdown files and 377 linksMutations (applied to
tools/pixel_aot.py, suite re-run, thengit checkout -- .)xy_coordinatesalways returns TrueUnknown interpolation context)free_coordinatesrefusal removedattribute_scalesnever setimage_sample_ltreated as a trailing-coordinate op (slice[-2:])6/7 killed.
Not run (honest limits)
dxc+offscreen_check, WARP/hardware,ctest -R pixel_aot_attribute_sampled_) and thebinarymode need DXC, a D3D12 adapter and LLVM 15 (llvm-mc-15), none available on this Linux host. The bit-exact 64-pixel readback and the swapped-z/w negative control are therefore not verified by me; I only checked the translator and refusal layer.Non-blocking notes (P3)
tests/pixel_attribute_sampled_check.py: no case usesimage_sample_l, so the survived mutation shows the[:2]slice for the explicit-LOD opcode is unguarded (the_lzcase has the same slice, so it hides the gap). One refusal case with z as the_lcoordinate, and one acceptance with z as the LOD operand, would pin it.image_sample_d/_cd) are also not covered with z/w as a coordinate or as a derivative operand.AI-assisted; commands listed were executed locally.