Skip to content

Choose command queue associated to swap chain in DirectX 12 hook - #209

Merged
veeenu merged 4 commits into
mainfrom
dx12-command-queue-vtable
Nov 6, 2024
Merged

veeenu merged 4 commits into
mainfrom
dx12-command-queue-vtable

Conversation

@veeenu

@veeenu veeenu commented Oct 30, 2024

Copy link
Copy Markdown
Owner

This PR changes the selection mechanism for the command queue. Whenever a command queue is detected via the ExecuteCommandLists hook, the command queue pointer is matched against the memory next to the swap chain. The assumption is that the swap chain will hold a reference to the command queue it uses. This is predicated on the fact that CreateSwapChainForHwnd accepts a command queue in DirectX 12.

A state machine enum implements the requisite logic.

Closes #203.

Create a builder-like data structure that has to have a IDXGISwapChain
set first, and a ID3D12CommandQueue set later, provided it is associated
with the previously-set swap chain. The heuristic used is to check
the first 512 pointers in the memory pointed to by the swap chain,
dereference each of them, and see if any of them matches the command queue
that gets passed in. In practice, the command queue is among the first
few pointers. A bit of extra care is given in checking for memory
readability with VirtualQuery before dereferencing. There is some
overhead but it is probably negligible, and only happens the first time
the methods are hooked, so it's way less than a frame in total.

Some concern might be raised by the fact that now we need to lock a
mutex twice per frame, but practically that will happen almost always
on the same thread and parking_lot has good performance for that case.
Besides, we already do that successfully with the Pipeline.
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.

rendering error in Black Myth

2 participants