| 2252 | } |
| 2253 | |
| 2254 | void 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 | } |
no test coverage detected