From dd1917b1e7983c17d57a94e4e4d44b9d31d3c7bb Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Thu, 30 Mar 2023 09:33:50 -0700 Subject: [PATCH] Move device/adapter parameters out of descriptors. --- .github/workflows/.patches/dawn.diff | 246 +++++++++--------- README.md | 5 +- include/gpgmm_d3d12.h | 47 ++-- src/fuzzers/D3D12Fuzzer.cpp | 6 +- src/fuzzers/D3D12ResidencyManagerFuzzer.cpp | 18 +- src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp | 4 +- src/gpgmm/d3d12/ResidencyManagerD3D12.cpp | 26 +- src/gpgmm/d3d12/ResidencyManagerD3D12.h | 7 +- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 45 ++-- src/gpgmm/d3d12/ResourceAllocatorD3D12.h | 5 + src/mvi/gpgmm_d3d12.cpp | 45 ++-- src/mvi/gpgmm_d3d12.h | 14 +- src/samples/D3D12Sample.cpp | 5 +- src/tests/D3D12Test.cpp | 9 - .../D3D12EventTraceReplay.cpp | 7 +- .../end2end/D3D12ResidencyManagerTests.cpp | 101 +++---- .../end2end/D3D12ResourceAllocatorTests.cpp | 202 +++++++------- 17 files changed, 423 insertions(+), 369 deletions(-) diff --git a/.github/workflows/.patches/dawn.diff b/.github/workflows/.patches/dawn.diff index 8d1f0ae88..e574d6cc4 100644 --- a/.github/workflows/.patches/dawn.diff +++ b/.github/workflows/.patches/dawn.diff @@ -23,7 +23,7 @@ index 44c173ca5..75b81684c 100644 @@ -148,6 +148,10 @@ deps = { 'condition': 'dawn_standalone', }, - + + 'third_party/gpgmm': { + 'url': '{github_git}/intel/gpgmm.git@1bef1757e937d6ae407e6c7283a4d718c1922991', + }, @@ -40,7 +40,7 @@ index 6440625c5..ef3784630 100644 dawn_vulkan_validation_layers_dir = "//third_party/vulkan-deps/vulkan-validation-layers/src" +dawn_gpgmm_dir = "//third_party/gpgmm" - + # Optional path to a one-liner version file. Default is empty path indicating # that git should be used to figure out the version. diff --git a/scripts/dawn_overrides_with_defaults.gni b/scripts/dawn_overrides_with_defaults.gni @@ -50,14 +50,14 @@ index bbe79e18c..3fd68fc73 100644 @@ -82,8 +82,9 @@ if (!defined(dawn_vulkan_validation_layers_dir)) { dawn_vulkan_validation_layers_dir = "" } - + -if (!defined(dawn_abseil_dir)) { - dawn_abseil_dir = "//third_party/abseil-cpp" +if (!defined(dawn_gpgmm_dir)) { + # Default to GPGMM being Dawn's DEPS + dawn_gpgmm_dir = "${dawn_root}/third_party/gpgmm" } - + if (!defined(dawn_version_file)) { diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index 19ca4d4b8..88bab7391 100644 @@ -109,7 +109,7 @@ index 2093a0a20..f5038beef 100644 SetToggle(Toggle::DisallowUnsafeAPIs, true); + SetToggle(Toggle::DumpResourceAllocator, false); } - + void DeviceBase::ApplyToggleOverrides(const DawnTogglesDeviceDescriptor* togglesDescriptor) { diff --git a/src/dawn/native/Toggles.cpp b/src/dawn/native/Toggles.cpp index 8fbf0e3e8..08a7229f4 100644 @@ -156,7 +156,7 @@ index e23830e89..144ea3e22 100644 + D3D12_MESSAGE_ID_MAP_INVALID_NULLRANGE, + D3D12_MESSAGE_ID_UNMAP_INVALID_NULLRANGE, }; - + // Create a retrieval filter with a deny list to suppress messages. diff --git a/src/dawn/native/d3d12/BufferD3D12.cpp b/src/dawn/native/d3d12/BufferD3D12.cpp index 0488fce6a..21b6f7eca 100644 @@ -165,7 +165,7 @@ index 0488fce6a..21b6f7eca 100644 @@ -153,9 +153,15 @@ MaybeError Buffer::Initialize(bool mappedAtCreation) { mLastUsage = wgpu::BufferUsage::CopySrc; } - + - DAWN_TRY_ASSIGN( - mResourceAllocation, - ToBackend(GetDevice())->AllocateMemory(heapType, resourceDescriptor, bufferUsage)); @@ -178,12 +178,12 @@ index 0488fce6a..21b6f7eca 100644 + DAWN_TRY_ASSIGN(mResourceAllocation, ToBackend(GetDevice()) + ->AllocateMemory(heapType, resourceDescriptor, + bufferUsage, allocationFlags)); - + SetLabelImpl(); - + @@ -190,7 +196,11 @@ MaybeError Buffer::Initialize(bool mappedAtCreation) { Buffer::~Buffer() = default; - + ID3D12Resource* Buffer::GetD3D12Resource() const { - return mResourceAllocation.GetD3D12Resource(); + if (mResourceAllocation == nullptr) { @@ -192,7 +192,7 @@ index 0488fce6a..21b6f7eca 100644 + + return mResourceAllocation->GetResource(); } - + // When true is returned, a D3D12_RESOURCE_BARRIER has been created and must be used in a @@ -200,8 +210,7 @@ bool Buffer::TrackUsageAndGetResourceBarrier(CommandRecordingContext* commandCon D3D12_RESOURCE_BARRIER* barrier, @@ -201,12 +201,12 @@ index 0488fce6a..21b6f7eca 100644 - Heap* heap = ToBackend(mResourceAllocation.GetResourceHeap()); - commandContext->TrackHeapUsage(heap, GetDevice()->GetPendingCommandSerial()); + commandContext->GetResidencyList()->Add(mResourceAllocation->GetMemory()); - + // Return the resource barrier. return TransitionUsageAndGetResourceBarrier(commandContext, barrier, newUsage); @@ -299,7 +308,11 @@ bool Buffer::TransitionUsageAndGetResourceBarrier(CommandRecordingContext* comma } - + D3D12_GPU_VIRTUAL_ADDRESS Buffer::GetVA() const { - return mResourceAllocation.GetGPUPointer(); + return mResourceAllocation->GetGPUVirtualAddress(); @@ -215,12 +215,12 @@ index 0488fce6a..21b6f7eca 100644 +uint64_t Buffer::GetOffsetFromResource() const { + return mResourceAllocation->GetOffsetFromResource(); } - + bool Buffer::IsCPUWritableAtCreation() const { @@ -320,9 +333,6 @@ MaybeError Buffer::MapInternal(bool isWrite, size_t offset, size_t size, const c // evicted. This buffer should already have been made resident when it was created. TRACE_EVENT0(GetDevice()->GetPlatform(), General, "BufferD3D12::MapInternal"); - + - Heap* heap = ToBackend(mResourceAllocation.GetResourceHeap()); - DAWN_TRY(ToBackend(GetDevice())->GetResidencyManager()->LockAllocation(heap)); - @@ -233,12 +233,12 @@ index 0488fce6a..21b6f7eca 100644 // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12resource-map - DAWN_TRY(CheckHRESULT(GetD3D12Resource()->Map(0, &range, &mMappedData), contextInfo)); + DAWN_TRY(CheckHRESULT(mResourceAllocation->Map(0, &range, &mMappedData), contextInfo)); - + if (isWrite) { mWrittenMappedRange = range; @@ -367,14 +377,9 @@ MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) } - + void Buffer::UnmapImpl() { - GetD3D12Resource()->Unmap(0, &mWrittenMappedRange); + mResourceAllocation->Unmap(0, &mWrittenMappedRange); @@ -250,39 +250,39 @@ index 0488fce6a..21b6f7eca 100644 - Heap* heap = ToBackend(mResourceAllocation.GetResourceHeap()); - ToBackend(GetDevice())->GetResidencyManager()->UnlockAllocation(heap); } - + void* Buffer::GetMappedPointerImpl() { @@ -392,16 +397,16 @@ void Buffer::DestroyImpl() { } BufferBase::DestroyImpl(); - + - ToBackend(GetDevice())->DeallocateMemory(mResourceAllocation); + ToBackend(GetDevice())->DeallocateMemory(std::move(mResourceAllocation)); } - + bool Buffer::CheckIsResidentForTesting() const { - Heap* heap = ToBackend(mResourceAllocation.GetResourceHeap()); - return heap->IsInList() || heap->IsResidencyLocked(); + return mResourceAllocation->GetMemory()->GetInfo().IsCachedForResidency || + mResourceAllocation->GetMemory()->GetInfo().IsLocked; } - + -bool Buffer::CheckAllocationMethodForTesting(AllocationMethod allocationMethod) const { - return mResourceAllocation.GetInfo().mMethod == allocationMethod; +bool Buffer::CheckAllocationMethodForTesting(gpgmm::AllocationMethod allocationMethod) const { + return mResourceAllocation->GetInfo().Method == allocationMethod; } - + MaybeError Buffer::EnsureDataInitialized(CommandRecordingContext* commandContext) { @@ -446,8 +451,7 @@ MaybeError Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* c } - + void Buffer::SetLabelImpl() { - SetDebugName(ToBackend(GetDevice()), mResourceAllocation.GetD3D12Resource(), "Dawn_Buffer", - GetLabel()); + SetDebugName(ToBackend(GetDevice()), GetD3D12Resource(), "Dawn_Buffer", GetLabel()); } - + MaybeError Buffer::InitializeToZero(CommandRecordingContext* commandContext) { diff --git a/src/dawn/native/d3d12/BufferD3D12.h b/src/dawn/native/d3d12/BufferD3D12.h index cb36a851a..0ab8e639c 100644 @@ -291,33 +291,33 @@ index cb36a851a..0ab8e639c 100644 @@ -22,6 +22,8 @@ #include "dawn/native/d3d12/ResourceHeapAllocationD3D12.h" #include "dawn/native/d3d12/d3d12_platform.h" - + +#include + namespace dawn::native::d3d12 { - + class CommandRecordingContext; @@ -33,6 +35,7 @@ class Buffer final : public BufferBase { - + ID3D12Resource* GetD3D12Resource() const; D3D12_GPU_VIRTUAL_ADDRESS GetVA() const; + uint64_t GetOffsetFromResource() const; - + bool TrackUsageAndGetResourceBarrier(CommandRecordingContext* commandContext, D3D12_RESOURCE_BARRIER* barrier, @@ -40,7 +43,7 @@ class Buffer final : public BufferBase { void TrackUsageAndTransitionNow(CommandRecordingContext* commandContext, wgpu::BufferUsage newUsage); - + - bool CheckAllocationMethodForTesting(AllocationMethod allocationMethod) const; + bool CheckAllocationMethodForTesting(gpgmm::AllocationMethod allocationMethod) const; bool CheckIsResidentForTesting() const; - + MaybeError EnsureDataInitialized(CommandRecordingContext* commandContext); @@ -77,7 +80,7 @@ class Buffer final : public BufferBase { uint64_t offset = 0, uint64_t size = 0); - + - ResourceHeapAllocation mResourceAllocation; + ComPtr mResourceAllocation; bool mFixedResourceState = false; @@ -329,7 +329,7 @@ index 08aad3418..b063f6225 100644 +++ b/src/dawn/native/d3d12/CommandBufferD3D12.cpp @@ -783,8 +783,10 @@ MaybeError CommandBuffer::RecordCommands(CommandRecordingContext* commandContext dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst); - + commandList->CopyBufferRegion( - dstBuffer->GetD3D12Resource(), copy->destinationOffset, - srcBuffer->GetD3D12Resource(), copy->sourceOffset, copy->size); @@ -339,7 +339,7 @@ index 08aad3418..b063f6225 100644 + srcBuffer->GetOffsetFromResource() + copy->sourceOffset, copy->size); break; } - + @@ -1103,7 +1105,8 @@ MaybeError CommandBuffer::RecordCommands(CommandRecordingContext* commandContext commandContext, offset, size)); DAWN_UNUSED(cleared); @@ -365,14 +365,14 @@ index 1f7e2766f..68d7e7c3b 100644 @@ -59,6 +60,11 @@ MaybeError CommandRecordingContext::Open(ID3D12Device* d3d12Device, mD3d12CommandList.As(&mD3d12CommandList4); } - + + ComPtr residencyList; + DAWN_TRY(CheckHRESULT(gpgmm::d3d12::CreateResidencyList(&residencyList), + "D3D12 creating a residency list")); + mResidencyList = std::move(residencyList); + mIsOpen = true; - + return {}; @@ -81,8 +87,6 @@ MaybeError CommandRecordingContext::ExecuteCommandList(Device* device) { Release(); @@ -380,12 +380,12 @@ index 1f7e2766f..68d7e7c3b 100644 } - DAWN_TRY(device->GetResidencyManager()->EnsureHeapsAreResident(mHeapsPendingUsage.data(), - mHeapsPendingUsage.size())); - + if (device->IsToggleEnabled(Toggle::RecordDetailedTimingInTraceEvents)) { uint64_t gpuTimestamp; @@ -121,7 +125,11 @@ MaybeError CommandRecordingContext::ExecuteCommandList(Device* device) { } - + ID3D12CommandList* d3d12CommandList = GetCommandList(); - device->GetCommandQueue()->ExecuteCommandLists(1, &d3d12CommandList); + gpgmm::d3d12::IResidencyList* residencyList = GetResidencyList(); @@ -393,7 +393,7 @@ index 1f7e2766f..68d7e7c3b 100644 + CheckHRESULT(device->GetResidencyManager()->ExecuteCommandLists( + device->GetCommandQueue().Get(), &d3d12CommandList, &residencyList, 1), + "D3D12 execute command list")); - + for (Texture* texture : mSharedTextures) { texture->SynchronizeImportedTextureAfterUse(); @@ -131,17 +139,14 @@ MaybeError CommandRecordingContext::ExecuteCommandList(Device* device) { @@ -404,7 +404,7 @@ index 1f7e2766f..68d7e7c3b 100644 } return {}; } - + -void CommandRecordingContext::TrackHeapUsage(Heap* heap, ExecutionSerial serial) { - // Before tracking the heap, check the last serial it was recorded on to ensure we aren't - // tracking it more than once. @@ -416,7 +416,7 @@ index 1f7e2766f..68d7e7c3b 100644 + ASSERT(mResidencyList != nullptr); + return mResidencyList.Get(); } - + ID3D12GraphicsCommandList* CommandRecordingContext::GetCommandList() const { @@ -161,6 +166,7 @@ ID3D12GraphicsCommandList4* CommandRecordingContext::GetCommandList4() const { void CommandRecordingContext::Release() { @@ -433,27 +433,27 @@ index 80b6204e1..181354a7b 100644 @@ -22,6 +22,8 @@ #include "dawn/native/d3d12/BufferD3D12.h" #include "dawn/native/d3d12/d3d12_platform.h" - + +#include + namespace dawn::native::d3d12 { class CommandAllocatorManager; class Device; @@ -40,7 +42,7 @@ class CommandRecordingContext { - + MaybeError ExecuteCommandList(Device* device); - + - void TrackHeapUsage(Heap* heap, ExecutionSerial serial); + gpgmm::d3d12::IResidencyList* GetResidencyList(); - + void AddToTempBuffers(Ref tempBuffer); - + @@ -50,6 +52,7 @@ class CommandRecordingContext { bool mIsOpen = false; std::set mSharedTextures; std::vector mHeapsPendingUsage; + ComPtr mResidencyList; - + std::vector> mTempBuffers; }; diff --git a/src/dawn/native/d3d12/D3D12Backend.cpp b/src/dawn/native/d3d12/D3D12Backend.cpp @@ -463,7 +463,7 @@ index 05ddd6b4c..acf1b659d 100644 @@ -99,8 +99,14 @@ uint64_t SetExternalMemoryReservation(WGPUDevice device, MemorySegment memorySegment) { Device* backendDevice = ToBackend(FromAPI(device)); - + - return backendDevice->GetResidencyManager()->SetExternalMemoryReservation( - memorySegment, requestedReservationSize); + uint64_t actualReservationSize = 0; @@ -475,30 +475,30 @@ index 05ddd6b4c..acf1b659d 100644 + } + return actualReservationSize; } - + AdapterDiscoveryOptions::AdapterDiscoveryOptions() diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp index 214fa67f8..d909d4d2a 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.cpp +++ b/src/dawn/native/d3d12/DeviceD3D12.cpp @@ -132,8 +132,43 @@ MaybeError Device::Initialize(const DeviceDescriptor* descriptor) { - + mSamplerHeapCache = std::make_unique(this); - + - mResidencyManager = std::make_unique(this); - mResourceAllocatorManager = std::make_unique(this); + Adapter* adapter = ToBackend(GetAdapter()); + + gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {}; -+ allocatorDesc.Adapter = adapter->GetHardwareAdapter(); -+ allocatorDesc.Device = mD3d12Device.Get(); ++ // allocatorDesc.Adapter = adapter->GetHardwareAdapter(); ++ // 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.Get(); ++ // residencyDesc.Adapter = adapter->GetHardwareAdapter(); ++ // residencyDesc.Device = mD3d12Device.Get(); + // residencyDesc.IsUMA = adapter->GetDeviceInfo().isUMA; + + if (IsToggleEnabled(Toggle::UseD3D12SmallResidencyBudgetForTesting)) { @@ -517,31 +517,31 @@ index 214fa67f8..d909d4d2a 100644 + if (IsToggleEnabled(Toggle::UseD3D12ResidencyManagement)) { + residencyDesc.MaxPctOfVideoMemoryToBudget = 0.95; // Use up to 95% + DAWN_TRY( -+ CheckHRESULT(gpgmm::d3d12::CreateResidencyManager(residencyDesc, &mResidencyManager), ++ CheckHRESULT(gpgmm::d3d12::CreateResidencyManager(residencyDesc, mD3d12Device.Get(), adapter->GetHardwareAdapter(), &mResidencyManager), + "D3D12 create residency manager")); + } + + DAWN_TRY(CheckHRESULT(gpgmm::d3d12::CreateResourceAllocator( -+ allocatorDesc, mResidencyManager.Get(), &mResourceAllocator), ++ allocatorDesc, mD3d12Device.Get(), adapter->GetHardwareAdapter(), mResidencyManager.Get(), &mResourceAllocator), + "D3D12 create resource allocator")); - + // ShaderVisibleDescriptorAllocators use the ResidencyManager and must be initialized after. DAWN_TRY_ASSIGN( @@ -250,8 +285,8 @@ CommandAllocatorManager* Device::GetCommandAllocatorManager() const { return mCommandAllocatorManager.get(); } - + -ResidencyManager* Device::GetResidencyManager() const { - return mResidencyManager.get(); +gpgmm::d3d12::IResidencyManager* Device::GetResidencyManager() const { + return mResidencyManager.Get(); } - + ResultOrError Device::GetPendingCommandContext() { @@ -318,7 +353,6 @@ MaybeError Device::TickImpl() { // Perform cleanup operations to free unused objects ExecutionSerial completedSerial = GetCompletedCommandSerial(); - + - mResourceAllocatorManager->Tick(completedSerial); DAWN_TRY(mCommandAllocatorManager->Tick(completedSerial)); mViewShaderVisibleDescriptorAllocator->Tick(completedSerial); @@ -549,7 +549,7 @@ index 214fa67f8..d909d4d2a 100644 @@ -492,9 +526,9 @@ void Device::CopyFromStagingToBufferImpl(CommandRecordingContext* commandContext StagingBuffer* srcBuffer = ToBackend(source); dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst); - + - commandContext->GetCommandList()->CopyBufferRegion(dstBuffer->GetD3D12Resource(), - destinationOffset, srcBuffer->GetResource(), - sourceOffset, size); @@ -557,12 +557,12 @@ index 214fa67f8..d909d4d2a 100644 + dstBuffer->GetD3D12Resource(), dstBuffer->GetOffsetFromResource() + destinationOffset, + srcBuffer->GetResource(), sourceOffset, size); } - + MaybeError Device::CopyFromStagingToTexture(const StagingBufferBase* source, @@ -523,15 +557,73 @@ MaybeError Device::CopyFromStagingToTexture(const StagingBufferBase* source, return {}; } - + -void Device::DeallocateMemory(ResourceHeapAllocation& allocation) { - mResourceAllocatorManager->DeallocateMemory(allocation); +void Device::DeallocateMemory(ComPtr allocation) { @@ -576,7 +576,7 @@ index 214fa67f8..d909d4d2a 100644 + // calls DeallocateMemory again using the same allocation. + allocation = nullptr; } - + -ResultOrError Device::AllocateMemory( +ResultOrError> Device::CreateExternalAllocation( + ComPtr texture) { @@ -636,7 +636,7 @@ index 214fa67f8..d909d4d2a 100644 + + return allocation; } - + std::unique_ptr Device::CreateExternalImageDXGIImpl( @@ -643,6 +735,7 @@ void Device::InitTogglesFromDriver() { SetToggle(Toggle::UseD3D12ResourceHeapTier2, useResourceHeapTier2); @@ -649,7 +649,7 @@ index 214fa67f8..d909d4d2a 100644 @@ -813,11 +906,6 @@ void Device::DestroyImpl() { ::CloseHandle(mFenceEvent); } - + - // Release recycled resource heaps. - if (mResourceAllocatorManager != nullptr) { - mResourceAllocatorManager->DestroyPool(); @@ -657,7 +657,7 @@ index 214fa67f8..d909d4d2a 100644 - // We need to handle clearing up com object refs that were enqeued after TickImpl mUsedComObjectRefs.ClearUpTo(std::numeric_limits::max()); - + diff --git a/src/dawn/native/d3d12/DeviceD3D12.h b/src/dawn/native/d3d12/DeviceD3D12.h index 0373cf9d8..4cea643f8 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.h @@ -665,11 +665,11 @@ index 0373cf9d8..4cea643f8 100644 @@ -25,14 +25,14 @@ #include "dawn/native/d3d12/Forward.h" #include "dawn/native/d3d12/TextureD3D12.h" - + +#include + namespace dawn::native::d3d12 { - + class CommandAllocatorManager; struct ExternalImageDescriptorDXGISharedHandle; class ExternalImageDXGIImpl; @@ -681,17 +681,17 @@ index 0373cf9d8..4cea643f8 100644 class StagingDescriptorAllocator; @@ -66,7 +66,7 @@ class Device final : public DeviceBase { ComPtr GetDrawIndexedIndirectSignature() const; - + CommandAllocatorManager* GetCommandAllocatorManager() const; - ResidencyManager* GetResidencyManager() const; + gpgmm::d3d12::IResidencyManager* GetResidencyManager() const; - + const PlatformFunctions* GetFunctions() const; ComPtr GetFactory() const; @@ -109,12 +109,16 @@ class Device final : public DeviceBase { TextureCopy* dst, const Extent3D& copySizePixels) override; - + - ResultOrError AllocateMemory( + ResultOrError> AllocateMemory( D3D12_HEAP_TYPE heapType, @@ -701,22 +701,22 @@ index 0373cf9d8..4cea643f8 100644 + gpgmm::d3d12::ALLOCATION_FLAGS allocationFlags = gpgmm::d3d12::ALLOCATION_FLAG_NONE); + + void DeallocateMemory(ComPtr allocation); - + - void DeallocateMemory(ResourceHeapAllocation& allocation); + ResultOrError> CreateExternalAllocation( + ComPtr texture); - + ShaderVisibleDescriptorAllocator* GetViewShaderVisibleDescriptorAllocator() const; ShaderVisibleDescriptorAllocator* GetSamplerShaderVisibleDescriptorAllocator() const; @@ -236,8 +240,8 @@ class Device final : public DeviceBase { SerialQueue> mUsedComObjectRefs; - + std::unique_ptr mCommandAllocatorManager; - std::unique_ptr mResourceAllocatorManager; - std::unique_ptr mResidencyManager; + ComPtr mResourceAllocator; + ComPtr mResidencyManager; - + static constexpr uint32_t kMaxSamplerDescriptorsPerBindGroup = 3 * kMaxSamplersPerShaderStage; static constexpr uint32_t kMaxViewDescriptorsPerBindGroup = diff --git a/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp b/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp @@ -734,7 +734,7 @@ index fe99a63ac..353e47b82 100644 heapType == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); } @@ -140,31 +141,23 @@ void ShaderVisibleDescriptorAllocator::Tick(ExecutionSerial completedSerial) { - + ResultOrError> ShaderVisibleDescriptorAllocator::AllocateHeap(uint32_t descriptorCount) const { + gpgmm::d3d12::HEAP_DESC heapDesc = {}; @@ -777,7 +777,7 @@ index fe99a63ac..353e47b82 100644 + + return std::make_unique(std::move(descriptorHeap)); } - + // Creates a GPU descriptor heap that manages descriptors in a FIFO queue. @@ -174,7 +167,9 @@ MaybeError ShaderVisibleDescriptorAllocator::AllocateAndSwitchShaderVisibleHeap( // The first phase increasingly grows a small heap in binary sizes for light users while the @@ -787,40 +787,40 @@ index fe99a63ac..353e47b82 100644 + if (mResidencyManagementEnabled) { + mDevice->GetResidencyManager()->UnlockHeap(mHeap->GetHeap()); + } - + const uint32_t maxDescriptorCount = GetD3D12ShaderVisibleHeapMaxSize( mHeapType, mDevice->IsToggleEnabled(Toggle::UseD3D12SmallShaderVisibleHeapForTesting)); @@ -200,7 +195,10 @@ MaybeError ShaderVisibleDescriptorAllocator::AllocateAndSwitchShaderVisibleHeap( DAWN_TRY_ASSIGN(descriptorHeap, AllocateHeap(mDescriptorCount)); } - + - DAWN_TRY(mDevice->GetResidencyManager()->LockAllocation(descriptorHeap.get())); + if (mResidencyManagementEnabled) { + DAWN_TRY(CheckHRESULT(mDevice->GetResidencyManager()->LockHeap(descriptorHeap->GetHeap()), + "Unable to lock descriptor heap")); + } - + // Create a FIFO buffer from the recently created heap. mHeap = std::move(descriptorHeap); @@ -227,12 +225,12 @@ uint64_t ShaderVisibleDescriptorAllocator::GetShaderVisiblePoolSizeForTesting() } - + bool ShaderVisibleDescriptorAllocator::IsShaderVisibleHeapLockedResidentForTesting() const { - return mHeap->IsResidencyLocked(); + return mHeap->GetHeap()->GetInfo().IsLocked; } - + bool ShaderVisibleDescriptorAllocator::IsLastShaderVisibleHeapInLRUForTesting() const { ASSERT(!mPool.empty()); - return mPool.back().heap->IsInResidencyLRUCache(); + return mPool.back().heap->GetHeap()->GetInfo().IsCachedForResidency; } - + bool ShaderVisibleDescriptorAllocator::IsAllocationStillValid( @@ -243,13 +241,46 @@ bool ShaderVisibleDescriptorAllocator::IsAllocationStillValid( allocation.GetHeapSerial() == mHeapSerial); } - + -ShaderVisibleDescriptorHeap::ShaderVisibleDescriptorHeap( - ComPtr d3d12DescriptorHeap, - uint64_t size) @@ -828,7 +828,7 @@ index fe99a63ac..353e47b82 100644 - mD3d12DescriptorHeap(std::move(d3d12DescriptorHeap)) {} +ShaderVisibleDescriptorHeap::ShaderVisibleDescriptorHeap(ComPtr descriptorHeap) + : mDescriptorHeap(std::move(descriptorHeap)) {} - + ID3D12DescriptorHeap* ShaderVisibleDescriptorHeap::GetD3D12DescriptorHeap() const { - return mD3d12DescriptorHeap.Get(); + ComPtr descriptorHeap; @@ -877,7 +877,7 @@ index cf09f9d50..f22684f27 100644 @@ -24,6 +24,8 @@ #include "dawn/native/d3d12/PageableD3D12.h" #include "dawn/native/d3d12/d3d12_platform.h" - + +#include + // |ShaderVisibleDescriptorAllocator| allocates a variable-sized block of descriptors from a GPU @@ -886,7 +886,7 @@ index cf09f9d50..f22684f27 100644 @@ -35,13 +37,14 @@ namespace dawn::native::d3d12 { class Device; class GPUDescriptorHeapAllocation; - + -class ShaderVisibleDescriptorHeap : public Pageable { +class ShaderVisibleDescriptorHeap { public: @@ -894,12 +894,12 @@ index cf09f9d50..f22684f27 100644 + ShaderVisibleDescriptorHeap(ComPtr descriptorHeap); ID3D12DescriptorHeap* GetD3D12DescriptorHeap() const; + gpgmm::d3d12::IHeap* GetHeap() const; - + private: - ComPtr mD3d12DescriptorHeap; + ComPtr mDescriptorHeap; }; - + class ShaderVisibleDescriptorAllocator { @@ -99,7 +102,25 @@ class ShaderVisibleDescriptorAllocator { // The descriptor count is the current size of the heap in number of descriptors. @@ -925,7 +925,7 @@ index cf09f9d50..f22684f27 100644 }; + } // namespace dawn::native::d3d12 - + #endif // SRC_DAWN_NATIVE_D3D12_SHADERVISIBLEDESCRIPTORALLOCATORD3D12_H_ diff --git a/src/dawn/native/d3d12/StagingBufferD3D12.cpp b/src/dawn/native/d3d12/StagingBufferD3D12.cpp index edaa2cff4..7753c25cf 100644 @@ -934,19 +934,19 @@ index edaa2cff4..7753c25cf 100644 @@ -41,35 +41,21 @@ MaybeError StagingBuffer::Initialize() { DAWN_TRY_ASSIGN(mUploadHeap, mDevice->AllocateMemory(D3D12_HEAP_TYPE_UPLOAD, resourceDescriptor, D3D12_RESOURCE_STATE_GENERIC_READ)); - + - // The mapped buffer can be accessed at any time, so it must be locked to ensure it is never - // evicted. This buffer should already have been made resident when it was created. - DAWN_TRY( - mDevice->GetResidencyManager()->LockAllocation(ToBackend(mUploadHeap.GetResourceHeap()))); - SetDebugName(mDevice, GetResource(), "Dawn_StagingBuffer"); - + - return CheckHRESULT(GetResource()->Map(0, nullptr, &mMappedPointer), "ID3D12Resource::Map"); + return CheckHRESULT(mUploadHeap->Map(0, nullptr, &mMappedPointer), + "Unable to map staging buffer"); } - + StagingBuffer::~StagingBuffer() { - // Always check if the allocation is valid before Unmap. - // The resource would not exist had it failed to allocate. @@ -962,10 +962,10 @@ index edaa2cff4..7753c25cf 100644 - GetResource()->Unmap(0, nullptr); + mUploadHeap->Unmap(0, nullptr); mMappedPointer = nullptr; - + mDevice->DeallocateMemory(mUploadHeap); } - + ID3D12Resource* StagingBuffer::GetResource() const { - return mUploadHeap.GetD3D12Resource(); + return mUploadHeap->GetResource(); @@ -978,21 +978,21 @@ index dcbe7dfed..57bcbcea9 100644 @@ -19,6 +19,8 @@ #include "dawn/native/d3d12/ResourceHeapAllocationD3D12.h" #include "dawn/native/d3d12/d3d12_platform.h" - + +#include + namespace dawn::native::d3d12 { - + class Device; @@ -34,7 +36,7 @@ class StagingBuffer : public StagingBufferBase { - + private: Device* mDevice; - ResourceHeapAllocation mUploadHeap; + ComPtr mUploadHeap; }; } // namespace dawn::native::d3d12 - + diff --git a/src/dawn/native/d3d12/TextureD3D12.cpp b/src/dawn/native/d3d12/TextureD3D12.cpp index 41bc0a099..a8d7caf5f 100644 --- a/src/dawn/native/d3d12/TextureD3D12.cpp @@ -1000,7 +1000,7 @@ index 41bc0a099..a8d7caf5f 100644 @@ -553,12 +553,8 @@ MaybeError Texture::InitializeAsExternalTexture(ComPtr d3d12Text D3D12_RESOURCE_DESC desc = d3d12Texture->GetDesc(); mD3D12ResourceFlags = desc.Flags; - + - AllocationInfo info; - info.mMethod = AllocationMethod::kExternal; - // When creating the ResourceHeapAllocation, the resource heap is set to nullptr because the @@ -1009,12 +1009,12 @@ index 41bc0a099..a8d7caf5f 100644 - mResourceAllocation = {info, 0, std::move(d3d12Texture), nullptr}; + DAWN_TRY_ASSIGN(mResourceAllocation, + ToBackend(GetDevice())->CreateExternalAllocation(d3d12Texture)); - + mD3D12Fence = std::move(d3d12Fence); mD3D11on12Resource = std::move(d3d11on12Resource); @@ -632,13 +628,8 @@ MaybeError Texture::InitializeAsInternalTexture() { } - + MaybeError Texture::InitializeAsSwapChainTexture(ComPtr d3d12Texture) { - AllocationInfo info; - info.mMethod = AllocationMethod::kExternal; @@ -1026,7 +1026,7 @@ index 41bc0a099..a8d7caf5f 100644 + DAWN_TRY_ASSIGN(mResourceAllocation, + ToBackend(GetDevice())->CreateExternalAllocation(d3d12Texture)); SetLabelHelper("Dawn_SwapChainTexture"); - + return {}; @@ -668,11 +659,11 @@ void Texture::DestroyImpl() { if (mSwapChainTexture) { @@ -1036,15 +1036,15 @@ index 41bc0a099..a8d7caf5f 100644 + d3dSharingContract->Present(mResourceAllocation->GetResource(), 0, 0); } } - + - device->DeallocateMemory(mResourceAllocation); + device->DeallocateMemory(std::move(mResourceAllocation)); - + // Now that we've deallocated the memory, the texture is no longer a swap chain texture. // We can set mSwapChainTexture to false to avoid passing a nullptr to @@ -703,7 +694,10 @@ DXGI_FORMAT Texture::GetD3D12Format() const { } - + ID3D12Resource* Texture::GetD3D12Resource() const { - return mResourceAllocation.GetD3D12Resource(); + if (mResourceAllocation == nullptr) { @@ -1052,7 +1052,7 @@ index 41bc0a099..a8d7caf5f 100644 + } + return mResourceAllocation->GetResource(); } - + D3D12_RESOURCE_FLAGS Texture::GetD3D12ResourceFlags() const { @@ -774,10 +768,9 @@ void Texture::TrackAllUsageAndTransitionNow(CommandRecordingContext* commandCont void Texture::TrackUsageAndTransitionNow(CommandRecordingContext* commandContext, @@ -1065,7 +1065,7 @@ index 41bc0a099..a8d7caf5f 100644 - commandContext->TrackHeapUsage(heap, GetDevice()->GetPendingCommandSerial()); + commandContext->GetResidencyList()->Add(mResourceAllocation->GetMemory()); } - + std::vector barriers; @@ -905,7 +898,7 @@ void Texture::HandleTransitionSpecialCases(CommandRecordingContext* commandConte // Externally allocated textures can be written from other graphics queues. Hence, they must be @@ -1088,17 +1088,17 @@ index 41bc0a099..a8d7caf5f 100644 + if (GetTextureState() != TextureState::OwnedExternal) { + commandContext->GetResidencyList()->Add(mResourceAllocation->GetMemory()); } - + HandleTransitionSpecialCases(commandContext); @@ -1184,8 +1176,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, } - + void Texture::SetLabelHelper(const char* prefix) { - SetDebugName(ToBackend(GetDevice()), mResourceAllocation.GetD3D12Resource(), prefix, - GetLabel()); + SetDebugName(ToBackend(GetDevice()), GetD3D12Resource(), prefix, GetLabel()); } - + void Texture::SetLabelImpl() { diff --git a/src/dawn/native/d3d12/TextureD3D12.h b/src/dawn/native/d3d12/TextureD3D12.h index 3e49bc232..bfdbddcd3 100644 @@ -1107,19 +1107,19 @@ index 3e49bc232..bfdbddcd3 100644 @@ -26,6 +26,8 @@ #include "dawn/native/d3d12/ResourceHeapAllocationD3D12.h" #include "dawn/native/d3d12/d3d12_platform.h" - + +#include + namespace dawn::native::d3d12 { - + class CommandRecordingContext; @@ -139,7 +141,7 @@ class Texture final : public TextureBase { void HandleTransitionSpecialCases(CommandRecordingContext* commandContext); - + D3D12_RESOURCE_FLAGS mD3D12ResourceFlags; - ResourceHeapAllocation mResourceAllocation; + ComPtr mResourceAllocation; - + // TODO(dawn:1460): Encapsulate imported image fields e.g. std::unique_ptr. ComPtr mD3D12Fence; diff --git a/src/dawn/native/d3d12/UtilsD3D12.cpp b/src/dawn/native/d3d12/UtilsD3D12.cpp @@ -1129,7 +1129,7 @@ index e706d8f65..513cf1830 100644 @@ -370,6 +370,17 @@ void RecordBufferTextureCopy(BufferTextureCopyDirection direction, bufferCopy.rowsPerImage, textureCopy, copySize); } - + +bool IsClearValueOptimizable(const D3D12_RESOURCE_DESC& resourceDescriptor) { + // Optimized clear color cannot be set on buffers, non-render-target/depth-stencil + // textures, or typeless resources @@ -1151,11 +1151,11 @@ index dcbe782cb..7222b7d43 100644 @@ -66,6 +66,8 @@ void RecordBufferTextureCopy(BufferTextureCopyDirection direction, const TextureCopy& textureCopy, const Extent3D& copySize); - + +bool IsClearValueOptimizable(const D3D12_RESOURCE_DESC& resourceDescriptor); + void SetDebugName(Device* device, ID3D12Object* object, const char* prefix, std::string label = ""); - + uint64_t MakeDXCVersion(uint64_t majorVersion, uint64_t minorVersion); diff --git a/src/dawn/tests/white_box/D3D12ResidencyTests.cpp b/src/dawn/tests/white_box/D3D12ResidencyTests.cpp index 6298d82f4..912bdb608 100644 @@ -1164,7 +1164,7 @@ index 6298d82f4..912bdb608 100644 @@ -40,11 +40,6 @@ class D3D12ResidencyTestBase : public DawnTest { DawnTest::SetUp(); DAWN_TEST_UNSUPPORTED_IF(UsesWire()); - + - // Restrict Dawn's budget to create an artificial budget. - dawn::native::d3d12::Device* d3dDevice = - dawn::native::d3d12::ToBackend(dawn::native::FromAPI((device.Get()))); @@ -1190,7 +1190,7 @@ index 6298d82f4..912bdb608 100644 - CheckAllocationMethod(bufferSet1[i], dawn::native::AllocationMethod::kSubAllocated)); + EXPECT_TRUE(CheckAllocationMethod(bufferSet1[i], gpgmm::AllocationMethod::kSubAllocated)); } - + // Create enough directly-allocated buffers to use the entire budget. @@ -166,7 +160,6 @@ TEST_P(D3D12ResourceResidencyTests, OvercommitLargeResources) { // allocated internally. @@ -1198,12 +1198,12 @@ index 6298d82f4..912bdb608 100644 EXPECT_TRUE(CheckIfBufferIsResident(bufferSet1[i])); - EXPECT_TRUE(CheckAllocationMethod(bufferSet1[i], dawn::native::AllocationMethod::kDirect)); } - + // Create enough directly-allocated buffers to use the entire budget. @@ -420,6 +413,8 @@ TEST_P(D3D12DescriptorResidencyTests, SwitchedViewHeapResidency) { EXPECT_FALSE(allocator->IsLastShaderVisibleHeapInLRUForTesting()); } - + -DAWN_INSTANTIATE_TEST(D3D12ResourceResidencyTests, D3D12Backend()); +DAWN_INSTANTIATE_TEST(D3D12ResourceResidencyTests, + D3D12Backend({"use_d3d12_small_residency_budget"})); diff --git a/README.md b/README.md index 01ec73fff..7588d9ed0 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,11 @@ First create an allocator then create allocations from it: ```cpp #include -// Required gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {}; -allocatorDesc.Device = Device; -allocatorDesc.Adapter = Adapter; ComPtr residency; // Optional ComPtr allocator; -gpgmm::d3d12::CreateResourceAllocator(desc, &allocator, &residency); +gpgmm::d3d12::CreateResourceAllocator(desc, device, adapter, &allocator, &residency); ``` ```cpp diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index 05d383f49..c3633a45a 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -337,19 +337,6 @@ namespace gpgmm::d3d12 { Specify parameters when creating a residency manager. */ struct RESIDENCY_DESC { - /** \brief Specifies the device used by this residency manager. - Required parameter. Use CreateDevice get the device. - */ - ID3D12Device* Device; - - /** \brief Specifies the adapter used by this residency manager. - - Requires DXGI 1.4 due to IDXGIAdapter3::QueryVideoMemoryInfo. - - Required parameter. Use EnumAdapters to get the adapter. - */ - IDXGIAdapter3* Adapter; - /** \brief Specifies residency options. Optional parameter. By default, no flags are specified or RESIDENCY_FLAG_NONE. @@ -536,12 +523,18 @@ namespace gpgmm::d3d12 { @param descriptor A reference to RESIDENCY_DESC structure that describes the residency manager. + @param pDevice device used by this allocator. Required parameter. Use CreateDevice get the + device. + @param pAdapter DXGI adapter used to create the device. Requires DXGI 1.4 due to + IDXGIAdapter3::QueryVideoMemoryInfo. Use EnumAdapters to get the adapter. @param[out] ppResidencyManagerOut Pointer to a memory block that receives a pointer to the residency manager. Pass NULL to test if residency Manager creation would succeed, but not actually create the residency Manager. If NULL is passed and residency manager creating would succeed, S_FALSE is returned. */ GPGMM_EXPORT HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut); /** \struct RESOURCE_ALLOCATION_INFO @@ -784,22 +777,6 @@ namespace gpgmm::d3d12 { Specify parameters for creating allocators. */ struct ALLOCATOR_DESC { - /** \brief Specifies the device used by this allocator. - - Required parameter. Use CreateDevice get the device. - */ - ID3D12Device* Device; - - /** \brief Specifies the adapter used by this allocator. - - The adapter is used to detect for additional device capabilities (by GPU vendor). - If the adapter is left unspecified, the capabiltities will not be detected and disabled by - CheckFeatureSupport. - - Optional parameter. Use EnumAdapters to get the adapter. - */ - IDXGIAdapter* Adapter; - /** \brief Specifies allocator options. For example, whether the allocator can reuse memory, or resources should be resident upon @@ -1220,6 +1197,10 @@ namespace gpgmm::d3d12 { @param allocatorDescriptor A reference to ALLOCATOR_DESC structure that describes the allocator. + @param pDevice device used by this allocator. Required parameter. Use CreateDevice get the + device. + @param pAdapter DXGI adapter used to create the device. Used to detect for additional device + capabilities (by GPU vendor). Optional parameter. Use EnumAdapters to get the adapter. @param[out] ppResourceAllocatorOut Pointer to a memory block that receives a pointer to the resource allocator. Pass NULL to test if allocator creation would succeed, but not actually create the allocator. @@ -1228,6 +1209,8 @@ namespace gpgmm::d3d12 { residency. */ GPGMM_EXPORT HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut); @@ -1235,6 +1218,10 @@ namespace gpgmm::d3d12 { @param allocatorDescriptor A reference to ALLOCATOR_DESC structure that describes the allocator. + @param pDevice device used by this allocator. Required parameter. Use CreateDevice get the + device. + @param pAdapter DXGI adapter used to create the device. Used to detect for additional device + capabilities (by GPU vendor). Optional parameter. Use EnumAdapters to get the adapter. @param pResidencyManager Pointer to a memory block that receives a pointer to the residency manager. @param[out] ppResourceAllocatorOut Pointer to a memory block that receives a pointer to the @@ -1242,6 +1229,8 @@ namespace gpgmm::d3d12 { create the allocator. */ GPGMM_EXPORT HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, IResourceAllocator** ppResourceAllocatorOut); diff --git a/src/fuzzers/D3D12Fuzzer.cpp b/src/fuzzers/D3D12Fuzzer.cpp index d3f0939af..c8ea4c581 100644 --- a/src/fuzzers/D3D12Fuzzer.cpp +++ b/src/fuzzers/D3D12Fuzzer.cpp @@ -30,10 +30,8 @@ HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* pAllocatorDesc return E_FAIL; } - allocatorDescOut.Device = *ppDeviceOut; - // Populate the adapter - LUID adapterLUID = allocatorDescOut.Device->GetAdapterLuid(); + LUID adapterLUID = (*ppDeviceOut)->GetAdapterLuid(); ComPtr dxgiFactory; if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)))) { return E_FAIL; @@ -48,8 +46,6 @@ HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* pAllocatorDesc return E_FAIL; } - allocatorDescOut.Adapter = *ppAdapterOut; - // Configure options allocatorDescOut.MinLogLevel = D3D12_MESSAGE_SEVERITY_MESSAGE; diff --git a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp index fe9f3e8d7..1a9e7c245 100644 --- a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp +++ b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp @@ -57,30 +57,28 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { allocatorDesc.Flags |= gpgmm::d3d12::ALLOCATOR_FLAG_ALWAYS_IN_BUDGET; - gpgmm::d3d12::RESIDENCY_DESC residencyDesc = {}; - ComPtr adapter3; - if (FAILED(allocatorDesc.Adapter->QueryInterface(IID_PPV_ARGS(&adapter3)))) { + if (FAILED(gAdapter->QueryInterface(IID_PPV_ARGS(&adapter3)))) { return 0; } - residencyDesc.Adapter = adapter3.Get(); - residencyDesc.Device = allocatorDesc.Device; + gpgmm::d3d12::RESIDENCY_DESC residencyDesc = {}; residencyDesc.MinLogLevel = D3D12_MESSAGE_SEVERITY_MESSAGE; // Create ResidencyManager - if (FAILED(gpgmm::d3d12::CreateResidencyManager(residencyDesc, &gResidencyManager))) { + if (FAILED(gpgmm::d3d12::CreateResidencyManager(residencyDesc, gDevice.Get(), adapter3.Get(), + &gResidencyManager))) { return 0; } - if (FAILED(gpgmm::d3d12::CreateResourceAllocator(allocatorDesc, gResidencyManager.Get(), + if (FAILED(gpgmm::d3d12::CreateResourceAllocator(allocatorDesc, gDevice.Get(), gAdapter.Get(), + gResidencyManager.Get(), &gResourceAllocator))) { return 0; } D3D12_FEATURE_DATA_ARCHITECTURE arch = {}; - if (FAILED(residencyDesc.Device->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &arch, - sizeof(arch)))) { + if (FAILED(gDevice->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &arch, sizeof(arch)))) { return 0; } @@ -88,7 +86,7 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; D3D12_HEAP_PROPERTIES heapProperties = - residencyDesc.Device->GetCustomHeapProperties(0, allocationDesc.HeapType); + gDevice->GetCustomHeapProperties(0, allocationDesc.HeapType); const DXGI_MEMORY_SEGMENT_GROUP bufferMemorySegment = gpgmm::d3d12::GetMemorySegmentGroup(heapProperties.MemoryPoolPreference, arch.UMA); diff --git a/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp b/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp index 0cecf3ea5..0feef6392 100644 --- a/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp +++ b/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp @@ -33,8 +33,8 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { return 0; } - if (FAILED( - gpgmm::d3d12::CreateResourceAllocator(allocatorDesc, &gResourceAllocator, nullptr))) { + if (FAILED(gpgmm::d3d12::CreateResourceAllocator(allocatorDesc, gDevice.Get(), gAdapter.Get(), + &gResourceAllocator, nullptr))) { return 0; } diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index a52d41a0f..e365c7343 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -161,20 +161,25 @@ namespace gpgmm::d3d12 { }; HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut) { - return ResidencyManager::CreateResidencyManager(descriptor, ppResidencyManagerOut); + return ResidencyManager::CreateResidencyManager(descriptor, pDevice, pAdapter, + ppResidencyManagerOut); } // static HRESULT ResidencyManager::CreateResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut) { - ReturnIfNullptr(descriptor.Adapter); - ReturnIfNullptr(descriptor.Device); + ReturnIfNullptr(pAdapter); + ReturnIfNullptr(pDevice); std::unique_ptr caps; { Caps* ptr = nullptr; - ReturnIfFailed(Caps::CreateCaps(descriptor.Device, descriptor.Adapter, &ptr)); + ReturnIfFailed(Caps::CreateCaps(pDevice, pAdapter, &ptr)); caps.reset(ptr); } @@ -200,8 +205,8 @@ namespace gpgmm::d3d12 { SetLogLevel(GetMessageSeverity(descriptor.MinLogLevel)); - std::unique_ptr residencyManager = - std::unique_ptr(new ResidencyManager(descriptor, std::move(caps))); + std::unique_ptr residencyManager = std::unique_ptr( + new ResidencyManager(descriptor, pDevice, pAdapter, std::move(caps))); // Require automatic video memory budget updates. if (!(descriptor.Flags & RESIDENCY_FLAG_NEVER_UPDATE_BUDGET_ON_WORKER_THREAD)) { @@ -264,9 +269,12 @@ namespace gpgmm::d3d12 { return S_OK; } - ResidencyManager::ResidencyManager(const RESIDENCY_DESC& descriptor, std::unique_ptr caps) - : mDevice(descriptor.Device), - mAdapter(descriptor.Adapter), + ResidencyManager::ResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter, + std::unique_ptr caps) + : mDevice(pDevice), + mAdapter(pAdapter), mMaxPctOfVideoMemoryToBudget(descriptor.MaxPctOfVideoMemoryToBudget == 0 ? kDefaultMaxPctOfVideoMemoryToBudget : descriptor.MaxPctOfVideoMemoryToBudget), diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.h b/src/gpgmm/d3d12/ResidencyManagerD3D12.h index 4e39d0e6d..48de1457e 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.h +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.h @@ -43,6 +43,8 @@ namespace gpgmm::d3d12 { class ResidencyManager final : public DebugObject, public IResidencyManager, public ObjectBase { public: static HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut); ~ResidencyManager() override; @@ -72,7 +74,10 @@ namespace gpgmm::d3d12 { friend ResourceAllocator; friend ResourceHeapAllocator; - ResidencyManager(const RESIDENCY_DESC& descriptor, std::unique_ptr caps); + ResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter, + std::unique_ptr caps); HRESULT EnsureInBudget(uint64_t bytesToEvict, const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup); diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 134e956e2..1b06b9baf 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -405,35 +405,39 @@ namespace gpgmm::d3d12 { } // namespace HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut = nullptr) { return ResourceAllocator::CreateResourceAllocator( - allocatorDescriptor, ppResourceAllocatorOut, ppResidencyManagerOut); + allocatorDescriptor, pDevice, pAdapter, ppResourceAllocatorOut, ppResidencyManagerOut); } HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, IResourceAllocator** ppResourceAllocatorOut) { - return ResourceAllocator::CreateResourceAllocator(allocatorDescriptor, pResidencyManager, - ppResourceAllocatorOut); + return ResourceAllocator::CreateResourceAllocator( + allocatorDescriptor, pDevice, pAdapter, pResidencyManager, ppResourceAllocatorOut); } // static HRESULT ResourceAllocator::CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut) { - ReturnIfNullptr(allocatorDescriptor.Device); + ReturnIfNullptr(pDevice); ComPtr residencyManager; if (ppResidencyManagerOut != nullptr) { - RESIDENCY_DESC residencyDesc = {}; - residencyDesc.Device = allocatorDescriptor.Device; - - if (allocatorDescriptor.Adapter != nullptr) { - ReturnIfFailed(allocatorDescriptor.Adapter->QueryInterface( - IID_PPV_ARGS(&residencyDesc.Adapter))); + ComPtr adapter3; + if (pAdapter != nullptr) { + ReturnIfFailed(pAdapter->QueryInterface(IID_PPV_ARGS(&adapter3))); } + RESIDENCY_DESC residencyDesc = {}; residencyDesc.MinLogLevel = allocatorDescriptor.MinLogLevel; residencyDesc.RecordOptions = allocatorDescriptor.RecordOptions; @@ -441,13 +445,13 @@ namespace gpgmm::d3d12 { residencyDesc.Flags |= RESIDENCY_FLAG_ALWAYS_IN_BUDGET; } - ReturnIfFailed( - ResidencyManager::CreateResidencyManager(residencyDesc, &residencyManager)); + ReturnIfFailed(ResidencyManager::CreateResidencyManager( + residencyDesc, pDevice, adapter3.Get(), &residencyManager)); } ComPtr resourceAllocator; - ReturnIfFailed(CreateResourceAllocator(allocatorDescriptor, residencyManager.Get(), - &resourceAllocator)); + ReturnIfFailed(CreateResourceAllocator(allocatorDescriptor, pDevice, pAdapter, + residencyManager.Get(), &resourceAllocator)); if (ppResourceAllocatorOut != nullptr) { *ppResourceAllocatorOut = resourceAllocator.Detach(); @@ -463,15 +467,16 @@ namespace gpgmm::d3d12 { // static HRESULT ResourceAllocator::CreateResourceAllocator( const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, IResourceAllocator** ppResourceAllocatorOut) { - ReturnIfNullptr(allocatorDescriptor.Device); + ReturnIfNullptr(pDevice); std::unique_ptr caps; { Caps* ptr = nullptr; - ReturnIfFailed( - Caps::CreateCaps(allocatorDescriptor.Device, allocatorDescriptor.Adapter, &ptr)); + ReturnIfFailed(Caps::CreateCaps(pDevice, pAdapter, &ptr)); caps.reset(ptr); } @@ -585,7 +590,8 @@ namespace gpgmm::d3d12 { std::unique_ptr resourceAllocator = std::unique_ptr(new ResourceAllocator( - newDescriptor, static_cast(pResidencyManager), std::move(caps))); + newDescriptor, pDevice, static_cast(pResidencyManager), + std::move(caps))); GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(resourceAllocator.get(), newDescriptor); @@ -597,9 +603,10 @@ namespace gpgmm::d3d12 { } ResourceAllocator::ResourceAllocator(const ALLOCATOR_DESC& descriptor, + ID3D12Device* pDevice, ResidencyManager* pResidencyManager, std::unique_ptr caps) - : mDevice(std::move(descriptor.Device)), + : mDevice(pDevice), mResidencyManager(pResidencyManager), mCaps(std::move(caps)), mResourceHeapTier(descriptor.ResourceHeapTier), diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index 8330ddeb3..9b1c767eb 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -40,10 +40,14 @@ namespace gpgmm::d3d12 { public MemoryAllocator { public: static HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut); static HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, IResourceAllocator** ppResourceAllocatorOut); @@ -84,6 +88,7 @@ namespace gpgmm::d3d12 { IResourceAllocation** ppResourceAllocationOut); ResourceAllocator(const ALLOCATOR_DESC& descriptor, + ID3D12Device* pDevice, ResidencyManager* pResidencyManager, std::unique_ptr caps); diff --git a/src/mvi/gpgmm_d3d12.cpp b/src/mvi/gpgmm_d3d12.cpp index 21a32251f..da6604c2a 100644 --- a/src/mvi/gpgmm_d3d12.cpp +++ b/src/mvi/gpgmm_d3d12.cpp @@ -150,15 +150,20 @@ namespace gpgmm::d3d12 { // ResidencyManager HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut) { - return ResidencyManager::CreateResidencyManager(descriptor, ppResidencyManagerOut); + return ResidencyManager::CreateResidencyManager(descriptor, pDevice, pAdapter, + ppResidencyManagerOut); } // static HRESULT ResidencyManager::CreateResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut) { if (ppResidencyManagerOut != nullptr) { - *ppResidencyManagerOut = new ResidencyManager(descriptor); + *ppResidencyManagerOut = new ResidencyManager(descriptor, pDevice, pAdapter); } return S_OK; @@ -203,8 +208,10 @@ namespace gpgmm::d3d12 { return E_NOTIMPL; } - ResidencyManager::ResidencyManager(const RESIDENCY_DESC& descriptor) - : mDevice(std::move(descriptor.Device)), mAdapter(std::move(descriptor.Adapter)) { + ResidencyManager::ResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter) + : mDevice(pDevice), mAdapter(pAdapter) { } HRESULT STDMETHODCALLTYPE ResidencyManager::QueryInterface(REFIID riid, void** ppvObject) { @@ -292,37 +299,40 @@ namespace gpgmm::d3d12 { // ResourceAllocator HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut) { return ResourceAllocator::CreateResourceAllocator( - allocatorDescriptor, ppResourceAllocatorOut, ppResidencyManagerOut); + allocatorDescriptor, pDevice, pAdapter, ppResourceAllocatorOut, ppResidencyManagerOut); } // static HRESULT ResourceAllocator::CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut) { - if (allocatorDescriptor.Device == nullptr) { + if (pDevice == nullptr) { return E_INVALIDARG; } Microsoft::WRL::ComPtr residencyManager; if (ppResidencyManagerOut != nullptr) { RESIDENCY_DESC residencyDesc = {}; - residencyDesc.Device = allocatorDescriptor.Device; - if (allocatorDescriptor.Adapter != nullptr) { - ReturnIfFailed(allocatorDescriptor.Adapter->QueryInterface( - IID_PPV_ARGS(&residencyDesc.Adapter))); + Microsoft::WRL::ComPtr adapter3; + if (pAdapter != nullptr) { + ReturnIfFailed(pAdapter->QueryInterface(IID_PPV_ARGS(&adapter3))); } - ReturnIfFailed( - ResidencyManager::CreateResidencyManager(residencyDesc, &residencyManager)); + ReturnIfFailed(ResidencyManager::CreateResidencyManager( + residencyDesc, pDevice, adapter3.Get(), &residencyManager)); } Microsoft::WRL::ComPtr resourceAllocator; - ReturnIfFailed(CreateResourceAllocator(allocatorDescriptor, residencyManager.Get(), - &resourceAllocator)); + ReturnIfFailed(CreateResourceAllocator(allocatorDescriptor, pDevice, pAdapter, + residencyManager.Get(), &resourceAllocator)); if (ppResourceAllocatorOut != nullptr) { *ppResourceAllocatorOut = resourceAllocator.Detach(); @@ -338,11 +348,13 @@ namespace gpgmm::d3d12 { // static HRESULT ResourceAllocator::CreateResourceAllocator( const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, IResourceAllocator** ppResourceAllocatorOut) { if (ppResourceAllocatorOut != nullptr) { *ppResourceAllocatorOut = new ResourceAllocator( - allocatorDescriptor, static_cast(pResidencyManager)); + allocatorDescriptor, pDevice, static_cast(pResidencyManager)); } return S_OK; @@ -403,8 +415,9 @@ namespace gpgmm::d3d12 { } ResourceAllocator::ResourceAllocator(const ALLOCATOR_DESC& descriptor, + ID3D12Device* pDevice, ResidencyManager* pResidencyManager) - : mDevice(std::move(descriptor.Device)), mResidencyManager(pResidencyManager) { + : mDevice(pDevice), mResidencyManager(pResidencyManager) { } void ResourceAllocator::DeallocateMemory(std::unique_ptr allocation) { diff --git a/src/mvi/gpgmm_d3d12.h b/src/mvi/gpgmm_d3d12.h index 37d3693c8..fd5ad77d3 100644 --- a/src/mvi/gpgmm_d3d12.h +++ b/src/mvi/gpgmm_d3d12.h @@ -106,6 +106,8 @@ namespace gpgmm::d3d12 { class ResidencyManager final : public Unknown, public IResidencyManager { public: static HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut); ~ResidencyManager() override; @@ -135,7 +137,9 @@ namespace gpgmm::d3d12 { HRESULT SetDebugName(LPCWSTR Name) override; private: - ResidencyManager(const RESIDENCY_DESC& descriptor); + ResidencyManager(const RESIDENCY_DESC& descriptor, + ID3D12Device* pDevice, + IDXGIAdapter3* pAdapter); Microsoft::WRL::ComPtr mDevice; Microsoft::WRL::ComPtr mAdapter; @@ -205,10 +209,14 @@ namespace gpgmm::d3d12 { public IResourceAllocator { public: static HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut); static HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, IResourceAllocator** ppResourceAllocatorOut); @@ -237,7 +245,9 @@ namespace gpgmm::d3d12 { HRESULT SetDebugName(LPCWSTR Name) override; private: - ResourceAllocator(const ALLOCATOR_DESC& descriptor, ResidencyManager* pResidencyManager); + ResourceAllocator(const ALLOCATOR_DESC& descriptor, + ID3D12Device* pDevice, + ResidencyManager* pResidencyManager); void DeallocateMemory(std::unique_ptr allocation) override; diff --git a/src/samples/D3D12Sample.cpp b/src/samples/D3D12Sample.cpp index ebbf20689..7fc6f8545 100644 --- a/src/samples/D3D12Sample.cpp +++ b/src/samples/D3D12Sample.cpp @@ -57,12 +57,11 @@ HRESULT Init() { } gpgmm::d3d12::ALLOCATOR_DESC desc = {}; - desc.Adapter = adapter3.Get(); - desc.Device = device.Get(); desc.ResourceHeapTier = options.ResourceHeapTier; Microsoft::WRL::ComPtr resourceAllocator; - hr = gpgmm::d3d12::CreateResourceAllocator(desc, &resourceAllocator, nullptr); + hr = gpgmm::d3d12::CreateResourceAllocator(desc, device.Get(), adapter3.Get(), + &resourceAllocator, nullptr); if (FAILED(hr)) { return hr; } diff --git a/src/tests/D3D12Test.cpp b/src/tests/D3D12Test.cpp index 8ec102ec4..4d4e12b5b 100644 --- a/src/tests/D3D12Test.cpp +++ b/src/tests/D3D12Test.cpp @@ -128,12 +128,7 @@ namespace gpgmm::d3d12 { ALLOCATOR_DESC D3D12TestBase::CreateBasicAllocatorDesc() const { ALLOCATOR_DESC desc = {}; - - // Required parameters. - desc.Adapter = mAdapter.Get(); - desc.Device = mDevice.Get(); desc.ResourceHeapTier = mCaps->GetMaxResourceHeapTierSupported(); - desc.MinLogLevel = GetMessageSeverity(GetLogLevel()); if (IsDumpEventsEnabled()) { @@ -148,10 +143,6 @@ namespace gpgmm::d3d12 { RESIDENCY_DESC D3D12TestBase::CreateBasicResidencyDesc() const { RESIDENCY_DESC desc = {}; - // Required - desc.Adapter = mAdapter.Get(); - desc.Device = mDevice.Get(); - desc.MinLogLevel = GetMessageSeverity(GetLogLevel()); if (IsDumpEventsEnabled()) { diff --git a/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp b/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp index b00081be1..2b9bfb469 100644 --- a/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp +++ b/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp @@ -398,8 +398,8 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith ConvertAndApplyToResidencyDesc(snapshot, newResidencyDesc); ComPtr residencyManager; - ASSERT_SUCCEEDED( - CreateResidencyManager(newResidencyDesc, &residencyManager)); + ASSERT_SUCCEEDED(CreateResidencyManager(newResidencyDesc, mDevice.Get(), + mAdapter.Get(), &residencyManager)); ASSERT_TRUE(playbackContext.CreatedResidencyManagersToID .insert({residencyManagerID, std::move(residencyManager)}) @@ -482,7 +482,8 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith ComPtr resourceAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator( - allocatorDescOfProfile, residencyManager.Get(), &resourceAllocator)); + allocatorDescOfProfile, mDevice.Get(), mAdapter.Get(), + residencyManager.Get(), &resourceAllocator)); ASSERT_TRUE(playbackContext.CreatedAllocatorsToID .insert({allocatorID, std::move(resourceAllocator)}) diff --git a/src/tests/end2end/D3D12ResidencyManagerTests.cpp b/src/tests/end2end/D3D12ResidencyManagerTests.cpp index 0836e9772..1a4fdea87 100644 --- a/src/tests/end2end/D3D12ResidencyManagerTests.cpp +++ b/src/tests/end2end/D3D12ResidencyManagerTests.cpp @@ -123,8 +123,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeapNotResident) { GPGMM_SKIP_TEST_IF(!mCaps->IsCreateHeapNotResidentSupported()); ComPtr residencyManager; - ASSERT_SUCCEEDED( - CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), &residencyManager)); + ASSERT_SUCCEEDED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), mDevice.Get(), + mAdapter.Get(), &residencyManager)); constexpr uint64_t kHeapSize = GPGMM_MB_TO_BYTES(10); @@ -151,8 +151,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeapNotResident) { TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) { ComPtr residencyManager; - ASSERT_SUCCEEDED( - CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), &residencyManager)); + ASSERT_SUCCEEDED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), mDevice.Get(), + mAdapter.Get(), &residencyManager)); constexpr uint64_t kHeapSize = GPGMM_MB_TO_BYTES(10); @@ -232,8 +232,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) { TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeap) { ComPtr residencyManager; - ASSERT_SUCCEEDED( - CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), &residencyManager)); + ASSERT_SUCCEEDED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), mDevice.Get(), + mAdapter.Get(), &residencyManager)); D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {}; heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; @@ -286,8 +286,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeap) { TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeapAlwaysResident) { ComPtr residencyManager; - ASSERT_SUCCEEDED( - CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), &residencyManager)); + ASSERT_SUCCEEDED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), mDevice.Get(), + mAdapter.Get(), &residencyManager)); D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {}; heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; @@ -313,8 +313,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeapAlwaysResident) { TEST_F(D3D12ResidencyManagerTests, CreateResidencyList) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; @@ -358,31 +358,29 @@ TEST_F(D3D12ResidencyManagerTests, CreateResidencyList) { TEST_F(D3D12ResidencyManagerTests, CreateResidencyManager) { // Create residency without adapter must always fail. { - RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); - residencyDesc.Adapter = nullptr; - - ASSERT_FAILED(CreateResidencyManager(residencyDesc, nullptr)); + ASSERT_FAILED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), + mDevice.Get(), nullptr, nullptr)); } // Create residency without device must always fail. { - RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); - residencyDesc.Device = nullptr; - - ASSERT_FAILED(CreateResidencyManager(residencyDesc, nullptr)); + ASSERT_FAILED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), nullptr, + mAdapter.Get(), nullptr)); } // Create residency alone. { ComPtr residencyManager; - ASSERT_SUCCEEDED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), nullptr)); + ASSERT_SUCCEEDED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), + mDevice.Get(), mAdapter.Get(), nullptr)); } // Create allocator with residency support, together. { ComPtr residencyManager; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, &residencyManager)); EXPECT_NE(resourceAllocator, nullptr); EXPECT_NE(residencyManager, nullptr); @@ -391,22 +389,22 @@ TEST_F(D3D12ResidencyManagerTests, CreateResidencyManager) { // Create allocator with residency, seperately, but no adapter should fail. { ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); - allocatorDesc.Adapter = nullptr; ComPtr residencyManager; ComPtr resourceAllocator; - ASSERT_FAILED( - CreateResourceAllocator(allocatorDesc, &resourceAllocator, &residencyManager)); + ASSERT_FAILED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), nullptr, + &resourceAllocator, &residencyManager)); } // Create allocator with residency, seperately. { ComPtr residencyManager; - ASSERT_SUCCEEDED( - CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), &residencyManager)); + ASSERT_SUCCEEDED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), + mDevice.Get(), mAdapter.Get(), &residencyManager)); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), residencyManager.Get(), + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), residencyManager.Get(), &resourceAllocator)); EXPECT_NE(resourceAllocator, nullptr); EXPECT_NE(residencyManager, nullptr); @@ -419,8 +417,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateResidencyManagerWithoutDeviceAddRef) { // Create a residency manager without adding a ref to the device. ComPtr residencyManager; - ASSERT_SUCCEEDED( - CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), &residencyManager)); + ASSERT_SUCCEEDED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), mDevice.Get(), + mAdapter.Get(), &residencyManager)); const uint32_t afterDeviceRefCount = GetRefCount(mDevice.Get()); @@ -434,17 +432,19 @@ TEST_F(D3D12ResidencyManagerTests, CreateResidencyManagerNoLeak) { { ComPtr residencyManager; ComPtr resourceAllocator; - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, &residencyManager); + CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), mAdapter.Get(), + &resourceAllocator, &residencyManager); } // Create allocator with residency, seperately. { ComPtr residencyManager; - CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), &residencyManager); + CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), mDevice.Get(), + mAdapter.Get(), &residencyManager); ComPtr resourceAllocator; - CreateResourceAllocator(CreateBasicAllocatorDesc(), residencyManager.Get(), - &resourceAllocator); + CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), mAdapter.Get(), + residencyManager.Get(), &resourceAllocator); } GPGMM_TEST_MEMORY_LEAK_END(); @@ -456,10 +456,12 @@ TEST_F(D3D12ResidencyManagerTests, OverBudget) { RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); ComPtr residencyManager; - ASSERT_SUCCEEDED(CreateResidencyManager(residencyDesc, &residencyManager)); + ASSERT_SUCCEEDED( + CreateResidencyManager(residencyDesc, mDevice.Get(), mAdapter.Get(), &residencyManager)); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), residencyManager.Get(), + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), residencyManager.Get(), &resourceAllocator)); constexpr uint64_t kBufferMemorySize = GPGMM_MB_TO_BYTES(1); @@ -514,10 +516,12 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetAsync) { residencyDesc.Flags ^= RESIDENCY_FLAG_NEVER_UPDATE_BUDGET_ON_WORKER_THREAD; ComPtr residencyManager; - ASSERT_SUCCEEDED(CreateResidencyManager(residencyDesc, &residencyManager)); + ASSERT_SUCCEEDED( + CreateResidencyManager(residencyDesc, mDevice.Get(), mAdapter.Get(), &residencyManager)); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), residencyManager.Get(), + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), residencyManager.Get(), &resourceAllocator)); constexpr uint64_t kBufferMemorySize = GPGMM_MB_TO_BYTES(1); @@ -558,13 +562,15 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetDisablesGrowth) { RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); ComPtr residencyManager; - ASSERT_SUCCEEDED(CreateResidencyManager(residencyDesc, &residencyManager)); + ASSERT_SUCCEEDED( + CreateResidencyManager(residencyDesc, mDevice.Get(), mAdapter.Get(), &residencyManager)); ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); allocatorDesc.MemoryGrowthFactor = 2; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), residencyManager.Get(), + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), residencyManager.Get(), &resourceAllocator)); std::vector> allocations = {}; @@ -603,10 +609,12 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetWithLockedHeaps) { RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); ComPtr residencyManager; - ASSERT_SUCCEEDED(CreateResidencyManager(residencyDesc, &residencyManager)); + ASSERT_SUCCEEDED( + CreateResidencyManager(residencyDesc, mDevice.Get(), mAdapter.Get(), &residencyManager)); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), residencyManager.Get(), + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), residencyManager.Get(), &resourceAllocator)); constexpr uint64_t kBufferMemorySize = GPGMM_MB_TO_BYTES(1); @@ -651,11 +659,12 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetWithLockedHeaps) { // gets paged-out. TEST_F(D3D12ResidencyManagerTests, OverBudgetExecuteCommandList) { ComPtr residencyManager; - ASSERT_SUCCEEDED( - CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), &residencyManager)); + ASSERT_SUCCEEDED(CreateResidencyManager(CreateBasicResidencyDesc(kDefaultBudget), mDevice.Get(), + mAdapter.Get(), &residencyManager)); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), residencyManager.Get(), + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), residencyManager.Get(), &resourceAllocator)); constexpr uint64_t kBufferMemorySize = GPGMM_MB_TO_BYTES(1); @@ -749,10 +758,12 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetImported) { RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); ComPtr residencyManager; - ASSERT_SUCCEEDED(CreateResidencyManager(residencyDesc, &residencyManager)); + ASSERT_SUCCEEDED( + CreateResidencyManager(residencyDesc, mDevice.Get(), mAdapter.Get(), &residencyManager)); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), residencyManager.Get(), + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), residencyManager.Get(), &resourceAllocator)); constexpr uint64_t kBufferMemorySize = GPGMM_MB_TO_BYTES(1); diff --git a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp index 0b8d8a747..5ab1c0765 100644 --- a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp +++ b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp @@ -82,8 +82,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocatorWithoutDeviceAddRef) // Create the resource allocator without adding a ref to the device. ComPtr resourceAllocator; - EXPECT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + EXPECT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); const uint32_t afterDeviceRefCount = GetRefCount(mDevice.Get()); @@ -94,28 +94,25 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocator) { // Creating an invalid allocator should always fail. { ComPtr resourceAllocator; - EXPECT_FAILED(CreateResourceAllocator({}, &resourceAllocator, nullptr)); + EXPECT_FAILED(CreateResourceAllocator({}, nullptr, nullptr, &resourceAllocator, nullptr)); EXPECT_EQ(resourceAllocator, nullptr); } // Creating an allocator without a device should always fail. { ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); - desc.Device = nullptr; ComPtr resourceAllocator; - EXPECT_FAILED(CreateResourceAllocator(desc, &resourceAllocator, nullptr)); + EXPECT_FAILED( + CreateResourceAllocator(desc, nullptr, mAdapter.Get(), &resourceAllocator, nullptr)); EXPECT_EQ(resourceAllocator, nullptr); } // Creating an allocator without the resource heap tier specified should always succeed. { - ALLOCATOR_DESC desc = {}; - desc.Device = mDevice.Get(); - desc.Adapter = mAdapter.Get(); - ComPtr resourceAllocator; - EXPECT_SUCCEEDED(CreateResourceAllocator(desc, &resourceAllocator, nullptr)); + EXPECT_SUCCEEDED(CreateResourceAllocator({}, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); EXPECT_NE(resourceAllocator, nullptr); } @@ -127,26 +124,25 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocator) { static_cast(D3D12_RESOURCE_HEAP_TIER_2 + 1); ComPtr resourceAllocator; - EXPECT_FAILED(CreateResourceAllocator(desc, &resourceAllocator, nullptr)); + EXPECT_FAILED(CreateResourceAllocator(desc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); EXPECT_EQ(resourceAllocator, nullptr); } // Creating an allocator without the adapter should always succeed. // Should output warning messages that some capabilities were not detected. { - ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); - desc.Adapter = nullptr; - ComPtr resourceAllocator; - EXPECT_SUCCEEDED(CreateResourceAllocator(desc, &resourceAllocator, nullptr)); + EXPECT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), nullptr, + &resourceAllocator, nullptr)); EXPECT_NE(resourceAllocator, nullptr); } // Creating a new allocator using the defaults should always succeed. { ComPtr resourceAllocator; - EXPECT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + EXPECT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); EXPECT_NE(resourceAllocator, nullptr); } @@ -158,7 +154,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocator) { desc.MaxResourceHeapSize = kBufferOf4MBAllocationSize / 2; ComPtr resourceAllocator; - EXPECT_FAILED(CreateResourceAllocator(desc, &resourceAllocator, nullptr)); + EXPECT_FAILED(CreateResourceAllocator(desc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); EXPECT_EQ(resourceAllocator, nullptr); } } @@ -167,7 +164,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocatorNoLeak) { GPGMM_TEST_MEMORY_LEAK_START(); { ComPtr resourceAllocator; - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr); + CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr); } GPGMM_TEST_MEMORY_LEAK_END(); } @@ -176,7 +174,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNoLeak) { GPGMM_TEST_MEMORY_LEAK_START(); { ComPtr resourceAllocator; - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr); + CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr); for (auto& bufferAllocationExpectation : GenerateBufferAllocations()) { ComPtr allocation; resourceAllocator->CreateResource( @@ -200,7 +199,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSameHeap) { GPGMM_SKIP_TEST_IF(allocatorDesc.ResourceHeapTier < D3D12_RESOURCE_HEAP_TIER_2); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); // Create memory for buffer in Heap A. { @@ -232,7 +232,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSeperateHeap) { allocatorDesc.PreferredResourceHeapSize = kBufferOf4MBAllocationSize; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); // Create memory for buffer in Heap A. { @@ -264,8 +265,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSeperateHeap) { // Exceeding the max resource heap size should always fail. TEST_F(D3D12ResourceAllocatorTests, CreateBufferOversized) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); constexpr uint64_t kOversizedBuffer = GPGMM_GB_TO_BYTES(32); @@ -292,7 +293,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_BUDDY_SYSTEM; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); for (auto& alloc : GenerateBufferAllocations()) { @@ -311,7 +313,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { newAllocatorDesc.PoolAlgorithm = ALLOCATOR_ALGORITHM_FIXED_POOL; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); for (auto& alloc : GenerateBufferAllocations()) { @@ -330,7 +333,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { newAllocatorDesc.PoolAlgorithm = ALLOCATOR_ALGORITHM_SEGMENTED_POOL; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); for (auto& alloc : GenerateBufferAllocations()) { @@ -348,7 +352,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_SLAB; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); for (auto& alloc : GenerateBufferAllocations()) { @@ -367,7 +372,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { newAllocatorDesc.PoolAlgorithm = ALLOCATOR_ALGORITHM_FIXED_POOL; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); for (auto& alloc : GenerateBufferAllocations()) { @@ -386,7 +392,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { newAllocatorDesc.PoolAlgorithm = ALLOCATOR_ALGORITHM_SEGMENTED_POOL; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); for (auto& alloc : GenerateBufferAllocations()) { @@ -404,7 +411,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { newAllocatorDesc.Flags |= ALLOCATOR_FLAG_ALWAYS_COMMITTED; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); for (auto& alloc : GenerateBufferAllocations()) { @@ -422,7 +430,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_DEDICATED; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); for (auto& alloc : GenerateBufferAllocations()) { @@ -445,7 +454,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPreferredHeapSize) { newAllocatorDesc.PreferredResourceHeapSize = GPGMM_MB_TO_BYTES(12); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ComPtr allocation; @@ -464,7 +474,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPreferredHeapSize) { newAllocatorDesc.PreferredResourceHeapSize = GPGMM_MB_TO_BYTES(12); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ComPtr allocation; @@ -483,7 +494,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPreferredHeapSize) { newAllocatorDesc.PreferredResourceHeapSize = GPGMM_MB_TO_BYTES(12); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ComPtr allocation; @@ -499,8 +511,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPreferredHeapSize) { TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyDeallocateAtEnd) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC allocationDesc = {}; @@ -525,8 +537,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyDeallocateAtEnd) { TEST_F(D3D12ResourceAllocatorTests, CreateBuffer) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); // Creating a resource without allocation should still succeed. @@ -681,8 +693,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBuffer) { TEST_F(D3D12ResourceAllocatorTests, CreateBufferLeaked) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ComPtr allocation; @@ -698,8 +710,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferUMA) { GPGMM_SKIP_TEST_IF(!mCaps->IsAdapterUMA()); ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ASSERT_SUCCEEDED( @@ -733,7 +745,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferDisableUMA) { allocatorDesc.Flags |= ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); { ComPtr allocation; @@ -780,8 +793,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateSmallTexture) { // DXGI_FORMAT_R8G8B8A8_UNORM { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC allocationDesc = {}; @@ -803,7 +816,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateSmallTexture) { allocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_DEDICATED; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; @@ -825,8 +839,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateSmallTexture) { TEST_F(D3D12ResourceAllocatorTests, CreateMultisampledTexture) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); // DXGI_FORMAT_R8G8B8A8_UNORM @@ -851,8 +865,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateMultisampledTexture) { TEST_F(D3D12ResourceAllocatorTests, CreateBufferImported) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); // Importing a non-existent buffer should always fail. @@ -892,8 +906,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferImported) { TEST_F(D3D12ResourceAllocatorTests, CreateBufferInvalid) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); // Garbage buffer descriptor should always fail. @@ -911,7 +925,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) { desc.Flags = ALLOCATOR_FLAG_ALWAYS_COMMITTED; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(desc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED( + CreateResourceAllocator(desc, mDevice.Get(), mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC allocationDesc = {}; @@ -948,8 +963,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) { TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverAllocate) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); // Check we can't reuse memory if CreateResource was never called previously. @@ -986,8 +1001,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverAllocate) { TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC baseAllocationDesc = {}; @@ -1144,8 +1159,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinMany) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC allocationDesc = {}; @@ -1262,8 +1277,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinMany) { TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverSubAllocated) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); constexpr uint64_t bufferSize = kBufferOf4MBAllocationSize / 2; @@ -1286,7 +1301,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverPooled) { allocatorDesc.Flags |= ALLOCATOR_FLAG_ALWAYS_ON_DEMAND; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC baseAllocationDesc = {}; @@ -1343,7 +1359,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); ComPtr poolAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &poolAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &poolAllocator, nullptr)); ASSERT_NE(poolAllocator, nullptr); // Only standalone allocations can be pool-allocated. @@ -1437,7 +1454,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(desc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(desc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ComPtr allocation; @@ -1455,8 +1473,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { // Calculate stats for a single standalone allocation. { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC standaloneAllocationDesc = {}; @@ -1480,7 +1498,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC standaloneAllocationDesc = {}; @@ -1513,8 +1532,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { // Calculate info for two sub-allocations. { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC subAllocationDesc = {}; @@ -1556,8 +1575,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { // Calculate stats for two sub-allocations within the same resource. { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC allocationWithinDesc = {}; @@ -1598,7 +1617,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateTexturePooled) { ComPtr poolAllocator; { ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &poolAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &poolAllocator, nullptr)); ASSERT_NE(poolAllocator, nullptr); } @@ -1649,7 +1669,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithLimitedFragmentation) { // By default, buffer should be sub-allocated. { ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ComPtr allocation; @@ -1663,7 +1684,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithLimitedFragmentation) { // Force standalone buffer creation. { ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC standaloneAllocationDesc = baseAllocationDesc; @@ -1682,7 +1704,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithLimitedFragmentation) { allocatorDesc.Flags |= ALLOCATOR_FLAG_ALWAYS_COMMITTED; ComPtr commitedAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &commitedAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &commitedAllocator, nullptr)); ASSERT_NE(commitedAllocator, nullptr); ComPtr allocation; @@ -1707,7 +1730,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyPrefetch) { allocatorDesc.Flags ^= ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH; ComPtr resourceAllocator; - ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), + &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); constexpr uint64_t kNumOfBuffers = 1000u; @@ -1734,8 +1758,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyPrefetch) { // Creates a bunch of buffers concurrently. TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyThreaded) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC allocationDesc = {}; @@ -1763,8 +1787,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyThreaded) { // Creates a bunch of buffers concurrently. TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinManyThreaded) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC allocationDesc = {}; @@ -1799,8 +1823,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferCacheSize) { GPGMM_SKIP_TEST_IF(IsSizeCacheEnabled()); ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); // First request is always a cache miss. @@ -1895,8 +1919,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferCacheSize) { // Verify two buffers, with and without padding, allocate the correct size. TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPadding) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); constexpr uint64_t kBufferSize = GPGMM_MB_TO_BYTES(1); @@ -1926,8 +1950,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPadding) { // Verify two textures, with and without padding, allocate the correct size. TEST_F(D3D12ResourceAllocatorTests, CreateTextureWithPadding) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC allocationDesc = {}; @@ -1954,8 +1978,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateTextureWithPadding) { TEST_F(D3D12ResourceAllocatorTests, AllocatorFeatures) { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( - CreateResourceAllocator(CreateBasicAllocatorDesc(), &resourceAllocator, nullptr)); + ASSERT_SUCCEEDED(CreateResourceAllocator(CreateBasicAllocatorDesc(), mDevice.Get(), + mAdapter.Get(), &resourceAllocator, nullptr)); ASSERT_NE(resourceAllocator, nullptr); // Request information with invalid data size.