@@ -26,75 +26,81 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
26
26
27
27
class NBL_API2 IIncludeLoader : public core::IReferenceCounted
28
28
{
29
- public:
30
- virtual std::optional<std::string> getInclude (const system::path& searchPath, const std::string& includeName) const = 0;
29
+ public:
30
+ struct found_t
31
+ {
32
+ system::path absolutePath = {};
33
+ std::string contents = {};
34
+
35
+ explicit inline operator bool () const {return !absolutePath.empty ();}
36
+ };
37
+ virtual found_t getInclude (const system::path& searchPath, const std::string& includeName) const = 0;
31
38
};
32
39
33
40
class NBL_API2 IIncludeGenerator : public core::IReferenceCounted
34
41
{
35
- public:
36
- // ! if includeName doesn't begin with prefix from `getPrefix` this function will return an empty string
37
- virtual std::optional<std::string> getInclude (const std::string& includeName) const ;
42
+ public:
43
+ // ! if includeName doesn't begin with prefix from `getPrefix` this function will return an empty string
44
+ virtual IIncludeLoader:: found_t getInclude (const std::string& includeName) const ;
38
45
39
- virtual std::string_view getPrefix () const = 0;
46
+ virtual std::string_view getPrefix () const = 0;
40
47
41
- protected:
48
+ protected:
42
49
43
- using HandleFunc_t = std::function<std::string(const std::string&)>;
44
- virtual core::vector<std::pair<std::regex, HandleFunc_t>> getBuiltinNamesToFunctionMapping () const = 0;
50
+ using HandleFunc_t = std::function<std::string(const std::string&)>;
51
+ virtual core::vector<std::pair<std::regex,HandleFunc_t>> getBuiltinNamesToFunctionMapping () const = 0;
45
52
46
- // ! Parses arguments from include path
47
- // ! template is path/to/shader.hlsl/arg0/arg1/...
48
- static core::vector<std::string> parseArgumentsFromPath (const std::string& _path);
53
+ // ! Parses arguments from include path
54
+ // ! template is path/to/shader.hlsl/arg0/arg1/...
55
+ static core::vector<std::string> parseArgumentsFromPath (const std::string& _path);
49
56
};
50
57
51
58
class NBL_API2 CFileSystemIncludeLoader : public IIncludeLoader
52
59
{
53
- public:
54
- CFileSystemIncludeLoader (core::smart_refctd_ptr<system::ISystem>&& system);
60
+ public:
61
+ CFileSystemIncludeLoader (core::smart_refctd_ptr<system::ISystem>&& system);
55
62
56
- std::optional<std::string> getInclude (const system::path& searchPath, const std::string& includeName) const override ;
63
+ IIncludeLoader:: found_t getInclude (const system::path& searchPath, const std::string& includeName) const override ;
57
64
58
- protected:
59
- core::smart_refctd_ptr<system::ISystem> m_system;
65
+ protected:
66
+ core::smart_refctd_ptr<system::ISystem> m_system;
60
67
};
61
68
62
69
class NBL_API2 CIncludeFinder : public core::IReferenceCounted
63
70
{
64
- public:
65
- CIncludeFinder (core::smart_refctd_ptr<system::ISystem>&& system);
66
-
67
- // ! includes within <>
68
- // @param requestingSourceDir: the directory where the incude was requested
69
- // @param includeName: the string within <> of the include preprocessing directive
70
- std::optional<std::string> getIncludeStandard (const system::path& requestingSourceDir, const std::string& includeName) const ;
71
+ public:
72
+ CIncludeFinder (core::smart_refctd_ptr<system::ISystem>&& system);
71
73
72
- // ! includes within ""
73
- // @param requestingSourceDir: the directory where the incude was requested
74
- // @param includeName: the string within "" of the include preprocessing directive
75
- std::optional<std::string> getIncludeRelative (const system::path& requestingSourceDir, const std::string& includeName) const ;
74
+ // ! includes within <>
75
+ // @param requestingSourceDir: the directory where the incude was requested
76
+ // @param includeName: the string within <> of the include preprocessing directive
77
+ IIncludeLoader:: found_t getIncludeStandard (const system::path& requestingSourceDir, const std::string& includeName) const ;
76
78
77
- inline core::smart_refctd_ptr<CFileSystemIncludeLoader> getDefaultFileSystemLoader () const { return m_defaultFileSystemLoader; }
79
+ // ! includes within ""
80
+ // @param requestingSourceDir: the directory where the incude was requested
81
+ // @param includeName: the string within "" of the include preprocessing directive
82
+ IIncludeLoader::found_t getIncludeRelative (const system::path& requestingSourceDir, const std::string& includeName) const ;
78
83
79
- void addSearchPath ( const std::string& searchPath, const core::smart_refctd_ptr<IIncludeLoader>& loader);
84
+ inline core::smart_refctd_ptr<CFileSystemIncludeLoader> getDefaultFileSystemLoader () const { return m_defaultFileSystemLoader; }
80
85
81
- void addGenerator (const core::smart_refctd_ptr<IIncludeGenerator >& generator );
86
+ void addSearchPath (const std::string& searchPath, const core::smart_refctd_ptr<IIncludeLoader >& loader );
82
87
83
- protected:
88
+ void addGenerator ( const core::smart_refctd_ptr<IIncludeGenerator>& generator);
84
89
85
- std::optional<std::string> trySearchPaths (const std::string& includeName) const ;
90
+ protected:
91
+ IIncludeLoader::found_t trySearchPaths (const std::string& includeName) const ;
86
92
87
- std::optional<std::string> tryIncludeGenerators (const std::string& includeName) const ;
93
+ IIncludeLoader:: found_t tryIncludeGenerators (const std::string& includeName) const ;
88
94
89
- struct LoaderSearchPath
90
- {
91
- core::smart_refctd_ptr<IIncludeLoader> loader = nullptr ;
92
- std::string searchPath = {};
93
- };
95
+ struct LoaderSearchPath
96
+ {
97
+ core::smart_refctd_ptr<IIncludeLoader> loader = nullptr ;
98
+ std::string searchPath = {};
99
+ };
94
100
95
- std::vector<LoaderSearchPath> m_loaders;
96
- std::vector<core::smart_refctd_ptr<IIncludeGenerator>> m_generators;
97
- core::smart_refctd_ptr<CFileSystemIncludeLoader> m_defaultFileSystemLoader;
101
+ std::vector<LoaderSearchPath> m_loaders;
102
+ std::vector<core::smart_refctd_ptr<IIncludeGenerator>> m_generators;
103
+ core::smart_refctd_ptr<CFileSystemIncludeLoader> m_defaultFileSystemLoader;
98
104
};
99
105
100
106
enum class E_SPIRV_VERSION : uint32_t
@@ -115,8 +121,12 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
115
121
std::string_view sourceIdentifier = " " ;
116
122
system::logger_opt_ptr logger = nullptr ;
117
123
const CIncludeFinder* includeFinder = nullptr ;
118
- uint32_t maxSelfInclusionCount = 4u ;
119
- core::SRange<const char * const > extraDefines = {nullptr , nullptr };
124
+ struct SMacroDefinition
125
+ {
126
+ std::string_view identifier;
127
+ std::string_view definition;
128
+ };
129
+ std::span<const SMacroDefinition> extraDefines = {};
120
130
};
121
131
122
132
// https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#debugging
@@ -290,8 +300,6 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
290
300
291
301
virtual void insertIntoStart (std::string& code, std::ostringstream&& ins) const = 0;
292
302
293
- void insertExtraDefines (std::string& code, const core::SRange<const char * const >& defines) const ;
294
-
295
303
core::smart_refctd_ptr<system::ISystem> m_system;
296
304
private:
297
305
core::smart_refctd_ptr<CIncludeFinder> m_defaultIncludeFinder;
0 commit comments