startup: add a compute stage to gfx2hlsl with the offen buffer store #2174
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2182"
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 NiiRoZz on 2026-11-25T03:09:38Z.
Change
This adds a compute stage to the startup translator,
tools/startup/gfx2hlsl.py. It lowers one computestore form. Refs #1412.
What it adds
gfx2hlsl.ComputePipeline(cs_code, root_blob, rsrc2, group)translates one gfx1013 compute program. Ituses the same root, resource and entry-constant model as the graphics stages.
Entry registers:
COMPUTE_PGM_RSRC2and the thread group size, which are pipeline register state.COMPUTE_PGM_RSRC2is decoded with the mergedcompute_store_aot.entry_registers(#1608). The userSGPRs come first, then one SGPR per enabled group-ID axis with no gap for an omitted axis
(
SV_GroupID). v0-v2 holdSV_GroupThreadIDup toTIDIG_COMP_CNT.gfx2hlslnow importscompute_store_aot(and through itpixel_aot) lazily.TG_SIZE_ENstays refused, as asked on #1544.way the graphics stages' s8 is. #1608 defines no root placement. The only evidence in the repository is
a local compute-record scan whose table bindings used s4 or s5 (
docs/experiments.md).Output:
csHLSL main with[numthreads].stage cs,group X Y Z,ud/udsrc/srvlines in the existing format,and
uav <slot> table <param> <byte offset>.Store lowering:
buffer_store_dword/x2/x3/x4in theoffenform. The address is aper-lane byte VGPR plus the scalar offset and the immediate. The descriptor must sit at a fixed
root-table offset, and the target is a
RWByteAddressBuffer.s_loadreturned.offandidxenforms, andglc/slc/dlc;New compute-only refusals:
v_readlane/v_readfirstlane/v_writelane) inside a block thats_cbranch_execzskips. The wave runs such a block when any lane is active. The one-lane model wouldskip it for an inactive lane and lose the scalar result.
image_samplewith implicit LOD. A compute lane has no derivatives. The_l/_lzforms are kept.Shared change (affects graphics too):
s_and_b32 s18, s18, …) was recorded under the key of theload's first descriptor. It is now recorded under the descriptor the word belongs to: load offset
plus
4 * (dword & ~3).idxenloads consult that set.123 of which translate. The HLSL and manifest hashes and the refusal texts were identical, so no
graphics output moved.
buffer_store_dwordx3), sorefusal census buckets do not move.
Not in this change
and slot 14 still drops the dispatch.
translated with no refusal; their weight is 2,926 direct and indirect dispatches. This is a local
observation and the frame's data is not public.
buffer_load_format_*(#2138 and the #2022 item A split),resource-heap
s_loadwith a register offset (#1143),s_mulk_i32,v_readfirstlaneuniformity,buffer_store_format_d16_x, LDS writes,src_scc(#1821) andimage_store.buffer_store_format_d16_x, adescriptor whose stride field was cleared (
s_andof dword 1 with0xc000ffff),image_storeandthe
offform.cache. It is on a local companion branch,
compute/slot67-requests.Open design question: which tool is the runtime compute translator?
On #1412 the maintainer described the first slot-67 fixture: "A useful first slot 67 fixture would bind
explicit group dimensions, a read buffer and a writable resource, then verify nonzero GPU output plus a
dropped-dispatch or swapped-binding control." This change follows that description.
The compute lowerings merged so far live in
compute_store_aot, and #2022 item A is being added there.compute_store_aottakes its bindings from the caller (table_reg,descriptor_offset, …), and #1994'srecords do the same. gfx2hlsl derives them from the root signature and already feeds the runtime shader
cache, which is why the stage is added here and reuses
compute_store_aotonly for theCOMPUTE_PGM_RSRC2decode.If the runtime compute translator should instead be
compute_store_aot, made to serve requests, thisstage should move there; please say so.
Overlapping work
#2059 (tedin7) adds
op_buffer_store_dword*to the same handler for vertex-stageoffstores.This change uses the same shapes:
uavsregistry anduav();RWByteAddressBuffer u<n> : register(u<n>)declaration and theuav <slot> table <param> <offset>line;
down.
Whichever lands second has to merge the two into one handler, with the address form chosen per stage.
Expect a textual conflict there.
#1994 (ArnabSaga): offline translation of fixture programs through
compute_store_aot, with aseparate cache protocol. No code overlap.
#2138 (tedin7):
buffer_load_format_*in gfx2hlsl, the largest first refusal above. No code overlap.Known gaps shared with the graphics stages, not changed here
refused only for compute in this change.
s_cbranch_vccz/vccnzands_cbranch_execnzloops are also evaluated per lane while the waveevaluates them per wave. Scalar state updated inside a loop that lanes leave at different times can
differ.
idxenload still checks only the first register of its descriptor operand. An overwritten laterword is not seen there.
AI-assisted (Claude Code).
Verification
Commit
0236bbcb(on65f8ef9d). Windows 11 build 26300, MSVC Release,offscreen_checkbuilt in theworktree, DXC 10.0.26100.0, debug layer enabled.
startup_gfx2hlsl_compute_{warp,hardware}: cases A (3x2x2 groups), B (4x1x3), C (1x5x1)swapped-axes(case A)dropped-store(case A)b-offset(case B without its immediate offset)c-unpredicated(case C without the exec predicate)ctest: 11/11 passed, 0 skipped. The hardware variants return 77 without a GPU; that path was not
exercised here because a GPU was present.
Debug layer: 0 errors and 0 warnings in every run.
Each control is pinned in CMake by
PASS_REGULAR_EXPRESSION "control <name>: rejected at word=[0-9]+ ".Pure-Python controls pass. Each of these reviewed inputs was accepted before and is now refused:
s_mov_b32 s18, 0);s_or_b32 s17, s17, 0x40000;s_and_b32 s18, s18, 0xffff;s_mov_b32 s18, 4between two stores;s_and_saveexec_b32form;
image_sample;offset:6.The modification is recorded under byte 16 of the x8 load, not byte 0. An
image_sample_lzstilltranslates. The graphics refusal text is unchanged.
The
binarymode reassembles the three programs and every spliced control instruction with llvm-mc 15.52 other pure-Python checks pass: all
tests/startup_gfx2hlsl_*_check.pyandstartup_translator,plus
compute_entry_layout,startup_flat_param,startup_buffer_address,startup_smem_address,startup_stream_fetch,startup_sampler_heap,startup_inline_sampler,docs_linksandbidi_controls.git diff --checkis clean.Not run: the full ctest suite, CI, FXC (the runtime cache's compiler) on compute output.
Evidence and follow-up
tests/startup_gfx2hlsl_compute_check.py, withtheir llvm-mc source and recorded words. They contain no retail bytes. MIT.
an exec mask set from a compare.
root signature (root SRV t0, root UAV u0, 16 root constants at b0). These match the translation's
r0,u0and entry cbuffer by register. The manifest'ssrv/uavtable lines and the descriptor fetchfrom the table are not exercised on the GPU; they are checked only as text.
compute/slot67-requestspublishes slot-67 requests (.cscode,.root, and a 28-byte state block.sa).A local run produced 2,689 of them.
.sadword 3 (low and high 16 bits), Z in dword 4 (low 16 bits);COMPUTE_PGM_RSRC2in dword 6.TG_SIZE_EN, which this stage refuses.load_requestfor.csintoComputePipelineis the piece after both PRs land.(4 + parameter SGPRs + heap pointers). That lies inside the observed user SGPR range of 4 to 14, so
the refusal "root needs more SGPRs than
USER_SGPR" is not expected to fire for them.USER_SGPRwith its own root.buffer_store_format_*andimage_storein gfx2hlsl.ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_compute_' -V. The new sectionis "Compute stage in the startup translator" in
docs/experiments.md.Checklist
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:20:58Z.
Review: COMMENTED
Review of head
0236bbcb5b(comment only, no approval).Scope read: tools/startup/gfx2hlsl.py (cs entry, execz guard, buffer_store_dword*), tests/startup_gfx2hlsl_compute_check.py, CMakeLists.txt, windows.yml, AGENTS.md, docs/experiments.md.
Commands executed locally (Linux):
python3 -B tests/startup_gfx2hlsl_compute_check.py-> "compute entry, numthreads, manifest, offen store forms and the store, descriptor, execz and sample refusals pass"python3 tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-15-> not runnable here (llvm-mc-15 not installed); covered by the Linux CI job, which is green.python3 tests/docs_links_check.py-> 402 links OK;python3 tests/bidi_controls_check.py-> OK;git diff --check origin/main...HEAD-> clean.0xfffffffcuto0xfffffff8uin op_buffer_store_dword. The Linux controls fail (exact-line assertion on the emitteda = (...) & 0xfffffffcu;). Reverted withgit checkout -- ..Windows (Win2025 node,
x2w_pipe.py win2025 2182 --scope direct --regex startup_gfx2hlsl_compute --force):Findings:
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T03:59:58Z.
Thanks for the review. Added
94b042bafor nit 2: a pure-Python control that pins today's translation of a store past the descriptor's range (offset:4092→a = (v4 + 4092) & 0xfffffffcu;then a plainu0.Store, no range check, manifest unchanged), so a later runtime change to range handling cannot go unnoticed. It is a text control rather than a GPU case because the fixture binds a root UAV, which has no bounds checking, so an out-of-range store has no defined GPU result to pin. Controls, binary mode against llvm-mc 15 and the 11 compute ctests pass on that head.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:04:19Z.
Review: COMMENTED
Re-review of head
94b042bac51961db9be4fd5218b3ab0eb92d9c01(previous review was on0236bbcb). Scope: compute stage intools/startup/gfx2hlsl.py, newtests/startup_gfx2hlsl_compute_check.py, CMake/CI/docs wiring.Status: mergeable, CI green on this head (Linux checks, gfx1013 fixtures, Windows build and test; /O2 and chart jobs skipped). Title and body are neutral. No external or clean-room concerns seen in the diff.
Commands executed locally in a worktree of the head:
git diff --stat origin/main...HEAD: 6 files, +652/-4python3 tests/startup_gfx2hlsl_compute_check.py: pass ("Self-test passed.")python3 tests/docs_links_check.py: pass (18 files, 402 links)python3 tests/bidi_controls_check.py: pass (1465 files)git diff --check origin/main...HEAD: cleanMutations (each reverted with
git checkout -- .):s_cbranch_execzskipped-block guard intranslate(): killed (test fails: expected refusal namings_add_u32 inside a block s_cbranch_execz skips).& 0xfffffffcudword rounding inop_buffer_store_dword: killed (test pins the emitteda = (v4 + 0) & 0xfffffffcu;).desc_key(first) in self.pipe.modifiedclause in the store's descriptor check: survived.Findings:
tools/startup/gfx2hlsl.py,op_buffer_store_dword, thedesc_key(first) in self.pipe.modifiedclause): mutation 3 survives. The per-wordself.symcomparison already catches a modified word because the writer now tags it('modified',), so the clause looks redundant. Either add a case where onlypipe.modifiedcarries the mark, or drop the clause.op_buffer_store_dword): the out-of-range store is deliberately unguarded and the comment and the new pinning test say so. It stays an assumption until a runtime sizes the UAV view. Fine to keep as documented.setup_entry): the compute root start at s4 is an inference. The code comment anddocs/experiments.mdsay so honestly, and unplaced user SGPRs are refused on read. Good.Not run: Win2025 WARP. The compute store is not yet covered by a GPU readback in this PR, which is acceptable for a translator-only slice, but a WARP readback of the offen store versus a CPU reference should come before the follow-up that binds the UAV.
Verdict: no blocking issues on this head; the earlier review points look addressed.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T04:54:02Z.
Review: CHANGES_REQUESTED
The combined tree with current main (including #2139) passed the compute buffer-store comparison and all four mutations on both WARP and RTX 4060 Laptop. I found one scope leak in that combination: a source-built CS Stage with a table SRV and
image_load v4, v[0:1], s[16:23] dim:SQ_RSRC_IMG_2D dmask:0x3 d16emitspack16_d16(..., ud0)andudsrc 0 d16unorm16 0. ComputePipeline.manifest does not emit thed16srvbound-view requirement, and the CS path has no equivalent per-view validation. Please update against #2139 and explicitly refuse D16 loads in CS for this buffer-store slice. Add that synthetic case as a refusal control. Supporting D16 compute textures can follow when the compute consumer validates the effective SRV format.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:23:05Z.
Review: COMMENTED
Re-review of head
0a523d0ec0(comment only, no approval). Earlier reviews covered0236bbcband94b042ba.Scope:
git diff --stat origin/main...HEADis 6 files (gfx2hlsl.py, the compute check, CMakeLists.txt, windows.yml, AGENTS.md, docs/experiments.md). The new part since the last review is the "refuse unvalidated compute D16 loads" change inimage()plus the D16 SRV format sets.Commands executed locally (Linux):
python3 -B tests/startup_gfx2hlsl_compute_check.py-> passpython3 -B tests/startup_image_sample_l_check.py-> FAIL:AttributeError: 'Stage' object has no attribute 'kind'(tools/startup/gfx2hlsl.py:1803, from tests/startup_image_sample_l_check.py:205bare.image(...))tests/startup_gfx2hlsl_*_check.pyandtests/startup_*gfx*check.py-> pass (the failure above is outside that glob)python3 tests/docs_links_check.py-> 407 links OK;python3 tests/bidi_controls_check.py-> OK;git diff --check origin/main...HEAD-> cleanself.kind == 'cs' and 'd16' in modswithFalse and 'd16' in mods. The compute check fails ("accepted, expected a refusal naming 'compute d16 image load requires validated SRV formats'"), so the new refusal is guarded. Reverted withgit checkout -- ..Findings:
image()now readsself.kindunconditionally.Stageinstances created withoutkind(the bare Stage in tests/startup_image_sample_l_check.py:205 and its address-count control) raise AttributeError before any other check, so an existing test fails and the Linux CI job is red. Fix: set a defaultkindonStage(orgetattr(self, 'kind', None)), or have that test setbare.kind = 'ps'like startup_gfx2hlsl_refusals_check.py:37 does. A class-level default is safer, since other callers could build a Stage the same way.Windows: I did not run
x2w_pipe.py win2025on this head. The Linux job is already red, and the earlier Win2025 debug result (11/11) was for0236bbcb. It needs a rerun after the P2 fix.Verdict: not ready until the P2 is fixed and CI is green.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T05:23:48Z.
Review: APPROVED
Re-reviewed
0a523d0e. The integration explicitly refuses a D16 load in compute until that consumer validates the bound SRV, and the new control checks that refusal. Compute buffer-store controls, graphics D16 tests, and the offline producer test pass. The combined branch's three 320-word GPU comparisons and four mutations ran on WARP and RTX 4060 Laptop before this narrow guard. This lands the standalone compute translator only. Runtime binding and the real application Dispatch remain separate.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:31:41Z.
Review: COMMENTED
Re-review of head
5633dcd0ff(PR #2182).Delta since my last review (
0a523d0e): one line, tools/startup/gfx2hlsl.py:1803,self.kind == 'cs'becamegetattr(self, 'kind', None) == 'cs'. This addresses the earlier P2 (bareStagewithoutkindraised AttributeError before the image refusals).Commands executed locally (Linux):
python3 -B tests/startup_image_sample_l_check.py-> pass (was FAIL on0a523d0e)python3 -B tests/startup_gfx2hlsl_compute_check.py-> passtests/startup_*gfx*check.pyandtests/startup_image*check.py-> pass, no failurespython3 tests/docs_links_check.py-> 18 files, 407 links OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleanFalse and 'd16' in mods. The compute check fails ("accepted, expected a refusal naming 'compute d16 image load requires validated SRV formats'"), so the refusal is guarded. Reverted withgit checkout -- ..Findings:
Windows: I did not run
x2w_pipe.py win2025. The change since the last Win2025 run is a one-line Python default with no HLSL output change, and the Windows CI job is green. The maintainer's Draft -> Ready gate still needs its own WARP run on the final head.Verdict: no blocking findings from this review.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T05:26:10Z.
The Linux Python job failed on
0a523d0e:tests/startup_image_sample_l_check.pybuilds a bareStage(Stage.__new__) to reach the operand-only refusals, and the new compute D16 guard at the top ofStage.imagereadsself.kind, which a bare stage does not have (AttributeError: 'Stage' object has no attribute 'kind').Pushed a one-line follow-up on top of your commit: the guard reads
getattr(self, 'kind', None), so it is unchanged for a compute stage and bare stages reach their refusals again. Locally the 16 pure-Python checks that build a bare stage, plusstartup_gfx2hlsl_compute_check.pyandstartup_translator_check.py, pass on that head.AI-assisted (Claude Code).