Skip to content

Commit

Permalink
Improved D3D12 handling of unrecoverable device loss
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 21, 2024
1 parent 315842c commit 92520c1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/render/direct3d12/SDL_render_d3d12.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,12 +1338,14 @@ D3D12_HandleDeviceLost(SDL_Renderer *renderer)
result = D3D12_CreateDeviceResources(renderer);
if (FAILED(result)) {
// D3D12_CreateDeviceResources will set the SDL error
D3D12_ReleaseAll(renderer);
return result;
}

result = D3D12_UpdateForWindowSizeChange(renderer);
if (FAILED(result)) {
// D3D12_UpdateForWindowSizeChange will set the SDL error
D3D12_ReleaseAll(renderer);
return result;
}

Expand Down Expand Up @@ -2830,6 +2832,10 @@ static bool D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd
D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal;
const int viewportRotation = D3D12_GetRotationForCurrentRenderTarget(renderer);

if (!rendererData->d3dDevice) {
return SDL_SetError("Device lost and couldn't be recovered");
}

if (rendererData->pixelSizeChanged) {
D3D12_UpdateForWindowSizeChange(renderer);
rendererData->pixelSizeChanged = false;
Expand Down Expand Up @@ -3113,6 +3119,10 @@ static bool D3D12_RenderPresent(SDL_Renderer *renderer)
D3D12_RenderData *data = (D3D12_RenderData *)renderer->internal;
HRESULT result;

if (!data->d3dDevice) {
return SDL_SetError("Device lost and couldn't be recovered");
}

// Transition the render target to present state
D3D12_TransitionResource(data,
data->renderTargets[data->currentBackBufferIndex],
Expand Down

0 comments on commit 92520c1

Please sign in to comment.