2019-01-03 19:16:26 -05:00
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
/*=============================================================================
ShaderParameterMetadata . cpp : Shader parameter metadata implementations .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
# include "ShaderParameterMetadata.h"
# include "RenderCore.h"
2018-11-21 18:45:02 -05:00
# include "ShaderCore.h"
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
2019-07-24 12:45:25 -04:00
# define VALIDATE_UNIFORM_BUFFER_UNIQUE_NAME (!UE_BUILD_SHIPPING && !UE_BUILD_TEST)
# if VALIDATE_UNIFORM_BUFFER_UNIQUE_NAME
static TMap < FName , FName > GlobalShaderVariableToStructMap ;
# endif
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
static TLinkedList < FShaderParametersMetadata * > * GUniformStructList = nullptr ;
TLinkedList < FShaderParametersMetadata * > * & FShaderParametersMetadata : : GetStructList ( )
{
return GUniformStructList ;
}
TMap < FName , FShaderParametersMetadata * > & FShaderParametersMetadata : : GetNameStructMap ( )
{
static TMap < FName , FShaderParametersMetadata * > GlobalNameStructMap ;
return GlobalNameStructMap ;
}
FShaderParametersMetadata * FindUniformBufferStructByName ( const TCHAR * StructName )
{
FName FindByName ( StructName , FNAME_Find ) ;
FShaderParametersMetadata * FoundStruct = FShaderParametersMetadata : : GetNameStructMap ( ) . FindRef ( FindByName ) ;
return FoundStruct ;
}
FShaderParametersMetadata * FindUniformBufferStructByFName ( FName StructName )
{
return FShaderParametersMetadata : : GetNameStructMap ( ) . FindRef ( StructName ) ;
}
class FUniformBufferMemberAndOffset
{
public :
FUniformBufferMemberAndOffset ( const FShaderParametersMetadata & InContainingStruct , const FShaderParametersMetadata : : FMember & InMember , int32 InStructOffset ) :
ContainingStruct ( InContainingStruct ) ,
Member ( InMember ) ,
StructOffset ( InStructOffset )
{ }
const FShaderParametersMetadata & ContainingStruct ;
const FShaderParametersMetadata : : FMember & Member ;
int32 StructOffset ;
} ;
FShaderParametersMetadata : : FShaderParametersMetadata (
EUseCase InUseCase ,
const FName & InLayoutName ,
const TCHAR * InStructTypeName ,
const TCHAR * InShaderVariableName ,
uint32 InSize ,
const TArray < FMember > & InMembers )
: StructTypeName ( InStructTypeName )
, ShaderVariableName ( InShaderVariableName )
, Size ( InSize )
, UseCase ( InUseCase )
, Layout ( InLayoutName )
, Members ( InMembers )
, GlobalListLink ( this )
, bLayoutInitialized ( false )
{
2018-10-23 19:08:17 -04:00
check ( StructTypeName ) ;
if ( UseCase = = EUseCase : : ShaderParameterStruct )
{
check ( ShaderVariableName = = nullptr ) ;
}
else
{
check ( ShaderVariableName ) ;
}
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
if ( UseCase = = EUseCase : : GlobalShaderParameterStruct )
{
// Register this uniform buffer struct in global list.
GlobalListLink . LinkHead ( GetStructList ( ) ) ;
FName StructTypeFName ( StructTypeName ) ;
// Verify that during FName creation there's no case conversion
checkSlow ( FCString : : Strcmp ( StructTypeName , * StructTypeFName . GetPlainNameString ( ) ) = = 0 ) ;
GetNameStructMap ( ) . Add ( FName ( StructTypeFName ) , this ) ;
2019-07-24 12:45:25 -04:00
# if VALIDATE_UNIFORM_BUFFER_UNIQUE_NAME
FName ShaderVariableFName ( ShaderVariableName ) ;
// Verify that the global variable name is unique so that we can disambiguate when reflecting from shader source.
if ( FName * StructFName = GlobalShaderVariableToStructMap . Find ( ShaderVariableFName ) )
{
checkf (
false ,
TEXT ( " Found duplicate Uniform Buffer shader variable name %s defined by struct %s. Previous definition " )
TEXT ( " found on struct %s. Uniform buffer shader names must be unique to support name-based reflection of " )
TEXT ( " shader source files. " ) ,
ShaderVariableName ,
StructTypeName ,
* StructFName - > GetPlainNameString ( ) ) ;
}
GlobalShaderVariableToStructMap . Add ( ShaderVariableFName , StructTypeFName ) ;
# endif
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
}
else
{
// We cannot initialize the layout during global initialization, since we have to walk nested struct members.
// Structs created during global initialization will have bRegisterForAutoBinding==false, and are initialized during startup.
// Structs created at runtime with bRegisterForAutoBinding==true can be initialized now.
InitializeLayout ( ) ;
}
}
2019-07-24 12:45:25 -04:00
FShaderParametersMetadata : : ~ FShaderParametersMetadata ( )
{
if ( UseCase = = EUseCase : : GlobalShaderParameterStruct )
{
GlobalListLink . Unlink ( ) ;
GetNameStructMap ( ) . Remove ( FName ( StructTypeName , FNAME_Find ) ) ;
# if VALIDATE_UNIFORM_BUFFER_UNIQUE_NAME
GlobalShaderVariableToStructMap . Remove ( FName ( ShaderVariableName , FNAME_Find ) ) ;
# endif
}
}
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
void FShaderParametersMetadata : : InitializeAllGlobalStructs ( )
{
for ( TLinkedList < FShaderParametersMetadata * > : : TIterator StructIt ( FShaderParametersMetadata : : GetStructList ( ) ) ; StructIt ; StructIt . Next ( ) )
{
StructIt - > InitializeLayout ( ) ;
}
}
void FShaderParametersMetadata : : InitializeLayout ( )
{
check ( ! bLayoutInitialized ) ;
Layout . ConstantBufferSize = Size ;
TArray < FUniformBufferMemberAndOffset > MemberStack ;
MemberStack . Reserve ( Members . Num ( ) ) ;
for ( int32 MemberIndex = 0 ; MemberIndex < Members . Num ( ) ; MemberIndex + + )
{
MemberStack . Push ( FUniformBufferMemberAndOffset ( * this , Members [ MemberIndex ] , 0 ) ) ;
}
2018-12-18 21:41:17 -05:00
/** The point of RDG is to track resources that have deferred allocation. Could deffer the creation of uniform buffer,
* but there is a risk where it create more resource dependency than necessary on passes that reference this deferred
* uniform buffers . Therefore only allow graph resources in shader parameter structures .
*/
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
bool bAllowGraphResources = UseCase = = EUseCase : : ShaderParameterStruct ;
2018-12-18 21:41:17 -05:00
/** Uniform buffer references are only allowed in shader parameter structures that may be used as a root shader parameter
* structure .
*/
bool bAllowUniformBufferReferences = UseCase = = EUseCase : : ShaderParameterStruct ;
2019-03-07 11:25:32 -05:00
/** Resource array are currently only supported for shader parameter structures. */
bool bAllowResourceArrays = UseCase = = EUseCase : : ShaderParameterStruct ;
2018-12-18 21:41:17 -05:00
/** White list all use cases that inline a structure within another. Data driven are not known to inline structures. */
bool bAllowStructureInlining = UseCase = = EUseCase : : ShaderParameterStruct | | UseCase = = EUseCase : : GlobalShaderParameterStruct ;
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
for ( int32 i = 0 ; i < MemberStack . Num ( ) ; + + i )
{
const FShaderParametersMetadata & CurrentStruct = MemberStack [ i ] . ContainingStruct ;
const FMember & CurrentMember = MemberStack [ i ] . Member ;
2019-03-07 11:25:32 -05:00
EUniformBufferBaseType BaseType = CurrentMember . GetBaseType ( ) ;
const uint32 ArraySize = CurrentMember . GetNumElements ( ) ;
2019-03-06 23:59:18 -05:00
const FShaderParametersMetadata * ChildStruct = CurrentMember . GetStructMetadata ( ) ;
2019-03-06 23:42:45 -05:00
2019-03-07 11:25:32 -05:00
const bool bIsArray = ArraySize > 0 ;
const bool bIsRHIResource = (
BaseType = = UBMT_TEXTURE | |
BaseType = = UBMT_SRV | |
BaseType = = UBMT_SAMPLER ) ;
const bool bIsRDGResource = IsRDGResourceReferenceShaderParameterType ( BaseType ) ;
const bool bIsVariableNativeType = (
BaseType = = UBMT_INT32 | |
BaseType = = UBMT_UINT32 | |
BaseType = = UBMT_FLOAT32 ) ;
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
if ( DO_CHECK )
{
const FString CppName = FString : : Printf ( TEXT ( " %s::%s " ) , CurrentStruct . GetStructTypeName ( ) , CurrentMember . GetName ( ) ) ;
2019-10-01 13:03:04 -04:00
if ( BaseType = = UBMT_BOOL )
{
UE_LOG ( LogRendererCore , Fatal ,
TEXT ( " Shader parameter %s error: bool are actually illegal in shader parameter structure, " )
TEXT ( " because bool type in HLSL means using scalar register to store binary information. " )
TEXT ( " Boolean information should always be packed explicitly in bitfield to reduce memory footprint, " )
TEXT ( " and use HLSL comparison operators to translate into clean SGPR, to have minimal VGPR footprint. " ) , * CppName ) ;
}
2018-12-18 21:41:17 -05:00
if ( IsRDGResourceReferenceShaderParameterType ( BaseType ) | | BaseType = = UBMT_RENDER_TARGET_BINDING_SLOTS )
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
2018-12-18 21:41:17 -05:00
if ( ! bAllowGraphResources )
{
UE_LOG ( LogRendererCore , Fatal , TEXT ( " Shader parameter %s error: Graph resources are only allowed in shader parameter structs. " ) , * CppName ) ;
}
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
}
2018-12-18 21:41:17 -05:00
else if ( BaseType = = UBMT_REFERENCED_STRUCT )
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
2018-12-18 21:41:17 -05:00
if ( ! bAllowUniformBufferReferences )
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
UE_LOG ( LogRendererCore , Fatal , TEXT ( " Shader parameter %s error: Shader parameter struct reference can only be done in shader parameter structs. " ) , * CppName ) ;
}
}
2018-12-18 21:41:17 -05:00
else if ( BaseType = = UBMT_NESTED_STRUCT | | BaseType = = UBMT_INCLUDED_STRUCT )
2018-10-22 14:48:33 -04:00
{
check ( ChildStruct ) ;
2018-12-18 21:41:17 -05:00
if ( ! bAllowStructureInlining )
{
UE_LOG ( LogRendererCore , Fatal , TEXT ( " Shader parameter %s error: Shader parameter struct is not known inline other structures. " ) , * CppName ) ;
}
else if ( ChildStruct - > GetUseCase ( ) ! = EUseCase : : ShaderParameterStruct & & UseCase = = EUseCase : : ShaderParameterStruct )
{
UE_LOG ( LogRendererCore , Fatal , TEXT ( " Shader parameter %s error: can only nests or include shader parameter struct define with BEGIN_SHADER_PARAMETER_STRUCT(), but %s is not. " ) , * CppName , ChildStruct - > GetStructTypeName ( ) ) ;
}
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
}
2019-03-07 11:25:32 -05:00
2019-06-11 18:27:07 -04:00
const bool bTypeCanBeArray = ( bAllowResourceArrays & & ( bIsRHIResource | | bIsRDGResource ) ) | | bIsVariableNativeType | | BaseType = = UBMT_NESTED_STRUCT ;
2019-03-07 11:25:32 -05:00
if ( bIsArray & & ! bTypeCanBeArray )
{
UE_LOG ( LogRendererCore , Fatal , TEXT ( " Shader parameter %s error: Not allowed to be an array. " ) , * CppName ) ;
}
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
}
2018-12-18 21:41:17 -05:00
if ( IsShaderParameterTypeForUniformBufferLayout ( BaseType ) )
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
2019-03-07 11:25:32 -05:00
for ( uint32 ArrayElementId = 0 ; ArrayElementId < ( bIsArray ? ArraySize : 1u ) ; ArrayElementId + + )
{
const uint32 AbsoluteMemberOffset = CurrentMember . GetOffset ( ) + MemberStack [ i ] . StructOffset + ArrayElementId * SHADER_PARAMETER_POINTER_ALIGNMENT ;
check ( AbsoluteMemberOffset < ( 1u < < ( sizeof ( FRHIUniformBufferLayout : : FResourceParameter : : MemberOffset ) * 8 ) ) ) ;
Layout . Resources . Add ( FRHIUniformBufferLayout : : FResourceParameter { uint16 ( AbsoluteMemberOffset ) , BaseType } ) ;
}
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
}
if ( ChildStruct & & BaseType ! = UBMT_REFERENCED_STRUCT )
{
2019-06-11 18:27:07 -04:00
for ( uint32 ArrayElementId = 0 ; ArrayElementId < ( bIsArray ? ArraySize : 1u ) ; ArrayElementId + + )
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
2019-06-11 18:27:07 -04:00
int32 AbsoluteStructOffset = CurrentMember . GetOffset ( ) + MemberStack [ i ] . StructOffset + ArrayElementId * ChildStruct - > GetSize ( ) ;
for ( int32 StructMemberIndex = 0 ; StructMemberIndex < ChildStruct - > Members . Num ( ) ; StructMemberIndex + + )
{
const FMember & StructMember = ChildStruct - > Members [ StructMemberIndex ] ;
MemberStack . Insert ( FUniformBufferMemberAndOffset ( * ChildStruct , StructMember , AbsoluteStructOffset ) , i + 1 + StructMemberIndex ) ;
}
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
}
}
2019-03-07 11:25:32 -05:00
} // for (int32 i = 0; i < MemberStack.Num(); ++i)
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
2018-12-18 21:41:17 -05:00
Layout . Resources . Sort ( [ ] (
const FRHIUniformBufferLayout : : FResourceParameter & A ,
const FRHIUniformBufferLayout : : FResourceParameter & B )
{
2019-06-11 18:27:07 -04:00
#if 0 // TODO(RDG)
/** Sort the resource on MemberType first to avoid CPU miss predictions when iterating over the resources. Then based on ascending offset
* to still allow O ( N ) complexity on offset cross referencing such as done in ClearUnusedGraphResourcesImpl ( ) .
*/
2018-12-18 21:41:17 -05:00
if ( A . MemberType = = B . MemberType )
{
return A . MemberOffset < B . MemberOffset ;
}
return A . MemberType < B . MemberType ;
2019-06-11 18:27:07 -04:00
# else
// Sorts the resource based on MemberOffset to allow O(N) complexity on offset cross referencing such as done in ClearUnusedGraphResourcesImpl().
return A . MemberOffset < B . MemberOffset ;
2018-12-18 21:41:17 -05:00
# endif
2019-06-11 18:27:07 -04:00
} ) ;
2018-12-18 21:41:17 -05:00
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
Layout . ComputeHash ( ) ;
bLayoutInitialized = true ;
}
void FShaderParametersMetadata : : GetNestedStructs ( TArray < const FShaderParametersMetadata * > & OutNestedStructs ) const
{
for ( int32 i = 0 ; i < Members . Num ( ) ; + + i )
{
const FMember & CurrentMember = Members [ i ] ;
const FShaderParametersMetadata * MemberStruct = CurrentMember . GetStructMetadata ( ) ;
if ( MemberStruct )
{
OutNestedStructs . Add ( MemberStruct ) ;
MemberStruct - > GetNestedStructs ( OutNestedStructs ) ;
}
}
}
void FShaderParametersMetadata : : AddResourceTableEntries ( TMap < FString , FResourceTableEntry > & ResourceTableMap , TMap < FString , uint32 > & ResourceTableLayoutHashes ) const
{
uint16 ResourceIndex = 0 ;
FString Prefix = FString : : Printf ( TEXT ( " %s_ " ) , ShaderVariableName ) ;
AddResourceTableEntriesRecursive ( ShaderVariableName , * Prefix , ResourceIndex , ResourceTableMap ) ;
ResourceTableLayoutHashes . Add ( ShaderVariableName , GetLayout ( ) . GetHash ( ) ) ;
}
void FShaderParametersMetadata : : AddResourceTableEntriesRecursive ( const TCHAR * UniformBufferName , const TCHAR * Prefix , uint16 & ResourceIndex , TMap < FString , FResourceTableEntry > & ResourceTableMap ) const
{
for ( int32 MemberIndex = 0 ; MemberIndex < Members . Num ( ) ; + + MemberIndex )
{
const FMember & Member = Members [ MemberIndex ] ;
2019-06-11 18:27:07 -04:00
uint32 NumElements = Member . GetNumElements ( ) ;
2018-12-18 21:41:17 -05:00
if ( IsShaderParameterTypeForUniformBufferLayout ( Member . GetBaseType ( ) ) )
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
FResourceTableEntry & Entry = ResourceTableMap . FindOrAdd ( FString : : Printf ( TEXT ( " %s%s " ) , Prefix , Member . GetName ( ) ) ) ;
if ( Entry . UniformBufferName . IsEmpty ( ) )
{
Entry . UniformBufferName = UniformBufferName ;
Entry . Type = Member . GetBaseType ( ) ;
Entry . ResourceIndex = ResourceIndex + + ;
}
}
2019-06-11 18:27:07 -04:00
else if ( Member . GetBaseType ( ) = = UBMT_NESTED_STRUCT & & NumElements = = 0 )
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
check ( Member . GetStructMetadata ( ) ) ;
FString MemberPrefix = FString : : Printf ( TEXT ( " %s%s_ " ) , Prefix , Member . GetName ( ) ) ;
Member . GetStructMetadata ( ) - > AddResourceTableEntriesRecursive ( UniformBufferName , * MemberPrefix , ResourceIndex , ResourceTableMap ) ;
}
2019-06-11 18:27:07 -04:00
else if ( Member . GetBaseType ( ) = = UBMT_NESTED_STRUCT & & NumElements > 0 )
{
for ( uint32 ArrayElementId = 0 ; ArrayElementId < NumElements ; ArrayElementId + + )
{
check ( Member . GetStructMetadata ( ) ) ;
FString MemberPrefix = FString : : Printf ( TEXT ( " %s%s_%u_ " ) , Prefix , Member . GetName ( ) , ArrayElementId ) ;
Member . GetStructMetadata ( ) - > AddResourceTableEntriesRecursive ( UniformBufferName , * MemberPrefix , ResourceIndex , ResourceTableMap ) ;
}
}
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
else if ( Member . GetBaseType ( ) = = UBMT_INCLUDED_STRUCT )
{
check ( Member . GetStructMetadata ( ) ) ;
2019-06-11 18:27:07 -04:00
check ( NumElements = = 0 ) ;
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
Member . GetStructMetadata ( ) - > AddResourceTableEntriesRecursive ( UniformBufferName , Prefix , ResourceIndex , ResourceTableMap ) ;
}
}
}
2019-03-07 11:25:32 -05:00
void FShaderParametersMetadata : : FindMemberFromOffset ( uint16 MemberOffset , const FShaderParametersMetadata * * OutContainingStruct , const FShaderParametersMetadata : : FMember * * OutMember , int32 * ArrayElementId , FString * NamePrefix ) const
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
check ( MemberOffset < GetSize ( ) ) ;
for ( const FMember & Member : Members )
{
EUniformBufferBaseType BaseType = Member . GetBaseType ( ) ;
2019-06-11 18:27:07 -04:00
uint32 NumElements = Member . GetNumElements ( ) ;
if ( ( BaseType = = UBMT_NESTED_STRUCT & & NumElements = = 0 ) | | BaseType = = UBMT_INCLUDED_STRUCT )
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
const FShaderParametersMetadata * SubStruct = Member . GetStructMetadata ( ) ;
2019-06-11 18:27:07 -04:00
if ( MemberOffset < ( Member . GetOffset ( ) + SubStruct - > GetSize ( ) ) )
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
{
2019-03-07 11:25:32 -05:00
if ( NamePrefix )
{
* NamePrefix = FString : : Printf ( TEXT ( " %s%s:: " ) , * * NamePrefix , Member . GetName ( ) ) ;
}
return SubStruct - > FindMemberFromOffset ( MemberOffset - Member . GetOffset ( ) , OutContainingStruct , OutMember , ArrayElementId , NamePrefix ) ;
}
}
2019-06-11 18:27:07 -04:00
else if ( BaseType = = UBMT_NESTED_STRUCT & & NumElements > 0 )
{
const FShaderParametersMetadata * SubStruct = Member . GetStructMetadata ( ) ;
uint32 StructSize = SubStruct - > GetSize ( ) ;
uint16 ArrayStartOffset = Member . GetOffset ( ) ;
uint16 ArrayEndOffset = ArrayStartOffset + SubStruct - > GetSize ( ) * NumElements ;
if ( MemberOffset > = ArrayStartOffset & & MemberOffset < ArrayEndOffset )
{
uint32 MemberOffsetInArray = MemberOffset - ArrayStartOffset ;
check ( ( MemberOffsetInArray % StructSize ) = = 0 ) ;
uint32 MemberPosInStructArray = MemberOffsetInArray / StructSize ;
uint32 MemberOffsetInStructElement = MemberOffsetInArray - MemberPosInStructArray * StructSize ;
if ( NamePrefix )
{
* NamePrefix = FString : : Printf ( TEXT ( " %s%s[%u]:: " ) , * * NamePrefix , Member . GetName ( ) , MemberPosInStructArray ) ;
}
return SubStruct - > FindMemberFromOffset ( MemberOffsetInStructElement , OutContainingStruct , OutMember , ArrayElementId , NamePrefix ) ;
}
}
else if ( NumElements > 0 & & (
2019-03-07 11:25:32 -05:00
BaseType = = UBMT_TEXTURE | |
BaseType = = UBMT_SRV | |
BaseType = = UBMT_SAMPLER | |
IsRDGResourceReferenceShaderParameterType ( BaseType ) ) )
{
uint16 ArrayStartOffset = Member . GetOffset ( ) ;
2019-06-11 18:27:07 -04:00
uint16 ArrayEndOffset = ArrayStartOffset + SHADER_PARAMETER_POINTER_ALIGNMENT * NumElements ;
2019-03-07 11:25:32 -05:00
if ( MemberOffset > = ArrayStartOffset & & MemberOffset < ArrayEndOffset )
{
check ( ( MemberOffset % SHADER_PARAMETER_POINTER_ALIGNMENT ) = = 0 ) ;
* OutContainingStruct = this ;
* OutMember = & Member ;
* ArrayElementId = ( MemberOffset - ArrayStartOffset ) / SHADER_PARAMETER_POINTER_ALIGNMENT ;
return ;
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
}
}
else if ( Member . GetOffset ( ) = = MemberOffset )
{
* OutContainingStruct = this ;
* OutMember = & Member ;
2019-03-07 11:25:32 -05:00
* ArrayElementId = 0 ;
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
return ;
}
}
checkf ( 0 , TEXT ( " Looks like this offset is invalid. " ) ) ;
}
2019-10-01 13:03:04 -04:00
FString FShaderParametersMetadata : : GetFullMemberCodeName ( uint16 MemberOffset ) const
{
const FShaderParametersMetadata * MemberContainingStruct = nullptr ;
const FShaderParametersMetadata : : FMember * Member = nullptr ;
int32 ArrayElementId = 0 ;
FString NamePrefix ;
FindMemberFromOffset ( MemberOffset , & MemberContainingStruct , & Member , & ArrayElementId , & NamePrefix ) ;
FString MemberName = FString : : Printf ( TEXT ( " %s%s " ) , * NamePrefix , Member - > GetName ( ) ) ;
if ( Member - > GetNumElements ( ) > 0 )
{
MemberName = FString : : Printf ( TEXT ( " %s%s[%d] " ) , * NamePrefix , Member - > GetName ( ) , ArrayElementId ) ;
}
return MemberName ;
}