diff --git a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp index f9c9316f67..f52c598e4f 100644 --- a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp +++ b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp @@ -258,7 +258,13 @@ namespace dawn_native { namespace d3d12 { resourceInfo = mDevice->GetD3D12Device()->GetResourceAllocationInfo(0, 1, &resourceDescriptor); } - if (resourceInfo.SizeInBytes == 0) { + + // If d3d tells us the resource size is invalid, treat the error as OOM. + // Otherwise, creating the resource could cause a device loss (too large). + // This is because NextPowerOfTwo(UINT64_MAX) overflows and proceeds to + // incorrectly allocate a mismatched size. + if (resourceInfo.SizeInBytes == 0 || + resourceInfo.SizeInBytes == std::numeric_limits::max()) { return DAWN_OUT_OF_MEMORY_ERROR("Resource allocation size was invalid."); } @@ -311,11 +317,14 @@ namespace dawn_native { namespace d3d12 { heapProperties.CreationNodeMask = 0; heapProperties.VisibleNodeMask = 0; - // If d3d tells us the resource is "zero-sized", the size is invalid and may cause a device - // lost (too large for driver). Instead, treat the error as a OOM. + // If d3d tells us the resource size is invalid, treat the error as OOM. + // Otherwise, creating the resource could cause a device loss (too large). + // This is because NextPowerOfTwo(UINT64_MAX) overflows and proceeds to + // incorrectly allocate a mismatched size. D3D12_RESOURCE_ALLOCATION_INFO resourceInfo = mDevice->GetD3D12Device()->GetResourceAllocationInfo(0, 1, &resourceDescriptor); - if (resourceInfo.SizeInBytes == 0) { + if (resourceInfo.SizeInBytes == 0 || + resourceInfo.SizeInBytes == std::numeric_limits::max()) { return DAWN_OUT_OF_MEMORY_ERROR("Resource allocation size was invalid."); }