Browse Source

gpu: Xbox fixes for swapchain presentation

Ethan Lee 8 months ago
parent
commit
7e8576fd19
1 changed files with 25 additions and 20 deletions
  1. 25 20
      src/gpu/d3d12/SDL_gpu_d3d12.c

+ 25 - 20
src/gpu/d3d12/SDL_gpu_d3d12.c

@@ -6374,6 +6374,9 @@ static bool D3D12_INTERNAL_CreateSwapchain(
     SDL_SyncWindow(windowData->window);
     SDL_SyncWindow(windowData->window);
     SDL_GetWindowSizeInPixels(windowData->window, &width, &height);
     SDL_GetWindowSizeInPixels(windowData->window, &width, &height);
 
 
+    // Min swapchain image count is 2
+    windowData->swapchainTextureCount = SDL_clamp(renderer->allowedFramesInFlight, 2, 3);
+
     // Create the swapchain textures
     // Create the swapchain textures
     SDL_zero(createInfo);
     SDL_zero(createInfo);
     createInfo.type = SDL_GPU_TEXTURETYPE_2D;
     createInfo.type = SDL_GPU_TEXTURETYPE_2D;
@@ -8691,26 +8694,6 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
             CHECK_D3D12_ERROR_AND_RETURN("Could not create D3D12Device", NULL);
             CHECK_D3D12_ERROR_AND_RETURN("Could not create D3D12Device", NULL);
         }
         }
 
 
-        res = renderer->device->SetFrameIntervalX(
-            NULL,
-            D3D12XBOX_FRAME_INTERVAL_60_HZ,
-            renderer->allowedFramesInFlight - 1,
-            D3D12XBOX_FRAME_INTERVAL_FLAG_NONE);
-        if (FAILED(res)) {
-            D3D12_INTERNAL_DestroyRenderer(renderer);
-            CHECK_D3D12_ERROR_AND_RETURN("Could not get set frame interval", NULL);
-        }
-
-        res = renderer->device->ScheduleFrameEventX(
-            D3D12XBOX_FRAME_EVENT_ORIGIN,
-            0,
-            NULL,
-            D3D12XBOX_SCHEDULE_FRAME_EVENT_FLAG_NONE);
-        if (FAILED(res)) {
-            D3D12_INTERNAL_DestroyRenderer(renderer);
-            CHECK_D3D12_ERROR_AND_RETURN("Could not schedule frame events", NULL);
-        }
-
         s_Device = renderer->device;
         s_Device = renderer->device;
     }
     }
 #else
 #else
@@ -8980,6 +8963,28 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
     // Blit resources
     // Blit resources
     D3D12_INTERNAL_InitBlitResources(renderer);
     D3D12_INTERNAL_InitBlitResources(renderer);
 
 
+#if (defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
+    res = renderer->device->SetFrameIntervalX(
+        NULL,
+        D3D12XBOX_FRAME_INTERVAL_60_HZ,
+        renderer->allowedFramesInFlight - 1,
+        D3D12XBOX_FRAME_INTERVAL_FLAG_NONE);
+    if (FAILED(res)) {
+        D3D12_INTERNAL_DestroyRenderer(renderer);
+        CHECK_D3D12_ERROR_AND_RETURN("Could not get set frame interval", NULL);
+    }
+
+    res = renderer->device->ScheduleFrameEventX(
+        D3D12XBOX_FRAME_EVENT_ORIGIN,
+        0,
+        NULL,
+        D3D12XBOX_SCHEDULE_FRAME_EVENT_FLAG_NONE);
+    if (FAILED(res)) {
+        D3D12_INTERNAL_DestroyRenderer(renderer);
+        CHECK_D3D12_ERROR_AND_RETURN("Could not schedule frame events", NULL);
+    }
+#endif
+
     // Create the SDL_GPU Device
     // Create the SDL_GPU Device
     result = (SDL_GPUDevice *)SDL_calloc(1, sizeof(SDL_GPUDevice));
     result = (SDL_GPUDevice *)SDL_calloc(1, sizeof(SDL_GPUDevice));