diff --git a/.github/workflows/.patches/dawn.diff b/.github/workflows/.patches/dawn.diff index 972c502a3..2a0f3d942 100644 --- a/.github/workflows/.patches/dawn.diff +++ b/.github/workflows/.patches/dawn.diff @@ -491,14 +491,14 @@ index 214fa67f8..d909d4d2a 100644 + + gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {}; + allocatorDesc.Adapter = adapter->GetHardwareAdapter(); -+ allocatorDesc.Device = mD3d12Device; ++ allocatorDesc.Device = mD3d12Device.Get(); + allocatorDesc.ResourceHeapTier = + static_cast(adapter->GetDeviceInfo().resourceHeapTier); + allocatorDesc.PreferredResourceHeapSize = 4ll * 1024ll * 1024ll; // 4MB + + gpgmm::d3d12::RESIDENCY_DESC residencyDesc = {}; + residencyDesc.Adapter = adapter->GetHardwareAdapter(); -+ residencyDesc.Device = mD3d12Device; ++ residencyDesc.Device = mD3d12Device.Get(); + residencyDesc.IsUMA = adapter->GetDeviceInfo().isUMA; + + if (IsToggleEnabled(Toggle::UseD3D12SmallResidencyBudgetForTesting)) { diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index ee6f247bc..dec6f0ed7 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -33,7 +33,6 @@ #ifndef GPGMM_WINDOWS_HEADERS_ALREADY_INCLUDED # include // for DEFINE_ENUM_FLAG_OPERATORS -# include // for Microsoft::WRL::ComPtr #endif #define GPGMM_INTERFACE struct @@ -317,7 +316,7 @@ namespace gpgmm::d3d12 { /** \brief Specifies the device used by this residency manager. Required parameter. Use CreateDevice get the device. */ - Microsoft::WRL::ComPtr Device; + ID3D12Device* Device; /** \brief Specifies the adapter used by this residency manager. @@ -325,7 +324,7 @@ namespace gpgmm::d3d12 { Required parameter. Use EnumAdapters to get the adapter. */ - Microsoft::WRL::ComPtr Adapter; + IDXGIAdapter3* Adapter; /** \brief Specifies if unified memory architecture (UMA) is enabled. @@ -785,7 +784,7 @@ namespace gpgmm::d3d12 { Required parameter. Use CreateDevice get the device. */ - Microsoft::WRL::ComPtr Device; + ID3D12Device* Device; /** \brief Specifies the adapter used by this allocator. @@ -795,7 +794,7 @@ namespace gpgmm::d3d12 { Optional parameter. Use EnumAdapters to get the adapter. */ - Microsoft::WRL::ComPtr Adapter; + IDXGIAdapter* Adapter; /** \brief Specifies allocator options. diff --git a/src/fuzzers/D3D12Fuzzer.cpp b/src/fuzzers/D3D12Fuzzer.cpp index a96a85915..d3f0939af 100644 --- a/src/fuzzers/D3D12Fuzzer.cpp +++ b/src/fuzzers/D3D12Fuzzer.cpp @@ -20,19 +20,20 @@ uint64_t UInt8ToUInt64(const uint8_t* src) { return dst; } -HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* allocatorDesc) { +HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* pAllocatorDesc, + ID3D12Device** ppDeviceOut, + IDXGIAdapter3** ppAdapterOut) { gpgmm::d3d12::ALLOCATOR_DESC allocatorDescOut = {}; // Populate the device - ComPtr d3dDevice; - if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&d3dDevice)))) { + if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(ppDeviceOut)))) { return E_FAIL; } - allocatorDescOut.Device = d3dDevice; + allocatorDescOut.Device = *ppDeviceOut; // Populate the adapter - LUID adapterLUID = d3dDevice->GetAdapterLuid(); + LUID adapterLUID = allocatorDescOut.Device->GetAdapterLuid(); ComPtr dxgiFactory; if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)))) { return E_FAIL; @@ -43,25 +44,17 @@ HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* allocatorDesc) return E_FAIL; } - ComPtr dxgiAdapter; - if (FAILED(dxgiFactory4->EnumAdapterByLuid(adapterLUID, IID_PPV_ARGS(&dxgiAdapter)))) { + if (FAILED(dxgiFactory4->EnumAdapterByLuid(adapterLUID, IID_PPV_ARGS(ppAdapterOut)))) { return E_FAIL; } - allocatorDescOut.Adapter = dxgiAdapter; + allocatorDescOut.Adapter = *ppAdapterOut; // Configure options - D3D12_FEATURE_DATA_D3D12_OPTIONS options = {}; - if (FAILED(d3dDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, - sizeof(options)))) { - return E_FAIL; - } - - allocatorDescOut.ResourceHeapTier = options.ResourceHeapTier; allocatorDescOut.MinLogLevel = D3D12_MESSAGE_SEVERITY_MESSAGE; - if (allocatorDesc != nullptr) { - *allocatorDesc = allocatorDescOut; + if (pAllocatorDesc != nullptr) { + *pAllocatorDesc = allocatorDescOut; } return S_OK; diff --git a/src/fuzzers/D3D12Fuzzer.h b/src/fuzzers/D3D12Fuzzer.h index 56cd93a26..c9daeb32e 100644 --- a/src/fuzzers/D3D12Fuzzer.h +++ b/src/fuzzers/D3D12Fuzzer.h @@ -17,11 +17,15 @@ #include +#include + using Microsoft::WRL::ComPtr; uint64_t UInt8ToUInt64(const uint8_t* src); -HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* allocatorDesc); +HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* allocatorDesc, + ID3D12Device** ppDeviceOut, + IDXGIAdapter3** ppAdapterOut); D3D12_RESOURCE_DESC CreateBufferDesc(uint64_t width, uint64_t alignment = 0); diff --git a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp index fb071cd0a..0f37f6246 100644 --- a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp +++ b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp @@ -22,6 +22,9 @@ namespace { + ComPtr gDevice; + ComPtr gAdapter; + ComPtr gResourceAllocator; ComPtr gResidencyManager; std::vector> gAllocationsBelowBudget = {}; @@ -41,7 +44,7 @@ namespace { extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {}; - if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc))) { + if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc, &gDevice, &gAdapter))) { return 0; } @@ -50,11 +53,11 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { gpgmm::d3d12::RESIDENCY_DESC residencyDesc = {}; ComPtr adapter3; - if (FAILED(allocatorDesc.Adapter.As(&adapter3))) { + if (FAILED(allocatorDesc.Adapter->QueryInterface(IID_PPV_ARGS(&adapter3)))) { return 0; } - residencyDesc.Adapter = adapter3; + residencyDesc.Adapter = adapter3.Get(); residencyDesc.Device = allocatorDesc.Device; residencyDesc.MinLogLevel = D3D12_MESSAGE_SEVERITY_MESSAGE; diff --git a/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp b/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp index 82020fd9f..0cecf3ea5 100644 --- a/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp +++ b/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp @@ -20,13 +20,16 @@ namespace { + ComPtr gDevice; + ComPtr gAdapter; + ComPtr gResourceAllocator; } // namespace extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {}; - if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc))) { + if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc, &gDevice, &gAdapter))) { return 0; } diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 66753616a..3f7b88355 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -168,8 +168,7 @@ namespace gpgmm::d3d12 { std::unique_ptr caps; { Caps* ptr = nullptr; - ReturnIfFailed( - Caps::CreateCaps(descriptor.Device.Get(), descriptor.Adapter.Get(), &ptr)); + ReturnIfFailed(Caps::CreateCaps(descriptor.Device, descriptor.Adapter, &ptr)); caps.reset(ptr); } diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index a0fad241e..c4d910a60 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -393,14 +393,14 @@ namespace gpgmm::d3d12 { residencyDesc.Device = allocatorDescriptor.Device; if (allocatorDescriptor.Adapter != nullptr) { - ReturnIfFailed(allocatorDescriptor.Adapter.As(&residencyDesc.Adapter)); + ReturnIfFailed(allocatorDescriptor.Adapter->QueryInterface( + IID_PPV_ARGS(&residencyDesc.Adapter))); } std::unique_ptr caps; { Caps* ptr = nullptr; - ReturnIfFailed(Caps::CreateCaps(residencyDesc.Device.Get(), - residencyDesc.Adapter.Get(), &ptr)); + ReturnIfFailed(Caps::CreateCaps(residencyDesc.Device, residencyDesc.Adapter, &ptr)); caps.reset(ptr); } @@ -437,8 +437,8 @@ namespace gpgmm::d3d12 { std::unique_ptr caps; { Caps* ptr = nullptr; - ReturnIfFailed(Caps::CreateCaps(allocatorDescriptor.Device.Get(), - allocatorDescriptor.Adapter.Get(), &ptr)); + ReturnIfFailed( + Caps::CreateCaps(allocatorDescriptor.Device, allocatorDescriptor.Adapter, &ptr)); caps.reset(ptr); } diff --git a/src/mvi/gpgmm_d3d12.cpp b/src/mvi/gpgmm_d3d12.cpp index 8091ad2a5..18894ff69 100644 --- a/src/mvi/gpgmm_d3d12.cpp +++ b/src/mvi/gpgmm_d3d12.cpp @@ -303,7 +303,8 @@ namespace gpgmm::d3d12 { residencyDesc.Device = allocatorDescriptor.Device; if (allocatorDescriptor.Adapter != nullptr) { - ReturnIfFailed(allocatorDescriptor.Adapter.As(&residencyDesc.Adapter)); + ReturnIfFailed(allocatorDescriptor.Adapter->QueryInterface( + IID_PPV_ARGS(&residencyDesc.Adapter))); } D3D12_FEATURE_DATA_ARCHITECTURE arch = {}; diff --git a/src/mvi/gpgmm_d3d12.h b/src/mvi/gpgmm_d3d12.h index fce4ae1bf..6cb01d1a6 100644 --- a/src/mvi/gpgmm_d3d12.h +++ b/src/mvi/gpgmm_d3d12.h @@ -42,6 +42,8 @@ #include "gpgmm.h" +#include // for Microsoft::WRL::ComPtr + namespace gpgmm::d3d12 { class Unknown : public IUnknown { diff --git a/src/samples/D3D12Sample.cpp b/src/samples/D3D12Sample.cpp index db6600e8f..ebbf20689 100644 --- a/src/samples/D3D12Sample.cpp +++ b/src/samples/D3D12Sample.cpp @@ -57,8 +57,8 @@ HRESULT Init() { } gpgmm::d3d12::ALLOCATOR_DESC desc = {}; - desc.Adapter = adapter3; - desc.Device = device; + desc.Adapter = adapter3.Get(); + desc.Device = device.Get(); desc.ResourceHeapTier = options.ResourceHeapTier; Microsoft::WRL::ComPtr resourceAllocator; diff --git a/src/tests/D3D12Test.cpp b/src/tests/D3D12Test.cpp index ee90c3591..2f6713077 100644 --- a/src/tests/D3D12Test.cpp +++ b/src/tests/D3D12Test.cpp @@ -100,8 +100,8 @@ namespace gpgmm::d3d12 { ALLOCATOR_DESC desc = {}; // Required parameters. - desc.Adapter = mAdapter; - desc.Device = mDevice; + desc.Adapter = mAdapter.Get(); + desc.Device = mDevice.Get(); desc.ResourceHeapTier = mCaps->GetMaxResourceHeapTierSupported(); desc.MinLogLevel = GetMessageSeverity(GetLogLevel()); @@ -127,8 +127,8 @@ namespace gpgmm::d3d12 { RESIDENCY_DESC D3D12TestBase::CreateBasicResidencyDesc() const { RESIDENCY_DESC desc = {}; // Required - desc.Adapter = mAdapter; - desc.Device = mDevice; + desc.Adapter = mAdapter.Get(); + desc.Device = mDevice.Get(); desc.IsUMA = mCaps->IsAdapterUMA(); desc.MinLogLevel = GetMessageSeverity(GetLogLevel()); diff --git a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp index 168eed6dd..bf2a62564 100644 --- a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp +++ b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp @@ -97,8 +97,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocator) { // Creating an allocator without the resource heap tier specified should always succeed. { ALLOCATOR_DESC desc = {}; - desc.Device = mDevice; - desc.Adapter = mAdapter; + desc.Device = mDevice.Get(); + desc.Adapter = mAdapter.Get(); ComPtr resourceAllocator; EXPECT_SUCCEEDED(CreateResourceAllocator(desc, &resourceAllocator, nullptr));