FidelityFX-SDK
FidelityFX-SDK copied to clipboard
ID3D12Device* leak
When a ffxQuery is called with a ID3D12Device*, the GetExternalProviders is going to leak the resource.
ffxQueryDescGetVersions versionsDesc{
.header{
.type = FFX_API_QUERY_DESC_TYPE_GET_VERSIONS,
},
.createDescType = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE,
.device = device,
.outputCount = &versionCount,
};
ffxQuery(nullptr, &versionsDesc.header);
The GetExternalProviders creates an IAmdExtFfxApi* object which holds a reference to the device
HRESULT hr = AmdExtD3DCreateInterface(device, IID_PPV_ARGS(&apiExtension));
but this IAmdExtFfxApi* is a function visible global pointer which never will be released.
I understand that the intention behind this function visible global pointer was to cache the IAmdExtFfxApi* but now at teardown of engine and hardware abstraction layer the engine's ID3D12Device* can not be released due to the increased refence count by static IAmdExtFfxApi* apiExtension.
during ffxDestroyContext this cache should be released as well.
While this problem exists, we are going to use a workaround in our projects https://github.com/GaijinEntertainment/FidelityFX-SDK/commit/64fa37e6c022be47b584b3e6cdd3a5023c8dcdfb
Would a Global reference counter for IAmdExtFfxApi* apiExtension solve the problem?
Unfortunately no, or at least with the 2.0.0 SDK and that splat DLLs wouldn't.
I was practicing a RAII encapsulation for this IAmdExtFfxApi apiExtension object, but without luck
We load the amd_fidelityfx_loader_dx12.dll and that internally loads the amd_fidelityfx_upscaler_dx12.dll. The upscaler dll contains the apiExtension. As i called the unload for amd_fidelityfx_loader_dx12.dll, it didn't call immediately the amd_fidelityfx_upscaler_dx12.dll's unload , and the destructor for apiExtension's RAII encapsulation. Therefore after the unload of FSR, at the call of D3D12Device's release, the upscaler still can hold reference for the device.
It can work only if the FreeLibrary(ffx_loader_handle); immediately calls all dependencies FreeLibrarys' as well to release the global objects.