Skip to content

Commit

Permalink
SDL: Swapchain changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcosmonaut committed May 30, 2024
1 parent 69ca465 commit 28d05ba
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/FNA3D_Driver_SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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
)) {
Expand All @@ -2418,7 +2423,7 @@ static void SDLGPU_ResetBackbuffer(
SDL_GpuSetSwapchainParameters(
renderer->device,
presentationParameters->deviceWindowHandle,
colorSpace,
swapchainComposition,
presentMode
);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
)) {
Expand All @@ -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!");
Expand Down

0 comments on commit 28d05ba

Please sign in to comment.