Check if allocation is valid before deallocating.

Ensure deallocate does not assert should allocation fail but still be used.

BUG=dawn:227

Change-Id: I5edd4c160bced7934970c5d59e541a3a8f7a8afb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11380
Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Bryan Bernhart 2019-09-19 20:40:12 +00:00 committed by Commit Bot service account
parent ae4dbeb178
commit bdd88a7dc1
4 changed files with 17 additions and 1 deletions

View File

@ -49,7 +49,6 @@ namespace dawn_native {
}
AllocationMethod ResourceMemoryAllocation::GetAllocationMethod() const {
ASSERT(mMethod != AllocationMethod::kInvalid);
return mMethod;
}

View File

@ -345,6 +345,9 @@ namespace dawn_native { namespace d3d12 {
}
void Device::DeallocateMemory(ResourceMemoryAllocation& allocation) {
if (allocation.GetAllocationMethod() == AllocationMethod::kInvalid) {
return;
}
CommittedResourceAllocator* allocator = nullptr;
D3D12_HEAP_PROPERTIES heapProp;
ToBackend(allocation.GetResourceHeap())

View File

@ -698,6 +698,9 @@ namespace dawn_native { namespace vulkan {
}
void Device::DeallocateMemory(ResourceMemoryAllocation& allocation) {
if (allocation.GetAllocationMethod() == AllocationMethod::kInvalid) {
return;
}
mResourceAllocator->Deallocate(allocation);
// Invalidate the underlying resource heap in case the client accidentally

View File

@ -627,6 +627,17 @@ TEST_P(CreateBufferMappedTests, CreateThenMapBeforeUnmapFailureAsync) {
EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0);
}
// Test that creating a very large buffers fails gracefully.
TEST_P(CreateBufferMappedTests, LargeBufferFails) {
// TODO(http://crbug.com/dawn/27): Missing support.
DAWN_SKIP_TEST_IF(IsMetal() || IsOpenGL());
dawn::BufferDescriptor descriptor;
descriptor.size = std::numeric_limits<uint64_t>::max();
descriptor.usage = dawn::BufferUsage::MapRead | dawn::BufferUsage::CopyDst;
ASSERT_DEVICE_ERROR(device.CreateBuffer(&descriptor));
}
DAWN_INSTANTIATE_TEST(CreateBufferMappedTests,
D3D12Backend,
MetalBackend,