Merge pull request #681 from krOoze/triangle_dependencies
Tweak Triangle subpass dependencies
This commit is contained in:
commit
78b25ebd71
3 changed files with 81 additions and 82 deletions
|
|
@ -182,8 +182,7 @@ public:
|
||||||
std::string name = "vulkanExample";
|
std::string name = "vulkanExample";
|
||||||
uint32_t apiVersion = VK_API_VERSION_1_0;
|
uint32_t apiVersion = VK_API_VERSION_1_0;
|
||||||
|
|
||||||
struct
|
struct {
|
||||||
{
|
|
||||||
VkImage image;
|
VkImage image;
|
||||||
VkDeviceMemory mem;
|
VkDeviceMemory mem;
|
||||||
VkImageView view;
|
VkImageView view;
|
||||||
|
|
|
||||||
|
|
@ -44,13 +44,12 @@ public:
|
||||||
|
|
||||||
// Vertex buffer and attributes
|
// Vertex buffer and attributes
|
||||||
struct {
|
struct {
|
||||||
VkDeviceMemory memory; // Handle to the device memory for this buffer
|
VkDeviceMemory memory; // Handle to the device memory for this buffer
|
||||||
VkBuffer buffer; // Handle to the Vulkan buffer object that the memory is bound to
|
VkBuffer buffer; // Handle to the Vulkan buffer object that the memory is bound to
|
||||||
} vertices;
|
} vertices;
|
||||||
|
|
||||||
// Index buffer
|
// Index buffer
|
||||||
struct
|
struct {
|
||||||
{
|
|
||||||
VkDeviceMemory memory;
|
VkDeviceMemory memory;
|
||||||
VkBuffer buffer;
|
VkBuffer buffer;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
|
|
@ -341,13 +340,13 @@ public:
|
||||||
// The submit info structure specifices a command buffer queue submission batch
|
// The submit info structure specifices a command buffer queue submission batch
|
||||||
VkSubmitInfo submitInfo = {};
|
VkSubmitInfo submitInfo = {};
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
submitInfo.pWaitDstStageMask = &waitStageMask; // Pointer to the list of pipeline stages that the semaphore waits will occur at
|
submitInfo.pWaitDstStageMask = &waitStageMask; // Pointer to the list of pipeline stages that the semaphore waits will occur at
|
||||||
submitInfo.pWaitSemaphores = &presentCompleteSemaphore; // Semaphore(s) to wait upon before the submitted command buffer starts executing
|
submitInfo.pWaitSemaphores = &presentCompleteSemaphore; // Semaphore(s) to wait upon before the submitted command buffer starts executing
|
||||||
submitInfo.waitSemaphoreCount = 1; // One wait semaphore
|
submitInfo.waitSemaphoreCount = 1; // One wait semaphore
|
||||||
submitInfo.pSignalSemaphores = &renderCompleteSemaphore; // Semaphore(s) to be signaled when command buffers have completed
|
submitInfo.pSignalSemaphores = &renderCompleteSemaphore; // Semaphore(s) to be signaled when command buffers have completed
|
||||||
submitInfo.signalSemaphoreCount = 1; // One signal semaphore
|
submitInfo.signalSemaphoreCount = 1; // One signal semaphore
|
||||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; // Command buffers(s) to execute in this batch (submission)
|
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; // Command buffers(s) to execute in this batch (submission)
|
||||||
submitInfo.commandBufferCount = 1; // One command buffer
|
submitInfo.commandBufferCount = 1; // One command buffer
|
||||||
|
|
||||||
// Submit to the graphics queue passing a wait fence
|
// Submit to the graphics queue passing a wait fence
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
|
||||||
|
|
@ -674,8 +673,8 @@ public:
|
||||||
for (size_t i = 0; i < frameBuffers.size(); i++)
|
for (size_t i = 0; i < frameBuffers.size(); i++)
|
||||||
{
|
{
|
||||||
std::array<VkImageView, 2> attachments;
|
std::array<VkImageView, 2> attachments;
|
||||||
attachments[0] = swapChain.buffers[i].view; // Color attachment is the view of the swapchain image
|
attachments[0] = swapChain.buffers[i].view; // Color attachment is the view of the swapchain image
|
||||||
attachments[1] = depthStencil.view; // Depth/Stencil attachment is the same for all frame buffers
|
attachments[1] = depthStencil.view; // Depth/Stencil attachment is the same for all frame buffers
|
||||||
|
|
||||||
VkFramebufferCreateInfo frameBufferCreateInfo = {};
|
VkFramebufferCreateInfo frameBufferCreateInfo = {};
|
||||||
frameBufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
frameBufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||||
|
|
@ -704,45 +703,45 @@ public:
|
||||||
std::array<VkAttachmentDescription, 2> attachments = {};
|
std::array<VkAttachmentDescription, 2> attachments = {};
|
||||||
|
|
||||||
// Color attachment
|
// Color attachment
|
||||||
attachments[0].format = swapChain.colorFormat; // Use the color format selected by the swapchain
|
attachments[0].format = swapChain.colorFormat; // Use the color format selected by the swapchain
|
||||||
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT; // We don't use multi sampling in this example
|
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT; // We don't use multi sampling in this example
|
||||||
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // Clear this attachment at the start of the render pass
|
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // Clear this attachment at the start of the render pass
|
||||||
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE; // Keep its contents after the render pass is finished (for displaying it)
|
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE; // Keep its contents after the render pass is finished (for displaying it)
|
||||||
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; // We don't use stencil, so don't care for load
|
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; // We don't use stencil, so don't care for load
|
||||||
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; // Same for store
|
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; // Same for store
|
||||||
attachments[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; // Layout at render pass start. Initial doesn't matter, so we use undefined
|
attachments[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; // Layout at render pass start. Initial doesn't matter, so we use undefined
|
||||||
attachments[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; // Layout to which the attachment is transitioned when the render pass is finished
|
attachments[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; // Layout to which the attachment is transitioned when the render pass is finished
|
||||||
// As we want to present the color buffer to the swapchain, we transition to PRESENT_KHR
|
// As we want to present the color buffer to the swapchain, we transition to PRESENT_KHR
|
||||||
// Depth attachment
|
// Depth attachment
|
||||||
attachments[1].format = depthFormat; // A proper depth format is selected in the example base
|
attachments[1].format = depthFormat; // A proper depth format is selected in the example base
|
||||||
attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
|
attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // Clear depth at start of first subpass
|
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // Clear depth at start of first subpass
|
||||||
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; // We don't need depth after render pass has finished (DONT_CARE may result in better performance)
|
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; // We don't need depth after render pass has finished (DONT_CARE may result in better performance)
|
||||||
attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; // No stencil
|
attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; // No stencil
|
||||||
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; // No Stencil
|
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; // No Stencil
|
||||||
attachments[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; // Layout at render pass start. Initial doesn't matter, so we use undefined
|
attachments[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; // Layout at render pass start. Initial doesn't matter, so we use undefined
|
||||||
attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; // Transition to depth/stencil attachment
|
attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; // Transition to depth/stencil attachment
|
||||||
|
|
||||||
// Setup attachment references
|
// Setup attachment references
|
||||||
VkAttachmentReference colorReference = {};
|
VkAttachmentReference colorReference = {};
|
||||||
colorReference.attachment = 0; // Attachment 0 is color
|
colorReference.attachment = 0; // Attachment 0 is color
|
||||||
colorReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; // Attachment layout used as color during the subpass
|
colorReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; // Attachment layout used as color during the subpass
|
||||||
|
|
||||||
VkAttachmentReference depthReference = {};
|
VkAttachmentReference depthReference = {};
|
||||||
depthReference.attachment = 1; // Attachment 1 is color
|
depthReference.attachment = 1; // Attachment 1 is color
|
||||||
depthReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; // Attachment used as depth/stemcil used during the subpass
|
depthReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; // Attachment used as depth/stemcil used during the subpass
|
||||||
|
|
||||||
// Setup a single subpass reference
|
// Setup a single subpass reference
|
||||||
VkSubpassDescription subpassDescription = {};
|
VkSubpassDescription subpassDescription = {};
|
||||||
subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||||
subpassDescription.colorAttachmentCount = 1; // Subpass uses one color attachment
|
subpassDescription.colorAttachmentCount = 1; // Subpass uses one color attachment
|
||||||
subpassDescription.pColorAttachments = &colorReference; // Reference to the color attachment in slot 0
|
subpassDescription.pColorAttachments = &colorReference; // Reference to the color attachment in slot 0
|
||||||
subpassDescription.pDepthStencilAttachment = &depthReference; // Reference to the depth attachment in slot 1
|
subpassDescription.pDepthStencilAttachment = &depthReference; // Reference to the depth attachment in slot 1
|
||||||
subpassDescription.inputAttachmentCount = 0; // Input attachments can be used to sample from contents of a previous subpass
|
subpassDescription.inputAttachmentCount = 0; // Input attachments can be used to sample from contents of a previous subpass
|
||||||
subpassDescription.pInputAttachments = nullptr; // (Input attachments not used by this example)
|
subpassDescription.pInputAttachments = nullptr; // (Input attachments not used by this example)
|
||||||
subpassDescription.preserveAttachmentCount = 0; // Preserved attachments can be used to loop (and preserve) attachments through subpasses
|
subpassDescription.preserveAttachmentCount = 0; // Preserved attachments can be used to loop (and preserve) attachments through subpasses
|
||||||
subpassDescription.pPreserveAttachments = nullptr; // (Preserve attachments not used by this example)
|
subpassDescription.pPreserveAttachments = nullptr; // (Preserve attachments not used by this example)
|
||||||
subpassDescription.pResolveAttachments = nullptr; // Resolve attachments are resolved at the end of a sub pass and can be used for e.g. multi sampling
|
subpassDescription.pResolveAttachments = nullptr; // Resolve attachments are resolved at the end of a sub pass and can be used for e.g. multi sampling
|
||||||
|
|
||||||
// Setup subpass dependencies
|
// Setup subpass dependencies
|
||||||
// These will add the implicit ttachment layout transitionss specified by the attachment descriptions
|
// These will add the implicit ttachment layout transitionss specified by the attachment descriptions
|
||||||
|
|
@ -754,33 +753,34 @@ public:
|
||||||
|
|
||||||
// First dependency at the start of the renderpass
|
// First dependency at the start of the renderpass
|
||||||
// Does the transition from final to initial layout
|
// Does the transition from final to initial layout
|
||||||
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; // Producer of the dependency
|
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; // Producer of the dependency
|
||||||
dependencies[0].dstSubpass = 0; // Consumer is our single subpass that will wait for the execution depdendency
|
dependencies[0].dstSubpass = 0; // Consumer is our single subpass that will wait for the execution depdendency
|
||||||
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; // Match our pWaitDstStageMask when we vkQueueSubmit
|
||||||
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; // is a loadOp stage for color attachments
|
||||||
dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
dependencies[0].srcAccessMask = 0; // semaphore wait already does memory dependency for us
|
||||||
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; // is a loadOp CLEAR access mask for color attachments
|
||||||
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||||
|
|
||||||
// Second dependency at the end the renderpass
|
// Second dependency at the end the renderpass
|
||||||
// Does the transition from the initial to the final layout
|
// Does the transition from the initial to the final layout
|
||||||
dependencies[1].srcSubpass = 0; // Producer of the dependency is our single subpass
|
// Technically this is the same as the implicit subpass dependency, but we are gonna state it explicitly here
|
||||||
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL; // Consumer are all commands outside of the renderpass
|
dependencies[1].srcSubpass = 0; // Producer of the dependency is our single subpass
|
||||||
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL; // Consumer are all commands outside of the renderpass
|
||||||
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; // is a storeOp stage for color attachments
|
||||||
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; // Do not block any subsequent work
|
||||||
dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; // is a storeOp `STORE` access mask for color attachments
|
||||||
|
dependencies[1].dstAccessMask = 0;
|
||||||
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||||
|
|
||||||
// Create the actual renderpass
|
// Create the actual renderpass
|
||||||
VkRenderPassCreateInfo renderPassInfo = {};
|
VkRenderPassCreateInfo renderPassInfo = {};
|
||||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||||
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size()); // Number of attachments used by this render pass
|
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size()); // Number of attachments used by this render pass
|
||||||
renderPassInfo.pAttachments = attachments.data(); // Descriptions of the attachments used by the render pass
|
renderPassInfo.pAttachments = attachments.data(); // Descriptions of the attachments used by the render pass
|
||||||
renderPassInfo.subpassCount = 1; // We only use one subpass in this example
|
renderPassInfo.subpassCount = 1; // We only use one subpass in this example
|
||||||
renderPassInfo.pSubpasses = &subpassDescription; // Description of that subpass
|
renderPassInfo.pSubpasses = &subpassDescription; // Description of that subpass
|
||||||
renderPassInfo.dependencyCount = static_cast<uint32_t>(dependencies.size()); // Number of subpass dependencies
|
renderPassInfo.dependencyCount = static_cast<uint32_t>(dependencies.size()); // Number of subpass dependencies
|
||||||
renderPassInfo.pDependencies = dependencies.data(); // Subpass dependencies used by the render pass
|
renderPassInfo.pDependencies = dependencies.data(); // Subpass dependencies used by the render pass
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassInfo, nullptr, &renderPass));
|
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassInfo, nullptr, &renderPass));
|
||||||
}
|
}
|
||||||
|
|
@ -873,7 +873,7 @@ public:
|
||||||
rasterizationState.lineWidth = 1.0f;
|
rasterizationState.lineWidth = 1.0f;
|
||||||
|
|
||||||
// Color blend state describes how blend factors are calculated (if used)
|
// Color blend state describes how blend factors are calculated (if used)
|
||||||
// We need one blend attachment state per color attachment (even if blending is not used
|
// We need one blend attachment state per color attachment (even if blending is not used)
|
||||||
VkPipelineColorBlendAttachmentState blendAttachmentState[1] = {};
|
VkPipelineColorBlendAttachmentState blendAttachmentState[1] = {};
|
||||||
blendAttachmentState[0].colorWriteMask = 0xf;
|
blendAttachmentState[0].colorWriteMask = 0xf;
|
||||||
blendAttachmentState[0].blendEnable = VK_FALSE;
|
blendAttachmentState[0].blendEnable = VK_FALSE;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue