Adding interface for renderpass layout transitions
This commit is contained in:
@@ -8,8 +8,8 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx::PViewport viewport)
|
||||
: Gfx::RenderPass(std::move(_layout))
|
||||
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Array<Gfx::SubPassDependency> _dependencies, Gfx::PViewport viewport)
|
||||
: Gfx::RenderPass(std::move(_layout), std::move(_dependencies))
|
||||
, graphics(graphics)
|
||||
{
|
||||
renderArea.extent.width = viewport->getWidth();
|
||||
@@ -25,7 +25,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
VkAttachmentReference2 depthResolveRef;
|
||||
|
||||
uint32 attachmentCounter = 0;
|
||||
for (auto& inputAttachment : layout->inputAttachments)
|
||||
for (auto& inputAttachment : layout.inputAttachments)
|
||||
{
|
||||
PTexture2D image = inputAttachment->getTexture().cast<Texture2D>();
|
||||
VkAttachmentDescription2& desc = attachments.add() = {
|
||||
@@ -37,8 +37,8 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
.storeOp = cast(inputAttachment->getStoreOp()),
|
||||
.stencilLoadOp = cast(inputAttachment->getStencilLoadOp()),
|
||||
.stencilStoreOp = cast(inputAttachment->getStencilStoreOp()),
|
||||
.initialLayout = image->isDepthStencil() ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
.finalLayout = image->isDepthStencil() ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
.initialLayout = cast(inputAttachment->getInitialLayout()),
|
||||
.finalLayout = cast(inputAttachment->getFinalLayout()),
|
||||
};
|
||||
|
||||
inputRefs.add() = {
|
||||
@@ -46,7 +46,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
.layout = desc.initialLayout,
|
||||
};
|
||||
}
|
||||
for (auto& colorAttachment : layout->colorAttachments)
|
||||
for (auto& colorAttachment : layout.colorAttachments)
|
||||
{
|
||||
attachments.add() = {
|
||||
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,
|
||||
@@ -58,8 +58,8 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
.storeOp = cast(colorAttachment->getStoreOp()),
|
||||
.stencilLoadOp = cast(colorAttachment->getStencilLoadOp()),
|
||||
.stencilStoreOp = cast(colorAttachment->getStencilStoreOp()),
|
||||
.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
.initialLayout = cast(colorAttachment->getInitialLayout()),
|
||||
.finalLayout = cast(colorAttachment->getFinalLayout()),
|
||||
};
|
||||
|
||||
VkClearValue& clearValue = clearValues.add();
|
||||
@@ -75,7 +75,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
};
|
||||
}
|
||||
for (auto& resolveAttachment : layout->resolveAttachments)
|
||||
for (auto& resolveAttachment : layout.resolveAttachments)
|
||||
{
|
||||
attachments.add() = {
|
||||
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,
|
||||
@@ -87,8 +87,8 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
.storeOp = cast(resolveAttachment->getStoreOp()),
|
||||
.stencilLoadOp = cast(resolveAttachment->getStencilLoadOp()),
|
||||
.stencilStoreOp = cast(resolveAttachment->getStencilStoreOp()),
|
||||
.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
.initialLayout = cast(resolveAttachment->getInitialLayout()),
|
||||
.finalLayout = cast(resolveAttachment->getFinalLayout()),
|
||||
};
|
||||
|
||||
VkClearValue& clearValue = clearValues.add();
|
||||
@@ -104,27 +104,27 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
};
|
||||
}
|
||||
if (layout->depthAttachment != nullptr)
|
||||
if (layout.depthAttachment != nullptr)
|
||||
{
|
||||
PTexture2D image = layout->depthAttachment->getTexture().cast<Texture2D>();
|
||||
PTexture2D image = layout.depthAttachment->getTexture().cast<Texture2D>();
|
||||
attachments.add() = {
|
||||
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.format = cast(image->getFormat()),
|
||||
.samples = (VkSampleCountFlagBits)image->getNumSamples(),
|
||||
.loadOp = cast(layout->depthAttachment->getLoadOp()),
|
||||
.storeOp = cast(layout->depthAttachment->getStoreOp()),
|
||||
.stencilLoadOp = cast(layout->depthAttachment->getStencilLoadOp()),
|
||||
.stencilStoreOp = cast(layout->depthAttachment->getStencilStoreOp()),
|
||||
.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
.loadOp = cast(layout.depthAttachment->getLoadOp()),
|
||||
.storeOp = cast(layout.depthAttachment->getStoreOp()),
|
||||
.stencilLoadOp = cast(layout.depthAttachment->getStencilLoadOp()),
|
||||
.stencilStoreOp = cast(layout.depthAttachment->getStencilStoreOp()),
|
||||
.initialLayout = cast(layout.depthAttachment->getInitialLayout()),
|
||||
.finalLayout = cast(layout.depthAttachment->getFinalLayout()),
|
||||
};
|
||||
|
||||
VkClearValue& clearValue = clearValues.add();
|
||||
if (attachments.back().loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
|
||||
{
|
||||
clearValue = cast(layout->depthAttachment->clear);
|
||||
clearValue = cast(layout.depthAttachment->clear);
|
||||
}
|
||||
|
||||
depthRef = {
|
||||
@@ -134,21 +134,21 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
};
|
||||
}
|
||||
if (layout->depthResolveAttachment != nullptr)
|
||||
if (layout.depthResolveAttachment != nullptr)
|
||||
{
|
||||
PTexture2D image = layout->depthResolveAttachment->getTexture().cast<Texture2D>();
|
||||
PTexture2D image = layout.depthResolveAttachment->getTexture().cast<Texture2D>();
|
||||
attachments.add() = {
|
||||
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.format = cast(image->getFormat()),
|
||||
.samples = (VkSampleCountFlagBits)image->getNumSamples(),
|
||||
.loadOp = cast(layout->depthResolveAttachment->getLoadOp()),
|
||||
.storeOp = cast(layout->depthResolveAttachment->getStoreOp()),
|
||||
.stencilLoadOp = cast(layout->depthResolveAttachment->getStencilLoadOp()),
|
||||
.stencilStoreOp = cast(layout->depthResolveAttachment->getStencilStoreOp()),
|
||||
.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
.loadOp = cast(layout.depthResolveAttachment->getLoadOp()),
|
||||
.storeOp = cast(layout.depthResolveAttachment->getStoreOp()),
|
||||
.stencilLoadOp = cast(layout.depthResolveAttachment->getStencilLoadOp()),
|
||||
.stencilStoreOp = cast(layout.depthResolveAttachment->getStencilStoreOp()),
|
||||
.initialLayout = cast(layout.depthResolveAttachment->getInitialLayout()),
|
||||
.finalLayout = cast(layout.depthResolveAttachment->getFinalLayout()),
|
||||
};
|
||||
depthResolveRef = {
|
||||
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2,
|
||||
@@ -167,7 +167,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
};
|
||||
VkSubpassDescription2 subPassDesc = {
|
||||
.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2,
|
||||
.pNext = layout->depthResolveAttachment != nullptr ? &depthResolve : nullptr,
|
||||
.pNext = layout.depthResolveAttachment != nullptr ? &depthResolve : nullptr,
|
||||
.flags = 0,
|
||||
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
.inputAttachmentCount = (uint32)inputRefs.size(),
|
||||
@@ -177,17 +177,20 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
.pResolveAttachments = resolveRefs.size() > 0 ? resolveRefs.data() : nullptr,
|
||||
.pDepthStencilAttachment = &depthRef,
|
||||
};
|
||||
VkSubpassDependency2 dependency = {
|
||||
.sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2,
|
||||
.pNext = nullptr,
|
||||
.srcSubpass = VK_SUBPASS_EXTERNAL,
|
||||
.dstSubpass = 0,
|
||||
.srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
||||
.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT,
|
||||
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
};
|
||||
|
||||
Array<VkSubpassDependency2> dep;
|
||||
for(const auto& d : dependencies) {
|
||||
dep.add() = {
|
||||
.sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2,
|
||||
.pNext = nullptr,
|
||||
.srcSubpass = d.srcSubpass,
|
||||
.dstSubpass = d.dstSubpass,
|
||||
.srcStageMask = d.srcStage,
|
||||
.dstStageMask = d.dstStage,
|
||||
.srcAccessMask = d.srcAccess,
|
||||
.dstAccessMask = d.dstAccess,
|
||||
.dependencyFlags = 0,
|
||||
};
|
||||
}
|
||||
VkRenderPassCreateInfo2 info = {
|
||||
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2,
|
||||
.pNext = nullptr,
|
||||
@@ -195,8 +198,8 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
.pAttachments = attachments.data(),
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subPassDesc,
|
||||
.dependencyCount = 1,
|
||||
.pDependencies = &dependency,
|
||||
.dependencyCount = (uint32)dep.size(),
|
||||
.pDependencies = dep.data(),
|
||||
};
|
||||
|
||||
VK_CHECK(vkCreateRenderPass2(graphics->getDevice(), &info, nullptr, &renderPass));
|
||||
@@ -211,20 +214,39 @@ uint32 RenderPass::getFramebufferHash()
|
||||
{
|
||||
FramebufferDescription description;
|
||||
std::memset(&description, 0, sizeof(FramebufferDescription));
|
||||
for (auto& inputAttachment : layout->inputAttachments)
|
||||
for (auto& inputAttachment : layout.inputAttachments)
|
||||
{
|
||||
PTexture2D tex = inputAttachment->getTexture().cast<Texture2D>();
|
||||
description.inputAttachments[description.numInputAttachments++] = tex->getView();
|
||||
}
|
||||
for (auto& colorAttachment : layout->colorAttachments)
|
||||
for (auto& colorAttachment : layout.colorAttachments)
|
||||
{
|
||||
PTexture2D tex = colorAttachment->getTexture().cast<Texture2D>();
|
||||
description.colorAttachments[description.numColorAttachments++] = tex->getView();
|
||||
}
|
||||
if (layout->depthAttachment != nullptr)
|
||||
if (layout.depthAttachment != nullptr)
|
||||
{
|
||||
PTexture2D tex = layout->depthAttachment->getTexture().cast<Texture2D>();
|
||||
PTexture2D tex = layout.depthAttachment->getTexture().cast<Texture2D>();
|
||||
description.depthAttachment = tex->getView();
|
||||
}
|
||||
return CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
|
||||
}
|
||||
|
||||
void Vulkan::RenderPass::endRenderPass()
|
||||
{
|
||||
for (auto& inputAttachment : layout.inputAttachments)
|
||||
{
|
||||
PTexture2D tex = inputAttachment->getTexture().cast<Texture2D>();
|
||||
tex->setLayout(inputAttachment->getFinalLayout());
|
||||
}
|
||||
for (auto& colorAttachment : layout.colorAttachments)
|
||||
{
|
||||
PTexture2D tex = colorAttachment->getTexture().cast<Texture2D>();
|
||||
tex->setLayout(colorAttachment->getFinalLayout());
|
||||
}
|
||||
if (layout.depthAttachment != nullptr)
|
||||
{
|
||||
PTexture2D tex = layout.depthAttachment->getTexture().cast<Texture2D>();
|
||||
tex->setLayout(layout.depthAttachment->getFinalLayout());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user