Run Minecraft: runtime HLE, D3D12.X device on the host GPU, shader IR

Loader: map title-shipped DLLs, patch static TLS loads to slot 0, crash
reporter, title paths for GetModuleFileName*.

HLE: task queue and async, XUser (one offline user), system ids,
title id, features, invites, game events, persistent local storage,
GameInput with no devices, xmem, console audio hardware queues, life
cycle (close suspends, then terminates), and a file layer with virtual
drives rewritten in path-taking imports.

GPU: D3D12.X device, DXGI chain, heaps, resources, fences, queues and
command lists translated onto a host D3D12 device; clears, barriers,
copies, resolves and PresentX into the title's window.

Shaders: SGD5 reader and `victory translate`; SSA IR with node
splitting for irreducible flow; structurisation removing EXEC.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MarvisandClaude Opus 5.5 committed 2026-11-23 14:42:21 +01:00
1 parent 12caefe804
commit 754619f30e
61 files changed
+12775 -88

No files matched your search

+27 -11
View File
@@ -18,7 +18,7 @@ mod fields;
mod opcodes;
mod sp3;
pub use fields::{Cache, Dpp, Fields, Operand, Sdwa, Valu};
pub use fields::{Cache, Dpp, Fields, NULL, Operand, Sdwa, Valu};
use std::collections::BTreeMap;
@@ -76,12 +76,9 @@ pub fn decode(code: &[u8]) -> Result<Vec<Instruction>, ShaderError> {
while !found.contains_key(&offset) {
let inst = instruction(code, offset)?;
let next = offset + 4 * inst.words.len();
let flow = match flow(&inst, next, code.len())? {
Flow::Stop if inst.name() == Some("s_setpc_b64") => {
far_jump(&found, &inst, code.len())?.map_or(Flow::Stop, Flow::Jump)
}
flow => flow,
};
let flow = control(&inst, code.len(), |at| {
found.range(..at).next_back().map(|(_, i)| i)
})?;
found.insert(offset, inst);
match flow {
Flow::Next => offset = next,
@@ -104,13 +101,32 @@ pub fn decode(code: &[u8]) -> Result<Vec<Instruction>, ShaderError> {
Ok(list)
}
enum Flow {
/// Where execution goes after an instruction.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Flow {
Next,
/// End of the program, or an indirect jump that is not a far jump.
Stop,
Jump(usize),
/// Conditional: to the target or the next instruction.
Branch(usize),
}
/// Control flow after `inst`, resolving far jumps. `before(at)` returns the
/// decoded instruction with the highest offset below `at`, if any.
pub(crate) fn control<'a>(
inst: &Instruction,
len: usize,
before: impl Fn(usize) -> Option<&'a Instruction>,
) -> Result<Flow, ShaderError> {
Ok(match flow(inst, inst.offset + 4 * inst.words.len(), len)? {
Flow::Stop if inst.name() == Some("s_setpc_b64") => {
far_jump(before, inst, len)?.map_or(Flow::Stop, Flow::Jump)
}
flow => flow,
})
}
fn flow(inst: &Instruction, next: usize, len: usize) -> Result<Flow, ShaderError> {
let target = || {
let delta = 4 * i64::from(inst.words[0] as u16 as i16);
@@ -138,8 +154,8 @@ fn flow(inst: &Instruction, next: usize, len: usize) -> Result<Flow, ShaderError
/// into s(n+1), `s_setpc_b64 s[n:n+1]`, looking back over the straight-line
/// run just decoded. Any other `s_setpc_b64` (e.g. a handover to the next
/// merged stage through registers) gives `None`.
fn far_jump(
found: &BTreeMap<usize, Instruction>,
fn far_jump<'a>(
before: impl Fn(usize) -> Option<&'a Instruction>,
setpc: &Instruction,
len: usize,
) -> Result<Option<usize>, ShaderError> {
@@ -147,7 +163,7 @@ fn far_jump(
let mut delta = None;
let mut at = setpc.offset;
for _ in 0..4 {
let Some((_, prev)) = found.range(..at).next_back() else {
let Some(prev) = before(at) else {
break;
};
if prev.offset + 4 * prev.words.len() != at {
File diff suppressed because it is too large. Load diff
+5
View File
@@ -9,7 +9,9 @@
pub mod dxbc;
pub mod dxil;
pub mod gfx10;
pub mod ir;
pub mod native;
pub mod structure;
pub use dxbc::{Container, FourCC, Part};
pub use dxil::{DxilProgram, ShaderKind, XboxExtras};
@@ -23,4 +25,7 @@ pub enum ShaderError {
Malformed(&'static str),
#[error("GFX10 code at {offset:#x}: {reason}")]
Isa { offset: usize, reason: &'static str },
/// Valid code the translator cannot handle yet: an opcode name or a construct.
#[error("GFX10 code at {offset:#x}: {what} is not supported")]
Unsupported { offset: usize, what: &'static str },
}
+15 -1
View File
@@ -17,6 +17,7 @@
//! mesh 0x48, compute 0x60; unused ones are 0xDEADBEEF_DEADBEEF
//! record +0x00 u64 code offset, +0x08 u64 code size (payload-relative),
//! +0x14 u32 flags: bit 5 wave32 (else wave64)
//! +0x50 u32 bits 0-9 VGPRs used, bits 20-27 SGPRs used
//! ```
//!
//! Other kinds seen: 0x07 program header + bitcode (or a stub when stripped),
@@ -47,9 +48,10 @@ const SLOTS: [(HwStage, usize); 8] = [
(HwStage::Cs, 0x60),
];
const ABSENT: u64 = 0xDEAD_BEEF_DEAD_BEEF;
const RECORD_SIZE: u64 = 0x18;
const RECORD_SIZE: u64 = 0x54;
const RECORD_FLAGS: usize = 0x14;
const FLAG_WAVE32: u32 = 1 << 5;
const RECORD_REGS: usize = 0x50;
/// Unpacked blobs are a few KiB; refuse to allocate for absurd sizes.
const MAX_UNPACKED: u64 = 16 << 20;
@@ -72,6 +74,8 @@ pub struct NativeProgram {
pub stage: HwStage,
/// Runs as 64 lanes per wave (else 32); sizes lane masks.
pub wave64: bool,
/// VGPRs the program uses (v0 up to this), the bound of indexed access.
pub vgprs: u16,
/// GFX10 machine code.
pub code: Vec<u8>,
}
@@ -145,9 +149,14 @@ fn programs(fssm: &[u8]) -> Result<Vec<NativeProgram>, ShaderError> {
bytes(payload, record, RECORD_SIZE).ok_or(Malformed("FSSM record out of bounds"))?;
let code = bytes(payload, u64_at(record, 0)?, u64_at(record, 8)?)
.ok_or(Malformed("native code out of bounds"))?;
let vgprs = (u32_at(record, RECORD_REGS)? & 0x3FF) as u16;
if vgprs > 256 {
return Err(Malformed("implausible VGPR count"));
}
out.push(NativeProgram {
stage,
wave64: u32_at(record, RECORD_FLAGS)? & FLAG_WAVE32 == 0,
vgprs,
code: code.to_vec(),
});
}
@@ -166,6 +175,7 @@ mod tests {
const VS_CODE: [u8; 8] = [1, 2, 3, 4, 5, 6, 7, 8];
const PS_CODE: [u8; 4] = [9, 10, 11, 12];
const VGPRS: u32 = 28;
fn slot(stage: HwStage) -> usize {
SLOTS.iter().find(|s| s.0 == stage).unwrap().1
@@ -187,6 +197,8 @@ mod tests {
let flags = if stage == HwStage::Ps { FLAG_WAVE32 } else { 0 };
payload.extend_from_slice(&[0; 4]);
payload.extend_from_slice(&flags.to_le_bytes());
payload.resize(record as usize + RECORD_REGS, 0);
payload.extend_from_slice(&(VGPRS | 31 << 20).to_le_bytes());
payload.extend_from_slice(code);
}
let mut out = b"FSSM".to_vec();
@@ -236,11 +248,13 @@ mod tests {
NativeProgram {
stage: HwStage::Vs,
wave64: true,
vgprs: 28,
code: VS_CODE.to_vec()
},
NativeProgram {
stage: HwStage::Ps,
wave64: false,
vgprs: 28,
code: PS_CODE.to_vec()
},
]
File diff suppressed because it is too large. Load diff