Skip to content

Commit

Permalink
rendervulkan: Fix NV12 capture colors
Browse files Browse the repository at this point in the history
Closes: #1014
  • Loading branch information
misyltoad committed Nov 14, 2023
1 parent 4d4cc40 commit 274d2a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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;
}
};

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/shaders/cs_rgb_to_nv12.comp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};
Expand Down Expand Up @@ -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));
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++ )
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 274d2a6

Please sign in to comment.