UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VulkanCommandBuffer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved..
2
3/*=============================================================================
4 VulkanCommandBuffer.h: Private Vulkan RHI definitions.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "VulkanConfiguration.h"
11#include "VulkanThirdParty.h"
12
13class FVulkanDevice;
16class FVulkanQueue;
19struct FGfxPipelineDesc;
20
21namespace VulkanRHI
22{
23 class FFence;
24 class FSemaphore;
25}
26
28{
29 Primary,
30
31 // Secondary command buffer with an inherited render pass that will get executed from a primary cmd buffer
32 // Used for parallel contexts without dynamic rendering
34
35 // Primary command buffer that suspend/resume the current renderpass
36 // Used for parallel contexts with dynamic rendering
38
39 Count
40};
41
43{
44protected:
46 friend class FVulkanQueue;
47
50
51public:
52 bool IsInsideRenderPass() const
53 {
55 }
56
58 {
60 }
61
62 bool HasBegun() const
63 {
65 }
66
67 bool HasEnded() const
68 {
69 return State == EState::HasEnded;
70 }
71
72 bool IsSubmitted() const
73 {
74 return State == EState::Submitted;
75 }
76
77 bool IsAllocated() const
78 {
80 }
81
83 {
84 return CommandBufferHandle;
85 }
86
88
89 void SetSubmitted();
90
93
94 enum class EState : uint8
95 {
100 Submitted,
102 NeedReset,
103 };
104
109
111
117
119
120 // Every secondary command buffer executed from this one with tied lifetimes
122
123 // You never want to call Begin/EndRenderPass directly as it will mess up the layout manager.
125 void EndRenderPass();
126
127 // Begin/End calls for when using VK_KHR_dynamic_rendering
128 void BeginDynamicRendering(const VkRenderingInfo& RenderingInfo);
129 void EndDynamicRendering();
130
131 // Flags used with the last dynamic rendering pass
133
134 // Split barriers
137
138#if RHI_NEW_GPU_PROFILER
139 template <typename TEventType, typename... TArgs>
141 {
142 TEventType& Data = EventStream.Emplace<TEventType>(Forward<TArgs>(Args)...);
143
144 if constexpr (std::is_same_v<UE::RHI::GPUProfiler::FEvent::FBeginWork, TEventType>)
145 {
146 // Store BeginEvents in a separate array as the CPUTimestamp field needs updating at submit time.
147 BeginEvents.Add(&Data);
148 }
149
150 return Data;
151 }
152
153 void FlushProfilerEvents(UE::RHI::GPUProfiler::FEventStream& Destination, uint64 CPUTimestamp)
154 {
156 {
157 checkSlow((BeginEvent->CPUTimestamp == 0) && (BeginEvent->GPUTimestampTOP == UINT64_MAX));
158 BeginEvent->CPUTimestamp = CPUTimestamp;
159 }
160 BeginEvents.Reset();
161
162 Destination.Append(MoveTemp(EventStream));
163 }
164#else
166 {
167 if (EndTimestamp > StartTimestamp)
168 {
169 return (EndTimestamp - StartTimestamp);
170 }
171 return 0;
172 }
173#endif
174
175 // Public immutable reference to be accessed directly
177
178private:
179 VkCommandBuffer CommandBufferHandle = VK_NULL_HANDLE;
180 double SubmittedTime = 0.0f;
181
182 void Reset();
183
184 FVulkanCommandBufferPool& CommandBufferPool;
185
186 TArray<VkEvent> EndedBarrierEvents;
187
188 void AllocMemory();
189 void FreeMemory();
190
191#if RHI_NEW_GPU_PROFILER
194#else
195 uint64 StartTimestamp = 0;
196 uint64 EndTimestamp = 0;
197#endif
198
199 friend class FVulkanDynamicRHI;
201};
202
204{
205public:
208
210 {
211 return Handle;
212 }
213
215 {
216 return &CS;
217 }
218
220 {
221 return Queue;
222 }
223
225 {
226 return CommandBufferType;
227 }
228
230
231private:
232 FVulkanDevice& Device;
233 FVulkanQueue& Queue;
234
235 const EVulkanCommandBufferType CommandBufferType;
236
238
240 TArray<FVulkanCommandBuffer*> FreeCmdBuffers;
241
243
244 FVulkanCommandBuffer* Create();
245
247};
248
249
251{
252 return CommandBufferPool.GetCommandBufferType();
253}
#define checkSlow(expr)
Definition AssertionMacros.h:332
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
EVulkanCommandBufferType
Definition VulkanCommandBuffer.h:28
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition PThreadSemaphore.h:15
Definition VulkanCommandBuffer.h:204
FCriticalSection * GetCS()
Definition VulkanCommandBuffer.h:214
EVulkanCommandBufferType GetCommandBufferType() const
Definition VulkanCommandBuffer.h:224
void FreeUnusedCmdBuffers(FVulkanQueue *Queue, bool bTrimMemory)
Definition VulkanCommandBuffer.cpp:326
FVulkanQueue & GetQueue()
Definition VulkanCommandBuffer.h:219
~FVulkanCommandBufferPool()
Definition VulkanCommandBuffer.cpp:308
VkCommandPool GetHandle() const
Definition VulkanCommandBuffer.h:209
Definition VulkanCommandBuffer.h:43
FGfxPipelineDesc * LastDynamicStateUpdate
Definition VulkanCommandBuffer.h:110
TArray< VkViewport, TInlineAllocator< 2 > > CurrentViewports
Definition VulkanCommandBuffer.h:105
bool IsSubmitted() const
Definition VulkanCommandBuffer.h:72
bool HasEnded() const
Definition VulkanCommandBuffer.h:67
VkRenderingFlags LastDynamicRenderingFlags
Definition VulkanCommandBuffer.h:132
uint8 bHasPipeline
Definition VulkanCommandBuffer.h:113
TArray< VkRect2D, TInlineAllocator< 2 > > CurrentScissors
Definition VulkanCommandBuffer.h:106
void EndSplitBarrier(VkEvent BarrierEvent, const VkDependencyInfo &DependencyInfo)
Definition VulkanCommandBuffer.cpp:289
uint8 bHasStencilRef
Definition VulkanCommandBuffer.h:116
uint8 bHasScissor
Definition VulkanCommandBuffer.h:115
bool IsOutsideRenderPass() const
Definition VulkanCommandBuffer.h:57
FVulkanDevice & Device
Definition VulkanCommandBuffer.h:176
void SetSubmitted()
Definition VulkanCommandBuffer.cpp:272
VkCommandBuffer GetHandle() const
Definition VulkanCommandBuffer.h:82
EState State
Definition VulkanCommandBuffer.h:108
void EndDynamicRendering()
Definition VulkanCommandBuffer.cpp:140
uint32 CurrentStencilRef
Definition VulkanCommandBuffer.h:107
uint8 bHasViewport
Definition VulkanCommandBuffer.h:114
void EndRenderPass()
Definition VulkanCommandBuffer.cpp:89
uint8 CurrentMultiViewCount
Definition VulkanCommandBuffer.h:118
void BeginSplitBarrier(VkEvent BarrierEvent, const VkDependencyInfo &DependencyInfo)
Definition VulkanCommandBuffer.cpp:284
EVulkanCommandBufferType GetCommandBufferType() const
Definition VulkanCommandBuffer.h:250
bool IsInsideRenderPass() const
Definition VulkanCommandBuffer.h:52
void BeginDynamicRendering(const VkRenderingInfo &RenderingInfo)
Definition VulkanCommandBuffer.cpp:130
TArray< FVulkanCommandBuffer * > ExecutedSecondaryCommandBuffers
Definition VulkanCommandBuffer.h:121
uint64 GetBusyCycles() const
Definition VulkanCommandBuffer.h:165
EState
Definition VulkanCommandBuffer.h:95
~FVulkanCommandBuffer()
Definition VulkanCommandBuffer.cpp:63
void BeginRenderPass(const FVulkanBeginRenderPassInfo &BeginRenderPassInfo, const VkClearValue *AttachmentClearValues)
Definition VulkanCommandBuffer.cpp:97
uint8 bNeedsFullDynamicStateUpdate
Definition VulkanCommandBuffer.h:112
bool IsAllocated() const
Definition VulkanCommandBuffer.h:77
bool HasBegun() const
Definition VulkanCommandBuffer.h:62
Definition VulkanContext.h:55
Definition VulkanDevice.h:279
Definition VulkanDynamicRHI.h:69
Definition VulkanQuery.h:49
Definition VulkanQueue.h:53
Definition Array.h:670
Definition GPUProfiler.h:310
void Append(FEventStream &&Other)
Definition GPUProfiler.h:447
Definition VulkanCommandBuffer.h:22
Definition VulkanPipeline.h:127
Definition VulkanRenderpass.h:899
Definition GPUProfiler.h:172