@@ -26,75 +26,81 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
2626
2727 class NBL_API2 IIncludeLoader : public core::IReferenceCounted
2828 {
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;
3138 };
3239
3340 class NBL_API2 IIncludeGenerator : public core::IReferenceCounted
3441 {
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 ;
3845
39- virtual std::string_view getPrefix () const = 0;
46+ virtual std::string_view getPrefix () const = 0;
4047
41- protected:
48+ protected:
4249
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;
4552
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);
4956 };
5057
5158 class NBL_API2 CFileSystemIncludeLoader : public IIncludeLoader
5259 {
53- public:
54- CFileSystemIncludeLoader (core::smart_refctd_ptr<system::ISystem>&& system);
60+ public:
61+ CFileSystemIncludeLoader (core::smart_refctd_ptr<system::ISystem>&& system);
5562
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 ;
5764
58- protected:
59- core::smart_refctd_ptr<system::ISystem> m_system;
65+ protected:
66+ core::smart_refctd_ptr<system::ISystem> m_system;
6067 };
6168
6269 class NBL_API2 CIncludeFinder : public core::IReferenceCounted
6370 {
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);
7173
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 ;
7678
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 ;
7883
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; }
8085
81- void addGenerator (const core::smart_refctd_ptr<IIncludeGenerator >& generator );
86+ void addSearchPath (const std::string& searchPath, const core::smart_refctd_ptr<IIncludeLoader >& loader );
8287
83- protected:
88+ void addGenerator ( const core::smart_refctd_ptr<IIncludeGenerator>& generator);
8489
85- std::optional<std::string> trySearchPaths (const std::string& includeName) const ;
90+ protected:
91+ IIncludeLoader::found_t trySearchPaths (const std::string& includeName) const ;
8692
87- std::optional<std::string> tryIncludeGenerators (const std::string& includeName) const ;
93+ IIncludeLoader:: found_t tryIncludeGenerators (const std::string& includeName) const ;
8894
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+ };
94100
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;
98104 };
99105
100106 enum class E_SPIRV_VERSION : uint32_t
@@ -115,8 +121,12 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
115121 std::string_view sourceIdentifier = " " ;
116122 system::logger_opt_ptr logger = nullptr ;
117123 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 = {};
120130 };
121131
122132 // https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#debugging
@@ -290,8 +300,6 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
290300
291301 virtual void insertIntoStart (std::string& code, std::ostringstream&& ins) const = 0;
292302
293- void insertExtraDefines (std::string& code, const core::SRange<const char * const >& defines) const ;
294-
295303 core::smart_refctd_ptr<system::ISystem> m_system;
296304 private:
297305 core::smart_refctd_ptr<CIncludeFinder> m_defaultIncludeFinder;
0 commit comments