From bd696e91d24987e304c29f6cbe5733a3f7a6cec7 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Thu, 20 Apr 2023 17:27:17 +0000 Subject: [PATCH] d3d11: fix several OOM end2end test on trybot BufferTests.CreateBufferOOM/D3D11_Intel_R_UHD_Graphics_630 fails on trybots due to buffer size overflow UINT which is used as size for create ID3D11Buffer. This CL fixes above issue and also uses CheckOutOfMemoryHRESULT() to handle hresult from texture and buffer creation. It makes OOM an allowed error. Bug: dawn:1705 Change-Id: I2c4a4841cac15934fe83b7f7d6e568e9f3c8d210 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128280 Reviewed-by: Austin Eng Auto-Submit: Peng Huang Kokoro: Kokoro Commit-Queue: Peng Huang --- src/dawn/native/d3d11/BufferD3D11.cpp | 11 ++++++----- src/dawn/native/d3d11/TextureD3D11.cpp | 18 +++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/dawn/native/d3d11/BufferD3D11.cpp b/src/dawn/native/d3d11/BufferD3D11.cpp index bbeb2cbefd..e6bf540137 100644 --- a/src/dawn/native/d3d11/BufferD3D11.cpp +++ b/src/dawn/native/d3d11/BufferD3D11.cpp @@ -162,7 +162,8 @@ MaybeError Buffer::Initialize(bool mappedAtCreation) { // Allocate at least 4 bytes so clamped accesses are always in bounds. uint64_t size = std::max(GetSize(), uint64_t(4u)); size_t alignment = D3D11BufferSizeAlignment(GetUsage()); - if (size > std::numeric_limits::max() - alignment) { + // Check for overflow, bufferDescriptor.ByteWidth is a UINT. + if (size > std::numeric_limits::max() - alignment) { // Alignment would overlow. return DAWN_OUT_OF_MEMORY_ERROR("Buffer allocation is too large"); } @@ -177,10 +178,10 @@ MaybeError Buffer::Initialize(bool mappedAtCreation) { bufferDescriptor.MiscFlags = D3D11BufferMiscFlags(GetUsage()); bufferDescriptor.StructureByteStride = 0; - DAWN_TRY(CheckHRESULT(ToBackend(GetDevice()) - ->GetD3D11Device() - ->CreateBuffer(&bufferDescriptor, nullptr, &mD3d11Buffer), - "ID3D11Device::CreateBuffer")); + DAWN_TRY(CheckOutOfMemoryHRESULT(ToBackend(GetDevice()) + ->GetD3D11Device() + ->CreateBuffer(&bufferDescriptor, nullptr, &mD3d11Buffer), + "ID3D11Device::CreateBuffer")); SetLabelImpl(); return {}; diff --git a/src/dawn/native/d3d11/TextureD3D11.cpp b/src/dawn/native/d3d11/TextureD3D11.cpp index 6f7a85a916..ecdba76e5c 100644 --- a/src/dawn/native/d3d11/TextureD3D11.cpp +++ b/src/dawn/native/d3d11/TextureD3D11.cpp @@ -85,9 +85,9 @@ MaybeError Texture::InitializeAsInternalTexture() { textureDescriptor.CPUAccessFlags = 0; textureDescriptor.MiscFlags = 0; ComPtr d3d11Texture1D; - DAWN_TRY(CheckHRESULT(device->GetD3D11Device()->CreateTexture1D( - &textureDescriptor, nullptr, &d3d11Texture1D), - "D3D11 create texture1d")); + DAWN_TRY(CheckOutOfMemoryHRESULT(device->GetD3D11Device()->CreateTexture1D( + &textureDescriptor, nullptr, &d3d11Texture1D), + "D3D11 create texture1d")); mD3d11Resource = std::move(d3d11Texture1D); break; } @@ -109,9 +109,9 @@ MaybeError Texture::InitializeAsInternalTexture() { textureDescriptor.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE; } ComPtr d3d11Texture2D; - DAWN_TRY(CheckHRESULT(device->GetD3D11Device()->CreateTexture2D( - &textureDescriptor, nullptr, &d3d11Texture2D), - "D3D11 create texture2d")); + DAWN_TRY(CheckOutOfMemoryHRESULT(device->GetD3D11Device()->CreateTexture2D( + &textureDescriptor, nullptr, &d3d11Texture2D), + "D3D11 create texture2d")); mD3d11Resource = std::move(d3d11Texture2D); break; } @@ -127,9 +127,9 @@ MaybeError Texture::InitializeAsInternalTexture() { textureDescriptor.CPUAccessFlags = 0; textureDescriptor.MiscFlags = 0; ComPtr d3d11Texture3D; - DAWN_TRY(CheckHRESULT(device->GetD3D11Device()->CreateTexture3D( - &textureDescriptor, nullptr, &d3d11Texture3D), - "D3D11 create texture3d")); + DAWN_TRY(CheckOutOfMemoryHRESULT(device->GetD3D11Device()->CreateTexture3D( + &textureDescriptor, nullptr, &d3d11Texture3D), + "D3D11 create texture3d")); mD3d11Resource = std::move(d3d11Texture3D); break; }