diff --git a/src/dawn_native/vulkan/BufferVk.cpp b/src/dawn_native/vulkan/BufferVk.cpp index 15571c7c90..8f8b3aa2f0 100644 --- a/src/dawn_native/vulkan/BufferVk.cpp +++ b/src/dawn_native/vulkan/BufferVk.cpp @@ -123,6 +123,16 @@ namespace dawn_native { namespace vulkan { } MaybeError Buffer::Initialize() { + // Avoid passing ludicrously large sizes to drivers because it causes issues: drivers add + // some constants to the size passed and align it, but for values close to the maximum + // VkDeviceSize this can cause overflows and makes drivers crash or return bad sizes in the + // VkmemoryRequirements. See https://gitlab.khronos.org/vulkan/vulkan/issues/1904 + // Any size with one of two top bits of VkDeviceSize set is a HUGE allocation and we can + // safely return an OOM error. + if (GetSize() & (uint64_t(3) << uint64_t(62))) { + return DAWN_OUT_OF_MEMORY_ERROR("Buffer size is HUGE and could cause overflows"); + } + VkBufferCreateInfo createInfo; createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; createInfo.pNext = nullptr; diff --git a/src/tests/end2end/BufferTests.cpp b/src/tests/end2end/BufferTests.cpp index 09640fa080..93fe804ddf 100644 --- a/src/tests/end2end/BufferTests.cpp +++ b/src/tests/end2end/BufferTests.cpp @@ -733,11 +733,6 @@ TEST_P(CreateBufferMappedTests, LargeBufferFails) { // TODO(http://crbug.com/dawn/27): Missing support. DAWN_SKIP_TEST_IF(IsMetal() || IsOpenGL()); - // TODO(http://crbug.com/dawn/241): Fails on NVIDIA cards when Vulkan validation layers are - // enabled becuase the maximum size of a single allocation cannot be larger than or equal to - // 4G on some platforms. - DAWN_SKIP_TEST_IF(IsVulkan() && IsNvidia() && IsBackendValidationEnabled()); - wgpu::BufferDescriptor descriptor; descriptor.size = std::numeric_limits::max(); descriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;