Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/gpgmm/d3d12/ErrorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<HRESULT>(kInternalFailureResult))) { \
return hr; \
} \
} \
for (;;) \
break

#define AssertIfFailed(expr) ASSERT(SUCCEEDED(expr));
#define AssertIfSucceded(expr) ASSERT(FAILED(expr));

Expand Down
6 changes: 3 additions & 3 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Heap*>(allocation.GetMemory());
ComPtr<ID3D12Resource> placedResource;
Expand Down
30 changes: 22 additions & 8 deletions src/gpgmm/vk/ErrorVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<HRESULT>(kInternalFailureResult))) { \
return result; \
} \
} \
for (;;) \
break

} // namespace gpgmm::vk
Expand Down