mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-05-06 09:40:54 +00:00
Added more D3D12 device hook points
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
|
||||
#include <detours/detours.h>
|
||||
|
||||
#include <d3d12.h>
|
||||
#include <dxgi1_6.h>
|
||||
|
||||
#pragma intrinsic(_ReturnAddress)
|
||||
@@ -44,9 +43,6 @@ typedef HRESULT (*PFN_D3D12GetInterface)(REFCLSID rclsid, REFIID riid, void** pp
|
||||
typedef HRESULT (*PFN_CreateDevice)(ID3D12DeviceFactory* pFactory, IUnknown* adapter, D3D_FEATURE_LEVEL FeatureLevel,
|
||||
REFIID riid, void** ppvDevice);
|
||||
|
||||
typedef HRESULT(WINAPI* PFN_D3D12SerializeVersionedRootSignature)(
|
||||
const D3D12_VERSIONED_ROOT_SIGNATURE_DESC* pRootSignature, ID3DBlob** ppBlob, ID3DBlob** ppErrorBlob);
|
||||
|
||||
typedef ULONG (*PFN_Release)(IUnknown* This);
|
||||
|
||||
static PFN_CreateSampler o_CreateSampler = nullptr;
|
||||
@@ -1014,3 +1010,5 @@ void D3D12Hooks::Unhook()
|
||||
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
void D3D12Hooks::HookDevice(ID3D12Device* device) { HookToDevice(device); }
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
|
||||
#include <pch.h>
|
||||
|
||||
#include <d3d12.h>
|
||||
|
||||
class D3D12Hooks
|
||||
{
|
||||
public:
|
||||
static void Hook();
|
||||
static void HookAgility(HMODULE module);
|
||||
static void HookDevice(ID3D12Device* device);
|
||||
static void Unhook();
|
||||
};
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <Config.h>
|
||||
|
||||
#include "D3D12_Hooks.h"
|
||||
|
||||
#include <spoofing/Dxgi_Spoofing.h>
|
||||
#include <wrapped/wrapped_swapchain.h>
|
||||
|
||||
@@ -258,6 +260,21 @@ HRESULT DxgiFactoryHooks::CreateSwapChain(IDXGIFactory* realFactory, IUnknown* p
|
||||
{
|
||||
cq->Release();
|
||||
|
||||
if (State::Instance().currentD3D12Device == nullptr)
|
||||
{
|
||||
ID3D12Device* device = nullptr;
|
||||
if (cq->GetDevice(IID_PPV_ARGS(&device)) == S_OK)
|
||||
{
|
||||
if (device != nullptr)
|
||||
{
|
||||
State::Instance().currentD3D12Device = device;
|
||||
LOG_INFO("Captured D3D12 device from command queue: {:X}", (UINT64) device);
|
||||
D3D12Hooks::HookDevice(State::Instance().currentD3D12Device);
|
||||
device->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Util::CheckForRealObject(__FUNCTION__, cq, &real))
|
||||
real = cq;
|
||||
|
||||
@@ -491,6 +508,28 @@ HRESULT DxgiFactoryHooks::CreateSwapChainForHwnd(IDXGIFactory2* realFactory, IUn
|
||||
{
|
||||
cq->Release();
|
||||
|
||||
LOG_DEBUG("currentD3D12Device: {:X}", (UINT64) State::Instance().currentD3D12Device);
|
||||
if (State::Instance().currentD3D12Device == nullptr)
|
||||
{
|
||||
LOG_DEBUG("Capturing D3D12 device from command queue");
|
||||
ID3D12Device* device = nullptr;
|
||||
auto capRes = cq->GetDevice(IID_PPV_ARGS(&device));
|
||||
if (SUCCEEDED(capRes))
|
||||
{
|
||||
if (device != nullptr)
|
||||
{
|
||||
State::Instance().currentD3D12Device = device;
|
||||
LOG_INFO("Captured D3D12 device from command queue: {:X}", (UINT64) device);
|
||||
D3D12Hooks::HookDevice(State::Instance().currentD3D12Device);
|
||||
device->Release();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DEBUG("Failed to get D3D12 device from command queue: {:X}", (UINT) capRes);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Util::CheckForRealObject(__FUNCTION__, cq, &real))
|
||||
real = cq;
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include <upscaler_time/UpscalerTime_Dx12.h>
|
||||
|
||||
#include <hooks/D3D12_Hooks.h>
|
||||
|
||||
#include <dxgi1_4.h>
|
||||
#include <shared_mutex>
|
||||
#include "detours/detours.h"
|
||||
@@ -184,8 +186,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(unsigned long long InApp
|
||||
}
|
||||
|
||||
D3D12Device = InDevice;
|
||||
|
||||
State::Instance().currentD3D12Device = InDevice;
|
||||
D3D12Hooks::HookDevice(InDevice);
|
||||
|
||||
if (!State::Instance().isWorkingAsNvngx)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <nvapi/fakenvapi.h>
|
||||
#include <hooks/Reflex_Hooks.h>
|
||||
#include <hooks/D3D12_Hooks.h>
|
||||
|
||||
#include <menu/menu_overlay_dx.h>
|
||||
|
||||
@@ -151,7 +152,9 @@ static HRESULT LocalPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT
|
||||
LOG_DEBUG("D3D12Device captured");
|
||||
|
||||
_dx12Device = true;
|
||||
|
||||
State::Instance().currentD3D12Device = device12;
|
||||
D3D12Hooks::HookDevice(device12);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user