UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VulkanRenderpass.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 VulkanState.h: Vulkan state definitions.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "RHI.h"
11#include "VulkanRHIPrivate.h"
13#include "VulkanResources.h"
14#include "VulkanPendingState.h"
15
17
18template <typename TAttachmentReferenceType>
38
39template <>
45
46template <>
48{
50 pNext = nullptr;
54}
55
56template<>
58{
60 pNext = nullptr;
64}
65
66template <>
74
75template <>
78{
80 {
82 }
83 const bool bHasStencilReference = StencilReference && (StencilReference->stencilLayout != VK_IMAGE_LAYOUT_UNDEFINED);
84
86 pNext = (bSupportsParallelRendering && bHasStencilReference) ? StencilReference : nullptr;
90}
91
92
93template<>
99
100template<>
102{
104 pNext = nullptr;
105 attachment = 0;
107 aspectMask = 0;
108}
109
110template<>
112{
114}
115
116template <typename TSubpassDescriptionType>
120
121template<>
122struct FVulkanSubpassDescription<VkSubpassDescription>
123 : public VkSubpassDescription
124{
126 {
127 FMemory::Memzero(this, sizeof(VkSubpassDescription));
129 }
130
132 {
133 colorAttachmentCount = (OverrideCount == -1) ? ColorAttachmentReferences.Num() : OverrideCount;
134 pColorAttachments = ColorAttachmentReferences.GetData();
135 }
136
138 {
139 if (ResolveAttachmentReferences.Num() > 0)
140 {
141 check(colorAttachmentCount == ResolveAttachmentReferences.Num());
142 pResolveAttachments = ResolveAttachmentReferences.GetData();
143 }
144 }
145
147 {
148 pDepthStencilAttachment = static_cast<VkAttachmentReference*>(DepthStencilAttachmentReference);
149 }
150
156
157 void SetDepthStencilResolveAttachment(VkSubpassDescriptionDepthStencilResolveKHR* DepthStencilResolveAttachmentDesc)
158 {
159 // No-op without VK_KHR_create_renderpass2
160 }
161
162 void SetShadingRateAttachment(VkFragmentShadingRateAttachmentInfoKHR* /* ShadingRateAttachmentInfo */)
163 {
164 // No-op without VK_KHR_create_renderpass2
165 }
166
168 {
169 // No-op without VK_KHR_create_renderpass2
170 }
171};
172
173template<>
174struct FVulkanSubpassDescription<VkSubpassDescription2>
175 : public VkSubpassDescription2
176{
183
185 {
186 colorAttachmentCount = OverrideCount == -1 ? ColorAttachmentReferences.Num() : OverrideCount;
187 pColorAttachments = ColorAttachmentReferences.GetData();
188 }
189
191 {
192 if (ResolveAttachmentReferences.Num() > 0)
193 {
194 check(colorAttachmentCount == ResolveAttachmentReferences.Num());
195 pResolveAttachments = ResolveAttachmentReferences.GetData();
196 }
197 }
198
200 {
201 pDepthStencilAttachment = static_cast<VkAttachmentReference2*>(DepthStencilAttachmentReference);
202 }
203
209
210 void SetDepthStencilResolveAttachment(VkSubpassDescriptionDepthStencilResolveKHR* DepthStencilResolveAttachmentDesc)
211 {
212 const void* Next = pNext;
215 }
216
217 void SetShadingRateAttachment(VkFragmentShadingRateAttachmentInfoKHR* ShadingRateAttachmentInfo)
218 {
219 const void* Next = pNext;
222 }
223
225 {
226 viewMask = Mask;
227 }
228};
229
230template <typename TSubpassDependencyType>
232 : public TSubpassDependencyType
233{
234};
235
236template<>
237struct FVulkanSubpassDependency<VkSubpassDependency>
238 : public VkSubpassDependency
239{
241 {
242 FMemory::Memzero(this, sizeof(VkSubpassDependency));
243 }
244};
245
246template<>
247struct FVulkanSubpassDependency<VkSubpassDependency2>
248 : public VkSubpassDependency2
249{
251 {
252 ZeroVulkanStruct(*this, VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2);
253 viewOffset = 0; // According to the Vulkan spec: "If dependencyFlags does not include VK_DEPENDENCY_VIEW_LOCAL_BIT, viewOffset must be 0"
254 }
255};
256
257template<typename TAttachmentDescriptionType>
261
262template<>
263struct FVulkanAttachmentDescription<VkAttachmentDescription>
264 : public VkAttachmentDescription
265{
267 {
268 FMemory::Memzero(this, sizeof(VkAttachmentDescription));
269 }
270
271 FVulkanAttachmentDescription(const VkAttachmentDescription& InDesc)
272 {
273 flags = InDesc.flags;
274 format = InDesc.format;
275 samples = InDesc.samples;
276 loadOp = InDesc.loadOp;
277 storeOp = InDesc.storeOp;
278 stencilLoadOp = InDesc.stencilLoadOp;
279 stencilStoreOp = InDesc.stencilStoreOp;
280 initialLayout = InDesc.initialLayout;
281 finalLayout = InDesc.finalLayout;
282 }
283
285 {
286 flags = InDesc.flags;
287 format = InDesc.format;
288 samples = InDesc.samples;
289 loadOp = InDesc.loadOp;
290 storeOp = InDesc.storeOp;
291 stencilLoadOp = InDesc.stencilLoadOp;
292 stencilStoreOp = InDesc.stencilStoreOp;
293
294 const bool bHasStencilLayout = VulkanRHI::VulkanFormatHasStencil(InDesc.format) && (InStencilDesc != nullptr);
299 }
300};
301
302template<>
303struct FVulkanAttachmentDescription<VkAttachmentDescription2>
304 : public VkAttachmentDescription2
305{
310
311 FVulkanAttachmentDescription(const VkAttachmentDescription& InDesc)
312 {
314 pNext = nullptr;
315 flags = InDesc.flags;
316 format = InDesc.format;
317 samples = InDesc.samples;
318 loadOp = InDesc.loadOp;
319 storeOp = InDesc.storeOp;
320 stencilLoadOp = InDesc.stencilLoadOp;
321 stencilStoreOp = InDesc.stencilStoreOp;
322 initialLayout = InDesc.initialLayout;
323 finalLayout = InDesc.finalLayout;
324 }
325
327 {
329 {
331 }
332 const bool bHasStencilLayout = bSupportsParallelRendering && VulkanRHI::VulkanFormatHasStencil(InDesc.format) && (InStencilDesc != nullptr);
333
335 pNext = (bHasStencilLayout && (InStencilDesc->stencilFinalLayout != VK_IMAGE_LAYOUT_UNDEFINED)) ? InStencilDesc : nullptr;
336 flags = InDesc.flags;
337 format = InDesc.format;
338 samples = InDesc.samples;
339 loadOp = InDesc.loadOp;
340 storeOp = InDesc.storeOp;
341 stencilLoadOp = InDesc.stencilLoadOp;
342 stencilStoreOp = InDesc.stencilStoreOp;
343 initialLayout = (bSupportsParallelRendering || (InStencilDesc == nullptr)) ? InDesc.initialLayout : VulkanRHI::GetMergedDepthStencilLayout(InDesc.initialLayout, InStencilDesc->stencilInitialLayout);
344 finalLayout = (bSupportsParallelRendering || (InStencilDesc == nullptr)) ? InDesc.finalLayout : VulkanRHI::GetMergedDepthStencilLayout(InDesc.finalLayout, InStencilDesc->stencilFinalLayout);
345 }
346};
347
348template <typename T>
351
352template<>
353struct FVulkanRenderPassCreateInfo<VkRenderPassCreateInfo>
354 : public VkRenderPassCreateInfo
355{
360
362 {
363 // No-op without VK_KHR_create_renderpass2
364 }
365
367 {
369 VERIFYVULKANRESULT_EXPANDED(VulkanRHI::vkCreateRenderPass(Device.GetHandle(), this, VULKAN_CPU_ALLOCATOR, &Handle));
370 return Handle;
371 }
372};
373
375 : public VkRenderPassFragmentDensityMapCreateInfoEXT
376{
381};
382
384 : public VkRenderPassMultiviewCreateInfo
385{
390};
391
392template<>
393struct FVulkanRenderPassCreateInfo<VkRenderPassCreateInfo2>
394 : public VkRenderPassCreateInfo2
395{
400
406
408 {
410 VERIFYVULKANRESULT_EXPANDED(VulkanRHI::vkCreateRenderPass2KHR(Device.GetHandle(), this, VULKAN_CPU_ALLOCATOR, &Handle));
411 return Handle;
412 }
413};
414
416 : public VkFragmentShadingRateAttachmentInfoKHR
417{
419 {
421 // For now, just use the smallest tile-size available. TODO: Add a setting to allow prioritizing either higher resolution/larger shading rate attachment targets
422 // or lower-resolution/smaller attachments.
424 }
425
430};
431
451
453{
454public:
456 {
457 return Layout;
458 }
459
460 inline VkRenderPass GetHandle() const
461 {
462 return RenderPass;
463 }
464
466 {
467 return NumUsedClearValues;
468 }
469
470private:
473
476
477private:
479 VkRenderPass RenderPass;
480 uint32 NumUsedClearValues;
481 FVulkanDevice& Device;
482};
483
485
486template <typename TSubpassDescriptionClass, typename TSubpassDependencyClass, typename TAttachmentReferenceClass, typename TAttachmentDescriptionClass, typename TRenderPassCreateInfoClass>
488{
489public:
491 : Device(InDevice)
492 , CorrelationMask(0)
493 {}
494
496 {
498 uint32 NumDependencies = 0;
499
500 //0b11 for 2, 0b1111 for 4, and so on
501 uint32 MultiviewMask = (0b1 << RTLayout.GetMultiViewCount()) - 1;
502
505 && RTLayout.GetFragmentDensityAttachmentReference() != nullptr
507 && Device.GetOptionalExtensionProperties().FragmentShadingRateFeatures.attachmentFragmentShadingRate == VK_TRUE;
510 RTLayout.GetHasDepthStencilResolve();
511
512 const bool bCustomResolveSubpass = RTLayout.GetSubpassHint() == ESubpassHint::CustomResolveSubpass;
513 const bool bDepthReadSubpass = bCustomResolveSubpass || (RTLayout.GetSubpassHint() == ESubpassHint::DepthReadSubpass);
514 const bool bHasDepthStencilAttachmentReference = (RTLayout.GetDepthAttachmentReference() != nullptr);
515
517 {
518 ShadingRateAttachmentReference.SetAttachment(*RTLayout.GetFragmentDensityAttachmentReference(), VkImageAspectFlagBits::VK_IMAGE_ASPECT_COLOR_BIT);
519 FragmentShadingRateAttachmentInfo.SetReference(&ShadingRateAttachmentReference);
520 }
521
522 if (bResolveDepth)
523 {
524 DepthStencilResolveAttachmentReference.SetAttachment(*RTLayout.GetDepthStencilResolveAttachmentReference(), VkImageAspectFlagBits::VK_IMAGE_ASPECT_NONE);
525 // Using zero bit because it is always supported if the extension is supported, from spec: "The VK_RESOLVE_MODE_SAMPLE_ZERO_BIT mode
526 // is the only mode that is required of all implementations (that support the extension or support Vulkan 1.2 or higher)."
528 DepthStencilResolveSubpassDesc.SetReference(&DepthStencilResolveAttachmentReference);
529 }
530
531 // Grab (and optionally convert) attachment references.
532 uint32 NumColorAttachments = RTLayout.GetNumColorAttachments();
533 for (uint32 ColorAttachment = 0; ColorAttachment < NumColorAttachments; ++ColorAttachment)
534 {
535 ColorAttachmentReferences.Add(TAttachmentReferenceClass(RTLayout.GetColorAttachmentReferences()[ColorAttachment], 0));
536 if (RTLayout.GetResolveAttachmentReferences() != nullptr)
537 {
538 ResolveAttachmentReferences.Add(TAttachmentReferenceClass(RTLayout.GetResolveAttachmentReferences()[ColorAttachment], 0));
539 }
540 }
541
542 // CustomResolveSubpass has an additional color attachment that should not be used by main and depth subpasses
543 if (bCustomResolveSubpass && (NumColorAttachments > 1))
544 {
545 NumColorAttachments--;
546 }
547
552 {
553 DepthStencilAttachmentReference.SetDepthStencilAttachment(*RTLayout.GetDepthAttachmentReference(), RTLayout.GetStencilAttachmentReference(), 0, Device.SupportsParallelRendering());
554
556 {
557 DepthStencilAttachment.attachment = RTLayout.GetDepthAttachmentReference()->attachment;
558 DepthStencilAttachment.SetAspect(VK_IMAGE_ASPECT_DEPTH_BIT); // @todo?
559
560 // FIXME: checking a Depth layout is not correct in all cases
561 // PSO cache can create a PSO for subpass 1 or 2 first, where depth is read-only but that does not mean depth pre-pass is enabled
562 if (false && RTLayout.GetDepthAttachmentReference()->layout == VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL)
563 {
564 // Depth is read only and is expected to be sampled as a regular texture
565 DepthStencilAttachment.layout = VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL;
566 }
567 else
568 {
569 // lights write to stencil for culling, so stencil is expected to be writebale while depth is read-only
571 DepthInputAttachment = DepthStencilAttachment.attachment;
572 DepthInputAttachmentLayout = DepthStencilAttachment.layout;
574 }
575 }
576 }
577
578 // main sub-pass
579 {
580 TSubpassDescriptionClass& SubpassDesc = SubpassDescriptions[NumSubpasses++];
581
582 SubpassDesc.SetColorAttachments(ColorAttachmentReferences, NumColorAttachments);
583
585 {
586 SubpassDesc.SetDepthStencilAttachment(&DepthStencilAttachmentReference);
587 }
588
590 {
591 SubpassDesc.SetDepthStencilResolveAttachment(&DepthStencilResolveSubpassDesc);
592 }
593
595 {
596 SubpassDesc.SetShadingRateAttachment(&FragmentShadingRateAttachmentInfo);
597 }
598 SubpassDesc.SetMultiViewMask(MultiviewMask);
599 }
600
601 // Color write and depth read sub-pass
603 {
604 TSubpassDescriptionClass& SubpassDesc = SubpassDescriptions[NumSubpasses++];
605
606 SubpassDesc.SetColorAttachments(ColorAttachmentReferences, 1);
607
608 check(RTLayout.GetDepthAttachmentReference());
609
610 // Depth as Input0
611 InputAttachments1[0].attachment = DepthInputAttachment;
612 InputAttachments1[0].layout = DepthInputAttachmentLayout;
613 InputAttachments1[0].SetAspect(DepthInputAspectMask);
614 SubpassDesc.SetInputAttachments(InputAttachments1, InputAttachment1Count);
615 // depth attachment is same as input attachment
616 SubpassDesc.SetDepthStencilAttachment(&DepthStencilAttachment);
617
618 if (bResolveDepth && !bCustomResolveSubpass)
619 {
620 SubpassDesc.SetDepthStencilResolveAttachment(&DepthStencilResolveSubpassDesc);
621 }
622
624 {
625 SubpassDesc.SetShadingRateAttachment(&FragmentShadingRateAttachmentInfo);
626 }
627 SubpassDesc.SetMultiViewMask(MultiviewMask);
628
629 TSubpassDependencyClass& SubpassDep = SubpassDependencies[NumDependencies++];
630 SubpassDep.srcSubpass = 0;
631 SubpassDep.dstSubpass = 1;
636 SubpassDep.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
637 }
638
639 // Two subpasses for deferred shading
641 {
642 //const VkAttachmentReference* ColorRef = RTLayout.GetColorAttachmentReferences();
643 //uint32 NumColorAttachments = RTLayout.GetNumColorAttachments();
644 //check(RTLayout.GetNumColorAttachments() == 5); //current layout is SceneColor, GBufferA/B/C/D
645
646 // 1. Write to SceneColor and GBuffer, input DepthStencil
647 {
648 TSubpassDescriptionClass& SubpassDesc = SubpassDescriptions[NumSubpasses++];
649 SubpassDesc.SetColorAttachments(ColorAttachmentReferences);
650 SubpassDesc.SetDepthStencilAttachment(&DepthStencilAttachment);
651 InputAttachments1[0].attachment = DepthInputAttachment;
652 InputAttachments1[0].layout = DepthInputAttachmentLayout;
653 InputAttachments1[0].SetAspect(DepthInputAspectMask);
654 SubpassDesc.SetInputAttachments(InputAttachments1, InputAttachment1Count);
655
657 {
658 SubpassDesc.SetShadingRateAttachment(&FragmentShadingRateAttachmentInfo);
659 }
660 SubpassDesc.SetMultiViewMask(MultiviewMask);
661
662 // Depth as Input0
663 TSubpassDependencyClass& SubpassDep = SubpassDependencies[NumDependencies++];
664 SubpassDep.srcSubpass = 0;
665 SubpassDep.dstSubpass = 1;
670 SubpassDep.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
671 }
672
673 // 2. Write to SceneColor, input GBuffer and DepthStencil
674 {
675 TSubpassDescriptionClass& SubpassDesc = SubpassDescriptions[NumSubpasses++];
676 SubpassDesc.SetColorAttachments(ColorAttachmentReferences, 1); // SceneColor only
677 SubpassDesc.SetDepthStencilAttachment(&DepthStencilAttachment);
678
679 // Depth as Input0
680 InputAttachments2[0].attachment = DepthInputAttachment;
681 InputAttachments2[0].layout = DepthInputAttachmentLayout;
682 InputAttachments2[0].SetAspect(DepthInputAspectMask);
683
684 // SceneColor write only
685 InputAttachments2[1].attachment = VK_ATTACHMENT_UNUSED;
686 InputAttachments2[1].layout = VK_IMAGE_LAYOUT_UNDEFINED;
687 InputAttachments2[1].SetAspect(0);
688
689 // GBufferA/B/C/D as Input2/3/4/5
690 int32 NumColorInputs = ColorAttachmentReferences.Num() - 1;
691 for (int32 i = 2; i < (NumColorInputs + 2); ++i)
692 {
693 InputAttachments2[i].attachment = ColorAttachmentReferences[i - 1].attachment;
694 InputAttachments2[i].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
695 InputAttachments2[i].SetAspect(VK_IMAGE_ASPECT_COLOR_BIT);
696 }
697
698 SubpassDesc.SetInputAttachments(InputAttachments2, NumColorInputs + 2);
700 {
701 SubpassDesc.SetShadingRateAttachment(&FragmentShadingRateAttachmentInfo);
702 }
703 SubpassDesc.SetMultiViewMask(MultiviewMask);
704
705 TSubpassDependencyClass& SubpassDep = SubpassDependencies[NumDependencies++];
706 SubpassDep.srcSubpass = 1;
707 SubpassDep.dstSubpass = 2;
713 {
714 // this is not required, but might flicker on some devices without
715 SubpassDep.dstAccessMask |= VK_ACCESS_SHADER_READ_BIT;
716 }
717 SubpassDep.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
718 }
719 }
720
721 // Custom resolve subpass
722 if (bCustomResolveSubpass)
723 {
724 TSubpassDescriptionClass& SubpassDesc = SubpassDescriptions[NumSubpasses++];
725 ColorAttachments3[0].attachment = ColorAttachmentReferences[1].attachment;
726 ColorAttachments3[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
727 ColorAttachments3[0].SetAspect(VK_IMAGE_ASPECT_COLOR_BIT);
728
729 InputAttachments3[0].attachment = VK_ATTACHMENT_UNUSED; // The subpass fetch logic expects depth in first attachment.
730 InputAttachments3[0].layout = VK_IMAGE_LAYOUT_UNDEFINED;
731 InputAttachments3[0].SetAspect(0);
732
733 InputAttachments3[1].attachment = ColorAttachmentReferences[0].attachment; // SceneColor as input
734 InputAttachments3[1].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
735 InputAttachments3[1].SetAspect(VK_IMAGE_ASPECT_COLOR_BIT);
736
737 SubpassDesc.SetDepthStencilAttachment(&DepthStencilAttachment);
738
739 if (bResolveDepth)
740 {
741 SubpassDesc.SetDepthStencilResolveAttachment(&DepthStencilResolveSubpassDesc);
742 }
743
744 SubpassDesc.SetInputAttachments(InputAttachments3, 2);
745 SubpassDesc.colorAttachmentCount = 1;
746 SubpassDesc.pColorAttachments = ColorAttachments3;
747
748 SubpassDesc.SetMultiViewMask(MultiviewMask);
749
750 TSubpassDependencyClass& SubpassDep = SubpassDependencies[NumDependencies++];
751 SubpassDep.srcSubpass = 1;
752 SubpassDep.dstSubpass = 2;
757 SubpassDep.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
758 }
759
760 // CustomResolveSubpass does a custom resolve into second color target and does not need resolve attachments
761 if (!bCustomResolveSubpass)
762 {
763 if (bDepthReadSubpass && ResolveAttachmentReferences.Num() > 1)
764 {
765 // Handle SceneDepthAux resolve:
766 // The depth read subpass has only a single color attachment (using more would not be compatible dual source blending), so make SceneDepthAux a resolve attachment of the first subpass instead
767 ResolveAttachmentReferences.Add(TAttachmentReferenceClass{});
768 ResolveAttachmentReferences.Last().attachment = VK_ATTACHMENT_UNUSED;
769 Swap(ResolveAttachmentReferences.Last(), ResolveAttachmentReferences[0]);
770
771 SubpassDescriptions[0].SetResolveAttachments(TArrayView<TAttachmentReferenceClass>(ResolveAttachmentReferences.GetData(), ResolveAttachmentReferences.Num() - 1));
772 SubpassDescriptions[NumSubpasses - 1].SetResolveAttachments(TArrayView<TAttachmentReferenceClass>(&ResolveAttachmentReferences.Last(), 1));
773 }
774 else
775 {
776 // Only set resolve attachment on the last subpass
777 SubpassDescriptions[NumSubpasses - 1].SetResolveAttachments(ResolveAttachmentReferences);
778 }
779 }
780
781 for (uint32 Attachment = 0; Attachment < RTLayout.GetNumAttachmentDescriptions(); ++Attachment)
782 {
783 if (bHasDepthStencilAttachmentReference && (Attachment == DepthStencilAttachmentReference.attachment))
784 {
785 AttachmentDescriptions.Add(TAttachmentDescriptionClass(RTLayout.GetAttachmentDescriptions()[Attachment], RTLayout.GetStencilDesc(), Device.SupportsParallelRendering()));
786 }
787 else
788 {
789 AttachmentDescriptions.Add(TAttachmentDescriptionClass(RTLayout.GetAttachmentDescriptions()[Attachment]));
790 }
791 }
792
793 CreateInfo.attachmentCount = AttachmentDescriptions.Num();
794 CreateInfo.pAttachments = AttachmentDescriptions.GetData();
795 CreateInfo.subpassCount = NumSubpasses;
796 CreateInfo.pSubpasses = SubpassDescriptions;
797 CreateInfo.dependencyCount = NumDependencies;
798 CreateInfo.pDependencies = SubpassDependencies;
799
800 /*
801 Bit mask that specifies which view rendering is broadcast to
802 0011 = Broadcast to first and second view (layer)
803 */
804 ViewMask[0] = MultiviewMask;
805 ViewMask[1] = MultiviewMask;
806
807 /*
808 Bit mask that specifices correlation between views
809 An implementation may use this for optimizations (concurrent render)
810 */
811 CorrelationMask = MultiviewMask;
812
813 if (RTLayout.GetIsMultiView())
814 {
816 {
817 CreateInfo.SetCorrelationMask(&CorrelationMask);
818 }
819 else
820 {
821 checkf(Device.GetOptionalExtensions().HasKHRMultiview, TEXT("Layout is multiview but extension is not supported!"));
822 MultiviewInfo.subpassCount = NumSubpasses;
823 MultiviewInfo.pViewMasks = ViewMask;
824 MultiviewInfo.dependencyCount = 0;
825 MultiviewInfo.pViewOffsets = nullptr;
826 MultiviewInfo.correlationMaskCount = 1;
827 MultiviewInfo.pCorrelationMasks = &CorrelationMask;
828
829 MultiviewInfo.pNext = CreateInfo.pNext;
830 CreateInfo.pNext = &MultiviewInfo;
831 }
832 }
833
834 if (Device.GetOptionalExtensions().HasEXTFragmentDensityMap && RTLayout.GetHasFragmentDensityAttachment())
835 {
836 FragDensityCreateInfo.fragmentDensityMapAttachment = *RTLayout.GetFragmentDensityAttachmentReference();
837
838 // Chain fragment density info onto create info and the rest of the pNexts
839 // onto the fragment density info
840 FragDensityCreateInfo.pNext = CreateInfo.pNext;
841 CreateInfo.pNext = &FragDensityCreateInfo;
842 }
843 }
844
846 {
848
849 return CreateInfo.Create(Device);
850 }
851
853 {
854 return CreateInfo;
855 }
856
857private:
858 TSubpassDescriptionClass SubpassDescriptions[8];
859 TSubpassDependencyClass SubpassDependencies[8];
860
861 TArray<TAttachmentReferenceClass> ColorAttachmentReferences;
862 TArray<TAttachmentReferenceClass> ResolveAttachmentReferences;
863
864 // Color write and depth read sub-pass
865 static const uint32 InputAttachment1Count = 1;
866 TAttachmentReferenceClass InputAttachments1[InputAttachment1Count];
867
868 // Two subpasses for deferred shading
870 TAttachmentReferenceClass DepthStencilAttachment;
871
872 TAttachmentReferenceClass DepthStencilAttachmentReference;
873 TArray<TAttachmentDescriptionClass> AttachmentDescriptions;
874
875 // Tonemap subpass
878
879 FVulkanAttachmentReference<VkAttachmentReference2> ShadingRateAttachmentReference;
880 FVulkanFragmentShadingRateAttachmentInfo FragmentShadingRateAttachmentInfo;
881
882 // Depth stencil resolve
883 FVulkanAttachmentReference<VkAttachmentReference2> DepthStencilResolveAttachmentReference;
884 FVulkanDepthStencilResolveSubpassDesc DepthStencilResolveSubpassDesc;
885
888
890 FVulkanDevice& Device;
891
892 uint32 ViewMask[2];
893 uint32 CorrelationMask;
894};
895
897
904
906{
907public:
910
913 {
914 const uint32 RenderPassHash = RTLayout.GetRenderPassFullHash();
915
916 {
918 FVulkanRenderPass** FoundRenderPass = RenderPasses.Find(RenderPassHash);
919 if (FoundRenderPass)
920 {
921 return *FoundRenderPass;
922 }
923 }
924
925 FVulkanRenderPass* RenderPass = new FVulkanRenderPass(Device, RTLayout);
926 {
928 FVulkanRenderPass** FoundRenderPass = RenderPasses.Find(RenderPassHash);
929 if (FoundRenderPass)
930 {
931 delete RenderPass;
932 return *FoundRenderPass;
933 }
934 RenderPasses.Add(RenderPassHash, RenderPass);
935 }
936 return RenderPass;
937 }
938
941
944
946
947private:
948
950
951 struct FFramebufferList
952 {
953 TArray<FVulkanFramebuffer*> Framebuffer;
954 };
956
957 FVulkanDevice& Device;
958};
GLenum attachment
Definition AndroidOpenGLFunctions.h:46
#define check(expr)
Definition AssertionMacros.h:314
#define checkNoEntry()
Definition AssertionMacros.h:316
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ MaxSimultaneousRenderTargets
Definition RHIDefinitions.h:287
#define GRHISupportsDepthStencilResolve
Definition RHIGlobals.h:918
#define GRHIVariableRateShadingImageTileMinWidth
Definition RHIGlobals.h:889
#define GRHISupportsAttachmentVariableRateShading
Definition RHIGlobals.h:884
#define GRHIVariableRateShadingImageTileMinHeight
Definition RHIGlobals.h:890
@ DeferredShadingSubpass
@ SLT_ReadOnly
Definition ScopeRWLock.h:138
@ SLT_Write
Definition ScopeRWLock.h:139
#define VULKAN_CPU_ALLOCATOR
Definition VulkanConfiguration.h:232
int32 GVulkanInputAttachmentShaderRead
Definition VulkanRHI.cpp:73
VkRenderPass CreateVulkanRenderPass(FVulkanDevice &Device, const FVulkanRenderTargetLayout &RTLayout)
Definition VulkanRenderpass.cpp:8
#define VERIFYVULKANRESULT_EXPANDED(VkFunction)
Definition VulkanUtil.h:33
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition RHIResources.h:4167
Definition ScopeRWLock.h:199
static bool RequiresMergedDepthStencilLayout()
Definition VulkanAndroidPlatform.h:213
Definition VulkanContext.h:241
Definition VulkanDevice.h:279
const FOptionalVulkanDeviceExtensionProperties & GetOptionalExtensionProperties() const
Definition VulkanDevice.h:545
VkDevice GetHandle() const
Definition VulkanDevice.h:425
bool SupportsParallelRendering() const
Definition VulkanDevice.h:555
const FOptionalVulkanDeviceExtensions & GetOptionalExtensions() const
Definition VulkanDevice.h:540
Definition VulkanFramebuffer.h:8
Definition VulkanPipeline.h:492
Definition VulkanRenderpass.h:488
FVulkanRenderPassBuilder(FVulkanDevice &InDevice)
Definition VulkanRenderpass.h:490
TRenderPassCreateInfoClass & GetCreateInfo()
Definition VulkanRenderpass.h:852
void BuildCreateInfo(const FVulkanRenderTargetLayout &RTLayout)
Definition VulkanRenderpass.h:495
VkRenderPass Create(const FVulkanRenderTargetLayout &RTLayout)
Definition VulkanRenderpass.h:845
Definition VulkanRenderpass.h:906
void BeginRenderPass(FVulkanCommandListContext &Context, const FRHIRenderPassInfo &RPInfo, const FVulkanRenderTargetLayout &RTLayout, const FVulkanBeginRenderPassInfo &BeginRenderPassInfo)
Definition VulkanRenderpass.cpp:124
void NotifyDeletedRenderTarget(VkImage Image)
Definition VulkanRenderpass.cpp:222
~FVulkanRenderPassManager()
Definition VulkanRenderpass.cpp:28
FVulkanRenderPass * GetOrCreateRenderPass(const FVulkanRenderTargetLayout &RTLayout)
Definition VulkanRenderpass.h:912
void EndRenderPass(FVulkanCommandListContext &Context)
Definition VulkanRenderpass.cpp:214
FRWLock FramebuffersLock
Definition VulkanRenderpass.h:943
FVulkanFramebuffer * GetOrCreateFramebuffer(const FRHISetRenderTargetsInfo &RenderTargetsInfo, const FVulkanRenderTargetLayout &RTLayout, FVulkanRenderPass &RenderPass)
Definition VulkanRenderpass.cpp:52
FVulkanRenderPassManager(FVulkanDevice &InDevice)
Definition VulkanRenderpass.h:908
FRWLock RenderPassesLock
Definition VulkanRenderpass.h:942
Definition VulkanRenderpass.h:453
const FVulkanRenderTargetLayout & GetLayout() const
Definition VulkanRenderpass.h:455
uint32 GetNumUsedClearValues() const
Definition VulkanRenderpass.h:465
VkRenderPass GetHandle() const
Definition VulkanRenderpass.h:460
Definition VulkanRenderTargetLayout.h:8
Definition VulkanRenderpass.h:118
Definition ArrayView.h:139
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT ElementType & Last(SizeType IndexFromTheEnd=0) UE_LIFETIMEBOUND
Definition Array.h:1263
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
Definition UnrealString.h.inl:34
Definition CriticalSection.h:14
Definition VulkanCommandBuffer.h:22
VkImageLayout GetMergedDepthStencilLayout(VkImageLayout DepthLayout, VkImageLayout StencilLayout)
Definition VulkanRHIPrivate.h:510
static UE_FORCEINLINE_HINT void * Memzero(void *Dest, SIZE_T Count)
Definition UnrealMemory.h:131
VkPhysicalDeviceFragmentShadingRateFeaturesKHR FragmentShadingRateFeatures
Definition VulkanDevice.h:167
uint64 HasKHRMultiview
Definition VulkanDevice.h:78
uint64 HasKHRDepthStencilResolve
Definition VulkanDevice.h:95
uint64 HasKHRRenderPass2
Definition VulkanDevice.h:83
uint64 HasKHRFragmentShadingRate
Definition VulkanDevice.h:51
uint64 HasEXTFragmentDensityMap
Definition VulkanDevice.h:49
Definition RHIResources.h:5248
FVulkanAttachmentDescription(const VkAttachmentDescription &InDesc)
Definition VulkanRenderpass.h:311
FVulkanAttachmentDescription(const VkAttachmentDescription &InDesc, const VkAttachmentDescriptionStencilLayout *InStencilDesc, bool bSupportsParallelRendering)
Definition VulkanRenderpass.h:326
FVulkanAttachmentDescription()
Definition VulkanRenderpass.h:306
FVulkanAttachmentDescription(const VkAttachmentDescription &InDesc, const VkAttachmentDescriptionStencilLayout *InStencilDesc, bool bSupportsParallelRendering)
Definition VulkanRenderpass.h:284
FVulkanAttachmentDescription()
Definition VulkanRenderpass.h:266
FVulkanAttachmentDescription(const VkAttachmentDescription &InDesc)
Definition VulkanRenderpass.h:271
Definition VulkanRenderpass.h:259
Definition VulkanRenderpass.h:21
void SetAttachment(const VkAttachmentReference &AttachmentReferenceIn, VkImageAspectFlags AspectMask)
Definition VulkanRenderpass.h:32
void SetDepthStencilAttachment(const VkAttachmentReference &AttachmentReferenceIn, const VkAttachmentReferenceStencilLayout *StencilReference, VkImageAspectFlags AspectMask, bool bSupportsParallelRendering)
Definition VulkanRenderpass.h:34
void SetAttachment(const FVulkanAttachmentReference< TAttachmentReferenceType > &AttachmentReferenceIn, VkImageAspectFlags AspectMask)
Definition VulkanRenderpass.h:33
void SetAspect(uint32 Aspect)
Definition VulkanRenderpass.h:36
void ZeroStruct()
Definition VulkanRenderpass.h:35
FVulkanAttachmentReference()
Definition VulkanRenderpass.h:22
FVulkanAttachmentReference(const VkAttachmentReference &AttachmentReferenceIn, VkImageAspectFlags AspectMask)
Definition VulkanRenderpass.h:27
Definition VulkanRenderpass.h:899
FVulkanRenderPass & RenderPass
Definition VulkanRenderpass.h:900
FVulkanFramebuffer & Framebuffer
Definition VulkanRenderpass.h:901
bool bIsParallelRenderPass
Definition VulkanRenderpass.h:902
Definition VulkanRenderpass.h:434
void SetReference(FVulkanAttachmentReference< VkAttachmentReference2 > *AttachmentReference)
Definition VulkanRenderpass.h:446
void SetResolveModes(VkResolveModeFlagBits DepthMode, VkResolveModeFlagBits StencilMode)
Definition VulkanRenderpass.h:440
FVulkanDepthStencilResolveSubpassDesc()
Definition VulkanRenderpass.h:435
Definition VulkanRenderpass.h:417
FVulkanFragmentShadingRateAttachmentInfo()
Definition VulkanRenderpass.h:418
void SetReference(FVulkanAttachmentReference< VkAttachmentReference2 > *AttachmentReference)
Definition VulkanRenderpass.h:426
FVulkanRenderPassCreateInfo()
Definition VulkanRenderpass.h:396
VkRenderPass Create(FVulkanDevice &Device)
Definition VulkanRenderpass.h:407
void SetCorrelationMask(const uint32_t *MaskPtr)
Definition VulkanRenderpass.h:401
void SetCorrelationMask(const uint32_t *MaskPtr)
Definition VulkanRenderpass.h:361
VkRenderPass Create(FVulkanDevice &Device)
Definition VulkanRenderpass.h:366
FVulkanRenderPassCreateInfo()
Definition VulkanRenderpass.h:356
Definition VulkanRenderpass.h:350
Definition VulkanRenderpass.h:376
FVulkanRenderPassFragmentDensityMapCreateInfoEXT()
Definition VulkanRenderpass.h:377
Definition VulkanRenderpass.h:385
FVulkanRenderPassMultiviewCreateInfo()
Definition VulkanRenderpass.h:386
FVulkanSubpassDependency()
Definition VulkanRenderpass.h:250
FVulkanSubpassDependency()
Definition VulkanRenderpass.h:240
Definition VulkanRenderpass.h:233
void SetShadingRateAttachment(VkFragmentShadingRateAttachmentInfoKHR *ShadingRateAttachmentInfo)
Definition VulkanRenderpass.h:217
void SetColorAttachments(const TArray< FVulkanAttachmentReference< VkAttachmentReference2 > > &ColorAttachmentReferences, int OverrideCount=-1)
Definition VulkanRenderpass.h:184
void SetInputAttachments(FVulkanAttachmentReference< VkAttachmentReference2 > *InputAttachmentReferences, uint32 NumInputAttachmentReferences)
Definition VulkanRenderpass.h:204
void SetDepthStencilResolveAttachment(VkSubpassDescriptionDepthStencilResolveKHR *DepthStencilResolveAttachmentDesc)
Definition VulkanRenderpass.h:210
void SetResolveAttachments(const TArrayView< FVulkanAttachmentReference< VkAttachmentReference2 > > &ResolveAttachmentReferences)
Definition VulkanRenderpass.h:190
void SetDepthStencilAttachment(FVulkanAttachmentReference< VkAttachmentReference2 > *DepthStencilAttachmentReference)
Definition VulkanRenderpass.h:199
FVulkanSubpassDescription()
Definition VulkanRenderpass.h:177
void SetMultiViewMask(uint32_t Mask)
Definition VulkanRenderpass.h:224
FVulkanSubpassDescription()
Definition VulkanRenderpass.h:125
void SetColorAttachments(const TArray< FVulkanAttachmentReference< VkAttachmentReference > > &ColorAttachmentReferences, int OverrideCount=-1)
Definition VulkanRenderpass.h:131
void SetDepthStencilAttachment(FVulkanAttachmentReference< VkAttachmentReference > *DepthStencilAttachmentReference)
Definition VulkanRenderpass.h:146
void SetInputAttachments(FVulkanAttachmentReference< VkAttachmentReference > *InputAttachmentReferences, uint32 NumInputAttachmentReferences)
Definition VulkanRenderpass.h:151
void SetMultiViewMask(uint32_t Mask)
Definition VulkanRenderpass.h:167
void SetResolveAttachments(const TArrayView< FVulkanAttachmentReference< VkAttachmentReference > > &ResolveAttachmentReferences)
Definition VulkanRenderpass.h:137
void SetShadingRateAttachment(VkFragmentShadingRateAttachmentInfoKHR *)
Definition VulkanRenderpass.h:162
void SetDepthStencilResolveAttachment(VkSubpassDescriptionDepthStencilResolveKHR *DepthStencilResolveAttachmentDesc)
Definition VulkanRenderpass.h:157