From 9d053bf020faf07227c9040a043f3172fd3c6589 Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Mon, 13 Feb 2023 18:08:19 -0800 Subject: [PATCH] Do not re-attempt if allocation failure is fatal. --- src/gpgmm/d3d12/ErrorD3D12.h | 14 ++++++++++ src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 6 ++--- src/gpgmm/vk/ErrorVk.h | 30 ++++++++++++++++------ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/gpgmm/d3d12/ErrorD3D12.h b/src/gpgmm/d3d12/ErrorD3D12.h index 7c4896f9e..8187dc8c4 100644 --- a/src/gpgmm/d3d12/ErrorD3D12.h +++ b/src/gpgmm/d3d12/ErrorD3D12.h @@ -14,6 +14,7 @@ #ifndef GPGMM_D3D12_ERRORD3D12_H_ #define GPGMM_D3D12_ERRORD3D12_H_ +#include "gpgmm/common/Error.h" #include "gpgmm/d3d12/d3d12_platform.h" #include "gpgmm/utils/Compiler.h" #include "gpgmm/utils/Log.h" @@ -53,6 +54,19 @@ namespace gpgmm::d3d12 { for (;;) \ break +// Same as ReturnIfSucceeded but also returns if error is lethal. +// Non-internal errors are always fatal and should not run re-attempt logic. +#define ReturnIfSucceededOrFatal(expr) \ + { \ + HRESULT hr = expr; \ + if (GPGMM_LIKELY(SUCCEEDED(hr)) || \ + GPGMM_UNLIKELY(hr != static_cast(kInternalFailureResult))) { \ + return hr; \ + } \ + } \ + for (;;) \ + break + #define AssertIfFailed(expr) ASSERT(SUCCEEDED(expr)); #define AssertIfSucceded(expr) ASSERT(FAILED(expr)); diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index dd38ec112..61ec87424 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -1101,7 +1101,7 @@ namespace gpgmm::d3d12 { // CreateResource(). request.AlwaysPrefetch = false; - ReturnIfSucceeded(TryAllocateResource( + ReturnIfSucceededOrFatal(TryAllocateResource( mDevice, allocator, request, [&](const auto& subAllocation) -> HRESULT { // Committed resource implicitly creates a resource heap which can be // used for sub-allocation. @@ -1137,7 +1137,7 @@ namespace gpgmm::d3d12 { request.Alignment = resourceInfo.Alignment; - ReturnIfSucceeded(TryAllocateResource( + ReturnIfSucceededOrFatal(TryAllocateResource( mDevice, allocator, request, [&](const auto& subAllocation) -> HRESULT { // Resource is placed at an offset corresponding to the allocation offset. // Each allocation maps to a disjoint (physical) address range so no physical @@ -1180,7 +1180,7 @@ namespace gpgmm::d3d12 { request.Alignment = allocator->GetMemoryAlignment(); - ReturnIfSucceeded(TryAllocateResource( + ReturnIfSucceededOrFatal(TryAllocateResource( mDevice, allocator, request, [&](const auto& allocation) -> HRESULT { Heap* resourceHeap = static_cast(allocation.GetMemory()); ComPtr placedResource; diff --git a/src/gpgmm/vk/ErrorVk.h b/src/gpgmm/vk/ErrorVk.h index c249aa956..876ce4676 100644 --- a/src/gpgmm/vk/ErrorVk.h +++ b/src/gpgmm/vk/ErrorVk.h @@ -14,6 +14,7 @@ #ifndef GPGMM_VK_ERRORVK_H_ #define GPGMM_VK_ERRORVK_H_ +#include "gpgmm/common/Error.h" #include "gpgmm/vk/vk_platform.h" namespace gpgmm::vk { @@ -28,14 +29,27 @@ namespace gpgmm::vk { for (;;) \ break -#define ReturnIfSuccess(expr) \ - { \ - VkResult result = expr; \ - if (result == VK_SUCCESS) { \ - return result; \ - } \ - } \ - for (;;) \ +#define ReturnIfSuccess(expr) \ + { \ + VkResult result = expr; \ + if (GPGMM_LIKELY(result == VK_SUCCESS)) { \ + return result; \ + } \ + } \ + for (;;) \ + break + +// Same as ReturnIfSuccess but also returns if error is lethal. +// Non-internal errors are always fatal and should not run re-attempt logic. +#define ReturnIfSuccessOrFatal(expr) \ + { \ + VkResult result = expr; \ + if (GPGMM_LIKELY(result == VK_SUCCESS) || \ + GPGMM_UNLIKELY(hr != static_cast(kInternalFailureResult))) { \ + return result; \ + } \ + } \ + for (;;) \ break } // namespace gpgmm::vk