d3d12: handle AMD-only clzero, monitorx and mwaitx on Intel CPUs #146
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/brcly--TuxBox!146
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/146/head"
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?
@JeffreyBytes on GitHub · 2026-11-25 05:23 UTC · original
JeffreyBytes:fix/amd-only-cpu-instructions→main· +685 −5 · 5 files · 1 commits · merged 2026-11-25 07:28 UTCSummary
Fixes #145.
ProjectScarlett 1.0.2.1 uses three AMD-only instructions that raise
EXCEPTION_ILLEGAL_INSTRUCTIONon Intel CPUs (exit code 29). This adds handlers for them next to theclwbone from #80, called from the vectored exception handler insurvey.rs:clzero(runtime/d3d12/src/clzero.rs): zero the 64-byte line atRAXand resume after the instruction. When the title'sclzero; add rax,0x40; cmp rax,rN; jbloop follows the fault, one trap clears the whole range and execution resumes at thecmp. Memory that isn't writable is left to fault, as it would on hardware.monitorx/mwaitx(runtime/d3d12/src/mwaitx.rs): on first fault, rewrite the second opcode byte01→1F, giving the same-length reserved NOP0F 1F /r. It's a single atomic byte store, so later iterations of the wait loop run natively. Neither instruction has architectural side effects, andmwaitxmay return at any time, so a NOP is valid. If the page can't be made writable, the handler steps over the instruction instead.Both act only when CPUID reports the instruction missing and the fault is inside the title image.
clwb.rsonly changesread_code_bytestopub(crate)so the new handlers can share it.On an i5-12600K, every AMD-only site the title reaches is now handled. After the rewrite, each wait site traps once and the rest of the loop runs natively. What remains is one
clzerotrap per clearing loop (about 250 a second). This fixes the CPU crashes only: on RADV the window stays black at a low frame rate for a separate GPU-side reason, which I'll report on its own.Checks
All commands from CONTRIBUTING.md pass:
python -m unittest discover -s tests -qcargo testfortools/shader-compiler,tuxbox-dxbc(withnative-bindings) andtuxbox-xg-layoutcargo check --target x86_64-pc-windows-msvc -p tuxbox-d3d12The new unit tests are Windows-only, like the existing
clwbones. I ran the fulltuxbox-d3d12test binary under Proton's Wine: 86/86 passed. One test executes the rewritten0F 1F FA/0F 1F FBnatively on the Intel host.No evidence JSON changed.