diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..47e65b4a6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build-and-test: + name: Build & Test (Windows x64) + runs-on: windows-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: x86_64-pc-windows-msvc + components: clippy, rustfmt + + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + + - name: Check code formatting + run: cargo fmt --check + + - name: Cargo check (workspace) + run: cargo check --workspace --all-targets + + - name: Cargo clippy (workspace) + run: cargo clippy --workspace --all-targets -- -D warnings + + - name: Cargo test (workspace) + run: cargo test --workspace -- --test-threads=4 diff --git a/HANDOFF.md b/HANDOFF.md index 62998ebda..01748a05b 100644 --- a/HANDOFF.md +++ b/HANDOFF.md @@ -1775,6 +1775,21 @@ to an outside server at every crash (`hle/netoff.rs`: the title's WinHTTP / Wins 4 GiB window – a redesign of how shaders reach title memory. - XDefiant, Fortnite, Unicorn Overlord and Minecraft were **not** run after these changes (only the test suites). +- **Retail GTA 6 bring-up (Series 1.0.2.1, `RockstarGamesInc.28872443D20A7`) – First-run report analysis & fixes (2026-11-23)**: + - First-run outcome: game boots, VFS loads package RPFs, 8 game DLLs load (0 unresolved imports, `XMemIsToolsMemAvailable` stubbed), + D3D12.X device on AMD Radeon RX 6600 (8146 MiB VRAM), UMA 512 MB (66112 KB used), 4,518 unique shaders seen (4,407 xbox-native), + 16,131,755 RDNA2 instructions decoded (0 undecoded dwords), 50,597 pipelines translated, 2 presents before crash at `game_scarlett_master.exe+0x2215c35`. + - **Crash at `+0x2215c35` (write at address 0x0)**: + - Root cause: title calls `xg_xs.dll: XGTextureAddressComputer::#10` 179 times during startup (`+0x344287`). The method was an auto-generated stub returning `E_NOTIMPL` (`0x80004001`). The game expected subresource layout or subresource offset, leaving internal texture descriptor pointers null (`rbx=0`), leading to deterministic write to null right after the 2nd present. + - Fix (`hle/xg.rs`): routed slots 10 & 11 in `vtbl()` to `get_subresource_info`, which supports both `GetSubresourceLayout(plane, sub, outLayout)` (writing the 0x70-byte `XG_SUBRESOURCE_LAYOUT` struct) and `GetSubresourceOffsetBytes(plane, sub) / (sub)` returning the byte offset in `rax`. Added `subresource_offset`, `write_subresource_layout`, and unit test `subresource_layout_and_offset`. + - **620 Rejected Graphics PSOs (`0x80070057; topology type 3, 2 render targets, DSV format 118`)**: + - Root cause: format 118 is `DXGI_FORMAT_D16_UNORM_S8_UINT` in the Xbox GDK. Desktop PC D3D12 drivers (including AMD RDNA2) reject this format as `E_INVALIDARG` (`0x80070057`) when passed in `D3D12_GRAPHICS_PIPELINE_STATE_DESC.DSVFormat`. + - Fix (`hle/d3d12x/real.rs`): in `pc_topology_type()`, remapped `DSVFormat == 118` to `DXGI_FORMAT_D24_UNORM_S8_UINT` (45), which PC hardware supports. In `translated_graphics_pso()`, added an automatic fallback retry with `DXGI_FORMAT_D32_FLOAT_S8X24_UINT` (20) if the driver rejects format 45. + - **Command Queue Slot #35 (5 calls from `+0x248268f`)**: + - Extended `queue_slots!` macro to include slot 35 (14..=35), routing calls through `queue_dispatch` with proper frame pacing and logging. + - **Mesh pipeline stream disambiguation (`hle/d3d12x/real.rs`)**: + - Handled console stream AS slot (24) holding MS containers (`MSNC_VS_TransformUnlit_*`, NGG) by falling back to MS when AS is rejected or MS subobject is absent. + ## Next steps (priority) Little is left to do without the exe – the rest needs an actual run of the game. 1. Once the user has a legal game exe: `xcl inspect`, `xcl run`, analysis of `report.json` diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 408901615..721e8c832 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -2968,7 +2968,11 @@ unsafe fn translated_graphics_pso(this: *mut c_void, f: PsoFn, desc: *const c_vo if debug_pso_switch("XCL_DEBUG_NO_CULL", ps_hash) { copy.RasterizerState.CullMode = D3D12_CULL_MODE_NONE; } - let hr = finish_pso(this, f, © as *const _ as *const c_void, riid, ppv); + let mut hr = finish_pso(this, f, © as *const _ as *const c_void, riid, ppv); + if hr < 0 && copy.DSVFormat.0 == 45 { + copy.DSVFormat = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(20); + hr = finish_pso(this, f, © as *const _ as *const c_void, riid, ppv); + } if hr < 0 { note_translation_error(format!( "the driver rejected the PSO with the translated shaders ({hr:#x}; topology type {}, {} render targets, DSV format {}, HS {}, GS {})", @@ -3258,7 +3262,11 @@ pub(super) unsafe extern "system" fn dev_create_graphics_pso(this: *mut c_void, copy.InputLayout = D3D12_INPUT_LAYOUT_DESC::default(); copy.CachedPSO = D3D12_CACHED_PIPELINE_STATE::default(); pc_topology_type(&mut copy); - let hr2 = finish_pso(this, f, © as *const _ as *const c_void, riid, ppv); + let mut hr2 = finish_pso(this, f, © as *const _ as *const c_void, riid, ppv); + if hr2 < 0 && copy.DSVFormat.0 == 45 { + copy.DSVFormat = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(20); + hr2 = finish_pso(this, f, © as *const _ as *const c_void, riid, ppv); + } note_fallback("graphics PSO", hr, hr2 >= 0); if hr2 >= 0 { hr2 @@ -3629,6 +3637,11 @@ fn pc_topology_type(g: &mut D3D12_GRAPHICS_PIPELINE_STATE_DESC) { if !(1..=4).contains(&g.PrimitiveTopologyType.0) { g.PrimitiveTopologyType = if g.HS.pShaderBytecode.is_null() { D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE } else { D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH }; } + // Format 118 is DXGI_FORMAT_D16_UNORM_S8_UINT on Xbox GDK, which desktop PC drivers reject (0x80070057). + // Remap to DXGI_FORMAT_D24_UNORM_S8_UINT (45) which is supported on PC hardware. + if g.DSVFormat.0 == 118 { + g.DSVFormat = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(45); + } } enum StreamPipeline { diff --git a/crates/xcl/src/hle/xg.rs b/crates/xcl/src/hle/xg.rs index 234f96492..271607c03 100644 --- a/crates/xcl/src/hle/xg.rs +++ b/crates/xcl/src/hle/xg.rs @@ -473,7 +473,7 @@ struct Computer { fn vtbl() -> &'static [usize] { static V: OnceLock<&'static [usize]> = OnceLock::new(); V.get_or_init(|| { - let mut v = vec![ + let v = vec![ add_ref as usize, release as usize, get_resource_layout as usize, @@ -484,11 +484,9 @@ fn vtbl() -> &'static [usize] { not_implemented as usize, copy_into as usize, copy_from as usize, + get_subresource_info as usize, + get_subresource_info as usize, ]; - for i in v.len()..12 { - let (stub, _) = crate::stubs::make_stub_info("xg_xs.dll", &format!("XGTextureAddressComputer::#{i}"), E_NOTIMPL as u32 as u64); - v.push(stub); - } Box::leak(v.into_boxed_slice()) }) } @@ -648,6 +646,90 @@ unsafe extern "system" fn copy_from(p: *mut c_void, dst: *mut u8, plane: u32, su S_OK } +/// The byte offset of a subresource (plane, subresource = mip + slice * mips) from the start of the resource. +pub fn subresource_offset(t: &Texture, plane: u32, sub: u32) -> Option { + let (s, at, i, k) = subresource(t, plane, sub)?; + Some(at + k as u64 * s.chain.slice_bytes as u64 + s.mip_offset(i)) +} + +/// Writes `XG_SUBRESOURCE_LAYOUT` (0x70 bytes) for a subresource. +pub fn write_subresource_layout(t: &Texture, plane: u32, sub: u32, out: &mut [u8]) -> bool { + let Some((s, at, i, k)) = subresource(t, plane, sub) else { return false }; + if out.len() < 0x20 { return false; } + let len = out.len().min(MIP_BYTES); + out[..len].fill(0); + let m = &s.chain.levels[i]; + let tail = i >= s.first_tail; + let (pw, ph) = s.padded(i); + let bytes = (pw * ph) as u64 * s.bpe as u64; + let (slices, padded_slices) = s.slices(i); + let total_bytes = if s.depth > 0 { bytes * padded_slices as u64 } else { bytes }; + let sub_offset = at + k as u64 * s.chain.slice_bytes as u64 + s.mip_offset(i); + let row_pitch = pw as u32 * s.bpe; + + let q = |b: &mut [u8], o: usize, v: u64| { if o + 8 <= b.len() { b[o..o + 8].copy_from_slice(&v.to_le_bytes()); } }; + let w = |b: &mut [u8], o: usize, v: u32| { if o + 4 <= b.len() { b[o..o + 4].copy_from_slice(&v.to_le_bytes()); } }; + + q(out, 0, total_bytes); + q(out, 8, sub_offset); + q(out, 0x10, bytes); + w(out, 0x18, pw as u32 * s.side); + w(out, 0x1C, row_pitch); + w(out, 0x20, if tail { 0x100 } else { s.alignment() as u32 }); + w(out, 0x24, pw as u32); + w(out, 0x28, ph as u32); + w(out, 0x2C, padded_slices); + w(out, 0x30, m.width as u32); + w(out, 0x34, m.height as u32); + w(out, 0x38, (s.width >> i).max(1)); + w(out, 0x3C, (s.height >> i).max(1)); + w(out, 0x40, slices); + w(out, 0x44, 1); + // the tail is in 256-byte tiles of the same kind (S 1, D 2, R 3; Z keeps its mode) + w(out, 0x48, if tail && !s.mode.is_multiple_of(4) { s.mode % 4 } else { s.mode }); + if !tail && (24..=27).contains(&s.mode) { + w(out, 0x50, 0x8000); + w(out, 0x58, 0x8000); + } + w(out, 0x60, s.chain.layout.block_d as u32); + w(out, 0x64, tail as u32); + true +} + +/// XGTextureAddressComputer methods #10 & #11: +/// - `GetSubresourceLayout(plane, sub, outLayout) -> HRESULT` +/// - `GetSubresourceLayout(sub, outLayout) -> HRESULT` +/// - `GetSubresourceOffsetBytes(plane, sub) -> u64` +/// - `GetSubresourceOffsetBytes(sub) -> u64` +unsafe extern "system" fn get_subresource_info(p: *mut c_void, a1: u64, a2: u64, a3: *mut u8) -> u64 { + let t = tex(p); + let is_ptr = |ptr: usize| ptr >= 0x1_0000 && ptr < 0x8000_0000_0000; + let (plane, sub, out_ptr) = if is_ptr(a3 as usize) { + (a1 as u32, a2 as u32, Some(a3)) + } else if is_ptr(a2 as usize) { + (0, a1 as u32, Some(a2 as *mut u8)) + } else if subresource(t, a1 as u32, a2 as u32).is_some() { + (a1 as u32, a2 as u32, None) + } else { + (0, a1 as u32, None) + }; + + let Some(off) = subresource_offset(t, plane, sub) else { + return if out_ptr.is_some() { E_INVALIDARG as u32 as u64 } else { 0 }; + }; + + if let Some(out) = out_ptr { + if !crate::gpu::shader::readable(out as usize, 0x20) { + return E_POINTER as u32 as u64; + } + let buf = std::slice::from_raw_parts_mut(out, MIP_BYTES); + write_subresource_layout(t, plane, sub, buf); + return S_OK as u32 as u64; + } + + off +} + #[cfg(test)] mod tests { use super::*; @@ -680,4 +762,20 @@ mod tests { assert_eq!((mip(2, 0), mip(2, 9), mip(2, 10), mip(2, 18), mip(6, 9), mip(6, 10)), (0x8000, 0x40, 0x80, 1, 8, 8)); assert_eq!(optimal_mode(0, 0, 32, 256, 256), 5); } + + #[test] + fn subresource_layout_and_offset() { + let t = Texture::new(&desc(256, 256, 1, 0, 28, 0x109)).unwrap(); + assert_eq!(subresource_offset(&t, 0, 0), Some(0x20000)); + assert_eq!(subresource_offset(&t, 0, 1), Some(0x10000)); + assert_eq!(subresource_offset(&t, 0, 2), Some(0x8000)); + + let mut layout = [0u8; MIP_BYTES]; + assert!(write_subresource_layout(&t, 0, 2, &mut layout)); + let q = |o: usize| u64::from_le_bytes(layout[o..o + 8].try_into().unwrap()); + let w = |o: usize| u32::from_le_bytes(layout[o..o + 4].try_into().unwrap()); + assert_eq!(q(8), 0x8000); + assert_eq!(w(0x30), 64); + assert_eq!(w(0x34), 64); + } }