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
25 changes: 10 additions & 15 deletions src/gpgmm/d3d12/ResourceAllocationD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ namespace gpgmm { namespace d3d12 {
return E_INVALIDARG;
}

Heap* resourceHeap = ToBackend(GetMemory());
ASSERT(resourceHeap != nullptr);

if (mResidencyManager != nullptr) {
ReturnIfFailed(mResidencyManager->LockHeap(resourceHeap));
ReturnIfFailed(mResidencyManager->LockHeap(GetMemory()));
}

// Range coordinates are always subresource-relative so the range should only be
Expand Down Expand Up @@ -126,11 +123,8 @@ namespace gpgmm { namespace d3d12 {
// subresource-relative coordinates.
ASSERT(subresource == 0 || GetMethod() != AllocationMethod::kSubAllocatedWithin);

Heap* resourceHeap = ToBackend(GetMemory());
ASSERT(resourceHeap != nullptr);

if (mResidencyManager != nullptr) {
mResidencyManager->UnlockHeap(resourceHeap);
mResidencyManager->UnlockHeap(GetMemory());
}

D3D12_RANGE newWrittenRange{};
Expand All @@ -145,13 +139,13 @@ namespace gpgmm { namespace d3d12 {
}

HRESULT ResourceAllocation::UpdateResidency(ResidencySet* residencySet) const {
Heap* resourceHeap = ToBackend(GetMemory());
Heap* resourceHeap = GetMemory();
ASSERT(resourceHeap != nullptr);
return resourceHeap->UpdateResidency(residencySet);
}

bool ResourceAllocation::IsResident() const {
const Heap* resourceHeap = ToBackend(GetMemory());
const Heap* resourceHeap = GetMemory();
ASSERT(resourceHeap != nullptr);
return resourceHeap->IsResident();
}
Expand All @@ -166,15 +160,16 @@ namespace gpgmm { namespace d3d12 {
}

RESOURCE_ALLOCATION_INFO ResourceAllocation::GetInfo() const {
Heap* resourceHeap = ToBackend(GetMemory());
ASSERT(resourceHeap != nullptr);

return {GetSize(), GetOffset(), mOffsetFromResource,
GetMethod(), resourceHeap, mResource.Get()};
return {GetSize(), GetOffset(), mOffsetFromResource,
GetMethod(), GetMemory(), mResource.Get()};
}

const char* ResourceAllocation::GetTypename() const {
return "GPUMemoryAllocation";
}

Heap* ResourceAllocation::GetMemory() const {
return ToBackend(MemoryAllocation::GetMemory());
}

}} // namespace gpgmm::d3d12
3 changes: 3 additions & 0 deletions src/gpgmm/d3d12/ResourceAllocationD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ namespace gpgmm { namespace d3d12 {

const char* GetTypename() const;

// Returns the heap assigned to this resource allocation.
Heap* GetMemory() const;

private:
void DeleteThis() override;

Expand Down
2 changes: 1 addition & 1 deletion src/tests/end2end/D3D12ResourceAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) {
EXPECT_EQ(allocation->GetSize(), kDefaultPreferredResourceHeapSize);

// Commmitted resources cannot be backed by a D3D12 heap.
Heap* resourceHeap = ToBackend(allocation->GetMemory());
Heap* resourceHeap = allocation->GetMemory();
ASSERT_NE(resourceHeap, nullptr);
ASSERT_EQ(resourceHeap->GetHeap(), nullptr);

Expand Down