r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame
r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame
#Overview
name: r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
The maximum number of transient rendering read buffer bytes to allocate before we start panic logging who is doing the allocations
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame is to control the maximum number of transient rendering read buffer bytes that can be allocated before the engine starts panic logging about the allocations. This setting is part of the rendering system’s memory management.
This setting variable is primarily used in the RenderCore module of Unreal Engine 5, specifically within the dynamic buffer allocation system. It’s utilized by the FGlobalDynamicReadBuffer class to manage memory allocation for rendering read buffers.
The value of this variable is set through the console variable system. It’s initialized with a default value of 32 MB (32 * 1024 * 1024 bytes) and can be modified at runtime using the console command system.
The associated variable GMaxReadBufferRenderingBytesAllocatedPerFrame directly interacts with r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame. They share the same value, with GMaxReadBufferRenderingBytesAllocatedPerFrame being the actual integer variable used in the C++ code.
Developers must be aware that this variable acts as a threshold for logging. When the total allocated memory for rendering read buffers exceeds this value, the engine will start logging detailed information about the allocations. This can be useful for debugging memory issues but may impact performance if set too low.
Best practices when using this variable include:
- Setting it high enough to avoid unnecessary logging during normal operation.
- Temporarily lowering it when debugging memory allocation issues in the rendering system.
- Monitoring its value in relation to the actual memory usage of your game to ensure it’s set appropriately for your project’s needs.
Regarding the associated variable GMaxReadBufferRenderingBytesAllocatedPerFrame:
The purpose of GMaxReadBufferRenderingBytesAllocatedPerFrame is to store the actual integer value used by the engine to determine when to start panic logging about read buffer allocations.
This variable is used directly in the RenderCore module, specifically in the FGlobalDynamicReadBuffer class to check if render alarm logging should be enabled.
The value of this variable is set through the console variable system, initialized with the same default value as r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame (32 MB).
It interacts directly with r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame, serving as the C++ representation of that console variable.
Developers should be aware that modifying GMaxReadBufferRenderingBytesAllocatedPerFrame directly in code is not recommended. Instead, they should use the console variable system to modify r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame, which will automatically update GMaxReadBufferRenderingBytesAllocatedPerFrame.
Best practices include using this variable for read-only purposes in C++ code and relying on the console variable system for modifications to ensure consistency between r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame and GMaxReadBufferRenderingBytesAllocatedPerFrame.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/DynamicBufferAllocator.cpp:13
Scope: file
Source code excerpt:
FAutoConsoleVariableRef CVarMaxReadBufferRenderingBytesAllocatedPerFrame(
TEXT("r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame"),
GMaxReadBufferRenderingBytesAllocatedPerFrame,
TEXT("The maximum number of transient rendering read buffer bytes to allocate before we start panic logging who is doing the allocations"));
// The allocator works by looking for the first free buffer that contains the required number of elements. There is currently no trim so buffers stay in memory.
// To avoid increasing allocation sizes over multiple frames causing severe memory bloat (i.e. 100 elements, 1001 elements) we first align the required
// number of elements to GMinReadBufferRenderingBufferSize, we then take the max(aligned num, GMinReadBufferRenderingBufferSize)
#Associated Variable and Callsites
This variable is associated with another variable named GMaxReadBufferRenderingBytesAllocatedPerFrame
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/DynamicBufferAllocator.cpp:10
Scope: file
Source code excerpt:
#include "RenderCore.h"
int32 GMaxReadBufferRenderingBytesAllocatedPerFrame = 32 * 1024 * 1024;
FAutoConsoleVariableRef CVarMaxReadBufferRenderingBytesAllocatedPerFrame(
TEXT("r.ReadBuffer.MaxRenderingBytesAllocatedPerFrame"),
GMaxReadBufferRenderingBytesAllocatedPerFrame,
TEXT("The maximum number of transient rendering read buffer bytes to allocate before we start panic logging who is doing the allocations"));
// The allocator works by looking for the first free buffer that contains the required number of elements. There is currently no trim so buffers stay in memory.
// To avoid increasing allocation sizes over multiple frames causing severe memory bloat (i.e. 100 elements, 1001 elements) we first align the required
// number of elements to GMinReadBufferRenderingBufferSize, we then take the max(aligned num, GMinReadBufferRenderingBufferSize)
int32 GMinReadBufferRenderingBufferSize = 256 * 1024;
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/DynamicBufferAllocator.cpp:207
Scope (from outer to inner):
file
function bool FGlobalDynamicReadBuffer::IsRenderAlarmLoggingEnabled
Source code excerpt:
bool FGlobalDynamicReadBuffer::IsRenderAlarmLoggingEnabled() const
{
return GMaxReadBufferRenderingBytesAllocatedPerFrame > 0 && TotalAllocatedSinceLastCommit >= (size_t)GMaxReadBufferRenderingBytesAllocatedPerFrame;
}
static void RemoveUnusedBuffers(FRHICommandListBase* RHICmdList, FDynamicReadBufferPool* BufferPool)
{
extern int32 GGlobalBufferNumFramesUnusedThreshold;