root.rs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. //! Root signatures.
  2. //!
  3. //! Serializing goes to the host's `D3D12SerializeRootSignature` (or its
  4. //! versioned form): the description is laid out as on PC, and the blob it
  5. //! returns works as the console's, whose two methods sit in the same slots.
  6. //! The console's own flags (bit 24 and up) are dropped first.
  7. #![allow(clippy::not_unsafe_ptr_arg_deref)]
  8. use std::ffi::{CStr, c_void};
  9. use std::sync::OnceLock;
  10. use crate::object::{
  11. self, E_INVALIDARG, E_NOTIMPL, HRESULT, Iid, Object, ROOT_SIGNATURE, Table, This, guid,
  12. };
  13. use crate::resource::PAGEABLE_IIDS;
  14. const ROOT_SIGNATURE_IIDS: [Iid; 3] = [
  15. guid(
  16. 0xc54a6b66,
  17. 0x72df,
  18. 0x4ee8,
  19. [0x8b, 0xe5, 0xa9, 0x46, 0xa1, 0x42, 0x92, 0x14],
  20. ),
  21. PAGEABLE_IIDS[1],
  22. PAGEABLE_IIDS[2],
  23. ];
  24. const CONSOLE_FLAGS: u32 = 0xff00_0000;
  25. #[repr(C)]
  26. #[derive(Clone, Copy)]
  27. pub struct Desc {
  28. parameter_count: u32,
  29. parameters: *const c_void,
  30. sampler_count: u32,
  31. samplers: *const c_void,
  32. flags: u32,
  33. }
  34. /// Every version's description starts with the fields of [`Desc`].
  35. #[repr(C)]
  36. #[derive(Clone, Copy)]
  37. pub struct VersionedDesc {
  38. version: u32,
  39. desc: Desc,
  40. }
  41. type Serialize =
  42. unsafe extern "system" fn(*const Desc, u32, *mut *mut c_void, *mut *mut c_void) -> HRESULT;
  43. type SerializeVersioned =
  44. unsafe extern "system" fn(*const VersionedDesc, *mut *mut c_void, *mut *mut c_void) -> HRESULT;
  45. /// An export of the host's `d3d12.dll` in System32, looked up once.
  46. fn host_export(cache: &OnceLock<Option<usize>>, name: &CStr) -> Option<usize> {
  47. *cache.get_or_init(|| {
  48. #[cfg(windows)]
  49. {
  50. use windows_sys::Win32::System::LibraryLoader::{
  51. GetProcAddress, LOAD_LIBRARY_SEARCH_SYSTEM32, LoadLibraryExW,
  52. };
  53. let dll: Vec<u16> = "d3d12.dll".encode_utf16().chain([0]).collect();
  54. // SAFETY: a NUL-terminated name; System32 only.
  55. let module = unsafe {
  56. LoadLibraryExW(
  57. dll.as_ptr(),
  58. std::ptr::null_mut(),
  59. LOAD_LIBRARY_SEARCH_SYSTEM32,
  60. )
  61. };
  62. if module.is_null() {
  63. return None;
  64. }
  65. // SAFETY: a loaded module and a NUL-terminated name.
  66. unsafe { GetProcAddress(module, name.as_ptr().cast()) }.map(|f| f as usize)
  67. }
  68. #[cfg(not(windows))]
  69. None
  70. })
  71. }
  72. fn without_console_flags(desc: Desc) -> Desc {
  73. if desc.flags & CONSOLE_FLAGS != 0 {
  74. tracing::debug!(
  75. flags = format_args!("{:#x}", desc.flags),
  76. "console root signature flags dropped"
  77. );
  78. }
  79. Desc {
  80. flags: desc.flags & !CONSOLE_FLAGS,
  81. ..desc
  82. }
  83. }
  84. /// `d3d12_xs!D3D12SerializeRootSignature`.
  85. pub extern "system" fn serialize(
  86. desc: *const Desc,
  87. version: u32,
  88. blob: *mut *mut c_void,
  89. error: *mut *mut c_void,
  90. ) -> HRESULT {
  91. // SAFETY: the title passes a description (null is tolerated).
  92. let Some(&desc) = (unsafe { desc.as_ref() }) else {
  93. return E_INVALIDARG;
  94. };
  95. static FUNCTION: OnceLock<Option<usize>> = OnceLock::new();
  96. let Some(address) = host_export(&FUNCTION, c"D3D12SerializeRootSignature") else {
  97. tracing::warn!("no host d3d12.dll to serialize root signatures");
  98. return E_NOTIMPL;
  99. };
  100. // SAFETY: the export has this signature; it takes what the title passed.
  101. unsafe {
  102. std::mem::transmute::<usize, Serialize>(address)(
  103. &without_console_flags(desc),
  104. version,
  105. blob,
  106. error,
  107. )
  108. }
  109. }
  110. /// `d3d12_xs!D3D12SerializeVersionedRootSignature`.
  111. pub extern "system" fn serialize_versioned(
  112. desc: *const VersionedDesc,
  113. blob: *mut *mut c_void,
  114. error: *mut *mut c_void,
  115. ) -> HRESULT {
  116. // SAFETY: the title passes a description (null is tolerated).
  117. let Some(&desc) = (unsafe { desc.as_ref() }) else {
  118. return E_INVALIDARG;
  119. };
  120. static FUNCTION: OnceLock<Option<usize>> = OnceLock::new();
  121. let Some(address) = host_export(&FUNCTION, c"D3D12SerializeVersionedRootSignature") else {
  122. tracing::warn!("no host d3d12.dll to serialize root signatures");
  123. return E_NOTIMPL;
  124. };
  125. let desc = VersionedDesc {
  126. desc: without_console_flags(desc.desc),
  127. ..desc
  128. };
  129. // SAFETY: the export has this signature; it takes what the title passed.
  130. unsafe { std::mem::transmute::<usize, SerializeVersioned>(address)(&desc, blob, error) }
  131. }
  132. type Deserialize =
  133. unsafe extern "system" fn(*const u8, usize, *const Iid, *mut *mut c_void) -> HRESULT;
  134. /// `d3d12_xs!D3D12CreateRootSignatureDeserializer`: our blobs are the
  135. /// host's serialization, so the host's deserializer reads them, and its
  136. /// object (IUnknown, then the description getter) is laid out as the
  137. /// console's. The title's upscaler asks with the PC interface id.
  138. pub extern "system" fn create_deserializer(
  139. blob: *const u8,
  140. size: usize,
  141. iid: *const Iid,
  142. out: *mut *mut c_void,
  143. ) -> HRESULT {
  144. // The host dereferences the interface id without checking it, so a null
  145. // one is answered here instead of crashing there; an empty blob is
  146. // malformed and rejected the same way.
  147. if blob.is_null() || size == 0 || iid.is_null() || out.is_null() {
  148. return E_INVALIDARG;
  149. }
  150. static FUNCTION: OnceLock<Option<usize>> = OnceLock::new();
  151. let Some(address) = host_export(&FUNCTION, c"D3D12CreateRootSignatureDeserializer") else {
  152. tracing::warn!("no host d3d12.dll to deserialize root signatures");
  153. return E_NOTIMPL;
  154. };
  155. // SAFETY: the export has this signature; it takes what the title passed.
  156. unsafe { std::mem::transmute::<usize, Deserialize>(address)(blob, size, iid, out) }
  157. }
  158. #[repr(C)]
  159. struct RootSignature {
  160. object: Object,
  161. /// The serialized form, kept for translating pipelines later.
  162. blob: Vec<u8>,
  163. }
  164. /// Device method.
  165. pub(crate) extern "system" fn create(
  166. _: This,
  167. _nodes: u32,
  168. blob: *const u8,
  169. size: usize,
  170. iid: *const Iid,
  171. out: *mut This,
  172. ) -> HRESULT {
  173. if blob.is_null() || size == 0 {
  174. return E_INVALIDARG;
  175. }
  176. // SAFETY: the title passes `size` bytes.
  177. let blob = unsafe { std::slice::from_raw_parts(blob, size) }.to_vec();
  178. tracing::debug!(size, "root signature");
  179. let root = Box::new(RootSignature {
  180. object: Object::new(&FUNCTIONS),
  181. blob,
  182. });
  183. object::hand_out(ROOT_SIGNATURE, root, iid, &ROOT_SIGNATURE_IIDS, out)
  184. }
  185. extern "system" fn query(this: This, iid: *const Iid, out: *mut This) -> HRESULT {
  186. let found = object::is(iid, &ROOT_SIGNATURE_IIDS).then_some(this);
  187. object::answer(ROOT_SIGNATURE, iid, found, out)
  188. }
  189. extern "system" fn release(this: This) -> u32 {
  190. object::release_boxed::<RootSignature>(this)
  191. }
  192. /// IUnknown 3, object 4, device child 1.
  193. static FUNCTIONS: Table<24> = {
  194. let mut f = object::d3d12_object(object::missing_table::<ROOT_SIGNATURE, 24>());
  195. f[0] = query as *const ();
  196. f[2] = release as *const ();
  197. f[7] = object::parent_device as *const (); // 0x38
  198. Table(f)
  199. };
  200. #[cfg(test)]
  201. mod tests {
  202. use super::*;
  203. use crate::object::{E_NOINTERFACE, E_POINTER, S_FALSE, S_OK, slot};
  204. /// An interface we do not implement.
  205. const OTHER_IID: Iid = guid(0x5a5a_5a5a, 0x5a5a, 0x5a5a, [0x5a; 8]);
  206. /// The shim hands the blob to the host unchanged; `create` keeps it, so
  207. /// any bytes serve.
  208. const BLOB: [u8; 4] = [0x01, 0x02, 0x03, 0x04];
  209. fn created(iid: &Iid) -> This {
  210. let mut out = std::ptr::null();
  211. let hr = create(
  212. std::ptr::null(),
  213. 0,
  214. BLOB.as_ptr(),
  215. BLOB.len(),
  216. iid,
  217. &mut out,
  218. );
  219. assert_eq!(hr, S_OK);
  220. assert!(!out.is_null());
  221. out
  222. }
  223. /// The host's structures, field for field (64-bit layout).
  224. #[cfg(target_pointer_width = "64")]
  225. #[test]
  226. fn descriptions_keep_the_pc_layout() {
  227. assert_eq!(std::mem::size_of::<Desc>(), 40);
  228. assert_eq!(std::mem::offset_of!(Desc, parameter_count), 0);
  229. assert_eq!(std::mem::offset_of!(Desc, parameters), 8);
  230. assert_eq!(std::mem::offset_of!(Desc, sampler_count), 16);
  231. assert_eq!(std::mem::offset_of!(Desc, samplers), 24);
  232. assert_eq!(std::mem::offset_of!(Desc, flags), 32);
  233. assert_eq!(std::mem::size_of::<VersionedDesc>(), 48);
  234. assert_eq!(std::mem::offset_of!(VersionedDesc, version), 0);
  235. assert_eq!(std::mem::offset_of!(VersionedDesc, desc), 8);
  236. }
  237. #[test]
  238. fn console_flags_are_dropped_and_the_rest_kept() {
  239. assert_eq!(CONSOLE_FLAGS, 0xff00_0000);
  240. let desc = Desc {
  241. parameter_count: 2,
  242. parameters: BLOB.as_ptr().cast(),
  243. sampler_count: 1,
  244. samplers: BLOB.as_ptr().cast(),
  245. flags: 0xffff_ffff,
  246. };
  247. let plain = without_console_flags(desc);
  248. assert_eq!(plain.flags, 0x00ff_ffff);
  249. assert_eq!((plain.parameter_count, plain.sampler_count), (2, 1));
  250. assert!(std::ptr::eq(plain.parameters, desc.parameters));
  251. assert!(std::ptr::eq(plain.samplers, desc.samplers));
  252. let low = Desc {
  253. flags: 0x00ab_cdef,
  254. ..desc
  255. };
  256. assert_eq!(without_console_flags(low).flags, 0x00ab_cdef);
  257. let none = Desc { flags: 0, ..desc };
  258. assert_eq!(without_console_flags(none).flags, 0);
  259. }
  260. #[test]
  261. fn serializers_reject_a_null_description() {
  262. let mut blob = std::ptr::null_mut();
  263. let mut error = std::ptr::null_mut();
  264. assert_eq!(
  265. serialize(std::ptr::null(), 1, &mut blob, &mut error),
  266. E_INVALIDARG
  267. );
  268. assert_eq!(
  269. serialize_versioned(std::ptr::null(), &mut blob, &mut error),
  270. E_INVALIDARG
  271. );
  272. assert!(blob.is_null() && error.is_null());
  273. }
  274. /// A null `riid` used to be forwarded to the host, which dereferences it
  275. /// (an access violation in `d3d12.dll`); an empty blob is malformed.
  276. #[test]
  277. fn deserializer_creation_rejects_missing_arguments() {
  278. let iid = ROOT_SIGNATURE_IIDS[0];
  279. let mut out = std::ptr::null_mut();
  280. assert_eq!(
  281. create_deserializer(std::ptr::null(), BLOB.len(), &iid, &mut out),
  282. E_INVALIDARG
  283. );
  284. assert_eq!(
  285. create_deserializer(BLOB.as_ptr(), BLOB.len(), std::ptr::null(), &mut out),
  286. E_INVALIDARG
  287. );
  288. assert_eq!(
  289. create_deserializer(BLOB.as_ptr(), 0, &iid, &mut out),
  290. E_INVALIDARG
  291. );
  292. assert_eq!(
  293. create_deserializer(BLOB.as_ptr(), BLOB.len(), &iid, std::ptr::null_mut()),
  294. E_INVALIDARG
  295. );
  296. assert!(out.is_null());
  297. }
  298. #[test]
  299. fn creating_a_root_signature_checks_its_arguments() {
  300. let iid = ROOT_SIGNATURE_IIDS[0];
  301. let mut out = std::ptr::null();
  302. assert_eq!(
  303. create(
  304. std::ptr::null(),
  305. 0,
  306. std::ptr::null(),
  307. BLOB.len(),
  308. &iid,
  309. &mut out
  310. ),
  311. E_INVALIDARG
  312. );
  313. assert_eq!(
  314. create(std::ptr::null(), 0, BLOB.as_ptr(), 0, &iid, &mut out),
  315. E_INVALIDARG
  316. );
  317. assert!(out.is_null());
  318. // An unknown interface is dropped, and the answer is null.
  319. assert_eq!(
  320. create(
  321. std::ptr::null(),
  322. 0,
  323. BLOB.as_ptr(),
  324. BLOB.len(),
  325. &OTHER_IID,
  326. &mut out
  327. ),
  328. E_NOINTERFACE
  329. );
  330. assert!(out.is_null());
  331. assert_eq!(
  332. create(
  333. std::ptr::null(),
  334. 0,
  335. BLOB.as_ptr(),
  336. BLOB.len(),
  337. std::ptr::null(),
  338. &mut out
  339. ),
  340. E_NOINTERFACE
  341. );
  342. assert!(out.is_null());
  343. // Nowhere to write means the title only asked whether creation works.
  344. assert_eq!(
  345. create(
  346. std::ptr::null(),
  347. 0,
  348. BLOB.as_ptr(),
  349. BLOB.len(),
  350. &iid,
  351. std::ptr::null_mut()
  352. ),
  353. S_FALSE
  354. );
  355. }
  356. #[test]
  357. fn every_known_interface_creates_a_working_object() {
  358. let root = created(&ROOT_SIGNATURE_IIDS[0]);
  359. let query = slot::<extern "system" fn(This, *const Iid, *mut This) -> HRESULT>(root, 0);
  360. for iid in &ROOT_SIGNATURE_IIDS {
  361. let mut out = std::ptr::null();
  362. assert_eq!(query(root, iid, &mut out), S_OK);
  363. assert!(std::ptr::eq(out, root));
  364. assert_eq!(object::release(out), 1, "the original reference remains");
  365. }
  366. let mut out = std::ptr::null();
  367. assert_eq!(query(root, &OTHER_IID, &mut out), E_NOINTERFACE);
  368. assert!(out.is_null());
  369. assert_eq!(query(root, std::ptr::null(), &mut out), E_NOINTERFACE);
  370. assert_eq!(
  371. query(root, &ROOT_SIGNATURE_IIDS[0], std::ptr::null_mut()),
  372. E_POINTER
  373. );
  374. assert_eq!(object::release(root), 0);
  375. }
  376. #[test]
  377. fn the_table_has_the_object_and_device_child_slots() {
  378. let root = created(&ROOT_SIGNATURE_IIDS[1]);
  379. // SetPrivateDataInterface is the one object method left out.
  380. assert_eq!(
  381. slot::<extern "system" fn() -> HRESULT>(root, 0x28)(),
  382. E_NOTIMPL
  383. );
  384. assert_eq!(
  385. slot::<extern "system" fn(This, *const u16) -> HRESULT>(root, 0x30)(
  386. root,
  387. std::ptr::null()
  388. ),
  389. S_OK
  390. );
  391. // GetDevice: an unknown interface is answered, not dereferenced.
  392. let mut device = std::ptr::null();
  393. let get_device =
  394. slot::<extern "system" fn(This, *const Iid, *mut This) -> HRESULT>(root, 0x38);
  395. assert_eq!(
  396. get_device(root, std::ptr::null(), &mut device),
  397. E_NOINTERFACE
  398. );
  399. assert!(device.is_null());
  400. assert_eq!(object::release(root), 0);
  401. }
  402. /// One 32-bit constant at b0, serialized by the host, then created.
  403. #[cfg(windows)]
  404. #[test]
  405. fn host_serialized_blobs_create_root_signatures() {
  406. use windows::Win32::Graphics::Direct3D12::{
  407. D3D12_ROOT_CONSTANTS, D3D12_ROOT_PARAMETER, D3D12_ROOT_PARAMETER_0,
  408. D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS, D3D12_SHADER_VISIBILITY_ALL,
  409. };
  410. let parameter = D3D12_ROOT_PARAMETER {
  411. ParameterType: D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS,
  412. Anonymous: D3D12_ROOT_PARAMETER_0 {
  413. Constants: D3D12_ROOT_CONSTANTS {
  414. ShaderRegister: 0,
  415. RegisterSpace: 0,
  416. Num32BitValues: 1,
  417. },
  418. },
  419. ShaderVisibility: D3D12_SHADER_VISIBILITY_ALL,
  420. };
  421. let desc = Desc {
  422. parameter_count: 1,
  423. parameters: (&raw const parameter).cast(),
  424. sampler_count: 0,
  425. samplers: std::ptr::null(),
  426. flags: 0x0100_0001,
  427. };
  428. let (mut blob, mut error) = (std::ptr::null_mut(), std::ptr::null_mut());
  429. assert_eq!(serialize(&desc, 1, &mut blob, &mut error), S_OK);
  430. let blob = blob.cast_const().cast::<Object>();
  431. let data = slot::<extern "system" fn(This) -> *const u8>(blob, 0x18)(blob);
  432. let size = slot::<extern "system" fn(This) -> usize>(blob, 0x20)(blob);
  433. assert!(size > 0);
  434. let null = std::ptr::null();
  435. let mut root = null;
  436. assert_eq!(
  437. create(null, 0, data, size, &ROOT_SIGNATURE_IIDS[0], &mut root),
  438. S_OK
  439. );
  440. assert_eq!(slot::<extern "system" fn(This) -> u32>(root, 0x10)(root), 0);
  441. slot::<extern "system" fn(This) -> u32>(blob, 0x10)(blob);
  442. }
  443. /// The host's deserializer reads our blobs back (the upscaler's call).
  444. #[cfg(windows)]
  445. #[test]
  446. fn our_blobs_deserialize_on_the_host() {
  447. use windows::Win32::Graphics::Direct3D12::ID3D12RootSignatureDeserializer;
  448. use windows::core::Interface;
  449. let desc = VersionedDesc {
  450. version: 1,
  451. desc: Desc {
  452. parameter_count: 0,
  453. parameters: std::ptr::null(),
  454. sampler_count: 0,
  455. samplers: std::ptr::null(),
  456. flags: 1,
  457. },
  458. };
  459. let (mut blob, mut error) = (std::ptr::null_mut(), std::ptr::null_mut());
  460. assert_eq!(serialize_versioned(&desc, &mut blob, &mut error), S_OK);
  461. let blob = blob.cast_const().cast::<Object>();
  462. let data = slot::<extern "system" fn(This) -> *const u8>(blob, 0x18)(blob);
  463. let size = slot::<extern "system" fn(This) -> usize>(blob, 0x20)(blob);
  464. let iid: Iid = ID3D12RootSignatureDeserializer::IID.to_u128().to_be_bytes();
  465. let iid = guid(
  466. u32::from_be_bytes(iid[0..4].try_into().unwrap()),
  467. u16::from_be_bytes(iid[4..6].try_into().unwrap()),
  468. u16::from_be_bytes(iid[6..8].try_into().unwrap()),
  469. iid[8..16].try_into().unwrap(),
  470. );
  471. let mut out = std::ptr::null_mut();
  472. assert_eq!(create_deserializer(data, size, &iid, &mut out), S_OK);
  473. // SAFETY: the host handed out this interface.
  474. let deserializer = unsafe { ID3D12RootSignatureDeserializer::from_raw(out) };
  475. // SAFETY: valid while the deserializer lives.
  476. let read = unsafe { &*deserializer.GetRootSignatureDesc() };
  477. assert_eq!((read.NumParameters, read.Flags.0), (0, 1));
  478. slot::<extern "system" fn(This) -> u32>(blob, 0x10)(blob);
  479. }
  480. /// Version 1.0 through the versioned entry point, with a console flag.
  481. #[cfg(windows)]
  482. #[test]
  483. fn versioned_descriptions_serialize_on_the_host() {
  484. let desc = VersionedDesc {
  485. version: 1,
  486. desc: Desc {
  487. parameter_count: 0,
  488. parameters: std::ptr::null(),
  489. sampler_count: 0,
  490. samplers: std::ptr::null(),
  491. flags: 0x0200_0001,
  492. },
  493. };
  494. let (mut blob, mut error) = (std::ptr::null_mut(), std::ptr::null_mut());
  495. assert_eq!(serialize_versioned(&desc, &mut blob, &mut error), S_OK);
  496. let blob = blob.cast_const().cast::<Object>();
  497. assert!(slot::<extern "system" fn(This) -> usize>(blob, 0x20)(blob) > 0);
  498. slot::<extern "system" fn(This) -> u32>(blob, 0x10)(blob);
  499. assert_eq!(
  500. serialize_versioned(std::ptr::null(), &mut blob.cast_mut().cast(), &mut error),
  501. E_INVALIDARG
  502. );
  503. }
  504. /// Truncated and nonsense blobs reach the host, which rejects them
  505. /// without writing an object.
  506. #[cfg(windows)]
  507. #[test]
  508. fn malformed_blobs_are_rejected_by_the_host() {
  509. use windows::Win32::Graphics::Direct3D12::ID3D12RootSignatureDeserializer;
  510. use windows::core::Interface;
  511. let desc = VersionedDesc {
  512. version: 1,
  513. desc: Desc {
  514. parameter_count: 0,
  515. parameters: std::ptr::null(),
  516. sampler_count: 0,
  517. samplers: std::ptr::null(),
  518. flags: 1,
  519. },
  520. };
  521. let (mut blob, mut error) = (std::ptr::null_mut(), std::ptr::null_mut());
  522. assert_eq!(serialize_versioned(&desc, &mut blob, &mut error), S_OK);
  523. let blob = blob.cast_const().cast::<Object>();
  524. let data = slot::<extern "system" fn(This) -> *const u8>(blob, 0x18)(blob);
  525. let size = slot::<extern "system" fn(This) -> usize>(blob, 0x20)(blob);
  526. let iid: Iid = ID3D12RootSignatureDeserializer::IID.to_u128().to_be_bytes();
  527. let iid = guid(
  528. u32::from_be_bytes(iid[0..4].try_into().unwrap()),
  529. u16::from_be_bytes(iid[4..6].try_into().unwrap()),
  530. u16::from_be_bytes(iid[6..8].try_into().unwrap()),
  531. iid[8..16].try_into().unwrap(),
  532. );
  533. let mut out = std::ptr::null_mut();
  534. assert_eq!(
  535. create_deserializer(data, size - 1, &iid, &mut out),
  536. E_INVALIDARG
  537. );
  538. assert!(out.is_null());
  539. let garbage = [0xffu8; 64];
  540. assert_eq!(
  541. create_deserializer(garbage.as_ptr(), garbage.len(), &iid, &mut out),
  542. E_INVALIDARG
  543. );
  544. assert!(out.is_null());
  545. slot::<extern "system" fn(This) -> u32>(blob, 0x10)(blob);
  546. }
  547. }