r.DrawRectangleOptimization
r.DrawRectangleOptimization
#Overview
name: r.DrawRectangleOptimization
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Controls an optimization for DrawRectangle(). When enabled a triangle can be used to draw a quad in certain situations (viewport sized quad).\nUsing a triangle allows for slightly faster post processing in lower resolutions but can not always be used.\n 0: Optimization is disabled, DrawDenormalizedQuad always render with quad\n 1: Optimization is enabled, a triangle can be rendered where specified (default)
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.DrawRectangleOptimization is to control an optimization for the DrawRectangle() function in Unreal Engine’s rendering system. This setting variable is primarily used in the post-processing pipeline to potentially improve performance when rendering certain types of quads, particularly viewport-sized quads.
This setting variable is utilized by the Renderer module, specifically within the post-processing subsystem. It’s referenced in the SceneFilterRendering.cpp file, which is part of the core rendering pipeline.
The value of this variable is set through a console variable (CVarDrawRectangleOptimization) with a default value of 1, meaning the optimization is enabled by default. Developers can change this value at runtime using console commands or through project settings.
The associated variable CVarDrawRectangleOptimization directly interacts with r.DrawRectangleOptimization. They share the same value and purpose.
Developers must be aware that this optimization is not always applicable and may only provide benefits in certain situations, particularly for lower resolutions. It’s important to note that enabling this optimization changes the rendering method from using a quad to using a triangle in specific cases.
Best practices when using this variable include:
- Testing performance with and without the optimization enabled, especially for different resolutions.
- Being cautious when modifying this setting in shipping builds, as it’s primarily intended for development and optimization phases.
- Understanding that this optimization might not always be beneficial and its effectiveness can vary based on the specific use case and hardware.
Regarding the associated variable CVarDrawRectangleOptimization:
The purpose of CVarDrawRectangleOptimization is to provide a runtime-configurable way to control the DrawRectangle optimization. It’s implemented as a TAutoConsoleVariable, allowing for easy modification during development and testing.
This variable is used directly in the rendering code to determine whether to apply the triangle optimization when drawing rectangles. It’s checked in the DoDrawRectangleFlagOverride function, which likely controls the actual rendering process.
The value of CVarDrawRectangleOptimization is set when the engine initializes, but can be changed at runtime through console commands.
Developers should be aware that changes to this variable will take effect on the render thread, as indicated by the ECVF_RenderThreadSafe flag.
Best practices for using CVarDrawRectangleOptimization include:
- Using it for performance testing and optimization during development.
- Documenting any custom settings used in production builds.
- Being cautious about changing its value in shipping builds, as it may affect rendering performance and quality.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/SceneFilterRendering.cpp:68
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarDrawRectangleOptimization(
TEXT("r.DrawRectangleOptimization"),
1,
TEXT("Controls an optimization for DrawRectangle(). When enabled a triangle can be used to draw a quad in certain situations (viewport sized quad).\n")
TEXT("Using a triangle allows for slightly faster post processing in lower resolutions but can not always be used.\n")
TEXT(" 0: Optimization is disabled, DrawDenormalizedQuad always render with quad\n")
TEXT(" 1: Optimization is enabled, a triangle can be rendered where specified (default)"),
ECVF_RenderThreadSafe);
#Associated Variable and Callsites
This variable is associated with another variable named CVarDrawRectangleOptimization
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/SceneFilterRendering.cpp:67
Scope: file
Source code excerpt:
IMPLEMENT_GLOBAL_SHADER_PARAMETER_STRUCT(FDrawRectangleParameters, "DrawRectangleParameters");
static TAutoConsoleVariable<int32> CVarDrawRectangleOptimization(
TEXT("r.DrawRectangleOptimization"),
1,
TEXT("Controls an optimization for DrawRectangle(). When enabled a triangle can be used to draw a quad in certain situations (viewport sized quad).\n")
TEXT("Using a triangle allows for slightly faster post processing in lower resolutions but can not always be used.\n")
TEXT(" 0: Optimization is disabled, DrawDenormalizedQuad always render with quad\n")
TEXT(" 1: Optimization is enabled, a triangle can be rendered where specified (default)"),
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/SceneFilterRendering.cpp:80
Scope (from outer to inner):
file
function static void DoDrawRectangleFlagOverride
Source code excerpt:
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
// Determine triangle draw mode
int Value = CVarDrawRectangleOptimization.GetValueOnRenderThread();
if(!Value)
{
// don't use triangle optimization
Flags = EDRF_Default;
}