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

Closed
Dufftwt wants to merge 1 commit from upstream-pr/271 into main
Dufftwt commented 2026-11-24 01:58:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dufftwt on 2026-11-24T01:58:10Z.


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:

  • This PR: everything passes. victory-gpu has 44 passed (1 ignored), the other crates have 0 failed.
  • The new test alone on main: it fails on the fence's first GetDevice with a device level: left: -2147467262 (E_NOINTERFACE), right: 0.
  • I ran with --test-threads=1. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (#181, #244).

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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572863347 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/271). Originally posted by [Dufftwt](https://github.com/Dufftwt) on 2026-11-24T01:58:10Z. --- ## 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`](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12devicechild-getdevice) docs only ask for "the GUID for the device interface". COM's [`QueryInterface` rules](https://learn.microsoft.com/en-us/windows/win32/com/rules-for-implementing-queryinterface) 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`: - **This PR:** everything passes. `victory-gpu` has 44 passed (1 ignored), the other crates have 0 failed. - **The new test alone on `main`:** it fails on the fence's first `GetDevice` with a device level: `left: -2147467262` (`E_NOINTERFACE`), `right: 0`. - I ran with `--test-threads=1`. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (#181, #244). **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.
upstream-sync closed this pull request 2026-11-24 06:52:09 +00:00
Dufftwt commented 2026-11-24 06:55:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dufftwt on 2026-11-24T01:58:33Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119632714 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/271#issuecomment-7119632714). Originally posted by [Dufftwt](https://github.com/Dufftwt) on 2026-11-24T01:58:33Z. --- Closing as a duplicate of #249, which makes the same change (with broader tests) and was opened first.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!271
No description provided.