@@ -152,4 +152,125 @@ RefCntAutoPtr<IShaderSourceInputStreamFactory> CreateMemoryShaderSourceFactory(c
152152 return CreateMemoryShaderSourceFactory (CI);
153153}
154154
155+
156+ // / C++ wrapper over PipelineResourceSignatureDesc.
157+ struct CompoundShaderSourceFactoryCreateInfoX : CompoundShaderSourceFactoryCreateInfo
158+ {
159+ CompoundShaderSourceFactoryCreateInfoX () noexcept
160+ {}
161+
162+ explicit CompoundShaderSourceFactoryCreateInfoX (const CompoundShaderSourceFactoryCreateInfo& _Desc) :
163+ CompoundShaderSourceFactoryCreateInfo{_Desc}
164+ {
165+ if (NumFactories != 0 )
166+ Factories.assign (ppFactories, ppFactories + NumFactories);
167+
168+ if (NumFileSubstitutes != 0 )
169+ FileSubstitutes.assign (pFileSubstitutes, pFileSubstitutes + NumFileSubstitutes);
170+
171+ SyncDesc (true );
172+ }
173+
174+ explicit CompoundShaderSourceFactoryCreateInfoX (const std::initializer_list<IShaderSourceInputStreamFactory*>& _Factories,
175+ const std::initializer_list<ShaderSourceFileSubstitueInfo>& _FileSubstitutes = {}) :
176+ Factories{_Factories},
177+ FileSubstitutes{_FileSubstitutes}
178+ {
179+ SyncDesc (true );
180+ }
181+
182+ CompoundShaderSourceFactoryCreateInfoX (const CompoundShaderSourceFactoryCreateInfoX& _DescX) :
183+ CompoundShaderSourceFactoryCreateInfoX{static_cast <const CompoundShaderSourceFactoryCreateInfo&>(_DescX)}
184+ {}
185+
186+ CompoundShaderSourceFactoryCreateInfoX& operator =(const CompoundShaderSourceFactoryCreateInfoX& _DescX)
187+ {
188+ CompoundShaderSourceFactoryCreateInfoX Copy{_DescX};
189+ std::swap (*this , Copy);
190+ return *this ;
191+ }
192+
193+ CompoundShaderSourceFactoryCreateInfoX (CompoundShaderSourceFactoryCreateInfoX&&) noexcept = default ;
194+ CompoundShaderSourceFactoryCreateInfoX& operator =(CompoundShaderSourceFactoryCreateInfoX&&) noexcept = default ;
195+
196+ CompoundShaderSourceFactoryCreateInfoX& AddFactory (IShaderSourceInputStreamFactory* pFactory)
197+ {
198+ Factories.push_back (pFactory);
199+ return SyncDesc ();
200+ }
201+
202+ CompoundShaderSourceFactoryCreateInfoX& AddFileSusbtitute (const ShaderSourceFileSubstitueInfo& Substitute)
203+ {
204+ FileSubstitutes.push_back (Substitute);
205+ FileSubstitutes.back ().Name = StringPool.emplace (Substitute.Name ).first ->c_str ();
206+ FileSubstitutes.back ().Substitute = StringPool.emplace (Substitute.Substitute ).first ->c_str ();
207+ return SyncDesc ();
208+ }
209+
210+ template <typename ... ArgsType>
211+ CompoundShaderSourceFactoryCreateInfoX& AddFileSusbtitute (ArgsType&&... args)
212+ {
213+ const ShaderSourceFileSubstitueInfo Sam{std::forward<ArgsType>(args)...};
214+ return AddFileSusbtitute (Sam);
215+ }
216+
217+ CompoundShaderSourceFactoryCreateInfoX& ClearFactories ()
218+ {
219+ Factories.clear ();
220+ return SyncDesc ();
221+ }
222+
223+ CompoundShaderSourceFactoryCreateInfoX& ClearFileSubstitutes ()
224+ {
225+ FileSubstitutes.clear ();
226+ return SyncDesc ();
227+ }
228+
229+ CompoundShaderSourceFactoryCreateInfoX& Clear ()
230+ {
231+ CompoundShaderSourceFactoryCreateInfoX CleanDesc;
232+ std::swap (*this , CleanDesc);
233+ return *this ;
234+ }
235+
236+ private:
237+ CompoundShaderSourceFactoryCreateInfoX& SyncDesc (bool UpdateStrings = false )
238+ {
239+ NumFactories = static_cast <Uint32>(Factories.size ());
240+ ppFactories = NumFactories > 0 ? Factories.data () : nullptr ;
241+
242+ NumFileSubstitutes = static_cast <Uint32>(FileSubstitutes.size ());
243+ pFileSubstitutes = NumFileSubstitutes > 0 ? FileSubstitutes.data () : nullptr ;
244+
245+ if (UpdateStrings)
246+ {
247+ for (auto & FileSubs : FileSubstitutes)
248+ {
249+ FileSubs.Name = StringPool.emplace (FileSubs.Name ).first ->c_str ();
250+ FileSubs.Substitute = StringPool.emplace (FileSubs.Substitute ).first ->c_str ();
251+ }
252+ }
253+
254+ return *this ;
255+ }
256+
257+ std::vector<IShaderSourceInputStreamFactory*> Factories;
258+ std::vector<ShaderSourceFileSubstitueInfo> FileSubstitutes;
259+ std::unordered_set<std::string> StringPool;
260+ };
261+
262+ inline RefCntAutoPtr<IShaderSourceInputStreamFactory> CreateCompoundShaderSourceFactory (const CompoundShaderSourceFactoryCreateInfo& CI)
263+ {
264+ RefCntAutoPtr<IShaderSourceInputStreamFactory> pFactory;
265+ CreateCompoundShaderSourceFactory (CI, &pFactory);
266+ return pFactory;
267+ }
268+
269+ RefCntAutoPtr<IShaderSourceInputStreamFactory> CreateCompoundShaderSourceFactory (const std::initializer_list<IShaderSourceInputStreamFactory*>& Factories,
270+ const std::initializer_list<ShaderSourceFileSubstitueInfo>& FileSubstitutes = {})
271+ {
272+ CompoundShaderSourceFactoryCreateInfoX CI{Factories, FileSubstitutes};
273+ return CreateCompoundShaderSourceFactory (CI);
274+ }
275+
155276} // namespace Diligent
0 commit comments