MCPcopy Create free account
hub / github.com/carbonengine/trinity / CreateGlobalsCB

Function CreateGlobalsCB

shadercompiler/ParserUtils.cpp:953–1041  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

951}
952
953void CreateGlobalsCB( ParserState& state )
954{
955 ZoneScoped;
956
957 auto root = state.GetTree();
958 if( !root )
959 {
960 return;
961 }
962 SortProgramNodes( root );
963 size_t varStart = root->GetChildrenCount();
964 size_t varEnd = 0;
965 for( size_t i = 0; i < root->GetChildrenCount(); ++i )
966 {
967 auto child = root->GetChild( i );
968 if( !child )
969 {
970 continue;
971 }
972 if( child->GetNodeType() == NT_VAR_DECLARATION_LIST )
973 {
974 if( auto name = child->GetChildOrNull( 0 ) )
975 {
976 if( name->GetNodeType() == NT_CBUFFER )
977 {
978 continue;
979 }
980 }
981 if( auto name = child->GetChildOrNull( 1 ) )
982 {
983 if( name->GetNodeType() == NT_CBUFFER )
984 {
985 continue;
986 }
987 }
988 if( !GetRegisterType( child->GetType() ) )
989 {
990 varStart = std::min( varStart, i );
991 varEnd = std::max( varEnd, i );
992 }
993 }
994 }
995 if( varStart <= varEnd )
996 {
997 ScannerToken token;
998 token.fileLocation = root->GetLocation();
999 token.intValue = 0;
1000 token.stringValue = MakeInlineString( "cbuffer" );
1001 token.type = OP_CBUFFER;
1002 ASTNode* cbuffer = new ASTNode( NT_CBUFFER, root->GetLocation(), root->GetScope(), &token );
1003
1004 Symbol* cbufferName = state.GetSymbolTable().AddBufferSymbol( MakeInlineString( "Globals" ) );
1005 RegisterSpecifier reg;
1006 reg.registerNumber = 0;
1007 reg.registerType = 'b';
1008 reg.shaderProfile.start = nullptr;
1009 reg.shaderProfile.end = nullptr;
1010 reg.subComponent = -1;

Callers 1

CompileEffectMethod · 0.85

Calls 15

SortProgramNodesFunction · 0.85
MakeInlineStringFunction · 0.85
swapFunction · 0.85
GetTreeMethod · 0.80
GetChildrenCountMethod · 0.80
GetNodeTypeMethod · 0.80
GetChildOrNullMethod · 0.80
GetScopeMethod · 0.80
AddBufferSymbolMethod · 0.80
SetSymbolMethod · 0.80
AddChildMethod · 0.80
RemoveChildMethod · 0.80

Tested by

no test coverage detected