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

Closed
github-bot wants to merge 1 commit from gh-pr/271/head into gh-pr/271/base
Owner

@⁠Dufftwt on GitHub · 2026-11-24 01:58 UTC · original
Dufftwt:fix/get-device-any-device-level → main · +31 −3 · 3 files · 1 commits · closed without merging

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.

**@⁠Dufftwt** on GitHub · 2026-11-24 01:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/271) `Dufftwt:fix/get-device-any-device-level` → `main` · +31 −3 · 3 files · 1 commits · closed without merging ## 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.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:25 +00:00
github-bot closed this pull request 2026-11-26 03:57:25 +00:00
Author
Owner

@⁠Dufftwt on GitHub · 2026-11-24 01:58 UTC · original

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

**@⁠Dufftwt** on GitHub · 2026-11-24 01:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/271#issuecomment-7119632714) Closing as a duplicate of #249, which makes the same change (with broader tests) and was opened first.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!271
No description provided.