yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1#ifndef SLANG_DOWNSTREAM_COMPILER_UTIL_H 2#define SLANG_DOWNSTREAM_COMPILER_UTIL_H 3 4#include "slang-downstream-compiler-set.h" 5#include "slang-downstream-compiler.h" 6 7namespace Slang 8{ 9 10typedef SlangResult (* DownstreamCompilerLocatorFunc )( 11const String & path , 12ISlangSharedLibraryLoader * loader , 13DownstreamCompilerSet * set ); 14 15struct DownstreamCompilerInfo 16{ 17typedef DownstreamCompilerInfo This ; 18typedef uint32_t SourceLanguageFlags ; 19struct SourceLanguageFlag 20 { 21enum Enum :SourceLanguageFlags 22 { 23Unknown = SourceLanguageFlags (1 ) <<SLANG_SOURCE_LANGUAGE_UNKNOWN , 24Slang = SourceLanguageFlags (1 ) <<SLANG_SOURCE_LANGUAGE_SLANG , 25HLSL = SourceLanguageFlags (1 ) <<SLANG_SOURCE_LANGUAGE_HLSL , 26GLSL = SourceLanguageFlags (1 ) <<SLANG_SOURCE_LANGUAGE_GLSL , 27C = SourceLanguageFlags (1 ) <<SLANG_SOURCE_LANGUAGE_C , 28CPP = SourceLanguageFlags (1 ) <<SLANG_SOURCE_LANGUAGE_CPP , 29CUDA = SourceLanguageFlags (1 ) <<SLANG_SOURCE_LANGUAGE_CUDA , 30SPIRV = SourceLanguageFlags (1 ) <<SLANG_SOURCE_LANGUAGE_SPIRV , 31 }; 32 }; 33 34/// Get info for a compiler type 35static const This & getInfo (SlangPassThrough compiler ); 36/// True if this compiler can compile the specified language 37static bool canCompile (SlangPassThrough compiler ,SlangSourceLanguage sourceLanguage ); 38 39DownstreamCompilerInfo () 40 :sourceLanguageFlags (0 ) 41 { 42 } 43 44DownstreamCompilerInfo (SourceLanguageFlags inSourceLanguageFlags ) 45 :sourceLanguageFlags (inSourceLanguageFlags ) 46 { 47 } 48SourceLanguageFlags sourceLanguageFlags ; 49}; 50 51 52// Combination of a downstream compiler type (pass through) and 53// a match version. 54struct DownstreamCompilerMatchVersion 55{ 56DownstreamCompilerMatchVersion (SlangPassThrough inType ,MatchSemanticVersion inMatchVersion ) 57 :type (inType ),matchVersion (inMatchVersion ) 58 { 59 } 60 61DownstreamCompilerMatchVersion () 62 :type (SLANG_PASS_THROUGH_NONE ) 63 { 64 } 65 66SlangPassThrough type ;///< The type of the compiler 67MatchSemanticVersion matchVersion ;///< The match version 68}; 69 70struct DownstreamCompilerUtil :public DownstreamCompilerUtilBase 71{ 72enum class MatchType 73 { 74MinGreaterEqual , 75MinAbsolute , 76Newest , 77 }; 78 79/// Find a compiler 80static IDownstreamCompiler * findCompiler ( 81const DownstreamCompilerSet * set , 82MatchType matchType , 83const DownstreamCompilerDesc & desc ); 84static IDownstreamCompiler * findCompiler ( 85const List < IDownstreamCompiler *>& compilers , 86MatchType matchType , 87const DownstreamCompilerDesc & desc ); 88 89static IDownstreamCompiler * findCompiler ( 90const List < IDownstreamCompiler *>& compilers , 91SlangPassThrough type , 92const SemanticVersion & version ); 93static IDownstreamCompiler * findCompiler ( 94const List < IDownstreamCompiler *>& compilers , 95const DownstreamCompilerDesc & desc ); 96 97/// Find all the compilers with the version 98static void findVersions ( 99const List < IDownstreamCompiler *>& compilers , 100SlangPassThrough compiler , 101List < SemanticVersion >& versions ); 102 103 104/// Find the compiler closest to the desc 105static IDownstreamCompiler * findClosestCompiler ( 106const List < IDownstreamCompiler *>& compilers , 107const DownstreamCompilerMatchVersion & version ); 108static IDownstreamCompiler * findClosestCompiler ( 109const DownstreamCompilerSet * set , 110const DownstreamCompilerMatchVersion & version ); 111 112/// Get the information on the compiler used to compile this source 113static DownstreamCompilerMatchVersion getCompiledVersion (); 114 115static void updateDefault (DownstreamCompilerSet * set ,SlangSourceLanguage sourceLanguage ); 116static void updateDefaults (DownstreamCompilerSet * set ); 117 118static void setDefaultLocators ( 119DownstreamCompilerLocatorFunc outFuncs [int (SLANG_PASS_THROUGH_COUNT_OF )]); 120 121/// Attempts to determine what 'path' is and load appropriately. Is it a path to a shared 122/// library? Is it a directory holding the libraries? Some downstream shared libraries need 123/// other shared libraries to be loaded before the main shared library, such that they are in 124/// the same directory otherwise the shared library could come from some unwanted location. 125/// dependentNames names shared libraries which should be attempted to be loaded in the path of 126/// the main shared library. The list is optional (nullptr can be passed in), and the list is 127/// terminated by nullptr. 128static SlangResult loadSharedLibrary ( 129const String & path , 130ISlangSharedLibraryLoader * loader , 131const char * const * dependantNames , 132const char * libraryName , 133ComPtr < ISlangSharedLibrary >& outSharedLib ); 134 135/// Append the desc as text 136static void appendAsText (const DownstreamCompilerDesc & desc ,StringBuilder & out ); 137}; 138 139}// namespace Slang 140 141#endif