rendervulkan: Fix NV12 capture colors

Closes: #1014
This commit is contained in:
Joshua Ashton 2023-11-14 20:09:04 +00:00
parent 4d4cc40440
commit 274d2a6555
3 changed files with 18 additions and 8 deletions

View file

@ -3368,7 +3368,8 @@ struct CaptureConvertBlitData_t
vec2_t scale[1];
vec2_t offset[1];
float opacity[1];
mat3x4 ctm[1];
glm::mat3x4 ctm[1];
mat3x4 outputCTM;
uint32_t borderMask;
uint32_t halfExtent[2];
@ -3377,7 +3378,13 @@ struct CaptureConvertBlitData_t
offset[0] = { 0.0f, 0.0f };
opacity[0] = 1.0f;
borderMask = 0;
ctm[0] = color_matrix;
ctm[0] = glm::mat3x4
{
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0
};
outputCTM = color_matrix;
}
};
@ -3752,7 +3759,7 @@ bool vulkan_composite( struct FrameInfo_t *frameInfo, std::shared_ptr<CVulkanTex
for (uint32_t i = 0; i < EOTF_Count; i++)
cmdBuffer->bindColorMgmtLuts(i, nullptr, nullptr);
cmdBuffer->bindPipeline(g_device.pipeline( ycbcr ? SHADER_TYPE_RGB_TO_NV12 : SHADER_TYPE_BLIT, 1, 0, 0, GAMESCOPE_APP_TEXTURE_COLORSPACE_SRGB, EOTF_Gamma22 ));
cmdBuffer->bindPipeline(g_device.pipeline( ycbcr ? SHADER_TYPE_RGB_TO_NV12 : SHADER_TYPE_BLIT, 1, 0, 0, GAMESCOPE_APP_TEXTURE_COLORSPACE_SRGB, EOTF_Count ));
cmdBuffer->bindTexture(0, compositeImage);
cmdBuffer->setTextureSrgb(0, true);
cmdBuffer->setSamplerNearest(0, false);

View file

@ -17,7 +17,7 @@ layout(
// UVUVUVUVUVUVUVU...
const uint u_frameId = 0;
const uint8_t u_shaderFilter[VKR_MAX_LAYERS] = { uint8_t(0), uint8_t(0), uint8_t(0), uint8_t(0), uint8_t(0), uint8_t(0) };
const uint8_t u_shaderFilter[VKR_MAX_LAYERS] = { uint8_t(filter_linear_emulated), uint8_t(0), uint8_t(0), uint8_t(0), uint8_t(0), uint8_t(0) };
const float u_linearToNits = 400.0f;
const float u_nitsToLinear = 1.0f / 100.0f;
const float u_itmSdrNits = 100.f;
@ -29,6 +29,7 @@ uniform layers_t {
vec2 u_offset[1];
float u_opacity[1];
mat3x4 u_ctm[1];
mat3x4 u_outputCTM;
uint u_borderMask;
uvec2 u_halfExtent;
};
@ -63,11 +64,11 @@ void main() {
};
vec3 avg_color = (color[0] + color[1] + color[2] + color[3]) / 4.0f;
vec2 uv = applyColorMatrix(avg_color, u_ctm[0]).yz;
vec2 uv = applyColorMatrix(avg_color, u_outputCTM).yz;
imageStore(dst_chroma, chroma_uv, vec4(uv, 0.0f, 1.0f));
for (int i = 0; i < 4; i++) {
float y = applyColorMatrix(color[i], u_ctm[0]).x;
float y = applyColorMatrix(color[i], u_outputCTM).x;
imageStore(dst_luma, luma_uv + offset_table[i], vec4(y, 0.0f, 0.0f, 1.0f));
}
}

View file

@ -2980,7 +2980,7 @@ paint_all(bool async)
if ( pScreenshotTexture )
{
if ( takeScreenshot != TAKE_SCREENSHOT_SCREEN_BUFFER )
if ( drmCaptureFormat == DRM_FORMAT_NV12 || takeScreenshot != TAKE_SCREENSHOT_SCREEN_BUFFER )
{
// Basically no color mgmt applied for screenshots. (aside from being able to handle HDR content with LUTs)
for ( uint32_t nInputEOTF = 0; nInputEOTF < EOTF_Count; nInputEOTF++ )
@ -3027,7 +3027,9 @@ paint_all(bool async)
frameInfo.applyOutputColorMgmt = true;
bool bResult;
if ( takeScreenshot == TAKE_SCREENSHOT_FULL_COMPOSITION || takeScreenshot == TAKE_SCREENSHOT_SCREEN_BUFFER )
if ( drmCaptureFormat == DRM_FORMAT_NV12 )
bResult = vulkan_composite( &frameInfo, pScreenshotTexture, false, false, nullptr );
else if ( takeScreenshot == TAKE_SCREENSHOT_FULL_COMPOSITION || takeScreenshot == TAKE_SCREENSHOT_SCREEN_BUFFER )
bResult = vulkan_composite( &frameInfo, nullptr, false, false, pScreenshotTexture );
else
bResult = vulkan_screenshot( &frameInfo, pScreenshotTexture );