diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp index d2e6393..2308c1b 100644 --- a/src/D3D12MemAlloc.cpp +++ b/src/D3D12MemAlloc.cpp @@ -6662,6 +6662,9 @@ private: #endif #ifdef __ID3D12Device10_INTERFACE_DEFINED__ ID3D12Device10* m_Device10 = NULL; // AddRef, optional +#endif +#ifdef __ID3D12Device12_INTERFACE_DEFINED__ + ID3D12Device12* m_Device12 = NULL; // AddRef, optional #endif IDXGIAdapter* m_Adapter; // AddRef #if D3D12MA_DXGI_1_4 @@ -6719,13 +6722,16 @@ private: HRESULT UpdateD3D12Budget(); - D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfoNative(const D3D12_RESOURCE_DESC& resourceDesc) const; + D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfoNative(const D3D12_RESOURCE_DESC& resourceDesc, UINT32 NumCastableFormats = 0, + DXGI_FORMAT* pCastableFormats = nullptr) const; #ifdef __ID3D12Device8_INTERFACE_DEFINED__ - D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfoNative(const D3D12_RESOURCE_DESC1& resourceDesc) const; + D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfoNative(const D3D12_RESOURCE_DESC1& resourceDesc, UINT32 NumCastableFormats = 0, + DXGI_FORMAT* pCastableFormats = nullptr) const; #endif template - D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfo(D3D12_RESOURCE_DESC_T& inOutResourceDesc) const; + D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfo(D3D12_RESOURCE_DESC_T& inOutResourceDesc, UINT32 NumCastableFormats = 0, + DXGI_FORMAT* pCastableFormats = nullptr) const; bool NewAllocationWithinBudget(D3D12_HEAP_TYPE heapType, UINT64 size); @@ -6796,6 +6802,10 @@ HRESULT AllocatorPimpl::Init(const ALLOCATOR_DESC& desc) m_Device->QueryInterface(D3D12MA_IID_PPV_ARGS(&m_Device10)); #endif +#ifdef __ID3D12Device12_INTERFACE_DEFINED__ + m_Device->QueryInterface(D3D12MA_IID_PPV_ARGS(&m_Device12)); +#endif + HRESULT hr = m_Adapter->GetDesc(&m_AdapterDesc); if (FAILED(hr)) { @@ -6857,6 +6867,9 @@ HRESULT AllocatorPimpl::Init(const ALLOCATOR_DESC& desc) AllocatorPimpl::~AllocatorPimpl() { +#ifdef __ID3D12Device12_INTERFACE_DEFINED__ + SAFE_RELEASE(m_Device12); +#endif #ifdef __ID3D12Device10_INTERFACE_DEFINED__ SAFE_RELEASE(m_Device10); #endif @@ -7033,7 +7046,7 @@ HRESULT AllocatorPimpl::CreateResource( } finalResourceDesc1 = *createParams.GetResourceDesc1(); finalCreateParams.AccessResourceDesc1() = &finalResourceDesc1; - resAllocInfo = GetResourceAllocationInfo(finalResourceDesc1); + resAllocInfo = GetResourceAllocationInfo(finalResourceDesc1, createParams.GetNumCastableFormats(), createParams.GetCastableFormats()); } #endif else @@ -8185,7 +8198,8 @@ HRESULT AllocatorPimpl::UpdateD3D12Budget() #endif } -D3D12_RESOURCE_ALLOCATION_INFO AllocatorPimpl::GetResourceAllocationInfoNative(const D3D12_RESOURCE_DESC& resourceDesc) const +D3D12_RESOURCE_ALLOCATION_INFO AllocatorPimpl::GetResourceAllocationInfoNative(const D3D12_RESOURCE_DESC& resourceDesc, UINT32 NumCastableFormats, + DXGI_FORMAT* pCastableFormats) const { // This is how new D3D12 headers define GetResourceAllocationInfo function - // different signature depending on these macros. @@ -8198,11 +8212,32 @@ D3D12_RESOURCE_ALLOCATION_INFO AllocatorPimpl::GetResourceAllocationInfoNative(c } #ifdef __ID3D12Device8_INTERFACE_DEFINED__ -D3D12_RESOURCE_ALLOCATION_INFO AllocatorPimpl::GetResourceAllocationInfoNative(const D3D12_RESOURCE_DESC1& resourceDesc) const +D3D12_RESOURCE_ALLOCATION_INFO AllocatorPimpl::GetResourceAllocationInfoNative(const D3D12_RESOURCE_DESC1& resourceDesc, UINT32 NumCastableFormats, + DXGI_FORMAT* pCastableFormats) const { D3D12MA_ASSERT(m_Device8 != NULL); D3D12_RESOURCE_ALLOCATION_INFO1 info1Unused; + if (NumCastableFormats != 0 && pCastableFormats) + { +#ifdef __ID3D12Device12_INTERFACE_DEFINED__ + D3D12MA_ASSERT(m_Device12 != NULL); + + // This is how new D3D12 headers define GetResourceAllocationInfo function - + // different signature depending on these macros. + #if defined(_MSC_VER) || !defined(_WIN32) + return m_Device12->GetResourceAllocationInfo3(0, 1, &resourceDesc, &NumCastableFormats, &pCastableFormats, &info1Unused); + #else + D3D12_RESOURCE_ALLOCATION_INFO retVal; + return *m_Device12->GetResourceAllocationInfo3(&retVal, 0, 1, &resourceDesc, &NumCastableFormats, &pCastableFormats, &info1Unused); + #endif + +#else + D3D12MA_ASSERT(false && "GetResourceAllocationInfo with castable formats can not be called without ID3D12Device12 supported"); +#endif + } + + // This is how new D3D12 headers define GetResourceAllocationInfo function - // different signature depending on these macros. #if defined(_MSC_VER) || !defined(_WIN32) @@ -8215,7 +8250,8 @@ D3D12_RESOURCE_ALLOCATION_INFO AllocatorPimpl::GetResourceAllocationInfoNative(c #endif // #ifdef __ID3D12Device8_INTERFACE_DEFINED__ template -D3D12_RESOURCE_ALLOCATION_INFO AllocatorPimpl::GetResourceAllocationInfo(D3D12_RESOURCE_DESC_T& inOutResourceDesc) const +D3D12_RESOURCE_ALLOCATION_INFO AllocatorPimpl::GetResourceAllocationInfo(D3D12_RESOURCE_DESC_T& inOutResourceDesc, UINT32 NumCastableFormats, + DXGI_FORMAT* pCastableFormats) const { #ifdef __ID3D12Device1_INTERFACE_DEFINED__ /* Optional optimization: Microsoft documentation says: @@ -8262,7 +8298,7 @@ D3D12_RESOURCE_ALLOCATION_INFO AllocatorPimpl::GetResourceAllocationInfo(D3D12_R } #endif // #if D3D12MA_USE_SMALL_RESOURCE_PLACEMENT_ALIGNMENT - return GetResourceAllocationInfoNative(inOutResourceDesc); + return GetResourceAllocationInfoNative(inOutResourceDesc, NumCastableFormats, pCastableFormats); } bool AllocatorPimpl::NewAllocationWithinBudget(D3D12_HEAP_TYPE heapType, UINT64 size)