Skip to content

GPU: GetDevice and the DXGI device answer for every device interface level - #271

Closed
Dufftwt wants to merge 1 commit into
Marvisak:mainfrom
Dufftwt:fix/get-device-any-device-level
Closed

Dufftwt wants to merge 1 commit into
Marvisak:mainfrom
Dufftwt:fix/get-device-any-device-level

Conversation

@Dufftwt

@Dufftwt Dufftwt commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What's wrong

The D3D12 device answers QueryInterface for ID3D12Device and for its newer levels (device::LEVEL_IIDS: 1–8 and 11). ID3D12Device11 is the one Grand Theft Auto VI creates. Two other places hand out the same device object, but each accepts only the first IID:

  • object::parent_device: ID3D12DeviceChild::GetDevice for every device child (command queues, command lists and allocators, resources, heaps, descriptor heaps, fences, query heaps, root and command signatures).
  • dxgi::device_query: the DXGI device's QueryInterface, which "also answers for the D3D12 device".

So a title that holds an ID3D12Device11 and asks one of its objects for it gets E_NOINTERFACE and a null pointer:

fence->GetDevice(__uuidof(ID3D12Device11), &device)   -> E_NOINTERFACE, device = null
fence->GetDevice(__uuidof(ID3D12Device),   &device)   -> S_OK
device->QueryInterface(__uuidof(ID3D12Device11), ...) -> S_OK, the same object

The GetDevice docs only ask for "the GUID for the device interface". COM's QueryInterface rules also require that an object reachable through one interface answers for every interface it has. With IID_PPV_ARGS(&device11) the failure ends in a null dereference in the title.

What the fix does

device::is_device, the device's own check for its interfaces (base IID and every level), becomes pub(crate). parent_device and dxgi::device_query now use it instead of comparing against the base IID only.

How it behaves after the fix

GetDevice on any device child, and QueryInterface on the DXGI device, return the device for any interface level the device itself answers: ID3D12Device, ID3D12Device1–8 or ID3D12Device11. Other IIDs still get E_NOINTERFACE.

Tests

The new test children_and_the_dxgi_device_give_every_device_level (in device.rs):

  • creates a fence and calls its GetDevice (slot 0x38) for ID3D12Device, ID3D12Device1 and ID3D12Device11;
  • calls the DXGI device's QueryInterface (slot 0) for the same three IIDs.

Each call must return S_OK and the device.

I ran cargo test --workspace on GitHub's windows-latest with Rust 1.98.1 from rust-toolchain.toml:

Not tested: the title's own GetDevice calls.

Not in this PR: none of these objects answers IUnknown. That's a separate identity question, and nothing shows a title asking for it.

The device answers QueryInterface for ID3D12Device and its newer
levels (1-8 and 11, the last what Grand Theft Auto VI creates). Its
children's GetDevice (queues, lists, resources, heaps, fences, query
heaps, root signatures) and the DXGI device's QueryInterface only took
the first: asking them for the ID3D12Device11 the title holds gave
E_NOINTERFACE and a null pointer, though it is the same object.

Both now use the device's own test for its interfaces.
@Dufftwt

Dufftwt commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #249, which makes the same change (with broader tests) and was opened first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant