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:
parent
e79b06100f
commit
e16a901fb8
4
BUILD.gn
4
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",
|
||||
|
|
|
@ -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<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
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<ResourceMemoryAllocation> CommittedResourceAllocator::Allocate(
|
||||
ResultOrError<ResourceHeapAllocation> 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> resourceHeap(ToBackend(allocation.GetResourceHeap()));
|
||||
mDevice->ReferenceUntilUnused(resourceHeap->GetD3D12Resource());
|
||||
void CommittedResourceAllocator::Deallocate(ResourceHeapAllocation& allocation) {
|
||||
mDevice->ReferenceUntilUnused(allocation.GetD3D12Resource());
|
||||
}
|
||||
}} // namespace dawn_native::d3d12
|
||||
|
|
|
@ -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<ResourceMemoryAllocation> Allocate(
|
||||
ResultOrError<ResourceHeapAllocation> 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;
|
||||
|
|
|
@ -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<ResourceMemoryAllocation> Device::AllocateMemory(
|
||||
ResultOrError<ResourceHeapAllocation> Device::AllocateMemory(
|
||||
D3D12_HEAP_TYPE heapType,
|
||||
const D3D12_RESOURCE_DESC& resourceDescriptor,
|
||||
D3D12_RESOURCE_STATES initialUsage,
|
||||
|
|
|
@ -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 <memory>
|
||||
|
@ -87,13 +87,13 @@ namespace dawn_native { namespace d3d12 {
|
|||
uint64_t destinationOffset,
|
||||
uint64_t size) override;
|
||||
|
||||
ResultOrError<ResourceMemoryAllocation> AllocateMemory(
|
||||
ResultOrError<ResourceHeapAllocation> 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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<ResourceMemoryAllocation> ResourceAllocatorManager::AllocateMemory(
|
||||
ResultOrError<ResourceHeapAllocation> 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();
|
||||
|
|
|
@ -29,13 +29,13 @@ namespace dawn_native { namespace d3d12 {
|
|||
public:
|
||||
ResourceAllocatorManager(Device* device);
|
||||
|
||||
ResultOrError<ResourceMemoryAllocation> AllocateMemory(
|
||||
ResultOrError<ResourceHeapAllocation> 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;
|
||||
|
|
|
@ -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<ID3D12Resource> resource) : mResource(resource) {
|
||||
ResourceHeapAllocation::ResourceHeapAllocation(const AllocationInfo& info,
|
||||
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;
|
||||
}
|
||||
|
||||
D3D12_GPU_VIRTUAL_ADDRESS ResourceHeap::GetGPUPointer() const {
|
||||
D3D12_GPU_VIRTUAL_ADDRESS ResourceHeapAllocation::GetGPUPointer() const {
|
||||
return mResource->GetGPUVirtualAddress();
|
||||
}
|
||||
}} // namespace dawn_native::d3d12
|
|
@ -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<ID3D12Resource> resource);
|
||||
|
||||
~ResourceHeap() = default;
|
||||
ResourceHeapAllocation() = default;
|
||||
ResourceHeapAllocation(const AllocationInfo& info,
|
||||
uint64_t offset,
|
||||
ComPtr<ID3D12Resource> resource);
|
||||
~ResourceHeapAllocation() = default;
|
||||
|
||||
ComPtr<ID3D12Resource> 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_
|
||||
#endif // DAWNNATIVE_D3D12_RESOURCEHEAPALLOCATIOND3D12_H_
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue