Skip to content

Commit 4e08f05

Browse files
Revert "Fix memory leak during D3D12 capture (#2740)" (#2771)
This reverts commit 865a785.
1 parent 5abf03f commit 4e08f05

5 files changed

Lines changed: 26 additions & 44 deletions

File tree

framework/decode/dx12_replay_consumer_base.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,14 +1537,16 @@ void Dx12ReplayConsumerBase::InitializeD3D12Device(HandlePointerDecoder<void*>*
15371537

15381538
void Dx12ReplayConsumerBase::DetectAdapters()
15391539
{
1540-
graphics::dx12::IDXGIFactory1ComPtr factory1 = nullptr;
1540+
IDXGIFactory1* factory1 = nullptr;
15411541

1542-
HRESULT result = CreateDXGIFactory1(IID_PPV_ARGS(&factory1));
1542+
HRESULT result = CreateDXGIFactory1(IID_IDXGIFactory1, reinterpret_cast<void**>(&factory1));
15431543

15441544
if (SUCCEEDED(result))
15451545
{
1546-
graphics::dx12::TrackAdapters(result, reinterpret_cast<void**>(&factory1.GetInterfacePtr()), adapters_);
1546+
graphics::dx12::TrackAdapters(result, reinterpret_cast<void**>(&factory1), adapters_);
15471547
render_adapter_ = graphics::dx12::GetAdapterbyIndex(adapters_, options_.override_gpu_index);
1548+
1549+
factory1->Release();
15481550
}
15491551
}
15501552

@@ -3784,7 +3786,7 @@ IDXGIAdapter* Dx12ReplayConsumerBase::GetAdapter()
37843786
{
37853787
for (const auto& adapter : adapters_)
37863788
{
3787-
if (adapter.second.adapter.GetInterfacePtr() == adapter_found)
3789+
if (adapter.second.adapter == adapter_found)
37883790
{
37893791
if (graphics::dx12::IsSoftwareAdapter(adapter.second.internal_desc) == true)
37903792
{
@@ -3801,7 +3803,7 @@ IDXGIAdapter* Dx12ReplayConsumerBase::GetAdapter()
38013803
{
38023804
if (graphics::dx12::IsSoftwareAdapter(adapter.second.internal_desc) == false)
38033805
{
3804-
adapter_found = adapter.second.adapter.GetInterfacePtr();
3806+
adapter_found = adapter.second.adapter;
38053807
break;
38063808
}
38073809
}

framework/encode/dx12_object_wrapper_info.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,6 @@ struct ID3D12ProtectedResourceSessionInfo : public DxWrapperInfo
384384

385385
struct ID3D12DeviceInfo : public DxWrapperInfo
386386
{
387-
virtual ~ID3D12DeviceInfo()
388-
{
389-
if (adapter3 != nullptr)
390-
{
391-
adapter3->Release();
392-
}
393-
}
394-
395387
// Track the device's parent adapter as IDXGIAdapter3
396388
// This enables checking GPU memory availability via QueryVideoMemoryInfo()
397389
IDXGIAdapter3* adapter3{ nullptr };

framework/graphics/dx12_util.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -770,20 +770,18 @@ void TrackAdapters(HRESULT result, void** ppFactory, graphics::dx12::ActiveAdapt
770770
if (SUCCEEDED(result))
771771
{
772772
// First see if the created factory can be queried as a 1.1 factory
773-
auto* base_factory = reinterpret_cast<IUnknown*>(*ppFactory);
774-
IDXGIFactory1ComPtr factory1 = nullptr;
773+
IDXGIFactory1* factory1 = reinterpret_cast<IDXGIFactory1*>(*ppFactory);
775774

776775
// DXGI 1.1 tracking (default)
777-
if (SUCCEEDED(base_factory->QueryInterface(IID_PPV_ARGS(&factory1))))
776+
if (SUCCEEDED(factory1->QueryInterface(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&factory1))))
778777
{
779778
// Get a fresh enumeration, in case it was previously filled by 1.0 tracking
780779
RemoveDeactivatedAdapters(adapters);
781780

782781
// Enumerate 1.1 adapters and fetch data with GetDesc1()
783-
IDXGIAdapter1ComPtr adapter1 = nullptr;
782+
IDXGIAdapter1* adapter1 = nullptr;
784783

785-
for (UINT adapter_idx = 0; SUCCEEDED(factory1->EnumAdapters1(adapter_idx, &adapter1.GetInterfacePtr()));
786-
++adapter_idx)
784+
for (UINT adapter_idx = 0; SUCCEEDED(factory1->EnumAdapters1(adapter_idx, &adapter1)); ++adapter_idx)
787785
{
788786
DXGI_ADAPTER_DESC1 dxgi_desc = {};
789787
adapter1->GetDesc1(&dxgi_desc);
@@ -794,7 +792,7 @@ void TrackAdapters(HRESULT result, void** ppFactory, graphics::dx12::ActiveAdapt
794792
adapter_type = format::AdapterType::kSoftwareAdapter;
795793
}
796794

797-
TrackAdapterDesc(adapter1.GetInterfacePtr(), adapter_idx, dxgi_desc, adapters, adapter_type);
795+
TrackAdapterDesc(adapter1, adapter_idx, dxgi_desc, adapters, adapter_type);
798796
}
799797
}
800798

@@ -804,25 +802,20 @@ void TrackAdapters(HRESULT result, void** ppFactory, graphics::dx12::ActiveAdapt
804802
// Only enumerate 1.0 factory adapters if nothing has been seen yet
805803
if (adapters.empty())
806804
{
807-
IDXGIFactoryComPtr factory = nullptr;
805+
IDXGIFactory* factory = reinterpret_cast<IDXGIFactory*>(*ppFactory);
808806

809-
if (SUCCEEDED(base_factory->QueryInterface(IID_PPV_ARGS(&factory))))
807+
if (SUCCEEDED(factory->QueryInterface(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory))))
810808
{
811809
// Enumerate 1.0 adapters and fetch data with GetDesc()
812-
IDXGIAdapterComPtr adapter = nullptr;
810+
IDXGIAdapter* adapter = nullptr;
813811

814-
for (UINT adapter_idx = 0;
815-
SUCCEEDED(factory->EnumAdapters(adapter_idx, &adapter.GetInterfacePtr()));
816-
++adapter_idx)
812+
for (UINT adapter_idx = 0; SUCCEEDED(factory->EnumAdapters(adapter_idx, &adapter)); ++adapter_idx)
817813
{
818814
DXGI_ADAPTER_DESC dxgi_desc = {};
819815
adapter->GetDesc(&dxgi_desc);
820816

821-
TrackAdapterDesc(adapter.GetInterfacePtr(),
822-
adapter_idx,
823-
dxgi_desc,
824-
adapters,
825-
format::AdapterType::kUnknownAdapter);
817+
TrackAdapterDesc(
818+
adapter, adapter_idx, dxgi_desc, adapters, format::AdapterType::kUnknownAdapter);
826819
}
827820
}
828821
else
@@ -949,7 +942,7 @@ bool GetAdapterAndIndexbyLUID(LUID luid,
949942
if (search != adapters.end())
950943
{
951944
index = search->second.adapter_idx;
952-
adapter_ptr = search->second.adapter.GetInterfacePtr();
945+
adapter_ptr = search->second.adapter;
953946
success = true;
954947
}
955948
return success;
@@ -979,7 +972,7 @@ IDXGIAdapter* GetAdapterbyIndex(graphics::dx12::ActiveAdapterMap& adapters, int3
979972
{
980973
if (static_cast<int32_t>(adapter.second.adapter_idx) == index)
981974
{
982-
return adapter.second.adapter.GetInterfacePtr();
975+
return adapter.second.adapter;
983976
}
984977
}
985978
return nullptr;

framework/graphics/dx12_util.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ GFXRECON_BEGIN_NAMESPACE(dx12)
5757

5858
#ifdef WIN32
5959
typedef _com_ptr_t<_com_IIID<IDXGISwapChain3, &__uuidof(IDXGISwapChain3)>> IDXGISwapChain3ComPtr;
60-
typedef _com_ptr_t<_com_IIID<IDXGIAdapter, &__uuidof(IDXGIAdapter)>> IDXGIAdapterComPtr;
61-
typedef _com_ptr_t<_com_IIID<IDXGIAdapter1, &__uuidof(IDXGIAdapter1)>> IDXGIAdapter1ComPtr;
62-
typedef _com_ptr_t<_com_IIID<IDXGIAdapter2, &__uuidof(IDXGIAdapter2)>> IDXGIAdapter2ComPtr;
63-
typedef _com_ptr_t<_com_IIID<IDXGIAdapter3, &__uuidof(IDXGIAdapter3)>> IDXGIAdapter3ComPtr;
64-
typedef _com_ptr_t<_com_IIID<IDXGIFactory, &__uuidof(IDXGIFactory)>> IDXGIFactoryComPtr;
65-
typedef _com_ptr_t<_com_IIID<IDXGIFactory1, &__uuidof(IDXGIFactory1)>> IDXGIFactory1ComPtr;
6660

6761
typedef _com_ptr_t<_com_IIID<ID3D12DescriptorHeap, &__uuidof(ID3D12DescriptorHeap)>> ID3D12DescriptorHeapComPtr;
6862
typedef _com_ptr_t<_com_IIID<ID3D12Device, &__uuidof(ID3D12Device)>> ID3D12DeviceComPtr;
@@ -141,7 +135,7 @@ uint32_t Dx12DumpResourcePosToArrayIndex(Dx12DumpResourcePos pos);
141135
struct ActiveAdapterInfo
142136
{
143137
format::DxgiAdapterDesc internal_desc;
144-
IDXGIAdapterComPtr adapter;
138+
IDXGIAdapter* adapter;
145139
UINT32 adapter_idx;
146140
bool active;
147141
};

tools/info/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,15 +1102,14 @@ static bool CheckOptionEnumGpuIndices(const char* exe_name, const gfxrecon::util
11021102
{
11031103
if (arg_parser.IsOptionSet(kEnumGpuIndices))
11041104
{
1105-
gfxrecon::graphics::dx12::IDXGIFactory1ComPtr factory1 = nullptr;
1105+
IDXGIFactory1* factory1 = nullptr;
11061106

1107-
HRESULT result = CreateDXGIFactory1(IID_PPV_ARGS(&factory1));
1107+
HRESULT result = CreateDXGIFactory1(IID_IDXGIFactory1, reinterpret_cast<void**>(&factory1));
11081108

11091109
if (SUCCEEDED(result))
11101110
{
11111111
gfxrecon::graphics::dx12::ActiveAdapterMap adapters{};
1112-
gfxrecon::graphics::dx12::TrackAdapters(
1113-
result, reinterpret_cast<void**>(&factory1.GetInterfacePtr()), adapters);
1112+
gfxrecon::graphics::dx12::TrackAdapters(result, reinterpret_cast<void**>(&factory1), adapters);
11141113

11151114
WriteOutput("GPU index\tGPU name\tSubSys ID");
11161115
for (size_t index = 0; index < adapters.size(); ++index)
@@ -1126,10 +1125,12 @@ static bool CheckOptionEnumGpuIndices(const char* exe_name, const gfxrecon::util
11261125
adapter.second.adapter_idx,
11271126
replay_adapter_str.c_str(),
11281127
adapter.second.internal_desc.SubSysId);
1128+
adapter.second.adapter->Release();
11291129
break;
11301130
}
11311131
}
11321132
}
1133+
factory1->Release();
11331134
}
11341135
else
11351136
{

0 commit comments

Comments
 (0)