yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
2.5 KiB99 linesraw
1// slang-downstream-compiler-set.cpp
2#include "slang-downstream-compiler-set.h"
3
4namespace Slang
5{
6
7/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DownstreamCompilerSet !!!!!!!!!!!!!!!!!!!!!!*/
8
9void DownstreamCompilerSet::getCompilerDescs(List<DownstreamCompilerDesc>& outCompilerDescs) const
10{
11    outCompilerDescs.clear();
12    for (IDownstreamCompiler* compiler : m_compilers)
13    {
14        outCompilerDescs.add(compiler->getDesc());
15    }
16}
17
18Index DownstreamCompilerSet::_findIndex(const DownstreamCompilerDesc& desc) const
19{
20    const Index count = m_compilers.getCount();
21    for (Index i = 0; i < count; ++i)
22    {
23        if (m_compilers[i]->getDesc() == desc)
24        {
25            return i;
26        }
27    }
28    return -1;
29}
30
31IDownstreamCompiler* DownstreamCompilerSet::getCompiler(
32    const DownstreamCompilerDesc& compilerDesc) const
33{
34    const Index index = _findIndex(compilerDesc);
35    return index >= 0 ? m_compilers[index] : nullptr;
36}
37
38void DownstreamCompilerSet::getCompilers(List<IDownstreamCompiler*>& outCompilers) const
39{
40    outCompilers.clear();
41    outCompilers.addRange((IDownstreamCompiler* const*)m_compilers.begin(), m_compilers.getCount());
42}
43
44bool DownstreamCompilerSet::hasSharedLibrary(ISlangSharedLibrary* lib)
45{
46    const Index foundIndex = m_sharedLibraries.findFirstIndex(
47        [lib](ISlangSharedLibrary* inLib) -> bool { return lib == inLib; });
48    return (foundIndex >= 0);
49}
50
51void DownstreamCompilerSet::addSharedLibrary(ISlangSharedLibrary* lib)
52{
53    SLANG_ASSERT(lib);
54    if (!hasSharedLibrary(lib))
55    {
56        m_sharedLibraries.add(ComPtr<ISlangSharedLibrary>(lib));
57    }
58}
59
60bool DownstreamCompilerSet::hasCompiler(SlangPassThrough compilerType) const
61{
62    for (IDownstreamCompiler* compiler : m_compilers)
63    {
64        const auto& desc = compiler->getDesc();
65        if (desc.type == compilerType)
66        {
67            return true;
68        }
69    }
70    return false;
71}
72
73void DownstreamCompilerSet::remove(SlangPassThrough compilerType)
74{
75    for (Index i = 0; i < m_compilers.getCount(); ++i)
76    {
77        IDownstreamCompiler* compiler = m_compilers[i];
78        if (compiler->getDesc().type == compilerType)
79        {
80            m_compilers.fastRemoveAt(i);
81            i--;
82        }
83    }
84}
85
86void DownstreamCompilerSet::addCompiler(IDownstreamCompiler* compiler)
87{
88    const Index index = _findIndex(compiler->getDesc());
89    if (index >= 0)
90    {
91        m_compilers[index] = compiler;
92    }
93    else
94    {
95        m_compilers.add(ComPtr<IDownstreamCompiler>(compiler));
96    }
97}
98
99} // namespace Slang