D3D12: Use CheckHRESULT for allocator errors.

BUG=dawn:27

Change-Id: If28d1cbafcbdac29bafac0fb0e846208634ece33
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12521
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Bryan Bernhart 2019-10-28 12:59:36 +00:00 committed by Commit Bot service account
parent f6281a5530
commit 9cf62efda9
6 changed files with 30 additions and 24 deletions

View File

@ -26,4 +26,11 @@ namespace dawn_native { namespace d3d12 {
return DAWN_DEVICE_LOST_ERROR(message); return DAWN_DEVICE_LOST_ERROR(message);
} }
MaybeError CheckOutOfMemoryHRESULT(HRESULT result, const char* context) {
if (result == E_OUTOFMEMORY) {
return DAWN_OUT_OF_MEMORY_ERROR(context);
}
return CheckHRESULT(result, context);
}
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12

View File

@ -23,6 +23,9 @@ namespace dawn_native { namespace d3d12 {
// Returns a success only if result of HResult is success // Returns a success only if result of HResult is success
MaybeError CheckHRESULT(HRESULT result, const char* context); MaybeError CheckHRESULT(HRESULT result, const char* context);
// Uses CheckRESULT but returns OOM specific error when recoverable.
MaybeError CheckOutOfMemoryHRESULT(HRESULT result, const char* context);
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12
#endif // DAWNNATIVE_D3D12_D3D12ERROR_H_ #endif // DAWNNATIVE_D3D12_D3D12ERROR_H_

View File

@ -15,6 +15,7 @@
#include "dawn_native/d3d12/DescriptorHeapAllocator.h" #include "dawn_native/d3d12/DescriptorHeapAllocator.h"
#include "common/Assert.h" #include "common/Assert.h"
#include "dawn_native/d3d12/D3D12Error.h"
#include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
@ -83,10 +84,9 @@ namespace dawn_native { namespace d3d12 {
heapDescriptor.Flags = flags; heapDescriptor.Flags = flags;
heapDescriptor.NodeMask = 0; heapDescriptor.NodeMask = 0;
ComPtr<ID3D12DescriptorHeap> heap; ComPtr<ID3D12DescriptorHeap> heap;
if (FAILED(mDevice->GetD3D12Device()->CreateDescriptorHeap(&heapDescriptor, DAWN_TRY(CheckHRESULT(
IID_PPV_ARGS(&heap)))) { mDevice->GetD3D12Device()->CreateDescriptorHeap(&heapDescriptor, IID_PPV_ARGS(&heap)),
return DAWN_OUT_OF_MEMORY_ERROR("Unable to allocate heap"); "ID3D12Device::CreateDescriptorHeap"));
}
mDevice->ReferenceUntilUnused(heap); mDevice->ReferenceUntilUnused(heap);

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include "dawn_native/d3d12/HeapAllocatorD3D12.h" #include "dawn_native/d3d12/HeapAllocatorD3D12.h"
#include "dawn_native/d3d12/D3D12Error.h"
#include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h"
#include "dawn_native/d3d12/HeapD3D12.h" #include "dawn_native/d3d12/HeapD3D12.h"
@ -41,9 +42,9 @@ namespace dawn_native { namespace d3d12 {
heapDesc.Flags = mHeapFlags; heapDesc.Flags = mHeapFlags;
ComPtr<ID3D12Heap> heap; ComPtr<ID3D12Heap> heap;
if (FAILED(mDevice->GetD3D12Device()->CreateHeap(&heapDesc, IID_PPV_ARGS(&heap)))) { DAWN_TRY(CheckOutOfMemoryHRESULT(
return DAWN_OUT_OF_MEMORY_ERROR("Unable to allocate heap"); mDevice->GetD3D12Device()->CreateHeap(&heapDesc, IID_PPV_ARGS(&heap)),
} "ID3D12Device::CreateHeap"));
return {std::make_unique<Heap>(std::move(heap))}; return {std::make_unique<Heap>(std::move(heap))};
} }

View File

@ -14,6 +14,7 @@
#include "dawn_native/d3d12/ResourceAllocatorManagerD3D12.h" #include "dawn_native/d3d12/ResourceAllocatorManagerD3D12.h"
#include "dawn_native/d3d12/D3D12Error.h"
#include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h"
#include "dawn_native/d3d12/HeapAllocatorD3D12.h" #include "dawn_native/d3d12/HeapAllocatorD3D12.h"
#include "dawn_native/d3d12/HeapD3D12.h" #include "dawn_native/d3d12/HeapD3D12.h"
@ -188,13 +189,10 @@ namespace dawn_native { namespace d3d12 {
// barrier). // barrier).
// https://docs.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device-createplacedresource // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device-createplacedresource
ComPtr<ID3D12Resource> placedResource; ComPtr<ID3D12Resource> placedResource;
if (FAILED(mDevice->GetD3D12Device()->CreatePlacedResource( DAWN_TRY(CheckOutOfMemoryHRESULT(mDevice->GetD3D12Device()->CreatePlacedResource(
heap, allocation.GetOffset(), &resourceDescriptor, initialUsage, nullptr, heap, allocation.GetOffset(), &resourceDescriptor,
IID_PPV_ARGS(&placedResource)))) { initialUsage, nullptr, IID_PPV_ARGS(&placedResource)),
// Note: Heap must already exist before the resource is created. If CreatePlacedResource "ID3D12Device::CreatePlacedResource"));
// fails, it's unlikely to be OOM.
return DAWN_DEVICE_LOST_ERROR("Unable to allocate resource");
}
return ResourceHeapAllocation{allocation.GetInfo(), allocation.GetOffset(), return ResourceHeapAllocation{allocation.GetInfo(), allocation.GetOffset(),
std::move(placedResource)}; std::move(placedResource)};
@ -214,11 +212,11 @@ namespace dawn_native { namespace d3d12 {
// Note: Heap flags are inferred by the resource descriptor and do not need to be explicitly // Note: Heap flags are inferred by the resource descriptor and do not need to be explicitly
// provided to CreateCommittedResource. // provided to CreateCommittedResource.
ComPtr<ID3D12Resource> committedResource; ComPtr<ID3D12Resource> committedResource;
if (FAILED(mDevice->GetD3D12Device()->CreateCommittedResource( DAWN_TRY(
&heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDescriptor, initialUsage, nullptr, CheckOutOfMemoryHRESULT(mDevice->GetD3D12Device()->CreateCommittedResource(
IID_PPV_ARGS(&committedResource)))) { &heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDescriptor,
return DAWN_OUT_OF_MEMORY_ERROR("Unable to allocate resource"); initialUsage, nullptr, IID_PPV_ARGS(&committedResource)),
} "ID3D12Device::CreateCommittedResource"));
AllocationInfo info; AllocationInfo info;
info.mMethod = AllocationMethod::kDirect; info.mMethod = AllocationMethod::kDirect;

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include "dawn_native/d3d12/StagingBufferD3D12.h" #include "dawn_native/d3d12/StagingBufferD3D12.h"
#include "dawn_native/d3d12/D3D12Error.h"
#include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h"
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
@ -39,11 +40,7 @@ namespace dawn_native { namespace d3d12 {
mDevice->AllocateMemory(D3D12_HEAP_TYPE_UPLOAD, resourceDescriptor, mDevice->AllocateMemory(D3D12_HEAP_TYPE_UPLOAD, resourceDescriptor,
D3D12_RESOURCE_STATE_GENERIC_READ)); D3D12_RESOURCE_STATE_GENERIC_READ));
if (FAILED(GetResource()->Map(0, nullptr, &mMappedPointer))) { return CheckHRESULT(GetResource()->Map(0, nullptr, &mMappedPointer), "ID3D12Resource::Map");
return DAWN_DEVICE_LOST_ERROR("Unable to map staging buffer.");
}
return {};
} }
StagingBuffer::~StagingBuffer() { StagingBuffer::~StagingBuffer() {