HydraHook
Direct3D and Core Audio hooking library for Windows
Loading...
Searching...
No Matches
HydraHookDirect3D12.h File Reference

Direct3D 12 hook callbacks. More...

#include "HydraHookCore.h"
#include <dxgi.h>
#include <d3d12.h>

Go to the source code of this file.

Classes

struct  PHYDRAHOOK_D3D12_EVENT_CALLBACKS
 Direct3D 12 event callback collection. More...

Typedefs

typedef VOID EVT_HYDRAHOOK_D3D12_PRE_PRESENT(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT Flags, PHYDRAHOOK_EVT_PRE_EXTENSION Extension)
 Pre-Present callback; receives extension with engine handle.
typedef EVT_HYDRAHOOK_D3D12_PRE_PRESENT * PFN_HYDRAHOOK_D3D12_PRE_PRESENT
typedef VOID EVT_HYDRAHOOK_D3D12_POST_PRESENT(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT Flags, PHYDRAHOOK_EVT_POST_EXTENSION Extension)
 Post-Present callback; receives extension with engine handle.
typedef EVT_HYDRAHOOK_D3D12_POST_PRESENT * PFN_HYDRAHOOK_D3D12_POST_PRESENT
typedef VOID EVT_HYDRAHOOK_D3D12_PRE_RESIZE_TARGET(IDXGISwapChain *pSwapChain, const DXGI_MODE_DESC *pNewTargetParameters, PHYDRAHOOK_EVT_PRE_EXTENSION Extension)
 Pre-ResizeTarget callback.
typedef EVT_HYDRAHOOK_D3D12_PRE_RESIZE_TARGET * PFN_HYDRAHOOK_D3D12_PRE_RESIZE_TARGET
typedef VOID EVT_HYDRAHOOK_D3D12_POST_RESIZE_TARGET(IDXGISwapChain *pSwapChain, const DXGI_MODE_DESC *pNewTargetParameters, PHYDRAHOOK_EVT_POST_EXTENSION Extension)
 Post-ResizeTarget callback.
typedef EVT_HYDRAHOOK_D3D12_POST_RESIZE_TARGET * PFN_HYDRAHOOK_D3D12_POST_RESIZE_TARGET
typedef VOID EVT_HYDRAHOOK_D3D12_PRE_RESIZE_BUFFERS(IDXGISwapChain *pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags, PHYDRAHOOK_EVT_PRE_EXTENSION Extension)
 Pre-ResizeBuffers callback.
typedef EVT_HYDRAHOOK_D3D12_PRE_RESIZE_BUFFERS * PFN_HYDRAHOOK_D3D12_PRE_RESIZE_BUFFERS
typedef VOID EVT_HYDRAHOOK_D3D12_POST_RESIZE_BUFFERS(IDXGISwapChain *pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags, PHYDRAHOOK_EVT_POST_EXTENSION Extension)
 Post-ResizeBuffers callback.
typedef EVT_HYDRAHOOK_D3D12_POST_RESIZE_BUFFERS * PFN_HYDRAHOOK_D3D12_POST_RESIZE_BUFFERS

Functions

HRESULT D3D12_DEVICE_FROM_SWAPCHAIN (IDXGISwapChain *pSwapChain, ID3D12Device **ppDevice)
HRESULT D3D12_BACKBUFFER_FROM_SWAPCHAIN (IDXGISwapChain *pSwapChain, ID3D12Resource **ppBackBuffer, UINT uBuffer=0)
 Retrieves back buffer resource from swap chain.
VOID HYDRAHOOK_D3D12_EVENT_CALLBACKS_INIT (_Out_ PHYDRAHOOK_D3D12_EVENT_CALLBACKS Callbacks)
VOID HydraHookEngineSetD3D12EventCallbacks (_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_D3D12_EVENT_CALLBACKS Callbacks)
 Registers Direct3D 12 render pipeline callbacks.
ID3D12CommandQueue * HydraHookEngineGetD3D12CommandQueue (_In_ IDXGISwapChain *pSwapChain)
 Returns the D3D12 command queue for a swap chain (for overlay rendering). Exact associations are recorded at creation and refreshed after successful ResizeBuffers1. On supported x64 DXGI builds, a late lookup can resolve the current back buffer's queue. ResizeBuffers1 can assign different queues to different buffers. Resolve the queue in the pre-present callback before submitting work for that buffer. When no exact association is available, the ExecuteCommandLists fallback is device-scoped and does not establish swap-chain ownership.
ID3D12CommandQueue * HydraHookEngineGetVerifiedD3D12CommandQueue (_In_ IDXGISwapChain *pSwapChain)
 Returns the verified direct queue for the current D3D12 back buffer.
BOOL HydraHookEngineDeferD3D12Resize (_In_ PHYDRAHOOK_EVT_PRE_EXTENSION Extension)
 Defers the active D3D12 ResizeBuffers or ResizeBuffers1 call.

Detailed Description

Direct3D 12 hook callbacks.

Defines event callbacks for Present, ResizeTarget, and ResizeBuffers with HYDRAHOOK_EVT_PRE_EXTENSION / HYDRAHOOK_EVT_POST_EXTENSION for engine access.

D3D10, D3D11, and D3D12 share unified DXGI swap-chain hooks (Present/Present1, ResizeTarget, ResizeBuffers/ResizeBuffers1) that dispatch per call to the callback table matching the swap chain's enabled device runtime.

Definition in file HydraHookDirect3D12.h.

Typedef Documentation

◆ EVT_HYDRAHOOK_D3D12_POST_PRESENT

typedef VOID EVT_HYDRAHOOK_D3D12_POST_PRESENT(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT Flags, PHYDRAHOOK_EVT_POST_EXTENSION Extension)

Post-Present callback; receives extension with engine handle.

Definition at line 67 of file HydraHookDirect3D12.h.

◆ EVT_HYDRAHOOK_D3D12_POST_RESIZE_BUFFERS

typedef VOID EVT_HYDRAHOOK_D3D12_POST_RESIZE_BUFFERS(IDXGISwapChain *pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags, PHYDRAHOOK_EVT_POST_EXTENSION Extension)

Post-ResizeBuffers callback.

Definition at line 120 of file HydraHookDirect3D12.h.

◆ EVT_HYDRAHOOK_D3D12_POST_RESIZE_TARGET

typedef VOID EVT_HYDRAHOOK_D3D12_POST_RESIZE_TARGET(IDXGISwapChain *pSwapChain, const DXGI_MODE_DESC *pNewTargetParameters, PHYDRAHOOK_EVT_POST_EXTENSION Extension)

Post-ResizeTarget callback.

Definition at line 92 of file HydraHookDirect3D12.h.

◆ EVT_HYDRAHOOK_D3D12_PRE_PRESENT

typedef VOID EVT_HYDRAHOOK_D3D12_PRE_PRESENT(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT Flags, PHYDRAHOOK_EVT_PRE_EXTENSION Extension)

Pre-Present callback; receives extension with engine handle.

Definition at line 54 of file HydraHookDirect3D12.h.

◆ EVT_HYDRAHOOK_D3D12_PRE_RESIZE_BUFFERS

typedef VOID EVT_HYDRAHOOK_D3D12_PRE_RESIZE_BUFFERS(IDXGISwapChain *pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags, PHYDRAHOOK_EVT_PRE_EXTENSION Extension)

Pre-ResizeBuffers callback.

Definition at line 104 of file HydraHookDirect3D12.h.

◆ EVT_HYDRAHOOK_D3D12_PRE_RESIZE_TARGET

typedef VOID EVT_HYDRAHOOK_D3D12_PRE_RESIZE_TARGET(IDXGISwapChain *pSwapChain, const DXGI_MODE_DESC *pNewTargetParameters, PHYDRAHOOK_EVT_PRE_EXTENSION Extension)

Pre-ResizeTarget callback.

Definition at line 80 of file HydraHookDirect3D12.h.

◆ PFN_HYDRAHOOK_D3D12_POST_PRESENT

◆ PFN_HYDRAHOOK_D3D12_POST_RESIZE_BUFFERS

◆ PFN_HYDRAHOOK_D3D12_POST_RESIZE_TARGET

◆ PFN_HYDRAHOOK_D3D12_PRE_PRESENT

◆ PFN_HYDRAHOOK_D3D12_PRE_RESIZE_BUFFERS

◆ PFN_HYDRAHOOK_D3D12_PRE_RESIZE_TARGET

Function Documentation

◆ D3D12_BACKBUFFER_FROM_SWAPCHAIN()

HRESULT D3D12_BACKBUFFER_FROM_SWAPCHAIN ( IDXGISwapChain * pSwapChain,
ID3D12Resource ** ppBackBuffer,
UINT uBuffer = 0 )
inline

Retrieves back buffer resource from swap chain.

Parameters
[in]pSwapChainValid swap chain.
[out]ppBackBufferReceives ID3D12Resource pointer.
[in]uBufferBuffer index (default 0).
Returns
S_OK on success.

Definition at line 157 of file HydraHookDirect3D12.h.

References D3D12_BACKBUFFER_FROM_SWAPCHAIN().

Referenced by D3D12_BACKBUFFER_FROM_SWAPCHAIN().

◆ D3D12_DEVICE_FROM_SWAPCHAIN()

HRESULT D3D12_DEVICE_FROM_SWAPCHAIN ( IDXGISwapChain * pSwapChain,
ID3D12Device ** ppDevice )
inline

Obtain the D3D12 device associated with a swap chain.

Parameters
[in]pSwapChainSwap chain to query for its device.
[out]ppDeviceReceives the ID3D12Device pointer; the returned interface is AddRef'd on success and must be Release'd by the caller.
Returns
S_OK on success; otherwise an HRESULT error code.

Definition at line 140 of file HydraHookDirect3D12.h.

References D3D12_DEVICE_FROM_SWAPCHAIN().

Referenced by D3D12_DEVICE_FROM_SWAPCHAIN().

◆ HYDRAHOOK_D3D12_EVENT_CALLBACKS_INIT()

VOID HYDRAHOOK_D3D12_EVENT_CALLBACKS_INIT ( _Out_ PHYDRAHOOK_D3D12_EVENT_CALLBACKS Callbacks)
inline

Initialize a HYDRAHOOK_D3D12_EVENT_CALLBACKS structure by zeroing its memory.

Parameters
[out]CallbacksPointer to the callback structure to initialize; all callback members will be set to NULL.

Definition at line 187 of file HydraHookDirect3D12.h.

References HYDRAHOOK_D3D12_EVENT_CALLBACKS_INIT().

Referenced by HYDRAHOOK_D3D12_EVENT_CALLBACKS_INIT().

◆ HydraHookEngineDeferD3D12Resize()

BOOL HydraHookEngineDeferD3D12Resize ( _In_ PHYDRAHOOK_EVT_PRE_EXTENSION Extension)

Defers the active D3D12 ResizeBuffers or ResizeBuffers1 call.

A deferred call returns DXGI_ERROR_WAS_STILL_DRAWING to the host and does not invoke the post-resize callback. The host can retry once outstanding GPU work drains.

Parameters
[in]ExtensionExtension from the active D3D12 pre-resize callback.
Returns
TRUE if deferred, or FALSE outside that callback or on another thread.

References HYDRAHOOK_API, and HydraHookEngineDeferD3D12Resize().

Referenced by HydraHookEngineDeferD3D12Resize(), and HydraHookEngineDeferD3D12Resize().

◆ HydraHookEngineGetD3D12CommandQueue()

ID3D12CommandQueue * HydraHookEngineGetD3D12CommandQueue ( _In_ IDXGISwapChain * pSwapChain)

Returns the D3D12 command queue for a swap chain (for overlay rendering). Exact associations are recorded at creation and refreshed after successful ResizeBuffers1. On supported x64 DXGI builds, a late lookup can resolve the current back buffer's queue. ResizeBuffers1 can assign different queues to different buffers. Resolve the queue in the pre-present callback before submitting work for that buffer. When no exact association is available, the ExecuteCommandLists fallback is device-scoped and does not establish swap-chain ownership.

Parameters
[in]pSwapChainThe swap chain (e.g. from Present callback).
Returns
The command queue with AddRef, or NULL if not yet captured. Caller must Release.

References HYDRAHOOK_API, and HydraHookEngineGetD3D12CommandQueue().

Referenced by HydraHookEngineGetD3D12CommandQueue(), and HydraHookEngineGetD3D12CommandQueue().

◆ HydraHookEngineGetVerifiedD3D12CommandQueue()

ID3D12CommandQueue * HydraHookEngineGetVerifiedD3D12CommandQueue ( _In_ IDXGISwapChain * pSwapChain)

Returns the verified direct queue for the current D3D12 back buffer.

Uses the exact creation or uniform resize association, or the current-buffer lookup on supported DXGI builds. Call in pre-present before submitting work.

Parameters
[in]pSwapChainThe swap chain being presented.
Returns
The queue with AddRef, or NULL when no exact association is available. Caller must Release.

References HYDRAHOOK_API, and HydraHookEngineGetVerifiedD3D12CommandQueue().

Referenced by HydraHookEngineGetVerifiedD3D12CommandQueue(), and HydraHookEngineGetVerifiedD3D12CommandQueue().

◆ HydraHookEngineSetD3D12EventCallbacks()

VOID HydraHookEngineSetD3D12EventCallbacks ( _In_ PHYDRAHOOK_ENGINE Engine,
_In_ PHYDRAHOOK_D3D12_EVENT_CALLBACKS Callbacks )

Registers Direct3D 12 render pipeline callbacks.

Parameters
[in]EngineValid engine handle.
[in]CallbacksCallback collection; NULL pointers are ignored.

References HYDRAHOOK_API, and HydraHookEngineSetD3D12EventCallbacks().

Referenced by HydraHookEngineSetD3D12EventCallbacks(), and HydraHookEngineSetD3D12EventCallbacks().