UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VulkanCommon.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 VulkanCommon.h: Common definitions used for both runtime and compiling shaders.
5=============================================================================*/
6
7#pragma once
8
9#include "RHIDefinitions.h"
10#include "Logging/LogMacros.h"
11
12#ifndef VULKAN_SUPPORTS_GEOMETRY_SHADERS
13 #define VULKAN_SUPPORTS_GEOMETRY_SHADERS PLATFORM_SUPPORTS_GEOMETRY_SHADERS
14#endif
15
16// This defines controls shader generation (so will cause a format rebuild)
17// be careful wrt cooker/target platform not matching define-wise!!!
18// ONLY used for debugging binding table/descriptor set bugs/mismatches.
19#define VULKAN_ENABLE_BINDING_DEBUG_NAMES 0
20
21// Bindless uses one descriptor set per resource type plus one for single use UBs, for a total of 9.
22// On platforms that have a maximum below 9, use mutable descriptors to lower total count to 6 by
23// creating a descriptor set per resource type rather than per descriptor type. On most platforms,
24// these descriptors have the same size and should still be packed tightly.
25// NOTE: Should invalidate Vulkan shaders when changing this value (for example, update VulkanCommon GUID).
26#define VULKAN_REDUCE_BINDLESS_DESCRIPTOR_SET_COUNT 0
27
28namespace ShaderStage
29{
30 // There should be one value for each value in EShaderFrequency.
31 // These values are meant to be used as indices in contexts where values for different bind points can overlap (Graphics/Compute/RayTracing)
32 // like shader arrays in pipeline states or UB binding indices for Graphics (Vertex==0, Pixel==1) that can overlap with Compute (Compute==0).
33 // IMPORTANT: Adjusting these requires a full shader rebuild (ie modify the GUID in VulkanCommon.usf)
34 enum EStage
35 {
36 Vertex = 0,
37 Pixel = 1,
39 Mesh = 3,
40 Task = 4,
41
43
44 RayGen = 0,
48
50
52
54
55 MaxNumStages = 6, // work with even count to simplify bindless alignment requirements
56
57 Invalid = -1,
58 };
59
60 static_assert(MaxNumStages >= FMath::Max(NumComputeStages, FMath::Max(NumGraphicsStages, NumRayTracingStages)), "MaxNumStages too small!");
61
63 {
64 switch (Stage)
65 {
66 case SF_Vertex: return Vertex;
67 case SF_Mesh: return Mesh;
68 case SF_Amplification: return Task;
69 case SF_Pixel: return Pixel;
70 case SF_Geometry: return Geometry;
71 case SF_RayGen: return RayGen;
72 case SF_RayMiss: return RayMiss;
73 case SF_RayHitGroup: return RayHitGroup;
74 case SF_RayCallable: return RayCallable;
75 case SF_Compute: return Compute;
76 default:
77 checkf(0, TEXT("Invalid shader Stage %d"), (int32)Stage);
78 break;
79 }
80
81 return Invalid;
82 }
83
85 {
86 switch (Stage)
87 {
88 case EStage::Vertex: return SF_Vertex;
89 case EStage::Pixel: return SF_Pixel;
90 case EStage::Geometry: return SF_Geometry;
91 case EStage::Mesh: return SF_Mesh;
92 case EStage::Task: return SF_Amplification;
93 default:
94 checkf(0, TEXT("Invalid graphic shader stage: %d"), (int32)Stage);
95 break;
96 }
97
98 return SF_NumFrequencies;
99 }
100};
101
103{
104 static constexpr uint32 MaxUniformBuffersPerStage = 16;
105
107 {
109
110#if VULKAN_REDUCE_BINDLESS_DESCRIPTOR_SET_COUNT
113
116
119#else
122
125
128#endif
129
131
132 // Number of sets reserved for samplers/resources
134
135 // Index of the descriptor set used for single use ub (like globals)
137
138 // Total number of descriptor sets used in a bindless pipeline
140 };
141};
142
144
145template< class T >
146static inline void ZeroVulkanStruct(T& Struct, int32 VkStructureType)
147{
148 static_assert(!TIsPointer<T>::Value, "Don't use a pointer!");
149 static_assert(STRUCT_OFFSET(T, sType) == 0, "Assumes sType is the first member in the Vulkan type!");
150 static_assert(sizeof(T::sType) == sizeof(int32), "Assumed sType is compatible with int32!");
151 // Horrible way to coerce the compiler to not have to know what T::sType is so we can have this header not have to include vulkan.h
152 (int32&)Struct.sType = VkStructureType;
153 FMemory::Memzero(((uint8*)&Struct) + sizeof(VkStructureType), sizeof(T) - sizeof(VkStructureType));
154}
#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
DIRECTLINK_API Display
Definition DirectLinkLog.h:8
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
EShaderFrequency
Definition RHIDefinitions.h:202
@ SF_Compute
Definition RHIDefinitions.h:208
@ SF_NumFrequencies
Definition RHIDefinitions.h:216
@ SF_Amplification
Definition RHIDefinitions.h:205
@ SF_Vertex
Definition RHIDefinitions.h:203
@ SF_Mesh
Definition RHIDefinitions.h:204
@ SF_Geometry
Definition RHIDefinitions.h:207
@ SF_RayGen
Definition RHIDefinitions.h:209
@ SF_RayCallable
Definition RHIDefinitions.h:212
@ SF_RayMiss
Definition RHIDefinitions.h:210
@ SF_RayHitGroup
Definition RHIDefinitions.h:211
@ SF_Pixel
Definition RHIDefinitions.h:206
#define STRUCT_OFFSET(struc, member)
Definition UnrealTemplate.h:218
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition VulkanCommon.h:29
EShaderFrequency GetFrequencyForGfxStage(EStage Stage)
Definition VulkanCommon.h:84
EStage
Definition VulkanCommon.h:35
@ Compute
Definition VulkanCommon.h:51
@ Invalid
Definition VulkanCommon.h:57
@ NumRayTracingStages
Definition VulkanCommon.h:49
@ Geometry
Definition VulkanCommon.h:38
@ NumGraphicsStages
Definition VulkanCommon.h:42
@ Mesh
Definition VulkanCommon.h:39
@ RayGen
Definition VulkanCommon.h:44
@ RayHitGroup
Definition VulkanCommon.h:46
@ NumComputeStages
Definition VulkanCommon.h:53
@ RayCallable
Definition VulkanCommon.h:47
@ Pixel
Definition VulkanCommon.h:37
@ RayMiss
Definition VulkanCommon.h:45
@ Vertex
Definition VulkanCommon.h:36
@ MaxNumStages
Definition VulkanCommon.h:55
@ Task
Definition VulkanCommon.h:40
EStage GetStageForFrequency(EShaderFrequency Stage)
Definition VulkanCommon.h:62
Definition VulkanCommon.h:103
EDescriptorSets
Definition VulkanCommon.h:107
@ BindlessSingleUseUniformBufferSet
Definition VulkanCommon.h:136
@ BindlessUniformTexelBufferSet
Definition VulkanCommon.h:127
@ BindlessAccelerationStructureSet
Definition VulkanCommon.h:130
@ NumBindlessSets
Definition VulkanCommon.h:133
@ BindlessUniformBufferSet
Definition VulkanCommon.h:121
@ MaxNumSets
Definition VulkanCommon.h:139
@ BindlessStorageImageSet
Definition VulkanCommon.h:123
@ BindlessSamplerSet
Definition VulkanCommon.h:108
@ BindlessStorageBufferSet
Definition VulkanCommon.h:120
@ BindlessSampledImageSet
Definition VulkanCommon.h:124
@ BindlessStorageTexelBufferSet
Definition VulkanCommon.h:126
static UE_FORCEINLINE_HINT void * Memzero(void *Dest, SIZE_T Count)
Definition UnrealMemory.h:131
Definition IsPointer.h:12