More Refactoring
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include "RenderPass.h"
|
||||
#include "Initializer.h"
|
||||
#include "Graphics.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "Texture.h"
|
||||
@@ -25,107 +24,104 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
|
||||
for (auto& inputAttachment : layout->inputAttachments)
|
||||
{
|
||||
PTexture2D image = inputAttachment->getTexture().cast<Texture2D>();
|
||||
VkAttachmentDescription& desc = attachments.add();
|
||||
desc.flags = 0;
|
||||
desc.format = cast(image->getFormat());
|
||||
desc.storeOp = cast(inputAttachment->getStoreOp());
|
||||
desc.loadOp = cast(inputAttachment->getLoadOp());
|
||||
desc.stencilStoreOp = cast(inputAttachment->getStencilStoreOp());
|
||||
desc.stencilLoadOp = cast(inputAttachment->getStencilLoadOp());
|
||||
desc.initialLayout = image->isDepthStencil() ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
desc.finalLayout = desc.initialLayout;
|
||||
|
||||
VkAttachmentReference &ref = inputRefs.add();
|
||||
ref.layout = desc.initialLayout;
|
||||
ref.attachment = attachmentCounter;
|
||||
attachmentCounter++;
|
||||
VkAttachmentDescription& desc = attachments.add() = {
|
||||
.flags = 0,
|
||||
.format = cast(image->getFormat()),
|
||||
.loadOp = cast(inputAttachment->getLoadOp()),
|
||||
.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 = desc.initialLayout,
|
||||
};
|
||||
|
||||
inputRefs.add() = {
|
||||
.attachment = attachmentCounter++,
|
||||
.layout = desc.initialLayout,
|
||||
};
|
||||
}
|
||||
for (auto& colorAttachment : layout->colorAttachments)
|
||||
{
|
||||
VkAttachmentDescription& desc = attachments.add();
|
||||
desc.flags = 0;
|
||||
desc.samples = (VkSampleCountFlagBits)colorAttachment->getNumSamples();
|
||||
desc.format = cast(colorAttachment->getFormat());
|
||||
desc.storeOp = cast(colorAttachment->getStoreOp());
|
||||
desc.loadOp = cast(colorAttachment->getLoadOp());
|
||||
desc.stencilStoreOp = cast(colorAttachment->getStencilStoreOp());
|
||||
desc.stencilLoadOp = cast(colorAttachment->getStencilLoadOp());
|
||||
desc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
attachments.add() = {
|
||||
.flags = 0,
|
||||
.format = cast(colorAttachment->getFormat()),
|
||||
.samples = (VkSampleCountFlagBits)colorAttachment->getNumSamples(),
|
||||
.loadOp = cast(colorAttachment->getLoadOp()),
|
||||
.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,
|
||||
};
|
||||
|
||||
VkClearValue& clearValue = clearValues.add();
|
||||
if(desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
|
||||
if(attachments.back().loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
|
||||
{
|
||||
clearValue = cast(colorAttachment->clear);
|
||||
}
|
||||
|
||||
VkAttachmentReference &ref = colorRefs.add();
|
||||
ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
ref.attachment = attachmentCounter;
|
||||
attachmentCounter++;
|
||||
colorRefs.add() = {
|
||||
.attachment = attachmentCounter++,
|
||||
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
};
|
||||
}
|
||||
if (layout->depthAttachment != nullptr)
|
||||
{
|
||||
PTexture2D image = layout->depthAttachment->getTexture().cast<Texture2D>();
|
||||
VkAttachmentDescription& desc = attachments.add();
|
||||
desc.flags = 0;
|
||||
desc.samples = (VkSampleCountFlagBits)image->getNumSamples();
|
||||
desc.format = cast(image->getFormat());
|
||||
desc.storeOp = cast(layout->depthAttachment->getStoreOp());
|
||||
desc.loadOp = cast(layout->depthAttachment->getLoadOp());
|
||||
desc.stencilStoreOp = cast(layout->depthAttachment->getStencilStoreOp());
|
||||
desc.stencilLoadOp = cast(layout->depthAttachment->getStencilLoadOp());
|
||||
desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
|
||||
attachments.add() = {
|
||||
.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,
|
||||
};
|
||||
|
||||
VkClearValue& clearValue = clearValues.add();
|
||||
if(desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
|
||||
if(attachments.back().loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
|
||||
{
|
||||
clearValue = cast(layout->depthAttachment->clear);
|
||||
}
|
||||
|
||||
VkAttachmentReference &ref = depthRef;
|
||||
ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
ref.attachment = attachmentCounter;
|
||||
attachmentCounter++;
|
||||
depthRef = {
|
||||
.attachment = attachmentCounter++,
|
||||
.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
};
|
||||
}
|
||||
VkSubpassDescription subPassDesc =
|
||||
init::SubpassDescription(
|
||||
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
(uint32)colorRefs.size(),
|
||||
colorRefs.data(),
|
||||
&depthRef,
|
||||
(uint32)inputRefs.size(),
|
||||
inputRefs.data());
|
||||
VkSubpassDependency dependency = {};
|
||||
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||
dependency.dstSubpass = 0;
|
||||
|
||||
dependency.srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
dependency.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||
|
||||
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
|
||||
VkRenderPassCreateInfo info =
|
||||
init::RenderPassCreateInfo(
|
||||
(uint32)attachments.size(),
|
||||
attachments.data(),
|
||||
1,
|
||||
&subPassDesc,
|
||||
1,
|
||||
&dependency);
|
||||
VkSubpassDescription subPassDesc = {
|
||||
.flags = 0,
|
||||
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
.inputAttachmentCount = (uint32)inputRefs.size(),
|
||||
.pInputAttachments = inputRefs.data(),
|
||||
.colorAttachmentCount = (uint32)colorRefs.size(),
|
||||
.pColorAttachments = colorRefs.data(),
|
||||
.pDepthStencilAttachment = &depthRef,
|
||||
};
|
||||
VkSubpassDependency dependency = {
|
||||
.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,
|
||||
};
|
||||
|
||||
VkRenderPassCreateInfo info = {
|
||||
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.attachmentCount = (uint32)attachments.size(),
|
||||
.pAttachments = attachments.data(),
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subPassDesc,
|
||||
.dependencyCount = 1,
|
||||
.pDependencies = &dependency,
|
||||
};
|
||||
|
||||
VK_CHECK(vkCreateRenderPass(graphics->getDevice(), &info, nullptr, &renderPass));
|
||||
}
|
||||
|
||||
RenderPass::~RenderPass()
|
||||
{
|
||||
vkDestroyRenderPass(graphics->getDevice(), renderPass, nullptr);
|
||||
}
|
||||
|
||||
uint32 RenderPass::getFramebufferHash()
|
||||
{
|
||||
FramebufferDescription description;
|
||||
std::memset(&description, 0, sizeof(FramebufferDescription));
|
||||
for (auto& inputAttachment : layout->inputAttachments)
|
||||
@@ -143,6 +139,11 @@ uint32 RenderPass::getFramebufferHash()
|
||||
PTexture2D tex = layout->depthAttachment->getTexture().cast<Texture2D>();
|
||||
description.depthAttachment = tex->getView();
|
||||
}
|
||||
return CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
|
||||
framebufferHash = CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
|
||||
}
|
||||
|
||||
RenderPass::~RenderPass()
|
||||
{
|
||||
vkDestroyRenderPass(graphics->getDevice(), renderPass, nullptr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user