2019-12-26 15:33:43 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2018-05-23 21:04:31 -04:00
//
# include "MaterialStatsGrid.h"
# include "MaterialStats.h"
# include "MaterialStatsCommon.h"
/*==============================================================================================================*/
/* FGridRow functions*/
void FStatsGridRow : : AddCell ( FName ColumnName , TSharedPtr < FGridCell > Cell )
{
RowCells . Add ( ColumnName , Cell ) ;
}
void FStatsGridRow : : RemoveCell ( FName ColumnName )
{
RowCells . Remove ( ColumnName ) ;
}
TSharedPtr < FGridCell > FStatsGridRow : : GetCell ( const FName ColumnName )
{
TSharedPtr < FGridCell > RetCell = nullptr ;
auto * CellPtr = RowCells . Find ( ColumnName ) ;
if ( CellPtr ! = nullptr )
{
RetCell = * CellPtr ;
}
return RetCell ;
}
2023-09-15 05:04:46 -04:00
void FStatsGridRow : : RemovePlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
2023-09-15 05:04:46 -04:00
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
RemoveCell ( ColumnName ) ;
}
void FStatsGridRow : : FillPlatformCellsHelper ( TSharedPtr < FMaterialStats > StatsManager )
{
auto & PlatformDB = StatsManager - > GetPlatformsDB ( ) ;
for ( auto Pair : PlatformDB )
{
auto Platform = Pair . Value ;
if ( ! Platform - > IsPresentInGrid ( ) )
{
continue ;
}
for ( int32 q = 0 ; q < ( int32 ) EMaterialQualityLevel : : Num ; + + q )
{
EMaterialQualityLevel : : Type QualityLevel = ( EMaterialQualityLevel : : Type ) q ;
if ( StatsManager - > GetStatsQualityFlag ( QualityLevel ) )
{
2023-09-15 05:04:46 -04:00
for ( int32 InstanceIndex = 0 ; InstanceIndex < Platform - > GetPlatformData ( QualityLevel ) . Instances . Num ( ) ; + + InstanceIndex )
{
// call implementation specific function to build the needed cell
AddPlatform ( StatsManager , Platform , QualityLevel , InstanceIndex ) ;
}
2018-05-23 21:04:31 -04:00
}
}
}
}
/* end FGridRow functions*/
/*==============================================================================================================*/
/*==============================================================================================================*/
/* FStatsGridRow_Empty functions*/
void FStatsGridRow_Empty : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// just an array of empty cells
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2023-12-19 09:36:35 -05:00
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2018-05-23 21:04:31 -04:00
FillPlatformCellsHelper ( StatsManager ) ;
}
2023-09-15 05:04:46 -04:00
void FStatsGridRow_Empty : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
TSharedPtr < FGridCell_Empty > Cell = MakeShareable ( new FGridCell_Empty ( ) ) ;
2023-09-15 05:04:46 -04:00
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
AddCell ( ColumnName , Cell ) ;
}
/* end FStatsGridRow_Empty functions*/
/*==============================================================================================================*/
2023-09-15 05:04:46 -04:00
/*==============================================================================================================*/
/* FStatsGridRow_Name functions*/
void FStatsGridRow_Name : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// we don't use a descriptor for this row
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2023-12-19 09:36:35 -05:00
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2023-09-15 05:04:46 -04:00
FillPlatformCellsHelper ( StatsManager ) ;
}
void FStatsGridRow_Name : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
{
// add a cell that will query any available errors for this platform
TSharedPtr < FGridCell_ShaderValue > Cell = MakeShareable ( new FGridCell_ShaderValue ( StatsManager , EShaderInfoType : : Name , ERepresentativeShader : : Num , QualityLevel , Platform - > GetPlatformShaderType ( ) , InstanceIndex ) ) ;
Cell - > SetHorizontalAlignment ( HAlign_Fill ) ;
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_Name functions*/
/*==============================================================================================================*/
2018-05-23 21:04:31 -04:00
/*==============================================================================================================*/
/* FStatsGridRow_Quality functions*/
void FStatsGridRow_Quality : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// we don't use a descriptor for this row
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2023-12-19 09:36:35 -05:00
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2018-05-23 21:04:31 -04:00
FillPlatformCellsHelper ( StatsManager ) ;
}
2023-09-15 05:04:46 -04:00
void FStatsGridRow_Quality : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
// translate material quality to string and store it inside a StaticString cell
const FString CellContent = FMaterialStatsUtils : : MaterialQualityToShortString ( QualityLevel ) ;
TSharedPtr < FGridCell_StaticString > Cell = MakeShareable ( new FGridCell_StaticString ( CellContent , CellContent ) ) ;
Cell - > SetContentBold ( true ) ;
2021-02-19 17:17:59 -04:00
FSlateColor CellColor = FMaterialStatsUtils : : QualitySettingColor ( QualityLevel ) ;
2018-05-23 21:04:31 -04:00
Cell - > SetColor ( CellColor ) ;
2023-09-15 05:04:46 -04:00
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_Quality functions*/
/*==============================================================================================================*/
/*==============================================================================================================*/
/* FStatsGridRow_Shaders functions*/
2023-12-19 09:36:35 -05:00
FStatsGridRow_Shaders : : FStatsGridRow_Shaders ( ERepresentativeShader RepresentativeShader , bool bHeader , bool bInstructionRow )
: bIsHeaderRow ( bHeader )
, bInstructionRow ( bInstructionRow )
, ShaderType ( RepresentativeShader )
2018-05-23 21:04:31 -04:00
{
}
FStatsGridRow_Shaders : : EShaderClass FStatsGridRow_Shaders : : GetShaderClass ( const ERepresentativeShader Shader )
{
switch ( Shader )
{
case ERepresentativeShader : : StationarySurface :
case ERepresentativeShader : : StationarySurfaceCSM :
case ERepresentativeShader : : StationarySurfaceNPointLights :
case ERepresentativeShader : : DynamicallyLitObject :
case ERepresentativeShader : : UIDefaultFragmentShader :
2022-11-02 23:06:33 -04:00
case ERepresentativeShader : : RuntimeVirtualTextureOutput :
2018-05-23 21:04:31 -04:00
return EShaderClass : : FragmentShader ;
break ;
case ERepresentativeShader : : StaticMesh :
case ERepresentativeShader : : SkeletalMesh :
case ERepresentativeShader : : UIDefaultVertexShader :
case ERepresentativeShader : : UIInstancedVertexShader :
return EShaderClass : : VertexShader ;
break ;
2024-06-27 10:33:39 -04:00
case ERepresentativeShader : : NaniteMesh :
return EShaderClass : : ComputeShader ;
break ;
2018-05-23 21:04:31 -04:00
}
return EShaderClass : : VertexShader ;
}
void FStatsGridRow_Shaders : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
TSharedPtr < FGridCell > HeaderCell ;
// in the first row of this type add a "Vertex/Fragment Shader" static text
if ( bIsHeaderRow )
{
EShaderClass ShaderClass = GetShaderClass ( ShaderType ) ;
2024-06-27 10:33:39 -04:00
FString HeaderContent ;
if ( ShaderClass = = EShaderClass : : VertexShader )
{
HeaderContent = TEXT ( " Vertex Shader " ) ;
}
else if ( ShaderClass = = EShaderClass : : FragmentShader )
{
HeaderContent = TEXT ( " Pixel Shader " ) ;
}
else if ( ShaderClass = = EShaderClass : : ComputeShader )
{
HeaderContent = TEXT ( " Compute Shader " ) ;
}
2018-05-23 21:04:31 -04:00
HeaderCell = MakeShareable ( new FGridCell_StaticString ( HeaderContent , HeaderContent ) ) ;
HeaderCell - > SetContentBold ( true ) ;
2021-02-16 15:32:41 -04:00
HeaderCell - > SetColor ( FStyleColors : : Foreground ) ;
2018-05-23 21:04:31 -04:00
}
else
{
HeaderCell = MakeShareable ( new FGridCell_Empty ( ) ) ;
}
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , HeaderCell ) ;
// now add a cell that can display the name of this shader's class
FString ShaderColumnContent = FMaterialStatsUtils : : RepresentativeShaderTypeToString ( ShaderType ) ;
TSharedPtr < FGridCell > ShaderNameCell = MakeShareable ( new FGridCell_StaticString ( ShaderColumnContent , ShaderColumnContent ) ) ;
ShaderNameCell - > SetHorizontalAlignment ( HAlign_Fill ) ;
ShaderNameCell - > SetContentBold ( true ) ;
2021-02-16 15:32:41 -04:00
ShaderNameCell - > SetColor ( FStyleColors : : Foreground ) ;
2018-05-23 21:04:31 -04:00
AddCell ( FMaterialStatsGrid : : ShaderColumnName , ShaderNameCell ) ;
2023-12-19 09:36:35 -05:00
// now add a cell that can display the what statistic we are describing.
FString ColumnContent = bInstructionRow ? TEXT ( " Instruction Count " ) : TEXT ( " Platform Statistics " ) ;
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_StaticString ( ColumnContent , ColumnContent ) ) ) ;
2018-05-23 21:04:31 -04:00
FillPlatformCellsHelper ( StatsManager ) ;
}
2023-09-15 05:04:46 -04:00
void FStatsGridRow_Shaders : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
// add a cell that display the instruction count for this platform
const FString CellContent = FMaterialStatsUtils : : MaterialQualityToShortString ( QualityLevel ) ;
2023-12-19 09:36:35 -05:00
TSharedPtr < FGridCell_ShaderValue > Cell = MakeShareable ( new FGridCell_ShaderValue ( StatsManager , bInstructionRow ? EShaderInfoType : : InstructionsCount : EShaderInfoType : : GenericShaderStatistics , ShaderType , QualityLevel , Platform - > GetPlatformShaderType ( ) , InstanceIndex ) ) ;
2018-05-23 21:04:31 -04:00
2023-09-15 05:04:46 -04:00
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_Shaders functions*/
/*==============================================================================================================*/
/*==============================================================================================================*/
/* FStatsGridRow_Samplers functions*/
void FStatsGridRow_Samplers : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// static text in the descriptor column
TSharedPtr < FGridCell > HeaderCell = MakeShareable ( new FGridCell_StaticString ( TEXT ( " Samplers " ) , TEXT ( " Texture Samplers " ) ) ) ;
HeaderCell - > SetColor ( FLinearColor : : Gray ) ;
HeaderCell - > SetContentBold ( true ) ;
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , HeaderCell ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2023-12-19 09:36:35 -05:00
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2018-05-23 21:04:31 -04:00
FillPlatformCellsHelper ( StatsManager ) ;
}
2023-09-15 05:04:46 -04:00
void FStatsGridRow_Samplers : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
// cell that will enumerate the total number of samplers in this material
const FString CellContent = FMaterialStatsUtils : : MaterialQualityToShortString ( QualityLevel ) ;
2023-09-15 05:04:46 -04:00
TSharedPtr < FGridCell_ShaderValue > Cell = MakeShareable ( new FGridCell_ShaderValue ( StatsManager , EShaderInfoType : : SamplersCount , ERepresentativeShader : : Num , QualityLevel , Platform - > GetPlatformShaderType ( ) , InstanceIndex ) ) ;
2018-05-23 21:04:31 -04:00
2023-09-15 05:04:46 -04:00
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_Samplers functions*/
/*==============================================================================================================*/
/*==============================================================================================================*/
/* FStatsGridRow_Interpolators functions*/
void FStatsGridRow_Interpolators : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// static string in the descriptor column
TSharedPtr < FGridCell > HeaderCell = MakeShareable ( new FGridCell_StaticString ( TEXT ( " Interpolators " ) , TEXT ( " Interpolators " ) ) ) ;
2021-02-16 15:32:41 -04:00
HeaderCell - > SetColor ( FStyleColors : : Foreground ) ;
2018-05-23 21:04:31 -04:00
HeaderCell - > SetContentBold ( true ) ;
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , HeaderCell ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2023-12-19 09:36:35 -05:00
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2018-05-23 21:04:31 -04:00
FillPlatformCellsHelper ( StatsManager ) ;
}
2023-09-15 05:04:46 -04:00
void FStatsGridRow_Interpolators : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
// cell that will enumerate the total number of interpolators in this material
const FString CellContent = FMaterialStatsUtils : : MaterialQualityToShortString ( QualityLevel ) ;
2023-09-15 05:04:46 -04:00
TSharedPtr < FGridCell_ShaderValue > Cell = MakeShareable ( new FGridCell_ShaderValue ( StatsManager , EShaderInfoType : : InterpolatorsCount , ERepresentativeShader : : Num , QualityLevel , Platform - > GetPlatformShaderType ( ) , InstanceIndex ) ) ;
2018-05-23 21:04:31 -04:00
2023-09-15 05:04:46 -04:00
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_Interpolators functions*/
/*==============================================================================================================*/
/*==============================================================================================================*/
/* FStatsGridRow_NumTextureSamples functions*/
void FStatsGridRow_NumTextureSamples : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// static string in the descriptor column
TSharedPtr < FGridCell > HeaderCell = MakeShareable ( new FGridCell_StaticString ( TEXT ( " Texture Lookups (Est.) " ) , TEXT ( " Texture Lookups (Est.) " ) ) ) ;
2021-02-16 15:32:41 -04:00
HeaderCell - > SetColor ( FStyleColors : : Foreground ) ;
2018-05-23 21:04:31 -04:00
HeaderCell - > SetContentBold ( true ) ;
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , HeaderCell ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2023-12-19 09:36:35 -05:00
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2018-05-23 21:04:31 -04:00
FillPlatformCellsHelper ( StatsManager ) ;
}
2023-09-15 05:04:46 -04:00
void FStatsGridRow_NumTextureSamples : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
// cell that will enumerate the total number of texture samples in this material
const FString CellContent = FMaterialStatsUtils : : MaterialQualityToShortString ( QualityLevel ) ;
2023-09-15 05:04:46 -04:00
TSharedPtr < FGridCell_ShaderValue > Cell = MakeShareable ( new FGridCell_ShaderValue ( StatsManager , EShaderInfoType : : TextureSampleCount , ERepresentativeShader : : Num , QualityLevel , Platform - > GetPlatformShaderType ( ) , InstanceIndex ) ) ;
2018-05-23 21:04:31 -04:00
2023-09-15 05:04:46 -04:00
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_NumTextureSamples functions*/
/*==============================================================================================================*/
2019-06-11 18:27:07 -04:00
/*==============================================================================================================*/
/* FStatsGridRow_NumVirtualTextureLookups functions*/
void FStatsGridRow_NumVirtualTextureLookups : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// static string in the descriptor column
TSharedPtr < FGridCell > HeaderCell = MakeShareable ( new FGridCell_StaticString ( TEXT ( " VT Lookups (Est.) " ) , TEXT ( " Virtual Texture Lookups (Est.) " ) ) ) ;
2021-02-16 15:32:41 -04:00
HeaderCell - > SetColor ( FStyleColors : : Foreground ) ;
2019-06-11 18:27:07 -04:00
HeaderCell - > SetContentBold ( true ) ;
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , HeaderCell ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2023-12-19 09:36:35 -05:00
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2019-06-11 18:27:07 -04:00
FillPlatformCellsHelper ( StatsManager ) ;
}
2023-09-15 05:04:46 -04:00
void FStatsGridRow_NumVirtualTextureLookups : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2019-06-11 18:27:07 -04:00
{
// cell that will enumerate the total number of texture samples in this material
const FString CellContent = FMaterialStatsUtils : : MaterialQualityToShortString ( QualityLevel ) ;
2023-09-15 05:04:46 -04:00
TSharedPtr < FGridCell_ShaderValue > Cell = MakeShareable ( new FGridCell_ShaderValue ( StatsManager , EShaderInfoType : : VirtualTextureLookupCount , ERepresentativeShader : : Num , QualityLevel , Platform - > GetPlatformShaderType ( ) , InstanceIndex ) ) ;
2019-06-11 18:27:07 -04:00
2023-09-15 05:04:46 -04:00
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
2019-06-11 18:27:07 -04:00
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_NumVirtualTextureLookups functions*/
/*==============================================================================================================*/
2021-03-03 16:24:00 -04:00
/*==============================================================================================================*/
2023-12-21 11:47:27 -05:00
/* FStatsGridRow_NumShaders functions*/
2021-03-03 16:24:00 -04:00
void FStatsGridRow_NumShaders : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// static string in the descriptor column
TSharedPtr < FGridCell > HeaderCell = MakeShareable ( new FGridCell_StaticString ( TEXT ( " Shader Count " ) , TEXT ( " Number of shaders compiled for this platform and quality level. " ) ) ) ;
HeaderCell - > SetColor ( FStyleColors : : Foreground ) ;
HeaderCell - > SetContentBold ( true ) ;
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , HeaderCell ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2023-12-19 09:36:35 -05:00
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
2021-03-03 16:24:00 -04:00
FillPlatformCellsHelper ( StatsManager ) ;
}
2023-09-15 05:04:46 -04:00
void FStatsGridRow_NumShaders : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2021-03-03 16:24:00 -04:00
{
// cell that will enumerate the number of shaders
const FString CellContent = FMaterialStatsUtils : : MaterialQualityToShortString ( QualityLevel ) ;
2023-09-15 05:04:46 -04:00
TSharedPtr < FGridCell_ShaderValue > Cell = MakeShareable ( new FGridCell_ShaderValue ( StatsManager , EShaderInfoType : : ShaderCount , ERepresentativeShader : : Num , QualityLevel , Platform - > GetPlatformShaderType ( ) , InstanceIndex ) ) ;
2021-03-03 16:24:00 -04:00
2023-09-15 05:04:46 -04:00
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
2021-03-03 16:24:00 -04:00
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_NumTotalShaders functions*/
/*==============================================================================================================*/
2023-12-21 11:47:27 -05:00
/*==============================================================================================================*/
/* FStatsGridRow_NumPreshaders functions*/
void FStatsGridRow_NumPreshaders : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// static string in the descriptor column
TSharedPtr < FGridCell > HeaderCell = MakeShareable ( new FGridCell_StaticString ( TEXT ( " Preshader Count " ) , TEXT ( " Number of preshader instructions that will be evaluated on the CPU for this material. " ) ) ) ;
HeaderCell - > SetColor ( FStyleColors : : Foreground ) ;
HeaderCell - > SetContentBold ( true ) ;
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , HeaderCell ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
FillPlatformCellsHelper ( StatsManager ) ;
}
void FStatsGridRow_NumPreshaders : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
{
// cell that will enumerate the number of pre shaders
const FString CellContent = FMaterialStatsUtils : : MaterialQualityToShortString ( QualityLevel ) ;
TSharedPtr < FGridCell_ShaderValue > Cell = MakeShareable ( new FGridCell_ShaderValue ( StatsManager , EShaderInfoType : : PreShaderCount , ERepresentativeShader : : Num , QualityLevel , Platform - > GetPlatformShaderType ( ) , InstanceIndex ) ) ;
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_NumPreshaders functions*/
/*==============================================================================================================*/
2024-01-09 12:32:53 -05:00
/*==============================================================================================================*/
/* FStatsGridRow_LWCUsage functions*/
void FStatsGridRow_LWCUsage : : CreateRow ( TSharedPtr < FMaterialStats > StatsManager )
{
// static string in the descriptor column
TSharedPtr < FGridCell > HeaderCell = MakeShareable ( new FGridCell_StaticString ( TEXT ( " Large World Coordinate Usages (Est.) " ) , TEXT ( " Estimates for the number of large world coordinate operations in the material. " ) ) ) ;
HeaderCell - > SetColor ( FStyleColors : : Foreground ) ;
HeaderCell - > SetContentBold ( true ) ;
AddCell ( FMaterialStatsGrid : : DescriptorColumnName , HeaderCell ) ;
AddCell ( FMaterialStatsGrid : : ShaderColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
AddCell ( FMaterialStatsGrid : : ShaderStatisticColumnName , MakeShareable ( new FGridCell_Empty ( ) ) ) ;
FillPlatformCellsHelper ( StatsManager ) ;
}
void FStatsGridRow_LWCUsage : : AddPlatform ( TSharedPtr < FMaterialStats > StatsManager , const TSharedPtr < FShaderPlatformSettings > Platform , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
{
// cell that will enumerate the number of pre shaders
const FString CellContent = FMaterialStatsUtils : : MaterialQualityToShortString ( QualityLevel ) ;
TSharedPtr < FGridCell_ShaderValue > Cell = MakeShareable ( new FGridCell_ShaderValue ( StatsManager , EShaderInfoType : : LWCUsage , ERepresentativeShader : : Num , QualityLevel , Platform - > GetPlatformShaderType ( ) , InstanceIndex ) ) ;
const FName ColumnName = FMaterialStatsGrid : : MakePlatformColumnName ( Platform , QualityLevel , InstanceIndex ) ;
AddCell ( ColumnName , Cell ) ;
}
/*end FStatsGridRow_LWCUsage functions*/
/*==============================================================================================================*/
2018-05-23 21:04:31 -04:00
/***********************************************************************************************************************/
/*FShaderStatsGrid functions*/
const FName FMaterialStatsGrid : : DescriptorColumnName = TEXT ( " Descriptor " ) ;
const FName FMaterialStatsGrid : : ShaderColumnName = TEXT ( " ShaderList " ) ;
2023-12-19 09:36:35 -05:00
const FName FMaterialStatsGrid : : ShaderStatisticColumnName = TEXT ( " ShaderStatistics " ) ;
2018-05-23 21:04:31 -04:00
FMaterialStatsGrid : : FMaterialStatsGrid ( TWeakPtr < FMaterialStats > _StatsManager )
{
StatsManagerWPtr = _StatsManager ;
}
FMaterialStatsGrid : : ~ FMaterialStatsGrid ( )
{
StaticRows . Empty ( ) ;
VertexShaderRows . Empty ( ) ;
FragmentShaderRows . Empty ( ) ;
GridColumnContent . Empty ( ) ;
}
TSharedPtr < FGridCell > FMaterialStatsGrid : : GetCell ( int32 RowID , FName ColumnName )
{
// if there is no such row return a newly created cell with empty content
ERowType RowType ;
int32 Index ;
DissasambleRowKey ( RowType , Index , RowID ) ;
if ( RowType = = ERowType : : FragmentShader & & Index > = 0 & & Index < FragmentShaderRows . Num ( ) )
{
return FragmentShaderRows [ Index ] - > GetCell ( ColumnName ) ;
}
else if ( RowType = = ERowType : : VertexShader & & Index > = 0 & & Index < VertexShaderRows . Num ( ) )
{
return VertexShaderRows [ Index ] - > GetCell ( ColumnName ) ;
}
else
{
auto * RowPtr = StaticRows . Find ( RowType ) ;
if ( RowPtr ! = nullptr )
{
return ( * RowPtr ) - > GetCell ( ColumnName ) ;
}
}
return MakeShareable ( new FGridCell_Empty ( ) ) ;
}
2023-09-15 05:04:46 -04:00
void FMaterialStatsGrid : : CollectShaderInfo ( const TSharedPtr < FShaderPlatformSettings > & PlatformPtr , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
const FShaderPlatformSettings : : FPlatformData & PlatformData = PlatformPtr - > GetPlatformData ( QualityLevel ) ;
for ( int32 i = 0 ; i < ( int32 ) ERepresentativeShader : : Num ; + + i )
{
2023-09-15 05:04:46 -04:00
UsedShaders [ i ] | = PlatformData . Instances [ InstanceIndex ] . ShaderStatsInfo . ShaderInstructionCount . Contains ( ( ERepresentativeShader ) i ) ;
2018-05-23 21:04:31 -04:00
}
}
void FMaterialStatsGrid : : CollectShaderInfo ( )
{
TSharedPtr < FMaterialStats > StatsManager = StatsManagerWPtr . Pin ( ) ;
if ( ! StatsManager . IsValid ( ) )
{
return ;
}
for ( int32 i = 0 ; i < UsedShaders . Num ( ) ; + + i )
{
UsedShaders [ i ] = false ;
}
auto & PlatformDB = StatsManager - > GetPlatformsDB ( ) ;
for ( auto Pair : PlatformDB )
{
auto Platform = Pair . Value ;
if ( ! Platform - > IsPresentInGrid ( ) )
{
continue ;
}
for ( int32 q = 0 ; q < EMaterialQualityLevel : : Num ; + + q )
{
EMaterialQualityLevel : : Type QualitySetting = static_cast < EMaterialQualityLevel : : Type > ( q ) ;
2023-09-15 05:04:46 -04:00
for ( int32 InstanceIndex = 0 ; InstanceIndex < Platform - > GetPlatformData ( QualitySetting ) . Instances . Num ( ) ; + + InstanceIndex )
{
CollectShaderInfo ( Platform , QualitySetting , InstanceIndex ) ;
}
2018-05-23 21:04:31 -04:00
}
}
}
FString FMaterialStatsGrid : : GetColumnContent ( const FName ColumnName ) const
{
auto * Ptr = GridColumnContent . Find ( ColumnName ) ;
return Ptr ! = nullptr ? Ptr - > Content : TEXT ( " " ) ;
}
FString FMaterialStatsGrid : : GetColumnContentLong ( const FName ColumnName ) const
{
auto * Ptr = GridColumnContent . Find ( ColumnName ) ;
return Ptr ! = nullptr ? Ptr - > ContentLong : TEXT ( " " ) ;
}
2021-02-16 15:32:41 -04:00
FSlateColor FMaterialStatsGrid : : GetColumnColor ( const FName ColumnName ) const
2018-05-23 21:04:31 -04:00
{
auto * Ptr = GridColumnContent . Find ( ColumnName ) ;
return Ptr ! = nullptr ? Ptr - > Color : FLinearColor : : Gray ;
}
void FMaterialStatsGrid : : BuildKeyAndInsert ( const ERowType RowType , int16 Index /*= 0*/ )
{
int32 Key = AssembleRowKey ( RowType , Index ) ;
RowIDs . Add ( MakeShareable ( new int32 ( Key ) ) ) ;
}
void FMaterialStatsGrid : : CheckForErrors ( )
{
PlatformErrorsType = EGlobalErrorsType : : NoErrors ;
TSharedPtr < FMaterialStats > StatsManager = StatsManagerWPtr . Pin ( ) ;
if ( StatsManager . IsValid ( ) )
{
auto & PlatformDB = StatsManager - > GetPlatformsDB ( ) ;
for ( auto Pair : PlatformDB )
{
auto Platform = Pair . Value ;
if ( ! Platform - > IsPresentInGrid ( ) )
{
continue ;
}
for ( int32 q = 0 ; q < EMaterialQualityLevel : : Num ; + + q )
{
EMaterialQualityLevel : : Type QualitySetting = static_cast < EMaterialQualityLevel : : Type > ( q ) ;
if ( StatsManager - > GetStatsQualityFlag ( QualitySetting ) )
{
2023-09-15 05:04:46 -04:00
for ( int32 InstanceIndex = 0 ; InstanceIndex < Platform - > GetPlatformData ( QualitySetting ) . Instances . Num ( ) ; + + InstanceIndex )
{
auto & Data = Platform - > GetInstanceData ( QualitySetting , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
2023-09-15 05:04:46 -04:00
if ( Data . ShaderStatsInfo . HasErrors ( ) )
{
PlatformErrorsType = PlatformErrorsType = = EGlobalErrorsType : : SpecificPlatformErrors ? EGlobalErrorsType : : SpecificPlatformErrors : EGlobalErrorsType : : GlobalPlatformErrors ;
}
else
{
PlatformErrorsType = PlatformErrorsType = = EGlobalErrorsType : : NoErrors ? EGlobalErrorsType : : NoErrors : EGlobalErrorsType : : SpecificPlatformErrors ;
}
2018-05-23 21:04:31 -04:00
}
}
}
}
}
}
void FMaterialStatsGrid : : BuildRowIds ( )
{
RowIDs . Reset ( ) ;
2023-09-15 05:04:46 -04:00
BuildKeyAndInsert ( ERowType : : Name ) ;
2018-05-23 21:04:31 -04:00
BuildKeyAndInsert ( ERowType : : Quality ) ;
// add the rest of the rows only if there's at least one error free platform
if ( PlatformErrorsType ! = EGlobalErrorsType : : GlobalPlatformErrors )
{
for ( int32 i = 0 ; i < FragmentShaderRows . Num ( ) ; + + i )
{
BuildKeyAndInsert ( ERowType : : FragmentShader , ( int16 ) i ) ;
}
if ( FragmentShaderRows . Num ( ) )
{
BuildKeyAndInsert ( ERowType : : Empty ) ;
}
for ( int32 i = 0 ; i < VertexShaderRows . Num ( ) ; + + i )
{
BuildKeyAndInsert ( ERowType : : VertexShader , ( int16 ) i ) ;
}
if ( VertexShaderRows . Num ( ) )
{
BuildKeyAndInsert ( ERowType : : Empty ) ;
}
BuildKeyAndInsert ( ERowType : : Samplers ) ;
BuildKeyAndInsert ( ERowType : : TextureSamples ) ;
2019-06-11 18:27:07 -04:00
BuildKeyAndInsert ( ERowType : : VirtualTextureLookups ) ;
2021-03-03 16:24:00 -04:00
BuildKeyAndInsert ( ERowType : : Interpolators ) ;
BuildKeyAndInsert ( ERowType : : Shaders ) ;
2023-12-21 11:47:27 -05:00
BuildKeyAndInsert ( ERowType : : PreShaders ) ;
2024-01-09 12:32:53 -05:00
BuildKeyAndInsert ( ERowType : : LWCUsage ) ;
2018-05-23 21:04:31 -04:00
}
}
void FMaterialStatsGrid : : OnShaderChanged ( )
{
CollectShaderInfo ( ) ;
2023-09-15 05:04:46 -04:00
2018-05-23 21:04:31 -04:00
BuildShaderRows ( ) ;
2023-09-15 05:04:46 -04:00
BuildColumnInfo ( ) ;
2018-05-23 21:04:31 -04:00
CheckForErrors ( ) ;
BuildRowIds ( ) ;
}
2023-09-15 05:04:46 -04:00
void FMaterialStatsGrid : : OnColumnNumChanged ( )
{
// nuke all rows to rebuild columns
BuildStaticRows ( ) ;
OnShaderChanged ( ) ;
}
2018-05-23 21:04:31 -04:00
void FMaterialStatsGrid : : BuildStaticRows ( )
{
TSharedPtr < FMaterialStats > StatsManager = StatsManagerWPtr . Pin ( ) ;
if ( ! StatsManager . IsValid ( ) )
{
return ;
}
StaticRows . Reset ( ) ;
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_Empty ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : Empty , Row ) ;
}
2023-09-15 05:04:46 -04:00
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_Name ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : Name , Row ) ;
}
2018-05-23 21:04:31 -04:00
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_Quality ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : Quality , Row ) ;
}
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_Samplers ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : Samplers , Row ) ;
}
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_NumTextureSamples ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : TextureSamples , Row ) ;
}
2019-06-11 18:27:07 -04:00
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_NumVirtualTextureLookups ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : VirtualTextureLookups , Row ) ;
}
2018-05-23 21:04:31 -04:00
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_Interpolators ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : Interpolators , Row ) ;
}
2021-03-03 16:24:00 -04:00
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_NumShaders ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : Shaders , Row ) ;
}
2023-12-21 11:47:27 -05:00
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_NumPreshaders ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : PreShaders , Row ) ;
}
2024-01-09 12:32:53 -05:00
{
TSharedPtr < FStatsGridRow > Row = MakeShareable ( new FStatsGridRow_LWCUsage ( ) ) ;
Row - > CreateRow ( StatsManager ) ;
StaticRows . Add ( ERowType : : LWCUsage , Row ) ;
}
2018-05-23 21:04:31 -04:00
}
void FMaterialStatsGrid : : BuildShaderRows ( )
{
TSharedPtr < FMaterialStats > StatsManager = StatsManagerWPtr . Pin ( ) ;
if ( ! StatsManager . IsValid ( ) )
{
return ;
}
VertexShaderRows . Empty ( ) ;
FragmentShaderRows . Empty ( ) ;
// fragment shaders
for ( auto i = ( int32 ) ERepresentativeShader : : FirstFragmentShader ; i < = ( int32 ) ERepresentativeShader : : LastFragmentShader ; + + i )
{
if ( UsedShaders [ i ] )
{
bool bFirstShader = ! FragmentShaderRows . Num ( ) ;
2023-12-19 09:36:35 -05:00
TSharedPtr < FStatsGridRow > FragShaderRow = MakeShareable ( new FStatsGridRow_Shaders ( ( ERepresentativeShader ) i , bFirstShader , true ) ) ;
2018-05-23 21:04:31 -04:00
FragShaderRow - > CreateRow ( StatsManager ) ;
FragmentShaderRows . Add ( FragShaderRow ) ;
2023-12-19 09:36:35 -05:00
TSharedPtr < FStatsGridRow > FragShaderRow2 = MakeShareable ( new FStatsGridRow_Shaders ( ( ERepresentativeShader ) i , false , false ) ) ;
FragShaderRow2 - > CreateRow ( StatsManager ) ;
FragmentShaderRows . Add ( FragShaderRow2 ) ;
2018-05-23 21:04:31 -04:00
}
}
// vertex shaders
for ( auto i = ( int32 ) ERepresentativeShader : : FirstVertexShader ; i < = ( int32 ) ERepresentativeShader : : LastVertexShader ; + + i )
{
if ( UsedShaders [ i ] )
{
bool bFirstShader = ! VertexShaderRows . Num ( ) ;
2023-12-19 09:36:35 -05:00
TSharedPtr < FStatsGridRow > VertShaderRow = MakeShareable ( new FStatsGridRow_Shaders ( ( ERepresentativeShader ) i , bFirstShader , true ) ) ;
2018-05-23 21:04:31 -04:00
VertShaderRow - > CreateRow ( StatsManager ) ;
VertexShaderRows . Add ( VertShaderRow ) ;
2024-08-07 11:07:33 -04:00
TSharedPtr < FStatsGridRow > VertShaderRow2 = MakeShareable ( new FStatsGridRow_Shaders ( ( ERepresentativeShader ) i , false , false ) ) ;
VertShaderRow2 - > CreateRow ( StatsManager ) ;
VertexShaderRows . Add ( VertShaderRow2 ) ;
2018-05-23 21:04:31 -04:00
}
}
}
void FMaterialStatsGrid : : BuildColumnInfo ( )
{
2023-09-15 05:04:46 -04:00
GridColumnContent . Empty ( ) ;
2018-05-23 21:04:31 -04:00
GridColumnContent . Add ( DescriptorColumnName , FColumnInfo ( ) ) ;
GridColumnContent . Add ( ShaderColumnName , FColumnInfo ( ) ) ;
2023-12-19 09:36:35 -05:00
GridColumnContent . Add ( ShaderStatisticColumnName , FColumnInfo ( ) ) ;
2018-05-23 21:04:31 -04:00
TSharedPtr < FMaterialStats > StatsManager = StatsManagerWPtr . Pin ( ) ;
if ( ! StatsManager . IsValid ( ) )
{
return ;
}
const auto & PlatformDB = StatsManager - > GetPlatformsDB ( ) ;
for ( auto PlatformPair : PlatformDB )
{
if ( ! PlatformPair . Value - > IsPresentInGrid ( ) )
{
continue ;
}
for ( int32 q = 0 ; q < EMaterialQualityLevel : : Num ; + + q )
{
auto QualityLevel = static_cast < EMaterialQualityLevel : : Type > ( q ) ;
if ( ! StatsManager - > GetStatsQualityFlag ( QualityLevel ) )
{
continue ;
}
2023-09-15 05:04:46 -04:00
const int32 NumInstances = PlatformPair . Value - > GetPlatformData ( QualityLevel ) . Instances . Num ( ) ;
// skip all derived MI's if not asked to show stats as errors are shown separately
const int32 IterateForNum = StatsManager - > GetMaterialStatsDerivedMIOption ( ) = = EMaterialStatsDerivedMIOption : : ShowStats ? NumInstances : FMath : : Min ( 1 , NumInstances ) ;
for ( int32 InstanceIndex = 0 ; InstanceIndex < IterateForNum ; + + InstanceIndex )
{
AddColumnInfo ( PlatformPair . Value , QualityLevel , InstanceIndex ) ;
}
2018-05-23 21:04:31 -04:00
}
}
}
void FMaterialStatsGrid : : BuildGrid ( )
{
CollectShaderInfo ( ) ;
BuildStaticRows ( ) ;
BuildShaderRows ( ) ;
BuildColumnInfo ( ) ;
CheckForErrors ( ) ;
BuildRowIds ( ) ;
}
2023-09-15 05:04:46 -04:00
void FMaterialStatsGrid : : AddColumnInfo ( TSharedPtr < FShaderPlatformSettings > PlatformPtr , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
FColumnInfo Info ;
Info . Color = FMaterialStatsUtils : : PlatformTypeColor ( PlatformPtr - > GetCategoryType ( ) ) ;
Info . Content = PlatformPtr - > GetPlatformName ( ) . ToString ( ) ;
Info . ContentLong = PlatformPtr - > GetPlatformDescription ( ) ;
2023-09-15 05:04:46 -04:00
const FName ColumnName = MakePlatformColumnName ( PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
GridColumnContent . Add ( ColumnName , Info ) ;
}
2023-09-15 05:04:46 -04:00
void FMaterialStatsGrid : : RemoveColumnInfo ( TSharedPtr < FShaderPlatformSettings > PlatformPtr , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
2023-09-15 05:04:46 -04:00
const FName ColumnName = MakePlatformColumnName ( PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
GridColumnContent . Remove ( ColumnName ) ;
}
2023-09-15 05:04:46 -04:00
void FMaterialStatsGrid : : AddOrRemovePlatform ( TSharedPtr < FShaderPlatformSettings > PlatformPtr , const bool bAdd , const EMaterialQualityLevel : : Type QualityLevel , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
TSharedPtr < FMaterialStats > StatsManager = StatsManagerWPtr . Pin ( ) ;
if ( ! StatsManager . IsValid ( ) )
{
return ;
}
// update column record
if ( bAdd )
{
2023-09-15 05:04:46 -04:00
AddColumnInfo ( PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
}
else
{
2023-09-15 05:04:46 -04:00
RemoveColumnInfo ( PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
}
for ( auto RowPair : StaticRows )
{
if ( bAdd )
{
2023-09-15 05:04:46 -04:00
RowPair . Value - > AddPlatform ( StatsManager , PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
}
else
{
2023-09-15 05:04:46 -04:00
RowPair . Value - > RemovePlatform ( StatsManager , PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
}
}
for ( int32 i = 0 ; i < VertexShaderRows . Num ( ) ; + + i )
{
if ( bAdd )
{
2023-09-15 05:04:46 -04:00
VertexShaderRows [ i ] - > AddPlatform ( StatsManager , PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
}
else
{
2023-09-15 05:04:46 -04:00
VertexShaderRows [ i ] - > RemovePlatform ( StatsManager , PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
}
}
for ( int32 i = 0 ; i < FragmentShaderRows . Num ( ) ; + + i )
{
if ( bAdd )
{
2023-09-15 05:04:46 -04:00
FragmentShaderRows [ i ] - > AddPlatform ( StatsManager , PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
}
else
{
2023-09-15 05:04:46 -04:00
FragmentShaderRows [ i ] - > RemovePlatform ( StatsManager , PlatformPtr , QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
}
}
}
void FMaterialStatsGrid : : OnAddOrRemovePlatform ( TSharedPtr < FShaderPlatformSettings > PlatformPtr )
{
bool bAdded = PlatformPtr - > IsPresentInGrid ( ) ;
TSharedPtr < FMaterialStats > StatsManager = StatsManagerWPtr . Pin ( ) ;
if ( ! StatsManager . IsValid ( ) )
{
return ;
}
for ( int32 q = 0 ; q < EMaterialQualityLevel : : Num ; + + q )
{
auto QualityLevel = static_cast < EMaterialQualityLevel : : Type > ( q ) ;
if ( ! StatsManager - > GetStatsQualityFlag ( QualityLevel ) )
{
continue ;
}
2023-09-15 05:04:46 -04:00
for ( int32 InstanceIndex = 0 ; InstanceIndex < PlatformPtr - > GetPlatformData ( QualityLevel ) . Instances . Num ( ) ; + + InstanceIndex )
{
AddOrRemovePlatform ( PlatformPtr , bAdded , QualityLevel , InstanceIndex ) ;
}
2018-05-23 21:04:31 -04:00
}
// recheck shader rows in case something changed
OnShaderChanged ( ) ;
}
void FMaterialStatsGrid : : OnQualitySettingChanged ( const EMaterialQualityLevel : : Type QualityLevel )
{
TSharedPtr < FMaterialStats > StatsManager = StatsManagerWPtr . Pin ( ) ;
if ( ! StatsManager . IsValid ( ) )
return ;
2024-01-17 11:31:40 -05:00
const bool bQualityOn = StatsManager - > GetStatsQualityFlag ( QualityLevel ) ;
2018-05-23 21:04:31 -04:00
const auto & PlatformDB = StatsManager - > GetPlatformsDB ( ) ;
for ( auto PlatformPair : PlatformDB )
{
if ( PlatformPair . Value - > IsPresentInGrid ( ) )
{
2023-09-15 05:04:46 -04:00
for ( int32 InstanceIndex = 0 ; InstanceIndex < PlatformPair . Value - > GetPlatformData ( QualityLevel ) . Instances . Num ( ) ; + + InstanceIndex )
{
AddOrRemovePlatform ( PlatformPair . Value , bQualityOn , QualityLevel , InstanceIndex ) ;
}
2018-05-23 21:04:31 -04:00
}
}
// recheck shader rows in case something changed
OnShaderChanged ( ) ;
}
2023-09-15 05:04:46 -04:00
FName FMaterialStatsGrid : : MakePlatformColumnName ( const TSharedPtr < FShaderPlatformSettings > & Platform , const EMaterialQualityLevel : : Type Quality , const int32 InstanceIndex )
2018-05-23 21:04:31 -04:00
{
2023-09-15 05:04:46 -04:00
FName RetName = * ( Platform - > GetPlatformID ( ) . ToString ( ) + " _ " + FMaterialStatsUtils : : MaterialQualityToString ( Quality ) + " _ " + FString : : FromInt ( InstanceIndex ) ) ;
2018-05-23 21:04:31 -04:00
return RetName ;
}
/*end FShaderStatsGrid functions*/
/***********************************************************************************************************************/
/***********************************************************************************************************************/
/* FGridCell functions */
FGridCell : : FGridCell ( )
{
2021-02-16 15:32:41 -04:00
CellColor = FStyleColors : : Foreground ;
2018-05-23 21:04:31 -04:00
}
FString FGridCell_Empty : : GetCellContent ( )
{
return TEXT ( " " ) ;
}
FString FGridCell_Empty : : GetCellContentLong ( )
{
return TEXT ( " " ) ;
}
FGridCell_StaticString : : FGridCell_StaticString ( const FString & _Content , const FString & _ContentLong )
{
Content = _Content ;
ContentLong = _ContentLong ;
}
FString FGridCell_StaticString : : GetCellContent ( )
{
return Content ;
}
FString FGridCell_StaticString : : GetCellContentLong ( )
{
return ContentLong ;
}
FGridCell_ShaderValue : : FGridCell_ShaderValue ( const TWeakPtr < FMaterialStats > & _MaterialStatsWPtr , const EShaderInfoType _InfoType , const ERepresentativeShader _ShaderType ,
2023-09-15 05:04:46 -04:00
const EMaterialQualityLevel : : Type _QualityLevel , const EShaderPlatform _PlatformType , const int32 _InstanceIndex )
2018-05-23 21:04:31 -04:00
{
MaterialStatsWPtr = _MaterialStatsWPtr ;
InfoType = _InfoType ;
ShaderType = _ShaderType ;
QualityLevel = _QualityLevel ;
PlatformType = _PlatformType ;
2023-09-15 05:04:46 -04:00
InstanceIndex = _InstanceIndex ;
2018-05-23 21:04:31 -04:00
}
FString FGridCell_ShaderValue : : InternalGetContent ( bool bLongContent )
{
auto MaterialStats = MaterialStatsWPtr . Pin ( ) ;
if ( ! MaterialStats . IsValid ( ) )
{
return TEXT ( " " ) ;
}
auto Platform = MaterialStats - > GetPlatformSettings ( PlatformType ) ;
2023-09-15 05:04:46 -04:00
if ( ! Platform . IsValid ( ) | | Platform - > GetPlatformData ( QualityLevel ) . Instances . Num ( ) < = InstanceIndex )
2018-05-23 21:04:31 -04:00
{
return TEXT ( " " ) ;
}
2023-09-15 05:04:46 -04:00
const auto & InstanceData = Platform - > GetInstanceData ( QualityLevel , InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
switch ( InfoType )
{
2023-09-15 05:04:46 -04:00
case EShaderInfoType : : Name :
return MaterialStats - > GetMaterialName ( InstanceIndex ) ;
2018-05-23 21:04:31 -04:00
break ;
case EShaderInfoType : : InstructionsCount :
{
2023-09-15 05:04:46 -04:00
auto * Count = InstanceData . ShaderStatsInfo . ShaderInstructionCount . Find ( ShaderType ) ;
2018-05-23 21:04:31 -04:00
if ( Count )
{
return bLongContent ? Count - > StrDescriptionLong : Count - > StrDescription ;
}
}
break ;
2023-12-19 09:36:35 -05:00
case EShaderInfoType : : GenericShaderStatistics :
{
auto * Count = InstanceData . ShaderStatsInfo . GenericShaderStatistics . Find ( ShaderType ) ;
if ( Count )
{
return bLongContent ? Count - > StrDescriptionLong : Count - > StrDescription ;
}
}
break ;
2018-05-23 21:04:31 -04:00
case EShaderInfoType : : InterpolatorsCount :
2023-09-15 05:04:46 -04:00
return bLongContent ? InstanceData . ShaderStatsInfo . InterpolatorsCount . StrDescriptionLong : InstanceData . ShaderStatsInfo . InterpolatorsCount . StrDescription ;
2018-05-23 21:04:31 -04:00
break ;
case EShaderInfoType : : TextureSampleCount :
2023-09-15 05:04:46 -04:00
return bLongContent ? InstanceData . ShaderStatsInfo . TextureSampleCount . StrDescriptionLong : InstanceData . ShaderStatsInfo . TextureSampleCount . StrDescription ;
2018-05-23 21:04:31 -04:00
break ;
case EShaderInfoType : : SamplersCount :
2023-09-15 05:04:46 -04:00
return bLongContent ? InstanceData . ShaderStatsInfo . SamplersCount . StrDescriptionLong : InstanceData . ShaderStatsInfo . SamplersCount . StrDescription ;
2018-05-23 21:04:31 -04:00
break ;
2019-06-11 18:27:07 -04:00
case EShaderInfoType : : VirtualTextureLookupCount :
2023-09-15 05:04:46 -04:00
return bLongContent ? InstanceData . ShaderStatsInfo . VirtualTextureLookupCount . StrDescriptionLong : InstanceData . ShaderStatsInfo . VirtualTextureLookupCount . StrDescription ;
2019-06-11 18:27:07 -04:00
break ;
2021-03-03 16:24:00 -04:00
case EShaderInfoType : : ShaderCount :
2023-09-15 05:04:46 -04:00
return bLongContent ? InstanceData . ShaderStatsInfo . ShaderCount . StrDescriptionLong : InstanceData . ShaderStatsInfo . ShaderCount . StrDescription ;
2021-03-03 16:24:00 -04:00
break ;
2023-12-21 11:47:27 -05:00
case EShaderInfoType : : PreShaderCount :
return bLongContent ? InstanceData . ShaderStatsInfo . PreShaderCount . StrDescriptionLong : InstanceData . ShaderStatsInfo . PreShaderCount . StrDescription ;
break ;
2024-01-09 12:32:53 -05:00
case EShaderInfoType : : LWCUsage :
return bLongContent ? InstanceData . ShaderStatsInfo . LWCUsage . StrDescriptionLong : InstanceData . ShaderStatsInfo . LWCUsage . StrDescription ;
break ;
2018-05-23 21:04:31 -04:00
}
return TEXT ( " " ) ;
}
FString FGridCell_ShaderValue : : GetCellContent ( )
{
return InternalGetContent ( false ) ;
}
FString FGridCell_ShaderValue : : GetCellContentLong ( )
{
return InternalGetContent ( true ) ;
}
2023-09-15 05:04:46 -04:00
FGridCell : : EIcon FGridCell_ShaderValue : : GetIcon ( ) const
{
auto MaterialStats = MaterialStatsWPtr . Pin ( ) ;
if ( ! MaterialStats . IsValid ( ) )
{
return EIcon : : None ;
}
auto Platform = MaterialStats - > GetPlatformSettings ( PlatformType ) ;
if ( ! Platform . IsValid ( ) | | Platform - > GetPlatformData ( QualityLevel ) . Instances . Num ( ) < = InstanceIndex )
{
return EIcon : : None ;
}
const auto & InstanceData = Platform - > GetInstanceData ( QualityLevel , InstanceIndex ) ;
switch ( InfoType )
{
case EShaderInfoType : : Name :
return InstanceData . MaterialResourcesStats - > GetCompileErrors ( ) . Num ( ) > 0 ? EIcon : : Error : EIcon : : None ;
default :
return EIcon : : None ;
}
}