[client] egl: prepare for DXGI HDR10 support

This commit is contained in:
Geoffrey McRae
2023-10-27 01:03:22 +11:00
parent 200b7b732c
commit 2f36aaff5c
6 changed files with 24 additions and 9 deletions

View File

@@ -53,6 +53,7 @@ struct DesktopShader
GLint uIsHDR;
GLint uMapHDRtoSDR;
GLint uMapHDRGain;
GLint uMapHDRPQ;
};
struct EGL_Desktop
@@ -68,6 +69,7 @@ struct EGL_Desktop
// internals
int width, height;
bool hdr;
bool hdrPQ;
LG_RendererRotate rotate;
bool useSpice;
@@ -125,6 +127,7 @@ static bool egl_initDesktopShader(
shader->uIsHDR = egl_shaderGetUniform(shader->shader, "isHDR" );
shader->uMapHDRtoSDR = egl_shaderGetUniform(shader->shader, "mapHDRtoSDR" );
shader->uMapHDRGain = egl_shaderGetUniform(shader->shader, "mapHDRGain" );
shader->uMapHDRPQ = egl_shaderGetUniform(shader->shader, "mapHDRPQ" );
return true;
}
@@ -342,6 +345,7 @@ bool egl_desktopSetup(EGL_Desktop * desktop, const LG_RendererFormat format)
desktop->width = format.frameWidth;
desktop->height = format.frameHeight;
desktop->hdr = format.hdr;
desktop->hdrPQ = format.hdrPQ;
if (!egl_textureSetup(
desktop->texture,
@@ -538,6 +542,11 @@ bool egl_desktopRender(EGL_Desktop * desktop, unsigned int outputWidth,
.type = EGL_UNIFORM_TYPE_1F,
.location = shader->uMapHDRGain,
.f = { mapHDRGain }
},
{
.type = EGL_UNIFORM_TYPE_1I,
.location = shader->uMapHDRPQ,
.f = { desktop->hdrPQ }
}
};

View File

@@ -23,6 +23,7 @@ uniform int cbMode;
uniform bool isHDR;
uniform bool mapHDRtoSDR;
uniform float mapHDRGain;
uniform bool mapHDRPQ;
void main()
{
@@ -43,7 +44,7 @@ void main()
}
if (isHDR && mapHDRtoSDR)
color.rgb = mapToSDR(color.rgb, mapHDRGain);
color.rgb = mapToSDR(color.rgb, mapHDRGain, mapHDRPQ);
if (cbMode > 0)
color = cbTransform(color, cbMode);

View File

@@ -40,7 +40,7 @@ float midGain(vec3 pixel)
min(pixel.r, pixel.g)); // min = b
}
vec3 compress(vec3 pixel, float gain)
vec3 compress(vec3 pixel)
{
float maxGain = maxGain(pixel);
return pixel * (maxGain < knee ? maxGain :
@@ -99,8 +99,10 @@ vec3 bt2020to709(vec3 bt2020)
bt2020.r * -0.0182 + bt2020.g * -0.1006 + bt2020.b * 1.1187);
}
vec3 mapToSDR(vec3 color, float gain)
vec3 mapToSDR(vec3 color, float gain, bool pq)
{
vec3 lin = bt2020to709(pq2lin(color.rgb, gain));
return lin2srgb(compress(lin, gain));
if (pq)
color = pq2lin(color.rgb, gain);
color = bt2020to709(color);
return lin2srgb(compress(color));
}