yum-mirror/slang

Making it easier to work with shaders

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

Julius IkkalaFix build on GCC 15 (#6971)6104a5554

master
4.7 KiB175 linesraw
1// slang-glslang.h
2#ifndef SLANG_GLSLANG_H_INCLUDED
3#define SLANG_GLSLANG_H_INCLUDED
4
5#include <cstdint>
6#include <cstring>
7#include <memory>
8#include <stddef.h>
9
10typedef void (*glslang_OutputFunc)(void const* data, size_t size, void* userData);
11
12enum
13{
14    GLSLANG_ACTION_COMPILE_GLSL_TO_SPIRV,
15    GLSLANG_ACTION_DISSASSEMBLE_SPIRV,
16    GLSLANG_ACTION_OPTIMIZE_SPIRV,
17};
18
19struct glsl_SPIRVVersion
20{
21    int major, minor, patch;
22};
23
24// clang-format off
25
26#define SLANG_GLSLANG_COMPILE_REQUEST_1_0(x)  \
27    x(sourcePath) \
28    x(inputBegin) \
29    x(inputEnd) \
30    x(diagnosticFunc) \
31    x(diagnosticUserData) \
32    x(outputFunc) \
33    x(outputUserData) \
34    x(slangStage) \
35    x(action) \
36    x(optimizationLevel) \
37    x(debugInfoType)
38
39#define SLANG_GLSLANG_FIELD_COPY(name) name = in.name;
40
41// clang-format on
42
43// Pre-declare
44struct glslang_CompileRequest_1_1;
45
46// 1.0 version
47struct glslang_CompileRequest_1_0
48{
49    void set(const glslang_CompileRequest_1_1& in);
50
51    char const* sourcePath;
52
53    void const* inputBegin;
54    void const* inputEnd;
55
56    glslang_OutputFunc diagnosticFunc;
57    void* diagnosticUserData;
58
59    glslang_OutputFunc outputFunc;
60    void* outputUserData;
61
62    int slangStage;
63
64    unsigned action;
65
66    unsigned optimizationLevel;
67    unsigned debugInfoType;
68};
69
70// 1.1 version
71struct glslang_CompileRequest_1_1
72{
73    /// Set from 1.0
74    void set(const glslang_CompileRequest_1_0& in);
75
76    size_t sizeInBytes; ///< Size in bytes of this structure
77
78    // START! Embed the glslang_CompileRequest_1_0 fields
79    char const* sourcePath;
80
81    void const* inputBegin;
82    void const* inputEnd;
83
84    glslang_OutputFunc diagnosticFunc;
85    void* diagnosticUserData;
86
87    glslang_OutputFunc outputFunc;
88    void* outputUserData;
89
90    int slangStage;
91
92    unsigned action;
93
94    unsigned optimizationLevel;
95    unsigned debugInfoType;
96    // END! Embed the glslang_CompileRequest_1_0 fields
97
98    const char* spirvTargetName;    /// A valid TargetName. If null will use universal based on the
99                                    /// spirVersion.
100    glsl_SPIRVVersion spirvVersion; ///< The SPIR-V version. If all are 0 will use the default which
101                                    ///< is 1.2 currently
102};
103
104// 1.2 version
105struct glslang_CompileRequest_1_2
106{
107    /// Set from 1.1
108    void set(const glslang_CompileRequest_1_1& in);
109
110    size_t sizeInBytes; ///< Size in bytes of this structure
111
112    // START! Embed the glslang_CompileRequest_1_0 fields
113    char const* sourcePath;
114
115    void const* inputBegin;
116    void const* inputEnd;
117
118    glslang_OutputFunc diagnosticFunc;
119    void* diagnosticUserData;
120
121    glslang_OutputFunc outputFunc;
122    void* outputUserData;
123
124    int slangStage;
125
126    unsigned action;
127
128    unsigned optimizationLevel;
129    unsigned debugInfoType;
130    // END! Embed the glslang_CompileRequest_1_0 fields
131
132    const char* spirvTargetName;    /// A valid TargetName. If null will use universal based on the
133                                    /// spirVersion.
134    glsl_SPIRVVersion spirvVersion; ///< The SPIR-V version. If all are 0 will use the default which
135                                    ///< is 1.2 currently
136
137    // glslang_CompileRequest_1_2 fields
138    const char* entryPointName; // The name of the entrypoint that will appear in output spirv.
139};
140
141inline void glslang_CompileRequest_1_0::set(const glslang_CompileRequest_1_1& in)
142{
143    SLANG_GLSLANG_COMPILE_REQUEST_1_0(SLANG_GLSLANG_FIELD_COPY)
144}
145
146inline void glslang_CompileRequest_1_1::set(const glslang_CompileRequest_1_0& in)
147{
148    SLANG_GLSLANG_COMPILE_REQUEST_1_0(SLANG_GLSLANG_FIELD_COPY)
149}
150
151inline void glslang_CompileRequest_1_2::set(const glslang_CompileRequest_1_1& in)
152{
153    memcpy(this, &in, sizeof(in));
154}
155
156typedef struct glslang_LinkRequest_t
157{
158    const uint32_t** modules;    // Input: array of pointers to SPIR-V modules
159    const uint32_t* moduleSizes; // Input: array of sizes of SPIR-V modules in 32-bit words
160    int moduleCount;             // Input: number of modules in the array
161    const uint32_t* linkResult;  // Output: pointer to linked SPIR-V module
162    size_t linkResultSize;       // Output: size of the linked SPIR-V module in 32-bit words
163} glslang_LinkRequest;
164
165typedef int (*glslang_CompileFunc_1_0)(glslang_CompileRequest_1_0* request);
166typedef int (*glslang_CompileFunc_1_1)(glslang_CompileRequest_1_1* request);
167typedef int (*glslang_CompileFunc_1_2)(glslang_CompileRequest_1_2* request);
168typedef bool (*glslang_ValidateSPIRVFunc)(const uint32_t* contents, int contentsSize);
169typedef bool (*glslang_DisassembleSPIRVFunc)(const uint32_t* contents, int contentsSize);
170typedef bool (*glslang_DisassembleSPIRVWithResultFunc)(
171    const uint32_t* contents,
172    int contentsSize,
173    char** outString);
174typedef bool (*glslang_LinkSPIRVFunc)(glslang_LinkRequest* request);
175#endif