Patches VPOS usages for pixel shaders: a common Dx9 legacy pattern of passing both POSITION (from vertex shader) and VPOS. Function remaps VPOS inputs to POSION so that there are no duplicate semantics in the stage_in struct.
| 2502 | // vertex shader) and VPOS. Function remaps VPOS inputs to POSION so that there are no duplicate semantics |
| 2503 | // in the stage_in struct. |
| 2504 | bool PatchVpos( ParserState& state, ASTNode* inputsStruct, std::vector<ASTNode*>& argumentAccessors ) |
| 2505 | { |
| 2506 | Type float4 = TypeFromTokenType( OP_FLOAT ); |
| 2507 | float4.width = 4; |
| 2508 | |
| 2509 | // First find POSITION input |
| 2510 | ASTNode* position = nullptr; |
| 2511 | size_t positionIndex = 0; |
| 2512 | for( size_t index = 0; index < inputsStruct->GetChildrenCount(); ++index ) |
| 2513 | { |
| 2514 | auto child = inputsStruct->GetChild( index ); |
| 2515 | auto member = child->GetChild( 0 ); |
| 2516 | if( IEquals( member->GetSymbol()->semantic, "SV_Position" ) || IEquals( member->GetSymbol()->semantic, "POSITION" ) || IEquals( member->GetSymbol()->semantic, "POSITION0" ) ) |
| 2517 | { |
| 2518 | if( child->GetType() != float4 ) |
| 2519 | { |
| 2520 | state.ShowMessage( EC_CUSTOM_ERROR, "Pixel shader %s input needs to be a float4", ToString( member->GetSymbol()->semantic ).c_str() ); |
| 2521 | return false; |
| 2522 | } |
| 2523 | position = child; |
| 2524 | positionIndex = index; |
| 2525 | break; |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | // Find any other POSITION/VPOS inputs and remap them to the first POSITION |
| 2530 | for( size_t index = 0; index < inputsStruct->GetChildrenCount(); ++index ) |
| 2531 | { |
| 2532 | auto child = inputsStruct->GetChild( index ); |
| 2533 | if( child == position ) |
| 2534 | { |
| 2535 | continue; |
| 2536 | } |
| 2537 | auto member = child->GetChild( 0 ); |
| 2538 | if( IEquals( member->GetSymbol()->semantic, "SV_Position" ) || IEquals( member->GetSymbol()->semantic, "POSITION" ) || IEquals( member->GetSymbol()->semantic, "POSITION0" ) || IEquals( member->GetSymbol()->semantic, "VPOS" ) ) |
| 2539 | { |
| 2540 | if( !child->GetType().IsScalarOrVector() || child->GetType().builtInType != OP_FLOAT ) |
| 2541 | { |
| 2542 | state.ShowMessage( EC_CUSTOM_ERROR, "Pixel shader %s input needs to be a float vector", ToString( member->GetSymbol()->semantic ).c_str() ); |
| 2543 | return false; |
| 2544 | } |
| 2545 | if( position ) |
| 2546 | { |
| 2547 | if( position->GetType() != child->GetType() ) |
| 2548 | { |
| 2549 | const char* swizzles = "xyzw"; |
| 2550 | argumentAccessors[index] = NewDot( state, |
| 2551 | argumentAccessors[positionIndex]->Copy(), |
| 2552 | MakeInlineString( swizzles, swizzles + 4 - child->GetType().width ) ); |
| 2553 | } |
| 2554 | else |
| 2555 | { |
| 2556 | argumentAccessors[index] = argumentAccessors[positionIndex]->Copy(); |
| 2557 | } |
| 2558 | inputsStruct->RemoveChild( index ); |
| 2559 | --index; |
| 2560 | } |
| 2561 | else if( child->GetType().width != 4 ) |
no test coverage detected