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>
diff --git a/src/dawn_native/Queue.cpp b/src/dawn_native/Queue.cpp
index d3b2455..f13079a 100644
--- a/src/dawn_native/Queue.cpp
+++ b/src/dawn_native/Queue.cpp
@@ -39,7 +39,9 @@
}
ASSERT(!IsError());
- SubmitImpl(commandCount, commands);
+ if (device->ConsumedError(SubmitImpl(commandCount, commands))) {
+ return;
+ }
device->GetErrorScopeTracker()->TrackUntilLastSubmitComplete(
device->GetCurrentErrorScope());
}
diff --git a/src/dawn_native/Queue.h b/src/dawn_native/Queue.h
index 7b1031e..5d94b3b 100644
--- a/src/dawn_native/Queue.h
+++ b/src/dawn_native/Queue.h
@@ -33,7 +33,8 @@
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);
diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
index 951911e..5fbb778 100644
--- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp
+++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
@@ -82,7 +82,7 @@
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 @@
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 @@
ASSERT(cbvSrvUavDescriptorIndex == mCbvSrvUavDescriptorHeapSize);
ASSERT(samplerDescriptorIndex == mSamplerDescriptorHeapSize);
+
+ return {};
}
// This function must only be called before calling AllocateDescriptorHeaps().
@@ -281,16 +286,19 @@
}
}
- 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,11 +453,11 @@
D3D12_INDEX_BUFFER_VIEW mD3D12BufferView = {};
};
- void AllocateAndSetDescriptorHeaps(Device* device,
- BindGroupStateTracker* bindingTracker,
- RenderPassDescriptorHeapTracker* renderPassTracker,
- CommandIterator* commands,
- uint32_t indexInSubmit) {
+ MaybeError AllocateAndSetDescriptorHeaps(Device* device,
+ BindGroupStateTracker* bindingTracker,
+ RenderPassDescriptorHeapTracker* renderPassTracker,
+ CommandIterator* commands,
+ uint32_t indexInSubmit) {
{
Command type;
@@ -495,8 +503,9 @@
commands->Reset();
}
- renderPassTracker->AllocateRTVAndDSVHeaps();
- bindingTracker->AllocateDescriptorHeaps(device);
+ DAWN_TRY(renderPassTracker->AllocateRTVAndDSVHeaps());
+ DAWN_TRY(bindingTracker->AllocateDescriptorHeaps(device));
+ return {};
}
void ResolveMultisampledRenderPass(ComPtr<ID3D12GraphicsCommandList> commandList,
@@ -542,8 +551,8 @@
FreeCommands(&mCommands);
}
- void CommandBuffer::RecordCommands(ComPtr<ID3D12GraphicsCommandList> commandList,
- uint32_t indexInSubmit) {
+ MaybeError CommandBuffer::RecordCommands(ComPtr<ID3D12GraphicsCommandList> commandList,
+ uint32_t indexInSubmit) {
Device* device = ToBackend(GetDevice());
BindGroupStateTracker bindingTracker(device);
RenderPassDescriptorHeapTracker renderPassTracker(device);
@@ -553,8 +562,8 @@
// 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 @@
}
DAWN_ASSERT(renderPassTracker.IsHeapAllocationCompleted());
+ return {};
}
void CommandBuffer::RecordComputePass(ComPtr<ID3D12GraphicsCommandList> commandList,
diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.h b/src/dawn_native/d3d12/CommandBufferD3D12.h
index 78c5630..64a9a86 100644
--- a/src/dawn_native/d3d12/CommandBufferD3D12.h
+++ b/src/dawn_native/d3d12/CommandBufferD3D12.h
@@ -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 @@
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,
diff --git a/src/dawn_native/d3d12/DescriptorHeapAllocator.cpp b/src/dawn_native/d3d12/DescriptorHeapAllocator.cpp
index 75d188d..3f28e5a 100644
--- a/src/dawn_native/d3d12/DescriptorHeapAllocator.cpp
+++ b/src/dawn_native/d3d12/DescriptorHeapAllocator.cpp
@@ -61,11 +61,12 @@
} {
}
- DescriptorHeapHandle DescriptorHeapAllocator::Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type,
- uint32_t count,
- uint32_t allocationSize,
- DescriptorHeapInfo* heapInfo,
- D3D12_DESCRIPTOR_HEAP_FLAGS flags) {
+ ResultOrError<DescriptorHeapHandle> DescriptorHeapAllocator::Allocate(
+ D3D12_DESCRIPTOR_HEAP_TYPE type,
+ uint32_t count,
+ uint32_t allocationSize,
+ DescriptorHeapInfo* heapInfo,
+ D3D12_DESCRIPTOR_HEAP_FLAGS flags) {
// TODO(enga@google.com): This is just a linear allocator so the heap will quickly run out
// of space causing a new one to be allocated We should reuse heap subranges that have been
// released
@@ -94,8 +95,10 @@
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,14 +108,16 @@
return handle;
}
- DescriptorHeapHandle DescriptorHeapAllocator::AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type,
- uint32_t count) {
+ 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,
- uint32_t count) {
+ 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);
unsigned int heapSize =
diff --git a/src/dawn_native/d3d12/DescriptorHeapAllocator.h b/src/dawn_native/d3d12/DescriptorHeapAllocator.h
index f1ba502..d98b7a8f 100644
--- a/src/dawn_native/d3d12/DescriptorHeapAllocator.h
+++ b/src/dawn_native/d3d12/DescriptorHeapAllocator.h
@@ -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 @@
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,11 +67,11 @@
using DescriptorHeapInfo = std::pair<ComPtr<ID3D12DescriptorHeap>, AllocationInfo>;
- DescriptorHeapHandle Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type,
- uint32_t count,
- uint32_t allocationSize,
- DescriptorHeapInfo* heapInfo,
- D3D12_DESCRIPTOR_HEAP_FLAGS flags);
+ ResultOrError<DescriptorHeapHandle> Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type,
+ uint32_t count,
+ uint32_t allocationSize,
+ DescriptorHeapInfo* heapInfo,
+ D3D12_DESCRIPTOR_HEAP_FLAGS flags);
void Release(DescriptorHeapHandle handle);
Device* mDevice;
diff --git a/src/dawn_native/d3d12/QueueD3D12.cpp b/src/dawn_native/d3d12/QueueD3D12.cpp
index 72c0acc..c9d24b15 100644
--- a/src/dawn_native/d3d12/QueueD3D12.cpp
+++ b/src/dawn_native/d3d12/QueueD3D12.cpp
@@ -22,20 +22,21 @@
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
diff --git a/src/dawn_native/d3d12/QueueD3D12.h b/src/dawn_native/d3d12/QueueD3D12.h
index 117d6ee..9a11f21 100644
--- a/src/dawn_native/d3d12/QueueD3D12.h
+++ b/src/dawn_native/d3d12/QueueD3D12.h
@@ -29,7 +29,7 @@
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;
};
diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp
index e92345c..c18bac9 100644
--- a/src/dawn_native/d3d12/TextureD3D12.cpp
+++ b/src/dawn_native/d3d12/TextureD3D12.cpp
@@ -494,8 +494,9 @@
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 @@
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};
diff --git a/src/dawn_native/metal/QueueMTL.h b/src/dawn_native/metal/QueueMTL.h
index 79bafb2..d9869de 100644
--- a/src/dawn_native/metal/QueueMTL.h
+++ b/src/dawn_native/metal/QueueMTL.h
@@ -27,7 +27,7 @@
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
diff --git a/src/dawn_native/metal/QueueMTL.mm b/src/dawn_native/metal/QueueMTL.mm
index 084c9ef..d815c6e 100644
--- a/src/dawn_native/metal/QueueMTL.mm
+++ b/src/dawn_native/metal/QueueMTL.mm
@@ -23,7 +23,7 @@
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 @@
"CommandBufferMTL::FillCommands");
device->SubmitPendingCommandBuffer();
+ return {};
}
}} // namespace dawn_native::metal
diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp
index 303445a..07c296f 100644
--- a/src/dawn_native/null/DeviceNull.cpp
+++ b/src/dawn_native/null/DeviceNull.cpp
@@ -318,8 +318,9 @@
Queue::~Queue() {
}
- void Queue::SubmitImpl(uint32_t, CommandBufferBase* const*) {
+ MaybeError Queue::SubmitImpl(uint32_t, CommandBufferBase* const*) {
ToBackend(GetDevice())->SubmitPendingOperations();
+ return {};
}
// SwapChain
diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h
index 232dff8..f0664d6 100644
--- a/src/dawn_native/null/DeviceNull.h
+++ b/src/dawn_native/null/DeviceNull.h
@@ -191,7 +191,7 @@
~Queue();
private:
- void SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
+ MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
};
class SwapChain : public SwapChainBase {
diff --git a/src/dawn_native/opengl/QueueGL.cpp b/src/dawn_native/opengl/QueueGL.cpp
index 241854a..fde06c8 100644
--- a/src/dawn_native/opengl/QueueGL.cpp
+++ b/src/dawn_native/opengl/QueueGL.cpp
@@ -22,7 +22,7 @@
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 @@
}
device->SubmitFenceSync();
+ return {};
}
}} // namespace dawn_native::opengl
diff --git a/src/dawn_native/opengl/QueueGL.h b/src/dawn_native/opengl/QueueGL.h
index 687d7a4..c18486c 100644
--- a/src/dawn_native/opengl/QueueGL.h
+++ b/src/dawn_native/opengl/QueueGL.h
@@ -27,7 +27,7 @@
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
diff --git a/src/dawn_native/vulkan/QueueVk.cpp b/src/dawn_native/vulkan/QueueVk.cpp
index c268bcd..83a765d 100644
--- a/src/dawn_native/vulkan/QueueVk.cpp
+++ b/src/dawn_native/vulkan/QueueVk.cpp
@@ -26,7 +26,7 @@
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 @@
}
device->SubmitPendingCommands();
+ return {};
}
}} // namespace dawn_native::vulkan
diff --git a/src/dawn_native/vulkan/QueueVk.h b/src/dawn_native/vulkan/QueueVk.h
index 2477c5a..ff77ffb 100644
--- a/src/dawn_native/vulkan/QueueVk.h
+++ b/src/dawn_native/vulkan/QueueVk.h
@@ -28,7 +28,7 @@
~Queue();
private:
- void SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
+ MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
};
}} // namespace dawn_native::vulkan