D3D12: Move resource into allocation handle.

Allows buffer/texture direct access to underlying resource rather than indirectly with a opaque memory type.

BUG=dawn:27

Change-Id: I2eb69f4e30c96c431dbc96094d671be1e0a29869
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11800
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com>
This commit is contained in:
Bryan Bernhart 2019-10-09 16:50:42 +00:00 committed by Commit Bot service account
parent e79b06100f
commit e16a901fb8
14 changed files with 45 additions and 54 deletions

View File

@ -279,8 +279,8 @@ source_set("libdawn_native_sources") {
"src/dawn_native/d3d12/ResourceAllocator.h", "src/dawn_native/d3d12/ResourceAllocator.h",
"src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp", "src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp",
"src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.h", "src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.h",
"src/dawn_native/d3d12/ResourceHeapD3D12.cpp", "src/dawn_native/d3d12/ResourceHeapAllocationD3D12.cpp",
"src/dawn_native/d3d12/ResourceHeapD3D12.h", "src/dawn_native/d3d12/ResourceHeapAllocationD3D12.h",
"src/dawn_native/d3d12/SamplerD3D12.cpp", "src/dawn_native/d3d12/SamplerD3D12.cpp",
"src/dawn_native/d3d12/SamplerD3D12.h", "src/dawn_native/d3d12/SamplerD3D12.h",
"src/dawn_native/d3d12/ShaderModuleD3D12.cpp", "src/dawn_native/d3d12/ShaderModuleD3D12.cpp",

View File

@ -18,7 +18,6 @@
#include "common/Constants.h" #include "common/Constants.h"
#include "common/Math.h" #include "common/Math.h"
#include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h"
#include "dawn_native/d3d12/ResourceHeapD3D12.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
@ -125,7 +124,7 @@ namespace dawn_native { namespace d3d12 {
} }
ComPtr<ID3D12Resource> Buffer::GetD3D12Resource() const { ComPtr<ID3D12Resource> 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 // 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 { 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) { void Buffer::OnMapCommandSerialFinished(uint32_t mapSerial, void* data, bool isWrite) {

View File

@ -18,7 +18,7 @@
#include "common/SerialQueue.h" #include "common/SerialQueue.h"
#include "dawn_native/Buffer.h" #include "dawn_native/Buffer.h"
#include "dawn_native/ResourceMemoryAllocation.h" #include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h"
#include "dawn_native/d3d12/d3d12_platform.h" #include "dawn_native/d3d12/d3d12_platform.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
@ -51,7 +51,7 @@ namespace dawn_native { namespace d3d12 {
bool IsMapWritable() const override; bool IsMapWritable() const override;
virtual MaybeError MapAtCreationImpl(uint8_t** mappedPointer) override; virtual MaybeError MapAtCreationImpl(uint8_t** mappedPointer) override;
ResourceMemoryAllocation mResourceAllocation; ResourceHeapAllocation mResourceAllocation;
bool mFixedResourceState = false; bool mFixedResourceState = false;
dawn::BufferUsage mLastUsage = dawn::BufferUsage::None; dawn::BufferUsage mLastUsage = dawn::BufferUsage::None;
Serial mLastUsedSerial = UINT64_MAX; Serial mLastUsedSerial = UINT64_MAX;

View File

@ -14,7 +14,6 @@
#include "dawn_native/d3d12/CommittedResourceAllocatorD3D12.h" #include "dawn_native/d3d12/CommittedResourceAllocatorD3D12.h"
#include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h"
#include "dawn_native/d3d12/ResourceHeapD3D12.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
@ -22,7 +21,7 @@ namespace dawn_native { namespace d3d12 {
: mDevice(device), mHeapType(heapType) { : mDevice(device), mHeapType(heapType) {
} }
ResultOrError<ResourceMemoryAllocation> CommittedResourceAllocator::Allocate( ResultOrError<ResourceHeapAllocation> CommittedResourceAllocator::Allocate(
const D3D12_RESOURCE_DESC& resourceDescriptor, const D3D12_RESOURCE_DESC& resourceDescriptor,
D3D12_RESOURCE_STATES initialUsage, D3D12_RESOURCE_STATES initialUsage,
D3D12_HEAP_FLAGS heapFlags) { D3D12_HEAP_FLAGS heapFlags) {
@ -43,13 +42,11 @@ namespace dawn_native { namespace d3d12 {
AllocationInfo info; AllocationInfo info;
info.mMethod = AllocationMethod::kDirect; info.mMethod = AllocationMethod::kDirect;
return ResourceMemoryAllocation{info, return ResourceHeapAllocation{info,
/*offset*/ 0, /*offset*/ 0, std::move(committedResource)};
new ResourceHeap(std::move(committedResource))};
} }
void CommittedResourceAllocator::Deallocate(ResourceMemoryAllocation& allocation) { void CommittedResourceAllocator::Deallocate(ResourceHeapAllocation& allocation) {
std::unique_ptr<ResourceHeap> resourceHeap(ToBackend(allocation.GetResourceHeap())); mDevice->ReferenceUntilUnused(allocation.GetD3D12Resource());
mDevice->ReferenceUntilUnused(resourceHeap->GetD3D12Resource());
} }
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12

View File

@ -17,7 +17,7 @@
#include "common/SerialQueue.h" #include "common/SerialQueue.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/ResourceMemoryAllocation.h" #include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h"
#include "dawn_native/d3d12/d3d12_platform.h" #include "dawn_native/d3d12/d3d12_platform.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
@ -31,11 +31,11 @@ namespace dawn_native { namespace d3d12 {
CommittedResourceAllocator(Device* device, D3D12_HEAP_TYPE heapType); CommittedResourceAllocator(Device* device, D3D12_HEAP_TYPE heapType);
~CommittedResourceAllocator() = default; ~CommittedResourceAllocator() = default;
ResultOrError<ResourceMemoryAllocation> Allocate( ResultOrError<ResourceHeapAllocation> Allocate(
const D3D12_RESOURCE_DESC& resourceDescriptor, const D3D12_RESOURCE_DESC& resourceDescriptor,
D3D12_RESOURCE_STATES initialUsage, D3D12_RESOURCE_STATES initialUsage,
D3D12_HEAP_FLAGS heapFlags); D3D12_HEAP_FLAGS heapFlags);
void Deallocate(ResourceMemoryAllocation& allocation); void Deallocate(ResourceHeapAllocation& allocation);
private: private:
Device* mDevice; Device* mDevice;

View File

@ -32,7 +32,6 @@
#include "dawn_native/d3d12/RenderPipelineD3D12.h" #include "dawn_native/d3d12/RenderPipelineD3D12.h"
#include "dawn_native/d3d12/ResourceAllocator.h" #include "dawn_native/d3d12/ResourceAllocator.h"
#include "dawn_native/d3d12/ResourceAllocatorManagerD3D12.h" #include "dawn_native/d3d12/ResourceAllocatorManagerD3D12.h"
#include "dawn_native/d3d12/ResourceHeapD3D12.h"
#include "dawn_native/d3d12/SamplerD3D12.h" #include "dawn_native/d3d12/SamplerD3D12.h"
#include "dawn_native/d3d12/ShaderModuleD3D12.h" #include "dawn_native/d3d12/ShaderModuleD3D12.h"
#include "dawn_native/d3d12/StagingBufferD3D12.h" #include "dawn_native/d3d12/StagingBufferD3D12.h"
@ -348,11 +347,11 @@ namespace dawn_native { namespace d3d12 {
return {}; return {};
} }
void Device::DeallocateMemory(ResourceMemoryAllocation& allocation) { void Device::DeallocateMemory(ResourceHeapAllocation& allocation) {
mResourceAllocatorManager->DeallocateMemory(allocation); mResourceAllocatorManager->DeallocateMemory(allocation);
} }
ResultOrError<ResourceMemoryAllocation> Device::AllocateMemory( ResultOrError<ResourceHeapAllocation> Device::AllocateMemory(
D3D12_HEAP_TYPE heapType, D3D12_HEAP_TYPE heapType,
const D3D12_RESOURCE_DESC& resourceDescriptor, const D3D12_RESOURCE_DESC& resourceDescriptor,
D3D12_RESOURCE_STATES initialUsage, D3D12_RESOURCE_STATES initialUsage,

View File

@ -19,8 +19,8 @@
#include "common/SerialQueue.h" #include "common/SerialQueue.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ResourceMemoryAllocation.h"
#include "dawn_native/d3d12/Forward.h" #include "dawn_native/d3d12/Forward.h"
#include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h"
#include "dawn_native/d3d12/d3d12_platform.h" #include "dawn_native/d3d12/d3d12_platform.h"
#include <memory> #include <memory>
@ -87,13 +87,13 @@ namespace dawn_native { namespace d3d12 {
uint64_t destinationOffset, uint64_t destinationOffset,
uint64_t size) override; uint64_t size) override;
ResultOrError<ResourceMemoryAllocation> AllocateMemory( ResultOrError<ResourceHeapAllocation> AllocateMemory(
D3D12_HEAP_TYPE heapType, D3D12_HEAP_TYPE heapType,
const D3D12_RESOURCE_DESC& resourceDescriptor, const D3D12_RESOURCE_DESC& resourceDescriptor,
D3D12_RESOURCE_STATES initialUsage, D3D12_RESOURCE_STATES initialUsage,
D3D12_HEAP_FLAGS heapFlags); D3D12_HEAP_FLAGS heapFlags);
void DeallocateMemory(ResourceMemoryAllocation& allocation); void DeallocateMemory(ResourceHeapAllocation& allocation);
TextureBase* WrapSharedHandle(const TextureDescriptor* descriptor, HANDLE sharedHandle); TextureBase* WrapSharedHandle(const TextureDescriptor* descriptor, HANDLE sharedHandle);

View File

@ -29,7 +29,6 @@ namespace dawn_native { namespace d3d12 {
class PipelineLayout; class PipelineLayout;
class Queue; class Queue;
class RenderPipeline; class RenderPipeline;
class ResourceHeap;
class Sampler; class Sampler;
class ShaderModule; class ShaderModule;
class StagingBuffer; class StagingBuffer;
@ -48,7 +47,6 @@ namespace dawn_native { namespace d3d12 {
using PipelineLayoutType = PipelineLayout; using PipelineLayoutType = PipelineLayout;
using QueueType = Queue; using QueueType = Queue;
using RenderPipelineType = RenderPipeline; using RenderPipelineType = RenderPipeline;
using ResourceHeapType = ResourceHeap;
using SamplerType = Sampler; using SamplerType = Sampler;
using ShaderModuleType = ShaderModule; using ShaderModuleType = ShaderModule;
using StagingBufferType = StagingBuffer; using StagingBufferType = StagingBuffer;

View File

@ -14,14 +14,13 @@
#include "dawn_native/d3d12/ResourceAllocatorManagerD3D12.h" #include "dawn_native/d3d12/ResourceAllocatorManagerD3D12.h"
#include "dawn_native/d3d12/Forward.h" #include "dawn_native/d3d12/Forward.h"
#include "dawn_native/d3d12/ResourceHeapD3D12.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
ResourceAllocatorManager::ResourceAllocatorManager(Device* device) : mDevice(device) { ResourceAllocatorManager::ResourceAllocatorManager(Device* device) : mDevice(device) {
} }
ResultOrError<ResourceMemoryAllocation> ResourceAllocatorManager::AllocateMemory( ResultOrError<ResourceHeapAllocation> ResourceAllocatorManager::AllocateMemory(
D3D12_HEAP_TYPE heapType, D3D12_HEAP_TYPE heapType,
const D3D12_RESOURCE_DESC& resourceDescriptor, const D3D12_RESOURCE_DESC& resourceDescriptor,
D3D12_RESOURCE_STATES initialUsage, D3D12_RESOURCE_STATES initialUsage,
@ -37,7 +36,7 @@ namespace dawn_native { namespace d3d12 {
allocator = mDirectResourceAllocators[heapTypeIndex].get(); allocator = mDirectResourceAllocators[heapTypeIndex].get();
} }
ResourceMemoryAllocation allocation; ResourceHeapAllocation allocation;
DAWN_TRY_ASSIGN(allocation, DAWN_TRY_ASSIGN(allocation,
allocator->Allocate(resourceDescriptor, initialUsage, heapFlags)); allocator->Allocate(resourceDescriptor, initialUsage, heapFlags));
@ -50,15 +49,13 @@ namespace dawn_native { namespace d3d12 {
return heapType - 1; return heapType - 1;
} }
void ResourceAllocatorManager::DeallocateMemory(ResourceMemoryAllocation& allocation) { void ResourceAllocatorManager::DeallocateMemory(ResourceHeapAllocation& allocation) {
if (allocation.GetInfo().mMethod == AllocationMethod::kInvalid) { if (allocation.GetInfo().mMethod == AllocationMethod::kInvalid) {
return; return;
} }
CommittedResourceAllocator* allocator = nullptr; CommittedResourceAllocator* allocator = nullptr;
D3D12_HEAP_PROPERTIES heapProp; D3D12_HEAP_PROPERTIES heapProp;
ToBackend(allocation.GetResourceHeap()) allocation.GetD3D12Resource()->GetHeapProperties(&heapProp, nullptr);
->GetD3D12Resource()
->GetHeapProperties(&heapProp, nullptr);
const size_t heapTypeIndex = GetD3D12HeapTypeToIndex(heapProp.Type); const size_t heapTypeIndex = GetD3D12HeapTypeToIndex(heapProp.Type);
ASSERT(heapTypeIndex < kNumHeapTypes); ASSERT(heapTypeIndex < kNumHeapTypes);
allocator = mDirectResourceAllocators[heapTypeIndex].get(); allocator = mDirectResourceAllocators[heapTypeIndex].get();

View File

@ -29,13 +29,13 @@ namespace dawn_native { namespace d3d12 {
public: public:
ResourceAllocatorManager(Device* device); ResourceAllocatorManager(Device* device);
ResultOrError<ResourceMemoryAllocation> AllocateMemory( ResultOrError<ResourceHeapAllocation> AllocateMemory(
D3D12_HEAP_TYPE heapType, D3D12_HEAP_TYPE heapType,
const D3D12_RESOURCE_DESC& resourceDescriptor, const D3D12_RESOURCE_DESC& resourceDescriptor,
D3D12_RESOURCE_STATES initialUsage, D3D12_RESOURCE_STATES initialUsage,
D3D12_HEAP_FLAGS heapFlags); D3D12_HEAP_FLAGS heapFlags);
void DeallocateMemory(ResourceMemoryAllocation& allocation); void DeallocateMemory(ResourceHeapAllocation& allocation);
private: private:
size_t GetD3D12HeapTypeToIndex(D3D12_HEAP_TYPE heapType) const; size_t GetD3D12HeapTypeToIndex(D3D12_HEAP_TYPE heapType) const;

View File

@ -12,19 +12,20 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "dawn_native/d3d12/ResourceHeapD3D12.h" #include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h"
#include "dawn_native/d3d12/DeviceD3D12.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
ResourceHeapAllocation::ResourceHeapAllocation(const AllocationInfo& info,
ResourceHeap::ResourceHeap(ComPtr<ID3D12Resource> resource) : mResource(resource) { uint64_t offset,
ComPtr<ID3D12Resource> resource)
: ResourceMemoryAllocation(info, offset, nullptr), mResource(std::move(resource)) {
} }
ComPtr<ID3D12Resource> ResourceHeap::GetD3D12Resource() const { ComPtr<ID3D12Resource> ResourceHeapAllocation::GetD3D12Resource() const {
return mResource; return mResource;
} }
D3D12_GPU_VIRTUAL_ADDRESS ResourceHeap::GetGPUPointer() const { D3D12_GPU_VIRTUAL_ADDRESS ResourceHeapAllocation::GetGPUPointer() const {
return mResource->GetGPUVirtualAddress(); return mResource->GetGPUVirtualAddress();
} }
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12

View File

@ -12,20 +12,21 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef DAWNNATIVE_D3D12_RESOURCEHEAPD3D12_H_ #ifndef DAWNNATIVE_D3D12_RESOURCEHEAPALLOCATIOND3D12_H_
#define DAWNNATIVE_D3D12_RESOURCEHEAPD3D12_H_ #define DAWNNATIVE_D3D12_RESOURCEHEAPALLOCATIOND3D12_H_
#include "dawn_native/ResourceHeap.h" #include "dawn_native/ResourceMemoryAllocation.h"
#include "dawn_native/d3d12/d3d12_platform.h" #include "dawn_native/d3d12/d3d12_platform.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
// Wrapper for physical memory used with or without a resource object. class ResourceHeapAllocation : public ResourceMemoryAllocation {
class ResourceHeap : public ResourceHeapBase {
public: public:
ResourceHeap(ComPtr<ID3D12Resource> resource); ResourceHeapAllocation() = default;
ResourceHeapAllocation(const AllocationInfo& info,
~ResourceHeap() = default; uint64_t offset,
ComPtr<ID3D12Resource> resource);
~ResourceHeapAllocation() = default;
ComPtr<ID3D12Resource> GetD3D12Resource() const; ComPtr<ID3D12Resource> GetD3D12Resource() const;
D3D12_GPU_VIRTUAL_ADDRESS GetGPUPointer() const; D3D12_GPU_VIRTUAL_ADDRESS GetGPUPointer() const;
@ -35,4 +36,4 @@ namespace dawn_native { namespace d3d12 {
}; };
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12
#endif // DAWNNATIVE_D3D12_RESOURCEHEAPD3D12_H_ #endif // DAWNNATIVE_D3D12_RESOURCEHEAPALLOCATIOND3D12_H_

View File

@ -14,7 +14,6 @@
#include "dawn_native/d3d12/StagingBufferD3D12.h" #include "dawn_native/d3d12/StagingBufferD3D12.h"
#include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h"
#include "dawn_native/d3d12/ResourceHeapD3D12.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
@ -56,7 +55,7 @@ namespace dawn_native { namespace d3d12 {
} }
ID3D12Resource* StagingBuffer::GetResource() const { ID3D12Resource* StagingBuffer::GetResource() const {
return ToBackend(mUploadHeap.GetResourceHeap())->GetD3D12Resource().Get(); return mUploadHeap.GetD3D12Resource().Get();
} }
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12

View File

@ -15,8 +15,8 @@
#ifndef DAWNNATIVE_STAGINGBUFFERD3D12_H_ #ifndef DAWNNATIVE_STAGINGBUFFERD3D12_H_
#define DAWNNATIVE_STAGINGBUFFERD3D12_H_ #define DAWNNATIVE_STAGINGBUFFERD3D12_H_
#include "dawn_native/ResourceMemoryAllocation.h"
#include "dawn_native/StagingBuffer.h" #include "dawn_native/StagingBuffer.h"
#include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h"
#include "dawn_native/d3d12/d3d12_platform.h" #include "dawn_native/d3d12/d3d12_platform.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
@ -34,7 +34,7 @@ namespace dawn_native { namespace d3d12 {
private: private:
Device* mDevice; Device* mDevice;
ResourceMemoryAllocation mUploadHeap; ResourceHeapAllocation mUploadHeap;
}; };
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12