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
21 changes: 11 additions & 10 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 = {};
GPGMM_RETURN_IF_FAILED_ON_DEVICE(
GPGMM_RETURN_IF_FAILED(
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 = {};
GPGMM_RETURN_IF_FAILED_ON_DEVICE(
GPGMM_RETURN_IF_FAILED(
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 = {};
GPGMM_RETURN_IF_FAILED_ON_DEVICE(
GPGMM_RETURN_IF_FAILED(
device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options)),
device);
*maxResourceHeapTierOut = options.ResourceHeapTier;
Expand All @@ -88,22 +88,23 @@ namespace gpgmm::d3d12 {
GPGMM_RETURN_IF_NULLPTR(device);

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

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

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

caps->mSharedSegmentSize = adapterDesc.SharedSystemMemory;
caps->mDedicatedSegmentSize = adapterDesc.DedicatedVideoMemory;
Expand Down
4 changes: 1 addition & 3 deletions src/gpgmm/d3d12/ErrorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
for (;;) \
break

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

#define GPGMM_RETURN_IF_FAILED_ON_DEVICE(expr, device) \
#define GPGMM_RETURN_IF_FAILED(expr, device) \
{ \
HRESULT hr = expr; \
if (GPGMM_UNLIKELY(FAILED(hr))) { \
Expand Down
9 changes: 6 additions & 3 deletions src/gpgmm/d3d12/FenceD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "gpgmm/d3d12/FenceD3D12.h"

#include "gpgmm/d3d12/ErrorD3D12.h"
#include "gpgmm/d3d12/UtilsD3D12.h"
#include "gpgmm/utils/Assert.h"

namespace gpgmm::d3d12 {
Expand All @@ -23,7 +24,7 @@ namespace gpgmm::d3d12 {
HRESULT Fence::CreateFence(ID3D12Device* device, uint64_t initialValue, Fence** fenceOut) {
ComPtr<ID3D12Fence> fence;
GPGMM_RETURN_IF_FAILED(
device->CreateFence(initialValue, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)));
device->CreateFence(initialValue, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)), device);
*fenceOut = new Fence(fence, initialValue);
return S_OK;
}
Expand Down Expand Up @@ -52,7 +53,8 @@ namespace gpgmm::d3d12 {

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

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

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

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

Expand Down Expand Up @@ -78,8 +79,10 @@ 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;
GPGMM_RETURN_IF_FAILED(residencyManager->EvictInternal(
descriptor.SizeInBytes, descriptor.HeapSegment, &bytesEvicted));
GPGMM_RETURN_IF_FAILED(
residencyManager->EvictInternal(descriptor.SizeInBytes, descriptor.HeapSegment,
&bytesEvicted),
residencyManager->mDevice);

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

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

// Pageable-based type is required for residency-managed heaps.
GPGMM_RETURN_IF_NULLPTR(pageable);
Expand Down Expand Up @@ -137,11 +140,14 @@ 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) {
GPGMM_RETURN_IF_FAILED(residencyManager->InsertHeap(heap.get()));
GPGMM_RETURN_IF_FAILED(residencyManager->InsertHeap(heap.get()),
GetDevice(pageable.Get()));
} else {
if (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_RESIDENCY) {
GPGMM_RETURN_IF_FAILED(residencyManager->LockHeap(heap.get()));
GPGMM_RETURN_IF_FAILED(residencyManager->UnlockHeap(heap.get()));
GPGMM_RETURN_IF_FAILED(residencyManager->LockHeap(heap.get()),
GetDevice(pageable.Get()));
GPGMM_RETURN_IF_FAILED(residencyManager->UnlockHeap(heap.get()),
GetDevice(pageable.Get()));
ASSERT(heap->mState == RESIDENCY_STATUS_CURRENT_RESIDENT);
}
}
Expand All @@ -154,7 +160,7 @@ namespace gpgmm::d3d12 {
}
}

GPGMM_RETURN_IF_FAILED(heap->SetDebugName(descriptor.DebugName));
GPGMM_RETURN_IF_FAILED(heap->SetDebugName(descriptor.DebugName), GetDevice(pageable.Get()));
GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(heap.get(), descriptor);

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