Make sure we actually have an HDR10 texture in the HDR10 shader

Some content uses the PQ transfer function but different color primaries
This commit is contained in:
Sam Lantinga 2024-02-22 11:50:58 -08:00
parent f4dd0dbbde
commit aeae202207
4 changed files with 15 additions and 16 deletions

View File

@ -1497,7 +1497,18 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
}
}
if (format == surface->format->format) {
if (surface_colorspace == SDL_COLORSPACE_SRGB_LINEAR ||
SDL_COLORSPACETRANSFER(surface_colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ) {
if (SDL_ISPIXELFORMAT_FLOAT(format)) {
texture_colorspace = SDL_COLORSPACE_SRGB_LINEAR;
} else if (SDL_ISPIXELFORMAT_10BIT(format)) {
texture_colorspace = SDL_COLORSPACE_HDR10;
} else {
texture_colorspace = SDL_COLORSPACE_SRGB;
}
}
if (format == surface->format->format && texture_colorspace == surface_colorspace) {
if (surface->format->Amask && SDL_SurfaceHasColorKey(surface)) {
/* Surface and Renderer formats are identical.
* Intermediate conversion is needed to convert color key to alpha (SDL_ConvertColorkeyToAlpha()). */
@ -1511,15 +1522,6 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
direct_update = SDL_FALSE;
}
if ((SDL_COLORSPACETRANSFER(surface_colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ && !SDL_ISPIXELFORMAT_10BIT(format)) ||
surface_colorspace == SDL_COLORSPACE_SRGB_LINEAR) {
if (SDL_ISPIXELFORMAT_FLOAT(format)) {
texture_colorspace = SDL_COLORSPACE_SRGB_LINEAR;
} else {
texture_colorspace = SDL_COLORSPACE_SRGB;
}
}
if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
surface_props = SDL_GetSurfaceProperties(surface);
} else {

View File

@ -2201,8 +2201,7 @@ static void D3D11_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderC
constants->texture_type = TEXTURETYPE_RGB;
if (texture->colorspace == SDL_COLORSPACE_SRGB_LINEAR) {
constants->input_type = INPUTTYPE_SCRGB;
} else if (SDL_COLORSPACEPRIMARIES(texture->colorspace) == SDL_COLOR_PRIMARIES_BT2020 &&
SDL_COLORSPACETRANSFER(texture->colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ) {
} else if (texture->colorspace == SDL_COLORSPACE_HDR10) {
constants->input_type = INPUTTYPE_HDR10;
} else {
constants->input_type = INPUTTYPE_UNSPECIFIED;

View File

@ -2551,8 +2551,7 @@ static void D3D12_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderC
constants->texture_type = TEXTURETYPE_RGB;
if (texture->colorspace == SDL_COLORSPACE_SRGB_LINEAR) {
constants->input_type = INPUTTYPE_SCRGB;
} else if (SDL_COLORSPACEPRIMARIES(texture->colorspace) == SDL_COLOR_PRIMARIES_BT2020 &&
SDL_COLORSPACETRANSFER(texture->colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ) {
} else if (texture->colorspace == SDL_COLORSPACE_HDR10) {
constants->input_type = INPUTTYPE_HDR10;
} else {
constants->input_type = INPUTTYPE_UNSPECIFIED;

View File

@ -1366,8 +1366,7 @@ static void SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand
constants->texture_type = TEXTURETYPE_RGB;
if (texture->colorspace == SDL_COLORSPACE_SRGB_LINEAR) {
constants->input_type = INPUTTYPE_SCRGB;
} else if (SDL_COLORSPACEPRIMARIES(texture->colorspace) == SDL_COLOR_PRIMARIES_BT2020 &&
SDL_COLORSPACETRANSFER(texture->colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ) {
} else if (texture->colorspace == SDL_COLORSPACE_HDR10) {
constants->input_type = INPUTTYPE_HDR10;
} else {
constants->input_type = INPUTTYPE_UNSPECIFIED;