1 // Copyright 2018 The Shaderc Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHADERC_SPVC_H_
16 #define SHADERC_SPVC_H_
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <stdint.h>
25 
26 #include "shaderc/env.h"
27 #include "shaderc/status.h"
28 #include "shaderc/visibility.h"
29 
30 // SPIR-V decorations supported by spvc. This is not an exhaustive list of all
31 // of the values in the spec, but more can be added if needed.
32 typedef enum {
33   shaderc_spvc_decoration_specid,
34   shaderc_spvc_decoration_block,
35   shaderc_spvc_decoration_rowmajor,
36   shaderc_spvc_decoration_colmajor,
37   shaderc_spvc_decoration_arraystride,
38   shaderc_spvc_decoration_matrixstride,
39   shaderc_spvc_decoration_builtin,
40   shaderc_spvc_decoration_noperspective,
41   shaderc_spvc_decoration_flat,
42   shaderc_spvc_decoration_centroid,
43   shaderc_spvc_decoration_restrict,
44   shaderc_spvc_decoration_aliased,
45   shaderc_spvc_decoration_nonwritable,
46   shaderc_spvc_decoration_nonreadable,
47   shaderc_spvc_decoration_uniform,
48   shaderc_spvc_decoration_location,
49   shaderc_spvc_decoration_component,
50   shaderc_spvc_decoration_index,
51   shaderc_spvc_decoration_binding,
52   shaderc_spvc_decoration_descriptorset,
53   shaderc_spvc_decoration_offset,
54   shaderc_spvc_decoration_nocontraction,
55 } shaderc_spvc_decoration;
56 
57 // Backwards compatiblity enum for Dawn. This will be removed once Dawn no
58 // longer depends on it.
59 #define SHADERC_SPVC_DECORATION_BINDING shaderc_spvc_decoration_binding
60 
61 typedef enum {
62   shaderc_spvc_msl_platform_ios,
63   shaderc_spvc_msl_platform_macos,
64 } shaderc_spvc_msl_platform;
65 
66 // Return code for spvc API calls. shaderc_spvc_status_success indicates success
67 // completion of the operation, all others indicate some sort of failure.
68 typedef enum {
69   shaderc_spvc_status_success,
70   shaderc_spvc_status_compilation_error,
71   shaderc_spvc_status_internal_error,
72   shaderc_spvc_status_validation_error,
73   shaderc_spvc_status_transformation_error,
74   shaderc_spvc_status_configuration_error,
75   shaderc_spvc_status_uninitialized_compiler_error,
76   shaderc_spvc_status_missing_context_error,
77   shaderc_spvc_status_invalid_out_param,
78   shaderc_spvc_status_missing_options_error,
79   shaderc_spvc_status_invalid_in_param,
80   shaderc_spvc_status_missing_result_error,
81 } shaderc_spvc_status;
82 
83 typedef enum {
84   shaderc_spvc_execution_model_vertex,
85   shaderc_spvc_execution_model_fragment,
86   shaderc_spvc_execution_model_glcompute,
87   shaderc_spvc_execution_model_invalid,
88 } shaderc_spvc_execution_model;
89 
90 typedef enum {
91   shaderc_spvc_binding_type_uniform_buffer = 0x00000000,
92   shaderc_spvc_binding_type_storage_buffer = 0x00000001,
93   shaderc_spvc_binding_type_readonly_storage_buffer = 0x00000002,
94   shaderc_spvc_binding_type_sampler = 0x00000003,
95   shaderc_spvc_binding_type_sampled_texture = 0x00000004,
96   shaderc_spvc_binding_type_storage_texture = 0x00000005,
97   shaderc_spvc_binding_type_readonly_storage_texture = 0x00000006,
98   shaderc_spvc_binding_type_writeonly_storage_texture = 0x00000007,
99 } shaderc_spvc_binding_type;
100 
101 typedef enum {
102   shaderc_spvc_texture_view_dimension_undefined = 0x00000000,
103   shaderc_spvc_texture_view_dimension_e1D = 0x00000001,
104   shaderc_spvc_texture_view_dimension_e2D = 0x00000002,
105   shaderc_spvc_texture_view_dimension_e2D_array = 0x00000003,
106   shaderc_spvc_texture_view_dimension_cube = 0x00000004,
107   shaderc_spvc_texture_view_dimension_cube_array = 0x00000005,
108   shaderc_spvc_texture_view_dimension_e3D = 0x00000006,
109 } shaderc_spvc_texture_view_dimension;
110 
111 typedef enum {
112   shaderc_spvc_texture_format_type_float,
113   shaderc_spvc_texture_format_type_sint,
114   shaderc_spvc_texture_format_type_uint,
115   shaderc_spvc_texture_format_type_other,
116 } shaderc_spvc_texture_format_type;
117 
118 typedef enum {
119   shaderc_spvc_shader_resource_uniform_buffers,
120   shaderc_spvc_shader_resource_separate_images,
121   shaderc_spvc_shader_resource_separate_samplers,
122   shaderc_spvc_shader_resource_storage_buffers,
123   shaderc_spvc_shader_resource_storage_images,
124 } shaderc_spvc_shader_resource;
125 
126 typedef enum {
127   shaderc_spvc_storage_texture_format_undefined = 0x00000000,
128   shaderc_spvc_storage_texture_format_r8unorm = 0x00000001,
129   shaderc_spvc_storage_texture_format_r8snorm = 0x00000002,
130   shaderc_spvc_storage_texture_format_r8uint = 0x00000003,
131   shaderc_spvc_storage_texture_format_r8sint = 0x00000004,
132   shaderc_spvc_storage_texture_format_r16uint = 0x00000005,
133   shaderc_spvc_storage_texture_format_r16sint = 0x00000006,
134   shaderc_spvc_storage_texture_format_r16float = 0x00000007,
135   shaderc_spvc_storage_texture_format_rg8unorm = 0x00000008,
136   shaderc_spvc_storage_texture_format_rg8snorm = 0x00000009,
137   shaderc_spvc_storage_texture_format_rg8uint = 0x0000000a,
138   shaderc_spvc_storage_texture_format_rg8sint = 0x0000000b,
139   shaderc_spvc_storage_texture_format_r32float = 0x0000000c,
140   shaderc_spvc_storage_texture_format_r32uint = 0x0000000d,
141   shaderc_spvc_storage_texture_format_r32sint = 0x0000000e,
142   shaderc_spvc_storage_texture_format_rg16uint = 0x0000000f,
143   shaderc_spvc_storage_texture_format_rg16sint = 0x00000010,
144   shaderc_spvc_storage_texture_format_rg16float = 0x00000011,
145   shaderc_spvc_storage_texture_format_rgba8unorm = 0x00000012,
146   shaderc_spvc_storage_texture_format_rgba8unormsrgb = 0x00000013,
147   shaderc_spvc_storage_texture_format_rgba8snorm = 0x00000014,
148   shaderc_spvc_storage_texture_format_rgba8uint = 0x00000015,
149   shaderc_spvc_storage_texture_format_rgba8sint = 0x00000016,
150   shaderc_spvc_storage_texture_format_bgra8unorm = 0x00000017,
151   shaderc_spvc_storage_texture_format_bgra8unormsrgb = 0x00000018,
152   shaderc_spvc_storage_texture_format_rgb10a2unorm = 0x00000019,
153   shaderc_spvc_storage_texture_format_rg11b10float = 0x0000001A,
154   shaderc_spvc_storage_texture_format_rg32float = 0x0000001B,
155   shaderc_spvc_storage_texture_format_rg32uint = 0x0000001C,
156   shaderc_spvc_storage_texture_format_rg32sint = 0x0000001D,
157   shaderc_spvc_storage_texture_format_rgba16uint = 0x0000001E,
158   shaderc_spvc_storage_texture_format_rgba16sint = 0x0000001F,
159   shaderc_spvc_storage_texture_format_rgba16float = 0x00000020,
160   shaderc_spvc_storage_texture_format_rgba32float = 0x00000021,
161   shaderc_spvc_storage_texture_format_rgba32uint = 0x00000022,
162   shaderc_spvc_storage_texture_format_rgba32sint = 0x00000023,
163   shaderc_spvc_storage_texture_format_depth32float = 0x00000024,
164   shaderc_spvc_storage_texture_format_depth24plus = 0x00000025,
165   shaderc_spvc_storage_texture_format_depth24plusstencil8 = 0x00000026,
166   shaderc_spvc_storage_texture_format_bc1rgbaunorm = 0x00000027,
167   shaderc_spvc_storage_texture_format_bc1rgbaunormsrgb = 0x00000028,
168   shaderc_spvc_storage_texture_format_bc2rgbaunorm = 0x00000029,
169   shaderc_spvc_storage_texture_format_bc2rgbaunormsrgb = 0x0000002A,
170   shaderc_spvc_storage_texture_format_bc3rgbaunorm = 0x0000002B,
171   shaderc_spvc_storage_texture_format_bc3rgbaunormsrgb = 0x0000002C,
172   shaderc_spvc_storage_texture_format_bc4runorm = 0x0000002D,
173   shaderc_spvc_storage_texture_format_bc4rsnorm = 0x0000002E,
174   shaderc_spvc_storage_texture_format_bc5rgunorm = 0x0000002F,
175   shaderc_spvc_storage_texture_format_bc5rgsnorm = 0x00000030,
176   shaderc_spvc_storage_texture_format_bc6hrgbufloat = 0x00000031,
177   shaderc_spvc_storage_texture_format_bc6hrgbsfloat = 0x00000032,
178   shaderc_spvc_storage_texture_format_bc7rgbaunorm = 0x00000033,
179   shaderc_spvc_storage_texture_format_bc7rgbaunormsrgb = 0x00000034,
180 } shaderc_spvc_storage_texture_format;
181 
182 typedef enum {
183   shaderc_spvc_spv_env_universal_1_0,
184   shaderc_spvc_spv_env_vulkan_1_0,
185   shaderc_spvc_spv_env_universal_1_1,
186   shaderc_spvc_spv_env_opencl_2_1,
187   shaderc_spvc_spv_env_opencl_2_2,
188   shaderc_spvc_spv_env_opengl_4_0,
189   shaderc_spvc_spv_env_opengl_4_1,
190   shaderc_spvc_spv_env_opengl_4_2,
191   shaderc_spvc_spv_env_opengl_4_3,
192   shaderc_spvc_spv_env_opengl_4_5,
193   shaderc_spvc_spv_env_universal_1_2,
194   shaderc_spvc_spv_env_opencl_1_2,
195   shaderc_spvc_spv_env_opencl_embedded_1_2,
196   shaderc_spvc_spv_env_opencl_2_0,
197   shaderc_spvc_spv_env_opencl_embedded_2_0,
198   shaderc_spvc_spv_env_opencl_embedded_2_1,
199   shaderc_spvc_spv_env_opencl_embedded_2_2,
200   shaderc_spvc_spv_env_universal_1_3,
201   shaderc_spvc_spv_env_vulkan_1_1,
202   shaderc_spvc_spv_env_webgpu_0,
203   shaderc_spvc_spv_env_universal_1_4,
204   shaderc_spvc_spv_env_vulkan_1_1_spirv_1_4,
205   shaderc_spvc_spv_env_universal_1_5,
206   shaderc_spvc_spv_env_vulkan_1_2,
207 } shaderc_spvc_spv_env;
208 
209 // An opaque handle to an object that manages all compiler state.
210 typedef struct shaderc_spvc_context* shaderc_spvc_context_t;
211 
212 typedef struct {
213   uint32_t combined_id;
214   uint32_t image_id;
215   uint32_t sampler_id;
216 } shaderc_spvc_combined_image_sampler;
217 
218 typedef struct {
219   shaderc_spvc_execution_model stage;
220   uint32_t desc_set;
221   uint32_t binding;
222   uint32_t msl_buffer;
223   uint32_t msl_texture;
224   uint32_t msl_sampler;
225 } shaderc_spvc_msl_resource_binding;
226 
227 typedef struct {
228   uint32_t x;
229   uint32_t y;
230   uint32_t z;
231   uint32_t constant;
232 } shaderc_spvc_workgroup_size;
233 
234 typedef struct {
235   uint32_t set;
236   uint32_t binding;
237   uint32_t id;
238   uint32_t base_type_id;
239   shaderc_spvc_binding_type binding_type;
240   shaderc_spvc_texture_view_dimension texture_dimension;
241   shaderc_spvc_texture_format_type texture_component_type;
242   bool multisampled;
243   shaderc_spvc_storage_texture_format storage_texture_format;
244 } shaderc_spvc_binding_info;
245 
246 typedef struct {
247   uint32_t id;
248   bool has_location;
249   uint32_t location;
250 } shaderc_spvc_resource_location_info;
251 
252 typedef struct {
253   uint32_t location;
254   shaderc_spvc_texture_format_type type;
255 } shaderc_spvc_resource_type_info;
256 
257 // Create a spvc state handle.  A return of NULL indicates that there was an
258 // error. Any function operating on a *_context_t must offer the basic
259 // thread-safety guarantee.
260 // [http://herbsutter.com/2014/01/13/gotw-95-solution-thread-safety-and-synchronization/]
261 // That is: concurrent invocation of these functions on DIFFERENT objects needs
262 // no synchronization; concurrent invocation of these functions on the SAME
263 // object requires synchronization IF AND ONLY IF some of them take a non-const
264 // argument.
265 SHADERC_EXPORT shaderc_spvc_context_t shaderc_spvc_context_create(void);
266 
267 // Release resources.  After this the handle cannot be used.
268 SHADERC_EXPORT void shaderc_spvc_context_destroy(
269     shaderc_spvc_context_t context);
270 
271 // Get validation/compilation error or informational messages.
272 SHADERC_EXPORT const char* shaderc_spvc_context_get_messages(
273     const shaderc_spvc_context_t context);
274 
275 // EXPERIMENTAL
276 // Get spirv_cross compiler reference, does NOT transfer ownership.
277 // Return type is actually spirv_cross::Compiler*, but cannot have that in the
278 // C API.
279 // This is being exposed temporarily to ease integration of spvc into Dawn, but
280 // this is will be removed in the future without warning.
281 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_context_get_compiler(
282     const shaderc_spvc_context_t context, void** compiler);
283 
284 // If true, use spvc built in parser to generate IR for spirv-cross, otherwise
285 // use spirv-cross's implementation.
286 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_context_set_use_spvc_parser(
287     shaderc_spvc_context_t context, bool b);
288 
289 // An opaque handle to an object that manages options to a single compilation
290 // result.
291 typedef struct shaderc_spvc_compile_options* shaderc_spvc_compile_options_t;
292 
293 // Creates default compiler options.
294 // A return of NULL indicates that there was an error initializing the options.
295 // Any function operating on shaderc_spvc_compile_options_t must offer the
296 // basic thread-safety guarantee.
297 SHADERC_EXPORT shaderc_spvc_compile_options_t
298 shaderc_spvc_compile_options_create(shaderc_spvc_spv_env source_env,
299                                     shaderc_spvc_spv_env target_env);
300 
301 // Returns a copy of the given options.
302 SHADERC_EXPORT shaderc_spvc_compile_options_t
303 shaderc_spvc_compile_options_clone(
304     const shaderc_spvc_compile_options_t options);
305 
306 // Destroys the compilation options. It is invalid to use the given
307 // option object in any future calls. It is safe to pass
308 // NULL to this function, and doing such will have no effect.
309 SHADERC_EXPORT void shaderc_spvc_compile_options_destroy(
310     shaderc_spvc_compile_options_t options);
311 
312 // DEPRECATED
313 // Sets the source shader environment, affecting which warnings or errors will
314 // be issued during validation.
315 // Default value for environment is Vulkan 1.0.
316 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_source_env(
317     shaderc_spvc_compile_options_t options, shaderc_target_env env,
318     shaderc_env_version version);
319 
320 // DEPRECATED
321 // Sets the target shader environment, if this is different from the source
322 // environment, then a transform between the environments will be performed if
323 // possible. Currently only WebGPU <-> Vulkan 1.1 are defined.
324 // Default value for environment is Vulkan 1.0.
325 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_target_env(
326     shaderc_spvc_compile_options_t options, shaderc_target_env env,
327     shaderc_env_version version);
328 
329 // Sets the entry point.
330 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_entry_point(
331     shaderc_spvc_compile_options_t options, const char* entry_point);
332 
333 // If true, unused variables will not appear in the output.
334 SHADERC_EXPORT shaderc_spvc_status
335 shaderc_spvc_compile_options_set_remove_unused_variables(
336     shaderc_spvc_compile_options_t options, bool b);
337 
338 // If true, enable robust buffer access pass in the spirv-opt, meaning:
339 // Inject code to clamp indexed accesses to buffers and internal
340 // arrays, providing guarantees satisfying Vulkan's robustBufferAccess rules.
341 // This is useful when an implementation does not support robust-buffer access
342 // as a driver option.
343 SHADERC_EXPORT shaderc_spvc_status
344 shaderc_spvc_compile_options_set_robust_buffer_access_pass(
345     shaderc_spvc_compile_options_t options, bool b);
346 
347 SHADERC_EXPORT shaderc_spvc_status
348 shaderc_spvc_compile_options_set_emit_line_directives(
349     shaderc_spvc_compile_options_t options, bool b);
350 
351 // If true, Vulkan GLSL features are used instead of GL-compatible features.
352 SHADERC_EXPORT shaderc_spvc_status
353 shaderc_spvc_compile_options_set_vulkan_semantics(
354     shaderc_spvc_compile_options_t options, bool b);
355 
356 // If true, gl_PerVertex is explicitly redeclared in vertex, geometry and
357 // tessellation shaders. The members of gl_PerVertex is determined by which
358 // built-ins are declared by the shader.
359 SHADERC_EXPORT shaderc_spvc_status
360 shaderc_spvc_compile_options_set_separate_shader_objects(
361     shaderc_spvc_compile_options_t options, bool b);
362 
363 // Flatten uniform or push constant variable into (i|u)vec4 array.
364 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_flatten_ubo(
365     shaderc_spvc_compile_options_t options, bool b);
366 
367 // Set GLSL language version.  Default is 450 (i.e. 4.5).
368 SHADERC_EXPORT shaderc_spvc_status
369 shaderc_spvc_compile_options_set_glsl_language_version(
370     shaderc_spvc_compile_options_t options, uint32_t version);
371 
372 // If true, flatten multidimensional arrays, e.g. foo[a][b][c] -> foo[a*b*c].
373 // Default is false.
374 SHADERC_EXPORT shaderc_spvc_status
375 shaderc_spvc_compile_options_set_flatten_multidimensional_arrays(
376     shaderc_spvc_compile_options_t options, bool b);
377 
378 // If true, initialize new variables from cross-compile to 0 if possible.
379 // Default is false.
380 SHADERC_EXPORT shaderc_spvc_status
381 shaderc_spvc_compile_options_set_force_zero_initialized_variables(
382     shaderc_spvc_compile_options_t options, bool b);
383 
384 // Force interpretion as ES, or not.  Default is to detect from source.
385 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_es(
386     shaderc_spvc_compile_options_t options, bool b);
387 
388 // If true, emit push constants as uniform buffer objects.  Default is false.
389 SHADERC_EXPORT shaderc_spvc_status
390 shaderc_spvc_compile_options_set_glsl_emit_push_constant_as_ubo(
391     shaderc_spvc_compile_options_t options, bool b);
392 
393 // Set MSL language version.  Default is 10200 (i.e. 1.2).
394 SHADERC_EXPORT shaderc_spvc_status
395 shaderc_spvc_compile_options_set_msl_language_version(
396     shaderc_spvc_compile_options_t options, uint32_t version);
397 
398 // If true, swizzle MSL texture samples.  Default is false.
399 SHADERC_EXPORT shaderc_spvc_status
400 shaderc_spvc_compile_options_set_msl_swizzle_texture_samples(
401     shaderc_spvc_compile_options_t options, bool b);
402 
403 // Choose MSL platform.  Default is MacOS.
404 SHADERC_EXPORT shaderc_spvc_status
405 shaderc_spvc_compile_options_set_msl_platform(
406     shaderc_spvc_compile_options_t options, shaderc_spvc_msl_platform platform);
407 
408 // If true, pad MSL fragment output.  Default is false.
409 SHADERC_EXPORT shaderc_spvc_status
410 shaderc_spvc_compile_options_set_msl_pad_fragment_output(
411     shaderc_spvc_compile_options_t options, bool b);
412 
413 // If true, capture MSL output to buffer.  Default is false.
414 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_msl_capture(
415     shaderc_spvc_compile_options_t options, bool b);
416 
417 // If true, flip the Y-coord of the built-in "TessCoord."  Default is top left.
418 SHADERC_EXPORT shaderc_spvc_status
419 shaderc_spvc_compile_options_set_msl_domain_lower_left(
420     shaderc_spvc_compile_options_t options, bool b);
421 
422 // Enable use of MSL 2.0 indirect argument buffers.  Default is not to use them.
423 SHADERC_EXPORT shaderc_spvc_status
424 shaderc_spvc_compile_options_set_msl_argument_buffers(
425     shaderc_spvc_compile_options_t options, bool b);
426 
427 // When using MSL argument buffers, force "classic" MSL 1.0 binding for the
428 // given descriptor sets. This corresponds to VK_KHR_push_descriptor in Vulkan.
429 SHADERC_EXPORT shaderc_spvc_status
430 shaderc_spvc_compile_options_set_msl_discrete_descriptor_sets(
431     shaderc_spvc_compile_options_t options, const uint32_t* descriptors,
432     size_t num_descriptors);
433 
434 // Set whether or not PointSize builtin is used for MSL shaders
435 SHADERC_EXPORT shaderc_spvc_status
436 shaderc_spvc_compile_options_set_msl_enable_point_size_builtin(
437     shaderc_spvc_compile_options_t options, bool b);
438 
439 // Set the index in the buffer size in the buffer for MSL
440 SHADERC_EXPORT shaderc_spvc_status
441 shaderc_spvc_compile_options_set_msl_buffer_size_buffer_index(
442     shaderc_spvc_compile_options_t options, uint32_t index);
443 
444 // Set HLSL shader model.  Default is 30.
445 SHADERC_EXPORT shaderc_spvc_status
446 shaderc_spvc_compile_options_set_hlsl_shader_model(
447     shaderc_spvc_compile_options_t options, uint32_t model);
448 
449 // If true, ignore PointSize.  Default is false.
450 SHADERC_EXPORT shaderc_spvc_status
451 shaderc_spvc_compile_options_set_hlsl_point_size_compat(
452     shaderc_spvc_compile_options_t options, bool b);
453 
454 // If true, ignore PointCoord.  Default is false.
455 SHADERC_EXPORT shaderc_spvc_status
456 shaderc_spvc_compile_options_set_hlsl_point_coord_compat(
457     shaderc_spvc_compile_options_t options, bool b);
458 
459 // If true (default is false):
460 //   GLSL: map depth from Vulkan/D3D style to GL style, i.e. [ 0,w] -> [-w,w]
461 //   MSL : map depth from GL style to Vulkan/D3D style, i.e. [-w,w] -> [ 0,w]
462 //   HLSL: map depth from GL style to Vulkan/D3D style, i.e. [-w,w] -> [ 0,w]
463 SHADERC_EXPORT shaderc_spvc_status
464 shaderc_spvc_compile_options_set_fixup_clipspace(
465     shaderc_spvc_compile_options_t options, bool b);
466 
467 // If true invert gl_Position.y or equivalent.  Default is false.
468 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_flip_vert_y(
469     shaderc_spvc_compile_options_t options, bool b);
470 
471 // Set if validation should be performed. Default is true.
472 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_validate(
473     shaderc_spvc_compile_options_t options, bool b);
474 
475 // Set if optimization should be performed. Default is true.
476 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_optimize(
477     shaderc_spvc_compile_options_t options, bool b);
478 
479 // Fill options with given data.  Return amount of data used, or zero
480 // if not enough data was given.
481 SHADERC_EXPORT size_t shaderc_spvc_compile_options_set_for_fuzzing(
482     shaderc_spvc_compile_options_t options, const uint8_t* data, size_t size);
483 
484 // An opaque handle to the results of a call to any
485 // shaderc_spvc_*_compile_*() function.
486 typedef struct shaderc_spvc_compilation_result*
487     shaderc_spvc_compilation_result_t;
488 
489 // Takes SPIR-V as a sequence of 32-bit words, validates it, then creates the
490 // internal compiler for translating to GLSL and performing reflection.
491 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_initialize_for_glsl(
492     const shaderc_spvc_context_t context, const uint32_t* source,
493     size_t source_len, shaderc_spvc_compile_options_t options);
494 
495 // Takes SPIR-V as a sequence of 32-bit words, validates it, then creates the
496 // internal compiler for translating to HLSL and performing reflection.
497 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_initialize_for_hlsl(
498     const shaderc_spvc_context_t context, const uint32_t* source,
499     size_t source_len, shaderc_spvc_compile_options_t options);
500 
501 // Takes SPIR-V as a sequence of 32-bit words, validates it, then creates the
502 // internal compiler for translating to MSL and performing reflection.
503 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_initialize_for_msl(
504     const shaderc_spvc_context_t context, const uint32_t* source,
505     size_t source_len, shaderc_spvc_compile_options_t options);
506 
507 // Takes SPIR-V as a sequence of 32-bit words, validates it, then creates the
508 // internal compiler for translating to Vulkan and performing reflection.
509 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_initialize_for_vulkan(
510     const shaderc_spvc_context_t context, const uint32_t* source,
511     size_t source_len, shaderc_spvc_compile_options_t options);
512 
513 // Given an initialized compiler, generates a shader of the appropriate
514 // language.
515 SHADERC_EXPORT shaderc_spvc_status
516 shaderc_spvc_compile_shader(const shaderc_spvc_context_t context,
517                             shaderc_spvc_compilation_result_t result);
518 
519 // Get spirv_cross decoration (added for GLSL API support in Dawn)
520 // Given an id and a decoration, result is sent out through |argument|
521 // if |id| does not exist, returns an error.
522 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_decoration(
523     const shaderc_spvc_context_t context, uint32_t id,
524     shaderc_spvc_decoration decoration, uint32_t* value);
525 
526 // Unset spirv_cross decoration (added for GLSL API support in Dawn)
527 // Given an id and a decoration. Assuming |id| is valid.
528 SHADERC_EXPORT shaderc_spvc_status
529 shaderc_spvc_unset_decoration(const shaderc_spvc_context_t context, uint32_t id,
530                               shaderc_spvc_decoration decoration);
531 
532 // Set |name| on a given |id| (added for GLSL API support in Dawn)
533 // Assuming |id| is valid.
534 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_set_name(
535     const shaderc_spvc_context_t context, uint32_t id, const char* name);
536 
537 // spirv-cross comment:
538 // Analyzes all separate image and samplers used from the currently selected
539 // entry point, and re-routes them all to a combined image sampler instead.
540 // (added for GLSL API support in Dawn)
541 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_build_combined_image_samplers(
542     const shaderc_spvc_context_t context);
543 
544 // Returns the combined image samplers.
545 
546 // If |samples| is NULL, then num_samplers is set, and no data is copied.
547 // The caller is responsible for |samplers| being large enough to
548 // contain all of the data.
549 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_combined_image_samplers(
550     const shaderc_spvc_context_t context,
551     shaderc_spvc_combined_image_sampler* samplers, size_t* num_samplers);
552 
553 // Set spirv_cross decoration (added for HLSL support in Dawn)
554 // Given an id, decoration and argument, the decoration flag on the id is set
555 // Assuming id is valid.
556 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_set_decoration(
557     const shaderc_spvc_context_t context, uint32_t id,
558     shaderc_spvc_decoration decoration, uint32_t argument);
559 
560 // Adds a binding to indicate the MSL buffer, texture or sampler index to use
561 // for a particular SPIR-V description set and binding.
562 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_add_msl_resource_binding(
563     const shaderc_spvc_context_t context,
564     const shaderc_spvc_msl_resource_binding binding);
565 
566 // Gets workgroup size for an entry point defined by a given execution model and
567 // function name.
568 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_workgroup_size(
569     const shaderc_spvc_context_t context, const char* function_name,
570     shaderc_spvc_execution_model execution_model,
571     shaderc_spvc_workgroup_size* workgroup_size);
572 
573 // Gets whether or not the shader needes a buffer of buffer sizes.
574 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_needs_buffer_size_buffer(
575     const shaderc_spvc_context_t context, bool* b);
576 
577 // Gets the execution model for the shader parsed by the compiler.
578 SHADERC_EXPORT shaderc_spvc_status
579 shaderc_spvc_get_execution_model(const shaderc_spvc_context_t context,
580                                  shaderc_spvc_execution_model* execution_model);
581 
582 // Gets the number of push constants buffers used by the shader.
583 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_push_constant_buffer_count(
584     const shaderc_spvc_context_t context, size_t* count);
585 
586 // Fetches all of the binding info for a given shader resource.
587 // If |bindings| is null, then |binding_count| is populated with the number of
588 // entries that would have been written out.
589 // The caller is responsible for ensuring that |bindings| has enough space
590 // allocated to contain all of the entries.
591 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_binding_info(
592     const shaderc_spvc_context_t context, shaderc_spvc_shader_resource resource,
593     shaderc_spvc_binding_type binding_type, shaderc_spvc_binding_info* bindings,
594     size_t* binding_count);
595 
596 // Fetches the Location decoration information for the stage inputs.
597 // If |locations| is null, then |location_count| is populated with the number of
598 // entries that would have been written out.
599 // The caller is responsible for ensuring that |locations| has enough space
600 // allocated to contain all of the entries.
601 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_input_stage_location_info(
602     const shaderc_spvc_context_t context,
603     shaderc_spvc_resource_location_info* locations, size_t* location_count);
604 
605 // Fetches the Location decoration information for the stage outputs.
606 // If |locations| is null, then |location_count| is populated with the number of
607 // entries that would have been written out.
608 // The caller is responsible for ensuring that |locations| has enough space
609 // allocated to contain all of the entries.
610 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_output_stage_location_info(
611     const shaderc_spvc_context_t context,
612     shaderc_spvc_resource_location_info* locations, size_t* location_count);
613 
614 // Fetches the type information for the stage outputs.
615 // If |types| is null, then |type_count| is populated with the number of
616 // entries that would have been written out.
617 // The caller is responsible for ensuring that |types| has enough space
618 // allocated to contain all of the entries.
619 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_output_stage_type_info(
620     const shaderc_spvc_context_t context,
621     shaderc_spvc_resource_type_info* types, size_t* type_count);
622 
623 // The following functions, operating on shaderc_spvc_compilation_result_t
624 // objects, offer only the basic thread-safety guarantee.
625 
626 // Creates an instant of compiliation result data structure.
627 // A return of NULL indicates that there was an error creating the structure.
628 // Any function operating on shaderc_spvc_compilation_result_t must offer the
629 // basic thread-safety guarantee.
630 SHADERC_EXPORT shaderc_spvc_compilation_result_t
631 shaderc_spvc_result_create(void);
632 
633 // Destroys the resources held by the result object. It is invalid to use the
634 // result object for any further operations.
635 SHADERC_EXPORT void shaderc_spvc_result_destroy(
636     shaderc_spvc_compilation_result_t result);
637 
638 // Get validation/compilation result as a string. This is only supported
639 // compiling to GLSL, HSL, and MSL.
640 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_result_get_string_output(
641     const shaderc_spvc_compilation_result_t result, const char** str);
642 
643 // Get validation/compilation result as a binary buffer. This is only supported
644 // compiling to Vulkan.
645 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_result_get_binary_output(
646     const shaderc_spvc_compilation_result_t result, const uint32_t** data);
647 
648 // Get length of validation/compilation result as a binary buffer. This is only
649 // supported compiling to Vulkan.
650 SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_result_get_binary_length(
651     const shaderc_spvc_compilation_result_t result, uint32_t* len);
652 
653 #ifdef __cplusplus
654 }
655 #endif  // __cplusplus
656 
657 #endif  // SHADERC_SPVC_H_
658