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

Function GatherSystemInputs

shadercompiler/EffectCompilerMetal.cpp:2377–2446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2375}
2376
2377void GatherSystemInputs( ASTNode* destStruct, std::vector<ASTNode*>& accessors, std::vector<ASTNode*>& argumentAccessors, const std::vector<Symbol*>& params, ASTNode* header, ASTNode* shaderBody, ParserState& state )
2378{
2379 for( size_t i = 0; i < header->GetChildrenCount(); ++i )
2380 {
2381 auto arg = header->GetChild( i );
2382
2383 if( IsUniformInputArgument( arg ) || arg->GetSymbol()->addressSpace != AddressSpace::None )
2384 {
2385 continue;
2386 }
2387 bool isIn = arg->GetToken() == 0 || arg->GetToken()->type == OP_IN;
2388 if( !isIn )
2389 {
2390 continue;
2391 }
2392
2393 Symbol* symbol = arg->GetSymbol();
2394 if( !symbol )
2395 {
2396 continue;
2397 }
2398
2399 if( HasSystemRegister( symbol ) )
2400 {
2401 // subtract base_vertex from vertex_id to match dx12 behaviour for SV_VertexID
2402 if( symbol->semantic == "SV_VertexID" )
2403 {
2404 auto param = NewFunctionParameter( state, hlsl::uint_t );
2405 param->GetSymbol()->registerSpecifier[{}] = MetalSystemSemantics( MetalSystemSemanticsType::Enum::base_vertex );
2406 destStruct->AddChild( param );
2407
2408 auto assignment = NewBinaryExpression(
2409 state,
2410 OP_SUB_ASSIGN,
2411 NewVarIdentifier( state, header->GetChild( i )->GetSymbol() ),
2412 NewVarIdentifier( state, param->GetSymbol() ) );
2413 ASTNode* node = NewExpressionStatement( state, assignment );
2414 shaderBody->AddChild( node );
2415 }
2416
2417 // subtract base_instance from instance_id to match dx12 behaviour for SV_InstanceID
2418 if( symbol->semantic == "SV_InstanceID" )
2419 {
2420 auto param = NewFunctionParameter( state, hlsl::uint_t );
2421 param->GetSymbol()->registerSpecifier[{}] = MetalSystemSemantics( MetalSystemSemanticsType::Enum::base_instance );
2422 destStruct->AddChild( param );
2423
2424 auto assignment = NewBinaryExpression(
2425 state,
2426 OP_SUB_ASSIGN,
2427 NewVarIdentifier( state, header->GetChild( i )->GetSymbol() ),
2428 NewVarIdentifier( state, param->GetSymbol() ) );
2429 ASTNode* node = NewExpressionStatement( state, assignment );
2430 shaderBody->AddChild( node );
2431 }
2432
2433 continue;
2434 }

Callers 1

PatchShaderFunction · 0.85

Calls 14

IsUniformInputArgumentFunction · 0.85
HasSystemRegisterFunction · 0.85
NewFunctionParameterFunction · 0.85
MetalSystemSemanticsFunction · 0.85
NewBinaryExpressionFunction · 0.85
NewVarIdentifierFunction · 0.85
NewExpressionStatementFunction · 0.85
GatherSystemFieldsFunction · 0.85
GetChildrenCountMethod · 0.80
GetSymbolMethod · 0.80
GetTokenMethod · 0.80
AddChildMethod · 0.80

Tested by

no test coverage detected