|
|
@@ -48,98 +48,110 @@ VkRenderPass CompatibleRenderPassCreator::getOrCreateCompatibleRenderPass(
|
|
|
else
|
|
|
{
|
|
|
// Not found, create one
|
|
|
- VkRenderPassCreateInfo ci = {};
|
|
|
- ci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
|
|
+ VkRenderPass rpass = createNewRenderPass(init);
|
|
|
|
|
|
- Array<VkAttachmentDescription, MAX_COLOR_ATTACHMENTS + 1>
|
|
|
- attachmentDescriptions;
|
|
|
- memset(&attachmentDescriptions[0], 0, sizeof(attachmentDescriptions));
|
|
|
+ m_hashmap.pushBack(m_manager->getAllocator(), key, rpass);
|
|
|
+ out = rpass;
|
|
|
+ }
|
|
|
|
|
|
- Array<VkAttachmentReference, MAX_COLOR_ATTACHMENTS> references;
|
|
|
- memset(&references[0], 0, sizeof(references));
|
|
|
+ ANKI_ASSERT(out);
|
|
|
+ return out;
|
|
|
+}
|
|
|
|
|
|
- for(U i = 0; i < init.m_color.m_attachmentCount; ++i)
|
|
|
- {
|
|
|
- // We only care about samples and format
|
|
|
-
|
|
|
- // Workaround unsupported formats
|
|
|
- VkFormat fmt;
|
|
|
- if(init.m_color.m_attachments[i].m_format.m_components
|
|
|
- == ComponentFormat::R8G8B8
|
|
|
- && !m_manager->getR8g8b8ImagesSupported())
|
|
|
- {
|
|
|
- PixelFormat newFmt = init.m_color.m_attachments[i].m_format;
|
|
|
- newFmt.m_components = ComponentFormat::R8G8B8A8;
|
|
|
- fmt = convertFormat(newFmt);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- fmt = convertFormat(init.m_color.m_attachments[i].m_format);
|
|
|
- }
|
|
|
-
|
|
|
- VkAttachmentDescription& desc = attachmentDescriptions[i];
|
|
|
- desc.format = (!init.m_color.m_drawsToDefaultFramebuffer)
|
|
|
- ? fmt
|
|
|
- : m_manager->getDefaultFramebufferSurfaceFormat();
|
|
|
- desc.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
- desc.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
- desc.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
- desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
- desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
- desc.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
- desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
-
|
|
|
- references[i].attachment = i;
|
|
|
- references[i].layout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
- }
|
|
|
+//==============================================================================
|
|
|
+VkRenderPass CompatibleRenderPassCreator::createNewRenderPass(
|
|
|
+ const PipelineInitInfo& init)
|
|
|
+{
|
|
|
+ VkRenderPassCreateInfo ci = {};
|
|
|
+ ci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
|
|
+
|
|
|
+ Array<VkAttachmentDescription, MAX_COLOR_ATTACHMENTS + 1>
|
|
|
+ attachmentDescriptions;
|
|
|
+ memset(&attachmentDescriptions[0], 0, sizeof(attachmentDescriptions));
|
|
|
|
|
|
- ci.attachmentCount = init.m_color.m_attachmentCount;
|
|
|
+ Array<VkAttachmentReference, MAX_COLOR_ATTACHMENTS> references;
|
|
|
+ memset(&references[0], 0, sizeof(references));
|
|
|
+
|
|
|
+ for(U i = 0; i < init.m_color.m_attachmentCount; ++i)
|
|
|
+ {
|
|
|
+ // We only care about samples and format
|
|
|
|
|
|
- Bool hasDepthStencil =
|
|
|
- init.m_depthStencil.m_format.m_components != ComponentFormat::NONE;
|
|
|
- VkAttachmentReference dsReference = {0, VK_IMAGE_LAYOUT_GENERAL};
|
|
|
- if(hasDepthStencil)
|
|
|
+ // Workaround unsupported formats
|
|
|
+ VkFormat fmt;
|
|
|
+ if(init.m_color.m_attachments[i].m_format.m_components
|
|
|
+ == ComponentFormat::R8G8B8
|
|
|
+ && !m_manager->getR8g8b8ImagesSupported())
|
|
|
{
|
|
|
- VkAttachmentDescription& desc =
|
|
|
- attachmentDescriptions[ci.attachmentCount];
|
|
|
- desc.format = convertFormat(init.m_depthStencil.m_format);
|
|
|
- desc.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
- desc.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
- desc.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
- desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
- desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
- desc.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
- desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
-
|
|
|
- dsReference.attachment = ci.attachmentCount;
|
|
|
- dsReference.layout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
-
|
|
|
- ++ci.attachmentCount;
|
|
|
+ PixelFormat newFmt = init.m_color.m_attachments[i].m_format;
|
|
|
+ newFmt.m_components = ComponentFormat::R8G8B8A8;
|
|
|
+ fmt = convertFormat(newFmt);
|
|
|
+ }
|
|
|
+ else if(init.m_color.m_attachments[i].m_format.m_components
|
|
|
+ == ComponentFormat::DEFAULT_FRAMEBUFFER)
|
|
|
+ {
|
|
|
+ // Default FB
|
|
|
+ fmt = m_manager->getDefaultFramebufferSurfaceFormat();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fmt = convertFormat(init.m_color.m_attachments[i].m_format);
|
|
|
}
|
|
|
|
|
|
- VkSubpassDescription desc = {};
|
|
|
- desc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
|
|
- desc.colorAttachmentCount = init.m_color.m_attachmentCount;
|
|
|
- desc.pColorAttachments =
|
|
|
- (init.m_color.m_attachmentCount) ? &references[0] : nullptr;
|
|
|
- desc.pDepthStencilAttachment =
|
|
|
- (hasDepthStencil) ? &dsReference : nullptr;
|
|
|
-
|
|
|
- ANKI_ASSERT(ci.attachmentCount);
|
|
|
- ci.pAttachments = &attachmentDescriptions[0];
|
|
|
- ci.subpassCount = 1;
|
|
|
- ci.pSubpasses = &desc;
|
|
|
+ VkAttachmentDescription& desc = attachmentDescriptions[i];
|
|
|
+ desc.format = fmt;
|
|
|
+ desc.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
+ desc.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
+ desc.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
+ desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
+ desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
+ desc.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
+ desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
+
|
|
|
+ references[i].attachment = i;
|
|
|
+ references[i].layout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
+ }
|
|
|
|
|
|
- VkRenderPass rpass;
|
|
|
- ANKI_VK_CHECKF(
|
|
|
- vkCreateRenderPass(m_manager->getDevice(), &ci, nullptr, &rpass));
|
|
|
+ ci.attachmentCount = init.m_color.m_attachmentCount;
|
|
|
|
|
|
- m_hashmap.pushBack(m_manager->getAllocator(), key, rpass);
|
|
|
- out = rpass;
|
|
|
+ Bool hasDepthStencil =
|
|
|
+ init.m_depthStencil.m_format.m_components != ComponentFormat::NONE;
|
|
|
+ VkAttachmentReference dsReference = {0, VK_IMAGE_LAYOUT_GENERAL};
|
|
|
+ if(hasDepthStencil)
|
|
|
+ {
|
|
|
+ VkAttachmentDescription& desc =
|
|
|
+ attachmentDescriptions[ci.attachmentCount];
|
|
|
+ desc.format = convertFormat(init.m_depthStencil.m_format);
|
|
|
+ desc.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
+ desc.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
+ desc.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
+ desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
+ desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
|
+ desc.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
+ desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
+
|
|
|
+ dsReference.attachment = ci.attachmentCount;
|
|
|
+ dsReference.layout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
+
|
|
|
+ ++ci.attachmentCount;
|
|
|
}
|
|
|
|
|
|
- ANKI_ASSERT(out);
|
|
|
- return out;
|
|
|
+ VkSubpassDescription desc = {};
|
|
|
+ desc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
|
|
+ desc.colorAttachmentCount = init.m_color.m_attachmentCount;
|
|
|
+ desc.pColorAttachments =
|
|
|
+ (init.m_color.m_attachmentCount) ? &references[0] : nullptr;
|
|
|
+ desc.pDepthStencilAttachment = (hasDepthStencil) ? &dsReference : nullptr;
|
|
|
+
|
|
|
+ ANKI_ASSERT(ci.attachmentCount);
|
|
|
+ ci.pAttachments = &attachmentDescriptions[0];
|
|
|
+ ci.subpassCount = 1;
|
|
|
+ ci.pSubpasses = &desc;
|
|
|
+
|
|
|
+ VkRenderPass rpass;
|
|
|
+ ANKI_VK_CHECKF(
|
|
|
+ vkCreateRenderPass(m_manager->getDevice(), &ci, nullptr, &rpass));
|
|
|
+
|
|
|
+ return rpass;
|
|
|
}
|
|
|
|
|
|
} // end namespace anki
|