UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
RHILockTracker.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "RHICommandList.h"
6
8{
10 {
11 FTextureLockParams() = default;
12
20
23 void* Data = nullptr;
24
25 //did we call the normal flushing/updating lock?
26 bool bDirectLock = false;
27 };
28
30
32 {
34#if DO_CHECK
36 {
37 check(Desc != OutstandingLock.Desc || (OutstandingLock.bDirectLock && bInDirectBufferWrite));
38 }
39#endif
41 }
42
44 {
45 for (int32 Index = 0; Index < OutstandingTextureLocks.Num(); Index++)
46 {
48 {
51 return Result;
52 }
53 }
55 return FTextureLockParams();
56 }
57
58
59
60
62 {
63 void* RHIBuffer;
64 void* Buffer;
68 bool bDirectLock; //did we call the normal flushing/updating lock?
69 bool bCreateLock; //did we lock to immediately initialize a newly created buffer?
70
81 };
82
94
97
100
101 inline void Lock(void* RHIBuffer, void* Buffer, uint32 Offset, uint32 SizeRHI, EResourceLockMode LockMode, bool bInDirectBufferWrite = false, bool bInCreateLock = false)
102 {
103#if DO_CHECK
104 for (auto& Parms : OutstandingLocks)
105 {
106 check((Parms.RHIBuffer != RHIBuffer) || (Parms.bDirectLock && bInDirectBufferWrite) || Parms.Offset != Offset);
107 }
108#endif
110 }
111 inline FLockParams Unlock(void* RHIBuffer, uint32 Offset = 0)
112 {
113 for (int32 Index = 0; Index < OutstandingLocks.Num(); Index++)
114 {
115 if (OutstandingLocks[Index].RHIBuffer == RHIBuffer && OutstandingLocks[Index].Offset == Offset)
116 {
119 return Result;
120 }
121 }
123 return FLockParams(nullptr, nullptr, 0, 0, RLM_WriteOnly, false, false);
124 }
125
126 template<class TIndexOrVertexBufferPointer>
128 {
129 if (LockParms.LockMode != RLM_WriteOnly || !(Buffer->GetUsage() & BUF_Volatile))
130 {
131 OutstandingUnlocks.Emplace(Buffer, RHICmdList.RHIThreadFence(true));
132 }
133 }
134
135 inline void WaitForUnlock(void* RHIBuffer)
136 {
137 for (int32 Index = 0; Index < OutstandingUnlocks.Num(); Index++)
138 {
139 if (OutstandingUnlocks[Index].RHIBuffer == RHIBuffer)
140 {
143 return;
144 }
145 }
146 }
147
149 {
151 for (uint32 Index = 0; Index < Count; Index++)
152 {
153 if (OutstandingUnlocks[Index].UnlockEvent->IsComplete())
154 {
155 OutstandingUnlocks.RemoveAt(Index, 1);
156 --Count;
157 --Index;
158 }
159 }
160 }
161
163};
164
#define check(expr)
Definition AssertionMacros.h:314
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
#define BUF_Volatile
Definition RHIDefinitions.h:982
EResourceLockMode
Definition RHIDefinitions.h:785
@ RLM_WriteOnly
Definition RHIDefinitions.h:787
RHI_API FRHILockTracker GRHILockTracker
Definition RHILockTracker.cpp:6
uint32 Offset
Definition VulkanMemory.cpp:4033
uint32_t uint32
Definition binka_ue_file_header.h:6
RHI_API FGraphEventRef RHIThreadFence(bool bSetLockFence=false)
Definition RHICommandList.cpp:1610
static RHI_API void WaitOnRHIThreadFence(FGraphEventRef &Fence)
Definition RHICommandList.cpp:1797
Definition RHICommandList.h:4626
Definition Array.h:670
U16 Index
Definition radfft.cpp:71
Definition DynamicRHI.h:149
Definition RHILockTracker.h:62
EResourceLockMode LockMode
Definition RHILockTracker.h:67
bool bDirectLock
Definition RHILockTracker.h:68
uint32 Offset
Definition RHILockTracker.h:66
void * Buffer
Definition RHILockTracker.h:64
bool bCreateLock
Definition RHILockTracker.h:69
FLockParams(void *InRHIBuffer, void *InBuffer, uint32 InOffset, uint32 InBufferSize, EResourceLockMode InLockMode, bool bInbDirectLock, bool bInCreateLock)
Definition RHILockTracker.h:71
uint32 BufferSize
Definition RHILockTracker.h:65
void * RHIBuffer
Definition RHILockTracker.h:63
Definition RHILockTracker.h:10
void * Data
Definition RHILockTracker.h:23
EResourceLockMode LockMode
Definition RHILockTracker.h:22
FRHILockedTextureDesc Desc
Definition RHILockTracker.h:21
FTextureLockParams(const FRHILockedTextureDesc &InDesc, EResourceLockMode InLockMode, void *InData, bool bInbDirectLock)
Definition RHILockTracker.h:13
bool bDirectLock
Definition RHILockTracker.h:26
Definition RHILockTracker.h:84
FUnlockFenceParams(void *InRHIBuffer, FGraphEventRef InUnlockEvent)
Definition RHILockTracker.h:85
void * RHIBuffer
Definition RHILockTracker.h:91
FGraphEventRef UnlockEvent
Definition RHILockTracker.h:92
Definition RHILockTracker.h:8
void WaitForUnlock(void *RHIBuffer)
Definition RHILockTracker.h:135
void Lock(const FRHILockTextureArgs &InArguments, void *InData, bool bInDirectBufferWrite)
Definition RHILockTracker.h:31
FLockParams Unlock(void *RHIBuffer, uint32 Offset=0)
Definition RHILockTracker.h:111
TArray< FTextureLockParams, TInlineAllocator< 16 > > OutstandingTextureLocks
Definition RHILockTracker.h:29
FRHILockTracker()
Definition RHILockTracker.h:98
void AddUnlockFence(TIndexOrVertexBufferPointer *Buffer, FRHICommandListImmediate &RHICmdList, const FLockParams &LockParms)
Definition RHILockTracker.h:127
TArray< FLockParams, TInlineAllocator< 16 > > OutstandingLocks
Definition RHILockTracker.h:95
void FlushCompleteUnlocks()
Definition RHILockTracker.h:148
TArray< FUnlockFenceParams, TInlineAllocator< 16 > > OutstandingUnlocks
Definition RHILockTracker.h:96
RHI_API void RaiseMismatchError()
Definition RHILockTracker.cpp:8
void Lock(void *RHIBuffer, void *Buffer, uint32 Offset, uint32 SizeRHI, EResourceLockMode LockMode, bool bInDirectBufferWrite=false, bool bInCreateLock=false)
Definition RHILockTracker.h:101
FTextureLockParams Unlock(const FRHILockedTextureDesc &InDesc)
Definition RHILockTracker.h:43
Definition DynamicRHI.h:129