Skip to content

Commit

Permalink
[client] egl: prepare for DXGI HDR10 support
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Oct 26, 2023
1 parent 200b7b7 commit 2f36aaf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions client/include/interface/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef struct LG_RendererFormat
{
FrameType type; // frame type
bool hdr; // if the frame is HDR or not
bool hdrPQ; // if the HDR content is PQ mapped
unsigned int screenWidth; // actual width of the host
unsigned int screenHeight; // actual height of the host
unsigned int frameWidth; // width of frame transmitted
Expand Down
9 changes: 9 additions & 0 deletions client/renderers/EGL/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct DesktopShader
GLint uIsHDR;
GLint uMapHDRtoSDR;
GLint uMapHDRGain;
GLint uMapHDRPQ;
};

struct EGL_Desktop
Expand All @@ -68,6 +69,7 @@ struct EGL_Desktop
// internals
int width, height;
bool hdr;
bool hdrPQ;
LG_RendererRotate rotate;

bool useSpice;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 }
}
};

Expand Down
3 changes: 2 additions & 1 deletion client/renderers/EGL/shader/desktop_rgb.frag
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ uniform int cbMode;
uniform bool isHDR;
uniform bool mapHDRtoSDR;
uniform float mapHDRGain;
uniform bool mapHDRPQ;

void main()
{
Expand All @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions client/renderers/EGL/shader/hdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down Expand Up @@ -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));
}
1 change: 1 addition & 0 deletions client/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ int main_frameThread(void * unused)
lgrFormat.stride = frame->stride;
lgrFormat.pitch = frame->pitch;
lgrFormat.hdr = frame->flags & FRAME_FLAG_HDR;
lgrFormat.hdrPQ = frame->flags & FRAME_FLAG_HDR_PQ;

if (frame->flags & FRAME_FLAG_TRUNCATED)
{
Expand Down
9 changes: 5 additions & 4 deletions common/include/common/KVMFR.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ KVMFRCursor;

enum
{
FRAME_FLAG_BLOCK_SCREENSAVER = 0x1,
FRAME_FLAG_REQUEST_ACTIVATION = 0x2,
FRAME_FLAG_TRUNCATED = 0x4, // ivshmem was too small for the frame
FRAME_FLAG_HDR = 0x8 // RGBA10 may not be HDR
FRAME_FLAG_BLOCK_SCREENSAVER = 0x1 ,
FRAME_FLAG_REQUEST_ACTIVATION = 0x2 ,
FRAME_FLAG_TRUNCATED = 0x4 , // ivshmem was too small for the frame
FRAME_FLAG_HDR = 0x8 , // RGBA10 may not be HDR
FRAME_FLAG_HDR_PQ = 0x10 // HDR PQ has been applied to the frame
};

typedef uint32_t KVMFRFrameFlags;
Expand Down

0 comments on commit 2f36aaf

Please sign in to comment.