Skip to content

Commit

Permalink
steamcompmgr: Use liter vulkan_screenshot for pipewire streams
Browse files Browse the repository at this point in the history
  • Loading branch information
misyltoad committed May 17, 2024
1 parent 64a3476 commit b02d87f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
33 changes: 32 additions & 1 deletion src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3632,7 +3632,7 @@ void bind_all_layers(CVulkanCmdBuffer* cmdBuffer, const struct FrameInfo_t *fram
}
}

std::optional<uint64_t> vulkan_screenshot( const struct FrameInfo_t *frameInfo, std::shared_ptr<CVulkanTexture> pScreenshotTexture )
std::optional<uint64_t> vulkan_screenshot( const struct FrameInfo_t *frameInfo, std::shared_ptr<CVulkanTexture> pScreenshotTexture, std::shared_ptr<CVulkanTexture> pYUVOutTexture )
{
EOTF outputTF = frameInfo->outputEncodingEOTF;
if (!frameInfo->applyOutputColorMgmt)
Expand All @@ -3652,6 +3652,37 @@ std::optional<uint64_t> vulkan_screenshot( const struct FrameInfo_t *frameInfo,

cmdBuffer->dispatch(div_roundup(currentOutputWidth, pixelsPerGroup), div_roundup(currentOutputHeight, pixelsPerGroup));

if ( pYUVOutTexture != nullptr )
{
float scale = (float)pScreenshotTexture->width() / pYUVOutTexture->width();

CaptureConvertBlitData_t constants( scale, colorspace_to_conversion_from_srgb_matrix( pScreenshotTexture->streamColorspace() ) );
constants.halfExtent[0] = pYUVOutTexture->width() / 2.0f;
constants.halfExtent[1] = pYUVOutTexture->height() / 2.0f;
cmdBuffer->uploadConstants<CaptureConvertBlitData_t>(constants);

for (uint32_t i = 0; i < EOTF_Count; i++)
cmdBuffer->bindColorMgmtLuts(i, nullptr, nullptr);

cmdBuffer->bindPipeline(g_device.pipeline( SHADER_TYPE_RGB_TO_NV12, 1, 0, 0, GAMESCOPE_APP_TEXTURE_COLORSPACE_SRGB, EOTF_Count ));
cmdBuffer->bindTexture(0, pScreenshotTexture);
cmdBuffer->setTextureSrgb(0, true);
cmdBuffer->setSamplerNearest(0, false);
cmdBuffer->setSamplerUnnormalized(0, true);
for (uint32_t i = 1; i < VKR_SAMPLER_SLOTS; i++)
{
cmdBuffer->bindTexture(i, nullptr);
}
cmdBuffer->bindTarget(pYUVOutTexture);

const int pixelsPerGroup = 8;

// For ycbcr, we operate on 2 pixels at a time, so use the half-extent.
const int dispatchSize = pixelsPerGroup * 2;

cmdBuffer->dispatch(div_roundup(pYUVOutTexture->width(), dispatchSize), div_roundup(pYUVOutTexture->height(), dispatchSize));
}

uint64_t sequence = g_device.submit(std::move(cmdBuffer));
return sequence;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rendervulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void vulkan_update_luts(const std::shared_ptr<CVulkanTexture>& lut1d, const std:

std::shared_ptr<CVulkanTexture> vulkan_get_hacky_blank_texture();

std::optional<uint64_t> vulkan_screenshot( const struct FrameInfo_t *frameInfo, std::shared_ptr<CVulkanTexture> pScreenshotTexture );
std::optional<uint64_t> vulkan_screenshot( const struct FrameInfo_t *frameInfo, std::shared_ptr<CVulkanTexture> pScreenshotTexture, std::shared_ptr<CVulkanTexture> pYUVOutTexture );

struct wlr_renderer *vulkan_renderer_create( void );

Expand Down
12 changes: 10 additions & 2 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,15 @@ static void paint_pipewire()
if ( pFocus->overrideWindow && !pFocus->focusWindow->isSteamStreamingClient )
paint_window( pFocus->overrideWindow, pFocus->focusWindow, &frameInfo, nullptr, PaintWindowFlag::NoFilter, 1.0f, pFocus->overrideWindow );

std::optional<uint64_t> oPipewireSequence = vulkan_composite( &frameInfo, s_pPipewireBuffer->texture, false, nullptr, false );
std::shared_ptr<CVulkanTexture> pRGBTexture = s_pPipewireBuffer->texture->isYcbcr()
? vulkan_acquire_screenshot_texture( g_nOutputWidth, g_nOutputHeight, false, DRM_FORMAT_XRGB2101010 )
: s_pPipewireBuffer->texture;

std::shared_ptr<CVulkanTexture> pYUVTexture = s_pPipewireBuffer->texture->isYcbcr() ? s_pPipewireBuffer->texture : nullptr;

std::optional<uint64_t> oPipewireSequence = vulkan_screenshot( &frameInfo, pRGBTexture, pYUVTexture );
// If we ever want the fat compositing path, use this.
//std::optional<uint64_t> oPipewireSequence = vulkan_composite( &frameInfo, s_pPipewireBuffer->texture, false, pRGBTexture, false );

if ( oPipewireSequence )
{
Expand Down Expand Up @@ -2608,7 +2616,7 @@ paint_all(bool async)
oScreenshotInfo->eScreenshotType == GAMESCOPE_CONTROL_SCREENSHOT_TYPE_SCREEN_BUFFER )
oScreenshotSeq = vulkan_composite( &frameInfo, nullptr, false, pScreenshotTexture );
else
oScreenshotSeq = vulkan_screenshot( &frameInfo, pScreenshotTexture );
oScreenshotSeq = vulkan_screenshot( &frameInfo, pScreenshotTexture, nullptr );

g_uCompositeDebug = uCompositeDebugBackup;

Expand Down

0 comments on commit b02d87f

Please sign in to comment.