Skip to content

shader: bind further constant buffers by table register and offset in pixel_aot - #727

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
rasptum:shader/cb-bindings
Nov 22, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
rasptum:shader/cb-bindings

Conversation

@rasptum

@rasptum rasptum commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Change

pixel_aot.lower() resolves one constant descriptor, on the texture table, to b0. A pixel program that loads a second 16-byte descriptor stops there: at Unresolved constant buffer binding when the table address comes from another entry register, or at Constant descriptor differs from binding contract when it is another offset of the same table. In the fixed-profile rescan this is the largest first rejection of the first general profile (4,411 PS records in my local input at 4c3b573, counts below).

This PR adds an explicit contract for further constant buffers:

  • lower(..., extra_constants=[(sgpr, offset), ...]), and --extra-constant SGPR OFFSET (repeatable) on the command line.
  • Each entry names one 16-byte descriptor by the entry SGPR that holds the low word of its table address and by its byte offset in that table. Entries map in order to b1, b2 and onward, each cbuffer ConstantsN : register(bN) { float4 paramsN[16]; }, read under the existing s_buffer_load_dword, dwordx2 and dwordx4 rules (dword-aligned immediate offsets inside 256 bytes).
  • The SGPR may be the texture table or another entry register. constant_descriptor keeps its meaning and its b0 mapping, and may be omitted.
  • Descriptor words now remember which buffer they belong to, so a read needs four consecutive words of one descriptor.

Still rejected, each with a diagnostic:

  • a descriptor load the contract does not name (Constant descriptor differs from binding contract);
  • a table address whose high word is not a tracked zero, or whose low word is not a contract table (Unresolved constant buffer binding);
  • an entry register outside the contract (it stays unbound, as before);
  • arithmetic on a table register (Expected a numeric scalar register);
  • a texture descriptor load from a constant table;
  • a four-register span that mixes words of two descriptors;
  • contract entries that overlap each other or a texture descriptor on the same table, name the interpolation register, or are unaligned, negative or malformed;
  • everything the single-buffer path already rejected: register offsets, reads past byte 256, the eight-word and sixteen-word loads.

Not done on purpose: no audit profile uses the new contract, and nothing is inferred. Which descriptors a title uses as constant buffers, their sizes and their original HLSL registers are not known from the shader bytes, so the caller supplies the contract and the translator only verifies each load against it. Descriptors that feed vector buffer_load_* are the subject of #319 and of docs/pixel_mubuf_contract.md, and stay rejected here.

Nine existing checks tested for the prefix "params[" to recognise a constant-buffer value. They now test "params", so that params1[...] and later arrays are recognised the same way. No other tracked value starts with that prefix.

Test harness: the offscreen_check pixel root signature gains root CBVs b1 and b2, set only for a case that supplies them. The pixel-case trailer carries their contents under bit 3 of the flags byte (512 bytes after the flags byte and any viewport). I used bit 3 because #694 uses bit 2 for its title memory.

Verification

Update before opening: rebased onto main at 121fdc3 as 837fd52. On that commit I reran the LLVM 15 round trip, tests/form_coverage_check.py and the full pixel_aot_check.py draw run on WARP (all pass); the hardware and ctest results below are from the commit named there.

Environment: Windows 10 Pro build 19045, Python 3.13, LLVM 15.0.7, DXC from Windows SDK 10.0.26100.0, D3D12 debug layer enabled. Commit 9b2b8c1 on 45559f9. Adapters: WARP (Microsoft Basic Render Driver) 10.0.19041.5794 and NVIDIA GeForce RTX 3060, driver 32.0.15.9636.

Command Result
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll> exit 0
python -B tests/pixel_aot_check.py draw <dxc> <offscreen_check> warp exit 0
python -B tests/pixel_aot_check.py draw <dxc> <offscreen_check> hardware exit 1 at the existing scalar fixture, see below
check_three_buffer_draw run on its own, warp and hardware pass on both
python -B tests/form_coverage_check.py pass
the 22 pure-Python checks listed in AGENTS.md all exit 0
ctest --preset dev -R 'pixel|bc7|coverage|offscreen|mesh_pixel|mesh_textured|mesh_attribute|mesh_depth|compute_to_pixel|compute_mesh' -j 4 (run one rebase earlier, on 787ace7; the later commits on main do not touch the renderer) 47 selected: 41 passed, 5 skipped, 1 failed, see below

Hardware run: the full draw ... hardware run stops at a pixel_mismatch in the existing scalar fixture (channel 0, expected_bits=3fa0c000 actual_bits=3fa04000). Unmodified main stops at the same fixture with the same bits on this adapter, so I am not counting the hardware run as a pass and it is not caused by this PR. The same mismatch is the one ctest failure, pixel_aot_blend_scalar_hardware, which also fails on unmodified b03f754 here. The new draw passes on this adapter when run on its own. pixel_aot_hardware and the other nine pixel_aot_*_hardware tests passed.

Capability skips (not passes): mesh_pixel_pipeline_warp, mesh_attribute_draw_warp, mesh_textured_draw_warp, compute_mesh_texture_warp, mesh_depth_pair_warp.

Because the root signature changed for every pixel draw, the ctest row above covers the other users of the renderer (bc7_draw, attribute, coverage, pixel_cb_read, compute to pixel) on both adapters.

Evidence and follow-up

Fixture: with_three_constant_buffers() in tests/pixel_aot_check.py, written for this PR (MIT), built from the existing source fixture. It loads the b0 descriptor and a second descriptor from the texture table and a third from the table at entry s9, reads word 2 of each buffer and exports one buffer per channel. Every other word of the three buffers holds a sentinel. It is in the LLVM 15 round trip list.

Draw and negative controls: two constant sets match all four channels of 4,096 pixels per draw. A reference with b1 and b2 exchanged, a reference that reads b0 in place of b1, and a translation with the two contract entries exchanged each report a mismatch on both adapters. A case file with a truncated pair of extra buffers is refused as a case-format error. check_three_constant_buffers() holds 31 rejection controls, 30 of them tied to their diagnostic text, beside the accepted variants.

Aggregate observation from one local input (counts only, 12,101 PS records; a local script outside the repository traced scalar moves and loads in linear order and then asked lower() to verify):

First-profile unresolved-CB group at 4c3b573 Records
Total 4,411
read 1 / 2 / 3 / 4 or more descriptors through s_buffer_load_* 81 / 140 / 90 / 4,099
descriptors taken from 1 / 2 / 3 entry registers 93 / 606 / 3,711
with one bound descriptor: next stop is a descriptor on another entry register 3,565
with one bound descriptor: next stop is another offset of the same table 144

With every traced entry-table descriptor bound through extra_constants:

Outcome Records
past every constant-descriptor stop 3,463
of those, complete translation 2
stop at a 16-byte descriptor that no s_buffer_load_* reads (candidate vector buffer, #319) 582
stop at a descriptor whose table address is not traced to an entry register 293
stop at an immediate read beyond byte 256 72
no traced descriptor 1

The 3,461 that get further without completing next stop at: a read of an unbound entry SGPR (1,553), a v_mov_b32 whose source is not a tracked numeric value (692), an unbound pixel input at v_cvt_u32_f32_e32 (624), v_interp_p1_f32_e32 outside the accepted contexts (162), a register-offset s_buffer_load_dword (97), an unbound texture descriptor offset (96), and smaller groups.

What this does and does not show: the fixture verifies the lowering of the contract. The counts say how far lowering proceeds under explicit bindings; they do not establish what a title binds to any slot. The trace is linear and 4,250 of these programs branch, so the trace only proposes bindings and lower() rejects anything it cannot verify. tools/shader_profile_audit.py is unchanged, and its output on this input is byte-identical before and after this PR (853 PS accepted: 339 general, 354 depth, 124 coverage, 36 attribute). The two records that complete do so with a single descriptor at an offset the fixed profiles do not try; adding that profile is a separate audit change.

Follow-up another contributor can pick up: the unbound entry SGPR reads (1,553 here) are the next largest stop and need entry-layout evidence, not a translator change. Reads beyond byte 256 need a decision on the bound buffer size.

Overlap with open PRs (same lines, textual conflicts only): #694 changes the lower() signature line, the write_case signature, and the trailer flag mask in tests/pixel_aot_render.cpp, and takes flag bit 2. #429 and #398 change write_case and the flag mask. #718 adds one more "params[" prefix test, which would need the same one-word edit after this lands. #651 touches other regions of lower(). No open PR or issue claims constant-buffer binding in pixel_aot; #319 covers vector loads.

docs/experiments.md documents the contract, the fixture, the trailer bit and the counts. No README row changes: the pixel shader row and its command are the same.

AI-assisted (Claude). I ran every command above locally and read the results.

🤖 Generated with Claude Code

… pixel_aot

lower() resolved one constant descriptor, on the texture table, to b0. A
program that loads a second 16-byte descriptor, from another offset or from
a table held in another entry register, stopped at "Unresolved constant
buffer binding" or "Constant descriptor differs from binding contract".

extra_constants (CLI: --extra-constant SGPR OFFSET, repeatable) names
further descriptors as (entry SGPR, byte offset) pairs and maps them in
order to b1 onward, each a 256-byte buffer under the existing read rules.
A table register is accepted only as the low address word of an
s_load_dwordx4 with a tracked zero high word. Descriptors outside the
contract, mixed descriptor words, arithmetic on a table register and
overlapping contract entries are rejected.

The three-buffers fixture reads one word from each of three buffers and is
covered by the LLVM 15 round trip, controls and a draw. The renderer root
signature gains root CBVs b1 and b2, and the pixel-case trailer carries
their contents under bit 3 of the flags byte.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@R0Y00
R0Y00 merged commit 87b861d into R0Y00:main Nov 22, 2026
5 checks passed
roansystemlabs added a commit to roansystemlabs/Xbox2Windows that referenced this pull request Nov 23, 2026
Use the same constant operand check as the other paths (R0Y00#727), so values
from params1, params2 and later buffers are recognised, and add a CPU
control whose comparison reference is read from b1.
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.

2 participants