diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 216240bd2..b5c39b455 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -4838,8 +4838,13 @@ pub fn mesh_passthrough_for(ms: &MsInterface, ps_inputs: Option<&[SigElement]>) let _ = writeln!(fill, " o.p{k} = {v};"); } let tri_base = MESH_HEADER + mv as usize * vd; + // The declaration is chosen by the vertex budget, the dispatch group count separately: + // a record over the budget in whole vertices can still fit one compact group (its few + // triangles' own copies fit) – declaring verts[mv] there is refused by DXC (80 vertices + // with 22 float4 rows are accounted as 96: 33792 B > 32768). + let cap = passthrough_max_vertices(16 * (1 + elems.len() as u32)); let split = passthrough_split(ms, elems.len()); - if split == 1 { + if mv <= cap { let _ = writeln!( h, "[outputtopology(\"triangle\")]\n[numthreads({t}, 1, 1)]\nvoid main(uint gi : SV_GroupIndex, uint3 gid : SV_GroupID, out vertices XclVert verts[{mv}], out indices uint3 tris[{mp}])\n{{" @@ -4885,15 +4890,26 @@ pub fn mesh_passthrough_for(ms: &MsInterface, ps_inputs: Option<&[SigElement]>) /// D3D12's limit on what one mesh shader group outputs (vertex + primitive attributes). const MESH_OUTPUT_BYTES: u32 = 32768; -/// Mesh groups the pass-through spends on one record: 1 when the record's vertices fit the -/// mesh output limit as they are, else the triangles are split into runs whose own vertex -/// copies (3 per triangle) fit. `elements`: output elements besides SV_Position. +/// Vertices the pass-through puts in one mesh group: the vertex output budget divided by the +/// stride, and DXC accounts whole chunks of 32 vertices even when fewer are declared (78 +/// vertices with 22 rows are accounted as 96). Measured with dxc 1.8.2502 (ms_6_6): every +/// boundary from 9 to 26 float4 rows agrees. +fn passthrough_max_vertices(vbytes: u32) -> u32 { + (MESH_OUTPUT_BYTES / vbytes).min(256) / 32 * 32 +} + +/// Mesh groups the pass-through spends on one record: the record's vertices fit the mesh +/// output limit as they are, or the triangles go out in runs whose own vertex copies (3 per +/// triangle) fit. The layout choice in `mesh_passthrough_for` is by the vertex budget alone; +/// this count is the dispatch's, and one compact group can carry a record whose whole +/// declaration would be refused. `elements`: output elements besides SV_Position. pub fn passthrough_split(ms: &MsInterface, elements: usize) -> u32 { let vbytes = 16 * (1 + elements as u32); - if vbytes * ms.max_vertices <= MESH_OUTPUT_BYTES { + let cap = passthrough_max_vertices(vbytes); + if ms.max_vertices <= cap { return 1; } - let ppg = (MESH_OUTPUT_BYTES / (3 * vbytes)).max(1); + let ppg = (cap / 3).max(1); ms.max_primitives.max(1).div_ceil(ppg) } diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 4e032b68d..5e572d9bc 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -2899,6 +2899,107 @@ fn gpu_mesh_mode_two_passes() { assert!(px16 == px, "split pass-through draws the same pixels"); } +/// The mesh output budget with wide vertices: DXC accounts whole chunks of 32 vertices even +/// when fewer are declared, so 78 vertices with 22 float4 rows are accounted as 96 (33792 B > +/// 32768) and the record must go out in split groups. A retail title's NGG transform programs +/// have this shape (128 vertices / 128 primitives, 21 params + SV_ClipDistance0); the previous +/// budget (32768 / stride) emitted verts[78] and DXC refused every one of them. +#[test] +fn mesh_split_accounts_vertex_chunks() { + use super::emit::{mesh_passthrough, passthrough_elements, passthrough_split}; + use super::MsInterface; + if super::dxc::location().is_err() { + println!("no DXC – skipping"); + runner::skip_test("no DXC"); + return; + } + let sig = |name: &str, sv: u32, reg: u32, index: u32| crate::gpu::dxbc::SigElement { + name: name.into(), + index, + system_value: sv, + component_type: 3, + register: reg, + mask: 0xF, + rw_mask: 0xF, + stream: 0, + }; + let mut outputs = vec![sig("SV_Position", 1, 0, 0)]; + for k in 0..20u32 { + outputs.push(sig("TEXCOORD", 0, k + 1, k)); + } + outputs.push(sig("SV_ClipDistance", 2, 21, 0)); + let ms = MsInterface { outputs, threads: 128, max_vertices: 128, max_primitives: 128 }; + let elems = passthrough_elements(&ms, None); + assert_eq!(elems, 21); + // 22 rows * 16 B = 352 B/vertex: 64 accounted vertices fit (96 would be 33792 B), so at + // most 21 triangles' worth of copies per group, ceil(128/21) = 7 groups of 19 + let split = passthrough_split(&ms, elems); + assert_eq!(split, 7, "chunks of 32: 78 verts are accounted as 96 and refused"); + let pass = mesh_passthrough(&ms); + assert!(pass.contains("verts[57]"), "19 triangles per group:\n{pass}"); + super::dxc::compile(&pass, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass}")); + // 20 rows * 16 B = 320 B/vertex: 96 accounted vertices fit (30720 B), but a whole record + // is 128 vertices (40960 B) – 4 groups of 32 triangles, 96 vertices each + let mut ms20 = ms.clone(); + ms20.outputs.pop(); + assert_eq!(passthrough_split(&ms20, passthrough_elements(&ms20, None)), 4); + let pass20 = mesh_passthrough(&ms20); + assert!(pass20.contains("verts[96]"), "96 vertices per group:\n{pass20}"); + super::dxc::compile(&pass20, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass20}")); + // 8 rows * 16 B = 128 B/vertex: 128 vertices are 16384 B – the record stays whole + let mut ms8 = ms.clone(); + ms8.outputs.truncate(8); + assert_eq!(passthrough_split(&ms8, passthrough_elements(&ms8, None)), 1); + let pass8 = mesh_passthrough(&ms8); + assert!(pass8.contains("verts[128]"), "whole record:\n{pass8}"); + super::dxc::compile(&pass8, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass8}")); +} + +/// The layout and the dispatch count are chosen separately: a record of 80 vertices with 22 +/// float4 rows does not fit the mesh output budget as a whole (DXC accounts 96 vertices: +/// 33792 B > 32768 B), but its single triangle's copies fit one compact group. The pass- +/// through must then declare the compact layout while `passthrough_split` returns 1, and DXC +/// accepts it (the whole-record declaration is refused). +#[test] +fn mesh_layout_independent_of_group_count() { + use super::emit::{mesh_passthrough, passthrough_elements, passthrough_split}; + use super::MsInterface; + if super::dxc::location().is_err() { + println!("no DXC – skipping"); + runner::skip_test("no DXC"); + return; + } + let sig = |name: &str, sv: u32, reg: u32, index: u32| crate::gpu::dxbc::SigElement { + name: name.into(), + index, + system_value: sv, + component_type: 3, + register: reg, + mask: 0xF, + rw_mask: 0xF, + stream: 0, + }; + let mut outputs = vec![sig("SV_Position", 1, 0, 0)]; + for k in 0..20u32 { + outputs.push(sig("TEXCOORD", 0, k + 1, k)); + } + outputs.push(sig("SV_ClipDistance", 2, 21, 0)); + // 22 rows * 16 B = 352 B/vertex: 64 accounted vertices fit; 80 declared do not + let ms = MsInterface { outputs, threads: 128, max_vertices: 80, max_primitives: 1 }; + let elems = passthrough_elements(&ms, None); + assert_eq!(elems, 21); + // one triangle: its 3 copies fit one compact group, so the dispatch count is 1 + assert_eq!(passthrough_split(&ms, elems), 1, "one triangle fits one compact group"); + let pass = mesh_passthrough(&ms); + assert!(pass.contains("verts[3]"), "the compact layout is chosen, not verts[80]:\n{pass}"); + super::dxc::compile(&pass, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass}")); + // the whole-record form is what DXC refuses at this width: the same record declared whole + // (verts[80], accounted as 96: 33792 B) does not validate + let whole = pass.replace("verts[3]", "verts[80]"); + assert!(whole.contains("verts[80]"), "the whole-record declaration for the refusal check:\n{whole}"); + assert!(super::dxc::compile(&whole, "main", "ms_6_6", &[]).is_err(), "DXC refuses 96 accounted vertices of 352 B"); +} + /// DXC optimisation levels on a saved HLSL file (`XCL_TIME_HLSL=path`, profile in `XCL_TIME_PROFILE`). #[test] #[ignore] diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 9168a5d66..5ea0f812d 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -138,6 +138,9 @@ static FALLBACK_PSO: AtomicU64 = AtomicU64::new(0); static FAILED_PSO: AtomicU64 = AtomicU64::new(0); static FALLBACK_RS: AtomicU64 = AtomicU64::new(0); static TRANSLATED_PSO: AtomicU64 = AtomicU64::new(0); +/// console MS containers moved from the AS slot and translated (logged sparsely: a title +/// creates tens of thousands of these pipelines during boot) +static AS_SLOT_MS: AtomicU64 = AtomicU64::new(0); static TRANSLATE_ERRORS: Mutex> = Mutex::new(Vec::new()); /// XCL shader ABI root signature on the backend device (raw, kept for the process lifetime) static ABI_RS: AtomicUsize = AtomicUsize::new(0); @@ -4265,6 +4268,149 @@ unsafe fn finish_two_pass(this: *mut c_void, stream: &StreamOut, tp: crate::gpu: hr } +/// The mesh and amplification shaders of a stream, as XCL translates them: a console MS +/// container in the AS slot with no MS subobject (a retail game's minimap pipelines) is the +/// mesh shader it says it is. It used to be refused – translated, the title rendered nothing +/// from then on, which was the translated mesh shaders failing their output budget (ms_6_6), +/// not the slot. With the chunk budget fixed they translate and the title keeps rendering. +/// Returns (MS to translate, AS left): the moved shader is not an AS any more. +fn mesh_shader_slots<'a>(ms_slot: Option<&'a [u8]>, as_slot: Option<&'a [u8]>) -> (Option<&'a [u8]>, Option<&'a [u8]>) { + use crate::gpu::recomp::pso::is_console; + match (ms_slot, as_slot) { + (None, Some(a)) if is_console(a) && crate::gpu::xbox::parse(a).is_some_and(|sh| sh.stage == "MS") => (Some(a), None), + (ms, a) => (ms, a), + } +} + +#[cfg(test)] +mod mesh_slot_tests { + use super::{console_ms_in_as_slot, fallback_stream, mesh_shader_slots}; + use crate::gpu::xbox::tests::{sample, fssm, CODE}; + + /// A stream subobject: its type, then the payload at 4 (align 4) or 8 (align 8). + fn sub(ty: u32, payload: &[u8]) -> Vec { + let (_, palign) = super::super::null::subobject_payload(ty).unwrap(); + let poff = if palign == 8 { 8 } else { 4 }; + let mut b = vec![0u8; (poff + payload.len() + 7) & !7]; + b[..4].copy_from_slice(&ty.to_le_bytes()); + b[poff..poff + payload.len()].copy_from_slice(payload); + b + } + + fn bytecode(s: &[u8]) -> Vec { + let mut b = Vec::new(); + b.extend_from_slice(&(s.as_ptr() as u64).to_le_bytes()); + b.extend_from_slice(&(s.len() as u64).to_le_bytes()); + b + } + + /// The stream the retail title's AS-slot MS pipelines have: a console MS container in the + /// AS subobject, no MS subobject, a PS and the graphics state (`mesh_shader_slots` moves it). + fn as_slot_ms_stream(ms: &[u8], ps: &[u8]) -> Vec { + let mut s = sub(0, &0u64.to_le_bytes()); // ROOT_SIGNATURE: null + s.extend_from_slice(&sub(24, &bytecode(ms))); + s.extend_from_slice(&sub(2, &bytecode(ps))); + s.extend_from_slice(&sub(8, &vec![0u8; 328])); // BLEND + s.extend_from_slice(&sub(9, &u32::MAX.to_le_bytes())); // SAMPLE_MASK + s.extend_from_slice(&sub(10, &vec![0u8; 44])); // RASTERIZER + s.extend_from_slice(&sub(11, &vec![0u8; 52])); // DEPTH_STENCIL + s.extend_from_slice(&sub(15, &vec![0u8; 36])); // RENDER_TARGET_FORMATS + s.extend_from_slice(&sub(17, &[1, 0, 0, 0, 0, 0, 0, 0])); // SAMPLE_DESC + s + } + + /// The stand-in for a console MS alone in the AS slot is a mesh pipeline: the subobject is + /// retyped to MS with the dummy MS (as `translated_mesh_stream` reads the title's stream), + /// the PS is the dummy PS. Left an empty AS and a PS, the stream had neither an MS nor a VS + /// and the driver refused it (E_INVALIDARG, NishantParajuli's and Chrysana's runs). + #[test] + fn the_stand_in_of_a_moved_ms_is_a_mesh_pipeline() { + let ms = sample(13, &[fssm(&CODE, &[(8, 13)])]); + let ps = b"DXBC-a-pixel-shader".to_vec(); + let stream = as_slot_ms_stream(&ms, &ps); + let desc = [stream.len(), stream.as_ptr() as usize]; + let subs = super::stream_subobjects(&stream).unwrap(); + assert!(unsafe { console_ms_in_as_slot(&subs) }); + let (buf, _) = unsafe { fallback_stream(desc.as_ptr() as *const u8) }.expect("a stand-in stream"); + let out = super::stream_subobjects(&buf).unwrap(); + assert!(!out.iter().any(|s| s.0 == 24), "no AS subobject left"); + let m = out.iter().find(|s| s.0 == 25).expect("an MS subobject"); + let dm = super::dummy_mesh().expect("DXC for the stand-in shaders"); + let got = unsafe { super::payload_shader(m.1) }.unwrap(); + assert_eq!(got, dm.0.as_slice(), "the dummy MS"); + let p = out.iter().find(|s| s.0 == 2).unwrap(); + assert_eq!(unsafe { super::payload_shader(p.1) }.unwrap(), dm.1.as_slice(), "the dummy PS"); + // a real AS with no MS is not moved, and its stand-in keeps the AS slot empty + let as_ = sample(14, &[fssm(&CODE, &[(8, 14)])]); + let stream = as_slot_ms_stream(&as_, &ps); + let desc = [stream.len(), stream.as_ptr() as usize]; + assert!(!unsafe { console_ms_in_as_slot(&super::stream_subobjects(&stream).unwrap()) }); + let (buf, _) = unsafe { fallback_stream(desc.as_ptr() as *const u8) }.unwrap(); + let out = super::stream_subobjects(&buf).unwrap(); + assert!(out.iter().any(|s| s.0 == 24) && !out.iter().any(|s| s.0 == 25)); + } + + /// The stand-in's target formats are the PC's, as the real pipeline's: the console's + /// D16_UNORM_S8_UINT (118) is D24_UNORM_S8_UINT (45) and a B4G4R4A4 target (115) is + /// R8G8B8A8 (28). With the console's the driver refuses the stand-in (the title's depth-only + /// mesh pipelines; NishantParajuli's follow-up, reproduced natively by thehollowedone). + #[test] + fn the_stand_in_of_a_stream_has_the_pcs_target_formats() { + let mut s = sub(15, &{ + let mut p = Vec::new(); + for f in [115u32, 28, 0, 0, 0, 0, 0, 0, 2] { + p.extend_from_slice(&f.to_le_bytes()); + } + p + }); + s.extend_from_slice(&sub(16, &118u32.to_le_bytes())); + let desc = [s.len(), s.as_ptr() as usize]; + let (out, _) = unsafe { fallback_stream(desc.as_ptr() as *const u8) }.expect("a stand-in stream"); + let subs = super::stream_subobjects(&out).unwrap(); + let word = |p: &[u8], k: usize| u32::from_le_bytes(p[4 * k..4 * k + 4].try_into().unwrap()); + assert_eq!((subs[0].0, word(subs[0].1, 0), word(subs[0].1, 1), word(subs[0].1, 8)), (15, 28, 28, 2)); + assert_eq!((subs[1].0, word(subs[1].1, 0)), (16, 45)); + } + + /// A console MS container alone in the AS slot becomes the MS; a real AS (console or PC), + /// an MS already present, or a PC shader in the AS slot are left as they are. + #[test] + fn a_console_ms_in_the_as_slot_is_the_mesh_shader() { + let ms = sample(13, &[fssm(&CODE, &[(8, 13)])]); + let as_ = sample(14, &[fssm(&CODE, &[(8, 14)])]); + let pc = b"DXBC-not-a-console-container".to_vec(); + // MS in the AS slot, no MS: moved, and not an AS any more + let (m, a) = mesh_shader_slots(None, Some(&ms)); + assert!(m.is_some_and(|m| std::ptr::eq(m, ms.as_slice())) && a.is_none()); + // an MS present: both slots untouched, whatever the AS holds + let (m, a) = mesh_shader_slots(Some(&ms), Some(&as_)); + assert!(m.is_some_and(|m| std::ptr::eq(m, ms.as_slice())) && a.is_some_and(|a| std::ptr::eq(a, as_.as_slice()))); + // a console AS (not an MS) stays in the AS slot + let (m, a) = mesh_shader_slots(None, Some(&as_)); + assert!(m.is_none() && a.is_some_and(|a| std::ptr::eq(a, as_.as_slice()))); + // a PC shader in the AS slot stays too + let (m, a) = mesh_shader_slots(None, Some(&pc)); + assert!(m.is_none() && a.is_some()); + // nothing: nothing + assert!(mesh_shader_slots(None, None) == (None, None)); + } + + /// The cached-only attempt defers a moved MS like a console compute pipeline: `defer` + /// marks the attempt missed, so `dev_create_pipeline_state` takes the background path + /// (stand-in now, translation on the worker / first bind) instead of translating on the + /// title's thread – tens of thousands of these pipelines during boot delayed the intro + /// by seconds on NVIDIA and past a minute on AMD wave64. Outside the attempt (the + /// worker's build) nothing is deferred. + #[test] + fn a_moved_ms_defers_in_the_attempt_only() { + let (_, missed) = crate::gpu::recomp::dxc::cached_only(|| { + assert!(crate::gpu::recomp::dxc::defer(), "inside the attempt: deferred"); + }); + assert!(missed, "the attempt is missed: the caller takes the background path"); + assert!(!crate::gpu::recomp::dxc::defer(), "outside: the build translates"); + } +} + /// CreatePipelineState with a console MS: Some(hr) when it was a console mesh pipeline /// (translated, or E_INVALIDARG – console bytecode must not reach the driver). unsafe fn translated_mesh_stream(this: *mut c_void, desc: *const c_void, riid: *const GUID, ppv: *mut *mut c_void) -> Option { @@ -4279,17 +4425,11 @@ unsafe fn translated_mesh_stream(this: *mut c_void, desc: *const c_void, riid: * let subs = stream_subobjects(std::slice::from_raw_parts(base as *const u8, size))?; let as_slot = subs.iter().find(|s| s.0 == D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS.0 as u32).and_then(|s| payload_shader(s.1)); let ms_slot = subs.iter().find(|s| s.0 == D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS.0 as u32).and_then(|s| payload_shader(s.1)); - // A console MS container in the AS slot and no MS subobject (a retail game's minimap - // pipelines): refused. Translated as the mesh shader they are, the title rendered nothing - // from then on (a black screen every run); refused, it goes on to its menus. What it - // expects of them is not known yet. - if let (None, Some(a)) = (ms_slot, as_slot) { - if is_console(a) && crate::gpu::xbox::parse(a).is_some_and(|sh| sh.stage == "MS") { - note_translation_error(format!("mesh pipeline with its MS {:016x} in the AS slot – refused", crate::gpu::shader::fnv64(a))); - return Some(E_INVALIDARG); - } - } - let ms = ms_slot?; + // a console MS in the AS slot with no MS subobject: moved, and translated when first + // bound (below), not on the title's thread for each of tens of thousands + let moved = ms_slot.is_none(); + let (ms, as_slot) = mesh_shader_slots(ms_slot, as_slot); + let Some(ms) = ms else { return None }; if !is_console(ms) { return None; } @@ -4302,6 +4442,21 @@ unsafe fn translated_mesh_stream(this: *mut c_void, desc: *const c_void, riid: * )); return Some(E_INVALIDARG); } + // In the cached-only attempt (non-blocking creation) a moved MS is not translated here: + // the title creates tens of thousands of these during boot and uses few; translating each + // on the calling thread delayed the intro by seconds (NVIDIA) or past a minute (AMD wave64, + // the split path). Made when first bound (`pso_async::lazy`), like a console compute + // pipeline: the attempt defers, `go_background` hands the title a stand-in and the worker + // (or the bind) runs this path again outside cached-only. + if moved && super::pso_async::lazy() && crate::gpu::recomp::dxc::defer() { + return Some(E_INVALIDARG); + } + if moved { + let n = AS_SLOT_MS.fetch_add(1, Ordering::Relaxed); + if n < 5 || n % 1000 == 0 { + crate::xlog_info!("D3D12.X: mesh pipeline with its MS {:016x} in the AS slot – translated as MS (#{})", crate::gpu::shader::fnv64(ms), n + 1); + } + } let ps = subs.iter().find(|s| s.0 == D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS.0 as u32).and_then(|s| payload_shader(s.1)); let (tp, (ps, ps_samplers)) = match (console_mesh(ms, ps, wave32_only(this)), two_pass_ps(ps, graphics_wave32(this))) { (Ok(tp), Ok(ps)) => (tp, ps), @@ -4413,6 +4568,13 @@ unsafe fn translated_gs_pso(this: *mut c_void, d: &D3D12_GRAPHICS_PIPELINE_STATE finish_two_pass(this, &out, tp, rs, "GS", riid, ppv) } +/// A console MS container in the stream's AS subobject and no MS subobject (`mesh_shader_slots`). +unsafe fn console_ms_in_as_slot(subs: &[(u32, &[u8])]) -> bool { + let shader = |ty: i32| subs.iter().find(|s| s.0 == ty as u32).and_then(|s| payload_shader(s.1)); + shader(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS.0).is_none() + && shader(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS.0).is_some_and(|a| crate::gpu::recomp::pso::is_console(a) && crate::gpu::xbox::parse(a).is_some_and(|sh| sh.stage == "MS")) +} + /// Rewrite a pipeline state stream with stand-in shaders. None if not possible. unsafe fn fallback_stream(desc: *const u8) -> Option<(Vec, [usize; 2])> { let size = *(desc as *const usize); @@ -4422,7 +4584,12 @@ unsafe fn fallback_stream(desc: *const u8) -> Option<(Vec, [usize; 2])> { } let mut buf = std::slice::from_raw_parts(base as *const u8, size).to_vec(); let d = dummy(); - let mesh = stream_subobjects(&buf).is_some_and(|subs| subs.iter().any(|s| s.0 == D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS.0 as u32)); + // A console MS alone in the AS slot is the stream's mesh shader (`mesh_shader_slots`), so its + // stand-in is a mesh pipeline too, with the dummy MS in that subobject as an MS. Left an AS + // without a shader, the stream had a PS and neither an MS nor a VS: the driver refused it + // (E_INVALIDARG) and every such pipeline was built in the title's call (NishantParajuli). + let ms_in_as = stream_subobjects(&buf).is_some_and(|subs| console_ms_in_as_slot(&subs)); + let mesh = ms_in_as || stream_subobjects(&buf).is_some_and(|subs| subs.iter().any(|s| s.0 == D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS.0 as u32)); let dm = if mesh { Some(dummy_mesh()?) } else { None }; let mut off = 0usize; while off + 8 <= size { @@ -4441,8 +4608,22 @@ unsafe fn fallback_stream(desc: *const u8) -> Option<(Vec, [usize; 2])> { 1 => put(&mut buf, &d.vs), 2 => put(&mut buf, dm.map_or(&d.ps[..], |m| &m.1[..])), 6 => put(&mut buf, &d.cs), + 24 if ms_in_as => { + buf[off..off + 4].copy_from_slice(&(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS.0 as u32).to_le_bytes()); + put(&mut buf, &dm?.0) + } 3 | 4 | 5 | 24 => put(&mut buf, &[]), 25 => put(&mut buf, &dm?.0), + // RENDER_TARGET_FORMATS, DEPTH_STENCIL_FORMAT: the console's formats as the PC's, as + // the real pipeline gets them (`translated_mesh_stream`) – with a console-only one + // (a retail game's depth-only mesh pipelines: D16_UNORM_S8_UINT) the driver refuses + // the stand-in (E_INVALIDARG) and the pipeline is built in the title's call + 15 | 16 => { + for k in 0..if ty == 15 { 8 } else { 1 } { + let f = super::device_x::pc_target_format(u32::from_le_bytes(buf[at + 4 * k..at + 4 * k + 4].try_into().ok()?)); + buf[at + 4 * k..at + 4 * k + 4].copy_from_slice(&f.to_le_bytes()); + } + } 12 | 19 => buf[at..at + 16].fill(0), // input layout, cached PSO 7 => buf[at..at + 32].fill(0), // stream output _ => {}