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
19 changes: 6 additions & 13 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,15 +1256,13 @@ namespace gpgmm::d3d12 {

std::lock_guard<std::mutex> lock(mMutex);

ComPtr<ID3D12Resource> resource(pCommittedResource);

D3D12_RESOURCE_DESC desc = resource->GetDesc();
D3D12_RESOURCE_DESC desc = pCommittedResource->GetDesc();
const D3D12_RESOURCE_ALLOCATION_INFO resourceInfo =
GetResourceAllocationInfo(mDevice, desc);

D3D12_HEAP_PROPERTIES heapProperties;
D3D12_HEAP_FLAGS heapFlags;
ReturnIfFailed(resource->GetHeapProperties(&heapProperties, &heapFlags));
ReturnIfFailed(pCommittedResource->GetHeapProperties(&heapProperties, &heapFlags));

// TODO: enable validation conditionally?
if (allocationDescriptor.HeapType != 0 &&
Expand Down Expand Up @@ -1306,7 +1304,7 @@ namespace gpgmm::d3d12 {
resourceHeapDesc.SizeInBytes = resourceInfo.SizeInBytes;
resourceHeapDesc.Alignment = resourceInfo.Alignment;

ImportResourceCallbackContext importResourceCallbackContext(resource);
ImportResourceCallbackContext importResourceCallbackContext(pCommittedResource);

ComPtr<IHeap> resourceHeap;
ReturnIfFailed(Heap::CreateHeap(
Expand All @@ -1328,7 +1326,7 @@ namespace gpgmm::d3d12 {

*ppResourceAllocationOut = new ResourceAllocation(allocationDesc, nullptr, this,
static_cast<Heap*>(resourceHeap.Detach()),
nullptr, std::move(resource));
nullptr, pCommittedResource);

return S_OK;
}
Expand Down Expand Up @@ -1534,7 +1532,7 @@ namespace gpgmm::d3d12 {
return E_INVALIDARG;
}

ImportResourceCallbackContext::ImportResourceCallbackContext(ComPtr<ID3D12Resource> resource)
ImportResourceCallbackContext::ImportResourceCallbackContext(ID3D12Resource* resource)
: mResource(resource) {
}

Expand All @@ -1544,12 +1542,7 @@ namespace gpgmm::d3d12 {
}

HRESULT ImportResourceCallbackContext::GetHeap(ID3D12Pageable** ppPageableOut) {
ComPtr<ID3D12Pageable> pageable;
ReturnIfFailed(mResource.As(&pageable));

*ppPageableOut = pageable.Detach();

return S_OK;
return mResource->QueryInterface(IID_PPV_ARGS(ppPageableOut));
}

CreateCommittedResourceCallbackContext::CreateCommittedResourceCallbackContext(
Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ namespace gpgmm::d3d12 {

class ImportResourceCallbackContext {
public:
ImportResourceCallbackContext(ComPtr<ID3D12Resource> resource);
ImportResourceCallbackContext(ID3D12Resource* resource);
static HRESULT GetHeap(void* pContext, ID3D12Pageable** ppPageableOut);

private:
HRESULT GetHeap(ID3D12Pageable** ppPageableOut);

ComPtr<ID3D12Resource> mResource;
ID3D12Resource* mResource = nullptr;
};

class CreateCommittedResourceCallbackContext {
Expand Down