[host] dxgi: fix failure to call FreeLibrary for d3d12

This commit is contained in:
Geoffrey McRae 2023-11-11 20:31:53 +11:00
parent 75e10688d4
commit 503efdd0d8

View File

@ -52,6 +52,7 @@ struct SharedCache
struct D3D12Backend struct D3D12Backend
{ {
HMODULE d3d12;
unsigned width, height, pitch; unsigned width, height, pitch;
DXGI_FORMAT format; DXGI_FORMAT format;
@ -90,17 +91,28 @@ static void d3d12_free(void);
static bool d3d12_create(unsigned textures) static bool d3d12_create(unsigned textures)
{ {
DEBUG_ASSERT(!this); DEBUG_ASSERT(!this);
comRef_scopePush();
bool result = false;
HRESULT status; HRESULT status;
HMODULE d3d12 = LoadLibrary("d3d12.dll"); this = calloc(1,
if (!d3d12) sizeof(struct D3D12Backend) +
return false; sizeof(*this->texture) * textures);
if (!this)
{
DEBUG_ERROR("failed to allocate D3D12Backend struct");
goto exit;
}
this->d3d12 = LoadLibrary("d3d12.dll");
if (!this->d3d12)
goto exit;
if (dxgi_debug()) if (dxgi_debug())
{ {
D3D12GetDebugInterface_t D3D12GetDebugInterface = (D3D12GetDebugInterface_t) D3D12GetDebugInterface_t D3D12GetDebugInterface = (D3D12GetDebugInterface_t)
GetProcAddress(d3d12, "D3D12GetDebugInterface"); GetProcAddress(this->d3d12, "D3D12GetDebugInterface");
ID3D12Debug1 * debug; ID3D12Debug1 * debug;
if (FAILED(status = D3D12GetDebugInterface(&IID_ID3D12Debug1, (void **)&debug))) if (FAILED(status = D3D12GetDebugInterface(&IID_ID3D12Debug1, (void **)&debug)))
DEBUG_WINERROR("D3D12GetDebugInterface", status); DEBUG_WINERROR("D3D12GetDebugInterface", status);
@ -114,28 +126,15 @@ static bool d3d12_create(unsigned textures)
} }
D3D12CreateDevice_t D3D12CreateDevice = (D3D12CreateDevice_t) D3D12CreateDevice_t D3D12CreateDevice = (D3D12CreateDevice_t)
GetProcAddress(d3d12, "D3D12CreateDevice"); GetProcAddress(this->d3d12, "D3D12CreateDevice");
if (!D3D12CreateDevice) if (!D3D12CreateDevice)
return false; goto exit;
this = calloc(1,
sizeof(struct D3D12Backend) +
sizeof(*this->texture) * textures);
if (!this)
{
DEBUG_ERROR("failed to allocate D3D12Backend struct");
return false;
}
this->textures = textures; this->textures = textures;
this->copySleep = option_get_float("dxgi", "d3d12CopySleep"); this->copySleep = option_get_float("dxgi", "d3d12CopySleep");
DEBUG_INFO("Sleep before copy : %f ms", this->copySleep); DEBUG_INFO("Sleep before copy : %f ms", this->copySleep);
bool result = false;
comRef_scopePush();
comRef_defineLocal(ID3D12Device, device); comRef_defineLocal(ID3D12Device, device);
status = D3D12CreateDevice((IUnknown *)dxgi_getAdapter(), status = D3D12CreateDevice((IUnknown *)dxgi_getAdapter(),
D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)device); D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)device);
@ -336,6 +335,9 @@ static void d3d12_free(void)
if (this->event) if (this->event)
CloseHandle(this->event); CloseHandle(this->event);
if (this->d3d12)
FreeLibrary(this->d3d12);
free(this); free(this);
this = NULL; this = NULL;
} }