Skip to content

Commit

Permalink
Fix initial attachment layout incorrectly being Undefined if we want …
Browse files Browse the repository at this point in the history
…the previous value.
  • Loading branch information
GPSnoopy committed Jan 30, 2021
1 parent fab9002 commit 28e80c5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ UserInterface::UserInterface(
{0, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0},
};
descriptorPool_.reset(new Vulkan::DescriptorPool(device, descriptorBindings, 1));
renderPass_.reset(new Vulkan::RenderPass(swapChain, depthBuffer, false, false));
renderPass_.reset(new Vulkan::RenderPass(swapChain, depthBuffer, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_LOAD_OP_LOAD));

// Initialise ImGui
IMGUI_CHECKVERSION();
Expand Down
2 changes: 1 addition & 1 deletion src/Vulkan/GraphicsPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ GraphicsPipeline::GraphicsPipeline(

// Create pipeline layout and render pass.
pipelineLayout_.reset(new class PipelineLayout(device, descriptorSetManager_->DescriptorSetLayout()));
renderPass_.reset(new class RenderPass(swapChain, depthBuffer, true, true));
renderPass_.reset(new class RenderPass(swapChain, depthBuffer, VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_LOAD_OP_CLEAR));

// Load shaders.
const ShaderModule vertShader(device, "../assets/shaders/Graphics.vert.spv");
Expand Down
12 changes: 6 additions & 6 deletions src/Vulkan/RenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ namespace Vulkan {
RenderPass::RenderPass(
const class SwapChain& swapChain,
const class DepthBuffer& depthBuffer,
const bool clearColorBuffer,
const bool clearDepthBuffer) :
const VkAttachmentLoadOp colorBufferLoadOp,
const VkAttachmentLoadOp depthBufferLoadOp) :
swapChain_(swapChain),
depthBuffer_(depthBuffer)
{
VkAttachmentDescription colorAttachment = {};
colorAttachment.format = swapChain.Format();
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
colorAttachment.loadOp = clearColorBuffer ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
colorAttachment.loadOp = colorBufferLoadOp;
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
colorAttachment.initialLayout = colorBufferLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;

VkAttachmentDescription depthAttachment = {};
depthAttachment.format = depthBuffer.Format();
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
depthAttachment.loadOp = clearDepthBuffer ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
depthAttachment.loadOp = depthBufferLoadOp;
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
depthAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
depthAttachment.initialLayout = depthBufferLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;

VkAttachmentReference colorAttachmentRef = {};
Expand Down
2 changes: 1 addition & 1 deletion src/Vulkan/RenderPass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Vulkan

VULKAN_NON_COPIABLE(RenderPass)

RenderPass(const SwapChain& swapChain, const DepthBuffer& depthBuffer, bool clearColorBuffer, bool clearDepthBuffer);
RenderPass(const SwapChain& swapChain, const DepthBuffer& depthBuffer, VkAttachmentLoadOp colorBufferLoadOp, VkAttachmentLoadOp depthBufferLoadOp);
~RenderPass();

const class SwapChain& SwapChain() const { return swapChain_; }
Expand Down

0 comments on commit 28e80c5

Please sign in to comment.