| 2375 | } |
| 2376 | |
| 2377 | void 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 | } |
no test coverage detected