@@ -903,6 +903,34 @@ void HLSL2GLSLConverterImpl::ConversionStream::ParseGlobalPreprocessorDefines()
903903 }
904904}
905905
906+ HLSL2GLSLConverterImpl::TokenListType::iterator HLSL2GLSLConverterImpl::ConversionStream::FindMacroDefinition (const std::string& MacroName)
907+ {
908+ auto define_it = m_PreprocessorDefinitions.find (MacroName.c_str ());
909+ if (define_it == m_PreprocessorDefinitions.end ())
910+ return m_Tokens.end ();
911+
912+ auto Token = define_it->second ;
913+ // #define PS_OUTPUT PSOutput
914+ // ^
915+
916+ ++Token;
917+ // #define PS_OUTPUT PSOutput
918+ // ^
919+ if (Token == m_Tokens.end () || Token->Literal != MacroName)
920+ return m_Tokens.end ();
921+
922+ ++Token;
923+ // #define PS_OUTPUT PSOutput
924+ // ^
925+
926+ // Check that the definition is on the same line (we don't handle multiline definitions)
927+ if (Token == m_Tokens.end () || Token->Delimiter .find_first_of (" \r\n " ) != std::string::npos)
928+ return m_Tokens.end ();
929+
930+ return (Token->IsBuiltInType () || Token->Type == TokenType::Identifier) ? Token : m_Tokens.end ();
931+ }
932+
933+
906934// The function replaces cbuffer with uniform and adds semicolon if it is missing after the closing brace:
907935// cbuffer
908936// {
@@ -2403,6 +2431,14 @@ void HLSL2GLSLConverterImpl::ConversionStream::ParseShaderParameter(TokenListTyp
24032431
24042432 if (!TypeToken->IsBuiltInType ())
24052433 {
2434+ {
2435+ auto DefinedTypeToken = FindMacroDefinition (TypeToken->Literal );
2436+ // Check that the define directive is before the type token
2437+ if (DefinedTypeToken != m_Tokens.end () && DefinedTypeToken->Idx < TypeToken->Idx )
2438+ {
2439+ TypeToken = DefinedTypeToken;
2440+ }
2441+ }
24062442 const auto & StructName = TypeToken->Literal ;
24072443 auto it = m_StructDefinitions.find (StructName.c_str ());
24082444 if (it == m_StructDefinitions.end ())
@@ -2459,38 +2495,15 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessFunctionParameters(TokenLi
24592495
24602496 auto ActualTypeToken = TypeToken;
24612497 {
2462- // PS_OUTPUT TestPS ( in VSOutput In,
2463-
2464- auto define_it = m_PreprocessorDefinitions.find (ActualTypeToken->Literal .c_str ());
2465- if (define_it != m_PreprocessorDefinitions.end ())
2498+ auto DefinedTypeToken = FindMacroDefinition (TypeToken->Literal );
2499+ // Check that the define directive is before the type token
2500+ if (DefinedTypeToken != m_Tokens.end () && DefinedTypeToken->Idx < TypeToken->Idx )
24662501 {
2467- auto DefinedTypeToken = define_it->second ;
2468- // #define PS_OUTPUT PSOutput
2502+ // PS_OUTPUT TestPS ( in VSOutput In,
24692503 // ^
2470- // DefinedTypeToken
2471-
2472- // Check that the define directive is before the type token
2473- if (DefinedTypeToken->Idx < TypeToken->Idx )
2474- {
2475- ++DefinedTypeToken;
2476- // #define PS_OUTPUT PSOutput
2477- // ^
2478- // DefinedTypeToken
2479- if (DefinedTypeToken != m_Tokens.end () && DefinedTypeToken->Literal == TypeToken->Literal )
2480- {
2481- ++DefinedTypeToken;
2482- // #define PS_OUTPUT PSOutput
2483- // ^
2484- // DefinedTypeToken
2485- if (DefinedTypeToken != m_Tokens.end () &&
2486- // Check that the definition is on the same line (we don't handle backslash at the moment)
2487- DefinedTypeToken->Delimiter .find_first_of (" \r\n " ) == std::string::npos &&
2488- (DefinedTypeToken->IsBuiltInType () || DefinedTypeToken->Type == TokenType::Identifier))
2489- {
2490- ActualTypeToken = DefinedTypeToken;
2491- }
2492- }
2493- }
2504+ ActualTypeToken = DefinedTypeToken;
2505+ // #define PS_OUTPUT PSOutput
2506+ // ^
24942507 }
24952508 }
24962509
@@ -2755,7 +2768,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessFunctionParameters(TokenLi
27552768 else
27562769 {
27572770 // VSOut TestVS ()
2758- auto TmpTypeToken = ActualTypeToken ;
2771+ auto TmpTypeToken = TypeToken ;
27592772 ParseShaderParameter (TmpTypeToken, RetParam);
27602773 }
27612774 TypeToken->Type = TokenType::Identifier;
0 commit comments