2019-12-26 14:45:42 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2019-06-11 18:27:07 -04:00
# pragma once
2020-11-18 18:25:03 -04:00
# include "RenderGraphAllocator.h"
2020-07-06 18:58:26 -04:00
# include "ProfilingDebugging/RealtimeGPUProfiler.h"
2019-06-11 18:27:07 -04:00
2020-09-24 00:43:27 -04:00
/** DEFINES */
2019-06-11 18:27:07 -04:00
/** Whether render graph debugging is enabled. */
2021-12-13 18:49:21 -05:00
# define RDG_ENABLE_DEBUG (!UE_BUILD_SHIPPING && !UE_BUILD_TEST)
2019-06-11 18:27:07 -04:00
2019-07-16 13:08:56 -04:00
/** Performs the operation if RDG_ENABLE_DEBUG is enabled. Useful for one-line checks without explicitly wrapping in #if. */
# if RDG_ENABLE_DEBUG
2020-09-24 00:43:27 -04:00
# define IF_RDG_ENABLE_DEBUG(Op) Op
2019-07-16 13:08:56 -04:00
# else
2020-09-24 00:43:27 -04:00
# define IF_RDG_ENABLE_DEBUG(Op)
2019-07-16 13:08:56 -04:00
# endif
2019-06-11 18:27:07 -04:00
/** Whether render graph debugging is enabled and we are compiling with the engine. */
# define RDG_ENABLE_DEBUG_WITH_ENGINE (RDG_ENABLE_DEBUG && WITH_ENGINE)
2021-02-03 13:17:04 -04:00
/** Whether render graph insight tracing is enabled. */
# define RDG_ENABLE_TRACE UE_TRACE_ENABLED && !IS_PROGRAM && !UE_BUILD_SHIPPING
# if RDG_ENABLE_TRACE
# define IF_RDG_ENABLE_TRACE(Op) Op
# else
# define IF_RDG_ENABLE_TRACE(Op)
# endif
2021-12-03 16:04:00 -05:00
/** Allows to dump all RDG resources of a frame. */
# define RDG_DUMP_RESOURCES (WITH_DUMPGPU)
/** Allows to dump RDG resource after each draw call. */
# define RDG_DUMP_RESOURCES_AT_EACH_DRAW (RDG_DUMP_RESOURCES)
2019-06-11 18:27:07 -04:00
/** The type of GPU events the render graph system supports.
* RDG_EVENTS = = 0 means there is no string processing at all .
* RDG_EVENTS = = 1 means the format component of the event name is stored as a const TCHAR * .
* RDG_EVENTS = = 2 means string formatting is evaluated and stored in an FString .
*/
# define RDG_EVENTS_NONE 0
# define RDG_EVENTS_STRING_REF 1
# define RDG_EVENTS_STRING_COPY 2
/** Whether render graph GPU events are enabled. */
2021-12-13 18:49:21 -05:00
# if WITH_PROFILEGPU
2019-06-11 18:27:07 -04:00
# define RDG_EVENTS RDG_EVENTS_STRING_COPY
2021-04-29 19:32:06 -04:00
# elif RHI_WANT_BREADCRUMB_EVENTS
# define RDG_EVENTS RDG_EVENTS_STRING_REF
2019-06-11 18:27:07 -04:00
# else
2021-01-21 16:22:06 -04:00
# define RDG_EVENTS RDG_EVENTS_NONE
2020-07-06 18:58:26 -04:00
# endif
2020-09-24 00:43:27 -04:00
# define RDG_GPU_SCOPES (RDG_EVENTS || HAS_GPU_STATS)
# if RDG_GPU_SCOPES
# define IF_RDG_GPU_SCOPES(Op) Op
2020-07-06 18:58:26 -04:00
# else
2020-09-24 00:43:27 -04:00
# define IF_RDG_GPU_SCOPES(Op)
2020-07-06 18:58:26 -04:00
# endif
2020-09-24 00:43:27 -04:00
# define RDG_CPU_SCOPES (CSV_PROFILER)
# if RDG_CPU_SCOPES
# define IF_RDG_CPU_SCOPES(Op) Op
# else
# define IF_RDG_CPU_SCOPES(Op)
# endif
2020-11-30 13:27:08 -04:00
# define RDG_CMDLIST_STATS (STATS || ENABLE_STATNAMEDEVENTS)
# if RDG_CMDLIST_STATS
# define IF_RDG_CMDLIST_STATS(Op) Op
# else
# define IF_RDG_CMDLIST_STATS(Op)
# endif
2020-09-24 00:43:27 -04:00
/** ENUMS */
2021-07-22 12:43:00 -04:00
enum class ERDGBuilderFlags
{
None = 0 ,
/** Allows the builder to parallelize execution of passes. Without this flag, all passes execute on the render thread. */
AllowParallelExecute = 1 < < 0
} ;
ENUM_CLASS_FLAGS ( ERDGBuilderFlags ) ;
2020-09-24 00:43:27 -04:00
/** Flags to annotate a pass with when calling AddPass. */
2020-07-06 18:58:26 -04:00
enum class ERDGPassFlags : uint8
{
2020-09-24 00:43:27 -04:00
/** Pass doesn't have any inputs or outputs tracked by the graph. This may only be used by the parameterless AddPass function. */
None = 0 ,
2020-07-06 18:58:26 -04:00
/** Pass uses rasterization on the graphics pipe. */
Raster = 1 < < 0 ,
/** Pass uses compute on the graphics pipe. */
Compute = 1 < < 1 ,
/** Pass uses compute on the async compute pipe. */
AsyncCompute = 1 < < 2 ,
/** Pass uses copy commands on the graphics pipe. */
Copy = 1 < < 3 ,
/** Pass (and its producers) will never be culled. Necessary if outputs cannot be tracked by the graph. */
NeverCull = 1 < < 4 ,
2020-09-24 00:43:27 -04:00
/** Render pass begin / end is skipped and left to the user. Only valid when combined with 'Raster'. Disables render pass merging for the pass. */
SkipRenderPass = 1 < < 5 ,
2021-04-12 15:36:14 -04:00
/** Pass will never have its render pass merged with other passes. */
NeverMerge = 1 < < 6 ,
2022-02-03 09:15:49 -05:00
/** Pass will never run off the render thread. */
NeverParallel = 1 < < 7 ,
2020-09-24 00:43:27 -04:00
/** Pass uses copy commands but writes to a staging resource. */
2021-02-18 19:54:54 -04:00
Readback = Copy | NeverCull
2020-07-06 18:58:26 -04:00
} ;
ENUM_CLASS_FLAGS ( ERDGPassFlags ) ;
2020-09-24 00:43:27 -04:00
/** Flags to annotate a render graph buffer. */
enum class ERDGBufferFlags : uint8
2020-07-06 18:58:26 -04:00
{
None = 0 ,
2020-09-24 00:43:27 -04:00
/** Tag the buffer to survive through frame, that is important for multi GPU alternate frame rendering. */
2020-11-17 18:21:53 -04:00
MultiFrame = 1 < < 0 ,
/** The buffer may only be used for read-only access within the graph. This flag is only allowed for registered buffers. */
Misc render-related changes:
* Added single-callback version of CreateStructuredBuffer to automatically infer element size, total size, element count and data pointer (e.g. CreateStructuredBuffer(GraphBuilder, TEXT("MyBuffer"), [&]() -> auto& { return BufferSource; });, where BufferSource is a TArray)
* Added support for uint2 shader parameters
* Added ForceTracking flag to ERDGBufferFlags/ERDGTextureFlags : force the RDG to track a resource even if it can be considered as readonly (no UAV, no RTV, etc.) This allows the graph to copy from and to external textures, and handling the corresponding transitions, for example.
#rb zach.bethel, sebastien.lussier
#tests editor
#preflight 61d8bc681f62d3ad4d728095
#ROBOMERGE-OWNER: jonathan.bard
#ROBOMERGE-AUTHOR: jonathan.bard
#ROBOMERGE-SOURCE: CL 18595021 via CL 18595031 via CL 18595035 via CL 18595668 via CL 18595682 via CL 18595700
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Test -> Main) (v899-18417669)
[CL 18596726 by jonathan bard in ue5-main branch]
2022-01-13 10:11:22 -05:00
ReadOnly = 1 < < 1 ,
/** Force the graph to track this resource even if it can be considered as readonly (no UAV, no RTV, etc.) This allows the graph copying from and to textures, and handling the corresponding transitions, for example.
This flag is only allowed for registered buffers . Mutually exclusive with ReadOnly . */
ForceTracking = 1 < < 2 ,
2020-07-06 18:58:26 -04:00
} ;
2020-09-24 00:43:27 -04:00
ENUM_CLASS_FLAGS ( ERDGBufferFlags ) ;
2020-07-06 18:58:26 -04:00
2020-09-24 00:43:27 -04:00
/** Flags to annotate a render graph texture. */
enum class ERDGTextureFlags : uint8
2020-07-06 18:58:26 -04:00
{
None = 0 ,
2020-09-24 00:43:27 -04:00
/** Tag the texture to survive through frame, that is important for multi GPU alternate frame rendering. */
2020-10-09 22:42:26 -04:00
MultiFrame = 1 < < 0 ,
2020-11-17 18:21:53 -04:00
/** The texture may only be used for read-only access within the graph. This flag is only allowed for registered textures. */
ReadOnly = 1 < < 1 ,
2020-10-09 22:42:26 -04:00
/** Prevents metadata decompression on this texture. */
2020-11-17 18:21:53 -04:00
MaintainCompression = 1 < < 2 ,
Misc render-related changes:
* Added single-callback version of CreateStructuredBuffer to automatically infer element size, total size, element count and data pointer (e.g. CreateStructuredBuffer(GraphBuilder, TEXT("MyBuffer"), [&]() -> auto& { return BufferSource; });, where BufferSource is a TArray)
* Added support for uint2 shader parameters
* Added ForceTracking flag to ERDGBufferFlags/ERDGTextureFlags : force the RDG to track a resource even if it can be considered as readonly (no UAV, no RTV, etc.) This allows the graph to copy from and to external textures, and handling the corresponding transitions, for example.
#rb zach.bethel, sebastien.lussier
#tests editor
#preflight 61d8bc681f62d3ad4d728095
#ROBOMERGE-OWNER: jonathan.bard
#ROBOMERGE-AUTHOR: jonathan.bard
#ROBOMERGE-SOURCE: CL 18595021 via CL 18595031 via CL 18595035 via CL 18595668 via CL 18595682 via CL 18595700
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Test -> Main) (v899-18417669)
[CL 18596726 by jonathan bard in ue5-main branch]
2022-01-13 10:11:22 -05:00
/** Force the graph to track this resource even if it can be considered as readonly (no UAV, no RTV, etc.) This allows the graph copying from and to textures, and handling the corresponding transitions, for example.
This flag is only allowed for registered buffers . Mutually exclusive with ReadOnly . */
ForceTracking = 1 < < 3 ,
2020-07-06 18:58:26 -04:00
} ;
2020-09-24 00:43:27 -04:00
ENUM_CLASS_FLAGS ( ERDGTextureFlags ) ;
2020-07-06 18:58:26 -04:00
2020-09-24 00:43:27 -04:00
/** Flags to annotate a view with when calling CreateUAV. */
enum class ERDGUnorderedAccessViewFlags : uint8
2020-07-06 18:58:26 -04:00
{
2020-09-24 00:43:27 -04:00
None = 0 ,
2020-07-06 18:58:26 -04:00
2020-09-24 00:43:27 -04:00
// The view will not perform UAV barriers between consecutive usage.
SkipBarrier = 1 < < 0
2020-07-06 18:58:26 -04:00
} ;
2020-09-24 00:43:27 -04:00
ENUM_CLASS_FLAGS ( ERDGUnorderedAccessViewFlags ) ;
2020-07-06 18:58:26 -04:00
2020-09-24 00:43:27 -04:00
/** The set of concrete parent resource types. */
2022-03-25 11:19:10 -04:00
enum class ERDGViewableResourceType : uint8
2020-07-06 18:58:26 -04:00
{
Texture ,
Buffer ,
MAX
} ;
2022-03-25 11:19:10 -04:00
UE_DEPRECATED ( 5.1 , " ERDGParentResourceType has been renamed to ERDGViewableResourceType. " )
typedef ERDGViewableResourceType ERDGParentResourceType ;
2020-09-24 00:43:27 -04:00
/** The set of concrete view types. */
enum class ERDGViewType : uint8
2020-07-06 18:58:26 -04:00
{
TextureUAV ,
TextureSRV ,
BufferUAV ,
BufferSRV ,
MAX
} ;
2022-01-03 18:28:16 -05:00
enum class ERDGResourceExtractionFlags : uint8
{
None = 0 ,
// Allows the resource to remain transient. Only use this flag if you intend to register the resource back
// into the graph and release the reference. This should not be used if the resource is cached for a long
// period of time.
AllowTransient = 1 ,
} ;
ENUM_CLASS_FLAGS ( ERDGResourceExtractionFlags ) ;
2021-05-25 20:46:17 -04:00
enum class ERDGInitialDataFlags : uint8
{
/** Specifies the default behavior, which is to make a copy of the initial data for replay when
* the graph is executed . The user does not need to preserve lifetime of the data pointer .
*/
None = 0 ,
/** Specifies that the user will maintain ownership of the data until the graph is executed. The
* upload pass will only use a reference to store the data . Use caution with this flag since graph
* execution is deferred ! Useful to avoid the copy if the initial data lifetime is guaranteed to
* outlive the graph .
*/
NoCopy = 1 < < 0
} ;
ENUM_CLASS_FLAGS ( ERDGInitialDataFlags )
2020-09-24 00:43:27 -04:00
/** Returns the equivalent parent resource type for a view type. */
2022-03-25 11:19:10 -04:00
inline ERDGViewableResourceType GetViewableResourceType ( ERDGViewType ViewType )
2020-09-24 00:43:27 -04:00
{
switch ( ViewType )
{
case ERDGViewType : : TextureUAV :
case ERDGViewType : : TextureSRV :
2022-03-25 11:19:10 -04:00
return ERDGViewableResourceType : : Texture ;
2020-09-24 00:43:27 -04:00
case ERDGViewType : : BufferUAV :
case ERDGViewType : : BufferSRV :
2022-03-25 11:19:10 -04:00
return ERDGViewableResourceType : : Buffer ;
2020-09-24 00:43:27 -04:00
default :
checkNoEntry ( ) ;
2022-03-25 11:19:10 -04:00
return ERDGViewableResourceType : : MAX ;
2020-09-24 00:43:27 -04:00
}
}
2022-03-25 11:19:10 -04:00
UE_DEPRECATED ( 5.1 , " GetParentResourceType has been renamed to GetViewableResourceType. " )
inline ERDGViewableResourceType GetParentResourceType ( ERDGViewType ViewType )
{
return GetViewableResourceType ( ViewType ) ;
}
2021-04-21 13:03:28 -04:00
using ERDGTextureMetaDataAccess = ERHITextureMetaDataAccess ;
2020-07-06 18:58:26 -04:00
2020-09-24 00:43:27 -04:00
/** Returns the associated FRHITransitionInfo plane index. */
2020-07-06 18:58:26 -04:00
inline int32 GetResourceTransitionPlaneForMetadataAccess ( ERDGTextureMetaDataAccess Metadata )
{
switch ( Metadata )
{
case ERDGTextureMetaDataAccess : : CompressedSurface :
case ERDGTextureMetaDataAccess : : HTile :
2020-09-24 00:43:27 -04:00
case ERDGTextureMetaDataAccess : : Depth :
2020-07-06 18:58:26 -04:00
return FRHITransitionInfo : : kDepthPlaneSlice ;
case ERDGTextureMetaDataAccess : : Stencil :
return FRHITransitionInfo : : kStencilPlaneSlice ;
default :
return 0 ;
}
}
2020-09-24 00:43:27 -04:00
/** HANDLE UTILITIES */
2020-07-06 18:58:26 -04:00
2020-09-24 00:43:27 -04:00
/** Handle helper class for internal tracking of RDG types. */
template < typename LocalObjectType , typename LocalIndexType >
2020-07-06 18:58:26 -04:00
class TRDGHandle
{
public :
2020-09-24 00:43:27 -04:00
using ObjectType = LocalObjectType ;
2020-07-06 18:58:26 -04:00
using IndexType = LocalIndexType ;
static const TRDGHandle Null ;
TRDGHandle ( ) = default ;
explicit inline TRDGHandle ( int32 InIndex )
{
2021-02-03 13:17:04 -04:00
check ( InIndex > = 0 & & InIndex < = kNullIndex ) ;
2021-09-20 22:59:26 -04:00
Index = ( IndexType ) InIndex ;
2020-07-06 18:58:26 -04:00
}
2020-09-24 00:43:27 -04:00
FORCEINLINE IndexType GetIndex ( ) const { check ( IsValid ( ) ) ; return Index ; }
2021-02-03 13:17:04 -04:00
FORCEINLINE IndexType GetIndexUnchecked ( ) const { return Index ; }
2020-09-24 00:43:27 -04:00
FORCEINLINE bool IsNull ( ) const { return Index = = kNullIndex ; }
FORCEINLINE bool IsValid ( ) const { return Index ! = kNullIndex ; }
2021-05-19 17:54:58 -04:00
FORCEINLINE operator bool ( ) const { return IsValid ( ) ; }
2020-09-24 00:43:27 -04:00
FORCEINLINE bool operator = = ( TRDGHandle Other ) const { return Index = = Other . Index ; }
FORCEINLINE bool operator ! = ( TRDGHandle Other ) const { return Index ! = Other . Index ; }
FORCEINLINE bool operator < = ( TRDGHandle Other ) const { check ( IsValid ( ) & & Other . IsValid ( ) ) ; return Index < = Other . Index ; }
FORCEINLINE bool operator > = ( TRDGHandle Other ) const { check ( IsValid ( ) & & Other . IsValid ( ) ) ; return Index > = Other . Index ; }
FORCEINLINE bool operator < ( TRDGHandle Other ) const { check ( IsValid ( ) & & Other . IsValid ( ) ) ; return Index < Other . Index ; }
FORCEINLINE bool operator > ( TRDGHandle Other ) const { check ( IsValid ( ) & & Other . IsValid ( ) ) ; return Index > Other . Index ; }
2020-07-06 18:58:26 -04:00
2021-05-19 17:54:58 -04:00
FORCEINLINE TRDGHandle & operator + = ( int32 Increment )
{
check ( int64 ( Index + Increment ) < = int64 ( kNullIndex ) ) ;
2022-01-07 10:39:08 -05:00
Index + = ( IndexType ) Increment ;
2021-05-19 17:54:58 -04:00
return * this ;
}
FORCEINLINE TRDGHandle & operator - = ( int32 Decrement )
{
check ( int64 ( Index - Decrement ) > 0 ) ;
2022-01-07 10:39:08 -05:00
Index - = ( IndexType ) Decrement ;
2021-05-19 17:54:58 -04:00
return * this ;
}
FORCEINLINE TRDGHandle operator - ( int32 Subtract ) const
{
TRDGHandle Handle = * this ;
Handle - = Subtract ;
return Handle ;
}
FORCEINLINE TRDGHandle operator + ( int32 Add ) const
{
TRDGHandle Handle = * this ;
Handle + = Add ;
return Handle ;
}
2020-07-06 18:58:26 -04:00
FORCEINLINE TRDGHandle & operator + + ( )
{
check ( IsValid ( ) ) ;
+ + Index ;
return * this ;
}
FORCEINLINE TRDGHandle & operator - - ( )
{
check ( IsValid ( ) ) ;
- - Index ;
return * this ;
}
2021-05-19 17:54:58 -04:00
// Returns the min of two pass handles. Returns null if both are null; returns the valid handle if one is null.
FORCEINLINE static TRDGHandle Min ( TRDGHandle A , TRDGHandle B )
{
// If either index is null is will fail the comparison.
return A . Index < B . Index ? A : B ;
}
// Returns the max of two pass handles. Returns null if both are null; returns the valid handle if one is null.
FORCEINLINE static TRDGHandle Max ( TRDGHandle A , TRDGHandle B )
{
// If either index is null, it will wrap around to 0 and fail the comparison.
return ( IndexType ) ( A . Index + 1 ) > ( IndexType ) ( B . Index + 1 ) ? A : B ;
}
2020-07-06 18:58:26 -04:00
private :
static const IndexType kNullIndex = TNumericLimits < IndexType > : : Max ( ) ;
IndexType Index = kNullIndex ;
} ;
2020-09-24 00:43:27 -04:00
template < typename ObjectType , typename IndexType >
FORCEINLINE uint32 GetTypeHash ( TRDGHandle < ObjectType , IndexType > Handle )
2020-07-06 18:58:26 -04:00
{
return Handle . GetIndex ( ) ;
}
2021-05-19 17:54:58 -04:00
enum class ERDGHandleRegistryDestructPolicy
{
Registry ,
Allocator ,
Never
} ;
2020-09-24 00:43:27 -04:00
/** Helper handle registry class for internal tracking of RDG types. */
2021-05-19 17:54:58 -04:00
template < typename LocalHandleType , ERDGHandleRegistryDestructPolicy DestructPolicy = ERDGHandleRegistryDestructPolicy : : Registry >
2020-09-24 00:43:27 -04:00
class TRDGHandleRegistry
2020-07-06 18:58:26 -04:00
{
public :
using HandleType = LocalHandleType ;
2020-09-24 00:43:27 -04:00
using ObjectType = typename HandleType : : ObjectType ;
2020-07-06 18:58:26 -04:00
using IndexType = typename HandleType : : IndexType ;
2020-09-24 00:43:27 -04:00
void Insert ( ObjectType * Object )
{
Array . Emplace ( Object ) ;
Object - > Handle = Last ( ) ;
}
template < typename DerivedType = ObjectType , class . . . TArgs >
DerivedType * Allocate ( FRDGAllocator & Allocator , TArgs & & . . . Args )
{
static_assert ( TIsDerivedFrom < DerivedType , ObjectType > : : Value , " You must specify a type that derives from ObjectType " ) ;
2021-05-19 17:54:58 -04:00
DerivedType * Object ;
if ( DestructPolicy = = ERDGHandleRegistryDestructPolicy : : Allocator )
{
Object = Allocator . Alloc < DerivedType > ( Forward < TArgs > ( Args ) . . . ) ;
}
else
{
Object = Allocator . AllocNoDestruct < DerivedType > ( Forward < TArgs > ( Args ) . . . ) ;
}
2020-09-24 00:43:27 -04:00
Insert ( Object ) ;
return Object ;
}
void Clear ( )
2020-07-06 18:58:26 -04:00
{
2021-05-19 17:54:58 -04:00
if ( DestructPolicy = = ERDGHandleRegistryDestructPolicy : : Registry )
2021-03-17 12:44:59 -04:00
{
2021-05-19 17:54:58 -04:00
for ( int32 Index = Array . Num ( ) - 1 ; Index > = 0 ; - - Index )
{
Array [ Index ] - > ~ ObjectType ( ) ;
}
2021-03-17 12:44:59 -04:00
}
2020-07-06 18:58:26 -04:00
Array . Empty ( ) ;
}
2021-05-19 17:54:58 -04:00
template < typename FunctionType >
void Enumerate ( FunctionType Function )
{
for ( ObjectType * Object : Array )
{
Function ( Object ) ;
}
}
template < typename FunctionType >
void Enumerate ( FunctionType Function ) const
{
for ( const ObjectType * Object : Array )
{
Function ( Object ) ;
}
}
2020-09-24 00:43:27 -04:00
FORCEINLINE const ObjectType * Get ( HandleType Handle ) const
2020-07-06 18:58:26 -04:00
{
return Array [ Handle . GetIndex ( ) ] ;
}
2020-09-24 00:43:27 -04:00
FORCEINLINE ObjectType * Get ( HandleType Handle )
2020-07-06 18:58:26 -04:00
{
return Array [ Handle . GetIndex ( ) ] ;
}
2020-09-24 00:43:27 -04:00
FORCEINLINE const ObjectType * operator [ ] ( HandleType Handle ) const
2020-07-06 18:58:26 -04:00
{
return Get ( Handle ) ;
}
2020-09-24 00:43:27 -04:00
FORCEINLINE ObjectType * operator [ ] ( HandleType Handle )
2020-07-06 18:58:26 -04:00
{
return Get ( Handle ) ;
}
FORCEINLINE HandleType Begin ( ) const
{
return HandleType ( 0 ) ;
}
FORCEINLINE HandleType End ( ) const
{
return HandleType ( Array . Num ( ) ) ;
}
FORCEINLINE HandleType Last ( ) const
{
return HandleType ( Array . Num ( ) - 1 ) ;
}
FORCEINLINE int32 Num ( ) const
{
return Array . Num ( ) ;
}
private :
2020-11-18 18:25:03 -04:00
TArray < ObjectType * , FRDGArrayAllocator > Array ;
2020-07-06 18:58:26 -04:00
} ;
2020-09-24 00:43:27 -04:00
/** Specialization of bit array with compile-time type checking for handles and a pre-configured allocator. */
2020-07-06 18:58:26 -04:00
template < typename HandleType >
2020-11-18 18:25:03 -04:00
class TRDGHandleBitArray : public TBitArray < FRDGBitArrayAllocator >
2020-09-24 00:43:27 -04:00
{
2020-11-18 18:25:03 -04:00
using Base = TBitArray < FRDGBitArrayAllocator > ;
2020-09-24 00:43:27 -04:00
public :
2021-04-21 13:03:28 -04:00
using Base : : Base ;
2020-09-24 00:43:27 -04:00
FORCEINLINE FBitReference operator [ ] ( HandleType Handle )
{
return Base : : operator [ ] ( Handle . GetIndex ( ) ) ;
}
FORCEINLINE const FConstBitReference operator [ ] ( HandleType Handle ) const
{
return Base : : operator [ ] ( Handle . GetIndex ( ) ) ;
}
} ;
/** Esoteric helper class which accumulates handles and will return a valid handle only if a single unique
* handle was added . Otherwise , it returns null until reset . This helper is chiefly used to track UAVs
* tagged as ' no UAV barrier ' ; such that a UAV barrier is issued only if a unique no - barrier UAV is used
* on a pass . Intended for internal use only .
*/
template < typename HandleType >
class TRDGHandleUniqueFilter
2020-07-06 18:58:26 -04:00
{
public :
2020-09-24 00:43:27 -04:00
TRDGHandleUniqueFilter ( ) = default ;
2020-07-06 18:58:26 -04:00
2020-09-24 00:43:27 -04:00
TRDGHandleUniqueFilter ( HandleType InHandle )
2020-07-06 18:58:26 -04:00
{
AddHandle ( InHandle ) ;
}
void Reset ( )
{
Handle = HandleType : : Null ;
bUnique = false ;
}
void AddHandle ( HandleType InHandle )
{
if ( Handle ! = InHandle & & InHandle . IsValid ( ) )
{
bUnique = Handle . IsNull ( ) ;
Handle = InHandle ;
}
}
HandleType GetUniqueHandle ( ) const
{
return bUnique ? Handle : HandleType : : Null ;
}
private :
HandleType Handle ;
bool bUnique = false ;
} ;
2020-09-24 00:43:27 -04:00
template < typename ObjectType , typename IndexType >
const TRDGHandle < ObjectType , IndexType > TRDGHandle < ObjectType , IndexType > : : Null ;
2022-03-25 14:18:22 -04:00
struct FRDGTextureDesc : public FRHITextureDesc
{
static FRDGTextureDesc Create2D (
FIntPoint Size
, EPixelFormat Format
, FClearValueBinding ClearValue
, ETextureCreateFlags Flags
, uint8 NumMips = 1
, uint8 NumSamples = 1
, uint32 ExtData = 0
)
{
const uint32 Depth = 1 ;
const uint32 ArraySize = 1 ;
return FRDGTextureDesc ( ETextureDimension : : Texture2D , Flags , Format , ClearValue , { Size . X , Size . Y } , Depth , ArraySize , NumMips , NumSamples , ExtData ) ;
}
2020-09-24 00:43:27 -04:00
2022-03-25 14:18:22 -04:00
static FRDGTextureDesc Create2DArray (
FIntPoint Size
, EPixelFormat Format
, FClearValueBinding ClearValue
, ETextureCreateFlags Flags
, uint16 ArraySize
, uint8 NumMips = 1
, uint8 NumSamples = 1
, uint32 ExtData = 0
)
{
const uint32 Depth = 1 ;
return FRDGTextureDesc ( ETextureDimension : : Texture2DArray , Flags , Format , ClearValue , { Size . X , Size . Y } , Depth , ArraySize , NumMips , NumSamples , ExtData ) ;
}
static FRDGTextureDesc Create3D (
FIntVector Size
, EPixelFormat Format
, FClearValueBinding ClearValue
, ETextureCreateFlags Flags
, uint8 NumMips = 1
, uint32 ExtData = 0
)
{
const uint32 ArraySize = 1 ;
const uint32 LocalNumSamples = 1 ;
checkf ( Size . Z < = TNumericLimits < decltype ( FRDGTextureDesc : : Depth ) > : : Max ( ) , TEXT ( " Depth parameter (Size.Z) exceeds valid range " ) ) ;
return FRDGTextureDesc ( ETextureDimension : : Texture3D , Flags , Format , ClearValue , { Size . X , Size . Y } , Size . Z , ArraySize , NumMips , LocalNumSamples , ExtData ) ;
}
static FRDGTextureDesc CreateCube (
uint32 Size
, EPixelFormat Format
, FClearValueBinding ClearValue
, ETextureCreateFlags Flags
, uint8 NumMips = 1
, uint8 NumSamples = 1
, uint32 ExtData = 0
)
{
checkf ( Size < = ( uint32 ) TNumericLimits < int32 > : : Max ( ) , TEXT ( " Size parameter exceeds valid range " ) ) ;
const uint32 Depth = 1 ;
const uint32 ArraySize = 1 ;
return FRDGTextureDesc ( ETextureDimension : : TextureCube , Flags , Format , ClearValue , { ( int32 ) Size , ( int32 ) Size } , Depth , ArraySize , NumMips , NumSamples , ExtData ) ;
}
static FRDGTextureDesc CreateCubeArray (
uint32 Size
, EPixelFormat Format
, FClearValueBinding ClearValue
, ETextureCreateFlags Flags
, uint16 ArraySize
, uint8 NumMips = 1
, uint8 NumSamples = 1
, uint32 ExtData = 0
)
{
checkf ( Size < = ( uint32 ) TNumericLimits < int32 > : : Max ( ) , TEXT ( " Size parameter exceeds valid range " ) ) ;
const uint32 Depth = 1 ;
return FRDGTextureDesc ( ETextureDimension : : TextureCubeArray , Flags , Format , ClearValue , { ( int32 ) Size , ( int32 ) Size } , Depth , ArraySize , NumMips , NumSamples , ExtData ) ;
}
FRDGTextureDesc ( ) = default ;
FRDGTextureDesc (
ETextureDimension InDimension
, ETextureCreateFlags InFlags
, EPixelFormat InFormat
, FClearValueBinding InClearValue
, FIntPoint InExtent
, uint16 InDepth
, uint16 InArraySize
, uint8 InNumMips
, uint8 InNumSamples
, uint32 InExtData
)
: FRHITextureDesc ( InDimension , InFlags , InFormat , InClearValue , InExtent , InDepth , InArraySize , InNumMips , InNumSamples , InExtData )
{
}
} ;
/** FORWARD DECLARATIONS */
2020-09-24 00:43:27 -04:00
2020-11-17 17:04:48 -04:00
class FRDGBlackboard ;
2020-09-24 00:43:27 -04:00
class FRDGAsyncComputeBudgetScopeGuard ;
class FRDGEventScopeGuard ;
class FRDGGPUStatScopeGuard ;
class FRDGScopedCsvStatExclusive ;
class FRDGScopedCsvStatExclusiveConditional ;
class FRDGBarrierBatch ;
class FRDGBarrierBatchBegin ;
class FRDGBarrierBatchEnd ;
class FRDGBarrierValidation ;
class FRDGBuilder ;
class FRDGEventName ;
class FRDGUserValidation ;
class FRDGResource ;
using FRDGResourceRef = FRDGResource * ;
2022-03-25 11:19:10 -04:00
class FRDGViewableResource ;
UE_DEPRECATED ( 5.1 , " FRDGParentResource has been renamed to FRDGViewableResource. " )
typedef FRDGViewableResource FRDGParentResource ;
UE_DEPRECATED ( 5.1 , " FRDGParentResourceRef has been renamed to FRDGViewableResource*. " )
typedef FRDGViewableResource * FRDGParentResourceRef ;
2020-09-24 00:43:27 -04:00
class FRDGShaderResourceView ;
using FRDGShaderResourceViewRef = FRDGShaderResourceView * ;
class FRDGUnorderedAccessView ;
using FRDGUnorderedAccessViewRef = FRDGUnorderedAccessView * ;
class FRDGTextureSRV ;
using FRDGTextureSRVRef = FRDGTextureSRV * ;
class FRDGTextureUAV ;
using FRDGTextureUAVRef = FRDGTextureUAV * ;
class FRDGBufferSRV ;
using FRDGBufferSRVRef = FRDGBufferSRV * ;
class FRDGBufferUAV ;
using FRDGBufferUAVRef = FRDGBufferUAV * ;
2020-07-06 18:58:26 -04:00
class FRDGPass ;
2021-05-19 17:54:58 -04:00
using FRDGPassRef = FRDGPass * ;
2020-07-06 18:58:26 -04:00
using FRDGPassHandle = TRDGHandle < FRDGPass , uint16 > ;
2020-09-24 00:43:27 -04:00
using FRDGPassRegistry = TRDGHandleRegistry < FRDGPassHandle > ;
2020-11-18 18:25:03 -04:00
using FRDGPassHandleArray = TArray < FRDGPassHandle , TInlineAllocator < 4 , FRDGArrayAllocator > > ;
2020-09-24 00:43:27 -04:00
using FRDGPassBitArray = TRDGHandleBitArray < FRDGPassHandle > ;
2020-07-06 18:58:26 -04:00
2020-09-24 00:43:27 -04:00
class FRDGUniformBuffer ;
using FRDGUniformBufferRef = FRDGUniformBuffer * ;
using FRDGUniformBufferHandle = TRDGHandle < FRDGUniformBuffer , uint16 > ;
using FRDGUniformBufferRegistry = TRDGHandleRegistry < FRDGUniformBufferHandle > ;
using FRDGUniformBufferBitArray = TRDGHandleBitArray < FRDGUniformBufferHandle > ;
class FRDGView ;
using FRDGViewRef = FRDGView * ;
using FRDGViewHandle = TRDGHandle < FRDGView , uint16 > ;
2021-05-19 17:54:58 -04:00
using FRDGViewRegistry = TRDGHandleRegistry < FRDGViewHandle , ERDGHandleRegistryDestructPolicy : : Never > ;
2020-09-24 00:43:27 -04:00
using FRDGViewUniqueFilter = TRDGHandleUniqueFilter < FRDGViewHandle > ;
class FRDGTexture ;
using FRDGTextureRef = FRDGTexture * ;
using FRDGTextureHandle = TRDGHandle < FRDGTexture , uint16 > ;
2021-05-19 17:54:58 -04:00
using FRDGTextureRegistry = TRDGHandleRegistry < FRDGTextureHandle , ERDGHandleRegistryDestructPolicy : : Never > ;
2020-09-24 00:43:27 -04:00
using FRDGTextureBitArray = TRDGHandleBitArray < FRDGTextureHandle > ;
class FRDGBuffer ;
using FRDGBufferRef = FRDGBuffer * ;
using FRDGBufferHandle = TRDGHandle < FRDGBuffer , uint16 > ;
2021-06-25 15:34:35 -04:00
using FRDGBufferRegistry = TRDGHandleRegistry < FRDGBufferHandle , ERDGHandleRegistryDestructPolicy : : Registry > ;
2020-09-24 00:43:27 -04:00
using FRDGBufferBitArray = TRDGHandleBitArray < FRDGBufferHandle > ;
2021-02-05 12:11:16 -04:00
class FRDGPooledTexture ;
class FRDGPooledBuffer ;
2022-01-03 18:28:16 -05:00
class FRDGBufferPool ;
class FRDGTransientRenderTarget ;
2021-02-05 12:11:16 -04:00
2020-09-24 00:43:27 -04:00
template < typename TUniformStruct > class TRDGUniformBuffer ;
template < typename TUniformStruct > using TRDGUniformBufferRef = TRDGUniformBuffer < TUniformStruct > * ;
template < typename InElementType , typename InAllocatorType = FDefaultAllocator >
2020-11-11 19:22:36 -04:00
using TRDGTextureSubresourceArray = TArray < InElementType , TInlineAllocator < 1 , InAllocatorType > > ;
2021-02-03 13:17:04 -04:00
using FRDGPassHandlesByPipeline = TRHIPipelineArray < FRDGPassHandle > ;
2021-05-19 17:54:58 -04:00
using FRDGPassesByPipeline = TRHIPipelineArray < FRDGPass * > ;
2021-02-03 13:17:04 -04:00
2021-06-07 12:19:06 -04:00
class FRDGTrace ;
using FRDGBufferNumElementsCallback = TFunction < uint32 ( ) > ;
using FRDGBufferInitialDataCallback = TFunction < const void * ( ) > ;
using FRDGBufferInitialDataSizeCallback = TFunction < uint64 ( ) > ;
Misc render-related changes:
* Added single-callback version of CreateStructuredBuffer to automatically infer element size, total size, element count and data pointer (e.g. CreateStructuredBuffer(GraphBuilder, TEXT("MyBuffer"), [&]() -> auto& { return BufferSource; });, where BufferSource is a TArray)
* Added support for uint2 shader parameters
* Added ForceTracking flag to ERDGBufferFlags/ERDGTextureFlags : force the RDG to track a resource even if it can be considered as readonly (no UAV, no RTV, etc.) This allows the graph to copy from and to external textures, and handling the corresponding transitions, for example.
#rb zach.bethel, sebastien.lussier
#tests editor
#preflight 61d8bc681f62d3ad4d728095
#ROBOMERGE-OWNER: jonathan.bard
#ROBOMERGE-AUTHOR: jonathan.bard
#ROBOMERGE-SOURCE: CL 18595021 via CL 18595031 via CL 18595035 via CL 18595668 via CL 18595682 via CL 18595700
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Test -> Main) (v899-18417669)
[CL 18596726 by jonathan bard in ue5-main branch]
2022-01-13 10:11:22 -05:00
template < typename ArrayType ,
typename ArrayTypeNoRef = std : : remove_reference_t < ArrayType > ,
typename = typename TEnableIf < TIsTArray < ArrayTypeNoRef > : : Value > : : Type > using TRDGBufferArrayCallback = TFunction < const ArrayType & ( ) > ;
2021-09-01 03:09:25 -04:00
using FRDGBufferInitialDataFreeCallback = TFunction < void ( const void * InData ) > ;
2021-06-07 12:19:06 -04:00
using FRDGDispatchGroupCountCallback = TFunction < FIntVector ( ) > ;