Initial work on DestroyDevice

d3d11-revived
Caleb Cornett 2023-10-12 08:42:32 -05:00
parent 0f1a2423d0
commit 741d3ebcff
1 changed files with 79 additions and 23 deletions

View File

@ -82,7 +82,6 @@
); \ ); \
} }
/* D3DCompile signature */ /* D3DCompile signature */
typedef HRESULT(WINAPI *PFN_D3DCOMPILE)( typedef HRESULT(WINAPI *PFN_D3DCOMPILE)(
@ -102,6 +101,10 @@ typedef HRESULT(WINAPI *PFN_D3DCOMPILE)(
/* Forward Declarations */ /* Forward Declarations */
static void D3D11_Wait(Refresh_Renderer *driverData); static void D3D11_Wait(Refresh_Renderer *driverData);
static void D3D11_UnclaimWindow(
Refresh_Renderer * driverData,
void *windowHandle
);
/* Conversions */ /* Conversions */
@ -354,7 +357,7 @@ typedef struct D3D11Renderer
uint32_t claimedWindowCount; uint32_t claimedWindowCount;
uint32_t claimedWindowCapacity; uint32_t claimedWindowCapacity;
D3D11CommandBufferPool *commandBufferPool; D3D11CommandBufferPool commandBufferPool;
SDL_mutex *contextLock; SDL_mutex *contextLock;
SDL_mutex *acquireCommandBufferLock; SDL_mutex *acquireCommandBufferLock;
@ -427,7 +430,54 @@ static void D3D11_INTERNAL_LogError(
static void D3D11_DestroyDevice( static void D3D11_DestroyDevice(
Refresh_Device *device Refresh_Device *device
) { ) {
NOT_IMPLEMENTED D3D11Renderer *renderer = (D3D11Renderer*) device->driverData;
D3D11CommandBuffer *commandBuffer;
int32_t i;
D3D11_Wait(device->driverData);
/* Release the window data */
for (i = renderer->claimedWindowCount - 1; i >= 0; i -= 1)
{
D3D11_UnclaimWindow(device->driverData, renderer->claimedWindows[i]->windowHandle);
}
SDL_free(renderer->claimedWindows);
D3D11_Wait(device->driverData); /* FIXME: Copied this from Vulkan, is it actually necessary? */
/* Release command buffer infrastructure */
SDL_free(renderer->submittedCommandBuffers);
for (i = 0; i < renderer->commandBufferPool.count; i += 1)
{
commandBuffer = renderer->commandBufferPool.elements[i];
ID3D11Query_Release(commandBuffer->completionQuery);
ID3D11DeviceContext_Release(commandBuffer->context);
SDL_free(commandBuffer);
}
/* Release the mutexes */
SDL_DestroyMutex(renderer->acquireCommandBufferLock);
SDL_DestroyMutex(renderer->contextLock);
/* Release the DLLs and D3D11 device infrastructure */
SDL_UnloadObject(renderer->d3d11_dll);
SDL_UnloadObject(renderer->d3dcompiler_dll);
ID3D11DeviceContext_Release(renderer->immediateContext);
ID3D11Device_Release(renderer->device);
IDXGIAdapter_Release(renderer->adapter);
IDXGIFactory_Release(renderer->factory);
SDL_free(renderer);
SDL_free(device);
} }
/* Drawing */ /* Drawing */
@ -1066,8 +1116,16 @@ static void D3D11_QueueDestroyShaderModule(
Refresh_ShaderModule *shaderModule Refresh_ShaderModule *shaderModule
) { ) {
D3D11ShaderModule *d3dShaderModule = (D3D11ShaderModule*) shaderModule; D3D11ShaderModule *d3dShaderModule = (D3D11ShaderModule*) shaderModule;
ID3D11DeviceChild_Release(d3dShaderModule->shader);
ID3D10Blob_Release(d3dShaderModule->blob); if (d3dShaderModule->shader)
{
ID3D11DeviceChild_Release(d3dShaderModule->shader);
}
if (d3dShaderModule->blob)
{
ID3D10Blob_Release(d3dShaderModule->blob);
}
SDL_free(d3dShaderModule->shaderSource); SDL_free(d3dShaderModule->shaderSource);
SDL_free(d3dShaderModule); SDL_free(d3dShaderModule);
} }
@ -1102,7 +1160,7 @@ static void D3D11_INTERNAL_AllocateCommandBuffers(
D3D11Renderer *renderer, D3D11Renderer *renderer,
uint32_t allocateCount uint32_t allocateCount
) { ) {
D3D11CommandBufferPool *pool = renderer->commandBufferPool; D3D11CommandBufferPool *pool = &renderer->commandBufferPool;
D3D11CommandBuffer *commandBuffer; D3D11CommandBuffer *commandBuffer;
D3D11_QUERY_DESC queryDesc; D3D11_QUERY_DESC queryDesc;
HRESULT res; HRESULT res;
@ -1144,19 +1202,19 @@ static void D3D11_INTERNAL_AllocateCommandBuffers(
static D3D11CommandBuffer* D3D11_INTERNAL_GetInactiveCommandBufferFromPool( static D3D11CommandBuffer* D3D11_INTERNAL_GetInactiveCommandBufferFromPool(
D3D11Renderer *renderer D3D11Renderer *renderer
) { ) {
D3D11CommandBufferPool *commandPool = renderer->commandBufferPool; D3D11CommandBufferPool *pool = &renderer->commandBufferPool;
D3D11CommandBuffer *commandBuffer; D3D11CommandBuffer *commandBuffer;
if (commandPool->count == 0) if (pool->count == 0)
{ {
D3D11_INTERNAL_AllocateCommandBuffers( D3D11_INTERNAL_AllocateCommandBuffers(
renderer, renderer,
commandPool->capacity pool->capacity
); );
} }
commandBuffer = commandPool->elements[commandPool->count - 1]; commandBuffer = pool->elements[pool->count - 1];
commandPool->count -= 1; pool->count -= 1;
return commandBuffer; return commandBuffer;
} }
@ -1837,23 +1895,24 @@ static void D3D11_INTERNAL_CleanCommandBuffer(
D3D11Renderer *renderer, D3D11Renderer *renderer,
D3D11CommandBuffer *commandBuffer D3D11CommandBuffer *commandBuffer
) { ) {
D3D11CommandBufferPool *commandBufferPool = &renderer->commandBufferPool;
uint32_t i; uint32_t i;
/* FIXME: All kinds of stuff should go here... */ /* FIXME: All kinds of stuff should go here... */
SDL_LockMutex(renderer->acquireCommandBufferLock); SDL_LockMutex(renderer->acquireCommandBufferLock);
if (renderer->commandBufferPool->count == renderer->commandBufferPool->capacity) if (commandBufferPool->count == commandBufferPool->capacity)
{ {
renderer->commandBufferPool->capacity += 1; commandBufferPool->capacity += 1;
renderer->commandBufferPool->elements = SDL_realloc( commandBufferPool->elements = SDL_realloc(
renderer->commandBufferPool->elements, commandBufferPool->elements,
renderer->commandBufferPool->capacity * sizeof(D3D11CommandBuffer*) commandBufferPool->capacity * sizeof(D3D11CommandBuffer*)
); );
} }
renderer->commandBufferPool->elements[renderer->commandBufferPool->count] = commandBuffer; commandBufferPool->elements[commandBufferPool->count] = commandBuffer;
renderer->commandBufferPool->count += 1; commandBufferPool->count += 1;
SDL_UnlockMutex(renderer->acquireCommandBufferLock); SDL_UnlockMutex(renderer->acquireCommandBufferLock);
@ -2246,11 +2305,8 @@ tryCreateDevice:
Refresh_LogInfo("Refresh Driver: D3D11"); Refresh_LogInfo("Refresh Driver: D3D11");
Refresh_LogInfo("D3D11 Adapter: %S", adapterDesc.Description); Refresh_LogInfo("D3D11 Adapter: %S", adapterDesc.Description);
/* Create the command buffer pool */ /* Initialize the command buffer pool */
renderer->commandBufferPool = (D3D11CommandBufferPool*) SDL_calloc( renderer->commandBufferPool = (D3D11CommandBufferPool) { 0 };
1,
sizeof(D3D11CommandBufferPool)
);
/* Create mutexes */ /* Create mutexes */
renderer->contextLock = SDL_CreateMutex(); renderer->contextLock = SDL_CreateMutex();