compute: accept a scratch-base register write that nothing can observe #1648
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1655"
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 triggered02 on 2026-11-24T16:22:10Z.
Fixes #1648, per the scope you set: the exact whole-register immediate write is handled when the accepted program cannot observe scratch state, direct reads and scratch-dependent memory stay refused, the untouched UAV guards are compared as well as the output, and the offline acceptance count is reported separately (as not measured — see the end).
Change
s_setreg_imm32_b32 hwreg(HW_REG_FLAT_SCR_LO|HI), <imm>now lowers to nothing. Nothing the compute lowering accepts can read either half — a read throughs_getreg_b32and everyscratch_*/flat_*memory form are themselves unmodelled and refused — so the write has no observable consumer. Its value is not tracked, which is why only this exact whole-register immediate form is accepted; every others_setreg_imm32_b32form stays refused.Tests
draw-scratch-base-write: lowers the indexed kernel with the write in front, requires the generated HLSL to be byte-identical to the untouched kernel, then runs the same WARP readback as the original case — so all 320 words and the untouched guard words are compared, and a wrong stored or guard word still fails.controls(): a read of either half, a scratch memory form, a write to any other hardware register, and a write-only kernel with a mismatched binding.Fail-first: with the write's acceptance removed, the fixture raises
and the new test exits 1.
What this does not establish
.dxbcreproduction was not run, and the acceptance-count rescan (389 of 2,689 records) is not measured here — reporting it separately as you asked, and reporting it as unmeasured rather than estimating from the unit fixture.One design note: my first version also pre-scanned the program for consumers of the base. That guard was unreachable — every consumer form is refused before it can observe anything — and no test could make it fire, so I removed it rather than ship a branch that looks protective but never runs. The comment and the docs say why the write is safe instead.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T16:25:24Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
c259252e11ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:32:25Z.
Review: COMMENTED
Peer review on
c259252e:Findings
No P1 or P2 defects found.
tools/compute_store_aot.pyaccepts only the whole-register immediates_setreg_imm32_b32 hwreg(HW_REG_FLAT_SCR_(?:LO|HI)), ...form, afterds_wait(s_waitcnt lgkmcnt(0)) and outside lane-guard restore blocks. Nos_getreg_b32,scratch_*, orflat_*consumer is accepted by the compute lowering, so the write has no observable consumer.Nits:
tests/compute_store_check.py:binarymode (Linux) only runs the negativemust_rejectchecks incontrols()and does not exercise positive lowering ofSCRATCH_BASE_WRITE_LINES(which runs indraw_scratch_base_writeon Windows). Also,HW_REG_FLAT_SCR_HIonly appears in amust_rejectcase (stride=8), so positiveHW_REG_FLAT_SCR_HIlowering is not directly covered.tests/compute_store_check.py: stray"at the end of the first line ofdraw_scratch_base_write's docstring.Verification
python3 -B tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM.so.19.1— PASS (exit 0).*_hardwareexcluded):--preset dev):cmake --build --preset dev --target offscreen_check -- -j 6(30.14s),ctest --preset dev -R '^(...|compute_store_aot_scratch_base_warp|...)$' --parallel 4 --no-tests=error --output-on-failure— 55/55 passed (77.57s;compute_store_aot_scratch_base_warp4.17s)./O2(--preset release):cmake --build --preset release --target offscreen_check -- -j 6(51.82s),ctest --preset release -R '^(...|compute_store_aot_scratch_base_warp|...)$' --parallel 4 --no-tests=error --output-on-failure— 55/55 passed (77.33s;compute_store_aot_scratch_base_warp4.31s).HW_REG_FLAT_SCR_(?:LO|HI)toHW_REG_FLAT_SCR_HIintools/compute_store_aot.py;draw_scratch_base_writefailed as expected (ValueError: Unsupported compute instruction: s_setreg_imm32_b32 hwreg(HW_REG_FLAT_SCR_LO), 0, exit 1). Restored cleanly (git status --shortclean).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T16:49:04Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T16:22:21Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
c259252ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T16:32:44Z.
Correct, and the integer-only literal check was wrong for exactly that reason: LLVM spells an imm32 whose bit pattern looks like a float as an inline float, and that is the string the disassembler hands to
lower().0x3f800000arrives as1.0,0x3e23f983as0.15915494. Fixed in30ef44f3.The hwreg match stays strict (only
HW_REG_FLAT_SCR_LO/_HI, whole register); only the literal became LLVM's spelling of an imm32 — decimal, hex, inline float with optional sign and exponent, or the non-finite names. Anything else is refused withUnsupported scratch-base immediate spelling, andhwreg(4)(a raw register id) or a register operand stay refused as unsupported instructions, both pinned incontrols().The fixture now lowers and reads back three spellings —
0,1.0,0.15915494— and the mode asserts each produces HLSL byte-identical to the untouched kernel before the WARP readback:Fail-first for the float path specifically: restoring the integer-only check fails the mode with
ValueError: Unsupported scratch-base immediate spelling: 1.0.Thanks — this one would have stayed latent until a real title record used a float-looking immediate, since every fixture I wrote used
0and0x400.Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T16:34:24Z.
Thanks — no P1/P2 and both nits were fair. Fixed in
e6d94835; the review was onc259252e, so it predates the float-spelling fix Codex raised separately.Positive coverage in every mode.
controls()now lowers the integer write and both float-spelled spellings and requires each to equal the untouched kernel:That also covers
HW_REG_FLAT_SCR_HIpositively (the0.15915494spelling writes HI), so it is no longer only a rejection case.controls()runs before mode dispatch, which is what the binary mode exercises first; I verified it by importing the module and callingcontrols()directly —controls ok, 2 extra spellings positively covered— since I do not have LLVM here to run the full binary mode.Docstring. The stray
"is gone.Your mutation check is the right one for the hwreg split; mine only removed the acceptance entirely, so narrowing LO/HI was not covered locally. Thanks for both.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T16:25:24Z.
Code review location:
tools/compute_store_aot.py; line 374When a valid scratch-base immediate has a bit pattern LLVM spells as an inline float, such as
0x3f800000becoming1.0intests/rdna2_tools_check.py::test_hwreg_operands_use_llvm_spelling,pixel_aot.disassemble()passes that spelling tolower(), but this integer-only regex misses it and lowering falls through toUnsupported compute instruction. Since the immediate is intentionally ignored, accept these float spellings too (or parse them back to their 32-bit values).Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T16:49:04Z.
Code review location:
tools/compute_store_aot.py; line 374Verified at
e6d94835. The lowering accepts LLVM floating spellings, and the source-built low/high cases including 1.0 and 0.15915494 produce identical HLSL. Direct reads, scratch memory and nonliteral operands remain refused. The related Windows Release checks passed on RTX and WARP (4/4).