2
0

query.rs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //! Query heaps. Nothing runs on a GPU yet, so no query ever produces a
  2. //! result; the heap only remembers its description.
  3. #![allow(clippy::not_unsafe_ptr_arg_deref)]
  4. use crate::object::{self, E_INVALIDARG, HRESULT, Iid, Object, QUERY_HEAP, Table, This, guid};
  5. use crate::resource::PAGEABLE_IIDS;
  6. const HEAP_IIDS: [Iid; 4] = [
  7. guid(
  8. 0x0d9658ae,
  9. 0xed45,
  10. 0x469e,
  11. [0xa6, 0x1d, 0x97, 0x0e, 0xc5, 0x83, 0xca, 0xb4],
  12. ),
  13. PAGEABLE_IIDS[0],
  14. PAGEABLE_IIDS[1],
  15. PAGEABLE_IIDS[2],
  16. ];
  17. #[repr(C)]
  18. #[derive(Debug, Clone, Copy)]
  19. pub(crate) struct Desc {
  20. kind: u32,
  21. count: u32,
  22. nodes: u32,
  23. }
  24. #[repr(C)]
  25. struct Heap {
  26. object: Object,
  27. desc: Desc,
  28. }
  29. /// Device method.
  30. pub(crate) extern "system" fn create(
  31. _: This,
  32. desc: *const Desc,
  33. iid: *const Iid,
  34. out: *mut This,
  35. ) -> HRESULT {
  36. // SAFETY: the title passes a description (null is tolerated).
  37. let Some(&desc) = (unsafe { desc.as_ref() }) else {
  38. return E_INVALIDARG;
  39. };
  40. tracing::debug!(?desc, "query heap");
  41. let heap = Box::new(Heap {
  42. object: Object::new(&FUNCTIONS),
  43. desc,
  44. });
  45. object::hand_out(QUERY_HEAP, heap, iid, &HEAP_IIDS, out)
  46. }
  47. extern "system" fn query(this: This, iid: *const Iid, out: *mut This) -> HRESULT {
  48. object::answer(
  49. QUERY_HEAP,
  50. iid,
  51. object::is(iid, &HEAP_IIDS).then_some(this),
  52. out,
  53. )
  54. }
  55. extern "system" fn release(this: This) -> u32 {
  56. object::release_boxed::<Heap>(this)
  57. }
  58. /// IUnknown 3, object 4, device child 1.
  59. static FUNCTIONS: Table<24> = {
  60. let mut f = object::d3d12_object(object::missing_table::<QUERY_HEAP, 24>());
  61. f[0] = query as *const ();
  62. f[2] = release as *const ();
  63. f[7] = object::parent_device as *const (); // 0x38
  64. Table(f)
  65. };