d3d12: handle AMD-only insertq on Intel CPUs #153

Manually merged
github merged 1 commit from gh-pr/153/head into gh-pr/153/base 2026-11-26 06:34:45 +00:00
Owner

@⁠3kynox on GitHub · 2026-11-25 08:56 UTC · original
3kynox:pr-insertq → main · +285 −4 · 3 files · 1 commits · merged 2026-11-25 09:06 UTC

Summary

Fixes #152.

ProjectScarlett 1.0.2.1 executes insertq (SSE4a), which raises EXCEPTION_ILLEGAL_INSTRUCTION on Intel CPUs. This adds a handler next to the clzero and mwaitx ones from #146, called from the same vectored exception handler in survey.rs:

  • Decode (runtime/d3d12/src/insertq.rs): only the form the title uses, F2 [REX] 0F 78 /r ib ib with register operands. extrq and insertq without immediates are left to fault. Neither occurs in the title.
  • Emulate: apply the insertion to the saved XMM state and resume after the instruction. Each immediate is taken modulo 64 and a length of zero means the whole quadword. The destination's upper quadword, which the instruction leaves undefined, is kept.

No Intel instruction of the same length does this, so the site is not rewritten in place. The handler acts only when CPUID reports no SSE4a and the fault is inside the title image.

On an i9-12900K with this change on top of 0a8d2ee the title gets past the first site: the log shows emulated unsupported insertq at RVA 0x2e7ff1 (host lacks SSE4a), the player-selection prompt is presented, and the run continued to its 240 s time limit (12,078 frames) with no unhandled illegal instruction.

Checks

All commands from CONTRIBUTING.md pass:

  • python -m unittest discover -s tests -q
  • cargo test for tools/shader-compiler, tuxbox-dxbc (with native-bindings) and tuxbox-xg-layout
  • cargo check --target x86_64-pc-windows-msvc -p tuxbox-d3d12

The new unit tests are Windows-only, like the clzero ones. I ran the tuxbox-d3d12 test binary under Proton's Wine on the Intel host, rebased on 53bb4d6: 95/95 passed, five of them new.

No evidence JSON changed.

**@⁠3kynox** on GitHub · 2026-11-25 08:56 UTC · [original](https://github.com/brcly/TuxBox/pull/153) `3kynox:pr-insertq` → `main` · +285 −4 · 3 files · 1 commits · merged 2026-11-25 09:06 UTC ## Summary Fixes #152. ProjectScarlett 1.0.2.1 executes `insertq` (SSE4a), which raises `EXCEPTION_ILLEGAL_INSTRUCTION` on Intel CPUs. This adds a handler next to the `clzero` and `mwaitx` ones from #146, called from the same vectored exception handler in `survey.rs`: - **Decode** (`runtime/d3d12/src/insertq.rs`): only the form the title uses, `F2 [REX] 0F 78 /r ib ib` with register operands. `extrq` and `insertq` without immediates are left to fault. Neither occurs in the title. - **Emulate**: apply the insertion to the saved XMM state and resume after the instruction. Each immediate is taken modulo 64 and a length of zero means the whole quadword. The destination's upper quadword, which the instruction leaves undefined, is kept. No Intel instruction of the same length does this, so the site is not rewritten in place. The handler acts only when CPUID reports no SSE4a and the fault is inside the title image. On an i9-12900K with this change on top of 0a8d2ee the title gets past the first site: the log shows `emulated unsupported insertq at RVA 0x2e7ff1 (host lacks SSE4a)`, the player-selection prompt is presented, and the run continued to its 240 s time limit (12,078 frames) with no unhandled illegal instruction. ## Checks All commands from CONTRIBUTING.md pass: - `python -m unittest discover -s tests -q` - `cargo test` for `tools/shader-compiler`, `tuxbox-dxbc` (with `native-bindings`) and `tuxbox-xg-layout` - `cargo check --target x86_64-pc-windows-msvc -p tuxbox-d3d12` The new unit tests are Windows-only, like the `clzero` ones. I ran the `tuxbox-d3d12` test binary under Proton's Wine on the Intel host, rebased on 53bb4d6: 95/95 passed, five of them new. No evidence JSON changed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:34:45 +00:00
github manually merged commit 7d281f83fa into gh-pr/153/base 2026-11-26 06:34:45 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 08:58 UTC · original · reviewed

No active review issues are reported for the insertq fallback that extends unsupported-instruction handling on Intel CPUs.

No open issues 🎉

What changed in this PR

Adds an insertq fallback to the D3D12 runtime so ProjectScarlett can continue past this AMD-only instruction on Intel CPUs, extending the existing unsupported-instruction handling for issue #152.

Changes:

  • Decodes and emulates the immediate, register-only form of insertq using saved XMM state.
  • Integrates the fallback into the existing exception handler, restricted to title code on hosts without SSE4a.
  • Adds unit tests for decoding, bit insertion, register updates, and instruction filtering.
File Description
runtime/​d3d12/​src/​survey.rs Calls the new fallback and updates handler documentation.
runtime/​d3d12/​src/​lib.rs Registers the insertq module.
runtime/​d3d12/​src/​insertq.rs Implements CPU detection, decoding, emulation, logging, and tests.

Review effort: Balanced

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 08:58 UTC · [original](https://github.com/brcly/TuxBox/pull/153#pullrequestreview-6054510410) · **reviewed** <!-- ccr-overview-v2 --> ### 🟢 Approval recommended No active review issues are reported for the insertq fallback that extends unsupported-instruction handling on Intel CPUs. **No open issues** 🎉 <details> <summary><strong>What changed in this PR</strong></summary> Adds an `insertq` fallback to the D3D12 runtime so ProjectScarlett can continue past this AMD-only instruction on Intel CPUs, extending the existing unsupported-instruction handling for issue #152. **Changes:** - Decodes and emulates the immediate, register-only form of `insertq` using saved XMM state. - Integrates the fallback into the existing exception handler, restricted to title code on hosts without SSE4a. - Adds unit tests for decoding, bit insertion, register updates, and instruction filtering. | File | Description | | ---- | ----------- | | `runtime/​d3d12/​src/​survey.rs` | Calls the new fallback and updates handler documentation. | | `runtime/​d3d12/​src/​lib.rs` | Registers the `insertq` module. | | `runtime/​d3d12/​src/​insertq.rs` | Implements CPU detection, decoding, emulation, logging, and tests. | </details> <sub>Review effort: Balanced</sub>
This discussion has been locked. Commenting is limited to contributors.
No description provided.