Permalink
Browse files

Vulkan: Make backbuffer transitions part of backbuffer render pass. O…

…ptimize depth buffer memory operations.
  • Loading branch information...
hrydgard committed Oct 31, 2017
1 parent 9e734b3 commit 74861d2d73aeb4fe733c67154eab306cceea93ee
@@ -153,20 +153,6 @@ VulkanContext::~VulkanContext() {
VulkanFree();
}
void TransitionToPresent(VkCommandBuffer cmd, VkImage image) {
TransitionImageLayout2(cmd, image, VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT);
}
void TransitionFromPresent(VkCommandBuffer cmd, VkImage image) {
TransitionImageLayout2(cmd, image, VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
VK_ACCESS_MEMORY_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
}
void VulkanContext::BeginFrame() {
FrameData *frame = &frame_[curFrame_];
// Process pending deletes.
@@ -393,9 +393,6 @@ void TransitionImageLayout2(VkCommandBuffer cmd, VkImage image, VkImageAspectFla
VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask,
VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask);
void TransitionFromPresent(VkCommandBuffer cmd, VkImage image);
void TransitionToPresent(VkCommandBuffer cmd, VkImage image);
// GLSL compiler
void init_glslang();
void finalize_glslang();
@@ -54,16 +54,16 @@ void VulkanQueueRunner::InitBackbufferRenderPass() {
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachments[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; // We don't want to preserve the backbuffer between frames so we really don't care.
attachments[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; // We only render once to the backbuffer per frame so we can do this here.
attachments[0].flags = 0;
attachments[1].format = vulkan_->GetDeviceInfo().preferredDepthStencilFormat; // must use this same format later for the back depth buffer.
attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; // Don't care about storing backbuffer Z - we clear it anyway.
attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachments[1].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachments[1].flags = 0;
@@ -302,6 +302,7 @@ VkCommandBuffer VulkanRenderManager::GetInitCmd() {
}
void VulkanRenderManager::BindFramebufferAsRenderTarget(VKRFramebuffer *fb, VKRRenderPassAction color, VKRRenderPassAction depth, uint32_t clearColor, float clearDepth, uint8_t clearStencil) {
assert(insideFrame_);
// Eliminate dupes.
if (steps_.size() && steps_.back()->render.framebuffer == fb && steps_.back()->stepType == VKRStepType::RENDER) {
if (color != VKRRenderPassAction::CLEAR && depth != VKRRenderPassAction::CLEAR) {
@@ -570,9 +571,6 @@ void VulkanRenderManager::BeginSubmitFrame(int frame) {
assert(res == VK_SUCCESS);
// TODO: Is it best to do this here, or combine with some other transition, or just do it right before the backbuffer bind-for-render?
TransitionFromPresent(frameData.mainCmd, swapchainImages_[frameData.curSwapchainImage].image);
queueRunner_.SetBackbuffer(framebuffers_[frameData.curSwapchainImage]);
frameData.hasBegun = true;
@@ -629,8 +627,6 @@ void VulkanRenderManager::EndSubmitFrame(int frame) {
frameData.hasBegun = false;
insideFrame_ = false;
TransitionToPresent(frameData.mainCmd, swapchainImages_[frameData.curSwapchainImage].image);
Submit(frame, true);
VkSwapchainKHR swapchain = vulkan_->GetSwapchain();
@@ -640,7 +636,6 @@ void VulkanRenderManager::EndSubmitFrame(int frame) {
present.pImageIndices = &frameData.curSwapchainImage;
present.pWaitSemaphores = &renderingCompleteSemaphore_;
present.waitSemaphoreCount = 1;
present.pResults = nullptr;
VkResult res = vkQueuePresentKHR(vulkan_->GetGraphicsQueue(), &present);
// TODO: Deal with the VK_SUBOPTIMAL_WSI and VK_ERROR_OUT_OF_DATE_WSI

0 comments on commit 74861d2

Please sign in to comment.