Skip to content

Commit

Permalink
Expose few compiler flags
Browse files Browse the repository at this point in the history
  • Loading branch information
SCell555 committed Oct 28, 2020
1 parent 600628c commit 7e57850
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 94 deletions.
49 changes: 26 additions & 23 deletions ShaderCompile/ShaderCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,29 +876,6 @@ void CWorkerAccumState<TMutexType>::RangeFinished()
TryToPackageData( m_iEndCommand - 1 );
}

template <size_t N>
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 <Threading::Mutex TMutexType>
void CWorkerAccumState<TMutexType>::ExecuteCompileCommandThreaded( CfgProcessor::ComboHandle hCombo )
{
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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<std::string> badOptions;
if ( !cmdLine.gotRequired( badOptions ) || cmdLine.lastArgs.size() != 1 )
{
Expand Down
71 changes: 0 additions & 71 deletions ShaderCompile/strmanip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,80 +72,9 @@ static inline std::_Smanip<int64_t> 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<int>( 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

0 comments on commit 7e57850

Please sign in to comment.