From 347339b254f5b7527e06bfa1caf3642ab0198df8 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 26 Feb 2019 12:25:17 +0100 Subject: [PATCH] - add a very basic present shader using a blit - avoid dealing with image layout transitions for the blit by using VK_IMAGE_LAYOUT_GENERAL for now --- .../vulkan/renderer/vk_renderpass.cpp | 4 +-- .../vulkan/system/vk_framebuffer.cpp | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/rendering/vulkan/renderer/vk_renderpass.cpp b/src/rendering/vulkan/renderer/vk_renderpass.cpp index 8adfbe2ce..320b43fe3 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/src/rendering/vulkan/renderer/vk_renderpass.cpp @@ -117,9 +117,9 @@ VkRenderPassSetup::VkRenderPassSetup() void VkRenderPassSetup::CreateRenderPass() { RenderPassBuilder builder; - builder.addRgba16fAttachment(false, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + builder.addRgba16fAttachment(false, VK_IMAGE_LAYOUT_GENERAL); builder.addSubpass(); - builder.addSubpassColorAttachmentRef(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + builder.addSubpassColorAttachmentRef(0, VK_IMAGE_LAYOUT_GENERAL); builder.addExternalSubpassDependency(); RenderPass = builder.create(GetVulkanFrameBuffer()->device); } diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 2f4dc24d7..9b5e5345c 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -107,6 +107,31 @@ void VulkanFrameBuffer::Update() mRenderState->EndRenderPass(); //DrawPresentTexture(mOutputLetterbox, true); + { + auto sceneColor = mRenderPassManager->SceneColor.get(); + + PipelineBarrier barrier0; + barrier0.addImage(sceneColor, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT); + barrier0.execute(mPresentCommands.get(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); + + VkImageBlit blit = {}; + blit.srcOffsets[0] = { 0, 0, 0 }; + blit.srcOffsets[1] = { sceneColor->width, sceneColor->height, 1 }; + blit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + blit.srcSubresource.mipLevel = 0; + blit.srcSubresource.baseArrayLayer = 0; + blit.srcSubresource.layerCount = 1; + blit.dstOffsets[0] = { 0, 0, 0 }; + blit.dstOffsets[1] = { (int32_t)device->swapChain->actualExtent.width, (int32_t)device->swapChain->actualExtent.height, 1 }; + blit.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + blit.dstSubresource.mipLevel = 0; + blit.dstSubresource.baseArrayLayer = 0; + blit.dstSubresource.layerCount = 1; + mPresentCommands->blitImage( + sceneColor->image, VK_IMAGE_LAYOUT_GENERAL, + device->swapChain->swapChainImages[device->presentImageIndex], VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR, + 1, &blit, VK_FILTER_NEAREST); + } mPresentCommands->end();