GPU: every object answers for IUnknown
No graphics object's interface list holds IUnknown, so QueryInterface for it (and every call that hands out an object by interface id) said E_NOINTERFACE and returned null. COM code asks for it to compare two pointers for identity, to keep an object as a plain reference, or to pass it on to an API that takes any object. object::is, which all of those go through, now also matches IUnknown. The DXGI device answers with the D3D12 device, which it already stands for: one pointer whichever of the object's interfaces is asked. Co-Authored-By: Claude Fable 5.2 <[email protected]> (cherry picked from commit 92f2c60c8159e34a47570aa81f3d25624cc6db5c)
This commit is contained in:
1 parent
7e4bb28d04
commit
89fb38b8cd
1 file changed
+37
-2
@@ -101,10 +101,13 @@ pub(crate) fn answer(kind: usize, iid: *const Iid, found: Option<This>, out: *mu
|
||||
hr
|
||||
}
|
||||
|
||||
/// Whether `iid` is one of `known`.
|
||||
/// `IUnknown`, which every COM object answers for.
|
||||
pub(crate) const IUNKNOWN: Iid = guid(0, 0, 0, [0xc0, 0, 0, 0, 0, 0, 0, 0x46]);
|
||||
|
||||
/// Whether `iid` is one of `known`, or `IUnknown`.
|
||||
pub(crate) fn is(iid: *const Iid, known: &[Iid]) -> bool {
|
||||
// SAFETY: the title passes an interface id (null is tolerated).
|
||||
unsafe { iid.as_ref() }.is_some_and(|i| known.contains(i))
|
||||
unsafe { iid.as_ref() }.is_some_and(|i| *i == IUNKNOWN || known.contains(i))
|
||||
}
|
||||
|
||||
/// Hands a new object to the title as one of `known`, or drops it. `T`
|
||||
@@ -381,4 +384,36 @@ mod tests {
|
||||
assert_eq!(g[..4], [0xf1, 0x19, 0x98, 0x18]);
|
||||
assert_eq!(guid_text(&g), "189819f1-1db6-4b57-be54-1821339b85f7");
|
||||
}
|
||||
|
||||
/// Every COM object answers for `IUnknown`, and with one pointer
|
||||
/// whichever of its interfaces is asked: the object's identity.
|
||||
#[test]
|
||||
fn every_object_answers_for_iunknown() {
|
||||
type Query = extern "system" fn(This, *const Iid, *mut This) -> HRESULT;
|
||||
let unknown = |object: This| {
|
||||
let mut found = std::ptr::null();
|
||||
let hr = slot::<Query>(object, 0)(object, &IUNKNOWN, &mut found);
|
||||
(hr, found)
|
||||
};
|
||||
let device = crate::device::device();
|
||||
let mut fence = std::ptr::null();
|
||||
let fence_iid = &crate::fence::FENCE_IIDS[0];
|
||||
assert_eq!(
|
||||
crate::fence::create(std::ptr::null(), 0, 0, fence_iid, &mut fence),
|
||||
S_OK
|
||||
);
|
||||
assert_eq!(unknown(device), (S_OK, device));
|
||||
assert_eq!(unknown(fence), (S_OK, fence));
|
||||
// The DXGI device is the same object as the device it answers for.
|
||||
assert_eq!(unknown(crate::dxgi::device()), (S_OK, device));
|
||||
// An id nobody has is still nobody's.
|
||||
let mut found = fence;
|
||||
let nobodys = guid(0x189819f1, 0x1db6, 0x4b57, [0xbe; 8]);
|
||||
assert_eq!(
|
||||
slot::<Query>(fence, 0)(fence, &nobodys, &mut found),
|
||||
E_NOINTERFACE
|
||||
);
|
||||
assert!(found.is_null());
|
||||
slot::<extern "system" fn(This) -> u32>(fence, 0x10)(fence);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user