From 2a15f65065b473a57d171bcaa6a6749f45340fd5 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 20 May 2019 12:36:45 +0200 Subject: [PATCH] - apply present shader on screenshots --- .../vulkan/renderer/vk_postprocess.cpp | 23 ++++++++++++++----- .../vulkan/renderer/vk_postprocess.h | 2 +- .../vulkan/system/vk_framebuffer.cpp | 9 +++++++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/rendering/vulkan/renderer/vk_postprocess.cpp b/src/rendering/vulkan/renderer/vk_postprocess.cpp index 78df34630..19ab003a9 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.cpp +++ b/src/rendering/vulkan/renderer/vk_postprocess.cpp @@ -169,7 +169,7 @@ void VkPostprocess::BlitCurrentToImage(VkTextureImage *dstimage, VkImageLayout f imageTransition1.execute(cmdbuffer); } -void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool clearBorders) +void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool screenshot) { auto fb = GetVulkanFrameBuffer(); @@ -193,10 +193,19 @@ void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool uniforms.GrayFormula = static_cast(gl_satformula); } uniforms.ColorScale = (gl_dither_bpc == -1) ? 255.0f : (float)((1 << gl_dither_bpc) - 1); - uniforms.Scale = { screen->mScreenViewport.width / (float)fb->GetBuffers()->GetWidth(), -screen->mScreenViewport.height / (float)fb->GetBuffers()->GetHeight() }; - uniforms.Offset = { 0.0f, 1.0f }; - if (applyGamma && fb->swapChain->swapChainFormat.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT) + if (screenshot) + { + uniforms.Scale = { screen->mScreenViewport.width / (float)fb->GetBuffers()->GetWidth(), screen->mScreenViewport.height / (float)fb->GetBuffers()->GetHeight() }; + uniforms.Offset = { 0.0f, 0.0f }; + } + else + { + uniforms.Scale = { screen->mScreenViewport.width / (float)fb->GetBuffers()->GetWidth(), -screen->mScreenViewport.height / (float)fb->GetBuffers()->GetHeight() }; + uniforms.Offset = { 0.0f, 1.0f }; + } + + if (applyGamma && fb->swapChain->swapChainFormat.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT && !screenshot) { uniforms.HdrMode = 1; } @@ -211,9 +220,11 @@ void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool renderstate.Viewport = box; renderstate.SetInputCurrent(0, ViewportLinearScale() ? PPFilterMode::Linear : PPFilterMode::Nearest); renderstate.SetInputTexture(1, &hw_postprocess.present.Dither, PPFilterMode::Nearest, PPWrapMode::Repeat); - renderstate.SetOutputSwapChain(); + if (screenshot) + renderstate.SetOutputNext(); + else + renderstate.SetOutputSwapChain(); renderstate.SetNoBlend(); - //if (clearBorders) renderstate.SetClearBorders(); renderstate.Draw(); } diff --git a/src/rendering/vulkan/renderer/vk_postprocess.h b/src/rendering/vulkan/renderer/vk_postprocess.h index bc9f247c1..fa50bebca 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.h +++ b/src/rendering/vulkan/renderer/vk_postprocess.h @@ -56,7 +56,7 @@ public: void BlitSceneToPostprocess(); void BlitCurrentToImage(VkTextureImage *image, VkImageLayout finallayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - void DrawPresentTexture(const IntRect &box, bool applyGamma, bool clearBorders); + void DrawPresentTexture(const IntRect &box, bool applyGamma, bool screenshot); private: void NextEye(int eyeCount); diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 173d5408b..0d0ee23a8 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -272,7 +272,7 @@ void VulkanFrameBuffer::WaitForCommands(bool finish) presentImageIndex = swapChain->AcquireImage(GetClientWidth(), GetClientHeight(), mSwapChainImageAvailableSemaphore.get()); if (presentImageIndex != 0xffffffff) - mPostprocess->DrawPresentTexture(mOutputLetterbox, true, true); + mPostprocess->DrawPresentTexture(mOutputLetterbox, true, false); } FlushCommands(finish, true); @@ -787,6 +787,13 @@ TArray VulkanFrameBuffer::GetScreenshotBuffer(int &pitch, ESSType &colo int w = SCREENWIDTH; int h = SCREENHEIGHT; + IntRect box; + box.left = 0; + box.top = 0; + box.width = w; + box.height = h; + mPostprocess->DrawPresentTexture(box, true, true); + TArray ScreenshotBuffer(w * h * 3, true); CopyScreenToBuffer(w, h, ScreenshotBuffer.Data());