diff --git a/CyberXeSS/CyberXeSS.vcxproj b/CyberXeSS/CyberXeSS.vcxproj index 7230eea0..e6b5a833 100644 --- a/CyberXeSS/CyberXeSS.vcxproj +++ b/CyberXeSS/CyberXeSS.vcxproj @@ -171,12 +171,11 @@ + - - @@ -193,8 +192,10 @@ Create - - + + + + diff --git a/CyberXeSS/WrappedD3D12Device.cpp b/CyberXeSS/WrappedD3D12Device.cpp deleted file mode 100644 index 142dd840..00000000 --- a/CyberXeSS/WrappedD3D12Device.cpp +++ /dev/null @@ -1,702 +0,0 @@ -#include "pch.h" -#include "WrappedD3D12Device.h" - -bool RefCountD3D12Object::HandleWrap(const char* ifaceName, REFIID riid, void** ppvObject) -{ - LOG("RefCountD3D12Object.HandleWrap"); - - if (ppvObject == NULL || *ppvObject == NULL) - { - std::string str(ifaceName); - LOG("RefCountD3D12Object.HandleWrap called with NULL ppvObject querying " + str); - return false; - } - - // unknown GUID that we only want to print once to avoid log spam - // {79D2046C-22EF-451B-9E74-2245D9C760EA} - static const GUID Unknown_uuid = { - 0x79d2046c, 0x22ef, 0x451b, {0x9e, 0x74, 0x22, 0x45, 0xd9, 0xc7, 0x60, 0xea} }; - - // unknown/undocumented internal interface - // {7abb6563-02bc-47c4-8ef9-acc4795edbcf} - static const GUID ID3D12DeviceInternal2_uuid = { - 0x7abb6563, 0x02bc, 0x47c4, {0x8e, 0xf9, 0xac, 0xc4, 0x79, 0x5e, 0xdb, 0xcf} }; - - if (riid == __uuidof(ID3D12Device)) - { - ID3D12Device* real = (ID3D12Device*)(*ppvObject); - *ppvObject = (ID3D12Device*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device1)) - { - ID3D12Device1* real = (ID3D12Device1*)(*ppvObject); - *ppvObject = (ID3D12Device1*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device2)) - { - ID3D12Device2* real = (ID3D12Device2*)(*ppvObject); - *ppvObject = (ID3D12Device2*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device3)) - { - ID3D12Device3* real = (ID3D12Device3*)(*ppvObject); - *ppvObject = (ID3D12Device3*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device4)) - { - ID3D12Device4* real = (ID3D12Device4*)(*ppvObject); - *ppvObject = (ID3D12Device4*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device5)) - { - ID3D12Device5* real = (ID3D12Device5*)(*ppvObject); - *ppvObject = (ID3D12Device5*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device6)) - { - ID3D12Device6* real = (ID3D12Device6*)(*ppvObject); - *ppvObject = (ID3D12Device6*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device7)) - { - ID3D12Device7* real = (ID3D12Device7*)(*ppvObject); - *ppvObject = (ID3D12Device7*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device8)) - { - ID3D12Device8* real = (ID3D12Device8*)(*ppvObject); - *ppvObject = (ID3D12Device8*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device9)) - { - ID3D12Device9* real = (ID3D12Device9*)(*ppvObject); - *ppvObject = (ID3D12Device9*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == __uuidof(ID3D12Device10)) - { - ID3D12Device10* real = (ID3D12Device10*)(*ppvObject); - *ppvObject = (ID3D12Device10*)(new WrappedD3D12Device(real)); - return true; - } - else if (riid == Unknown_uuid) - { - LOG("RefCountDXGIObject.HandleWrap Querying Unknown_uuid, returning false"); - } - else if (riid == ID3D12DeviceInternal2_uuid) - { - LOG("RefCountDXGIObject.HandleWrap Querying ID3D12DeviceInternal2_uuid, returning false"); - } - else - { - std::string str(ifaceName); - LOG("RefCountDXGIObject.HandleWrap Querying " + str + " for unrecognized GUID: " + ToString(riid)); - } - - return false; -} - -HRESULT RefCountD3D12Object::WrapQueryInterface(IUnknown* real, const char* ifaceName, REFIID riid, void** ppvObject) -{ - LOG("RefCountD3D12Object.WrapQueryInterface"); - - HRESULT ret = real->QueryInterface(riid, ppvObject); - - if (ret == S_OK && HandleWrap(ifaceName, riid, ppvObject)) - return ret; - - *ppvObject = NULL; - return E_NOINTERFACE; -} - -WrappedD3D12Device::WrappedD3D12Device(ID3D12Device* device) : RefCountD3D12Object(device), m_device(device) -{ - m_device1 = NULL; - device->QueryInterface(__uuidof(ID3D12Device1), (void**)&m_device1); - m_device2 = NULL; - device->QueryInterface(__uuidof(ID3D12Device2), (void**)&m_device2); - m_device3 = NULL; - device->QueryInterface(__uuidof(ID3D12Device3), (void**)&m_device3); - m_device4 = NULL; - device->QueryInterface(__uuidof(ID3D12Device4), (void**)&m_device4); - m_device5 = NULL; - device->QueryInterface(__uuidof(ID3D12Device5), (void**)&m_device5); - m_device6 = NULL; - device->QueryInterface(__uuidof(ID3D12Device6), (void**)&m_device6); - m_device7 = NULL; - device->QueryInterface(__uuidof(ID3D12Device7), (void**)&m_device7); - m_device8 = NULL; - device->QueryInterface(__uuidof(ID3D12Device8), (void**)&m_device8); - m_device9 = NULL; - device->QueryInterface(__uuidof(ID3D12Device9), (void**)&m_device9); - m_device10 = NULL; - device->QueryInterface(__uuidof(ID3D12Device10), (void**)&m_device10); -} - -WrappedD3D12Device::~WrappedD3D12Device() -{ - SAFE_RELEASE(m_device); - SAFE_RELEASE(m_device1); - SAFE_RELEASE(m_device2); - SAFE_RELEASE(m_device3); - SAFE_RELEASE(m_device4); - SAFE_RELEASE(m_device5); - SAFE_RELEASE(m_device6); - SAFE_RELEASE(m_device7); - SAFE_RELEASE(m_device8); - SAFE_RELEASE(m_device9); - SAFE_RELEASE(m_device10); -} - - -HRESULT __stdcall WrappedD3D12Device::QueryInterface(REFIID riid, void** ppvObject) -{ - LOG("D3D12Device.QueryInterface: " + ToString(riid)); - - if (ppvObject == nullptr) - return E_POINTER; - - if (riid == __uuidof(ID3D12Device)) - { - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - if (riid == __uuidof(ID3D12ProxyDevice)) - { - LOG("D3D12Device.QueryInterface: Looking for ID3D12ProxyDevice, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device1)) - { - if (m_device1 == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device1 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device1, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device2)) - { - if (m_device2 == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device2 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device2, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device3)) - { - if (m_device == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device3 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device3, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device4)) - { - if (m_device4 == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device4 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device4, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device5)) - { - if (m_device5 == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device5 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device5, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device6)) - { - if (m_device6 == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device6 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device6, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device7)) - { - if (m_device7 == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device7 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device7, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device8)) - { - if (m_device8 == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device8 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device8, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device9)) - { - if (m_device9 == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device9 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device9, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Device10)) - { - if (m_device10 == nullptr) - { - LOG("D3D12Device.QueryInterface: m_device10 is not available, returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - - LOG("D3D12Device.QueryInterface: Looking for ID3D12Device10, returning this"); - AddRef(); - *ppvObject = this; - return S_OK; - } - else if (riid == __uuidof(ID3D12DeviceRemovedExtendedData) || - riid == __uuidof(ID3D12DeviceRemovedExtendedData1) || - riid == __uuidof(ID3D12DeviceRemovedExtendedData2)) - { - LOG("D3D12Device.QueryInterface: Looking for ID3D12DeviceRemovedExtendedData"); - auto ret = m_device->QueryInterface(riid, ppvObject); - LOG("D3D12Device.QueryInterface: Looking for ID3D12DeviceRemovedExtendedData result: " + int_to_hex(ret)); - return ret; - } - - auto hr = m_device->QueryInterface(riid, ppvObject); - - if (hr == S_OK && *ppvObject != nullptr) - { - auto wrapResult = RefCountD3D12Object::HandleWrap("ID3DDevice", riid, ppvObject); - - if (!wrapResult) - { - LOG("D3D12Device.QueryInterface: returning E_NOINTERFACE"); - return E_NOINTERFACE; - } - } - - LOG("D3D12Device.QueryInterface Unknown interface result: " + int_to_hex(hr)); - return hr; -} - -HRESULT STDMETHODCALLTYPE RefCountD3D12Object::SetName(_In_z_ LPCWSTR Name) -{ - return m_pReal->SetName(Name); -} - -UINT __stdcall WrappedD3D12Device::GetNodeCount(void) -{ - return m_device->GetNodeCount(); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommandQueue(const D3D12_COMMAND_QUEUE_DESC* pDesc, REFIID riid, void** ppCommandQueue) -{ - return m_device->CreateCommandQueue(pDesc, riid, ppCommandQueue); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE type, REFIID riid, void** ppCommandAllocator) -{ - return m_device->CreateCommandAllocator(type, riid, ppCommandAllocator); -} - -HRESULT __stdcall WrappedD3D12Device::CreateGraphicsPipelineState(const D3D12_GRAPHICS_PIPELINE_STATE_DESC* pDesc, REFIID riid, void** ppPipelineState) -{ - return m_device->CreateGraphicsPipelineState(pDesc, riid, ppPipelineState); -} - -HRESULT __stdcall WrappedD3D12Device::CreateComputePipelineState(const D3D12_COMPUTE_PIPELINE_STATE_DESC* pDesc, REFIID riid, void** ppPipelineState) -{ - return m_device->CreateComputePipelineState(pDesc, riid, ppPipelineState); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommandList(UINT nodeMask, D3D12_COMMAND_LIST_TYPE type, ID3D12CommandAllocator* pCommandAllocator, ID3D12PipelineState* pInitialState, REFIID riid, void** ppCommandList) -{ - return m_device->CreateCommandList(nodeMask, type, pCommandAllocator, pInitialState, riid, ppCommandList); -} - -HRESULT __stdcall WrappedD3D12Device::CheckFeatureSupport(D3D12_FEATURE Feature, void* pFeatureSupportData, UINT FeatureSupportDataSize) -{ - return m_device->CheckFeatureSupport(Feature, pFeatureSupportData, FeatureSupportDataSize); -} - -HRESULT __stdcall WrappedD3D12Device::CreateDescriptorHeap(const D3D12_DESCRIPTOR_HEAP_DESC* pDescriptorHeapDesc, REFIID riid, void** ppvHeap) -{ - return m_device->CreateDescriptorHeap(pDescriptorHeapDesc, riid, ppvHeap); -} - -UINT __stdcall WrappedD3D12Device::GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE DescriptorHeapType) -{ - return m_device->GetDescriptorHandleIncrementSize(DescriptorHeapType); -} - -HRESULT __stdcall WrappedD3D12Device::CreateRootSignature(UINT nodeMask, const void* pBlobWithRootSignature, SIZE_T blobLengthInBytes, REFIID riid, void** ppvRootSignature) -{ - return m_device->CreateRootSignature(nodeMask, pBlobWithRootSignature, blobLengthInBytes, riid, ppvRootSignature); -} - -void __stdcall WrappedD3D12Device::CreateConstantBufferView(const D3D12_CONSTANT_BUFFER_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) -{ - return m_device->CreateConstantBufferView(pDesc, DestDescriptor); -} - -void __stdcall WrappedD3D12Device::CreateShaderResourceView(ID3D12Resource* pResource, const D3D12_SHADER_RESOURCE_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) -{ - return m_device->CreateShaderResourceView(pResource, pDesc, DestDescriptor); -} - -void __stdcall WrappedD3D12Device::CreateUnorderedAccessView(ID3D12Resource* pResource, ID3D12Resource* pCounterResource, const D3D12_UNORDERED_ACCESS_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) -{ - return m_device->CreateUnorderedAccessView(pResource, pCounterResource, pDesc, DestDescriptor); -} - -void __stdcall WrappedD3D12Device::CreateRenderTargetView(ID3D12Resource* pResource, const D3D12_RENDER_TARGET_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) -{ - return m_device->CreateRenderTargetView(pResource, pDesc, DestDescriptor); -} - -void __stdcall WrappedD3D12Device::CreateDepthStencilView(ID3D12Resource* pResource, const D3D12_DEPTH_STENCIL_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) -{ - return m_device->CreateDepthStencilView(pResource, pDesc, DestDescriptor); -} - -void __stdcall WrappedD3D12Device::CreateSampler(const D3D12_SAMPLER_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) -{ - return m_device->CreateSampler(pDesc, DestDescriptor); -} - -void __stdcall WrappedD3D12Device::CopyDescriptors(UINT NumDestDescriptorRanges, const D3D12_CPU_DESCRIPTOR_HANDLE* pDestDescriptorRangeStarts, const UINT* pDestDescriptorRangeSizes, UINT NumSrcDescriptorRanges, const D3D12_CPU_DESCRIPTOR_HANDLE* pSrcDescriptorRangeStarts, const UINT* pSrcDescriptorRangeSizes, D3D12_DESCRIPTOR_HEAP_TYPE DescriptorHeapsType) -{ - return m_device->CopyDescriptors(NumDestDescriptorRanges, pDestDescriptorRangeStarts, pDestDescriptorRangeSizes, NumSrcDescriptorRanges, pSrcDescriptorRangeStarts, pSrcDescriptorRangeSizes, DescriptorHeapsType); -} - -void __stdcall WrappedD3D12Device::CopyDescriptorsSimple(UINT NumDescriptors, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptorRangeStart, D3D12_CPU_DESCRIPTOR_HANDLE SrcDescriptorRangeStart, D3D12_DESCRIPTOR_HEAP_TYPE DescriptorHeapsType) -{ - return m_device->CopyDescriptorsSimple(NumDescriptors, DestDescriptorRangeStart, SrcDescriptorRangeStart, DescriptorHeapsType); -} - -D3D12_RESOURCE_ALLOCATION_INFO __stdcall WrappedD3D12Device::GetResourceAllocationInfo(UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs) -{ - return m_device->GetResourceAllocationInfo(visibleMask, numResourceDescs, pResourceDescs); -} - -D3D12_HEAP_PROPERTIES __stdcall WrappedD3D12Device::GetCustomHeapProperties(UINT nodeMask, D3D12_HEAP_TYPE heapType) -{ - return m_device->GetCustomHeapProperties(nodeMask, heapType); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommittedResource(const D3D12_HEAP_PROPERTIES* pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialResourceState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, REFIID riidResource, void** ppvResource) -{ - return m_device->CreateCommittedResource(pHeapProperties, HeapFlags, pDesc, InitialResourceState, pOptimizedClearValue, riidResource, ppvResource); -} - -HRESULT __stdcall WrappedD3D12Device::CreateHeap(const D3D12_HEAP_DESC* pDesc, REFIID riid, void** ppvHeap) -{ - return m_device->CreateHeap(pDesc, riid, ppvHeap); -} - -HRESULT __stdcall WrappedD3D12Device::CreatePlacedResource(ID3D12Heap* pHeap, UINT64 HeapOffset, const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, REFIID riid, void** ppvResource) -{ - return m_device->CreatePlacedResource(pHeap, HeapOffset, pDesc, InitialState, pOptimizedClearValue, riid, ppvResource); -} - -HRESULT __stdcall WrappedD3D12Device::CreateReservedResource(const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, REFIID riid, void** ppvResource) -{ - return m_device->CreateReservedResource(pDesc, InitialState, pOptimizedClearValue, riid, ppvResource); -} - -HRESULT __stdcall WrappedD3D12Device::CreateSharedHandle(ID3D12DeviceChild* pObject, const SECURITY_ATTRIBUTES* pAttributes, DWORD Access, LPCWSTR Name, HANDLE* pHandle) -{ - return m_device->CreateSharedHandle(pObject, pAttributes, Access, Name, pHandle); -} - -HRESULT __stdcall WrappedD3D12Device::OpenSharedHandle(HANDLE NTHandle, REFIID riid, void** ppvObj) -{ - return m_device->OpenSharedHandle(NTHandle, riid, ppvObj); -} - -HRESULT __stdcall WrappedD3D12Device::OpenSharedHandleByName(LPCWSTR Name, DWORD Access, HANDLE* pNTHandle) -{ - return m_device->OpenSharedHandleByName(Name, Access, pNTHandle); -} - -HRESULT __stdcall WrappedD3D12Device::MakeResident(UINT NumObjects, ID3D12Pageable* const* ppObjects) -{ - return m_device->MakeResident(NumObjects, ppObjects); -} - -HRESULT __stdcall WrappedD3D12Device::Evict(UINT NumObjects, ID3D12Pageable* const* ppObjects) -{ - return m_device->Evict(NumObjects, ppObjects); -} - -HRESULT __stdcall WrappedD3D12Device::CreateFence(UINT64 InitialValue, D3D12_FENCE_FLAGS Flags, REFIID riid, void** ppFence) -{ - return m_device->CreateFence(InitialValue, Flags, riid, ppFence); -} - -HRESULT __stdcall WrappedD3D12Device::GetDeviceRemovedReason(void) -{ - return m_device->GetDeviceRemovedReason(); -} - -void __stdcall WrappedD3D12Device::GetCopyableFootprints(const D3D12_RESOURCE_DESC* pResourceDesc, UINT FirstSubresource, UINT NumSubresources, UINT64 BaseOffset, D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts, UINT* pNumRows, UINT64* pRowSizeInBytes, UINT64* pTotalBytes) -{ - return m_device->GetCopyableFootprints(pResourceDesc, FirstSubresource, NumSubresources, BaseOffset, pLayouts, pNumRows, pRowSizeInBytes, pTotalBytes); -} - -HRESULT __stdcall WrappedD3D12Device::CreateQueryHeap(const D3D12_QUERY_HEAP_DESC* pDesc, REFIID riid, void** ppvHeap) -{ - return m_device->CreateQueryHeap(pDesc, riid, ppvHeap); -} - -HRESULT __stdcall WrappedD3D12Device::SetStablePowerState(BOOL Enable) -{ - return m_device->SetStablePowerState(Enable); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommandSignature(const D3D12_COMMAND_SIGNATURE_DESC* pDesc, ID3D12RootSignature* pRootSignature, REFIID riid, void** ppvCommandSignature) -{ - return m_device->CreateCommandSignature(pDesc, pRootSignature, riid, ppvCommandSignature); -} - -void __stdcall WrappedD3D12Device::GetResourceTiling(ID3D12Resource* pTiledResource, UINT* pNumTilesForEntireResource, D3D12_PACKED_MIP_INFO* pPackedMipDesc, D3D12_TILE_SHAPE* pStandardTileShapeForNonPackedMips, UINT* pNumSubresourceTilings, UINT FirstSubresourceTilingToGet, D3D12_SUBRESOURCE_TILING* pSubresourceTilingsForNonPackedMips) -{ - return m_device->GetResourceTiling(pTiledResource, pNumTilesForEntireResource, pPackedMipDesc, pStandardTileShapeForNonPackedMips, pNumSubresourceTilings, FirstSubresourceTilingToGet, pSubresourceTilingsForNonPackedMips); -} - -LUID __stdcall WrappedD3D12Device::GetAdapterLuid(void) -{ - return LUID{ 0, 56090 }; -} - -HRESULT __stdcall WrappedD3D12Device::CreatePipelineLibrary(const void* pLibraryBlob, SIZE_T BlobLength, REFIID riid, void** ppPipelineLibrary) -{ - return m_device1->CreatePipelineLibrary(pLibraryBlob, BlobLength, riid, ppPipelineLibrary); -} - -HRESULT __stdcall WrappedD3D12Device::SetEventOnMultipleFenceCompletion(ID3D12Fence* const* ppFences, const UINT64* pFenceValues, UINT NumFences, D3D12_MULTIPLE_FENCE_WAIT_FLAGS Flags, HANDLE hEvent) -{ - return m_device1->SetEventOnMultipleFenceCompletion(ppFences, pFenceValues, NumFences, Flags, hEvent); -} - -HRESULT __stdcall WrappedD3D12Device::SetResidencyPriority(UINT NumObjects, ID3D12Pageable* const* ppObjects, const D3D12_RESIDENCY_PRIORITY* pPriorities) -{ - return m_device1->SetResidencyPriority(NumObjects, ppObjects, pPriorities); -} - -HRESULT __stdcall WrappedD3D12Device::CreatePipelineState(const D3D12_PIPELINE_STATE_STREAM_DESC* pDesc, REFIID riid, void** ppPipelineState) -{ - return m_device2->CreatePipelineState(pDesc, riid, ppPipelineState); -} - -HRESULT __stdcall WrappedD3D12Device::OpenExistingHeapFromAddress(const void* pAddress, REFIID riid, void** ppvHeap) -{ - return m_device3->OpenExistingHeapFromAddress(pAddress, riid, ppvHeap); -} - -HRESULT __stdcall WrappedD3D12Device::OpenExistingHeapFromFileMapping(HANDLE hFileMapping, REFIID riid, void** ppvHeap) -{ - return m_device3->OpenExistingHeapFromFileMapping(hFileMapping, riid, ppvHeap); -} - -HRESULT __stdcall WrappedD3D12Device::EnqueueMakeResident(D3D12_RESIDENCY_FLAGS Flags, UINT NumObjects, ID3D12Pageable* const* ppObjects, ID3D12Fence* pFenceToSignal, UINT64 FenceValueToSignal) -{ - return m_device3->EnqueueMakeResident(Flags, NumObjects, ppObjects, pFenceToSignal, FenceValueToSignal); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommandList1(UINT nodeMask, D3D12_COMMAND_LIST_TYPE type, D3D12_COMMAND_LIST_FLAGS flags, REFIID riid, void** ppCommandList) -{ - return m_device4->CreateCommandList1(nodeMask, type, flags, riid, ppCommandList); -} - -HRESULT __stdcall WrappedD3D12Device::CreateProtectedResourceSession(const D3D12_PROTECTED_RESOURCE_SESSION_DESC* pDesc, REFIID riid, void** ppSession) -{ - return m_device4->CreateProtectedResourceSession(pDesc, riid, ppSession); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommittedResource1(const D3D12_HEAP_PROPERTIES* pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialResourceState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, REFIID riidResource, void** ppvResource) -{ - return m_device4->CreateCommittedResource1(pHeapProperties, HeapFlags, pDesc, InitialResourceState, pOptimizedClearValue, pProtectedSession, riidResource, ppvResource); -} - -HRESULT __stdcall WrappedD3D12Device::CreateHeap1(const D3D12_HEAP_DESC* pDesc, ID3D12ProtectedResourceSession* pProtectedSession, REFIID riid, void** ppvHeap) -{ - return m_device4->CreateHeap1(pDesc, pProtectedSession, riid, ppvHeap); -} - -HRESULT __stdcall WrappedD3D12Device::CreateReservedResource1(const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, REFIID riid, void** ppvResource) -{ - return m_device4->CreateReservedResource1(pDesc, InitialState, pOptimizedClearValue, pProtectedSession, riid, ppvResource); -} - -D3D12_RESOURCE_ALLOCATION_INFO __stdcall WrappedD3D12Device::GetResourceAllocationInfo1(UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs, D3D12_RESOURCE_ALLOCATION_INFO1* pResourceAllocationInfo1) -{ - return m_device4->GetResourceAllocationInfo1(visibleMask, numResourceDescs, pResourceDescs, pResourceAllocationInfo1); -} - -HRESULT __stdcall WrappedD3D12Device::CreateLifetimeTracker(ID3D12LifetimeOwner* pOwner, REFIID riid, void** ppvTracker) -{ - return m_device5->CreateLifetimeTracker(pOwner, riid, ppvTracker); -} - -void __stdcall WrappedD3D12Device::RemoveDevice(void) -{ - return m_device5->RemoveDevice(); -} - -HRESULT __stdcall WrappedD3D12Device::EnumerateMetaCommands(UINT* pNumMetaCommands, D3D12_META_COMMAND_DESC* pDescs) -{ - return m_device5->EnumerateMetaCommands(pNumMetaCommands, pDescs); -} - -HRESULT __stdcall WrappedD3D12Device::EnumerateMetaCommandParameters(REFGUID CommandId, D3D12_META_COMMAND_PARAMETER_STAGE Stage, UINT* pTotalStructureSizeInBytes, UINT* pParameterCount, D3D12_META_COMMAND_PARAMETER_DESC* pParameterDescs) -{ - return m_device5->EnumerateMetaCommandParameters(CommandId, Stage, pTotalStructureSizeInBytes, pParameterCount, pParameterDescs); -} - -HRESULT __stdcall WrappedD3D12Device::CreateMetaCommand(REFGUID CommandId, UINT NodeMask, const void* pCreationParametersData, SIZE_T CreationParametersDataSizeInBytes, REFIID riid, void** ppMetaCommand) -{ - return m_device5->CreateMetaCommand(CommandId, NodeMask, pCreationParametersData, CreationParametersDataSizeInBytes, riid, ppMetaCommand); -} - -HRESULT __stdcall WrappedD3D12Device::CreateStateObject(const D3D12_STATE_OBJECT_DESC* pDesc, REFIID riid, void** ppStateObject) -{ - return m_device5->CreateStateObject(pDesc, riid, ppStateObject); -} - -void __stdcall WrappedD3D12Device::GetRaytracingAccelerationStructurePrebuildInfo(const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS* pDesc, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO* pInfo) -{ - return m_device5->GetRaytracingAccelerationStructurePrebuildInfo(pDesc, pInfo); -} - -D3D12_DRIVER_MATCHING_IDENTIFIER_STATUS __stdcall WrappedD3D12Device::CheckDriverMatchingIdentifier(D3D12_SERIALIZED_DATA_TYPE SerializedDataType, const D3D12_SERIALIZED_DATA_DRIVER_MATCHING_IDENTIFIER* pIdentifierToCheck) -{ - return m_device5->CheckDriverMatchingIdentifier(SerializedDataType, pIdentifierToCheck); -} - -HRESULT __stdcall WrappedD3D12Device::SetBackgroundProcessingMode(D3D12_BACKGROUND_PROCESSING_MODE Mode, D3D12_MEASUREMENTS_ACTION MeasurementsAction, HANDLE hEventToSignalUponCompletion, BOOL* pbFurtherMeasurementsDesired) -{ - return m_device6->SetBackgroundProcessingMode(Mode, MeasurementsAction, hEventToSignalUponCompletion, pbFurtherMeasurementsDesired); -} - -HRESULT __stdcall WrappedD3D12Device::AddToStateObject(const D3D12_STATE_OBJECT_DESC* pAddition, ID3D12StateObject* pStateObjectToGrowFrom, REFIID riid, void** ppNewStateObject) -{ - return m_device7->AddToStateObject(pAddition, pStateObjectToGrowFrom, riid, ppNewStateObject); -} - -HRESULT __stdcall WrappedD3D12Device::CreateProtectedResourceSession1(const D3D12_PROTECTED_RESOURCE_SESSION_DESC1* pDesc, REFIID riid, void** ppSession) -{ - return m_device7->CreateProtectedResourceSession1(pDesc, riid, ppSession); -} - -D3D12_RESOURCE_ALLOCATION_INFO __stdcall WrappedD3D12Device::GetResourceAllocationInfo2(UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC1* pResourceDescs, D3D12_RESOURCE_ALLOCATION_INFO1* pResourceAllocationInfo1) -{ - return m_device8->GetResourceAllocationInfo2(visibleMask, numResourceDescs, pResourceDescs, pResourceAllocationInfo1); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommittedResource2(const D3D12_HEAP_PROPERTIES* pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC1* pDesc, D3D12_RESOURCE_STATES InitialResourceState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, REFIID riidResource, void** ppvResource) -{ - return m_device8->CreateCommittedResource2(pHeapProperties, HeapFlags, pDesc, InitialResourceState, pOptimizedClearValue, pProtectedSession, riidResource, ppvResource); -} - -HRESULT __stdcall WrappedD3D12Device::CreatePlacedResource1(ID3D12Heap* pHeap, UINT64 HeapOffset, const D3D12_RESOURCE_DESC1* pDesc, D3D12_RESOURCE_STATES InitialState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, REFIID riid, void** ppvResource) -{ - return m_device8->CreatePlacedResource1(pHeap, HeapOffset, pDesc, InitialState, pOptimizedClearValue, riid, ppvResource); -} - -void __stdcall WrappedD3D12Device::CreateSamplerFeedbackUnorderedAccessView(ID3D12Resource* pTargetedResource, ID3D12Resource* pFeedbackResource, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) -{ - return m_device8->CreateSamplerFeedbackUnorderedAccessView(pTargetedResource, pFeedbackResource, DestDescriptor); -} - -void __stdcall WrappedD3D12Device::GetCopyableFootprints1(const D3D12_RESOURCE_DESC1* pResourceDesc, UINT FirstSubresource, UINT NumSubresources, UINT64 BaseOffset, D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts, UINT* pNumRows, UINT64* pRowSizeInBytes, UINT64* pTotalBytes) -{ - return m_device8->GetCopyableFootprints1(pResourceDesc, FirstSubresource, NumSubresources, BaseOffset, pLayouts, pNumRows, pRowSizeInBytes, pTotalBytes); -} - -HRESULT __stdcall WrappedD3D12Device::CreateShaderCacheSession(const D3D12_SHADER_CACHE_SESSION_DESC* pDesc, REFIID riid, void** ppvSession) -{ - return m_device9->CreateShaderCacheSession(pDesc, riid, ppvSession); -} - -HRESULT __stdcall WrappedD3D12Device::ShaderCacheControl(D3D12_SHADER_CACHE_KIND_FLAGS Kinds, D3D12_SHADER_CACHE_CONTROL_FLAGS Control) -{ - return m_device9->ShaderCacheControl(Kinds, Control); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommandQueue1(const D3D12_COMMAND_QUEUE_DESC* pDesc, REFIID CreatorID, REFIID riid, void** ppCommandQueue) -{ - return m_device9->CreateCommandQueue1(pDesc, CreatorID, riid, ppCommandQueue); -} - -HRESULT __stdcall WrappedD3D12Device::CreateCommittedResource3(const D3D12_HEAP_PROPERTIES* pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC1* pDesc, D3D12_BARRIER_LAYOUT InitialLayout, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, UINT32 NumCastableFormats, DXGI_FORMAT* pCastableFormats, REFIID riidResource, void** ppvResource) -{ - return m_device10->CreateCommittedResource3(pHeapProperties, HeapFlags, pDesc, InitialLayout, pOptimizedClearValue, pProtectedSession, NumCastableFormats, pCastableFormats, riidResource, ppvResource); -} - -HRESULT __stdcall WrappedD3D12Device::CreatePlacedResource2(ID3D12Heap* pHeap, UINT64 HeapOffset, const D3D12_RESOURCE_DESC1* pDesc, D3D12_BARRIER_LAYOUT InitialLayout, const D3D12_CLEAR_VALUE* pOptimizedClearValue, UINT32 NumCastableFormats, DXGI_FORMAT* pCastableFormats, REFIID riid, void** ppvResource) -{ - return m_device10->CreatePlacedResource2(pHeap, HeapOffset, pDesc, InitialLayout, pOptimizedClearValue, NumCastableFormats, pCastableFormats, riid, ppvResource); -} - -HRESULT __stdcall WrappedD3D12Device::CreateReservedResource2(const D3D12_RESOURCE_DESC* pDesc, D3D12_BARRIER_LAYOUT InitialLayout, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, UINT32 NumCastableFormats, DXGI_FORMAT* pCastableFormats, REFIID riid, void** ppvResource) -{ - return m_device10->CreateReservedResource2(pDesc, InitialLayout, pOptimizedClearValue, pProtectedSession, NumCastableFormats, pCastableFormats, riid, ppvResource); -} diff --git a/CyberXeSS/WrappedD3D12Device.h b/CyberXeSS/WrappedD3D12Device.h deleted file mode 100644 index f27ecf32..00000000 --- a/CyberXeSS/WrappedD3D12Device.h +++ /dev/null @@ -1,245 +0,0 @@ -#pragma once - -#include "WrappedDXGIObjects.h" - -class RefCountD3D12Object : public ID3D12Object -{ - ID3D12Object* m_pReal; - unsigned int m_iRefcount; - -public: - RefCountD3D12Object(ID3D12Object* real) : m_pReal(real), m_iRefcount(1) {} - virtual ~RefCountD3D12Object() {} - static bool HandleWrap(const char* ifaceName, REFIID riid, void** ppvObject); - static HRESULT WrapQueryInterface(IUnknown* real, const char* ifaceName, REFIID riid, void** ppvObject); - - ////////////////////////////// - // implement IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface( /* [in] */ REFIID riid, /* [annotation][iid_is][out] */ __RPC__deref_out void** ppvObject) - { - LOG("RefCountD3D12Object.QueryInterface"); - auto result = QueryInterface("IUnknown", riid, ppvObject); - LOG("RefCountD3D12Object.QueryInterface result: " + int_to_hex(result)); - - return result; - } - - // optional overload that's useful for passing down the name of the current interface to put in - // any 'unknown interface' query logs. - HRESULT STDMETHODCALLTYPE QueryInterface(const char* ifaceName, REFIID riid, void** ppvObject) - { - if (riid == __uuidof(IUnknown)) - { - AddRef(); - *ppvObject = (IUnknown*)(ID3D12Object*)this; - return S_OK; - } - else if (riid == __uuidof(ID3D12Object)) - { - AddRef(); - *ppvObject = (ID3D12Object*)this; - return S_OK; - } - - return WrapQueryInterface(m_pReal, ifaceName, riid, ppvObject); - } - - ULONG STDMETHODCALLTYPE AddRef() - { - LOG("RefCountD3D12Object.AddRef"); - InterlockedIncrement(&m_iRefcount); - LOG("RefCountD3D12Object.AddRef result: " + int_to_hex(m_iRefcount)); - return m_iRefcount; - } - ULONG STDMETHODCALLTYPE Release() - { - LOG("RefCountD3D12Object.Release"); - - unsigned int ret = InterlockedDecrement(&m_iRefcount); - - LOG("RefCountD3D12Object.Release result: " + int_to_hex(m_iRefcount)); - - if (ret == 0) - { - LOG("RefCountD3D12Object.Release deleting object"); - delete this; - } - - return ret; - } - - ////////////////////////////// - // implement ID3D12Object - - virtual HRESULT STDMETHODCALLTYPE SetPrivateData( /* [in] */ REFGUID Name, /* [in] */ UINT DataSize, /* [in] */ const void* pData) - { - LOG("RefCountDXGIObject.SetPrivateData"); - auto result = m_pReal->SetPrivateData(Name, DataSize, pData); - LOG("RefCountDXGIObject.SetPrivateData result: " + int_to_hex(result)); - return result; - } - - virtual HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( /* [in] */ REFGUID Name, /* [in] */ const IUnknown* pUnknown) - { - LOG("RefCountDXGIObject.SetPrivateDataInterface"); - auto result = m_pReal->SetPrivateDataInterface(Name, pUnknown); - LOG("RefCountDXGIObject.SetPrivateDataInterface result: " + int_to_hex(result)); - return result; - } - - virtual HRESULT STDMETHODCALLTYPE GetPrivateData( /* [in] */ REFGUID Name, /* [out][in] */ UINT* pDataSize, /* [out] */ void* pData) - { - LOG("RefCountDXGIObject.GetPrivateData"); - auto result = m_pReal->GetPrivateData(Name, pDataSize, pData); - LOG("RefCountDXGIObject.GetPrivateData result: " + int_to_hex(result)); - return result; - } - - virtual HRESULT STDMETHODCALLTYPE SetName(_In_z_ LPCWSTR Name); -}; - -#define IMPLEMENT_ID3D12OBJECT_WITH_REFCOUNTDXGIOBJECT_CUSTOMQUERY \ - ULONG STDMETHODCALLTYPE AddRef() \ - { \ - return RefCountD3D12Object::AddRef(); \ - } \ - ULONG STDMETHODCALLTYPE Release() \ - { \ - return RefCountD3D12Object::Release(); \ - } \ - HRESULT STDMETHODCALLTYPE SetPrivateData(REFIID Name, UINT DataSize, const void *pData) \ - { \ - return RefCountD3D12Object::SetPrivateData(Name, DataSize, pData); \ - } \ - HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(REFIID Name, const IUnknown *pUnknown) \ - { \ - return RefCountD3D12Object::SetPrivateDataInterface(Name, pUnknown); \ - } \ - HRESULT STDMETHODCALLTYPE GetPrivateData(REFIID Name, UINT *pDataSize, void *pData) \ - { \ - return RefCountD3D12Object::GetPrivateData(Name, pDataSize, pData); \ - } \ - HRESULT STDMETHODCALLTYPE SetName(_In_z_ LPCWSTR Name) \ - { \ - return RefCountD3D12Object::SetName(Name); \ - } - -MIDL_INTERFACE("fa4994ad-dbe4-44b9-8c5c-bb5cf7188b6e") -ID3D12ProxyDevice : public IUnknown -{ -public: - virtual HRESULT STDMETHODCALLTYPE GetProxyAdapter(IDXGIProxyAdapter** adapter); - virtual HRESULT STDMETHODCALLTYPE SetProxyAdapter(IDXGIProxyAdapter* adapter); -}; - -class WrappedD3D12Device : public ID3D12Device10, public RefCountD3D12Object, public ID3D12ProxyDevice -{ - ID3D12Device1* m_device1; - ID3D12Device2* m_device2; - ID3D12Device3* m_device3; - ID3D12Device4* m_device4; - ID3D12Device5* m_device5; - ID3D12Device6* m_device6; - ID3D12Device7* m_device7; - ID3D12Device8* m_device8; - ID3D12Device9* m_device9; - ID3D12Device10* m_device10; - IDXGIProxyAdapter* m_adapter; - -public: - ID3D12Device* m_device; - WrappedD3D12Device(ID3D12Device* device); - - virtual ~WrappedD3D12Device(); - - IMPLEMENT_ID3D12OBJECT_WITH_REFCOUNTDXGIOBJECT_CUSTOMQUERY; - - // Inherited via ID3D12Device10 - - HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObject) override; - UINT __stdcall GetNodeCount(void) override; - HRESULT __stdcall CreateCommandQueue(const D3D12_COMMAND_QUEUE_DESC* pDesc, REFIID riid, void** ppCommandQueue) override; - HRESULT __stdcall CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE type, REFIID riid, void** ppCommandAllocator) override; - HRESULT __stdcall CreateGraphicsPipelineState(const D3D12_GRAPHICS_PIPELINE_STATE_DESC* pDesc, REFIID riid, void** ppPipelineState) override; - HRESULT __stdcall CreateComputePipelineState(const D3D12_COMPUTE_PIPELINE_STATE_DESC* pDesc, REFIID riid, void** ppPipelineState) override; - HRESULT __stdcall CreateCommandList(UINT nodeMask, D3D12_COMMAND_LIST_TYPE type, ID3D12CommandAllocator* pCommandAllocator, ID3D12PipelineState* pInitialState, REFIID riid, void** ppCommandList) override; - HRESULT __stdcall CheckFeatureSupport(D3D12_FEATURE Feature, void* pFeatureSupportData, UINT FeatureSupportDataSize) override; - HRESULT __stdcall CreateDescriptorHeap(const D3D12_DESCRIPTOR_HEAP_DESC* pDescriptorHeapDesc, REFIID riid, void** ppvHeap) override; - UINT __stdcall GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE DescriptorHeapType) override; - HRESULT __stdcall CreateRootSignature(UINT nodeMask, const void* pBlobWithRootSignature, SIZE_T blobLengthInBytes, REFIID riid, void** ppvRootSignature) override; - void __stdcall CreateConstantBufferView(const D3D12_CONSTANT_BUFFER_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) override; - void __stdcall CreateShaderResourceView(ID3D12Resource* pResource, const D3D12_SHADER_RESOURCE_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) override; - void __stdcall CreateUnorderedAccessView(ID3D12Resource* pResource, ID3D12Resource* pCounterResource, const D3D12_UNORDERED_ACCESS_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) override; - void __stdcall CreateRenderTargetView(ID3D12Resource* pResource, const D3D12_RENDER_TARGET_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) override; - void __stdcall CreateDepthStencilView(ID3D12Resource* pResource, const D3D12_DEPTH_STENCIL_VIEW_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) override; - void __stdcall CreateSampler(const D3D12_SAMPLER_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) override; - void __stdcall CopyDescriptors(UINT NumDestDescriptorRanges, const D3D12_CPU_DESCRIPTOR_HANDLE* pDestDescriptorRangeStarts, const UINT* pDestDescriptorRangeSizes, UINT NumSrcDescriptorRanges, const D3D12_CPU_DESCRIPTOR_HANDLE* pSrcDescriptorRangeStarts, const UINT* pSrcDescriptorRangeSizes, D3D12_DESCRIPTOR_HEAP_TYPE DescriptorHeapsType) override; - void __stdcall CopyDescriptorsSimple(UINT NumDescriptors, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptorRangeStart, D3D12_CPU_DESCRIPTOR_HANDLE SrcDescriptorRangeStart, D3D12_DESCRIPTOR_HEAP_TYPE DescriptorHeapsType) override; - D3D12_RESOURCE_ALLOCATION_INFO __stdcall GetResourceAllocationInfo(UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs) override; - D3D12_HEAP_PROPERTIES __stdcall GetCustomHeapProperties(UINT nodeMask, D3D12_HEAP_TYPE heapType) override; - HRESULT __stdcall CreateCommittedResource(const D3D12_HEAP_PROPERTIES* pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialResourceState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, REFIID riidResource, void** ppvResource) override; - HRESULT __stdcall CreateHeap(const D3D12_HEAP_DESC* pDesc, REFIID riid, void** ppvHeap) override; - HRESULT __stdcall CreatePlacedResource(ID3D12Heap* pHeap, UINT64 HeapOffset, const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, REFIID riid, void** ppvResource) override; - HRESULT __stdcall CreateReservedResource(const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, REFIID riid, void** ppvResource) override; - HRESULT __stdcall CreateSharedHandle(ID3D12DeviceChild* pObject, const SECURITY_ATTRIBUTES* pAttributes, DWORD Access, LPCWSTR Name, HANDLE* pHandle) override; - HRESULT __stdcall OpenSharedHandle(HANDLE NTHandle, REFIID riid, void** ppvObj) override; - HRESULT __stdcall OpenSharedHandleByName(LPCWSTR Name, DWORD Access, HANDLE* pNTHandle) override; - HRESULT __stdcall MakeResident(UINT NumObjects, ID3D12Pageable* const* ppObjects) override; - HRESULT __stdcall Evict(UINT NumObjects, ID3D12Pageable* const* ppObjects) override; - HRESULT __stdcall CreateFence(UINT64 InitialValue, D3D12_FENCE_FLAGS Flags, REFIID riid, void** ppFence) override; - HRESULT __stdcall GetDeviceRemovedReason(void) override; - void __stdcall GetCopyableFootprints(const D3D12_RESOURCE_DESC* pResourceDesc, UINT FirstSubresource, UINT NumSubresources, UINT64 BaseOffset, D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts, UINT* pNumRows, UINT64* pRowSizeInBytes, UINT64* pTotalBytes) override; - HRESULT __stdcall CreateQueryHeap(const D3D12_QUERY_HEAP_DESC* pDesc, REFIID riid, void** ppvHeap) override; - HRESULT __stdcall SetStablePowerState(BOOL Enable) override; - HRESULT __stdcall CreateCommandSignature(const D3D12_COMMAND_SIGNATURE_DESC* pDesc, ID3D12RootSignature* pRootSignature, REFIID riid, void** ppvCommandSignature) override; - void __stdcall GetResourceTiling(ID3D12Resource* pTiledResource, UINT* pNumTilesForEntireResource, D3D12_PACKED_MIP_INFO* pPackedMipDesc, D3D12_TILE_SHAPE* pStandardTileShapeForNonPackedMips, UINT* pNumSubresourceTilings, UINT FirstSubresourceTilingToGet, D3D12_SUBRESOURCE_TILING* pSubresourceTilingsForNonPackedMips) override; - LUID __stdcall GetAdapterLuid(void) override; - HRESULT __stdcall CreatePipelineLibrary(const void* pLibraryBlob, SIZE_T BlobLength, REFIID riid, void** ppPipelineLibrary) override; - HRESULT __stdcall SetEventOnMultipleFenceCompletion(ID3D12Fence* const* ppFences, const UINT64* pFenceValues, UINT NumFences, D3D12_MULTIPLE_FENCE_WAIT_FLAGS Flags, HANDLE hEvent) override; - HRESULT __stdcall SetResidencyPriority(UINT NumObjects, ID3D12Pageable* const* ppObjects, const D3D12_RESIDENCY_PRIORITY* pPriorities) override; - HRESULT __stdcall CreatePipelineState(const D3D12_PIPELINE_STATE_STREAM_DESC* pDesc, REFIID riid, void** ppPipelineState) override; - HRESULT __stdcall OpenExistingHeapFromAddress(const void* pAddress, REFIID riid, void** ppvHeap) override; - HRESULT __stdcall OpenExistingHeapFromFileMapping(HANDLE hFileMapping, REFIID riid, void** ppvHeap) override; - HRESULT __stdcall EnqueueMakeResident(D3D12_RESIDENCY_FLAGS Flags, UINT NumObjects, ID3D12Pageable* const* ppObjects, ID3D12Fence* pFenceToSignal, UINT64 FenceValueToSignal) override; - HRESULT __stdcall CreateCommandList1(UINT nodeMask, D3D12_COMMAND_LIST_TYPE type, D3D12_COMMAND_LIST_FLAGS flags, REFIID riid, void** ppCommandList) override; - HRESULT __stdcall CreateProtectedResourceSession(const D3D12_PROTECTED_RESOURCE_SESSION_DESC* pDesc, REFIID riid, void** ppSession) override; - HRESULT __stdcall CreateCommittedResource1(const D3D12_HEAP_PROPERTIES* pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialResourceState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, REFIID riidResource, void** ppvResource) override; - HRESULT __stdcall CreateHeap1(const D3D12_HEAP_DESC* pDesc, ID3D12ProtectedResourceSession* pProtectedSession, REFIID riid, void** ppvHeap) override; - HRESULT __stdcall CreateReservedResource1(const D3D12_RESOURCE_DESC* pDesc, D3D12_RESOURCE_STATES InitialState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, REFIID riid, void** ppvResource) override; - D3D12_RESOURCE_ALLOCATION_INFO __stdcall GetResourceAllocationInfo1(UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs, D3D12_RESOURCE_ALLOCATION_INFO1* pResourceAllocationInfo1) override; - HRESULT __stdcall CreateLifetimeTracker(ID3D12LifetimeOwner* pOwner, REFIID riid, void** ppvTracker) override; - void __stdcall RemoveDevice(void) override; - HRESULT __stdcall EnumerateMetaCommands(UINT* pNumMetaCommands, D3D12_META_COMMAND_DESC* pDescs) override; - HRESULT __stdcall EnumerateMetaCommandParameters(REFGUID CommandId, D3D12_META_COMMAND_PARAMETER_STAGE Stage, UINT* pTotalStructureSizeInBytes, UINT* pParameterCount, D3D12_META_COMMAND_PARAMETER_DESC* pParameterDescs) override; - HRESULT __stdcall CreateMetaCommand(REFGUID CommandId, UINT NodeMask, const void* pCreationParametersData, SIZE_T CreationParametersDataSizeInBytes, REFIID riid, void** ppMetaCommand) override; - HRESULT __stdcall CreateStateObject(const D3D12_STATE_OBJECT_DESC* pDesc, REFIID riid, void** ppStateObject) override; - void __stdcall GetRaytracingAccelerationStructurePrebuildInfo(const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS* pDesc, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO* pInfo) override; - D3D12_DRIVER_MATCHING_IDENTIFIER_STATUS __stdcall CheckDriverMatchingIdentifier(D3D12_SERIALIZED_DATA_TYPE SerializedDataType, const D3D12_SERIALIZED_DATA_DRIVER_MATCHING_IDENTIFIER* pIdentifierToCheck) override; - HRESULT __stdcall SetBackgroundProcessingMode(D3D12_BACKGROUND_PROCESSING_MODE Mode, D3D12_MEASUREMENTS_ACTION MeasurementsAction, HANDLE hEventToSignalUponCompletion, BOOL* pbFurtherMeasurementsDesired) override; - HRESULT __stdcall AddToStateObject(const D3D12_STATE_OBJECT_DESC* pAddition, ID3D12StateObject* pStateObjectToGrowFrom, REFIID riid, void** ppNewStateObject) override; - HRESULT __stdcall CreateProtectedResourceSession1(const D3D12_PROTECTED_RESOURCE_SESSION_DESC1* pDesc, REFIID riid, void** ppSession) override; - D3D12_RESOURCE_ALLOCATION_INFO __stdcall GetResourceAllocationInfo2(UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC1* pResourceDescs, D3D12_RESOURCE_ALLOCATION_INFO1* pResourceAllocationInfo1) override; - HRESULT __stdcall CreateCommittedResource2(const D3D12_HEAP_PROPERTIES* pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC1* pDesc, D3D12_RESOURCE_STATES InitialResourceState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, REFIID riidResource, void** ppvResource) override; - HRESULT __stdcall CreatePlacedResource1(ID3D12Heap* pHeap, UINT64 HeapOffset, const D3D12_RESOURCE_DESC1* pDesc, D3D12_RESOURCE_STATES InitialState, const D3D12_CLEAR_VALUE* pOptimizedClearValue, REFIID riid, void** ppvResource) override; - void __stdcall CreateSamplerFeedbackUnorderedAccessView(ID3D12Resource* pTargetedResource, ID3D12Resource* pFeedbackResource, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) override; - void __stdcall GetCopyableFootprints1(const D3D12_RESOURCE_DESC1* pResourceDesc, UINT FirstSubresource, UINT NumSubresources, UINT64 BaseOffset, D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts, UINT* pNumRows, UINT64* pRowSizeInBytes, UINT64* pTotalBytes) override; - HRESULT __stdcall CreateShaderCacheSession(const D3D12_SHADER_CACHE_SESSION_DESC* pDesc, REFIID riid, void** ppvSession) override; - HRESULT __stdcall ShaderCacheControl(D3D12_SHADER_CACHE_KIND_FLAGS Kinds, D3D12_SHADER_CACHE_CONTROL_FLAGS Control) override; - HRESULT __stdcall CreateCommandQueue1(const D3D12_COMMAND_QUEUE_DESC* pDesc, REFIID CreatorID, REFIID riid, void** ppCommandQueue) override; - HRESULT __stdcall CreateCommittedResource3(const D3D12_HEAP_PROPERTIES* pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC1* pDesc, D3D12_BARRIER_LAYOUT InitialLayout, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, UINT32 NumCastableFormats, DXGI_FORMAT* pCastableFormats, REFIID riidResource, void** ppvResource) override; - HRESULT __stdcall CreatePlacedResource2(ID3D12Heap* pHeap, UINT64 HeapOffset, const D3D12_RESOURCE_DESC1* pDesc, D3D12_BARRIER_LAYOUT InitialLayout, const D3D12_CLEAR_VALUE* pOptimizedClearValue, UINT32 NumCastableFormats, DXGI_FORMAT* pCastableFormats, REFIID riid, void** ppvResource) override; - HRESULT __stdcall CreateReservedResource2(const D3D12_RESOURCE_DESC* pDesc, D3D12_BARRIER_LAYOUT InitialLayout, const D3D12_CLEAR_VALUE* pOptimizedClearValue, ID3D12ProtectedResourceSession* pProtectedSession, UINT32 NumCastableFormats, DXGI_FORMAT* pCastableFormats, REFIID riid, void** ppvResource) override; - - virtual HRESULT STDMETHODCALLTYPE GetProxyAdapter(IDXGIProxyAdapter** adapter) - { - *adapter = m_adapter; - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE SetProxyAdapter(IDXGIProxyAdapter* adapter) - { - m_adapter = adapter; - return S_OK; - } -}; - diff --git a/CyberXeSS/WrappedDXGIObjects.cpp b/CyberXeSS/WrappedDXGIObjects.cpp deleted file mode 100644 index 4e44a561..00000000 --- a/CyberXeSS/WrappedDXGIObjects.cpp +++ /dev/null @@ -1,542 +0,0 @@ -#include "pch.h" -#include "dxgi1_6.h" -#include "WrappedDXGIObjects.h" - -bool RefCountDXGIObject::HandleWrap(const char* ifaceName, REFIID riid, void** ppvObject) -{ - LOG("RefCountDXGIObject.HandleWrap"); - - if (ppvObject == NULL || *ppvObject == NULL) - { - std::string str(ifaceName); - LOG("RefCountDXGIObject.HandleWrap called with NULL ppvObject querying " + str); - return false; - } - - // unknown GUID that we only want to print once to avoid log spam - // {79D2046C-22EF-451B-9E74-2245D9C760EA} - static const GUID Unknown_uuid = { 0x79d2046c, 0x22ef, 0x451b, {0x9e, 0x74, 0x22, 0x45, 0xd9, 0xc7, 0x60, 0xea} }; - - // ditto - // {9B7E4C04-342C-4106-A19F-4F2704F689F0} - static const GUID ID3D10Texture2D_uuid = { 0x9b7e4c04, 0x342c, 0x4106, {0xa1, 0x9f, 0x4f, 0x27, 0x04, 0xf6, 0x89, 0xf0} }; - -#ifdef BLOCK_IDXGIAdapterInternal2 - // unknown/undocumented internal interface - // {7abb6563-02bc-47c4-8ef9-acc4795edbcf} - static const GUID IDXGIAdapterInternal2_uuid = { 0x7abb6563, 0x02bc, 0x47c4, {0x8e, 0xf9, 0xac, 0xc4, 0x79, 0x5e, 0xdb, 0xcf} }; -#endif - - - if (riid == __uuidof(IDXGIDevice) || - riid == __uuidof(IDXGIDevice1)) - { - // should have been handled elsewhere, so we can properly create this device - std::string str(ifaceName); - LOG("Unexpected uuid in RefCountDXGIObject::HandleWrap querying : " + str); - return false; - } - else if (riid == __uuidof(IDXGIAdapter)) - { - if (b_wrappingEnabled) - { - IDXGIAdapter* real = (IDXGIAdapter*)(*ppvObject); - *ppvObject = (IDXGIAdapter*)(new WrappedIDXGIAdapter4(real)); - } - } - else if (riid == __uuidof(IDXGIAdapter1)) - { - if (b_wrappingEnabled) - { - IDXGIAdapter1* real = (IDXGIAdapter1*)(*ppvObject); - *ppvObject = (IDXGIAdapter1*)(new WrappedIDXGIAdapter4(real)); - } - } - else if (riid == __uuidof(IDXGIAdapter2)) - { - if (b_wrappingEnabled) - { - IDXGIAdapter2* real = (IDXGIAdapter2*)(*ppvObject); - *ppvObject = (IDXGIAdapter2*)(new WrappedIDXGIAdapter4(real)); - } - } - else if (riid == __uuidof(IDXGIAdapter3)) - { - if (b_wrappingEnabled) - { - IDXGIAdapter3* real = (IDXGIAdapter3*)(*ppvObject); - *ppvObject = (IDXGIAdapter3*)(new WrappedIDXGIAdapter4(real)); - } - } - else if (riid == __uuidof(IDXGIAdapter4)) - { - if (b_spoofEnabled) - { - IDXGIAdapter4* real = (IDXGIAdapter4*)(*ppvObject); - *ppvObject = (IDXGIAdapter4*)(new WrappedIDXGIAdapter4(real)); - } - } - else if (riid == __uuidof(IDXGIFactory)) - { - // yes I know PRECISELY how fucked up this is. Speak to microsoft - after KB2670838 the internal - // D3D11 device creation function will pass in __uuidof(IDXGIFactory) then attempt to call - // EnumDevices1 (which is in the IDXGIFactory1 vtable). Doing this *should* be safe as using a - // IDXGIFactory1 like a IDXGIFactory should all just work by definition, but there's no way to - // know now if someone trying to create a IDXGIFactory really means it or not. - IDXGIFactory* real = (IDXGIFactory*)(*ppvObject); - *ppvObject = (IDXGIFactory*)(new WrappedIDXGIFactory(real)); - } - else if (riid == __uuidof(IDXGIFactory1)) - { - IDXGIFactory1* real = (IDXGIFactory1*)(*ppvObject); - *ppvObject = (IDXGIFactory1*)(new WrappedIDXGIFactory(real)); - } - else if (riid == __uuidof(IDXGIFactory2)) - { - IDXGIFactory2* real = (IDXGIFactory2*)(*ppvObject); - *ppvObject = (IDXGIFactory2*)(new WrappedIDXGIFactory(real)); - } - else if (riid == __uuidof(IDXGIFactory3)) - { - IDXGIFactory3* real = (IDXGIFactory3*)(*ppvObject); - *ppvObject = (IDXGIFactory3*)(new WrappedIDXGIFactory(real)); - } - else if (riid == __uuidof(IDXGIFactory4)) - { - IDXGIFactory4* real = (IDXGIFactory4*)(*ppvObject); - *ppvObject = (IDXGIFactory4*)(new WrappedIDXGIFactory(real)); - } - else if (riid == __uuidof(IDXGIFactory5)) - { - IDXGIFactory5* real = (IDXGIFactory5*)(*ppvObject); - *ppvObject = (IDXGIFactory5*)(new WrappedIDXGIFactory(real)); - } - else if (riid == __uuidof(IDXGIFactory6)) - { - IDXGIFactory6* real = (IDXGIFactory6*)(*ppvObject); - *ppvObject = (IDXGIFactory6*)(new WrappedIDXGIFactory(real)); - } - else if (riid == __uuidof(IDXGIFactory7)) - { - IDXGIFactory7* real = (IDXGIFactory7*)(*ppvObject); - *ppvObject = (IDXGIFactory7*)(new WrappedIDXGIFactory(real)); - } - else if (riid == ID3D10Texture2D_uuid) - { - static bool printed = false; - - if (!printed) - { - printed = true; - std::string str(ifaceName); - LOG("RefCountDXGIObject.HandleWrap Querying " + str + " for unsupported ID3D10Texture2D_uuid interface: " + ToString(riid)); - } - - return false; - } - else if (riid == Unknown_uuid) - { - static bool printed = false; - if (!printed) - { - printed = true; - std::string str(ifaceName); - LOG("RefCountDXGIObject.HandleWrap Querying " + str + " for unknown GUID: " + ToString(riid)); - } - - return false; - } -#ifdef BLOCK_IDXGIAdapterInternal2 - else if (riid == IDXGIAdapterInternal2_uuid) - { - static bool printed = false; - if (!printed) - { - printed = true; - std::string str(ifaceName); - LOG("RefCountDXGIObject.HandleWrap Querying " + str + " for unsupported/undocumented interface: IDXGIAdapterInternal2"); - } - - return false; - } -#endif - else - { - std::string str(ifaceName); - LOG("RefCountDXGIObject.HandleWrap Querying " + str + " for unrecognized GUID: " + ToString(riid)); - } - - return true; -} - -HRESULT STDMETHODCALLTYPE RefCountDXGIObject::GetParent( - /* [in] */ REFIID riid, - /* [retval][out] */ void** ppParent) -{ - LOG("RefCountDXGIObject.GetParent"); - - HRESULT ret = m_pReal->GetParent(riid, ppParent); - - if (ret == S_OK) - HandleWrap("GetParent", riid, ppParent); - - return ret; -} - -HRESULT RefCountDXGIObject::WrapQueryInterface(IUnknown* real, const char* ifaceName, REFIID riid, void** ppvObject) -{ - LOG("RefCountDXGIObject.WrapQueryInterface riid: " + ToString(riid)); - -#ifdef BLOCK_IDXGIAdapterInternal2 - // unknown/undocumented internal interface - // {7abb6563-02bc-47c4-8ef9-acc4795edbcf} - static const GUID IDXGIAdapterInternal2_uuid = { 0x7abb6563, 0x02bc, 0x47c4, {0x8e, 0xf9, 0xac, 0xc4, 0x79, 0x5e, 0xdb, 0xcf} }; - - if (riid == IDXGIAdapterInternal2_uuid) - { - LOG("RefCountDXGIObject.WrapQueryInterface IDXGIAdapterInternal2 result: " + int_to_hex(E_NOINTERFACE)); - return E_NOINTERFACE; - } -#endif - - HRESULT ret = real->QueryInterface(riid, ppvObject); - LOG("RefCountDXGIObject.WrapQueryInterface real->QueryInterface result: " + int_to_hex(ret)); - - if (ret == S_OK && HandleWrap(ifaceName, riid, ppvObject)) - { - LOG("RefCountDXGIObject.WrapQueryInterface HandleWrap result: " + int_to_hex(ret)); - return ret; - } - - LOG("RefCountDXGIObject.WrapQueryInterface result: E_NOINTERFACE"); - return E_NOINTERFACE; -} - - -WrappedIDXGIAdapter4::WrappedIDXGIAdapter4(IDXGIAdapter* real) - : RefCountDXGIObject(real), m_pReal(real) -{ - LOG("WrappedIDXGIAdapter4.ctor"); - - m_pReal1 = NULL; - real->QueryInterface(__uuidof(IDXGIAdapter1), (void**)&m_pReal1); - m_pReal2 = NULL; - real->QueryInterface(__uuidof(IDXGIAdapter2), (void**)&m_pReal2); - m_pReal3 = NULL; - real->QueryInterface(__uuidof(IDXGIAdapter3), (void**)&m_pReal3); - m_pReal4 = NULL; - real->QueryInterface(__uuidof(IDXGIAdapter4), (void**)&m_pReal4); - - b_spoofEnabled = true; -} - -WrappedIDXGIAdapter4::~WrappedIDXGIAdapter4() -{ - LOG("WrappedIDXGIAdapter4.dtor"); - - SAFE_RELEASE(m_pReal1); - SAFE_RELEASE(m_pReal2); - SAFE_RELEASE(m_pReal3); - SAFE_RELEASE(m_pReal4); - SAFE_RELEASE(m_pReal); -} - -HRESULT STDMETHODCALLTYPE WrappedIDXGIAdapter4::QueryInterface(REFIID riid, void** ppvObject) -{ - LOG("WrappedIDXGIAdapter4.QueryInterface riid: " + ToString(riid)); - -#ifndef BLOCK_IDXGIAdapterInternal2 - // unknown/undocumented internal interface - // {7abb6563-02bc-47c4-8ef9-acc4795edbcf} - static const GUID IDXGIAdapterInternal2_uuid = { 0x7abb6563, 0x02bc, 0x47c4, {0x8e, 0xf9, 0xac, 0xc4, 0x79, 0x5e, 0xdb, 0xcf} }; -#endif - - - if (riid == __uuidof(IDXGIAdapter)) - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter"); - AddRef(); - *ppvObject = (IDXGIAdapter*)this; - return S_OK; - } - else if (riid == __uuidof(IDXGIProxyAdapter)) - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIProxyAdapter"); - AddRef(); - *ppvObject = (IDXGIProxyAdapter*)this; - return S_OK; - } - else if (riid == __uuidof(IDXGIAdapter1)) - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter1"); - - if (m_pReal1) - { - AddRef(); - *ppvObject = (IDXGIAdapter1*)this; - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter1 result: OK"); - return S_OK; - } - else - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter1 result: E_NOINTERFACE"); - return E_NOINTERFACE; - } - } - else if (riid == __uuidof(IDXGIAdapter2)) - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter2"); - - if (m_pReal2) - { - AddRef(); - *ppvObject = (IDXGIAdapter2*)this; - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter2 result: OK"); - return S_OK; - } - else - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter2 result: E_NOINTERFACE"); - return E_NOINTERFACE; - } - } - else if (riid == __uuidof(IDXGIAdapter3)) - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter3"); - - if (m_pReal3) - { - AddRef(); - *ppvObject = (IDXGIAdapter3*)this; - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter3 result: OK"); - return S_OK; - } - else - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter3 result: E_NOINTERFACE"); - return E_NOINTERFACE; - } - } - else if (riid == __uuidof(IDXGIAdapter4)) - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter4"); - - if (m_pReal4) - { - AddRef(); - *ppvObject = (IDXGIAdapter4*)this; - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter4 result: OK"); - return S_OK; - } - else - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapter4 result: E_NOINTERFACE"); - return E_NOINTERFACE; - } - } -#ifndef BLOCK_IDXGIAdapterInternal2 - else if (riid == IDXGIAdapterInternal2_uuid && m_pReal != nullptr) - { - LOG("WrappedIDXGIAdapter4.QueryInterface for IDXGIAdapterInternal2, returning real adapter"); - return m_pReal->QueryInterface(riid, ppvObject); - } -#endif - - return RefCountDXGIObject::QueryInterface("IDXGIAdapter", riid, ppvObject); -} - -WrappedIDXGIFactory::WrappedIDXGIFactory(IDXGIFactory* real) - : RefCountDXGIObject(real), m_pReal(real) -{ - LOG("WrappedIDXGIFactory.ctor"); - - m_pReal1 = NULL; - real->QueryInterface(__uuidof(IDXGIFactory1), (void**)&m_pReal1); - m_pReal2 = NULL; - real->QueryInterface(__uuidof(IDXGIFactory2), (void**)&m_pReal2); - m_pReal3 = NULL; - real->QueryInterface(__uuidof(IDXGIFactory3), (void**)&m_pReal3); - m_pReal4 = NULL; - real->QueryInterface(__uuidof(IDXGIFactory4), (void**)&m_pReal4); - m_pReal5 = NULL; - real->QueryInterface(__uuidof(IDXGIFactory5), (void**)&m_pReal5); - m_pReal6 = NULL; - real->QueryInterface(__uuidof(IDXGIFactory6), (void**)&m_pReal6); - m_pReal7 = NULL; - real->QueryInterface(__uuidof(IDXGIFactory7), (void**)&m_pReal7); -} - -WrappedIDXGIFactory::~WrappedIDXGIFactory() -{ - LOG("WrappedIDXGIFactory.dtor"); - - SAFE_RELEASE(m_pReal1); - SAFE_RELEASE(m_pReal2); - SAFE_RELEASE(m_pReal3); - SAFE_RELEASE(m_pReal4); - SAFE_RELEASE(m_pReal5); - SAFE_RELEASE(m_pReal6); - SAFE_RELEASE(m_pReal7); - SAFE_RELEASE(m_pReal); -} - -HRESULT STDMETHODCALLTYPE WrappedIDXGIFactory::QueryInterface(REFIID riid, void** ppvObject) -{ - LOG("WrappedIDXGIFactory.QueryInterface"); - - // {713f394e-92ca-47e7-ab81-1159c2791e54} - static const GUID IDXGIFactoryDWM_uuid = { - 0x713f394e, 0x92ca, 0x47e7, {0xab, 0x81, 0x11, 0x59, 0xc2, 0x79, 0x1e, 0x54} }; - - // {1ddd77aa-9a4a-4cc8-9e55-98c196bafc8f} - static const GUID IDXGIFactoryDWM8_uuid = { - 0x1ddd77aa, 0x9a4a, 0x4cc8, {0x9e, 0x55, 0x98, 0xc1, 0x96, 0xba, 0xfc, 0x8f} }; - - if (riid == __uuidof(IDXGIFactory)) - { - AddRef(); - *ppvObject = (IDXGIFactory*)this; - return S_OK; - } - else if (riid == __uuidof(IDXGIFactory1)) - { - if (m_pReal1) - { - AddRef(); - *ppvObject = (IDXGIFactory1*)this; - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else if (riid == __uuidof(IDXGIFactory2)) - { - if (m_pReal2) - { - AddRef(); - *ppvObject = (IDXGIFactory2*)this; - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else if (riid == __uuidof(IDXGIFactory3)) - { - if (m_pReal3) - { - AddRef(); - *ppvObject = (IDXGIFactory3*)this; - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else if (riid == __uuidof(IDXGIFactory4)) - { - if (m_pReal4) - { - AddRef(); - *ppvObject = (IDXGIFactory4*)this; - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else if (riid == __uuidof(IDXGIFactory5)) - { - if (m_pReal5) - { - AddRef(); - *ppvObject = (IDXGIFactory5*)this; - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else if (riid == __uuidof(IDXGIFactory6)) - { - if (m_pReal6) - { - AddRef(); - *ppvObject = (IDXGIFactory6*)this; - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else if (riid == __uuidof(IDXGIFactory7)) - { - if (m_pReal7) - { - AddRef(); - *ppvObject = (IDXGIFactory7*)this; - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else if (riid == IDXGIFactoryDWM_uuid) - { - //RDCWARN("Blocking QueryInterface for IDXGIFactoryDWM"); - return E_NOINTERFACE; - } - else if (riid == IDXGIFactoryDWM8_uuid) - { - //RDCWARN("Blocking QueryInterface for IDXGIFactoryDWM8"); - return E_NOINTERFACE; - } - - return RefCountDXGIObject::QueryInterface("IDXGIFactory", riid, ppvObject); -} - -HRESULT WrappedIDXGIFactory::CreateSwapChain(IUnknown* pDevice, DXGI_SWAP_CHAIN_DESC* pDesc, - IDXGISwapChain** ppSwapChain) -{ - LOG("WrappedIDXGIFactory.CreateSwapChain"); - - return m_pReal->CreateSwapChain(pDevice, pDesc, ppSwapChain); -} - -HRESULT WrappedIDXGIFactory::CreateSwapChainForHwnd( - IUnknown* pDevice, HWND hWnd, const DXGI_SWAP_CHAIN_DESC1* pDesc, - const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullscreenDesc, IDXGIOutput* pRestrictToOutput, - IDXGISwapChain1** ppSwapChain) -{ - LOG("WrappedIDXGIFactory.CreateSwapChainForHwnd"); - - return m_pReal2->CreateSwapChainForHwnd(pDevice, hWnd, pDesc, pFullscreenDesc, pRestrictToOutput, ppSwapChain); -} - -HRESULT WrappedIDXGIFactory::CreateSwapChainForCoreWindow(IUnknown* pDevice, IUnknown* pWindow, - const DXGI_SWAP_CHAIN_DESC1* pDesc, - IDXGIOutput* pRestrictToOutput, - IDXGISwapChain1** ppSwapChain) -{ - LOG("WrappedIDXGIFactory.CreateSwapChainForCoreWindow"); - - return m_pReal2->CreateSwapChainForCoreWindow(pDevice, pWindow, pDesc, pRestrictToOutput, ppSwapChain); -} - -HRESULT WrappedIDXGIFactory::CreateSwapChainForComposition(IUnknown* pDevice, - const DXGI_SWAP_CHAIN_DESC1* pDesc, - IDXGIOutput* pRestrictToOutput, - IDXGISwapChain1** ppSwapChain) -{ - LOG("WrappedIDXGIFactory.CreateSwapChainForComposition"); - - return m_pReal2->CreateSwapChainForComposition(pDevice, pDesc, pRestrictToOutput, ppSwapChain); -} diff --git a/CyberXeSS/WrappedDXGIObjects.h b/CyberXeSS/WrappedDXGIObjects.h deleted file mode 100644 index c7044f0c..00000000 --- a/CyberXeSS/WrappedDXGIObjects.h +++ /dev/null @@ -1,882 +0,0 @@ -#include "pch.h" -#include "dxgi1_6.h" - -//#define BLOCK_IDXGIAdapterInternal2 - -class RefCountDXGIObject : public IDXGIObject -{ - IDXGIObject* m_pReal; - unsigned int m_iRefcount; - -public: - RefCountDXGIObject(IDXGIObject* real) : m_pReal(real), m_iRefcount(1) {} - virtual ~RefCountDXGIObject() {} - static bool HandleWrap(const char* ifaceName, REFIID riid, void** ppvObject); - static HRESULT WrapQueryInterface(IUnknown* real, const char* ifaceName, REFIID riid, void** ppvObject); - - ////////////////////////////// - // implement IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface( /* [in] */ REFIID riid, /* [annotation][iid_is][out] */ __RPC__deref_out void** ppvObject) - { - LOG("RefCountDXGIObject.QueryInterface"); - auto result = QueryInterface("IUnknown", riid, ppvObject); - LOG("RefCountDXGIObject.QueryInterface result: " + int_to_hex(result)); - - return result; - } - - // optional overload that's useful for passing down the name of the current interface to put in - // any 'unknown interface' query logs. - HRESULT STDMETHODCALLTYPE QueryInterface(const char* ifaceName, REFIID riid, void** ppvObject) - { - if (riid == __uuidof(IUnknown)) - { - AddRef(); - *ppvObject = (IUnknown*)(IDXGIObject*)this; - return S_OK; - } - else if (riid == __uuidof(IDXGIObject)) - { - AddRef(); - *ppvObject = (IDXGIObject*)this; - return S_OK; - } - - return WrapQueryInterface(m_pReal, ifaceName, riid, ppvObject); - } - - ULONG STDMETHODCALLTYPE AddRef() - { - LOG("RefCountDXGIObject.AddRef"); - InterlockedIncrement(&m_iRefcount); - LOG("RefCountDXGIObject.AddRef result: " + int_to_hex(m_iRefcount)); - return m_iRefcount; - } - ULONG STDMETHODCALLTYPE Release() - { - LOG("RefCountDXGIObject.Release"); - - unsigned int ret = InterlockedDecrement(&m_iRefcount); - - LOG("RefCountDXGIObject.Release result: " + int_to_hex(m_iRefcount)); - - if (ret == 0) - { - LOG("RefCountDXGIObject.Release deleting object"); - delete this; - } - - return ret; - } - - ////////////////////////////// - // implement IDXGIObject - - virtual HRESULT STDMETHODCALLTYPE SetPrivateData( - /* [in] */ REFGUID Name, - /* [in] */ UINT DataSize, - /* [in] */ const void* pData) - { - LOG("RefCountDXGIObject.SetPrivateData"); - auto result = m_pReal->SetPrivateData(Name, DataSize, pData); - LOG("RefCountDXGIObject.SetPrivateData result: " + int_to_hex(result)); - return result; - } - - virtual HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( - /* [in] */ REFGUID Name, - /* [in] */ const IUnknown* pUnknown) - { - LOG("RefCountDXGIObject.SetPrivateDataInterface"); - auto result = m_pReal->SetPrivateDataInterface(Name, pUnknown); - LOG("RefCountDXGIObject.SetPrivateDataInterface result: " + int_to_hex(result)); - return result; - } - - virtual HRESULT STDMETHODCALLTYPE GetPrivateData( - /* [in] */ REFGUID Name, - /* [out][in] */ UINT* pDataSize, - /* [out] */ void* pData) - { - LOG("RefCountDXGIObject.GetPrivateData"); - auto result = m_pReal->GetPrivateData(Name, pDataSize, pData); - LOG("RefCountDXGIObject.GetPrivateData result: " + int_to_hex(result)); - return result; - } - - virtual HRESULT STDMETHODCALLTYPE GetParent( - /* [in] */ REFIID riid, - /* [retval][out] */ void** ppParent); -}; - -#define IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT_CUSTOMQUERY \ - ULONG STDMETHODCALLTYPE AddRef() \ - { \ - return RefCountDXGIObject::AddRef(); \ - } \ - ULONG STDMETHODCALLTYPE Release() \ - { \ - return RefCountDXGIObject::Release(); \ - } \ - HRESULT STDMETHODCALLTYPE SetPrivateData(REFIID Name, UINT DataSize, const void *pData) \ - { \ - return RefCountDXGIObject::SetPrivateData(Name, DataSize, pData); \ - } \ - HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(REFIID Name, const IUnknown *pUnknown) \ - { \ - return RefCountDXGIObject::SetPrivateDataInterface(Name, pUnknown); \ - } \ - HRESULT STDMETHODCALLTYPE GetPrivateData(REFIID Name, UINT *pDataSize, void *pData) \ - { \ - return RefCountDXGIObject::GetPrivateData(Name, pDataSize, pData); \ - } \ - HRESULT STDMETHODCALLTYPE GetParent(REFIID riid, void **ppvObject) \ - { \ - return RefCountDXGIObject::GetParent(riid, ppvObject); \ - } - - -MIDL_INTERFACE("cfdf09b3-a084-4453-a755-7d4e5389b845") -IDXGIProxyAdapter : public IUnknown -{ -public: - virtual HRESULT STDMETHODCALLTYPE Spoofing(bool enable); - virtual HRESULT STDMETHODCALLTYPE Wrapping(bool enable); -}; - -static bool b_spoofEnabled = true; -static bool b_wrappingEnabled = true; - -class WrappedIDXGIAdapter4 : public IDXGIAdapter4, public RefCountDXGIObject, public IDXGIProxyAdapter -{ - IDXGIAdapter* m_pReal; - IDXGIAdapter1* m_pReal1; - IDXGIAdapter2* m_pReal2; - IDXGIAdapter3* m_pReal3; - IDXGIAdapter4* m_pReal4; - -public: - WrappedIDXGIAdapter4(IDXGIAdapter* real); - virtual ~WrappedIDXGIAdapter4(); - - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT_CUSTOMQUERY; - - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); - - ////////////////////////////// - // implement IDXGIAdapter - - virtual HRESULT STDMETHODCALLTYPE EnumOutputs( /* [in] */ UINT Output, /* [annotation][out][in] */ __out IDXGIOutput** ppOutput) - { - LOG("WrappedIDXGIAdapter4.EnumOutputs"); - HRESULT ret = m_pReal->EnumOutputs(Output, ppOutput); - LOG("WrappedIDXGIAdapter4.EnumOutputs result: " + int_to_hex(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE GetDesc( /* [annotation][out] */ __out DXGI_ADAPTER_DESC* pDesc) - { - LOG("WrappedIDXGIAdapter4.GetDesc"); - - HRESULT hr; - hr = m_pReal->GetDesc(pDesc); - - if (hr == S_OK && b_spoofEnabled && pDesc != nullptr && (pDesc->VendorId == 0x8086 || pDesc->VendorId == 0x1002)) - { - LOG("WrappedIDXGIAdapter4.GetDesc Spoofing card info"); - pDesc->VendorId = 0x10de; - pDesc->DeviceId = 0x24c9; - pDesc->SubSysId = 0x88ac1043; - pDesc->Revision = 0x00a1; - - std::wstring name(L"NVIDIA GeForce RTX 3060 Ti"); - const wchar_t* szName = name.c_str(); - std::memset(pDesc->Description, 0, sizeof(pDesc->Description)); - std::memcpy(pDesc->Description, szName, 54); - - LUID luid = LUID{ 0, 56090 }; - std::memcpy(&pDesc->AdapterLuid, &luid, 8); - } - - //b_spoofEnabled = true; - - LOG("WrappedIDXGIAdapter4.GetDesc result: " + int_to_hex(hr)); - return hr; - } - - virtual HRESULT STDMETHODCALLTYPE CheckInterfaceSupport( - /* [annotation][in] */ - __in REFGUID InterfaceName, - /* [annotation][out] */ - __out LARGE_INTEGER* pUMDVersion) - { - LOG("WrappedIDXGIAdapter4.CheckInterfaceSupport"); - auto result = m_pReal->CheckInterfaceSupport(InterfaceName, pUMDVersion); - LOG("WrappedIDXGIAdapter4.CheckInterfaceSupport result: " + int_to_hex(result)); - return result; - } - - ////////////////////////////// - // implement IDXGIAdapter1 - - virtual HRESULT STDMETHODCALLTYPE GetDesc1( - /* [out] */ DXGI_ADAPTER_DESC1* pDesc) - { - LOG("WrappedIDXGIAdapter4.GetDesc1"); - - if (!m_pReal1) - { - LOG("WrappedIDXGIAdapter4.GetDesc1 no adapter!"); - return E_NOINTERFACE; - } - - - HRESULT hr; - hr = m_pReal1->GetDesc1(pDesc); - - if (hr == S_OK && b_spoofEnabled && pDesc != nullptr && (pDesc->VendorId == 0x8086 || pDesc->VendorId == 0x1002)) - { - LOG("WrappedIDXGIAdapter4.GetDesc1 Spoofing card info"); - - pDesc->VendorId = 0x10de; - pDesc->DeviceId = 0x24c9; - pDesc->SubSysId = 0x88ac1043; - pDesc->Revision = 0x00a1; - - std::wstring name(L"NVIDIA GeForce RTX 3060 Ti"); - const wchar_t* szName = name.c_str(); - std::memset(pDesc->Description, 0, sizeof(pDesc->Description)); - std::memcpy(pDesc->Description, szName, 54); - - LUID luid = LUID{ 0, 56090 }; - std::memcpy(&pDesc->AdapterLuid, &luid, 8); - } - - //b_spoofEnabled = true; - - LOG("WrappedIDXGIAdapter4.GetDesc1 result: " + int_to_hex(hr)); - return hr; - } - - ////////////////////////////// - // implement IDXGIAdapter2 - - virtual HRESULT STDMETHODCALLTYPE GetDesc2( - /* [annotation][out] */ - _Out_ DXGI_ADAPTER_DESC2* pDesc) - { - LOG("WrappedIDXGIAdapter4.GetDesc2"); - - if (!m_pReal2) - { - LOG("WrappedIDXGIAdapter4.GetDesc2 no adapter!"); - return E_NOINTERFACE; - } - - HRESULT hr; - hr = m_pReal2->GetDesc2(pDesc); - - if (hr == S_OK && b_spoofEnabled && pDesc != nullptr && (pDesc->VendorId == 0x8086 || pDesc->VendorId == 0x1002)) - { - LOG("WrappedIDXGIAdapter4.GetDesc2 Spoofing card info"); - - pDesc->VendorId = 0x10de; - pDesc->DeviceId = 0x24c9; - pDesc->SubSysId = 0x88ac1043; - pDesc->Revision = 0x00a1; - - std::wstring name(L"NVIDIA GeForce RTX 3060 Ti"); - const wchar_t* szName = name.c_str(); - std::memset(pDesc->Description, 0, sizeof(pDesc->Description)); - std::memcpy(pDesc->Description, szName, 54); - - LUID luid = LUID{ 0, 56090 }; - std::memcpy(&pDesc->AdapterLuid, &luid, 8); - } - - //b_spoofEnabled = true; - - LOG("WrappedIDXGIAdapter4.GetDesc2 result: " + int_to_hex(hr)); - - return hr; - } - - ////////////////////////////// - // implement IDXGIAdapter3 - - virtual HRESULT STDMETHODCALLTYPE RegisterHardwareContentProtectionTeardownStatusEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD* pdwCookie) - { - LOG("WrappedIDXGIAdapter4.RegisterHardwareContentProtectionTeardownStatusEvent"); - auto result = m_pReal3->RegisterHardwareContentProtectionTeardownStatusEvent(hEvent, pdwCookie); - LOG("WrappedIDXGIAdapter4.RegisterHardwareContentProtectionTeardownStatusEvent result: " + int_to_hex(result)); - return result; - } - - virtual void STDMETHODCALLTYPE UnregisterHardwareContentProtectionTeardownStatus( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - LOG("WrappedIDXGIAdapter4.UnregisterHardwareContentProtectionTeardownStatus"); - m_pReal3->UnregisterHardwareContentProtectionTeardownStatus(dwCookie); - LOG("WrappedIDXGIAdapter4.UnregisterHardwareContentProtectionTeardownStatus done"); - } - - virtual HRESULT STDMETHODCALLTYPE QueryVideoMemoryInfo( - /* [annotation][in] */ - _In_ UINT NodeIndex, - /* [annotation][in] */ - _In_ DXGI_MEMORY_SEGMENT_GROUP MemorySegmentGroup, - /* [annotation][out] */ - _Out_ DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfo) - { - LOG("WrappedIDXGIAdapter4.QueryVideoMemoryInfo"); - - auto result = m_pReal3->QueryVideoMemoryInfo(NodeIndex, MemorySegmentGroup, pVideoMemoryInfo); - LOG("WrappedIDXGIAdapter4.QueryVideoMemoryInfo result: " + int_to_hex(result)); - return result; - } - - virtual HRESULT STDMETHODCALLTYPE SetVideoMemoryReservation( - /* [annotation][in] */ - _In_ UINT NodeIndex, - /* [annotation][in] */ - _In_ DXGI_MEMORY_SEGMENT_GROUP MemorySegmentGroup, - /* [annotation][in] */ - _In_ UINT64 Reservation) - { - LOG("WrappedIDXGIAdapter4.SetVideoMemoryReservation"); - - auto result = m_pReal3->SetVideoMemoryReservation(NodeIndex, MemorySegmentGroup, Reservation); - LOG("WrappedIDXGIAdapter4.SetVideoMemoryReservation result: " + int_to_hex(result)); - return result; - } - - virtual HRESULT STDMETHODCALLTYPE RegisterVideoMemoryBudgetChangeNotificationEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD* pdwCookie) - { - LOG("WrappedIDXGIAdapter4.RegisterVideoMemoryBudgetChangeNotificationEvent"); - - auto result = m_pReal3->RegisterVideoMemoryBudgetChangeNotificationEvent(hEvent, pdwCookie); - LOG("WrappedIDXGIAdapter4.RegisterVideoMemoryBudgetChangeNotificationEvent result: " + int_to_hex(result)); - return result; - } - - virtual void STDMETHODCALLTYPE UnregisterVideoMemoryBudgetChangeNotification( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - LOG("WrappedIDXGIAdapter4.UnregisterVideoMemoryBudgetChangeNotification"); - - m_pReal3->UnregisterVideoMemoryBudgetChangeNotification(dwCookie); - LOG("WrappedIDXGIAdapter4.UnregisterVideoMemoryBudgetChangeNotification done"); - } - - ////////////////////////////// - // implement IDXGIAdapter4 - - virtual HRESULT STDMETHODCALLTYPE GetDesc3( - /* [annotation][out] */ - _Out_ DXGI_ADAPTER_DESC3* pDesc) - { - LOG("WrappedIDXGIAdapter4.GetDesc3"); - - if (!m_pReal4) - { - LOG("WrappedIDXGIAdapter4.GetDesc3 no adapter!"); - return E_NOINTERFACE; - } - - HRESULT hr; - hr = m_pReal4->GetDesc3(pDesc); - - if (hr == S_OK && b_spoofEnabled && pDesc != nullptr && (pDesc->VendorId == 0x8086 || pDesc->VendorId == 0x1002)) - { - LOG("WrappedIDXGIAdapter4.GetDesc3 Spoofing card info"); - - pDesc->VendorId = 0x10de; - pDesc->DeviceId = 0x24c9; - pDesc->SubSysId = 0x88ac1043; - pDesc->Revision = 0x00a1; - - std::wstring name(L"NVIDIA GeForce RTX 3060 Ti"); - const wchar_t* szName = name.c_str(); - std::memset(pDesc->Description, 0, sizeof(pDesc->Description)); - std::memcpy(pDesc->Description, szName, 54); - - LUID luid = LUID{ 0, 56090 }; - std::memcpy(&pDesc->AdapterLuid, &luid, 8); - } - - //b_spoofEnabled = true; - - LOG("WrappedIDXGIAdapter4.GetDesc3 result: " + int_to_hex(hr)); - - return hr; - } - - virtual HRESULT STDMETHODCALLTYPE Spoofing(bool enable) - { - LOG("WrappedIDXGIAdapter4.Spoofing : " + std::to_string(enable)); - b_spoofEnabled = enable; - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Wrapping(bool enable) - { - LOG("WrappedIDXGIAdapter4.Wrapping : " + std::to_string(enable)); - b_wrappingEnabled = enable; - return S_OK; - } -}; - -class WrappedIDXGIFactory : public IDXGIFactory7, public RefCountDXGIObject -{ - IDXGIFactory* m_pReal; - IDXGIFactory1* m_pReal1; - IDXGIFactory2* m_pReal2; - IDXGIFactory3* m_pReal3; - IDXGIFactory4* m_pReal4; - IDXGIFactory5* m_pReal5; - IDXGIFactory6* m_pReal6; - IDXGIFactory7* m_pReal7; - -public: - WrappedIDXGIFactory(IDXGIFactory* real); - virtual ~WrappedIDXGIFactory(); - - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT_CUSTOMQUERY; - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); - - ////////////////////////////// - // implement IDXGIFactory - - virtual HRESULT STDMETHODCALLTYPE EnumAdapters( - /* [in] */ UINT Adapter, - /* [annotation][out] */ - __out IDXGIAdapter** ppAdapter) - { - LOG("WrappedIDXGIFactory.EnumAdapters " + std::to_string(Adapter)); - - HRESULT ret = m_pReal->EnumAdapters(Adapter, ppAdapter); - - if (ret == S_OK && b_wrappingEnabled) - *ppAdapter = (IDXGIAdapter*)(new WrappedIDXGIAdapter4(*ppAdapter)); - - LOG("WrappedIDXGIFactory.EnumAdapters result: " + int_to_hex(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE MakeWindowAssociation(HWND WindowHandle, UINT Flags) - { - LOG("WrappedIDXGIFactory.MakeWindowAssociation"); - - auto ret = m_pReal->MakeWindowAssociation(WindowHandle, Flags); - LOG("WrappedIDXGIFactory.MakeWindowAssociation result: " + int_to_hex(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE GetWindowAssociation( - /* [annotation][out] */ - __out HWND* pWindowHandle) - { - LOG("WrappedIDXGIFactory.GetWindowAssociation"); - - auto ret = m_pReal->GetWindowAssociation(pWindowHandle); - LOG("WrappedIDXGIFactory.GetWindowAssociation result: " + int_to_hex(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChain( - /* [annotation][in] */ - __in IUnknown* pDevice, - /* [annotation][in] */ - __in DXGI_SWAP_CHAIN_DESC* pDesc, - /* [annotation][out] */ - __out IDXGISwapChain** ppSwapChain); - - virtual HRESULT STDMETHODCALLTYPE CreateSoftwareAdapter( - /* [in] */ HMODULE Module, - /* [annotation][out] */ - __out IDXGIAdapter** ppAdapter) - { - LOG("WrappedIDXGIFactory.CreateSoftwareAdapter"); - - HRESULT ret = m_pReal->CreateSoftwareAdapter(Module, ppAdapter); - - if (ret == S_OK && b_wrappingEnabled) - *ppAdapter = (IDXGIAdapter*)(new WrappedIDXGIAdapter4(*ppAdapter)); - - LOG("WrappedIDXGIFactory.CreateSoftwareAdapter result: " + int_to_hex(ret)); - return ret; - } - - ////////////////////////////// - // implement IDXGIFactory1 - - virtual HRESULT STDMETHODCALLTYPE EnumAdapters1( - /* [in] */ UINT Adapter, - /* [annotation][out] */ - __out IDXGIAdapter1** ppAdapter) - { - LOG("WrappedIDXGIFactory.EnumAdapters1 " + std::to_string(Adapter)); - - IDXGIFactory1* factory = m_pReal1; - if (m_pReal1 == NULL) - { - // see comment in RefCountDXGIObject::HandleWrap for IDXGIFactory - //RDCWARN("Calling EnumAdapters1 with no IDXGIFactory1 - assuming weird internal call"); - factory = (IDXGIFactory1*)m_pReal; - } - - HRESULT ret = factory->EnumAdapters1(Adapter, ppAdapter); - - if (ret == S_OK && b_wrappingEnabled) - *ppAdapter = (IDXGIAdapter1*)(new WrappedIDXGIAdapter4(*ppAdapter)); - - LOG("WrappedIDXGIFactory.EnumAdapters1 result: " + int_to_hex(ret)); - return ret; - } - - virtual BOOL STDMETHODCALLTYPE IsCurrent(void) - { - LOG("WrappedIDXGIFactory.IsCurrent"); - - auto ret = m_pReal1->IsCurrent(); - LOG("WrappedIDXGIFactory.IsCurrent result: " + std::to_string(ret)); - return ret; - } - ////////////////////////////// - // implement IDXGIFactory2 - - virtual BOOL STDMETHODCALLTYPE IsWindowedStereoEnabled(void) - { - LOG("WrappedIDXGIFactory.IsWindowedStereoEnabled"); - - auto ret = m_pReal2->IsWindowedStereoEnabled(); - LOG("WrappedIDXGIFactory.IsCurrent result: " + std::to_string(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForHwnd( - /* [annotation][in] */ - _In_ IUnknown* pDevice, - /* [annotation][in] */ - _In_ HWND hWnd, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1* pDesc, - /* [annotation][in] */ - _In_opt_ const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullscreenDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput* pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1** ppSwapChain); - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForCoreWindow( - /* [annotation][in] */ - _In_ IUnknown* pDevice, - /* [annotation][in] */ - _In_ IUnknown* pWindow, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1* pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput* pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1** ppSwapChain); - - virtual HRESULT STDMETHODCALLTYPE GetSharedResourceAdapterLuid( - /* [annotation] */ - _In_ HANDLE hResource, - /* [annotation] */ - _Out_ LUID* pLuid) - { - LOG("WrappedIDXGIFactory.GetSharedResourceAdapterLuid"); - - auto ret = m_pReal2->GetSharedResourceAdapterLuid(hResource, pLuid); - LOG("WrappedIDXGIFactory.GetSharedResourceAdapterLuid result: " + int_to_hex(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE RegisterStereoStatusWindow( - /* [annotation][in] */ - _In_ HWND WindowHandle, - /* [annotation][in] */ - _In_ UINT wMsg, - /* [annotation][out] */ - _Out_ DWORD* pdwCookie) - { - LOG("WrappedIDXGIFactory.RegisterStereoStatusWindow"); - - auto ret = m_pReal2->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); - LOG("WrappedIDXGIFactory.RegisterStereoStatusWindow result: " + int_to_hex(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE RegisterStereoStatusEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD* pdwCookie) - { - LOG("WrappedIDXGIFactory.RegisterStereoStatusEvent"); - - auto ret = m_pReal2->RegisterStereoStatusEvent(hEvent, pdwCookie); - LOG("WrappedIDXGIFactory.RegisterStereoStatusEvent result: " + int_to_hex(ret)); - return ret; - } - - virtual void STDMETHODCALLTYPE UnregisterStereoStatus( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - LOG("WrappedIDXGIFactory.UnregisterStereoStatus"); - - m_pReal2->UnregisterStereoStatus(dwCookie); - LOG("WrappedIDXGIFactory.UnregisterStereoStatus done"); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterOcclusionStatusWindow( - /* [annotation][in] */ - _In_ HWND WindowHandle, - /* [annotation][in] */ - _In_ UINT wMsg, - /* [annotation][out] */ - _Out_ DWORD* pdwCookie) - { - LOG("WrappedIDXGIFactory.RegisterOcclusionStatusWindow"); - - auto ret = m_pReal2->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); - LOG("WrappedIDXGIFactory.RegisterOcclusionStatusWindow result: " + int_to_hex(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE RegisterOcclusionStatusEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD* pdwCookie) - { - LOG("WrappedIDXGIFactory.RegisterOcclusionStatusEvent"); - - auto ret = m_pReal2->RegisterOcclusionStatusEvent(hEvent, pdwCookie); - LOG("WrappedIDXGIFactory.RegisterOcclusionStatusEvent result: " + int_to_hex(ret)); - return ret; - } - - virtual void STDMETHODCALLTYPE UnregisterOcclusionStatus( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - LOG("WrappedIDXGIFactory.UnregisterOcclusionStatus"); - - m_pReal2->UnregisterOcclusionStatus(dwCookie); - LOG("WrappedIDXGIFactory.UnregisterOcclusionStatus done"); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForComposition( - /* [annotation][in] */ - _In_ IUnknown* pDevice, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1* pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput* pRestrictToOutput, - /* [annotation][out] */ - _Outptr_ IDXGISwapChain1** ppSwapChain); - - ////////////////////////////// - // implement IDXGIFactory3 - - virtual UINT STDMETHODCALLTYPE GetCreationFlags(void) - { - LOG("WrappedIDXGIFactory.GetCreationFlags"); - - auto ret = m_pReal3->GetCreationFlags(); - LOG("WrappedIDXGIFactory.GetCreationFlags result: " + int_to_hex(ret)); - return ret; - } - ////////////////////////////// - // implement IDXGIFactory4 - - bool WrapAdapter(REFIID riid, void** ppvAdapter) - { - LOG("WrappedIDXGIFactory.WrapAdapter"); - - if (ppvAdapter == NULL || *ppvAdapter == NULL) - { - LOG("WrappedIDXGIFactory.WrapAdapter ppvAdapter is NULL!"); - return false; - } - - if (riid == __uuidof(IDXGIAdapter4) && b_wrappingEnabled) - { - IDXGIAdapter4* adapter = (IDXGIAdapter4*)*ppvAdapter; - *ppvAdapter = (IDXGIAdapter4*)(new WrappedIDXGIAdapter4(adapter)); - return true; - } - else if (riid == __uuidof(IDXGIAdapter3) && b_wrappingEnabled) - { - IDXGIAdapter3* adapter = (IDXGIAdapter3*)*ppvAdapter; - *ppvAdapter = (IDXGIAdapter3*)(new WrappedIDXGIAdapter4(adapter)); - return true; - } - else if (riid == __uuidof(IDXGIAdapter2) && b_wrappingEnabled) - { - IDXGIAdapter2* adapter = (IDXGIAdapter2*)*ppvAdapter; - *ppvAdapter = (IDXGIAdapter2*)(new WrappedIDXGIAdapter4(adapter)); - return true; - } - else if (riid == __uuidof(IDXGIAdapter1) && b_wrappingEnabled) - { - IDXGIAdapter1* adapter = (IDXGIAdapter1*)*ppvAdapter; - *ppvAdapter = (IDXGIAdapter1*)(new WrappedIDXGIAdapter4(adapter)); - return true; - } - else if (riid == __uuidof(IDXGIAdapter) && b_wrappingEnabled) - { - IDXGIAdapter* adapter = (IDXGIAdapter*)*ppvAdapter; - *ppvAdapter = (IDXGIAdapter*)(new WrappedIDXGIAdapter4(adapter)); - return true; - } - else - { - return RefCountDXGIObject::HandleWrap("IDXGIAdapter", riid, ppvAdapter); - } - - return false; - } - - virtual HRESULT STDMETHODCALLTYPE EnumAdapterByLuid( /* [annotation] */ _In_ LUID AdapterLuid, /* [annotation] */ _In_ REFIID riid, /* [annotation] */ _COM_Outptr_ void** ppvAdapter) - - { -#ifdef BLOCK_IDXGIAdapterInternal2 - // unknown/undocumented internal interface - // {7abb6563-02bc-47c4-8ef9-acc4795edbcf} - static const GUID IDXGIAdapterInternal2_uuid = { - 0x7abb6563, 0x02bc, 0x47c4, {0x8e, 0xf9, 0xac, 0xc4, 0x79, 0x5e, 0xdb, 0xcf} }; - - if (riid == IDXGIAdapterInternal2_uuid) - { - LOG("WrappedIDXGIFactory.EnumAdapterByLuid IDXGIAdapterInternal2_uuid result: " + int_to_hex(DXGI_ERROR_NOT_FOUND)); - return DXGI_ERROR_NOT_FOUND; - } -#endif - - LOG("WrappedIDXGIFactory.EnumAdapterByLuid LUID: " + int_to_hex(AdapterLuid.HighPart) + "-" + int_to_hex(AdapterLuid.LowPart) + " riid: " + ToString(riid)); - - HRESULT ret = m_pReal4->EnumAdapterByLuid(AdapterLuid, riid, ppvAdapter); - - if (ret == S_OK && b_wrappingEnabled) - { - auto wrapResult = this->WrapAdapter(riid, ppvAdapter); - - if (!wrapResult) - { - LOG("WrappedIDXGIFactory.EnumAdapterByLuid wrapResult result: " + int_to_hex(DXGI_ERROR_NOT_FOUND)); - return DXGI_ERROR_NOT_FOUND; - } - } - else - { - LOG("WrappedIDXGIFactory.EnumAdapterByLuid can't get adapter by LUID, user first adapter"); - IDXGIAdapter* wrappedAdapter; - ret = this->EnumAdapters(0, &wrappedAdapter); - - if (ret == S_OK) - *ppvAdapter = wrappedAdapter; - } - - LOG("WrappedIDXGIFactory.EnumAdapterByLuid result: " + int_to_hex(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE EnumWarpAdapter( - /* [annotation] */ - _In_ REFIID riid, - /* [annotation] */ - _COM_Outptr_ void** ppvAdapter) - { - LOG("WrappedIDXGIFactory.EnumWarpAdapter"); - - HRESULT ret = m_pReal4->EnumWarpAdapter(riid, ppvAdapter); - - if (ret == S_OK && b_wrappingEnabled) - WrapAdapter(riid, ppvAdapter); - - LOG("WrappedIDXGIFactory.EnumWarpAdapter result: " + int_to_hex(ret)); - return ret; - } - - ////////////////////////////// - // implement IDXGIFactory5 - - virtual HRESULT STDMETHODCALLTYPE - CheckFeatureSupport(DXGI_FEATURE Feature, - /* [annotation] */ - _Inout_updates_bytes_(FeatureSupportDataSize) void* pFeatureSupportData, - UINT FeatureSupportDataSize) - { - LOG("WrappedIDXGIFactory.CheckFeatureSupport"); - - auto ret = m_pReal5->CheckFeatureSupport(Feature, pFeatureSupportData, FeatureSupportDataSize); - LOG("WrappedIDXGIFactory.CheckFeatureSupport result: " + int_to_hex(ret)); - return ret; - } - - ////////////////////////////// - // implement IDXGIFactory6 - - virtual HRESULT STDMETHODCALLTYPE EnumAdapterByGpuPreference( - /* [annotation] */ - _In_ UINT Adapter, - /* [annotation] */ - _In_ DXGI_GPU_PREFERENCE GpuPreference, - /* [annotation] */ - _In_ REFIID riid, - /* [annotation] */ - _COM_Outptr_ void** ppvAdapter) - { - LOG("WrappedIDXGIFactory.EnumAdapterByGpuPreference " + std::to_string(Adapter) + ", GpuPreference: " + int_to_hex(GpuPreference)); - - HRESULT ret = m_pReal6->EnumAdapterByGpuPreference(Adapter, GpuPreference, riid, ppvAdapter); - - if (ret == S_OK && b_wrappingEnabled) - WrapAdapter(riid, ppvAdapter); - - LOG("WrappedIDXGIFactory.EnumAdapterByGpuPreference result: " + int_to_hex(ret)); - return ret; - } - - ////////////////////////////// - // implement IDXGIFactory7 - - virtual HRESULT STDMETHODCALLTYPE RegisterAdaptersChangedEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD* pdwCookie) - { - LOG("WrappedIDXGIFactory.RegisterAdaptersChangedEvent"); - - auto ret = m_pReal7->RegisterAdaptersChangedEvent(hEvent, pdwCookie); - LOG("WrappedIDXGIFactory.RegisterAdaptersChangedEvent result: " + int_to_hex(ret)); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE UnregisterAdaptersChangedEvent( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - LOG("WrappedIDXGIFactory.UnregisterAdaptersChangedEvent"); - - auto ret = m_pReal7->UnregisterAdaptersChangedEvent(dwCookie); - LOG("WrappedIDXGIFactory.UnregisterAdaptersChangedEvent result: " + int_to_hex(ret)); - return ret; - } -}; -