yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
4.9 KiB141 linesraw
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)(
11    const String& path,
12    ISlangSharedLibraryLoader* loader,
13    DownstreamCompilerSet* set);
14
15struct DownstreamCompilerInfo
16{
17    typedef DownstreamCompilerInfo This;
18    typedef uint32_t SourceLanguageFlags;
19    struct SourceLanguageFlag
20    {
21        enum Enum : SourceLanguageFlags
22        {
23            Unknown = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_UNKNOWN,
24            Slang = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_SLANG,
25            HLSL = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_HLSL,
26            GLSL = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_GLSL,
27            C = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_C,
28            CPP = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_CPP,
29            CUDA = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_CUDA,
30            SPIRV = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_SPIRV,
31        };
32    };
33
34    /// Get info for a compiler type
35    static const This& getInfo(SlangPassThrough compiler);
36    /// True if this compiler can compile the specified language
37    static bool canCompile(SlangPassThrough compiler, SlangSourceLanguage sourceLanguage);
38
39    DownstreamCompilerInfo()
40        : sourceLanguageFlags(0)
41    {
42    }
43
44    DownstreamCompilerInfo(SourceLanguageFlags inSourceLanguageFlags)
45        : sourceLanguageFlags(inSourceLanguageFlags)
46    {
47    }
48    SourceLanguageFlags sourceLanguageFlags;
49};
50
51
52// Combination of a downstream compiler type (pass through) and
53// a match version.
54struct DownstreamCompilerMatchVersion
55{
56    DownstreamCompilerMatchVersion(SlangPassThrough inType, MatchSemanticVersion inMatchVersion)
57        : type(inType), matchVersion(inMatchVersion)
58    {
59    }
60
61    DownstreamCompilerMatchVersion()
62        : type(SLANG_PASS_THROUGH_NONE)
63    {
64    }
65
66    SlangPassThrough type;             ///< The type of the compiler
67    MatchSemanticVersion matchVersion; ///< The match version
68};
69
70struct DownstreamCompilerUtil : public DownstreamCompilerUtilBase
71{
72    enum class MatchType
73    {
74        MinGreaterEqual,
75        MinAbsolute,
76        Newest,
77    };
78
79    /// Find a compiler
80    static IDownstreamCompiler* findCompiler(
81        const DownstreamCompilerSet* set,
82        MatchType matchType,
83        const DownstreamCompilerDesc& desc);
84    static IDownstreamCompiler* findCompiler(
85        const List<IDownstreamCompiler*>& compilers,
86        MatchType matchType,
87        const DownstreamCompilerDesc& desc);
88
89    static IDownstreamCompiler* findCompiler(
90        const List<IDownstreamCompiler*>& compilers,
91        SlangPassThrough type,
92        const SemanticVersion& version);
93    static IDownstreamCompiler* findCompiler(
94        const List<IDownstreamCompiler*>& compilers,
95        const DownstreamCompilerDesc& desc);
96
97    /// Find all the compilers with the version
98    static void findVersions(
99        const List<IDownstreamCompiler*>& compilers,
100        SlangPassThrough compiler,
101        List<SemanticVersion>& versions);
102
103
104    /// Find the compiler closest to the desc
105    static IDownstreamCompiler* findClosestCompiler(
106        const List<IDownstreamCompiler*>& compilers,
107        const DownstreamCompilerMatchVersion& version);
108    static IDownstreamCompiler* findClosestCompiler(
109        const DownstreamCompilerSet* set,
110        const DownstreamCompilerMatchVersion& version);
111
112    /// Get the information on the compiler used to compile this source
113    static DownstreamCompilerMatchVersion getCompiledVersion();
114
115    static void updateDefault(DownstreamCompilerSet* set, SlangSourceLanguage sourceLanguage);
116    static void updateDefaults(DownstreamCompilerSet* set);
117
118    static void setDefaultLocators(
119        DownstreamCompilerLocatorFunc 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.
128    static SlangResult loadSharedLibrary(
129        const String& path,
130        ISlangSharedLibraryLoader* loader,
131        const char* const* dependantNames,
132        const char* libraryName,
133        ComPtr<ISlangSharedLibrary>& outSharedLib);
134
135    /// Append the desc as text
136    static void appendAsText(const DownstreamCompilerDesc& desc, StringBuilder& out);
137};
138
139} // namespace Slang
140
141#endif