Repository navigation
shader: read attr0.z/w as plain values in sampled pixel programs - #1912
Merged
Merged
Conversation
tools/pixel_aot.py refused every interpolation in a sampled pixel program except attr0.x/y used as sample coordinates. A matched P1/P2 of attr0.z or attr0.w in the entry mask now lowers to a plain value from a four-component TEXCOORD0, as the unsampled path already does. In such a program every sample coordinate must still come from attr0.x/y, either the interpolated value or a whole-quad value, which cannot read an entry z or w; any other coordinate is refused by name, whichever comes first. z/w in whole-quad mode, whole-quad arithmetic on them and attr1 and above stay refused. tests/pixel_attribute_sampled_check.py builds three gfx1013 programs that sample an 8x8 float texture at attr0.xy and scale red by z, green by w and blue by z*w: an implicit-LOD sample in whole-quad mode, the same with a zero bias ahead of the coordinates, and image_sample_lz. An exact CPU reference checks all 64 pixels bit for bit; the program with z and w exchanged must fail at the predicted first pixel. It also checks the refusals and, in binary mode, that LLVM-assembled machine code translates to the same HLSL.
tedin7
reviewed
Nov 24, 2026
tedin7
left a comment
Collaborator
There was a problem hiding this comment.
Review of #1912 at exact head bbf897794364692ab1a9b54072f152ff99491240 (fetched from pull/1912/head, HEAD equals current headRefOid; git merge-tree against current main shows no conflicts).
Verdict: no P1/P2 found. Comment only, not an approval.
What I checked
- Scope:
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. - Clean-room: programs are source-built from assembly text in the test, the texture and attributes are synthetic binary fractions, no vendor bytes. Title is neutral.
- Logic: with a sampler,
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 checked- Regression, same venv:
pixel_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 0 bidi_controls_check.py->no bidirectional controls;docs_links_check.py->Checked 18 Markdown files and 377 links
Mutations (applied to tools/pixel_aot.py, suite re-run, then git checkout -- .)
| Mutation | Result |
|---|---|
xy_coordinates always returns True |
killed (refusal accepted) |
| z/w entry interpolation disabled when a sampler exists | killed (Unknown interpolation context) |
free_coordinates refusal removed |
killed |
attribute_scales never set |
killed |
| comparison-sample coordinate check removed | killed (refusal 0 accepted) |
| gather coordinate check removed | killed (refusal 2 accepted) |
image_sample_l treated as a trailing-coordinate op (slice [-2:]) |
survived |
6/7 killed.
Not run (honest limits)
- The draw step (
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.- Gradient forms (
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.
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 shader: translate four-component entry interpolation in unsampled pixels #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.