r.MaxVertexBytesAllocatedPerFrame
r.MaxVertexBytesAllocatedPerFrame
#Overview
name: r.MaxVertexBytesAllocatedPerFrame
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
The maximum number of transient vertex buffer bytes to allocate before we start panic logging who is doing the allocations
It is referenced in 5
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.MaxVertexBytesAllocatedPerFrame is to set a threshold for the maximum number of transient vertex buffer bytes that can be allocated per frame before triggering panic logging. This setting is primarily used in the rendering system to monitor and control memory usage for vertex buffers.
This setting variable is mainly relied upon by the RenderCore module of Unreal Engine 5. It’s used in the GlobalRenderResources and DynamicBufferAllocator components, which are crucial parts of the engine’s rendering pipeline.
The value of this variable is set through the console variable system in Unreal Engine. It’s initialized with a default value of 32 MB (32 * 1024 * 1024 bytes) in the source code, but can be modified at runtime using console commands.
The associated variable GMaxVertexBytesAllocatedPerFrame interacts directly with r.MaxVertexBytesAllocatedPerFrame. They share the same value, with GMaxVertexBytesAllocatedPerFrame being the actual integer variable used in the C++ code to perform checks and comparisons.
Developers must be aware that this variable acts as a safeguard against excessive memory allocation for vertex buffers. When the allocated memory exceeds this threshold, the engine will start logging detailed information about the allocations, which can help identify potential memory leaks or inefficient resource usage.
Best practices when using this variable include:
- Monitoring the logs for any panic logging triggered by exceeding this threshold.
- Adjusting the value based on the specific needs of your project and target hardware capabilities.
- Using this in conjunction with profiling tools to optimize vertex buffer usage in your game.
Regarding the associated variable GMaxVertexBytesAllocatedPerFrame:
The purpose of GMaxVertexBytesAllocatedPerFrame is to store the actual integer value of the maximum allowed vertex buffer bytes allocation per frame. It’s used directly in the C++ code for comparisons and checks.
This variable is used in the same subsystems as r.MaxVertexBytesAllocatedPerFrame, primarily in the RenderCore module.
The value of GMaxVertexBytesAllocatedPerFrame is set through the console variable system, mirroring the value of r.MaxVertexBytesAllocatedPerFrame.
It interacts directly with the IsRenderAlarmLoggingEnabled() function, which checks if the total allocated memory has exceeded this threshold.
Developers should be aware that modifying r.MaxVertexBytesAllocatedPerFrame will directly affect GMaxVertexBytesAllocatedPerFrame, and vice versa.
Best practices include using this variable for direct comparisons in C++ code when implementing custom rendering features or optimizations that involve vertex buffer allocations.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/GlobalRenderResources.cpp:12
Scope: file
Source code excerpt:
FAutoConsoleVariableRef CVarMaxVertexBytesAllocatedPerFrame(
TEXT("r.MaxVertexBytesAllocatedPerFrame"),
GMaxVertexBytesAllocatedPerFrame,
TEXT("The maximum number of transient vertex buffer bytes to allocate before we start panic logging who is doing the allocations"));
int32 GGlobalBufferNumFramesUnusedThreshold = 30;
FAutoConsoleVariableRef CVarGlobalBufferNumFramesUnusedThreshold(
TEXT("r.NumFramesUnusedBeforeReleasingGlobalResourceBuffers"),
#Associated Variable and Callsites
This variable is associated with another variable named GMaxVertexBytesAllocatedPerFrame
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/GlobalRenderResources.cpp:9
Scope: file
Source code excerpt:
// The maximum number of transient vertex buffer bytes to allocate before we start panic logging who is doing the allocations
int32 GMaxVertexBytesAllocatedPerFrame = 32 * 1024 * 1024;
FAutoConsoleVariableRef CVarMaxVertexBytesAllocatedPerFrame(
TEXT("r.MaxVertexBytesAllocatedPerFrame"),
GMaxVertexBytesAllocatedPerFrame,
TEXT("The maximum number of transient vertex buffer bytes to allocate before we start panic logging who is doing the allocations"));
int32 GGlobalBufferNumFramesUnusedThreshold = 30;
FAutoConsoleVariableRef CVarGlobalBufferNumFramesUnusedThreshold(
TEXT("r.NumFramesUnusedBeforeReleasingGlobalResourceBuffers"),
GGlobalBufferNumFramesUnusedThreshold,
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/GlobalRenderResources.cpp:827
Scope (from outer to inner):
file
function bool IsRenderAlarmLoggingEnabled
Source code excerpt:
bool IsRenderAlarmLoggingEnabled() const
{
return GMaxVertexBytesAllocatedPerFrame > 0 && TotalAllocatedMemory >= (size_t)GMaxVertexBytesAllocatedPerFrame;
}
private:
void ReleaseRHI() override
{
check(LockList.IsEmpty());
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Public/DynamicBufferAllocator.h:99
Scope: file
Source code excerpt:
void Commit() { Commit(FRHICommandListImmediate::Get()); }
/** Returns true if log statements should be made because we exceeded GMaxVertexBytesAllocatedPerFrame */
RENDERCORE_API bool IsRenderAlarmLoggingEnabled() const;
protected:
RENDERCORE_API virtual void InitRHI(FRHICommandListBase& RHICmdList) override;
RENDERCORE_API virtual void ReleaseRHI() override;
RENDERCORE_API void Cleanup();
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Public/GlobalRenderResources.h:222
Scope: file
Source code excerpt:
void GarbageCollect() {}
/** Returns true if log statements should be made because we exceeded GMaxVertexBytesAllocatedPerFrame */
RENDERCORE_API bool IsRenderAlarmLoggingEnabled() const;
private:
FRHICommandListBase* RHICmdList = nullptr;
TArray<FDynamicVertexBuffer*> VertexBuffers;
};