@ -101,7 +101,25 @@ namespace {
using namespace Containers : : Literals ;
using namespace Containers : : Literals ;
Containers : : StringView formatForExtension ( const char * prefix , const Containers : : StringView filename ) {
Containers : : StringView stringForFormat ( const Format format ) {
switch ( format ) {
# define _c(format) case Format::format: return #format ## _s;
_c ( Glsl )
_c ( Spirv )
_c ( SpirvAssembly )
_c ( Hlsl )
_c ( Msl )
_c ( Wgsl )
_c ( Dxil )
# undef _c
case Format : : Unspecified : return { } ;
}
CORRADE_INTERNAL_ASSERT_UNREACHABLE ( ) ; /* LCOV_EXCL_LINE */
}
Format formatForExtension ( const char * prefix , const Containers : : StringView filename ) {
/** @todo lowercase only the extension, once Directory::split() is done */
/** @todo lowercase only the extension, once Directory::split() is done */
const std : : string normalized = Utility : : String : : lowercase ( filename ) ;
const std : : string normalized = Utility : : String : : lowercase ( filename ) ;
@ -126,7 +144,7 @@ Containers::StringView formatForExtension(const char* prefix, const Containers::
Utility : : String : : endsWith ( normalized , " .asm.rcall " ) | |
Utility : : String : : endsWith ( normalized , " .asm.rcall " ) | |
Utility : : String : : endsWith ( normalized , " .asm.mesh " ) | |
Utility : : String : : endsWith ( normalized , " .asm.mesh " ) | |
Utility : : String : : endsWith ( normalized , " .asm.task " ) )
Utility : : String : : endsWith ( normalized , " .asm.task " ) )
return " SpirvAssembly " _s ;
return Format : : SpirvAssembly ;
/* https://github.com/KhronosGroup/glslang/blob/3ce148638bdc3807316e358dee4a5c9583189ae7/StandAlone/StandAlone.cpp#L260-L274 */
/* https://github.com/KhronosGroup/glslang/blob/3ce148638bdc3807316e358dee4a5c9583189ae7/StandAlone/StandAlone.cpp#L260-L274 */
else if ( Utility : : String : : endsWith ( normalized , " .glsl " ) | |
else if ( Utility : : String : : endsWith ( normalized , " .glsl " ) | |
Utility : : String : : endsWith ( normalized , " .vert " ) | |
Utility : : String : : endsWith ( normalized , " .vert " ) | |
@ -143,9 +161,9 @@ Containers::StringView formatForExtension(const char* prefix, const Containers::
Utility : : String : : endsWith ( normalized , " .rcall " ) | |
Utility : : String : : endsWith ( normalized , " .rcall " ) | |
Utility : : String : : endsWith ( normalized , " .mesh " ) | |
Utility : : String : : endsWith ( normalized , " .mesh " ) | |
Utility : : String : : endsWith ( normalized , " .task " ) )
Utility : : String : : endsWith ( normalized , " .task " ) )
return " Glsl " _s ;
return Format : : Glsl ;
else if ( Utility : : String : : endsWith ( normalized , " .spv " ) )
else if ( Utility : : String : : endsWith ( normalized , " .spv " ) )
return " Spirv " _s ;
return Format : : Spirv ;
Error { } < < prefix < < " cannot determine the format of " < < filename ;
Error { } < < prefix < < " cannot determine the format of " < < filename ;
return { } ;
return { } ;
@ -156,9 +174,15 @@ Containers::StringView formatForExtension(const char* prefix, const Containers::
std : : pair < bool , Containers : : String > AnyConverter : : doValidateFile ( const Stage stage , const Containers : : StringView filename ) {
std : : pair < bool , Containers : : String > AnyConverter : : doValidateFile ( const Stage stage , const Containers : : StringView filename ) {
CORRADE_INTERNAL_ASSERT ( manager ( ) ) ;
CORRADE_INTERNAL_ASSERT ( manager ( ) ) ;
/* Decide on a plugin name based on the extension */
/* Prefer the explicitly set input format. If not set, fall back to
const Containers : : StringView format = formatForExtension ( " ShaderTools::AnyConverter::validateFile(): " , filename ) ;
detecting based on extension . */
const Containers : : StringView format = stringForFormat (
_state - > inputFormat ! = Format : : Unspecified ? _state - > inputFormat :
formatForExtension ( " ShaderTools::AnyConverter::validateFile(): " , filename )
) ;
if ( format . isEmpty ( ) ) return { } ;
if ( format . isEmpty ( ) ) return { } ;
/* Decide on a plugin name based on the format */
const std : : string plugin = Utility : : formatString ( " {}ShaderConverter " , format ) ;
const std : : string plugin = Utility : : formatString ( " {}ShaderConverter " , format ) ;
/* Try to load the plugin */
/* Try to load the plugin */
@ -207,12 +231,19 @@ std::pair<bool, Containers::String> AnyConverter::doValidateFile(const Stage sta
bool AnyConverter : : doConvertFileToFile ( const Stage stage , const Containers : : StringView from , const Containers : : StringView to ) {
bool AnyConverter : : doConvertFileToFile ( const Stage stage , const Containers : : StringView from , const Containers : : StringView to ) {
CORRADE_INTERNAL_ASSERT ( manager ( ) ) ;
CORRADE_INTERNAL_ASSERT ( manager ( ) ) ;
/* Decide on a plugin name based on the input and output extension. This
/* Prefer the explicitly set input format. If not set, fall back to
might result in invalid combinations such as SpirvToGlslShaderConverter
detecting based on input and output extension . */
which can ' t be really handled yet but I think that ' s okay for now */
const Containers : : StringView formatFrom = stringForFormat (
const Containers : : StringView formatFrom = formatForExtension ( " ShaderTools::AnyConverter::convertFileToFile(): " , from ) ;
_state - > inputFormat ! = Format : : Unspecified ? _state - > inputFormat : formatForExtension ( " ShaderTools::AnyConverter::convertFileToFile(): " , from )
const Containers : : StringView formatTo = formatForExtension ( " ShaderTools::AnyConverter::convertFileToFile(): " , to ) ;
) ;
const Containers : : StringView formatTo = stringForFormat (
_state - > outputFormat ! = Format : : Unspecified ? _state - > outputFormat : formatForExtension ( " ShaderTools::AnyConverter::convertFileToFile(): " , to )
) ;
if ( formatFrom . isEmpty ( ) | | formatTo . isEmpty ( ) ) return { } ;
if ( formatFrom . isEmpty ( ) | | formatTo . isEmpty ( ) ) return { } ;
/* Decide on a plugin name based on the format. This might result in
invalid combinations such as SpirvToGlslShaderConverter which can ' t be
really handled yet but I think that ' s okay for now . */
const std : : string plugin = Utility : : formatString (
const std : : string plugin = Utility : : formatString (
formatFrom = = formatTo ? " {}ShaderConverter " : " {}To{}ShaderConverter " ,
formatFrom = = formatTo ? " {}ShaderConverter " : " {}To{}ShaderConverter " ,
formatFrom , formatTo ) ;
formatFrom , formatTo ) ;