yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
2.0 KiB72 linesraw
1#ifndef GFX_FLAG_COMBINER_H
2#define GFX_FLAG_COMBINER_H
3
4#include "../../source/core/slang-list.h"
5
6namespace gfx
7{
8
9/* A default set of flags that can be used for checking devices */
10typedef uint32_t DeviceCheckFlags;
11struct DeviceCheckFlag
12{
13    enum Enum : DeviceCheckFlags
14    {
15        UseFullFeatureLevel = 0x1, //< If set will use full feature level (on dx this is
16                                   // D3D_FEATURE_LEVEL_11_1 else will try D3D_FEATURE_LEVEL_11_0)
17        UseHardwareDevice = 0x2,   //< If set will try a hardware device
18        UseDebug = 0x4,            //< If set will enable use of debug
19    };
20};
21
22/* Controls how and the order flags are changed, on the FlagCombiner */
23enum class ChangeType
24{
25    On,    ///< Always on
26    Off,   ///< Always off
27    OnOff, ///< Initially on then off
28    OffOn, ///< Initially off then on
29};
30
31/* Calculates all the combinations of flags as controlled by the change types.
32
33The order of adding flags can be considered to be like a nested loop
34for (first added) {
35    for (second added)
36    {
37        ///..
38    }
39}
40
41So the last added flags will have the highest frequency.
42*/
43class FlagCombiner
44{
45public:
46    /// Add a flag and how it changes over the combinations
47    /// NOTE! That the order flags are added controls the order they change when combinations are
48    /// calculated - earlier added flags will change with the highest frequency
49    void add(uint32_t flags, ChangeType changeType);
50    /// Calculate all of the combinations and place in an array
51    void calcCombinations(Slang::List<uint32_t>& outCombinations) const;
52
53    /// Reset back to initial state
54    void reset();
55
56    /// Get the total amount of combinations
57    int getNumCombinations() const { return 1 << m_numChangingBits; }
58
59    /// Get the combination at i
60    uint32_t getCombination(int i) const;
61
62protected:
63    uint32_t m_changingBits[32];
64    int m_numChangingBits = 0;
65
66    uint32_t m_usedFlags = 0;
67    uint32_t m_invertBits = 0;
68};
69
70} // namespace gfx
71
72#endif // GFX_FLAG_COMBINER_H