yum-mirror/slang

Making it easier to work with shaders

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

jarcherNVAdd command line option for separate debug info (#7178)0d16228ae

master
4.4 KiB148 linesraw
1#pragma once
2
3#include "../core/slang-dictionary.h"
4#include "../core/slang-smart-pointer.h"
5#include "../core/slang-string-slice-pool.h"
6#include "../core/slang-string.h"
7
8#include <optional>
9#include <spirv/unified1/NonSemanticShaderDebugInfo100.h>
10#include <spirv/unified1/spirv.h>
11
12namespace Slang
13{
14using SpvWord = uint32_t;
15class DiagnosticSink;
16class SourceView;
17
18struct SPIRVCoreGrammarInfo : public RefObject
19{
20    static RefPtr<SPIRVCoreGrammarInfo> loadFromJSON(SourceView& source, DiagnosticSink& sink);
21    static RefPtr<SPIRVCoreGrammarInfo>& getEmbeddedVersion();
22    static inline void freeEmbeddedGrammerInfo() { getEmbeddedVersion() = nullptr; }
23
24    template<typename K, typename T>
25    struct Lookup
26    {
27        std::optional<T> lookup(const K& name) const
28        {
29            T ret;
30            if (embedded ? embedded(name, ret) : dict.tryGetValue(name, ret))
31                return ret;
32            else
33                return std::nullopt;
34        }
35
36        bool (*embedded)(const K&, T&) = nullptr;
37        Dictionary<K, T> dict;
38    };
39
40    struct OperandKind
41    {
42        uint8_t index;
43        SLANG_COMPONENTWISE_HASHABLE_1;
44        SLANG_COMPONENTWISE_EQUALITY_1(OperandKind);
45    };
46
47    struct QualifiedEnumName
48    {
49        OperandKind kind;
50        UnownedStringSlice name;
51        SLANG_COMPONENTWISE_HASHABLE_2;
52        SLANG_COMPONENTWISE_EQUALITY_2(QualifiedEnumName);
53    };
54
55    struct QualifiedEnumValue
56    {
57        OperandKind kind;
58        SpvWord value;
59        SLANG_COMPONENTWISE_HASHABLE_2;
60        SLANG_COMPONENTWISE_EQUALITY_2(QualifiedEnumValue);
61    };
62
63    struct OpInfo
64    {
65        enum Class
66        {
67            // Unrecognized instructions go in here
68            Other,
69
70            // Adding to this? Don't forget to update the embedding generator
71            Miscellaneous,
72            Debug,
73            Annotation,
74            Extension,
75            ModeSetting,
76            TypeDeclaration,
77            ConstantCreation,
78            Memory,
79            Function,
80            Image,
81            Conversion,
82            Composite,
83            Arithmetic,
84            Bit,
85            Relational_and_Logical,
86            Derivative,
87            ControlFlow,
88            Atomic,
89            Primitive,
90            Barrier,
91            Group,
92            DeviceSideEnqueue,
93            Pipe,
94            NonUniform,
95            Reserved,
96        };
97        constexpr static int8_t kNoResultTypeId = -1;
98        constexpr static int8_t kNoResultId = -1;
99
100        Class class_;
101        // -1 or 0
102        int8_t resultTypeIndex = kNoResultTypeId;
103        // -1 or 0 or 1
104        int8_t resultIdIndex = kNoResultId;
105        // The range of valid operand counts for this instruction,
106        // including any result type and id. Multi-word operands count as a
107        // single operand.
108        uint16_t minOperandCount;
109        uint16_t maxOperandCount;
110        // when looking up an operand type, clamp to this number-1 to
111        // account for variable length operands at the end
112        uint16_t numOperandTypes;
113        const OperandKind* operandTypes;
114    };
115
116    //
117    // Our tables:
118    //
119
120    // Instruction name to opcode
121    Lookup<UnownedStringSlice, SpvOp> opcodes;
122    // Capability name to value
123    Lookup<UnownedStringSlice, SpvCapability> capabilities;
124    // String-qualified enum name (one with the type prefix) to value
125    Lookup<UnownedStringSlice, SpvWord> allEnumsWithTypePrefix;
126    // kind * enum name to value
127    Lookup<QualifiedEnumName, SpvWord> allEnums;
128    // kine * enum value to unqualified name
129    Lookup<QualifiedEnumValue, UnownedStringSlice> allEnumNames;
130    // Any other information on instructions
131    Lookup<SpvOp, OpInfo> opInfos;
132    // Opcode to instruction name
133    Lookup<SpvOp, UnownedStringSlice> opNames;
134    // Operand kind string to numeric id
135    Lookup<UnownedStringSlice, OperandKind> operandKinds;
136    // Operand kind id to string
137    Lookup<OperandKind, UnownedStringSlice> operandKindNames;
138    // Operand kind to the "un-id" version of itself, for example IdMemorySemantics to
139    // MemorySemantics
140    Lookup<OperandKind, OperandKind> operandKindUnderneathIds;
141
142private:
143    // If this is loaded from JSON, we keep the strings around instead of
144    // copying them as dictionary keys
145    StringSlicePool strings = StringSlicePool(StringSlicePool::Style::Empty);
146    List<OperandKind> operandTypesStorage;
147};
148} // namespace Slang