diff --git a/ShaderCompile/ShaderCompile.cpp b/ShaderCompile/ShaderCompile.cpp index 14ee664..c47f142 100644 --- a/ShaderCompile/ShaderCompile.cpp +++ b/ShaderCompile/ShaderCompile.cpp @@ -876,29 +876,6 @@ void CWorkerAccumState::RangeFinished() TryToPackageData( m_iEndCommand - 1 ); } -template -static __forceinline void PrepareFlagsForSubprocess( char ( &pBuf )[N] ) -{ - if ( gFlags & D3DCOMPILE_PARTIAL_PRECISION ) - strcat_s( pBuf, "/Gpp " ); - - if ( gFlags & D3DCOMPILE_SKIP_VALIDATION ) - strcat_s( pBuf, "/Vd " ); - - if ( gFlags & D3DCOMPILE_NO_PRESHADER ) - strcat_s( pBuf, "/Op " ); - - if ( gFlags & D3DCOMPILE_AVOID_FLOW_CONTROL ) - strcat_s( pBuf, "/Gfa " ); - else if ( gFlags & D3DCOMPILE_PREFER_FLOW_CONTROL ) - strcat_s( pBuf, "/Gfp " ); - - if ( gFlags & D3DCOMPILE_SKIP_OPTIMIZATION ) - strcat_s( pBuf, "/Od" ); - - V_StrTrim( pBuf ); -} - template void CWorkerAccumState::ExecuteCompileCommandThreaded( CfgProcessor::ComboHandle hCombo ) { @@ -1557,6 +1534,8 @@ int main( int argc, const char* argv[] ) cmdLine.add( "", false, 0, 0, "Directs the compiler to not use flow-control constructs where possible", "/Gfa", "-no-flow-control" ); cmdLine.add( "", false, 0, 0, "Directs the compiler to use flow-control constructs where possible", "/Gfp", "-prefer-flow-control" ); cmdLine.add( "", false, 0, 0, "Disables shader optimization", "/Od", "-disable-optimization" ); + cmdLine.add( "", false, 0, 0, "Enable debugging information", "/Zi", "-debug-info" ); + cmdLine.add( "1", false, 1, 0, "Set optimization level (0-3)", "/O", "-optimize" ); cmdLine.parse( argc, argv ); @@ -1595,6 +1574,30 @@ int main( int argc, const char* argv[] ) if ( cmdLine.isSet( "/Od" ) ) gFlags |= D3DCOMPILE_SKIP_OPTIMIZATION; + if ( cmdLine.isSet( "/Zi" ) ) + gFlags |= D3DCOMPILE_DEBUG; + + int optLevel = 1; + cmdLine.get( "/O" )->getInt( optLevel ); + switch ( optLevel ) + { + case 0: + gFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL0; + break; + default: + std::cout << "Unknown optimization level " << optLevel << ", using default!" << std::endl; + [[fallthrough]]; + case 1: + gFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL1; + break; + case 2: + gFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL2; + break; + case 3: + gFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL3; + break; + } + std::vector badOptions; if ( !cmdLine.gotRequired( badOptions ) || cmdLine.lastArgs.size() != 1 ) { diff --git a/ShaderCompile/strmanip.hpp b/ShaderCompile/strmanip.hpp index 02a4fa9..1ba05ee 100644 --- a/ShaderCompile/strmanip.hpp +++ b/ShaderCompile/strmanip.hpp @@ -72,80 +72,9 @@ static inline std::_Smanip FormatTimeShort( int64_t i ) return { __FormatTime2, i }; } -static __forceinline bool PATHSEPARATOR( char c ) -{ - return c == '\\' || c == '/'; -} - -static inline const char* V_GetFileExtension( const char* path ) -{ - const char* src = path + ( strlen( path ) - 1 ); - - while ( src != path && *( src - 1 ) != '.' ) - src--; - - if ( src == path || PATHSEPARATOR( *src ) ) - return nullptr; // no extension - - return src; -} - static __forceinline bool V_IsAbsolutePath( const char* pStr ) { return ( pStr[0] && pStr[1] == ':' ) || pStr[0] == '/' || pStr[0] == '\\'; } -static inline void V_StripFilename( char* path ) -{ - int length = static_cast( strlen( path ) ) - 1; - if ( length <= 0 ) - return; - - while ( length > 0 && !PATHSEPARATOR( path[length] ) ) - length--; - - path[length] = 0; -} - -static inline void V_FixSlashes( char* pname, char separator = '\\' ) -{ - while ( *pname ) - { - if ( *pname == '/' || *pname == '\\' ) - *pname = separator; - pname++; - } -} - -static inline void V_StrTrim( char* pStr ) -{ - char* pSource = pStr; - char* pDest = pStr; - - // skip white space at the beginning - while ( *pSource != 0 && isspace( *pSource ) ) - pSource++; - - // copy everything else - char* pLastWhiteBlock = nullptr; - while ( *pSource != 0 ) - { - *pDest = *pSource++; - if ( isspace( *pDest ) ) - { - if ( pLastWhiteBlock == nullptr ) - pLastWhiteBlock = pDest; - } - else - pLastWhiteBlock = nullptr; - pDest++; - } - *pDest = 0; - - // did we end in a whitespace block? - if ( pLastWhiteBlock != nullptr ) - // yep; shorten the string - *pLastWhiteBlock = 0; -} - #endif // STRMANIP_HPP \ No newline at end of file