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.

@Dufftwt Dufftwt closed this Nov 24, 2026
titilyonnais added a commit to titilyonnais/VIctory that referenced this pull request Nov 26, 2026
…shapes kept from filling up; freed copies not kept 300 s near the commit limit

From avatarmanz/VIctory-7900XTX#206, Marvisak#271 and the simple leak fixes of Marvisak#229:
- ram.rs: the PC's memory asked at most once a second (this branch has no
  residency module): short below 3 GiB free RAM or 4 GiB commit, out again
  above 5 / 6; near the commit limit at 70 % of the smaller of RAM and
  commit limit in private bytes. VICTORY_RAM_PRESSURE=0 turns it all off,
  VICTORY_NEAR_COMMIT=0 the commit-limit rule alone.
- Idle host copies of textures go after 5 s while the PC is short.
- On a PC of 32 GB or less at most 12 empty texture blocks are kept, not 64.
- Freed system-RAM copies are not kept five minutes near the commit limit.
- Placed views: padding words zeroed (VICTORY_PLACED_PADDING=1 keeps them),
  the shape index keyed by hash, not by a second copy of each shape.
- Shared preludes, opt-in (VICTORY_SHARED_PRELUDE=1): off by default here,
  as this branch takes host lists back at their reset.
- dstorage: no handle or queue leaked on a null out; file names kept only
  for the walls trace. net: at most 256 blocked destinations remembered.
  xgamesave: a provider refused by XAsyncBegin is freed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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