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 maxDualSourceDrawBuffersEXT;
152 
153     glslang_limits_t limits;
154 } glslang_resource_t;
155 
156 typedef struct glslang_input_s {
157     glslang_source_t language;
158     glslang_stage_t stage;
159     glslang_client_t client;
160     glslang_target_client_version_t client_version;
161     glslang_target_language_t target_language;
162     glslang_target_language_version_t target_language_version;
163     /** Shader source code */
164     const char* code;
165     int default_version;
166     glslang_profile_t default_profile;
167     int force_default_version_and_profile;
168     int forward_compatible;
169     glslang_messages_t messages;
170     const glslang_resource_t* resource;
171 } glslang_input_t;
172 
173 /* Inclusion result structure allocated by C include_local/include_system callbacks */
174 typedef struct glsl_include_result_s {
175     /* Header file name or NULL if inclusion failed */
176     const char* header_name;
177 
178     /* Header contents or NULL */
179     const char* header_data;
180     size_t header_length;
181 
182 } glsl_include_result_t;
183 
184 /* Callback for local file inclusion */
185 typedef glsl_include_result_t* (*glsl_include_local_func)(void* ctx, const char* header_name, const char* includer_name,
186                                                           size_t include_depth);
187 
188 /* Callback for system file inclusion */
189 typedef glsl_include_result_t* (*glsl_include_system_func)(void* ctx, const char* header_name,
190                                                            const char* includer_name, size_t include_depth);
191 
192 /* Callback for include result destruction */
193 typedef int (*glsl_free_include_result_func)(void* ctx, glsl_include_result_t* result);
194 
195 /* Collection of callbacks for GLSL preprocessor */
196 typedef struct glsl_include_callbacks_s {
197     glsl_include_system_func include_system;
198     glsl_include_local_func include_local;
199     glsl_free_include_result_func free_include_result;
200 } glsl_include_callbacks_t;
201 
202 #ifdef __cplusplus
203 extern "C" {
204 #endif
205 
206 #ifdef GLSLANG_IS_SHARED_LIBRARY
207     #ifdef _WIN32
208         #ifdef GLSLANG_EXPORTING
209             #define GLSLANG_EXPORT __declspec(dllexport)
210         #else
211             #define GLSLANG_EXPORT __declspec(dllimport)
212         #endif
213     #elif __GNUC__ >= 4
214         #define GLSLANG_EXPORT __attribute__((visibility("default")))
215     #endif
216 #endif // GLSLANG_IS_SHARED_LIBRARY
217 
218 #ifndef GLSLANG_EXPORT
219 #define GLSLANG_EXPORT
220 #endif
221 
222 GLSLANG_EXPORT int glslang_initialize_process();
223 GLSLANG_EXPORT void glslang_finalize_process();
224 
225 GLSLANG_EXPORT glslang_shader_t* glslang_shader_create(const glslang_input_t* input);
226 GLSLANG_EXPORT void glslang_shader_delete(glslang_shader_t* shader);
227 GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input);
228 GLSLANG_EXPORT int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input);
229 GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);
230 GLSLANG_EXPORT const char* glslang_shader_get_info_log(glslang_shader_t* shader);
231 GLSLANG_EXPORT const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader);
232 
233 GLSLANG_EXPORT glslang_program_t* glslang_program_create();
234 GLSLANG_EXPORT void glslang_program_delete(glslang_program_t* program);
235 GLSLANG_EXPORT void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader);
236 GLSLANG_EXPORT int glslang_program_link(glslang_program_t* program, int messages); // glslang_messages_t
237 GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage);
238 GLSLANG_EXPORT size_t glslang_program_SPIRV_get_size(glslang_program_t* program);
239 GLSLANG_EXPORT void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*);
240 GLSLANG_EXPORT unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program);
241 GLSLANG_EXPORT const char* glslang_program_SPIRV_get_messages(glslang_program_t* program);
242 GLSLANG_EXPORT const char* glslang_program_get_info_log(glslang_program_t* program);
243 GLSLANG_EXPORT const char* glslang_program_get_info_debug_log(glslang_program_t* program);
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #endif /* #ifdef GLSLANG_C_IFACE_INCLUDED */
250