shader: categorise refusals and isolate translation failures per request #3799
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3799"
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-12-01T23:29:44Z.
Problem
The shader translator reports an input it cannot handle by throwing
UnsupportedComputeShader, optionally with a reason code. Three paths did not follow that contract:std::runtime_errorfor a truncated, misaligned or malformed instruction, and returned an instruction with an empty mnemonic for an unknown opcode. Callers then had to treat an empty name as a special case, and one of them (name.substr(name.size()-4)in the SDWA compare path) indexed before the start of an empty name.std::logic_error. While a compute pack was being prepared, the per-record handler caught onlystd::runtime_error, so such an exception was not confined to its record.This PR is part of making the translator base more solid: every refusal has a category, and one failing request does not affect the others.
Change
Refusal categories:
UnsupportedComputeShadermoves to its own header,src/shader_translation_error.h, sogfx1013_isaandgfx1013_compute_ircan throw it without including the native translator header.invalid_isa.gfx1013::instruction()now refuses an unknown opcode with codeunknown_isa_opcodeand the messageunknown gfx1013 opcode <n> at byte <pc>. The newgfx1013::probe_instruction()keeps the previous structural decode (form, opcode, size, empty mnemonic) for the two mesh lookahead sites that only inspect the next instruction.Failure isolation:
translate_compute,translate_compute_container,translate_graphics_container,translate_mesh_program,translate_mesh_container,translate_mesh_pixel_program,translate_graphics_pair,translate_reflected_graphics) convert astd::logic_errorinto a refusal with codeinternaland the message prefixinternal:.build_compute_frontend_packtracks each record as prepared, unsupported or internal, and catchesstd::exceptionper record. An internal failure is written to the pack as a refusal record like any other, the remaining records are published unchanged, andComputePackCountsgains aninternalcount.compile_dxil --prepare-compute-packprintsinternal=<n>aftererrors=<n>and returns a failing status wheninternalis non-zero. Scripts that parse this line need to accept the extra field.tools/startup/triage_run.pygroups the new unknown-opcode message with the existingunsupported opcodereason and reportsinternal:messages asinternal translator error.Tests and documentation:
gfx1013_isa:valid_vop3_empty_namebecomesrefuse_unknown_vop3, andrefuse_unknown_vopc_sdwais added (VOPC opcode0x40with an SDWA extension word). Refusal cases now check the reason code as well as the diagnostic, and the two unknown-opcode cases also check the probe result. The case count goes from 80 to 81; the Python model, the CMake fragment anddocs/experiments/gfx1013-isa.mdare updated to match.native_compute_pack_refusals(tests/cmake/native_compute_pack_refusals.cmake). It builds a second copy of the pack check from sources with two injected faults, one in the translator and one in the per-record pack code, each selected by a distincts_nopprefix. It checks the reported refusal codes, the counts and exit status, that the record with the forced invariant failure carriesinternal: forced translation failure, that the unaffected records are byte-identical to those from the unmodified build, and that the pack is identical with 1 and 3 preparation threads.startup_triage_runcovers the two new report groups and checks that the text of an internal error is not echoed.The third commit is a build fix: MSVC rejected a qualified local enumerator used as a default member initializer of a local struct (
RecordStatus status = RecordStatus::prepared, error C2653). The member is now value-initialized withstatus{}, which selects the first enumerator,prepared.Validation
Built on Windows with MSVC and run on the exact head
40aab7ea6:Result: PASS.
The first attempt, on the second commit, failed to build with MSVC (C2653, described above). The third commit fixes it, and the result above is from the head that includes it.
Not covered by this run: hardware GPU tests, and a comparison of generated DXIL or IR against the base commit for inputs that translate successfully.
Related PRs
CMakeLists.txt: both PRs add an entry to the same native shader source list line. The other shared files merge cleanly.src/gfx1013_compute_native.h, where #3794 renames a constructor parameter ofUnsupportedComputeShaderand this PR moves that class tosrc/shader_translation_error.h. The resolution is to apply the rename in the new header.tools/startup/compile_dxil.cppand merges cleanly.None of these must land first. I will rebase this branch onto whichever of them is merged before it.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T04:13:44Z.
Rebased onto
main(0dd65da11).ShaderTranslationErrornow lives insrc/shader_translation_error.h; this PR keeps thereason_codeparameter name frommain, which/WXneeds forgfx1013_isa.cpp. The CTest selection from the description passes again with MSVC on the new head.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:24:41Z.
Review: APPROVED
Confirmed the rebase keeps the
reason_codeconstructor spelling required by the Windows build. Atc8cdc10aI builtcompile_dxil,native_compute_pack_checkandnative_compute_pack_refusal_checkin Windows Debug.ctest --preset dev --no-tests=error -j 2 -R '^(native_compile_dxil_refusals|native_compute_pack(_parts|_refusals)?|startup_triage_run)$' --output-on-failurepassed 5/5, including refusal isolation and the injected pack failure control.