• 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     int maxDualSourceDrawBuffersEXT;
161 
162     glslang_limits_t limits;
163 } glslang_resource_t;
164 
165 typedef struct glslang_input_s {
166     glslang_source_t language;
167     glslang_stage_t stage;
168     glslang_client_t client;
169     glslang_target_client_version_t client_version;
170     glslang_target_language_t target_language;
171     glslang_target_language_version_t target_language_version;
172     /** Shader source code */
173     const char* code;
174     int default_version;
175     glslang_profile_t default_profile;
176     int force_default_version_and_profile;
177     int forward_compatible;
178     glslang_messages_t messages;
179     const glslang_resource_t* resource;
180 } glslang_input_t;
181 
182 /* Inclusion result structure allocated by C include_local/include_system callbacks */
183 typedef struct glsl_include_result_s {
184     /* Header file name or NULL if inclusion failed */
185     const char* header_name;
186 
187     /* Header contents or NULL */
188     const char* header_data;
189     size_t header_length;
190 
191 } glsl_include_result_t;
192 
193 /* Callback for local file inclusion */
194 typedef glsl_include_result_t* (*glsl_include_local_func)(void* ctx, const char* header_name, const char* includer_name,
195                                                           size_t include_depth);
196 
197 /* Callback for system file inclusion */
198 typedef glsl_include_result_t* (*glsl_include_system_func)(void* ctx, const char* header_name,
199                                                            const char* includer_name, size_t include_depth);
200 
201 /* Callback for include result destruction */
202 typedef int (*glsl_free_include_result_func)(void* ctx, glsl_include_result_t* result);
203 
204 /* Collection of callbacks for GLSL preprocessor */
205 typedef struct glsl_include_callbacks_s {
206     glsl_include_system_func include_system;
207     glsl_include_local_func include_local;
208     glsl_free_include_result_func free_include_result;
209 } glsl_include_callbacks_t;
210 
211 /* SpvOptions counterpart */
212 typedef struct glslang_spv_options_s {
213     bool generate_debug_info;
214     bool strip_debug_info;
215     bool disable_optimizer;
216     bool optimize_size;
217     bool disassemble;
218     bool validate;
219     bool emit_nonsemantic_shader_debug_info;
220     bool emit_nonsemantic_shader_debug_source;
221 } glslang_spv_options_t;
222 
223 #ifdef __cplusplus
224 extern "C" {
225 #endif
226 
227 #ifdef GLSLANG_IS_SHARED_LIBRARY
228     #ifdef _WIN32
229         #ifdef GLSLANG_EXPORTING
230             #define GLSLANG_EXPORT __declspec(dllexport)
231         #else
232             #define GLSLANG_EXPORT __declspec(dllimport)
233         #endif
234     #elif __GNUC__ >= 4
235         #define GLSLANG_EXPORT __attribute__((visibility("default")))
236     #endif
237 #endif // GLSLANG_IS_SHARED_LIBRARY
238 
239 #ifndef GLSLANG_EXPORT
240 #define GLSLANG_EXPORT
241 #endif
242 
243 GLSLANG_EXPORT int glslang_initialize_process();
244 GLSLANG_EXPORT void glslang_finalize_process();
245 
246 GLSLANG_EXPORT glslang_shader_t* glslang_shader_create(const glslang_input_t* input);
247 GLSLANG_EXPORT void glslang_shader_delete(glslang_shader_t* shader);
248 GLSLANG_EXPORT void glslang_shader_set_preamble(glslang_shader_t* shader, const char* s);
249 GLSLANG_EXPORT void glslang_shader_shift_binding(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base);
250 GLSLANG_EXPORT void glslang_shader_shift_binding_for_set(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base, unsigned int set);
251 GLSLANG_EXPORT void glslang_shader_set_options(glslang_shader_t* shader, int options); // glslang_shader_options_t
252 GLSLANG_EXPORT void glslang_shader_set_glsl_version(glslang_shader_t* shader, int version);
253 GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input);
254 GLSLANG_EXPORT int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input);
255 GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);
256 GLSLANG_EXPORT const char* glslang_shader_get_info_log(glslang_shader_t* shader);
257 GLSLANG_EXPORT const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader);
258 
259 GLSLANG_EXPORT glslang_program_t* glslang_program_create();
260 GLSLANG_EXPORT void glslang_program_delete(glslang_program_t* program);
261 GLSLANG_EXPORT void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader);
262 GLSLANG_EXPORT int glslang_program_link(glslang_program_t* program, int messages); // glslang_messages_t
263 GLSLANG_EXPORT void glslang_program_add_source_text(glslang_program_t* program, glslang_stage_t stage, const char* text, size_t len);
264 GLSLANG_EXPORT void glslang_program_set_source_file(glslang_program_t* program, glslang_stage_t stage, const char* file);
265 GLSLANG_EXPORT int glslang_program_map_io(glslang_program_t* program);
266 GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage);
267 GLSLANG_EXPORT void glslang_program_SPIRV_generate_with_options(glslang_program_t* program, glslang_stage_t stage, glslang_spv_options_t* spv_options);
268 GLSLANG_EXPORT size_t glslang_program_SPIRV_get_size(glslang_program_t* program);
269 GLSLANG_EXPORT void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*);
270 GLSLANG_EXPORT unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program);
271 GLSLANG_EXPORT const char* glslang_program_SPIRV_get_messages(glslang_program_t* program);
272 GLSLANG_EXPORT const char* glslang_program_get_info_log(glslang_program_t* program);
273 GLSLANG_EXPORT const char* glslang_program_get_info_debug_log(glslang_program_t* program);
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 
279 #endif /* #ifdef GLSLANG_C_IFACE_INCLUDED */
280