startup: add a read-only --refusals census of gfx2hlsl refusal sites #1971
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1978"
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 Leyukaka on 2026-11-24T22:31:28Z.
Refs #1723.
Change
tools/startup/gfx2hlsl.pystops a pipeline at its first refused instruction. A cache of refused requests therefore shows one layer of gaps at a time: fixing a refusal reveals the next one behind it, and the census in #1723 notes that the gaps behind the first refusal are undercounted.This adds a read-only diagnostic:
It loads every request in the directory through the same loader as
--pending, including RTV variants and requests that already have a.txtor.fail. Each request is translated in memory with a collector:.fail, after normalisation; file errors are reported asunreadable shader requestbecause their text holds the path and key;translator crash in <op>: <type>when nothing was recorded before it, a translator bug, or asinternal error in <op>: <type>after an earlier refusal or crash, a possible follow-on effect.The report has two views:
decode,vs,ps,pipeline), the requests that contain it, that reach it first, and that have it as their only distinct reason, plus a histogram of refusal sites per request and the count with no refusal recorded (not compiled);.aand.bbytes, excluding RTV variants, with each reason counted under every observed root signature or under some roots only.Register numbers and immediates are normalised (
sN,s[N:N],vN), as are raw instruction words. Numbers that are the cause, such as a format, a width or a shader model, are kept. No request key or path is printed; refusal text is printed only after this normalisation. Counts after the first refusal are approximate, because a skipped instruction leaves later state unmodelled; the report and the docs say so.The mode writes nothing:
refusals_mainnever reachestranslate_to, opens no file for writing, never starts fxc, and exits beforemain()'sos.makedirs. It is selected by--refusals DIRor--refusals=DIRanywhere on the command line. With the collector unset, the default path is unchanged. Thedecode()encoding checks, #1932's NEG rewrite included, move verbatim intocheck_encoding(). Request loading is split out oftranslate_request()intoload_request(). The end ofmain()(the pending loop that #1749 rewrites) is untouched. On a translator without this change,--refusals DIRis treated as--pending DIRand writes into the directory; the docs say so.Registered as CTest
startup_gfx2hlsl_refusals, in thepython-linuxCI list and inAGENTS.md. There is a section indocs/experiments.mdand a short note indocs/startup-runtime.md.Verification
On
425cd53b(based onmainat889cd3f4), Windows 11 build 26300, Python 3.14.10:47 checks pass, without game data or LLVM, and with
X2W_FXCempty so fxc is never started. The disassembler is stubbed with synthetic words, except the NEG check, which decodes one hand-assembledv_cndmask_b32_e64word with the in-tree decoder. They cover:.failtext;only;word_0x…;--refusals=DIR, and a missing directory that is never created;translate_topatched to raise aBaseExceptionsubclass.A control stops at the first refusal and requires the second reason to disappear from the report. On
mainthe script ends at its first collector call with an uncaughtgfx2hlsl.Unsupported: unsupported_first.Local data, not in the repository. On a local cache of 575 recorded requests (the synthetic check above covers the same properties without it: unchanged default output, an unchanged directory, no key in the report):
X2W_FXC= python -B tools/startup/gfx2hlsl.py --pending <copy>with this branch and withmainat889cd3f4gives byte-identical directories (897 files) and identical logs;--refusals <copy>leaves every file byte-identical and prints no 16-hex-digit key or rawword_0xname.Also run on this branch, each
python -B tests/<name>exiting 0:startup_translator_check.py,startup_gfx2hlsl_capture_check.py,startup_ngg_slice_check.py,startup_gfx2hlsl_f32_lg_check.py,startup_gfx2hlsl_f32_nan_check.py;startup_gfx2hlsl_cndmask_neg_check.py,startup_gfx2hlsl_op_refusals_check.py,startup_uniform_lane_check.py,startup_gfx2hlsl_scalar_m0_check.py,startup_gfx2hlsl_sop2_complement_check.py,startup_gfx2hlsl_smem_offset_check.py;docs_links_check.py,bidi_controls_check.py.CTest was not run: no build tree was configured for this change. The registration is one
add_testbeside its neighbours, and CI runs the script directly.Evidence and follow-up
tools/startup/gfx2hlsl.py: none textual with #1749 (it rewrites the end ofmain()) or #1931 (translate()hunks separated by unchanged lines). #1931 and this change both add anadd_testafterstartup_gfx2hlsl_smem_offsetinCMakeLists.txt; whichever lands second needs a one-line rebase. #1631 edits the same lines ofPipeline.__init__,Stage.__init__and the top ofStage.translate(), so the second to land needs a manual rebase; its newStageargument is positional and this change passes its own by keyword, so the two compose.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T22:37:59Z.
Ran it, broke the normaliser five ways: four caught, the hex redaction is unpinned
Windows 11 build 26300.9974, device-free:
normalize_refusals[16:23]range normalisation removeds16→sN)word_0x…normalisation removedWhat the surviving line does, and why its loss matters
Calling
normalize_refusaldirectly, before and after removing line 2130:So the operand-position rule at 2132–2133 covers
offset 0x10, which is why the fixture still passes — but a bare literal in thereason text keeps its exact bits. That is the case the function's own comment is about ("redact hex operands and offsets"), and it
has two consequences for a census: an input-derived value lands in a report meant to be safe to paste into an issue, and two
refusals that differ only in a literal are counted as two different sites — the overcount this diagnostic exists to reduce.
Suggested case, one line in the existing shape:
One process note, not a finding about the PR
Two neighbouring checks (
startup_translator_check.py,startup_gfx2hlsl_capture_check.py) reported exit 2 in my first batch runand exit 0 when run individually — that was my own loop, not your change. Both are green on this branch; I re-ran them directly
before writing anything down.
What I like about the design
load_request()with arefusalslist instead of a second decode path, so a new refusal siteis picked up without touching the census.
handler_errordistinguishesinternal errorfromtranslator crashdepending on whether refusals were being collected — thedifference between "this form is not lowered yet" and "the translator broke"; getting it backwards would hide crashes.
of the input.
What this does not establish
Nothing about a full cache: the fixture builds its own requests. The undercount behind the first refusal (#1723's motivation) is a
claim about real caches, not something this check measures.
Verdict
Reviewed. The normaliser is well covered except its hex-redaction line, which the fixture never exercises.
Notes