43 template <
typename TAttachmentReferenceType>
44 struct FVulkanAttachmentReference :
public TAttachmentReferenceType
46 FVulkanAttachmentReference()
85 inline void SetAttachment(
const FVulkanAttachmentReference<TAttachmentReferenceType>& AttachmentReferenceIn, VkImageAspectFlags AspectMask) { *
this = AttachmentReferenceIn; }
96 inline void SetDepthStencilAttachment(
const VkAttachmentReference& AttachmentReferenceIn,
const VkAttachmentReferenceStencilLayout* StencilReference, VkImageAspectFlags AspectMask,
bool bSupportsParallelRendering) {
checkNoEntry(); }
116 attachment = AttachmentReferenceIn.attachment;
117 layout = AttachmentReferenceIn.layout;
128 const VkAttachmentReferenceStencilLayout* StencilReference, VkImageAspectFlags AspectMask,
bool bSupportsParallelRendering)
130 attachment = AttachmentReferenceIn.attachment;
133 layout = AttachmentReferenceIn.layout;
147 layout = VK_IMAGE_LAYOUT_UNDEFINED;
162 template<
typename TAttachmentDescriptionType>
174 :
public VkAttachmentDescription
195 flags = InDesc.flags;
196 format = InDesc.format;
197 samples = InDesc.samples;
198 loadOp = InDesc.loadOp;
199 storeOp = InDesc.storeOp;
200 stencilLoadOp = InDesc.stencilLoadOp;
201 stencilStoreOp = InDesc.stencilStoreOp;
202 initialLayout = InDesc.initialLayout;
203 finalLayout = InDesc.finalLayout;
213 FVulkanAttachmentDescription(
const VkAttachmentDescription& InDesc,
const VkAttachmentDescriptionStencilLayout* InStencilDesc,
bool bSupportsParallelRendering)
216 format = InDesc.format;
217 samples = InDesc.samples;
218 loadOp = InDesc.loadOp;
219 storeOp = InDesc.storeOp;
220 stencilLoadOp = InDesc.stencilLoadOp;
221 stencilStoreOp = InDesc.stencilStoreOp;
245 template <
typename TSubpassDescriptionType>
255 :
public VkSubpassDescription
267 pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
280 colorAttachmentCount = (OverrideCount == -1) ? ColorAttachmentReferences.Num() : OverrideCount;
281 pColorAttachments = ColorAttachmentReferences.GetData();
302 pDepthStencilAttachment =
static_cast<VkAttachmentReference*
>(DepthStencilAttachmentReference);
333 template <
typename TSubpassDependencyType>
335 :
public TSubpassDependencyType
346 :
public VkSubpassDependency
368 template <
typename T>
378 :
public VkRenderPassCreateInfo
390 this->sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
391 FMemory::Memzero(((uint8_t*)&(*
this)) +
sizeof(VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO),
sizeof(VkRenderPassCreateInfo) -
sizeof(VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO));
401 VkRenderPass Handle = VK_NULL_HANDLE;
403 VkResult result = vkCreateRenderPass(Device.
GetLogicalDevice(),
this,
nullptr, &Handle);
405 KR_CORE_ASSERT(result == VK_SUCCESS,
"Failed to create render pass");
420 MaxSimultaneousRenderTargets = 8,
421 MaxSimultaneousRenderTargets_NumBits = 3,
423 static_assert(MaxSimultaneousRenderTargets <= (1 << MaxSimultaneousRenderTargets_NumBits),
"MaxSimultaneousRenderTargets will not fit on MaxSimultaneousRenderTargets_NumBits");
524 bool bHasDepthAttachment;
526 VkRect2D m_RenderArea;
552 inline const VkAttachmentReference* GetColorAttachmentReferences()
const {
return m_NumColorAttachments > 0 ? m_ColorReferences :
nullptr; }
553 inline const VkAttachmentReference* GetDepthAttachmentReference()
const {
return bHasDepthStencil ? &m_DepthReference :
nullptr; }
554 inline const VkAttachmentReferenceStencilLayout* GetStencilAttachmentReference()
const {
return bHasDepthStencil ? &m_StencilReference :
nullptr; }
555 inline uint32_t GetNumColorAttachments()
const {
return m_NumColorAttachments; }
556 inline uint32_t GetNumAttachmentDescriptions()
const {
return m_NumAttachmentDescriptions; }
557 inline const VkAttachmentDescription* GetAttachmentDescriptions()
const {
return m_AttachmentDescriptions; }
558 inline const VkRect2D& GetRenderArea()
const {
return m_RenderArea; }
561 VkAttachmentReference m_ColorReferences[MaxSimultaneousRenderTargets];
564 VkAttachmentReference m_DepthReference;
567 VkAttachmentReferenceStencilLayout m_StencilReference;
569 uint8_t m_NumColorAttachments;
570 uint8_t m_NumAttachmentDescriptions;
577 VkAttachmentDescription m_AttachmentDescriptions[MaxSimultaneousRenderTargets * 2 + 2];
580 uint8_t bHasDepthStencil;
582 VkRect2D m_RenderArea;
593 inline VkRenderPass GetHandle()
const {
return m_RenderPass; }
614 VkRenderPass m_RenderPass;
625 template <
typename TSubpassDescriptionClass,
typename TSubpassDependencyClass,
typename TAttachmentReferenceClass,
typename TAttachmentDescriptionClass,
typename TRenderPassCreateInfoClass>
646 uint32_t NumSubpasses = 0;
647 uint32_t NumDependencies = 0;
650 uint32_t NumColorAttachments = RTLayout.GetNumColorAttachments();
653 const bool bHasDepthStencilAttachmentReference = (RTLayout.GetDepthAttachmentReference() !=
nullptr);
656 for (uint32_t Attachment = 0; Attachment < RTLayout.GetNumAttachmentDescriptions(); ++Attachment)
664 m_AttachmentDescriptions.Add(TAttachmentDescriptionClass(RTLayout.GetAttachmentDescriptions()[Attachment]));
669 for (uint32_t ColorAttachment = 0; ColorAttachment < NumColorAttachments; ++ColorAttachment)
671 m_ColorAttachmentReferences.Add(TAttachmentReferenceClass(RTLayout.GetColorAttachmentReferences()[ColorAttachment], 0));
675 if (bHasDepthStencilAttachmentReference)
678 m_DepthStencilAttachmentReference.SetDepthStencilAttachment(*RTLayout.GetDepthAttachmentReference(), RTLayout.GetStencilAttachmentReference(), 0,
false);
687 TSubpassDescriptionClass& SubpassDesc = m_SubpassDescriptions[NumSubpasses++];
689 SubpassDesc.SetColorAttachments(m_ColorAttachmentReferences, NumColorAttachments);
691 if (bHasDepthStencilAttachmentReference)
693 SubpassDesc.SetDepthStencilAttachment(&m_DepthStencilAttachmentReference);
698 TSubpassDependencyClass& SubpassDep = m_SubpassDependencies[NumDependencies++];
699 SubpassDep.srcSubpass = VK_SUBPASS_EXTERNAL;
700 SubpassDep.dstSubpass = 0;
701 SubpassDep.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
702 SubpassDep.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
703 SubpassDep.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
705 SubpassDep.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
707 m_CreateInfo.attachmentCount = m_AttachmentDescriptions.Num();
708 m_CreateInfo.pAttachments = m_AttachmentDescriptions.GetData();
709 m_CreateInfo.subpassCount = NumSubpasses;
710 m_CreateInfo.pSubpasses = m_SubpassDescriptions;
711 m_CreateInfo.dependencyCount = NumDependencies;
712 m_CreateInfo.pDependencies = m_SubpassDependencies;
724 return m_CreateInfo.Create(m_Device);
728 TSubpassDescriptionClass m_SubpassDescriptions[8];
729 TSubpassDependencyClass m_SubpassDependencies[8];
736 TAttachmentReferenceClass m_DepthStencilAttachmentReference;
737 TAttachmentReferenceClass m_DepthStencilAttachment;
739 TRenderPassCreateInfoClass m_CreateInfo;
743 VkRenderPass CreateVulkanRenderPass(FVulkanDevice& Device,
const FVulkanRenderTargetLayout& RTLayout);
This file contains the macros for Karma's classes' general purpose use, including assertions and stor...
#define checkNoEntry()
Denotes code paths that should never be reached.
Definition Core.h:117
This file contains the class FMemory..
This file contains the custom types used in Engine's logic.
#define KR_CORE_INFO(...)
A macro for logging information in the Core part.
Definition Log.h:85
Declaration of the FVulkanDevice class for managing Vulkan device resources.
Manages Vulkan device resources and operations.
Definition VulkanDevice.h:33
VkDevice GetLogicalDevice() const
Retrieves the Vulkan logical device handle.
Definition VulkanDevice.h:84
FVulkanRenderPassBuilder(FVulkanDevice &InDevice)
Constructor.
Definition VulkanRenderPass.h:634
VkRenderPass Create(const FVulkanRenderTargetLayout &RTLayout)
Create the Vulkan renderpass.
Definition VulkanRenderPass.h:720
void BuildCreateInfo(const FVulkanRenderTargetLayout &RTLayout)
Build the VkRenderPassCreateInfo structure from the supplied FVulkanRenderTargetLayout.
Definition VulkanRenderPass.h:644
FVulkanRenderPass(FVulkanDevice &Device, const FVulkanRenderTargetLayout &RTLayout)
Constructor to create a renderpass with supplied rendertarget layout.
Definition VulkanRenderPass.cpp:58
~FVulkanRenderPass()
Destroys renderpass.
Definition VulkanRenderPass.cpp:64
Data structure for Vulkan's render targets (color buffers and depth buffer).
Definition VulkanRenderPass.h:535
FVulkanRenderTargetLayout()=default
Default constructor provided for FVulkanRenderPass class constructor.
Template (for VkSubpassDescription(2)) definition of FVulkanSubpassDescription.
Definition VulkanRenderPass.h:247
Karma's std::vector wrapper with additional functionalities.
Definition KarmaTypes.h:243
static FORCEINLINE void * Memzero(void *Dest, SIZE_T Count)
Zeros the Count number of characters of object pointed by Dest.
Definition KarmaMemory.h:134
FVulkanAttachmentDescription(const VkAttachmentDescription &InDesc)
Constructor to copy from VkAttachmentDescription.
Definition VulkanRenderPass.h:193
FVulkanAttachmentDescription(const VkAttachmentDescription &InDesc, const VkAttachmentDescriptionStencilLayout *InStencilDesc, bool bSupportsParallelRendering)
Seems like we are not supporting VkAttachmentDescriptionStencilLayout.
Definition VulkanRenderPass.h:213
FVulkanAttachmentDescription()
Default constructor to zero initialize the structure.
Definition VulkanRenderPass.h:181
Template (for VkAttachmentDescription(2)) definition of FVulkanAttachmentDescription.
Definition VulkanRenderPass.h:164
Template definition of FVulkanAttachmentReference with specializations done later.
Definition VulkanRenderPass.h:45
void SetAttachment(const VkAttachmentReference &AttachmentReferenceIn, VkImageAspectFlags AspectMask)
Disable method enforced here (checkNoEntry()).
Definition VulkanRenderPass.h:78
void SetDepthStencilAttachment(const VkAttachmentReference &AttachmentReferenceIn, const VkAttachmentReferenceStencilLayout *StencilReference, VkImageAspectFlags AspectMask, bool bSupportsParallelRendering)
Disable method enforced here (checkNoEntry()).
Definition VulkanRenderPass.h:96
FVulkanAttachmentReference(const VkAttachmentReference &AttachmentReferenceIn, VkImageAspectFlags AspectMask)
Constructor to copy from VkAttachmentReference.
Definition VulkanRenderPass.h:56
void SetAttachment(const FVulkanAttachmentReference< TAttachmentReferenceType > &AttachmentReferenceIn, VkImageAspectFlags AspectMask)
Template definition of SetAttachment (specialized out-of-class definition exists).
Definition VulkanRenderPass.h:85
void ZeroStruct()
Template definition for zero initialization. Specialized out-of-class definition exists.
Definition VulkanRenderPass.h:103
VkRenderPass Create(FVulkanDevice &Device)
Actual renderpass creation function.
Definition VulkanRenderPass.h:399
FVulkanRenderPassCreateInfo()
Constructor to initialize the renderpass create info structure.
Definition VulkanRenderPass.h:387
Template definition of FVulkanRenderPassCreateInfo for VkRenderPassCreateInfo(2).
Definition VulkanRenderPass.h:370
Information about a single attachment in the renderpass.
Definition VulkanRenderPass.h:438
VkSampleCountFlagBits AttachmentSampleCount
Attachment sample count.
Definition VulkanRenderPass.h:452
VkAttachmentStoreOp AttachmentStoreOperation
what to do with attachment data after rendering
Definition VulkanRenderPass.h:462
VkAttachmentLoadOp AttachmentLoadOperation
what to do with attachment data before rendering
Definition VulkanRenderPass.h:457
VkImageLayout AttachmentFinalLayout
Attachment layout at the end of renderpass.
Definition VulkanRenderPass.h:498
VkImageLayout AttachmentInitialLayout
Attachment layout before renderpass begins.
Definition VulkanRenderPass.h:493
VkFormat AttachmentFormat
Format of the attachment (color format VK_FORMAT_R8G8B8A8_UNORM for instance).
Definition VulkanRenderPass.h:447
VkAttachmentLoadOp AttachmentStencilLoadOperation
what to do with stencil data before rendering
Definition VulkanRenderPass.h:467
VkAttachmentDescriptionFlags AttachmentFlags
Attachment description flags.
Definition VulkanRenderPass.h:442
VkAttachmentStoreOp AttachmentStencilStoreOperation
what to do with stencil data after rendering
Definition VulkanRenderPass.h:472
Reference to an attachment in the renderpass.
Definition VulkanRenderPass.h:505
VkImageLayout layout
The variable specifies which layout we would like the attachment to have during a subpass that uses t...
Definition VulkanRenderPass.h:519
uint32_t attachment
The parameter specifies which attachment to reference by its index in the attachment descriptions arr...
Definition VulkanRenderPass.h:509
Data structure to hold information about Vulkan renderpass attachments (like color and depth attachme...
Definition VulkanRenderPass.h:433
FVulkanSubpassDependency()
Default constructor to zero initialize the structure.
Definition VulkanRenderPass.h:355
Template definition of FVulkanSubpassDependency.
Definition VulkanRenderPass.h:336
FVulkanSubpassDescription()
Default constructor to zero initialize the structure.
Definition VulkanRenderPass.h:264
void SetDepthStencilAttachment(FVulkanAttachmentReference< VkAttachmentReference > *DepthStencilAttachmentReference)
Set depth-stencil attachment for the subpass.
Definition VulkanRenderPass.h:300
void SetColorAttachments(const KarmaVector< FVulkanAttachmentReference< VkAttachmentReference > > &ColorAttachmentReferences, int OverrideCount=-1)
Set color attachments for the subpass.
Definition VulkanRenderPass.h:278