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

Function CollectConstants

shadercompiler/EffectCompilerMetal.cpp:3551–3706  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3549}
3550
3551bool CollectConstants( ParserState& state, StageData& stage, ASTNode* node, std::map<StringReference, ParameterAnnotation>& annotations )
3552{
3553 assert( node->GetNodeType() == NT_STRUCT );
3554
3555 size_t offset = 0;
3556
3557 for( auto memberNode : node->GetChildren() )
3558 {
3559 assert( memberNode && memberNode->GetNodeType() == NT_STRUCT_MEMBER );
3560
3561 for( auto childNode : memberNode->GetChildren() )
3562 {
3563 assert( childNode && childNode->GetNodeType() == NT_NAME_DECLARATION );
3564
3565 Symbol* symbol = childNode->GetSymbol();
3566 assert( symbol );
3567
3568 if( !symbol->used )
3569 {
3570 continue;
3571 }
3572
3573 const Type& type = symbol->type;
3574
3575 // Multi-dimensional arrays are not supported yet.
3576 assert( type.arrayDimensions <= 1 );
3577
3578 size_t size = 0;
3579 CalculateSizeAndOffset( type, size, offset );
3580
3581 int elementCount = 1;
3582 for( int i = 0; i < type.arrayDimensions; ++i )
3583 {
3584 elementCount *= type.arraySizes[i];
3585 }
3586
3587 // Note: This calculation is correct only when type can be tightly packed in an array,
3588 // i.e. type size divisible by alignment.
3589 size *= elementCount;
3590
3591 Constant constant;
3592 constant.name = g_stringTable.AddString( symbol->name );
3593 constant.offset = (uint32_t)offset;
3594 constant.size = (uint32_t)size;
3595
3596 offset += size;
3597
3598 switch( type.builtInType )
3599 {
3600 case OP_FLOAT:
3601 constant.type = CONSTANT_TYPE_FLOAT;
3602 break;
3603 case OP_INT:
3604 constant.type = CONSTANT_TYPE_INT;
3605 break;
3606 case OP_UINT:
3607 case OP_BINDLESSHANDLETEXTURE2D:
3608 case OP_BINDLESSHANDLETEXTURE3D:

Callers 1

GetStageDataFunction · 0.85

Calls 15

CalculateSizeAndOffsetFunction · 0.85
FillDefaultsFunction · 0.85
BindlessTextureTypeFunction · 0.85
GetSamplerStateFunction · 0.85
MakeInlineStringFunction · 0.85
GetNodeTypeMethod · 0.80
GetSymbolMethod · 0.80
AddStringMethod · 0.80
sizeMethod · 0.80
GetChildOrNullMethod · 0.80
GetChildrenCountMethod · 0.80
ShowMessageMethod · 0.80

Tested by

no test coverage detected