From 28d05baa5e05535f1fe7f940caa5fa37a7c14a73 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 30 May 2024 10:52:16 -0700 Subject: [PATCH] SDL: Swapchain changes --- src/FNA3D_Driver_SDL.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/FNA3D_Driver_SDL.c b/src/FNA3D_Driver_SDL.c index 145d0cda..9d684182 100644 --- a/src/FNA3D_Driver_SDL.c +++ b/src/FNA3D_Driver_SDL.c @@ -261,6 +261,7 @@ static SDL_GpuStencilOp XNAToSDL_StencilOp[] = static inline SDL_bool XNAToSDL_PresentMode( SDL_GpuDevice *device, + SDL_Window *window, FNA3D_PresentInterval interval, SDL_GpuPresentMode *presentMode ) { @@ -271,7 +272,7 @@ static inline SDL_bool XNAToSDL_PresentMode( if (SDL_GetHintBoolean("FNA3D_VULKAN_FORCE_MAILBOX_VSYNC", 0)) { *presentMode = SDL_GPU_PRESENTMODE_MAILBOX; - if (!SDL_GpuSupportsPresentMode(device, *presentMode)) + if (!SDL_GpuSupportsPresentMode(device, window, *presentMode)) { *presentMode = SDL_GPU_PRESENTMODE_VSYNC; } @@ -285,7 +286,7 @@ static inline SDL_bool XNAToSDL_PresentMode( else if (interval == FNA3D_PRESENTINTERVAL_IMMEDIATE) { *presentMode = SDL_GPU_PRESENTMODE_IMMEDIATE; - if (!SDL_GpuSupportsPresentMode(device, *presentMode)) + if (!SDL_GpuSupportsPresentMode(device, window, *presentMode)) { *presentMode = SDL_GPU_PRESENTMODE_VSYNC; } @@ -1096,10 +1097,13 @@ static void SDLGPU_INTERNAL_BeginRenderPass( &gpuViewport ); - SDL_GpuSetScissor( - renderer->renderPass, - &renderer->scissorRect - ); + if (renderer->fnaRasterizerState.scissorTestEnable) + { + SDL_GpuSetScissor( + renderer->renderPass, + &renderer->scissorRect + ); + } renderer->needNewRenderPass = 0; @@ -1892,7 +1896,7 @@ static void SDLGPU_SetScissorRect( renderer->scissorRect.w = scissor->w; renderer->scissorRect.h = scissor->h; - if (renderer->renderPassInProgress) + if (renderer->renderPassInProgress && renderer->fnaRasterizerState.scissorTestEnable) { SDL_GpuSetScissor( renderer->renderPass, @@ -2380,7 +2384,7 @@ static void SDLGPU_ResetBackbuffer( FNA3D_PresentationParameters *presentationParameters ) { SDLGPU_Renderer *renderer = (SDLGPU_Renderer*) driverData; - SDL_GpuColorSpace colorSpace; + SDL_GpuSwapchainComposition swapchainComposition; SDL_GpuPresentMode presentMode; SDLGPU_INTERNAL_FlushCommandsAndStall(renderer); @@ -2391,23 +2395,24 @@ static void SDLGPU_ResetBackbuffer( presentationParameters ); - colorSpace = SDL_GPU_COLORSPACE_NONLINEAR_SRGB; + swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_SDR; if (SDL_GetHintBoolean("FNA3D_ENABLE_HDR_COLORSPACE", SDL_FALSE)) { if (presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_RGBA1010102) { - colorSpace = SDL_GPU_COLORSPACE_HDR10_ST2048; + swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048; } else if ( presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_HALFVECTOR4 || presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_HDRBLENDABLE ) { - colorSpace = SDL_GPU_COLORSPACE_LINEAR_SRGB; + swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_HDR_EXTENDED_LINEAR; } } if (!XNAToSDL_PresentMode( renderer->device, + presentationParameters->deviceWindowHandle, presentationParameters->presentationInterval, &presentMode )) { @@ -2418,7 +2423,7 @@ static void SDLGPU_ResetBackbuffer( SDL_GpuSetSwapchainParameters( renderer->device, presentationParameters->deviceWindowHandle, - colorSpace, + swapchainComposition, presentMode ); @@ -3986,7 +3991,7 @@ static FNA3D_Device* SDLGPU_CreateDevice( ) { SDLGPU_Renderer *renderer; SDL_GpuDevice *device; - SDL_GpuColorSpace colorSpace; + SDL_GpuSwapchainComposition swapchainComposition; SDL_GpuTextureCreateInfo textureCreateInfo; SDL_GpuSamplerStateCreateInfo samplerCreateInfo; SDL_GpuPresentMode desiredPresentMode; @@ -4015,23 +4020,24 @@ static FNA3D_Device* SDLGPU_CreateDevice( result->driverData = (FNA3D_Renderer*) renderer; - colorSpace = SDL_GPU_COLORSPACE_NONLINEAR_SRGB; + swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_SDR; if (SDL_GetHintBoolean("FNA3D_ENABLE_HDR_COLORSPACE", SDL_FALSE)) { if (presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_RGBA1010102) { - colorSpace = SDL_GPU_COLORSPACE_HDR10_ST2048; + swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048; } else if ( presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_HALFVECTOR4 || presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_HDRBLENDABLE ) { - colorSpace = SDL_GPU_COLORSPACE_LINEAR_SRGB; + swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_HDR_EXTENDED_LINEAR; } } if (!XNAToSDL_PresentMode( renderer->device, + presentationParameters->deviceWindowHandle, presentationParameters->presentationInterval, &desiredPresentMode )) { @@ -4044,7 +4050,7 @@ static FNA3D_Device* SDLGPU_CreateDevice( if (!SDL_GpuClaimWindow( renderer->device, presentationParameters->deviceWindowHandle, - colorSpace, + swapchainComposition, desiredPresentMode )) { FNA3D_LogError("Failed to claim window!");