From 37053687bd669a844946af8c09ad3d99e7408c62 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 24 Nov 2026 21:46:44 -0300 Subject: [PATCH] D3D12.X: guard truncated, null, and unreadable mesh pipeline streams --- crates/xcl/src/hle/d3d12x/real.rs | 210 ++++++++++++++++++++++++-- crates/xcl/tests/d3d12_mesh_stream.rs | 195 ++++++++++++++++++++++++ 2 files changed, 394 insertions(+), 11 deletions(-) create mode 100644 crates/xcl/tests/d3d12_mesh_stream.rs diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 49c0cd711..51dd2bc49 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -4699,9 +4699,13 @@ unsafe fn own_graphics(desc: *const c_void) -> Option { Some(OwnedDesc::Graphics(d, blobs, elems, names)) } -/// A pipeline state stream with its shaders copied. None when another subobject points at -/// title memory (input layout, stream output, view instancing). +/// A pipeline state stream with its shaders copied. None when the stream is unreadable or +/// truncated, a shader pointer is unreadable, or another subobject points at title memory +/// (input layout, stream output, view instancing). unsafe fn own_stream(desc: *const c_void) -> Option { + if !crate::gpu::shader::readable(desc as usize, 16) { + return None; + } let (size, base) = (*(desc as *const usize), *((desc as usize + 8) as *const usize)); if !crate::gpu::shader::readable(base, size) { return None; @@ -4712,21 +4716,29 @@ unsafe fn own_stream(desc: *const c_void) -> Option { while off + 8 <= size { let ty = u32::from_le_bytes(buf[off..off + 4].try_into().ok()?); let (psize, palign) = super::null::subobject_payload(ty)?; - let at = off + if palign == 8 { 8 } else { 4 }; + let at = off.checked_add(if palign == 8 { 8 } else { 4 })?; + let end = at.checked_add(psize)?; + if end > size { + return None; + } let word = |buf: &[u8], k: usize| u64::from_le_bytes(buf[at + 8 * k..at + 8 * k + 8].try_into().unwrap()); match ty { 1..=6 | 24 | 25 => { let (p, n) = (word(&buf, 0) as usize, word(&buf, 1) as usize); - if p != 0 && n != 0 && crate::gpu::shader::readable(p, n) { + if p == 0 || n == 0 { + buf[at..at + 16].fill(0); + } else if crate::gpu::shader::readable(p, n) { blobs.push(std::slice::from_raw_parts(p as *const u8, n).to_vec()); buf[at..at + 8].copy_from_slice(&(blobs.last().unwrap().as_ptr() as u64).to_le_bytes()); + } else { + return None; } } - 7 | 12 | 22 if buf[at..at + psize].iter().any(|&b| b != 0) => return None, + 7 | 12 | 22 if buf[at..end].iter().any(|&b| b != 0) => return None, 19 => buf[at..at + 16].fill(0), _ => {} } - off += ((at - off) + psize + 7) & !7; + off = end.checked_add(7)? & !7; } let d = Box::new([buf.len(), buf.as_ptr() as usize]); Some(OwnedDesc::Stream(d, buf, blobs)) @@ -5062,10 +5074,11 @@ unsafe fn finish_two_pass(this: *mut c_void, stream: &StreamOut, tp: crate::gpu: crate::xlog_info!("D3D12.X: two-pass {kind} PSO ({bytes} B DXIL) gated: {}, waited {} ms", _slot.is_some(), waited.elapsed().as_millis()); } let hr = driver_compile(kind, stream.shader_bytes(), false, || finish_pso(this, fs, desc.as_ptr() as *const c_void, riid, ppv)); - if hr < 0 { + if hr < 0 || ppv.is_null() || (*ppv).is_null() { note_translation_error(format!("the driver rejected the mesh pipeline from the console {kind} ({hr:#x})")); return E_INVALIDARG; } + let mesh_pso = *ppv; let fc: PsoFn = std::mem::transmute(orig_fn(this, slot_of(this, "CreateComputePipelineState"))); let mut cdesc = D3D12_COMPUTE_PIPELINE_STATE_DESC::default(); cdesc.pRootSignature = std::mem::transmute::<*mut c_void, std::mem::ManuallyDrop>>(rs); @@ -5112,13 +5125,13 @@ unsafe fn finish_two_pass(this: *mut c_void, stream: &StreamOut, tp: crate::gpu: drop(_slot); if hc < 0 || compute.is_null() { note_translation_error(format!("the driver rejected the compute pass of the console {kind} ({hc:#x})")); - let release: unsafe extern "system" fn(*mut c_void) -> u32 = std::mem::transmute(*(*(*ppv as *const *const usize)).add(2)); - release(*ppv); + let release: unsafe extern "system" fn(*mut c_void) -> u32 = std::mem::transmute(*(*(mesh_pso as *const *const usize)).add(2)); + release(mesh_pso); *ppv = std::ptr::null_mut(); return E_INVALIDARG; } - note_pso_rs(*ppv, mesh_rs); - TWO_PASS.lock().unwrap().get_or_insert_with(HashMap::new).insert(*ppv as usize, std::sync::Arc::new(TwoPassPso { compute: compute as usize, compute_rs: rs as usize, mesh_rs: mesh_rs as usize, record: tp.record, mesh_groups_per_record: tp.mesh_groups_per_record, kind })); + note_pso_rs(mesh_pso, mesh_rs); + TWO_PASS.lock().unwrap().get_or_insert_with(HashMap::new).insert(mesh_pso as usize, std::sync::Arc::new(TwoPassPso { compute: compute as usize, compute_rs: rs as usize, mesh_rs: mesh_rs as usize, record: tp.record, mesh_groups_per_record: tp.mesh_groups_per_record, kind })); let n = TRANSLATED_PSO.fetch_add(1, Ordering::Relaxed); if n < 5 || n % 1000 == 0 { crate::xlog_info!("D3D12.X: pipeline from the console {kind} in two passes (compute {} B + mesh {} B DXIL)", tp.cs.len(), tp.ms.len()); @@ -5520,6 +5533,26 @@ unsafe fn put(to: &mut T, from: &[u8]) { std::ptr::copy_nonoverlapping(from.as_ptr(), to as *mut T as *mut u8, n); } +/// True when a pipeline stream carries a shader subobject whose non-null, non-empty bytecode +/// pointer is not readable (handing it to D3D12Core would access-violate instead of failing). +unsafe fn stream_has_unreadable_shader(desc: *const c_void) -> bool { + if !crate::gpu::shader::readable(desc as usize, 16) { + return false; + } + let (size, base) = (*(desc as *const usize), *((desc as usize + 8) as *const usize)); + if !crate::gpu::shader::readable(base, size) { + return false; + } + let buf = std::slice::from_raw_parts(base as *const u8, size); + known_subobjects(buf).into_iter().any(|(ty, p)| { + matches!(ty, 1..=6 | 24 | 25) && p.len() >= 16 && { + let ptr = u64::from_le_bytes(p[0..8].try_into().unwrap()) as usize; + let len = u64::from_le_bytes(p[8..16].try_into().unwrap()) as usize; + ptr != 0 && len != 0 && !crate::gpu::shader::readable(ptr, len) + } + }) +} + pub(super) unsafe extern "system" fn dev_create_pipeline_state(this: *mut c_void, desc: *const c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { super::null::capture_stream_desc(desc as *const u8); let f: PsoFn = std::mem::transmute(orig_fn(this, slot_of(this, "CreatePipelineState"))); @@ -5539,6 +5572,9 @@ pub(super) unsafe extern "system" fn dev_create_pipeline_state(this: *mut c_void StreamPipeline::Compute(d) => return dev_create_compute_pso(this, &*d as *const _ as *const c_void, riid, ppv), StreamPipeline::Unknown => {} } + if stream_has_unreadable_shader(desc) { + return E_INVALIDARG; + } let hr = finish_pso(this, f, desc, riid, ppv); if hr >= 0 || !crate::gpu::shader::readable(desc as usize, 16) { return hr; @@ -6864,3 +6900,155 @@ mod map_tests { } } } + +#[cfg(test)] +mod mesh_stream_tests { + use super::*; + + #[test] + fn own_stream_rejects_null_truncated_and_unreadable_streams() { + unsafe { + // null desc pointer and empty / null stream buffer + assert!(own_stream(std::ptr::null()).is_none()); + let empty_desc: [usize; 2] = [0, 0]; + assert!(own_stream(empty_desc.as_ptr() as *const c_void).is_none()); + + // truncated shader subobject (MS = 25, align 8, payload 16 B -> needs 24 B, only 16 B given) + let mut trunc_ms = [0u8; 16]; + trunc_ms[0..4].copy_from_slice(&25u32.to_le_bytes()); + let d_trunc_ms: [usize; 2] = [trunc_ms.len(), trunc_ms.as_ptr() as usize]; + assert!(own_stream(d_trunc_ms.as_ptr() as *const c_void).is_none()); + + // truncated INPUT_LAYOUT (12, align 8, payload 16 B -> only 12 B given) + let mut trunc_il = [0u8; 12]; + trunc_il[0..4].copy_from_slice(&12u32.to_le_bytes()); + let d_trunc_il: [usize; 2] = [trunc_il.len(), trunc_il.as_ptr() as usize]; + assert!(own_stream(d_trunc_il.as_ptr() as *const c_void).is_none()); + + // truncated CACHED_PSO (19, align 8, payload 16 B -> only 16 B given) + let mut trunc_cache = [0u8; 16]; + trunc_cache[0..4].copy_from_slice(&19u32.to_le_bytes()); + let d_trunc_cache: [usize; 2] = [trunc_cache.len(), trunc_cache.as_ptr() as usize]; + assert!(own_stream(d_trunc_cache.as_ptr() as *const c_void).is_none()); + + // unreadable shader pointer in MS subobject (must not leak raw pointer into background worker) + let mut bad_ptr = [0u8; 24]; + bad_ptr[0..4].copy_from_slice(&25u32.to_le_bytes()); + bad_ptr[8..16].copy_from_slice(&0x1000u64.to_le_bytes()); + bad_ptr[16..24].copy_from_slice(&64u64.to_le_bytes()); + let d_bad: [usize; 2] = [bad_ptr.len(), bad_ptr.as_ptr() as usize]; + assert!(own_stream(d_bad.as_ptr() as *const c_void).is_none()); + + // valid stream: readable MS blob copied, zero-len stale PS pointer zeroed, CACHED_PSO zeroed + let shader = vec![0x44u8, 0x58, 0x42, 0x43, 1, 2, 3, 4]; + let mut valid = [0u8; 72]; + // [0..24]: MS (25) with readable shader + valid[0..4].copy_from_slice(&25u32.to_le_bytes()); + valid[8..16].copy_from_slice(&(shader.as_ptr() as u64).to_le_bytes()); + valid[16..24].copy_from_slice(&(shader.len() as u64).to_le_bytes()); + // [24..48]: PS (2) with non-null pointer and length 0 + valid[24..28].copy_from_slice(&2u32.to_le_bytes()); + valid[32..40].copy_from_slice(&0xDEAD_BEEFu64.to_le_bytes()); + valid[40..48].copy_from_slice(&0u64.to_le_bytes()); + // [48..72]: CACHED_PSO (19) with non-zero bytes + valid[48..52].copy_from_slice(&19u32.to_le_bytes()); + valid[56..72].fill(0xAA); + + let d_valid: [usize; 2] = [valid.len(), valid.as_ptr() as usize]; + let owned = own_stream(d_valid.as_ptr() as *const c_void).expect("valid stream"); + let OwnedDesc::Stream(_, buf, blobs) = owned else { panic!("expected Stream") }; + assert_eq!(blobs.len(), 1); + assert_eq!(blobs[0], shader); + let rebased = u64::from_le_bytes(buf[8..16].try_into().unwrap()) as usize; + assert_eq!(rebased, blobs[0].as_ptr() as usize); + assert_ne!(rebased, shader.as_ptr() as usize); + assert_eq!(&buf[32..48], &[0u8; 16], "zero-len shader entry cleared"); + assert_eq!(&buf[56..72], &[0u8; 16], "cached PSO cleared"); + } + } + + unsafe extern "system" fn fake_create_pso_null_ok( + _: *mut c_void, + _: *const c_void, + _: *const GUID, + ppv: *mut *mut c_void, + ) -> HRESULT { + if !ppv.is_null() { + *ppv = std::ptr::null_mut(); + } + S_OK + } + + unsafe extern "system" fn fake_create_compute_unexpected( + _: *mut c_void, + _: *const c_void, + _: *const GUID, + _: *mut *mut c_void, + ) -> HRESULT { + panic!("CreateComputePipelineState must not be called when mesh PSO out-pointer is null"); + } + + #[test] + fn finish_two_pass_rejects_null_mesh_out_pointer() { + let iface = layout::find("ID3D12Device2").expect("ID3D12Device2 layout"); + let pso_slot = layout::slot(iface, "CreatePipelineState").expect("CreatePipelineState slot"); + let cs_slot = layout::slot(iface, "CreateComputePipelineState").expect("CreateComputePipelineState slot"); + let mut pc = vec![0usize; iface.methods.len()]; + pc[pso_slot] = fake_create_pso_null_ok as usize; + pc[cs_slot] = fake_create_compute_unexpected as usize; + + let ext_buf = [pc.as_ptr() as usize, 0]; + let ext_vtbl = ext_buf.as_ptr() as usize + std::mem::size_of::(); + let mut fake_dev = [ext_vtbl]; + let this = fake_dev.as_mut_ptr() as *mut c_void; + + // Unique synthetic sampler key so we never touch global ABI_RS or real sampler caches. + let sampler: crate::gpu::recomp::pso::StaticSampler = ([0x55AA_1968, 0xCAFE_1968, 0xBEEF_1968, 0x0001_1968], true); + let key: Vec = sampler.0.iter().copied().chain([1u32]).collect(); + + struct Cleanup { + ext: usize, + key: Vec, + } + impl Drop for Cleanup { + fn drop(&mut self) { + CLASSES.lock().unwrap().retain(|c| c.ext != self.ext); + if let Some(m) = ABI_RS_SAMPLERS.lock().unwrap().as_mut() { + m.remove(&self.key); + } + } + } + CLASSES.lock().unwrap().push(Class { + orig: pc.as_ptr() as usize, + kind: Kind::Device, + ext: ext_vtbl, + iface, + public: iface.methods.len(), + scanned: iface.methods.len(), + }); + ABI_RS_SAMPLERS.lock().unwrap().get_or_insert_with(HashMap::new).insert(key.clone(), 0x1234_5678); + let _cleanup = Cleanup { ext: ext_vtbl, key }; + + let make_tp = || crate::gpu::recomp::pso::TwoPass { + cs: vec![0; 16], + ms: vec![0; 16], + record: crate::gpu::recomp::MsInterface { outputs: Vec::new(), threads: 32, max_vertices: 3, max_primitives: 1 }, + mesh_groups_per_record: 1, + samplers: vec![sampler], + }; + let stream = StreamOut::default(); + let iid = pc_iid(Kind::PipelineState); + + unsafe { + // Case 1: driver returns S_OK but leaves *ppv == null + let mut out: *mut c_void = std::ptr::null_mut(); + let hr = finish_two_pass(this, &stream, make_tp(), 0x1234_5678 as *mut c_void, "MS", &iid, &mut out); + assert_eq!(hr, E_INVALIDARG); + assert!(out.is_null()); + + // Case 2: caller passes ppv == null + let hr = finish_two_pass(this, &stream, make_tp(), 0x1234_5678 as *mut c_void, "MS", &iid, std::ptr::null_mut()); + assert_eq!(hr, E_INVALIDARG); + } + } +} diff --git a/crates/xcl/tests/d3d12_mesh_stream.rs b/crates/xcl/tests/d3d12_mesh_stream.rs new file mode 100644 index 000000000..d742ee26d --- /dev/null +++ b/crates/xcl/tests/d3d12_mesh_stream.rs @@ -0,0 +1,195 @@ +//! Robustness and concurrency checks for `ID3D12Device2::CreatePipelineState` +//! (`d3d12x::real::dev_create_pipeline_state` / `translated_mesh_stream`), with no game data. +//! +//! Runs on any D3D12 adapter (AMD, NVIDIA, Intel, or WARP) with zero vendor-specific skips: +//! 1. Synthetic console MS placed in the AS slot with no MS slot is refused cleanly with +//! `E_INVALIDARG` and records the `"in the AS slot – refused"` error. +//! 2. Synthetic console MS paired with an AS subobject is refused cleanly with `E_INVALIDARG`. +//! 3. Empty, truncated, unknown-subobject, and unreadable-shader pipeline streams fail cleanly +//! without panicking or crashing. +//! 4. Five worker threads submitting malformed/refused console mesh streams concurrently complete +//! without panicking or corrupting state. + +use std::ffi::c_void; +use std::sync::OnceLock; + +use windows::core::Interface; +use windows::Win32::Foundation::E_INVALIDARG; +use windows::Win32::Graphics::Direct3D12::*; + +use xcl::gpu::recomp::runner; +use xcl::hle::d3d12x::real; + +fn device2() -> Option { + static DEV: OnceLock> = OnceLock::new(); + DEV.get_or_init(|| unsafe { + if real::init().is_err() { + runner::skip_test("d3d12x::real::init failed"); + return None; + } + let raw = real::device_raw(); + let dev = ID3D12Device::from_raw_borrowed(&raw)?.clone(); + match dev.cast::() { + Ok(d2) => Some(d2), + Err(_) => { + runner::skip_test("no ID3D12Device2"); + None + } + } + }) + .clone() +} + +/// Minimal synthetic console shader DXBC container recognized by `pso::is_console` and +/// `xbox::parse` (`kind = 13` for `"MS"`, `14` for `"AS"`), with no game data. +fn synthetic_console_shader(kind: u32) -> Vec { + let dxil_size = 32u32; + let total_size = 36u32 + 8 + dxil_size; + let mut b = Vec::with_capacity(total_size as usize); + b.extend_from_slice(b"DXBC"); + b.extend_from_slice(&[0u8; 16]); // digest + b.extend_from_slice(&1u32.to_le_bytes()); + b.extend_from_slice(&total_size.to_le_bytes()); + b.extend_from_slice(&1u32.to_le_bytes()); // part count + b.extend_from_slice(&36u32.to_le_bytes()); // part 0 offset + b.extend_from_slice(b"DXIL"); + b.extend_from_slice(&dxil_size.to_le_bytes()); + let pv = (kind << 16) | 0x65; // SM 6.5 + b.extend_from_slice(&pv.to_le_bytes()); + b.extend_from_slice(&[0u8; 20]); // rest of 24-byte program header + b.extend_from_slice(b"XDAT"); + b.extend_from_slice(&0u32.to_le_bytes()); + assert!(xcl::gpu::recomp::pso::is_console(&b)); + b +} + +#[repr(C, align(8))] +struct Sub { + ty: D3D12_PIPELINE_STATE_SUBOBJECT_TYPE, + v: T, +} + +fn bytecode(b: &[u8]) -> D3D12_SHADER_BYTECODE { + D3D12_SHADER_BYTECODE { pShaderBytecode: b.as_ptr() as *const c_void, BytecodeLength: b.len() } +} + +#[test] +fn console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly() { + let Some(d2) = device2() else { return }; + let ms = synthetic_console_shader(13); + let as_blob = synthetic_console_shader(14); + assert_eq!(xcl::gpu::xbox::parse(&ms).unwrap().stage, "MS"); + assert_eq!(xcl::gpu::xbox::parse(&as_blob).unwrap().stage, "AS"); + + // Case 1: console MS placed in the AS slot with no MS slot (#1968 context path) + #[repr(C)] + struct AsOnly { + as_slot: Sub, + } + let st = AsOnly { as_slot: Sub { ty: D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS, v: bytecode(&ms) } }; + let desc = D3D12_PIPELINE_STATE_STREAM_DESC { + SizeInBytes: std::mem::size_of::(), + pPipelineStateSubobjectStream: &st as *const _ as *mut c_void, + }; + let err = unsafe { d2.CreatePipelineState::(&desc) }.expect_err("MS in AS slot must be refused"); + assert_eq!(err.code(), E_INVALIDARG); + assert!( + real::stats().translation_errors.iter().any(|e| e.contains("in the AS slot")), + "expected AS-slot refusal in translation_errors: {:?}", + real::stats().translation_errors + ); + + // Case 2: console MS paired with an AS subobject + #[repr(C)] + struct AsAndMs { + as_slot: Sub, + ms_slot: Sub, + } + let st2 = AsAndMs { + as_slot: Sub { ty: D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS, v: bytecode(&as_blob) }, + ms_slot: Sub { ty: D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS, v: bytecode(&ms) }, + }; + let desc2 = D3D12_PIPELINE_STATE_STREAM_DESC { + SizeInBytes: std::mem::size_of::(), + pPipelineStateSubobjectStream: &st2 as *const _ as *mut c_void, + }; + let err2 = unsafe { d2.CreatePipelineState::(&desc2) }.expect_err("MS + AS must be refused"); + assert_eq!(err2.code(), E_INVALIDARG); +} + +#[test] +fn malformed_and_truncated_pipeline_streams_do_not_panic_or_crash() { + let Some(d2) = device2() else { return }; + + // Empty / null stream pointer + let empty = D3D12_PIPELINE_STATE_STREAM_DESC { SizeInBytes: 0, pPipelineStateSubobjectStream: std::ptr::null_mut() }; + assert!(unsafe { d2.CreatePipelineState::(&empty) }.is_err()); + + // Truncated MS subobject (header says MS=25, only 16 bytes available instead of 24) + let mut trunc = [0u8; 16]; + trunc[0..4].copy_from_slice(&(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS.0 as u32).to_le_bytes()); + let desc_trunc = D3D12_PIPELINE_STATE_STREAM_DESC { + SizeInBytes: trunc.len(), + pPipelineStateSubobjectStream: trunc.as_mut_ptr() as *mut c_void, + }; + assert!(unsafe { d2.CreatePipelineState::(&desc_trunc) }.is_err()); + + // Unknown subobject type + let mut unknown = [0u8; 16]; + unknown[0..4].copy_from_slice(&0xBEEFu32.to_le_bytes()); + let desc_unknown = D3D12_PIPELINE_STATE_STREAM_DESC { + SizeInBytes: unknown.len(), + pPipelineStateSubobjectStream: unknown.as_mut_ptr() as *mut c_void, + }; + assert!(unsafe { d2.CreatePipelineState::(&desc_unknown) }.is_err()); + + // Unreadable shader pointer in MS subobject + let mut unreadable = [0u8; 24]; + unreadable[0..4].copy_from_slice(&(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS.0 as u32).to_le_bytes()); + unreadable[8..16].copy_from_slice(&0x1000u64.to_le_bytes()); + unreadable[16..24].copy_from_slice(&64u64.to_le_bytes()); + let desc_unreadable = D3D12_PIPELINE_STATE_STREAM_DESC { + SizeInBytes: unreadable.len(), + pPipelineStateSubobjectStream: unreadable.as_mut_ptr() as *mut c_void, + }; + assert!(unsafe { d2.CreatePipelineState::(&desc_unreadable) }.is_err()); +} + +#[test] +fn concurrent_mesh_stream_refusals_across_five_threads_survive() { + let Some(d2) = device2() else { return }; + let ms = std::sync::Arc::new(synthetic_console_shader(13)); + let mut handles = Vec::new(); + for _ in 0..5 { + let d2 = d2.clone(); + let ms = ms.clone(); + handles.push(std::thread::spawn(move || { + #[repr(C)] + struct AsOnly { + as_slot: Sub, + } + for i in 0..20 { + if i % 2 == 0 { + let st = AsOnly { as_slot: Sub { ty: D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS, v: bytecode(&ms) } }; + let desc = D3D12_PIPELINE_STATE_STREAM_DESC { + SizeInBytes: std::mem::size_of::(), + pPipelineStateSubobjectStream: &st as *const _ as *mut c_void, + }; + let err = unsafe { d2.CreatePipelineState::(&desc) }.expect_err("MS in AS slot"); + assert_eq!(err.code(), E_INVALIDARG); + } else { + let mut trunc = [0u8; 16]; + trunc[0..4].copy_from_slice(&(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS.0 as u32).to_le_bytes()); + let desc = D3D12_PIPELINE_STATE_STREAM_DESC { + SizeInBytes: trunc.len(), + pPipelineStateSubobjectStream: trunc.as_mut_ptr() as *mut c_void, + }; + assert!(unsafe { d2.CreatePipelineState::(&desc) }.is_err()); + } + } + })); + } + for h in handles { + h.join().expect("worker thread panicked"); + } +}