Return Dawn result upon submit.
Missing OOM error should submit fail to create a descriptor heap. BUG=dawn:177 Change-Id: I6ccc10f3e0b8de0bd21caa9aca35f4f269ce51e3 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11540 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
27a35eb2a9
commit
41f8aa550b
|
@ -39,7 +39,9 @@ namespace dawn_native {
|
|||
}
|
||||
ASSERT(!IsError());
|
||||
|
||||
SubmitImpl(commandCount, commands);
|
||||
if (device->ConsumedError(SubmitImpl(commandCount, commands))) {
|
||||
return;
|
||||
}
|
||||
device->GetErrorScopeTracker()->TrackUntilLastSubmitComplete(
|
||||
device->GetCurrentErrorScope());
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ namespace dawn_native {
|
|||
FenceBase* CreateFence(const FenceDescriptor* descriptor);
|
||||
|
||||
private:
|
||||
virtual void SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) = 0;
|
||||
virtual MaybeError SubmitImpl(uint32_t commandCount,
|
||||
CommandBufferBase* const* commands) = 0;
|
||||
|
||||
MaybeError ValidateSubmit(uint32_t commandCount, CommandBufferBase* const* commands);
|
||||
MaybeError ValidateSignal(const FenceBase* fence, uint64_t signalValue);
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
mInCompute = inCompute_;
|
||||
}
|
||||
|
||||
void AllocateDescriptorHeaps(Device* device) {
|
||||
MaybeError AllocateDescriptorHeaps(Device* device) {
|
||||
// This function should only be called once.
|
||||
ASSERT(mCbvSrvUavGPUDescriptorHeap.Get() == nullptr &&
|
||||
mSamplerGPUDescriptorHeap.Get() == nullptr);
|
||||
|
@ -90,13 +90,16 @@ namespace dawn_native { namespace d3d12 {
|
|||
DescriptorHeapAllocator* descriptorHeapAllocator = device->GetDescriptorHeapAllocator();
|
||||
|
||||
if (mCbvSrvUavDescriptorHeapSize > 0) {
|
||||
mCbvSrvUavGPUDescriptorHeap = descriptorHeapAllocator->AllocateGPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, mCbvSrvUavDescriptorHeapSize);
|
||||
DAWN_TRY_ASSIGN(
|
||||
mCbvSrvUavGPUDescriptorHeap,
|
||||
descriptorHeapAllocator->AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
|
||||
mCbvSrvUavDescriptorHeapSize));
|
||||
}
|
||||
|
||||
if (mSamplerDescriptorHeapSize > 0) {
|
||||
mSamplerGPUDescriptorHeap = descriptorHeapAllocator->AllocateGPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, mSamplerDescriptorHeapSize);
|
||||
DAWN_TRY_ASSIGN(mSamplerGPUDescriptorHeap, descriptorHeapAllocator->AllocateGPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER,
|
||||
mSamplerDescriptorHeapSize));
|
||||
}
|
||||
|
||||
uint32_t cbvSrvUavDescriptorIndex = 0;
|
||||
|
@ -115,6 +118,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
|
||||
ASSERT(cbvSrvUavDescriptorIndex == mCbvSrvUavDescriptorHeapSize);
|
||||
ASSERT(samplerDescriptorIndex == mSamplerDescriptorHeapSize);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// This function must only be called before calling AllocateDescriptorHeaps().
|
||||
|
@ -281,16 +286,19 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
}
|
||||
|
||||
void AllocateRTVAndDSVHeaps() {
|
||||
MaybeError AllocateRTVAndDSVHeaps() {
|
||||
// This function should only be called once.
|
||||
DAWN_ASSERT(mRTVHeap.Get() == nullptr && mDSVHeap.Get() == nullptr);
|
||||
DescriptorHeapAllocator* allocator = mDevice->GetDescriptorHeapAllocator();
|
||||
if (mNumRTVs > 0) {
|
||||
mRTVHeap = allocator->AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_RTV, mNumRTVs);
|
||||
DAWN_TRY_ASSIGN(
|
||||
mRTVHeap, allocator->AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_RTV, mNumRTVs));
|
||||
}
|
||||
if (mNumDSVs > 0) {
|
||||
mDSVHeap = allocator->AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_DSV, mNumDSVs);
|
||||
DAWN_TRY_ASSIGN(
|
||||
mDSVHeap, allocator->AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_DSV, mNumDSVs));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// TODO(jiawei.shao@intel.com): use hash map <RenderPass, OMSetRenderTargetArgs> as
|
||||
|
@ -445,7 +453,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
D3D12_INDEX_BUFFER_VIEW mD3D12BufferView = {};
|
||||
};
|
||||
|
||||
void AllocateAndSetDescriptorHeaps(Device* device,
|
||||
MaybeError AllocateAndSetDescriptorHeaps(Device* device,
|
||||
BindGroupStateTracker* bindingTracker,
|
||||
RenderPassDescriptorHeapTracker* renderPassTracker,
|
||||
CommandIterator* commands,
|
||||
|
@ -495,8 +503,9 @@ namespace dawn_native { namespace d3d12 {
|
|||
commands->Reset();
|
||||
}
|
||||
|
||||
renderPassTracker->AllocateRTVAndDSVHeaps();
|
||||
bindingTracker->AllocateDescriptorHeaps(device);
|
||||
DAWN_TRY(renderPassTracker->AllocateRTVAndDSVHeaps());
|
||||
DAWN_TRY(bindingTracker->AllocateDescriptorHeaps(device));
|
||||
return {};
|
||||
}
|
||||
|
||||
void ResolveMultisampledRenderPass(ComPtr<ID3D12GraphicsCommandList> commandList,
|
||||
|
@ -542,7 +551,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
FreeCommands(&mCommands);
|
||||
}
|
||||
|
||||
void CommandBuffer::RecordCommands(ComPtr<ID3D12GraphicsCommandList> commandList,
|
||||
MaybeError CommandBuffer::RecordCommands(ComPtr<ID3D12GraphicsCommandList> commandList,
|
||||
uint32_t indexInSubmit) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
BindGroupStateTracker bindingTracker(device);
|
||||
|
@ -553,8 +562,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
// should have a system where commands and descriptors are recorded in parallel then the
|
||||
// heaps set using a small CommandList inserted just before the main CommandList.
|
||||
{
|
||||
AllocateAndSetDescriptorHeaps(device, &bindingTracker, &renderPassTracker, &mCommands,
|
||||
indexInSubmit);
|
||||
DAWN_TRY(AllocateAndSetDescriptorHeaps(device, &bindingTracker, &renderPassTracker,
|
||||
&mCommands, indexInSubmit));
|
||||
bindingTracker.Reset();
|
||||
bindingTracker.SetID3D12DescriptorHeaps(commandList);
|
||||
}
|
||||
|
@ -765,6 +774,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
|
||||
DAWN_ASSERT(renderPassTracker.IsHeapAllocationCompleted());
|
||||
return {};
|
||||
}
|
||||
|
||||
void CommandBuffer::RecordComputePass(ComPtr<ID3D12GraphicsCommandList> commandList,
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "common/Constants.h"
|
||||
#include "dawn_native/CommandAllocator.h"
|
||||
#include "dawn_native/CommandBuffer.h"
|
||||
#include "dawn_native/Error.h"
|
||||
|
||||
#include "dawn_native/d3d12/Forward.h"
|
||||
#include "dawn_native/d3d12/d3d12_platform.h"
|
||||
|
@ -40,7 +41,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
CommandBuffer(CommandEncoderBase* encoder, const CommandBufferDescriptor* descriptor);
|
||||
~CommandBuffer();
|
||||
|
||||
void RecordCommands(ComPtr<ID3D12GraphicsCommandList> commandList, uint32_t indexInSubmit);
|
||||
MaybeError RecordCommands(ComPtr<ID3D12GraphicsCommandList> commandList,
|
||||
uint32_t indexInSubmit);
|
||||
|
||||
private:
|
||||
void RecordComputePass(ComPtr<ID3D12GraphicsCommandList> commandList,
|
||||
|
|
|
@ -61,7 +61,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
} {
|
||||
}
|
||||
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
ResultOrError<DescriptorHeapHandle> DescriptorHeapAllocator::Allocate(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
uint32_t count,
|
||||
uint32_t allocationSize,
|
||||
DescriptorHeapInfo* heapInfo,
|
||||
|
@ -94,8 +95,10 @@ namespace dawn_native { namespace d3d12 {
|
|||
heapDescriptor.Flags = flags;
|
||||
heapDescriptor.NodeMask = 0;
|
||||
ComPtr<ID3D12DescriptorHeap> heap;
|
||||
ASSERT_SUCCESS(
|
||||
mDevice->GetD3D12Device()->CreateDescriptorHeap(&heapDescriptor, IID_PPV_ARGS(&heap)));
|
||||
if (FAILED(mDevice->GetD3D12Device()->CreateDescriptorHeap(&heapDescriptor,
|
||||
IID_PPV_ARGS(&heap)))) {
|
||||
return DAWN_OUT_OF_MEMORY_ERROR("Unable to allocate heap");
|
||||
}
|
||||
|
||||
AllocationInfo allocationInfo = {allocationSize, allocationSize - count};
|
||||
*heapInfo = std::make_pair(heap, allocationInfo);
|
||||
|
@ -105,13 +108,15 @@ namespace dawn_native { namespace d3d12 {
|
|||
return handle;
|
||||
}
|
||||
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
ResultOrError<DescriptorHeapHandle> DescriptorHeapAllocator::AllocateCPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
uint32_t count) {
|
||||
return Allocate(type, count, count, &mCpuDescriptorHeapInfos[type],
|
||||
D3D12_DESCRIPTOR_HEAP_FLAG_NONE);
|
||||
}
|
||||
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
ResultOrError<DescriptorHeapHandle> DescriptorHeapAllocator::AllocateGPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
uint32_t count) {
|
||||
ASSERT(type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ||
|
||||
type == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <vector>
|
||||
#include "common/SerialQueue.h"
|
||||
|
||||
#include "dawn_native/Error.h"
|
||||
|
||||
namespace dawn_native { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
@ -46,8 +48,10 @@ namespace dawn_native { namespace d3d12 {
|
|||
public:
|
||||
DescriptorHeapAllocator(Device* device);
|
||||
|
||||
DescriptorHeapHandle AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t count);
|
||||
DescriptorHeapHandle AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t count);
|
||||
ResultOrError<DescriptorHeapHandle> AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
uint32_t count);
|
||||
ResultOrError<DescriptorHeapHandle> AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
uint32_t count);
|
||||
void Tick(uint64_t lastCompletedSerial);
|
||||
|
||||
private:
|
||||
|
@ -63,7 +67,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
|
||||
using DescriptorHeapInfo = std::pair<ComPtr<ID3D12DescriptorHeap>, AllocationInfo>;
|
||||
|
||||
DescriptorHeapHandle Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
ResultOrError<DescriptorHeapHandle> Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
uint32_t count,
|
||||
uint32_t allocationSize,
|
||||
DescriptorHeapInfo* heapInfo,
|
||||
|
|
|
@ -22,20 +22,21 @@ namespace dawn_native { namespace d3d12 {
|
|||
Queue::Queue(Device* device) : QueueBase(device) {
|
||||
}
|
||||
|
||||
void Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
|
||||
MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
device->Tick();
|
||||
|
||||
device->OpenCommandList(&mCommandList);
|
||||
for (uint32_t i = 0; i < commandCount; ++i) {
|
||||
ToBackend(commands[i])->RecordCommands(mCommandList, i);
|
||||
DAWN_TRY(ToBackend(commands[i])->RecordCommands(mCommandList, i));
|
||||
}
|
||||
ASSERT_SUCCESS(mCommandList->Close());
|
||||
|
||||
device->ExecuteCommandList(mCommandList.Get());
|
||||
|
||||
device->NextSerial();
|
||||
return {};
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::d3d12
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
Queue(Device* device);
|
||||
|
||||
private:
|
||||
void SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
|
||||
ComPtr<ID3D12GraphicsCommandList> mCommandList;
|
||||
};
|
||||
|
|
|
@ -494,8 +494,9 @@ namespace dawn_native { namespace d3d12 {
|
|||
if (GetFormat().isRenderable) {
|
||||
if (GetFormat().HasDepthOrStencil()) {
|
||||
TransitionUsageNow(commandList, D3D12_RESOURCE_STATE_DEPTH_WRITE);
|
||||
DescriptorHeapHandle dsvHeap =
|
||||
descriptorHeapAllocator->AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1);
|
||||
DescriptorHeapHandle dsvHeap;
|
||||
DAWN_TRY_ASSIGN(dsvHeap, descriptorHeapAllocator->AllocateCPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1));
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = dsvHeap.GetCPUHandle(0);
|
||||
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = GetDSVDescriptor(baseMipLevel);
|
||||
device->GetD3D12Device()->CreateDepthStencilView(mResource.Get(), &dsvDesc,
|
||||
|
@ -513,8 +514,9 @@ namespace dawn_native { namespace d3d12 {
|
|||
nullptr);
|
||||
} else {
|
||||
TransitionUsageNow(commandList, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
DescriptorHeapHandle rtvHeap =
|
||||
descriptorHeapAllocator->AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1);
|
||||
DescriptorHeapHandle rtvHeap;
|
||||
DAWN_TRY_ASSIGN(rtvHeap, descriptorHeapAllocator->AllocateCPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1));
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = rtvHeap.GetCPUHandle(0);
|
||||
const float clearColorRGBA[4] = {clearColor, clearColor, clearColor, clearColor};
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace dawn_native { namespace metal {
|
|||
Queue(Device* device);
|
||||
|
||||
private:
|
||||
void SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
};
|
||||
|
||||
}} // namespace dawn_native::metal
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace dawn_native { namespace metal {
|
|||
Queue::Queue(Device* device) : QueueBase(device) {
|
||||
}
|
||||
|
||||
void Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
|
||||
MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
device->Tick();
|
||||
id<MTLCommandBuffer> commandBuffer = device->GetPendingCommandBuffer();
|
||||
|
@ -37,6 +37,7 @@ namespace dawn_native { namespace metal {
|
|||
"CommandBufferMTL::FillCommands");
|
||||
|
||||
device->SubmitPendingCommandBuffer();
|
||||
return {};
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::metal
|
||||
|
|
|
@ -318,8 +318,9 @@ namespace dawn_native { namespace null {
|
|||
Queue::~Queue() {
|
||||
}
|
||||
|
||||
void Queue::SubmitImpl(uint32_t, CommandBufferBase* const*) {
|
||||
MaybeError Queue::SubmitImpl(uint32_t, CommandBufferBase* const*) {
|
||||
ToBackend(GetDevice())->SubmitPendingOperations();
|
||||
return {};
|
||||
}
|
||||
|
||||
// SwapChain
|
||||
|
|
|
@ -191,7 +191,7 @@ namespace dawn_native { namespace null {
|
|||
~Queue();
|
||||
|
||||
private:
|
||||
void SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
};
|
||||
|
||||
class SwapChain : public SwapChainBase {
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace dawn_native { namespace opengl {
|
|||
Queue::Queue(Device* device) : QueueBase(device) {
|
||||
}
|
||||
|
||||
void Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
|
||||
MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
for (uint32_t i = 0; i < commandCount; ++i) {
|
||||
|
@ -30,6 +30,7 @@ namespace dawn_native { namespace opengl {
|
|||
}
|
||||
|
||||
device->SubmitFenceSync();
|
||||
return {};
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace dawn_native { namespace opengl {
|
|||
Queue(Device* device);
|
||||
|
||||
private:
|
||||
void SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
};
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace dawn_native { namespace vulkan {
|
|||
Queue::~Queue() {
|
||||
}
|
||||
|
||||
void Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
|
||||
MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
device->Tick();
|
||||
|
@ -37,6 +37,7 @@ namespace dawn_native { namespace vulkan {
|
|||
}
|
||||
|
||||
device->SubmitPendingCommands();
|
||||
return {};
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::vulkan
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace dawn_native { namespace vulkan {
|
|||
~Queue();
|
||||
|
||||
private:
|
||||
void SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
|
||||
};
|
||||
|
||||
}} // namespace dawn_native::vulkan
|
||||
|
|
Loading…
Reference in New Issue