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
23 changes: 11 additions & 12 deletions src/gpgmm/d3d12/CapsD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace gpgmm::d3d12 {

HRESULT SetMaxResourceSize(ID3D12Device* device, uint64_t* sizeOut) {
D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT feature = {};
ReturnIfFailedDevice(
GPGMM_RETURN_IF_FAILED_ON_DEVICE(
device->CheckFeatureSupport(D3D12_FEATURE_GPU_VIRTUAL_ADDRESS_SUPPORT, &feature,
sizeof(D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT)),
device);
Expand All @@ -43,7 +43,7 @@ namespace gpgmm::d3d12 {

HRESULT SetMaxResourceHeapSize(ID3D12Device* device, uint64_t* sizeOut) {
D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT feature = {};
ReturnIfFailedDevice(
GPGMM_RETURN_IF_FAILED_ON_DEVICE(
device->CheckFeatureSupport(D3D12_FEATURE_GPU_VIRTUAL_ADDRESS_SUPPORT, &feature,
sizeof(D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT)),
device);
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace gpgmm::d3d12 {
HRESULT SetMaxResourceHeapTierSupported(ID3D12Device* device,
D3D12_RESOURCE_HEAP_TIER* maxResourceHeapTierOut) {
D3D12_FEATURE_DATA_D3D12_OPTIONS options = {};
ReturnIfFailedDevice(
GPGMM_RETURN_IF_FAILED_ON_DEVICE(
device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options)),
device);
*maxResourceHeapTierOut = options.ResourceHeapTier;
Expand All @@ -85,26 +85,25 @@ namespace gpgmm::d3d12 {

// static
HRESULT Caps::CreateCaps(ID3D12Device* device, IDXGIAdapter* adapter, Caps** capsOut) {
if (device == nullptr) {
return E_INVALIDARG;
}
GPGMM_RETURN_IF_NULLPTR(device);

std::unique_ptr<Caps> caps(new Caps());
ReturnIfFailed(SetMaxResourceSize(device, &caps->mMaxResourceSize));
ReturnIfFailed(SetMaxResourceHeapSize(device, &caps->mMaxResourceHeapSize));
ReturnIfFailed(SetMaxResourceHeapTierSupported(device, &caps->mMaxResourceHeapTier));
ReturnIfFailed(
GPGMM_RETURN_IF_FAILED(SetMaxResourceSize(device, &caps->mMaxResourceSize));
GPGMM_RETURN_IF_FAILED(SetMaxResourceHeapSize(device, &caps->mMaxResourceHeapSize));
GPGMM_RETURN_IF_FAILED(
SetMaxResourceHeapTierSupported(device, &caps->mMaxResourceHeapTier));
GPGMM_RETURN_IF_FAILED(
SetCreateHeapNotResidentSupported(device, &caps->mIsCreateHeapNotResidentSupported));

D3D12_FEATURE_DATA_ARCHITECTURE arch = {};
ReturnIfFailedDevice(
GPGMM_RETURN_IF_FAILED_ON_DEVICE(
device->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &arch, sizeof(arch)), device);
caps->mIsAdapterUMA = arch.UMA;
caps->mIsAdapterCacheCoherentUMA = arch.CacheCoherentUMA;

if (adapter != nullptr) {
DXGI_ADAPTER_DESC adapterDesc;
ReturnIfFailed(adapter->GetDesc(&adapterDesc));
GPGMM_RETURN_IF_FAILED(adapter->GetDesc(&adapterDesc));

// D3D12 has no feature to detect support and must be set manually.
if (adapterDesc.VendorId == static_cast<uint32_t>(GPUVendor::kIntel_VkVendor)) {
Expand Down
16 changes: 8 additions & 8 deletions src/gpgmm/d3d12/ErrorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace gpgmm::d3d12 {

#define ReturnIfNullptr(expr) \
#define GPGMM_RETURN_IF_NULLPTR(expr) \
{ \
if (GPGMM_UNLIKELY(expr == nullptr)) { \
gpgmm::ErrorLog() << #expr << ": " << GetErrorMessage(E_POINTER); \
Expand All @@ -33,9 +33,9 @@ namespace gpgmm::d3d12 {
for (;;) \
break

#define ReturnIfFailed(expr) ReturnIfFailedDevice(expr, nullptr)
#define GPGMM_RETURN_IF_FAILED(expr) GPGMM_RETURN_IF_FAILED_ON_DEVICE(expr, nullptr)

#define ReturnIfFailedDevice(expr, device) \
#define GPGMM_RETURN_IF_FAILED_ON_DEVICE(expr, device) \
{ \
HRESULT hr = expr; \
if (GPGMM_UNLIKELY(FAILED(hr))) { \
Expand All @@ -46,7 +46,7 @@ namespace gpgmm::d3d12 {
for (;;) \
break

#define ReturnIfSucceeded(expr) \
#define GPGMM_RETURN_IF_SUCCEEDED(expr) \
{ \
HRESULT hr = expr; \
if (GPGMM_LIKELY(SUCCEEDED(hr))) { \
Expand All @@ -56,9 +56,9 @@ namespace gpgmm::d3d12 {
for (;;) \
break

// Same as ReturnIfSucceeded but also returns if error is lethal.
// Same as GPGMM_RETURN_IF_SUCCEEDED but also returns if error is lethal.
// Non-internal errors are always fatal and should not run re-attempt logic.
#define ReturnIfSucceededOrFatal(expr) \
#define GPGMM_RETURN_IF_SUCCEEDED_OR_FATAL(expr) \
{ \
HRESULT hr = expr; \
if (GPGMM_LIKELY(SUCCEEDED(hr)) || \
Expand All @@ -69,8 +69,8 @@ namespace gpgmm::d3d12 {
for (;;) \
break

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

std::string GetDeviceErrorMessage(ID3D12Device* device, HRESULT error);
std::string GetErrorMessage(HRESULT error) noexcept;
Expand Down
6 changes: 3 additions & 3 deletions src/gpgmm/d3d12/FenceD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace gpgmm::d3d12 {
// static
HRESULT Fence::CreateFence(ID3D12Device* device, uint64_t initialValue, Fence** fenceOut) {
ComPtr<ID3D12Fence> fence;
ReturnIfFailed(
GPGMM_RETURN_IF_FAILED(
device->CreateFence(initialValue, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)));
*fenceOut = new Fence(fence, initialValue);
return S_OK;
Expand Down Expand Up @@ -52,7 +52,7 @@ namespace gpgmm::d3d12 {

HRESULT Fence::WaitFor(uint64_t fenceValue) {
if (!IsCompleted(fenceValue)) {
ReturnIfFailed(mFence->SetEventOnCompletion(fenceValue, mCompletionEvent));
GPGMM_RETURN_IF_FAILED(mFence->SetEventOnCompletion(fenceValue, mCompletionEvent));

// Wait for the event to complete (it will automatically reset).
const uint32_t result = WaitForSingleObject(mCompletionEvent, INFINITE);
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace gpgmm::d3d12 {

HRESULT Fence::Signal(ID3D12CommandQueue* pCommandQueue) {
ASSERT(mLastSignaledFence != mCurrentFence);
ReturnIfFailed(pCommandQueue->Signal(mFence.Get(), mCurrentFence));
GPGMM_RETURN_IF_FAILED(pCommandQueue->Signal(mFence.Get(), mCurrentFence));
mLastSignaledFence = mCurrentFence;
mCurrentFence++;
return S_OK;
Expand Down
22 changes: 11 additions & 11 deletions src/gpgmm/d3d12/HeapD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace gpgmm::d3d12 {

ComPtr<ID3D12Resource> committedResource;
if (SUCCEEDED(pageable.As(&committedResource))) {
ReturnIfFailed(committedResource->GetHeapProperties(nullptr, heapFlags));
GPGMM_RETURN_IF_FAILED(committedResource->GetHeapProperties(nullptr, heapFlags));
return S_OK;
}

Expand Down Expand Up @@ -68,7 +68,7 @@ namespace gpgmm::d3d12 {
CreateHeapFn createHeapFn,
void* pCreateHeapContext,
IHeap** ppHeapOut) {
ReturnIfNullptr(pCreateHeapContext);
GPGMM_RETURN_IF_NULLPTR(pCreateHeapContext);

const bool isResidencyDisabled = (pResidencyManager == nullptr);

Expand All @@ -77,8 +77,8 @@ namespace gpgmm::d3d12 {
// Ensure enough budget exists before creating the heap to avoid an out-of-memory error.
if (!isResidencyDisabled && (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_BUDGET)) {
uint64_t bytesEvicted = descriptor.SizeInBytes;
ReturnIfFailed(residencyManager->EvictInternal(descriptor.SizeInBytes,
descriptor.HeapSegment, &bytesEvicted));
GPGMM_RETURN_IF_FAILED(residencyManager->EvictInternal(
descriptor.SizeInBytes, descriptor.HeapSegment, &bytesEvicted));

if (bytesEvicted < descriptor.SizeInBytes) {
DXGI_QUERY_VIDEO_MEMORY_INFO currentVideoInfo = {};
Expand All @@ -98,11 +98,11 @@ namespace gpgmm::d3d12 {
}

ComPtr<ID3D12Pageable> pageable;
ReturnIfFailedDevice(createHeapFn(pCreateHeapContext, &pageable),
GetDevice(pageable.Get()));
GPGMM_RETURN_IF_FAILED_ON_DEVICE(createHeapFn(pCreateHeapContext, &pageable),
GetDevice(pageable.Get()));

// Pageable-based type is required for residency-managed heaps.
ReturnIfNullptr(pageable);
GPGMM_RETURN_IF_NULLPTR(pageable);

GPGMM_TRACE_EVENT_OBJECT_CALL("Heap.CreateHeap",
(CREATE_HEAP_DESC{descriptor, pageable.Get()}));
Expand Down Expand Up @@ -136,11 +136,11 @@ namespace gpgmm::d3d12 {
// descriptor heap), they must be manually locked and unlocked to be inserted into the
// residency cache.
if (heap->mState != RESIDENCY_STATUS_UNKNOWN) {
ReturnIfFailed(residencyManager->InsertHeap(heap.get()));
GPGMM_RETURN_IF_FAILED(residencyManager->InsertHeap(heap.get()));
} else {
if (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_RESIDENCY) {
ReturnIfFailed(residencyManager->LockHeap(heap.get()));
ReturnIfFailed(residencyManager->UnlockHeap(heap.get()));
GPGMM_RETURN_IF_FAILED(residencyManager->LockHeap(heap.get()));
GPGMM_RETURN_IF_FAILED(residencyManager->UnlockHeap(heap.get()));
ASSERT(heap->mState == RESIDENCY_STATUS_CURRENT_RESIDENT);
}
}
Expand All @@ -153,7 +153,7 @@ namespace gpgmm::d3d12 {
}
}

ReturnIfFailed(heap->SetDebugName(descriptor.DebugName));
GPGMM_RETURN_IF_FAILED(heap->SetDebugName(descriptor.DebugName));
GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(heap.get(), descriptor);

gpgmm::DebugLog(MessageId::kObjectCreated, heap.get())
Expand Down
Loading