diff --git a/src/dawn_native/Queue.cpp b/src/dawn_native/Queue.cpp index d3b2455aee..f13079a137 100644 --- a/src/dawn_native/Queue.cpp +++ b/src/dawn_native/Queue.cpp @@ -39,7 +39,9 @@ namespace dawn_native { } 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 7b1031eab5..5d94b3ba9b 100644 --- a/src/dawn_native/Queue.h +++ b/src/dawn_native/Queue.h @@ -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); diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index 951911e6ae..5fbb778968 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -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 as @@ -445,11 +453,11 @@ namespace dawn_native { namespace d3d12 { 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 @@ 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 commandList, @@ -542,8 +551,8 @@ namespace dawn_native { namespace d3d12 { FreeCommands(&mCommands); } - void CommandBuffer::RecordCommands(ComPtr commandList, - uint32_t indexInSubmit) { + MaybeError CommandBuffer::RecordCommands(ComPtr commandList, + uint32_t indexInSubmit) { Device* device = ToBackend(GetDevice()); BindGroupStateTracker bindingTracker(device); RenderPassDescriptorHeapTracker renderPassTracker(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 commandList, diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.h b/src/dawn_native/d3d12/CommandBufferD3D12.h index 78c56300ff..64a9a86cbd 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 @@ namespace dawn_native { namespace d3d12 { CommandBuffer(CommandEncoderBase* encoder, const CommandBufferDescriptor* descriptor); ~CommandBuffer(); - void RecordCommands(ComPtr commandList, uint32_t indexInSubmit); + MaybeError RecordCommands(ComPtr commandList, + uint32_t indexInSubmit); private: void RecordComputePass(ComPtr commandList, diff --git a/src/dawn_native/d3d12/DescriptorHeapAllocator.cpp b/src/dawn_native/d3d12/DescriptorHeapAllocator.cpp index 75d188db01..3f28e5a201 100644 --- a/src/dawn_native/d3d12/DescriptorHeapAllocator.cpp +++ b/src/dawn_native/d3d12/DescriptorHeapAllocator.cpp @@ -61,11 +61,12 @@ namespace dawn_native { namespace d3d12 { } { } - DescriptorHeapHandle DescriptorHeapAllocator::Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type, - uint32_t count, - uint32_t allocationSize, - DescriptorHeapInfo* heapInfo, - D3D12_DESCRIPTOR_HEAP_FLAGS flags) { + ResultOrError 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 @@ namespace dawn_native { namespace d3d12 { heapDescriptor.Flags = flags; heapDescriptor.NodeMask = 0; ComPtr 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 @@ namespace dawn_native { namespace d3d12 { return handle; } - DescriptorHeapHandle DescriptorHeapAllocator::AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, - uint32_t count) { + ResultOrError 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 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 f1ba5029f8..d98b7a8fe3 100644 --- a/src/dawn_native/d3d12/DescriptorHeapAllocator.h +++ b/src/dawn_native/d3d12/DescriptorHeapAllocator.h @@ -21,6 +21,8 @@ #include #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 AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, + uint32_t count); + ResultOrError AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, + uint32_t count); void Tick(uint64_t lastCompletedSerial); private: @@ -63,11 +67,11 @@ namespace dawn_native { namespace d3d12 { using DescriptorHeapInfo = std::pair, AllocationInfo>; - DescriptorHeapHandle Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type, - uint32_t count, - uint32_t allocationSize, - DescriptorHeapInfo* heapInfo, - D3D12_DESCRIPTOR_HEAP_FLAGS flags); + ResultOrError 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 72c0acc829..c9d24b1511 100644 --- a/src/dawn_native/d3d12/QueueD3D12.cpp +++ b/src/dawn_native/d3d12/QueueD3D12.cpp @@ -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 diff --git a/src/dawn_native/d3d12/QueueD3D12.h b/src/dawn_native/d3d12/QueueD3D12.h index 117d6eeb97..9a11f211c7 100644 --- a/src/dawn_native/d3d12/QueueD3D12.h +++ b/src/dawn_native/d3d12/QueueD3D12.h @@ -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 mCommandList; }; diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index e92345cda0..c18bac9433 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -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}; diff --git a/src/dawn_native/metal/QueueMTL.h b/src/dawn_native/metal/QueueMTL.h index 79bafb2339..d9869dec70 100644 --- a/src/dawn_native/metal/QueueMTL.h +++ b/src/dawn_native/metal/QueueMTL.h @@ -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 diff --git a/src/dawn_native/metal/QueueMTL.mm b/src/dawn_native/metal/QueueMTL.mm index 084c9ef05b..d815c6e56c 100644 --- a/src/dawn_native/metal/QueueMTL.mm +++ b/src/dawn_native/metal/QueueMTL.mm @@ -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 commandBuffer = device->GetPendingCommandBuffer(); @@ -37,6 +37,7 @@ namespace dawn_native { namespace metal { "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 303445a06e..07c296fb42 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -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 diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index 232dff82ba..f0664d647a 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -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 { diff --git a/src/dawn_native/opengl/QueueGL.cpp b/src/dawn_native/opengl/QueueGL.cpp index 241854a6fb..fde06c853a 100644 --- a/src/dawn_native/opengl/QueueGL.cpp +++ b/src/dawn_native/opengl/QueueGL.cpp @@ -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 diff --git a/src/dawn_native/opengl/QueueGL.h b/src/dawn_native/opengl/QueueGL.h index 687d7a4491..c18486ce2a 100644 --- a/src/dawn_native/opengl/QueueGL.h +++ b/src/dawn_native/opengl/QueueGL.h @@ -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 diff --git a/src/dawn_native/vulkan/QueueVk.cpp b/src/dawn_native/vulkan/QueueVk.cpp index c268bcd3d4..83a765d76d 100644 --- a/src/dawn_native/vulkan/QueueVk.cpp +++ b/src/dawn_native/vulkan/QueueVk.cpp @@ -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 diff --git a/src/dawn_native/vulkan/QueueVk.h b/src/dawn_native/vulkan/QueueVk.h index 2477c5ae46..ff77ffba13 100644 --- a/src/dawn_native/vulkan/QueueVk.h +++ b/src/dawn_native/vulkan/QueueVk.h @@ -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