Skip to content

shader: read attr0.z/w as plain values in sampled pixel programs - #1912

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
roansystemlabs:pixel/730-attr0-zw
Nov 24, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
roansystemlabs:pixel/730-attr0-zw

Conversation

@roansystemlabs

Copy link
Copy Markdown
Contributor

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.py now accepts v_interp_p1/p2_f32 for attr0.z and attr0.w in the entry mask, as plain interpolated values. It is independent of #1779 (limit 3); limit 2 was covered by #1702.

  • Accepted: a matched P1/P2 of attr0.z or attr0.w in the entry mask of a sampled program lowers to float aluN = uv.z; (or uv.w), and the entry declares a float4 TEXCOORD0, 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.
  • Sample coordinates: only attr0.x/y. In a sampled program that reads z or w, every sample's u and v must be the interpolated attr0.x/y themselves or whole-quad values. Whole-quad arithmetic only takes whole-quad registers, so neither can come from z or w. Anything else, including a copy of z (v_mov_b32) or a value computed from it, is refused with A 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 of image_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.
  • Still refused: z or w interpolated in whole-quad mode, whole-quad arithmetic on an entry z or w, and attr1 and above. The 16-bit interpolation pair and the high word from shader: how should 16-bit attribute interpolation bind the high word and attributes above attr0? #711 are not touched.

tools/pixel_aot.py changes 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 in docs/experiments.md after the tools/pixel_aot.py overview. No C++ change: the draw uses the existing --check-pixel-gather case format (one RGBA32F level, point sampler, one reference color per pixel of an 8×8 target).

Verification

Commit bbf8977 on main 94dbdbf. The repeated runs of the new test below were made one rebase earlier, on main 3ad0069; the only upstream change in between to files this branch touches is in CMakeLists.txt and docs/experiments.md, and the wide run (which includes the new test on both adapters) is on bbf8977. 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-LOD image_sample, z/w interpolated in the entry mask after the exec restore;
  • whole_quad_bias: the same with image_sample_b and 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.

ctest --preset dev --no-tests=error -R "^pixel_aot_attribute_sampled_" -V      # 3 runs
100% tests passed, 0 tests failed out of 2
ctest --preset release --no-tests=error -R "^pixel_aot_attribute_sampled_" -V  # 2 runs
100% tests passed, 0 tests failed out of 2
ctest --preset dev --no-tests=error -R "^(pixel_|sampled_coverage|mesh_lit|mesh_shadow)" -j 4
100% tests passed, 0 tests failed out of 186

On both adapters, in every run, each of the three programs gives pixels=64 channels=256 max_absolute_error=0 with debug_errors=0 debug_warnings=0. No capability skip on this machine.

Negative controls

Control Expected Result on RTX 3070 and WARP
z and w exchanged in each program, drawn against the correct reference first mismatch predicted by the reference: x=1 y=0 (red and green are zero in the first texel, so pixel 0,0 cannot differ) exit 1, pixel_mismatch x=1 y=0, all three programs
z and w as the sample coordinates (entry_lz, whole_quad) refused refused by name
a v_mov_b32 copy of z, or z + w, as the v coordinate refused refused by name
a computed coordinate sampled before z/w are interpolated refused refused by name
z as the v coordinate of image_sample_c_lz, w as its u refused refused by name (translation only)
gfx1030 image_gather4: a copy of z as v; a constant coordinate gathered before z/w are interpolated refused refused by name (translation only)
attr1.z refused Unsupported instruction
z/w interpolated in whole-quad mode refused Unknown interpolation context
whole-quad v_add_f32 on an entry z refused Operand lacks a helper-lane definition

With main's translator the test fails at the first translation with ValueError: 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 for image_sample and image_sample_lz; it is killed only by the whole_quad_bias program, 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 with disassemble, and requires the same HLSL as the source text, both through lower and through the tools/pixel_aot.py command 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 for llvm-mc, with llvm-objcopy and LLVM-C.dll from the same release. With the same setup the binary modes of sampled_coverage_check, depth_mask_check, pixel_sample_offset_check, pixel_compare_sample_check, pixel_compare_check, mesh_lit_check, mesh_shadow_check, pixel_gather_check and pixel_compare_gather_check pass. pixel_aot_check.py binary passes its fixture loop and stops at its wave32 fixture, and pixel_get_lod_check.py binary at 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.py and git diff --check: all pass.

Overlap. git merge-tree against each of the 100 open PRs that touch tools/pixel_aot.py, docs/experiments.md, CMakeLists.txt or the workflow: this branch adds no conflicted file that main does 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

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

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 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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), new tests/pixel_attribute_sampled_check.py, a ctest registration (SKIP_RETURN_CODE 77), one line in windows.yml, one paragraph in docs/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/w are now accepted as plain entry-mask values (tools/pixel_aot.py, entry_interp line). The new attribute_scales / free_coordinates flags 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/_l take 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 0
  • python -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 the binary mode 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 uses image_sample_l, so the survived mutation shows the [:2] slice for the explicit-LOD opcode is unguarded (the _lz case has the same slice, so it hides the gap). One refusal case with z as the _l coordinate, 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.

@R0Y00
R0Y00 merged commit df15e92 into R0Y00:main Nov 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants