• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2     This code is based on the glslang_c_interface implementation by Viktor Latypov
3 **/
4 
5 /**
6 BSD 2-Clause License
7 
8 Copyright (c) 2019, Viktor Latypov
9 All rights reserved.
10 
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 
14 1. Redistributions of source code must retain the above copyright notice, this
15    list of conditions and the following disclaimer.
16 
17 2. Redistributions in binary form must reproduce the above copyright notice,
18    this list of conditions and the following disclaimer in the documentation
19    and/or other materials provided with the distribution.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 **/
32 
33 #ifndef GLSLANG_C_IFACE_H_INCLUDED
34 #define GLSLANG_C_IFACE_H_INCLUDED
35 
36 #include <stdbool.h>
37 #include <stdlib.h>
38 
39 #include "glslang_c_shader_types.h"
40 
41 typedef struct glslang_shader_s glslang_shader_t;
42 typedef struct glslang_program_s glslang_program_t;
43 
44 /* TLimits counterpart */
45 typedef struct glslang_limits_s {
46     bool non_inductive_for_loops;
47     bool while_loops;
48     bool do_while_loops;
49     bool general_uniform_indexing;
50     bool general_attribute_matrix_vector_indexing;
51     bool general_varying_indexing;
52     bool general_sampler_indexing;
53     bool general_variable_indexing;
54     bool general_constant_matrix_vector_indexing;
55 } glslang_limits_t;
56 
57 /* TBuiltInResource counterpart */
58 typedef struct glslang_resource_s {
59     int max_lights;
60     int max_clip_planes;
61     int max_texture_units;
62     int max_texture_coords;
63     int max_vertex_attribs;
64     int max_vertex_uniform_components;
65     int max_varying_floats;
66     int max_vertex_texture_image_units;
67     int max_combined_texture_image_units;
68     int max_texture_image_units;
69     int max_fragment_uniform_components;
70     int max_draw_buffers;
71     int max_vertex_uniform_vectors;
72     int max_varying_vectors;
73     int max_fragment_uniform_vectors;
74     int max_vertex_output_vectors;
75     int max_fragment_input_vectors;
76     int min_program_texel_offset;
77     int max_program_texel_offset;
78     int max_clip_distances;
79     int max_compute_work_group_count_x;
80     int max_compute_work_group_count_y;
81     int max_compute_work_group_count_z;
82     int max_compute_work_group_size_x;
83     int max_compute_work_group_size_y;
84     int max_compute_work_group_size_z;
85     int max_compute_uniform_components;
86     int max_compute_texture_image_units;
87     int max_compute_image_uniforms;
88     int max_compute_atomic_counters;
89     int max_compute_atomic_counter_buffers;
90     int max_varying_components;
91     int max_vertex_output_components;
92     int max_geometry_input_components;
93     int max_geometry_output_components;
94     int max_fragment_input_components;
95     int max_image_units;
96     int max_combined_image_units_and_fragment_outputs;
97     int max_combined_shader_output_resources;
98     int max_image_samples;
99     int max_vertex_image_uniforms;
100     int max_tess_control_image_uniforms;
101     int max_tess_evaluation_image_uniforms;
102     int max_geometry_image_uniforms;
103     int max_fragment_image_uniforms;
104     int max_combined_image_uniforms;
105     int max_geometry_texture_image_units;
106     int max_geometry_output_vertices;
107     int max_geometry_total_output_components;
108     int max_geometry_uniform_components;
109     int max_geometry_varying_components;
110     int max_tess_control_input_components;
111     int max_tess_control_output_components;
112     int max_tess_control_texture_image_units;
113     int max_tess_control_uniform_components;
114     int max_tess_control_total_output_components;
115     int max_tess_evaluation_input_components;
116     int max_tess_evaluation_output_components;
117     int max_tess_evaluation_texture_image_units;
118     int max_tess_evaluation_uniform_components;
119     int max_tess_patch_components;
120     int max_patch_vertices;
121     int max_tess_gen_level;
122     int max_viewports;
123     int max_vertex_atomic_counters;
124     int max_tess_control_atomic_counters;
125     int max_tess_evaluation_atomic_counters;
126     int max_geometry_atomic_counters;
127     int max_fragment_atomic_counters;
128     int max_combined_atomic_counters;
129     int max_atomic_counter_bindings;
130     int max_vertex_atomic_counter_buffers;
131     int max_tess_control_atomic_counter_buffers;
132     int max_tess_evaluation_atomic_counter_buffers;
133     int max_geometry_atomic_counter_buffers;
134     int max_fragment_atomic_counter_buffers;
135     int max_combined_atomic_counter_buffers;
136     int max_atomic_counter_buffer_size;
137     int max_transform_feedback_buffers;
138     int max_transform_feedback_interleaved_components;
139     int max_cull_distances;
140     int max_combined_clip_and_cull_distances;
141     int max_samples;
142     int max_mesh_output_vertices_nv;
143     int max_mesh_output_primitives_nv;
144     int max_mesh_work_group_size_x_nv;
145     int max_mesh_work_group_size_y_nv;
146     int max_mesh_work_group_size_z_nv;
147     int max_task_work_group_size_x_nv;
148     int max_task_work_group_size_y_nv;
149     int max_task_work_group_size_z_nv;
150     int max_mesh_view_count_nv;
151     int max_mesh_output_vertices_ext;
152     int max_mesh_output_primitives_ext;
153     int max_mesh_work_group_size_x_ext;
154     int max_mesh_work_group_size_y_ext;
155     int max_mesh_work_group_size_z_ext;
156     int max_task_work_group_size_x_ext;
157     int max_task_work_group_size_y_ext;
158     int max_task_work_group_size_z_ext;
159     int max_mesh_view_count_ext;
160     union
161     {
162         int max_dual_source_draw_buffers_ext;
163 
164         /* Incorrectly capitalized name retained for backward compatibility */
165         int maxDualSourceDrawBuffersEXT;
166     };
167 
168     glslang_limits_t limits;
169 } glslang_resource_t;
170 
171 /* Inclusion result structure allocated by C include_local/include_system callbacks */
172 typedef struct glsl_include_result_s {
173     /* Header file name or NULL if inclusion failed */
174     const char* header_name;
175 
176     /* Header contents or NULL */
177     const char* header_data;
178     size_t header_length;
179 
180 } glsl_include_result_t;
181 
182 /* Callback for local file inclusion */
183 typedef glsl_include_result_t* (*glsl_include_local_func)(void* ctx, const char* header_name, const char* includer_name,
184                                                           size_t include_depth);
185 
186 /* Callback for system file inclusion */
187 typedef glsl_include_result_t* (*glsl_include_system_func)(void* ctx, const char* header_name,
188                                                            const char* includer_name, size_t include_depth);
189 
190 /* Callback for include result destruction */
191 typedef int (*glsl_free_include_result_func)(void* ctx, glsl_include_result_t* result);
192 
193 /* Collection of callbacks for GLSL preprocessor */
194 typedef struct glsl_include_callbacks_s {
195     glsl_include_system_func include_system;
196     glsl_include_local_func include_local;
197     glsl_free_include_result_func free_include_result;
198 } glsl_include_callbacks_t;
199 
200 typedef struct glslang_input_s {
201     glslang_source_t language;
202     glslang_stage_t stage;
203     glslang_client_t client;
204     glslang_target_client_version_t client_version;
205     glslang_target_language_t target_language;
206     glslang_target_language_version_t target_language_version;
207     /** Shader source code */
208     const char* code;
209     int default_version;
210     glslang_profile_t default_profile;
211     int force_default_version_and_profile;
212     int forward_compatible;
213     glslang_messages_t messages;
214     const glslang_resource_t* resource;
215     glsl_include_callbacks_t callbacks;
216     void* callbacks_ctx;
217 } glslang_input_t;
218 
219 /* SpvOptions counterpart */
220 typedef struct glslang_spv_options_s {
221     bool generate_debug_info;
222     bool strip_debug_info;
223     bool disable_optimizer;
224     bool optimize_size;
225     bool disassemble;
226     bool validate;
227     bool emit_nonsemantic_shader_debug_info;
228     bool emit_nonsemantic_shader_debug_source;
229     bool compile_only;
230 } glslang_spv_options_t;
231 
232 #ifdef __cplusplus
233 extern "C" {
234 #endif
235 
236 #ifdef GLSLANG_IS_SHARED_LIBRARY
237     #ifdef _WIN32
238         #ifdef GLSLANG_EXPORTING
239             #define GLSLANG_EXPORT __declspec(dllexport)
240         #else
241             #define GLSLANG_EXPORT __declspec(dllimport)
242         #endif
243     #elif __GNUC__ >= 4
244         #define GLSLANG_EXPORT __attribute__((visibility("default")))
245     #endif
246 #endif // GLSLANG_IS_SHARED_LIBRARY
247 
248 #ifndef GLSLANG_EXPORT
249 #define GLSLANG_EXPORT
250 #endif
251 
252 GLSLANG_EXPORT int glslang_initialize_process(void);
253 GLSLANG_EXPORT void glslang_finalize_process(void);
254 
255 GLSLANG_EXPORT glslang_shader_t* glslang_shader_create(const glslang_input_t* input);
256 GLSLANG_EXPORT void glslang_shader_delete(glslang_shader_t* shader);
257 GLSLANG_EXPORT void glslang_shader_set_preamble(glslang_shader_t* shader, const char* s);
258 GLSLANG_EXPORT void glslang_shader_shift_binding(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base);
259 GLSLANG_EXPORT void glslang_shader_shift_binding_for_set(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base, unsigned int set);
260 GLSLANG_EXPORT void glslang_shader_set_options(glslang_shader_t* shader, int options); // glslang_shader_options_t
261 GLSLANG_EXPORT void glslang_shader_set_glsl_version(glslang_shader_t* shader, int version);
262 GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input);
263 GLSLANG_EXPORT int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input);
264 GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);
265 GLSLANG_EXPORT const char* glslang_shader_get_info_log(glslang_shader_t* shader);
266 GLSLANG_EXPORT const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader);
267 
268 GLSLANG_EXPORT glslang_program_t* glslang_program_create(void);
269 GLSLANG_EXPORT void glslang_program_delete(glslang_program_t* program);
270 GLSLANG_EXPORT void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader);
271 GLSLANG_EXPORT int glslang_program_link(glslang_program_t* program, int messages); // glslang_messages_t
272 GLSLANG_EXPORT void glslang_program_add_source_text(glslang_program_t* program, glslang_stage_t stage, const char* text, size_t len);
273 GLSLANG_EXPORT void glslang_program_set_source_file(glslang_program_t* program, glslang_stage_t stage, const char* file);
274 GLSLANG_EXPORT int glslang_program_map_io(glslang_program_t* program);
275 GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage);
276 GLSLANG_EXPORT void glslang_program_SPIRV_generate_with_options(glslang_program_t* program, glslang_stage_t stage, glslang_spv_options_t* spv_options);
277 GLSLANG_EXPORT size_t glslang_program_SPIRV_get_size(glslang_program_t* program);
278 GLSLANG_EXPORT void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*);
279 GLSLANG_EXPORT unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program);
280 GLSLANG_EXPORT const char* glslang_program_SPIRV_get_messages(glslang_program_t* program);
281 GLSLANG_EXPORT const char* glslang_program_get_info_log(glslang_program_t* program);
282 GLSLANG_EXPORT const char* glslang_program_get_info_debug_log(glslang_program_t* program);
283 
284 #ifdef __cplusplus
285 }
286 #endif
287 
288 #endif /* #ifdef GLSLANG_C_IFACE_INCLUDED */
289