Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sRGB backbuffers on the SDL_GPU and D3D11 backends #240

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/FNA3D_Driver_D3D11.c
Original file line number Diff line number Diff line change
Expand Up @@ -2571,6 +2571,7 @@ static void D3D11_INTERNAL_CreateSwapChain(
DXGI_COLOR_SPACE_TYPE colorSpace;
HRESULT res;

uint8_t sRGB = 0;
uint8_t growSwapchains = (swapchainData == NULL);

#ifdef FNA3D_DXVK_NATIVE
Expand All @@ -2595,7 +2596,15 @@ static void D3D11_INTERNAL_CreateSwapChain(
swapchainDesc.BufferDesc.Height = 0;
swapchainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapchainDesc.BufferDesc.RefreshRate.Denominator = 0;
swapchainDesc.BufferDesc.Format = XNAToD3D_TextureFormat[backBufferFormat];
if (backBufferFormat == FNA3D_SURFACEFORMAT_COLORSRGB_EXT)
{
sRGB = 1;
swapchainDesc.BufferDesc.Format = XNAToD3D_TextureFormat[FNA3D_SURFACEFORMAT_COLOR];
}
else
{
swapchainDesc.BufferDesc.Format = XNAToD3D_TextureFormat[backBufferFormat];
}
swapchainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapchainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

Expand Down Expand Up @@ -2683,7 +2692,7 @@ static void D3D11_INTERNAL_CreateSwapChain(
}

/* Set colorspace, if applicable */
if (SDL_GetHintBoolean("FNA3D_ENABLE_HDR_COLORSPACE", SDL_FALSE))
if (SDL_GetHintBoolean("FNA3D_ENABLE_HDR_COLORSPACE", SDL_FALSE) || sRGB)
{
if (SUCCEEDED(IDXGISwapChain_QueryInterface(
swapchain,
Expand All @@ -2699,11 +2708,17 @@ static void D3D11_INTERNAL_CreateSwapChain(
{
colorSpace = DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709;
}
else if (sRGB)
{
colorSpace = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the else cover this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this or the other else are both the correct color space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some more testing and it seems like they're right, but it feels like either the sRGB or non-sRGB arm should be G10 so I'm not sure what's going on.

}
else
{
colorSpace = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;
}
IDXGISwapChain3_SetColorSpace1(swapchain3, colorSpace);

IDXGISwapChain_Release(swapchain);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/FNA3D_Driver_SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,9 @@ static void SDLGPU_ResetBackbuffer(
presentationParameters
);

swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_SDR;
swapchainComposition = (presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_COLORSRGB_EXT)
? SDL_GPU_SWAPCHAINCOMPOSITION_SDR_LINEAR
: SDL_GPU_SWAPCHAINCOMPOSITION_SDR;

if (SDL_GetHintBoolean("FNA3D_ENABLE_HDR_COLORSPACE", false))
{
Expand Down