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

Function GatherSystemFields

shadercompiler/EffectCompilerMetal.cpp:2254–2313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2252}
2253
2254void GatherSystemFields( ASTNode* destStruct, std::vector<ASTNode*>& accessors, std::vector<ASTNode*>& argumentAccessors, ASTNode* accessParent, ASTNode* sourceStruct, ASTNode* shaderBody, ParserState& state )
2255{
2256 for( auto member : sourceStruct->GetChildren() )
2257 {
2258 if( member->GetType().IsStruct() )
2259 {
2260 for( auto name : member->GetChildren() )
2261 {
2262 GatherSystemFields( destStruct, accessors, argumentAccessors, NewDot( state, accessParent->Copy(), name->GetSymbol() ), name->GetType().symbol->definition, shaderBody, state );
2263 }
2264 }
2265 else
2266 {
2267 for( auto name : member->GetChildren() )
2268 {
2269 auto it = s_systemSemantics.find( name->GetSymbol()->semantic );
2270 if( it != s_systemSemantics.end() )
2271 {
2272 auto param = NewFunctionParameter( state, name->GetType() );
2273 param->GetSymbol()->registerSpecifier[{}] = MetalSystemSemantics( it->second );
2274 destStruct->AddChild( param );
2275 argumentAccessors.push_back( NewVarIdentifier( state, param->GetSymbol() ) );
2276 accessors.push_back( NewDot( state, accessParent->Copy(), name->GetSymbol() ) );
2277
2278 // subtract base_vertex from vertex_id to match dx12 behaviour for SV_VertexID
2279 if( name->GetSymbol()->semantic == "SV_VertexID" )
2280 {
2281 auto base_param = NewFunctionParameter( state, hlsl::uint_t );
2282 base_param->GetSymbol()->registerSpecifier[{}] = MetalSystemSemantics( MetalSystemSemanticsType::Enum::base_vertex );
2283 destStruct->AddChild( base_param );
2284
2285 auto assignment = NewBinaryExpression(
2286 state,
2287 OP_SUB_ASSIGN,
2288 NewVarIdentifier( state, param->GetSymbol() ),
2289 NewVarIdentifier( state, base_param->GetSymbol() ) );
2290 ASTNode* node = NewExpressionStatement( state, assignment );
2291 shaderBody->AddChild( node );
2292 }
2293
2294 // subtract base_instance from instance_id to match dx12 behaviour for SV_InstanceID
2295 if( name->GetSymbol()->semantic == "SV_InstanceID" )
2296 {
2297 auto base_param = NewFunctionParameter( state, hlsl::uint_t );
2298 base_param->GetSymbol()->registerSpecifier[{}] = MetalSystemSemantics( MetalSystemSemanticsType::Enum::base_instance );
2299 destStruct->AddChild( base_param );
2300
2301 auto assignment = NewBinaryExpression(
2302 state,
2303 OP_SUB_ASSIGN,
2304 NewVarIdentifier( state, param->GetSymbol() ),
2305 NewVarIdentifier( state, base_param->GetSymbol() ) );
2306 ASTNode* node = NewExpressionStatement( state, assignment );
2307 shaderBody->AddChild( node );
2308 }
2309 }
2310 }
2311 }

Callers 1

GatherSystemInputsFunction · 0.85

Calls 12

NewDotFunction · 0.85
NewFunctionParameterFunction · 0.85
MetalSystemSemanticsFunction · 0.85
NewVarIdentifierFunction · 0.85
NewBinaryExpressionFunction · 0.85
NewExpressionStatementFunction · 0.85
IsStructMethod · 0.80
CopyMethod · 0.80
GetSymbolMethod · 0.80
AddChildMethod · 0.80
GetTypeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected