yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
2.1 KiB73 linesraw
1#ifndef SLANG_DOWNSTREAM_COMPILER_SET_H
2#define SLANG_DOWNSTREAM_COMPILER_SET_H
3
4#include "slang-downstream-compiler.h"
5
6namespace Slang
7{
8
9class DownstreamCompilerSet : public RefObject
10{
11public:
12    typedef RefObject Super;
13
14    /// Find all the available compilers
15    void getCompilerDescs(List<IDownstreamCompiler::Desc>& outCompilerDescs) const;
16    /// Returns list of all compilers
17    void getCompilers(List<IDownstreamCompiler*>& outCompilers) const;
18
19    /// Get a compiler
20    IDownstreamCompiler* getCompiler(const DownstreamCompilerDesc& compilerDesc) const;
21
22    /// Will replace if there is one with same desc
23    void addCompiler(IDownstreamCompiler* compiler);
24
25    /// Get a default compiler
26    IDownstreamCompiler* getDefaultCompiler(SlangSourceLanguage sourceLanguage) const
27    {
28        return m_defaultCompilers[int(sourceLanguage)];
29    }
30    /// Set the default compiler
31    void setDefaultCompiler(SlangSourceLanguage sourceLanguage, IDownstreamCompiler* compiler)
32    {
33        m_defaultCompilers[int(sourceLanguage)] = compiler;
34    }
35
36    /// True if has a compiler of the specified type
37    bool hasCompiler(SlangPassThrough compilerType) const;
38
39    void remove(SlangPassThrough compilerType);
40
41    void clear() { m_compilers.clear(); }
42
43    bool hasSharedLibrary(ISlangSharedLibrary* lib);
44    void addSharedLibrary(ISlangSharedLibrary* lib);
45
46    ~DownstreamCompilerSet()
47    {
48        // A compiler may be implemented in a shared library, so release all first.
49        m_compilers.clearAndDeallocate();
50        for (auto& defaultCompiler : m_defaultCompilers)
51        {
52            defaultCompiler.setNull();
53        }
54
55        // Release any shared libraries
56        m_sharedLibraries.clearAndDeallocate();
57    }
58
59protected:
60    Index _findIndex(const DownstreamCompilerDesc& desc) const;
61
62
63    ComPtr<IDownstreamCompiler> m_defaultCompilers[int(SLANG_SOURCE_LANGUAGE_COUNT_OF)];
64    // This could be a dictionary/map - but doing a linear search is going to be fine and it makes
65    // somethings easier.
66    List<ComPtr<IDownstreamCompiler>> m_compilers;
67
68    List<ComPtr<ISlangSharedLibrary>> m_sharedLibraries;
69};
70
71} // namespace Slang
72
73#endif