The README had drifted from the code, and in one place contradicted the repository's own documentation. **Claims that were wrong, now measured:** - "the first known static recompilation project targeting the original Xbox" -- contradicted by docs/technical/ms-fusion-recompiler.md in this same repo. Microsoft's Ficl/Fission got there first, shipping Xbox back-compat on the 360. Reworded to "first *public*", with the pointer to our own study of theirs. - Kernel coverage was "115 of 366 ordinals resolved, 55 with dedicated bridges". Counted: 152 of 371 routed, 112 with bridges. - Every per-module line count was stale (kernel 8,298 -> 11,128; d3d 7,018 -> 8,838; apu 3,918 -> 4,168; nv2a 4,778 -> 4,892; input 212 -> 360). - Burnout 3 was still listed as "playable ... main menu at 60fps" three sections after a note explaining that build leaned on hand-written scaffolding. Says so in one place now, and retires the claim until the recompiled path earns it back. - "handles ~95% of instructions" is not measured anywhere. Replaced with the honest signal: an unhandled instruction lifts to a bare comment, so grep the generated output. - The Quick Start skipped `tools.abi_analysis` entirely -- which is exactly what issues #1 and #2 both walked into. Now step 6, with a note on what silently degrades if it is skipped. - Dependencies omitted pytest; the tool list omitted five tools that exist. **Versioning.** v0.6.0 "Credit Where Due", with a changelog back to v0.1.0 reconstructed from commit dates rather than invented -- the feature groupings and months come from the actual commits that landed them. Per-item attribution follows ps3recomp's convention, so a contributor can find their work by name. Replaces the undated "Recent Changes" bullet list, which had no ordering and no way to tell what shipped when. **Docs.** "How The Key Pieces Work" restated register-model.md, memory-layout.md and indirect-calls.md badly and in less detail than the real documents (246, 303 and 386 lines respectively), and its code snippets had gone stale -- `PUSH32(val)` has been `PUSH32(sp, val)` for a while, and the register globals are thread-local now. Replaced with a short index. The two NV2A sections had no document to point at, so their content moves to docs/technical/nv2a-shaders.md rather than being dropped. Also removes four "(NEW)" markers that have survived several releases. README 494 -> 553 lines, of which the changelog is 120. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PZDe6qTWAvohfDtYXbpRyM
2.8 KiB
NV2A Shader Translation
Xbox games do not ship HLSL. They configure the NV2A's fixed-function combiner pipeline, or upload raw vertex-shader microcode. Both have to become something D3D11 or OpenGL will accept, and both are translated at runtime and cached.
This document covers the two translators. For what is and is not implemented, see gap-analysis.md; for the wider D3D8 layer, see d3d-translation.md.
Register combiners → HLSL pixel shaders
Xbox games do not use traditional pixel shaders. They configure the NV2A's 8-stage register combiner pipeline. Each stage performs independent RGB and alpha math — multiply, dot product, MUX — over a register file of textures, vertex colours and constants. A final combiner blends the result.
The game sets this up as a packed descriptor:
SetPixelShader(0x00000103); /* 3 stages, tex0 = 2D, tex1 = 2D */
At draw time that configuration is translated into an HLSL pixel shader:
Stage 0: r0.rgb = tex0 * diffuse
Stage 1: r0.rgb = r0 * tex1 (environment-map modulate)
Stage 2: r0.a = tex0.a * diffuse.a
Final: output = r0
A 128-entry shader cache keys on the combiner configuration, so each unique setup is compiled once and reused. Multi-texturing is covered outright.
Bump and environment mapping are partial: the combiner side is there, but
texture-coordinate generation (TEXCOORDINDEX with the camera-space modes) is
not, so effects that depend on generated coordinates will not look right yet.
Vertex-shader microcode → HLSL vertex shaders
When a game uses programmable vertex shaders — water displacement, skeletal animation, custom lighting — it uploads NV2A microcode rather than any high-level source. Each instruction is 128 bits and carries a paired MAC and ILU operation.
The translator parses that microcode and emits HLSL:
- 14 MAC ops —
MOV,MUL,ADD,MAD,DP3,DP4,DPH,DST,MIN,MAX,SLT,SGE,ARL - 8 ILU ops —
MOV,RCP,RCC,RSQ,EXP,LOG,LIT - 192 constant registers, 12 temporaries, 16 vertex inputs
- Relative addressing through the address register (
A0) - A 64-entry compiled-shader cache
Because both halves of an instruction issue together, the translator has to emit them so that the MAC and ILU results are written from the pre-instruction register values — reading a register the paired op just wrote is the classic way to get this subtly wrong.
Where the code lives
| Piece | File |
|---|---|
| Combiner → HLSL | src/d3d/d3d8_combiners.c, src/d3d/d3d8_combiners.h |
| Vertex microcode → HLSL | src/nv2a/nv2a_pgraph_d3d11.c |
| Texture unswizzling | src/d3d/d3d8_swizzle.h |
d3d8_combiners.h and d3d8_swizzle.h cite xemu as a reference for the
hardware's behaviour; both are our own implementations. See NOTICE.