Swapchain code cleanup
Use references instead of pointers
This commit is contained in:
parent
372cab5779
commit
dcec337fa9
12 changed files with 65 additions and 85 deletions
|
|
@ -104,7 +104,7 @@ public:
|
|||
// This set of barriers prepares the color and depth images for output
|
||||
vks::tools::insertImageMemoryBarrier(
|
||||
drawCmdBuffers[i],
|
||||
swapChain.buffers[i].image,
|
||||
swapChain.images[i],
|
||||
0,
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
|
|
@ -126,7 +126,7 @@ public:
|
|||
// New structures are used to define the attachments used in dynamic rendering
|
||||
VkRenderingAttachmentInfoKHR colorAttachment{};
|
||||
colorAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
|
||||
colorAttachment.imageView = swapChain.buffers[i].view;
|
||||
colorAttachment.imageView = swapChain.imageViews[i];
|
||||
colorAttachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
|
|
@ -173,7 +173,7 @@ public:
|
|||
// This set of barriers prepares the color image for presentation, we don't need to care for the depth image
|
||||
vks::tools::insertImageMemoryBarrier(
|
||||
drawCmdBuffers[i],
|
||||
swapChain.buffers[i].image,
|
||||
swapChain.images[i],
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
0,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ public:
|
|||
frameBuffers.resize(swapChain.imageCount);
|
||||
for (uint32_t i = 0; i < frameBuffers.size(); i++)
|
||||
{
|
||||
views[0] = swapChain.buffers[i].view;
|
||||
views[0] = swapChain.imageViews[i];
|
||||
views[1] = attachments[i].color.view;
|
||||
views[2] = attachments[i].depth.view;
|
||||
VK_CHECK_RESULT(vkCreateFramebuffer(device, &frameBufferCI, nullptr, &frameBuffers[i]));
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ public:
|
|||
frameBuffers.resize(swapChain.imageCount);
|
||||
for (uint32_t i = 0; i < frameBuffers.size(); i++)
|
||||
{
|
||||
attachments[1] = swapChain.buffers[i].view;
|
||||
attachments[1] = swapChain.imageViews[i];
|
||||
VK_CHECK_RESULT(vkCreateFramebuffer(device, &frameBufferCreateInfo, nullptr, &frameBuffers[i]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,11 +268,11 @@ public:
|
|||
for (int32_t i = 0; i < drawCmdBuffers.size(); ++i)
|
||||
{
|
||||
VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));
|
||||
|
||||
|
||||
// Transition color and depth images for drawing
|
||||
vks::tools::insertImageMemoryBarrier(
|
||||
drawCmdBuffers[i],
|
||||
swapChain.buffers[i].image,
|
||||
swapChain.images[i],
|
||||
0,
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
|
|
@ -294,7 +294,7 @@ public:
|
|||
// New structures are used to define the attachments used in dynamic rendering
|
||||
VkRenderingAttachmentInfoKHR colorAttachment{};
|
||||
colorAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
|
||||
colorAttachment.imageView = swapChain.buffers[i].view;
|
||||
colorAttachment.imageView = swapChain.imageViews[i];
|
||||
colorAttachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
|
|
@ -385,7 +385,7 @@ public:
|
|||
// Transition color image for presentation
|
||||
vks::tools::insertImageMemoryBarrier(
|
||||
drawCmdBuffers[i],
|
||||
swapChain.buffers[i].image,
|
||||
swapChain.images[i],
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
0,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ public:
|
|||
frameBuffers.resize(swapChain.imageCount);
|
||||
for (uint32_t i = 0; i < frameBuffers.size(); i++)
|
||||
{
|
||||
attachments[0] = swapChain.buffers[i].view;
|
||||
attachments[0] = swapChain.imageViews[i];
|
||||
attachments[1] = this->attachments.position.view;
|
||||
attachments[2] = this->attachments.normal.view;
|
||||
attachments[3] = this->attachments.albedo.view;
|
||||
|
|
|
|||
|
|
@ -510,7 +510,7 @@ public:
|
|||
{
|
||||
std::array<VkImageView, 2> attachments{};
|
||||
// Color attachment is the view of the swapchain image
|
||||
attachments[0] = swapChain.buffers[i].view;
|
||||
attachments[0] = swapChain.imageViews[i];
|
||||
// Depth/Stencil attachment is the same for all frame buffers due to how depth works with current GPUs
|
||||
attachments[1] = depthStencil.view;
|
||||
|
||||
|
|
|
|||
|
|
@ -705,13 +705,13 @@ public:
|
|||
VK_CHECK_RESULT(vkBeginCommandBuffer(commandBuffer, &cmdBufInfo));
|
||||
|
||||
// With dynamic rendering we need to explicitly add layout transitions by using barriers, this set of barriers prepares the color and depth images for output
|
||||
vks::tools::insertImageMemoryBarrier(commandBuffer, swapChain.buffers[imageIndex].image, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
|
||||
vks::tools::insertImageMemoryBarrier(commandBuffer, swapChain.images[imageIndex], 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
|
||||
vks::tools::insertImageMemoryBarrier(commandBuffer, depthStencil.image, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, VkImageSubresourceRange{ VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1 });
|
||||
|
||||
// New structures are used to define the attachments used in dynamic rendering
|
||||
// Color attachment
|
||||
VkRenderingAttachmentInfo colorAttachment{ VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO };
|
||||
colorAttachment.imageView = swapChain.buffers[imageIndex].view;
|
||||
colorAttachment.imageView = swapChain.imageViews[imageIndex];
|
||||
colorAttachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
|
|
@ -755,7 +755,7 @@ public:
|
|||
vkCmdEndRendering(commandBuffer);
|
||||
|
||||
// This barrier prepares the color image for presentation, we don't need to care for the depth image
|
||||
vks::tools::insertImageMemoryBarrier(commandBuffer, swapChain.buffers[imageIndex].image, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, 0, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_2_NONE, VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
|
||||
vks::tools::insertImageMemoryBarrier(commandBuffer, swapChain.images[imageIndex], VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, 0, VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_2_NONE, VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
|
||||
VK_CHECK_RESULT(vkEndCommandBuffer(commandBuffer));
|
||||
|
||||
// Submit the command buffer to the graphics queue
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Vulkan Example - Variable rate shading
|
||||
*
|
||||
* Copyright (C) 2020-2023 by Sascha Willems - www.saschawillems.de
|
||||
* Copyright (C) 2020-2024 by Sascha Willems - www.saschawillems.de
|
||||
*
|
||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||
*/
|
||||
|
|
@ -91,10 +91,9 @@ void VulkanExample::setupFrameBuffer()
|
|||
frameBufferCreateInfo.layers = 1;
|
||||
|
||||
// Create frame buffers for every swap chain image
|
||||
frameBuffers.resize(swapChain.imageCount);
|
||||
for (uint32_t i = 0; i < frameBuffers.size(); i++)
|
||||
{
|
||||
attachments[0] = swapChain.buffers[i].view;
|
||||
frameBuffers.resize(swapChain.images.size());
|
||||
for (uint32_t i = 0; i < frameBuffers.size(); i++) {
|
||||
attachments[0] = swapChain.imageViews[i];
|
||||
VK_CHECK_RESULT(vkCreateFramebuffer(device, &frameBufferCreateInfo, nullptr, &frameBuffers[i]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue