diff --git a/BUILD.gn b/BUILD.gn index acf0042889..6da0affaca 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -279,8 +279,8 @@ source_set("libdawn_native_sources") { "src/dawn_native/d3d12/ResourceAllocator.h", "src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp", "src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.h", - "src/dawn_native/d3d12/ResourceHeapD3D12.cpp", - "src/dawn_native/d3d12/ResourceHeapD3D12.h", + "src/dawn_native/d3d12/ResourceHeapAllocationD3D12.cpp", + "src/dawn_native/d3d12/ResourceHeapAllocationD3D12.h", "src/dawn_native/d3d12/SamplerD3D12.cpp", "src/dawn_native/d3d12/SamplerD3D12.h", "src/dawn_native/d3d12/ShaderModuleD3D12.cpp", diff --git a/src/dawn_native/d3d12/BufferD3D12.cpp b/src/dawn_native/d3d12/BufferD3D12.cpp index 148a7408a3..b8544bd18a 100644 --- a/src/dawn_native/d3d12/BufferD3D12.cpp +++ b/src/dawn_native/d3d12/BufferD3D12.cpp @@ -18,7 +18,6 @@ #include "common/Constants.h" #include "common/Math.h" #include "dawn_native/d3d12/DeviceD3D12.h" -#include "dawn_native/d3d12/ResourceHeapD3D12.h" namespace dawn_native { namespace d3d12 { @@ -125,7 +124,7 @@ namespace dawn_native { namespace d3d12 { } ComPtr Buffer::GetD3D12Resource() const { - return ToBackend(mResourceAllocation.GetResourceHeap())->GetD3D12Resource(); + return mResourceAllocation.GetD3D12Resource(); } // When true is returned, a D3D12_RESOURCE_BARRIER has been created and must be used in a @@ -198,7 +197,7 @@ namespace dawn_native { namespace d3d12 { } D3D12_GPU_VIRTUAL_ADDRESS Buffer::GetVA() const { - return ToBackend(mResourceAllocation.GetResourceHeap())->GetGPUPointer(); + return mResourceAllocation.GetGPUPointer(); } void Buffer::OnMapCommandSerialFinished(uint32_t mapSerial, void* data, bool isWrite) { diff --git a/src/dawn_native/d3d12/BufferD3D12.h b/src/dawn_native/d3d12/BufferD3D12.h index 7a9b433091..f7ccd130c0 100644 --- a/src/dawn_native/d3d12/BufferD3D12.h +++ b/src/dawn_native/d3d12/BufferD3D12.h @@ -18,7 +18,7 @@ #include "common/SerialQueue.h" #include "dawn_native/Buffer.h" -#include "dawn_native/ResourceMemoryAllocation.h" +#include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h" #include "dawn_native/d3d12/d3d12_platform.h" namespace dawn_native { namespace d3d12 { @@ -51,7 +51,7 @@ namespace dawn_native { namespace d3d12 { bool IsMapWritable() const override; virtual MaybeError MapAtCreationImpl(uint8_t** mappedPointer) override; - ResourceMemoryAllocation mResourceAllocation; + ResourceHeapAllocation mResourceAllocation; bool mFixedResourceState = false; dawn::BufferUsage mLastUsage = dawn::BufferUsage::None; Serial mLastUsedSerial = UINT64_MAX; diff --git a/src/dawn_native/d3d12/CommittedResourceAllocatorD3D12.cpp b/src/dawn_native/d3d12/CommittedResourceAllocatorD3D12.cpp index 115ade4f83..9a55e690b2 100644 --- a/src/dawn_native/d3d12/CommittedResourceAllocatorD3D12.cpp +++ b/src/dawn_native/d3d12/CommittedResourceAllocatorD3D12.cpp @@ -14,7 +14,6 @@ #include "dawn_native/d3d12/CommittedResourceAllocatorD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h" -#include "dawn_native/d3d12/ResourceHeapD3D12.h" namespace dawn_native { namespace d3d12 { @@ -22,7 +21,7 @@ namespace dawn_native { namespace d3d12 { : mDevice(device), mHeapType(heapType) { } - ResultOrError CommittedResourceAllocator::Allocate( + ResultOrError CommittedResourceAllocator::Allocate( const D3D12_RESOURCE_DESC& resourceDescriptor, D3D12_RESOURCE_STATES initialUsage, D3D12_HEAP_FLAGS heapFlags) { @@ -43,13 +42,11 @@ namespace dawn_native { namespace d3d12 { AllocationInfo info; info.mMethod = AllocationMethod::kDirect; - return ResourceMemoryAllocation{info, - /*offset*/ 0, - new ResourceHeap(std::move(committedResource))}; + return ResourceHeapAllocation{info, + /*offset*/ 0, std::move(committedResource)}; } - void CommittedResourceAllocator::Deallocate(ResourceMemoryAllocation& allocation) { - std::unique_ptr resourceHeap(ToBackend(allocation.GetResourceHeap())); - mDevice->ReferenceUntilUnused(resourceHeap->GetD3D12Resource()); + void CommittedResourceAllocator::Deallocate(ResourceHeapAllocation& allocation) { + mDevice->ReferenceUntilUnused(allocation.GetD3D12Resource()); } }} // namespace dawn_native::d3d12 diff --git a/src/dawn_native/d3d12/CommittedResourceAllocatorD3D12.h b/src/dawn_native/d3d12/CommittedResourceAllocatorD3D12.h index 419d1c6cbd..7bfb9d8b42 100644 --- a/src/dawn_native/d3d12/CommittedResourceAllocatorD3D12.h +++ b/src/dawn_native/d3d12/CommittedResourceAllocatorD3D12.h @@ -17,7 +17,7 @@ #include "common/SerialQueue.h" #include "dawn_native/Error.h" -#include "dawn_native/ResourceMemoryAllocation.h" +#include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h" #include "dawn_native/d3d12/d3d12_platform.h" namespace dawn_native { namespace d3d12 { @@ -31,11 +31,11 @@ namespace dawn_native { namespace d3d12 { CommittedResourceAllocator(Device* device, D3D12_HEAP_TYPE heapType); ~CommittedResourceAllocator() = default; - ResultOrError Allocate( + ResultOrError Allocate( const D3D12_RESOURCE_DESC& resourceDescriptor, D3D12_RESOURCE_STATES initialUsage, D3D12_HEAP_FLAGS heapFlags); - void Deallocate(ResourceMemoryAllocation& allocation); + void Deallocate(ResourceHeapAllocation& allocation); private: Device* mDevice; diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 651b366b2f..b3c4c97604 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -32,7 +32,6 @@ #include "dawn_native/d3d12/RenderPipelineD3D12.h" #include "dawn_native/d3d12/ResourceAllocator.h" #include "dawn_native/d3d12/ResourceAllocatorManagerD3D12.h" -#include "dawn_native/d3d12/ResourceHeapD3D12.h" #include "dawn_native/d3d12/SamplerD3D12.h" #include "dawn_native/d3d12/ShaderModuleD3D12.h" #include "dawn_native/d3d12/StagingBufferD3D12.h" @@ -348,11 +347,11 @@ namespace dawn_native { namespace d3d12 { return {}; } - void Device::DeallocateMemory(ResourceMemoryAllocation& allocation) { + void Device::DeallocateMemory(ResourceHeapAllocation& allocation) { mResourceAllocatorManager->DeallocateMemory(allocation); } - ResultOrError Device::AllocateMemory( + ResultOrError Device::AllocateMemory( D3D12_HEAP_TYPE heapType, const D3D12_RESOURCE_DESC& resourceDescriptor, D3D12_RESOURCE_STATES initialUsage, diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h index e1a2fe223e..eb575430e6 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.h +++ b/src/dawn_native/d3d12/DeviceD3D12.h @@ -19,8 +19,8 @@ #include "common/SerialQueue.h" #include "dawn_native/Device.h" -#include "dawn_native/ResourceMemoryAllocation.h" #include "dawn_native/d3d12/Forward.h" +#include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h" #include "dawn_native/d3d12/d3d12_platform.h" #include @@ -87,13 +87,13 @@ namespace dawn_native { namespace d3d12 { uint64_t destinationOffset, uint64_t size) override; - ResultOrError AllocateMemory( + ResultOrError AllocateMemory( D3D12_HEAP_TYPE heapType, const D3D12_RESOURCE_DESC& resourceDescriptor, D3D12_RESOURCE_STATES initialUsage, D3D12_HEAP_FLAGS heapFlags); - void DeallocateMemory(ResourceMemoryAllocation& allocation); + void DeallocateMemory(ResourceHeapAllocation& allocation); TextureBase* WrapSharedHandle(const TextureDescriptor* descriptor, HANDLE sharedHandle); diff --git a/src/dawn_native/d3d12/Forward.h b/src/dawn_native/d3d12/Forward.h index f42f82430f..ade12e3ac8 100644 --- a/src/dawn_native/d3d12/Forward.h +++ b/src/dawn_native/d3d12/Forward.h @@ -29,7 +29,6 @@ namespace dawn_native { namespace d3d12 { class PipelineLayout; class Queue; class RenderPipeline; - class ResourceHeap; class Sampler; class ShaderModule; class StagingBuffer; @@ -48,7 +47,6 @@ namespace dawn_native { namespace d3d12 { using PipelineLayoutType = PipelineLayout; using QueueType = Queue; using RenderPipelineType = RenderPipeline; - using ResourceHeapType = ResourceHeap; using SamplerType = Sampler; using ShaderModuleType = ShaderModule; using StagingBufferType = StagingBuffer; diff --git a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp index 9562892835..b18c998fb8 100644 --- a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp +++ b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp @@ -14,14 +14,13 @@ #include "dawn_native/d3d12/ResourceAllocatorManagerD3D12.h" #include "dawn_native/d3d12/Forward.h" -#include "dawn_native/d3d12/ResourceHeapD3D12.h" namespace dawn_native { namespace d3d12 { ResourceAllocatorManager::ResourceAllocatorManager(Device* device) : mDevice(device) { } - ResultOrError ResourceAllocatorManager::AllocateMemory( + ResultOrError ResourceAllocatorManager::AllocateMemory( D3D12_HEAP_TYPE heapType, const D3D12_RESOURCE_DESC& resourceDescriptor, D3D12_RESOURCE_STATES initialUsage, @@ -37,7 +36,7 @@ namespace dawn_native { namespace d3d12 { allocator = mDirectResourceAllocators[heapTypeIndex].get(); } - ResourceMemoryAllocation allocation; + ResourceHeapAllocation allocation; DAWN_TRY_ASSIGN(allocation, allocator->Allocate(resourceDescriptor, initialUsage, heapFlags)); @@ -50,15 +49,13 @@ namespace dawn_native { namespace d3d12 { return heapType - 1; } - void ResourceAllocatorManager::DeallocateMemory(ResourceMemoryAllocation& allocation) { + void ResourceAllocatorManager::DeallocateMemory(ResourceHeapAllocation& allocation) { if (allocation.GetInfo().mMethod == AllocationMethod::kInvalid) { return; } CommittedResourceAllocator* allocator = nullptr; D3D12_HEAP_PROPERTIES heapProp; - ToBackend(allocation.GetResourceHeap()) - ->GetD3D12Resource() - ->GetHeapProperties(&heapProp, nullptr); + allocation.GetD3D12Resource()->GetHeapProperties(&heapProp, nullptr); const size_t heapTypeIndex = GetD3D12HeapTypeToIndex(heapProp.Type); ASSERT(heapTypeIndex < kNumHeapTypes); allocator = mDirectResourceAllocators[heapTypeIndex].get(); diff --git a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.h b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.h index 7de6c58c6d..d8f1cdb30e 100644 --- a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.h +++ b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.h @@ -29,13 +29,13 @@ namespace dawn_native { namespace d3d12 { public: ResourceAllocatorManager(Device* device); - ResultOrError AllocateMemory( + ResultOrError AllocateMemory( D3D12_HEAP_TYPE heapType, const D3D12_RESOURCE_DESC& resourceDescriptor, D3D12_RESOURCE_STATES initialUsage, D3D12_HEAP_FLAGS heapFlags); - void DeallocateMemory(ResourceMemoryAllocation& allocation); + void DeallocateMemory(ResourceHeapAllocation& allocation); private: size_t GetD3D12HeapTypeToIndex(D3D12_HEAP_TYPE heapType) const; diff --git a/src/dawn_native/d3d12/ResourceHeapD3D12.cpp b/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.cpp similarity index 56% rename from src/dawn_native/d3d12/ResourceHeapD3D12.cpp rename to src/dawn_native/d3d12/ResourceHeapAllocationD3D12.cpp index 5aec4b3256..a55983493d 100644 --- a/src/dawn_native/d3d12/ResourceHeapD3D12.cpp +++ b/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.cpp @@ -12,19 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "dawn_native/d3d12/ResourceHeapD3D12.h" -#include "dawn_native/d3d12/DeviceD3D12.h" +#include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h" namespace dawn_native { namespace d3d12 { - - ResourceHeap::ResourceHeap(ComPtr resource) : mResource(resource) { + ResourceHeapAllocation::ResourceHeapAllocation(const AllocationInfo& info, + uint64_t offset, + ComPtr resource) + : ResourceMemoryAllocation(info, offset, nullptr), mResource(std::move(resource)) { } - ComPtr ResourceHeap::GetD3D12Resource() const { + ComPtr ResourceHeapAllocation::GetD3D12Resource() const { return mResource; } - D3D12_GPU_VIRTUAL_ADDRESS ResourceHeap::GetGPUPointer() const { + D3D12_GPU_VIRTUAL_ADDRESS ResourceHeapAllocation::GetGPUPointer() const { return mResource->GetGPUVirtualAddress(); } }} // namespace dawn_native::d3d12 \ No newline at end of file diff --git a/src/dawn_native/d3d12/ResourceHeapD3D12.h b/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.h similarity index 62% rename from src/dawn_native/d3d12/ResourceHeapD3D12.h rename to src/dawn_native/d3d12/ResourceHeapAllocationD3D12.h index 18b342a691..8230857dbf 100644 --- a/src/dawn_native/d3d12/ResourceHeapD3D12.h +++ b/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.h @@ -12,20 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef DAWNNATIVE_D3D12_RESOURCEHEAPD3D12_H_ -#define DAWNNATIVE_D3D12_RESOURCEHEAPD3D12_H_ +#ifndef DAWNNATIVE_D3D12_RESOURCEHEAPALLOCATIOND3D12_H_ +#define DAWNNATIVE_D3D12_RESOURCEHEAPALLOCATIOND3D12_H_ -#include "dawn_native/ResourceHeap.h" +#include "dawn_native/ResourceMemoryAllocation.h" #include "dawn_native/d3d12/d3d12_platform.h" namespace dawn_native { namespace d3d12 { - // Wrapper for physical memory used with or without a resource object. - class ResourceHeap : public ResourceHeapBase { + class ResourceHeapAllocation : public ResourceMemoryAllocation { public: - ResourceHeap(ComPtr resource); - - ~ResourceHeap() = default; + ResourceHeapAllocation() = default; + ResourceHeapAllocation(const AllocationInfo& info, + uint64_t offset, + ComPtr resource); + ~ResourceHeapAllocation() = default; ComPtr GetD3D12Resource() const; D3D12_GPU_VIRTUAL_ADDRESS GetGPUPointer() const; @@ -35,4 +36,4 @@ namespace dawn_native { namespace d3d12 { }; }} // namespace dawn_native::d3d12 -#endif // DAWNNATIVE_D3D12_RESOURCEHEAPD3D12_H_ \ No newline at end of file +#endif // DAWNNATIVE_D3D12_RESOURCEHEAPALLOCATIOND3D12_H_ \ No newline at end of file diff --git a/src/dawn_native/d3d12/StagingBufferD3D12.cpp b/src/dawn_native/d3d12/StagingBufferD3D12.cpp index cab3a18413..9e6c2bd7c6 100644 --- a/src/dawn_native/d3d12/StagingBufferD3D12.cpp +++ b/src/dawn_native/d3d12/StagingBufferD3D12.cpp @@ -14,7 +14,6 @@ #include "dawn_native/d3d12/StagingBufferD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h" -#include "dawn_native/d3d12/ResourceHeapD3D12.h" namespace dawn_native { namespace d3d12 { @@ -56,7 +55,7 @@ namespace dawn_native { namespace d3d12 { } ID3D12Resource* StagingBuffer::GetResource() const { - return ToBackend(mUploadHeap.GetResourceHeap())->GetD3D12Resource().Get(); + return mUploadHeap.GetD3D12Resource().Get(); } }} // namespace dawn_native::d3d12 diff --git a/src/dawn_native/d3d12/StagingBufferD3D12.h b/src/dawn_native/d3d12/StagingBufferD3D12.h index 633be53c32..ebba0c6718 100644 --- a/src/dawn_native/d3d12/StagingBufferD3D12.h +++ b/src/dawn_native/d3d12/StagingBufferD3D12.h @@ -15,8 +15,8 @@ #ifndef DAWNNATIVE_STAGINGBUFFERD3D12_H_ #define DAWNNATIVE_STAGINGBUFFERD3D12_H_ -#include "dawn_native/ResourceMemoryAllocation.h" #include "dawn_native/StagingBuffer.h" +#include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h" #include "dawn_native/d3d12/d3d12_platform.h" namespace dawn_native { namespace d3d12 { @@ -34,7 +34,7 @@ namespace dawn_native { namespace d3d12 { private: Device* mDevice; - ResourceMemoryAllocation mUploadHeap; + ResourceHeapAllocation mUploadHeap; }; }} // namespace dawn_native::d3d12