21 #include <glslang/build_info.h>
22 #include <glslang/Include/glslang_c_interface.h>
34 .max_texture_units = 32,
35 .max_texture_coords = 32,
36 .max_vertex_attribs = 64,
37 .max_vertex_uniform_components = 4096,
38 .max_varying_floats = 64,
39 .max_vertex_texture_image_units = 32,
40 .max_combined_texture_image_units = 80,
41 .max_texture_image_units = 32,
42 .max_fragment_uniform_components = 4096,
43 .max_draw_buffers = 32,
44 .max_vertex_uniform_vectors = 128,
45 .max_varying_vectors = 8,
46 .max_fragment_uniform_vectors = 16,
47 .max_vertex_output_vectors = 16,
48 .max_fragment_input_vectors = 15,
49 .min_program_texel_offset = -8,
50 .max_program_texel_offset = 7,
51 .max_clip_distances = 8,
52 .max_compute_work_group_count_x = 65535,
53 .max_compute_work_group_count_y = 65535,
54 .max_compute_work_group_count_z = 65535,
55 .max_compute_work_group_size_x = 1024,
56 .max_compute_work_group_size_y = 1024,
57 .max_compute_work_group_size_z = 64,
58 .max_compute_uniform_components = 1024,
59 .max_compute_texture_image_units = 16,
60 .max_compute_image_uniforms = 8,
61 .max_compute_atomic_counters = 8,
62 .max_compute_atomic_counter_buffers = 1,
63 .max_varying_components = 60,
64 .max_vertex_output_components = 64,
65 .max_geometry_input_components = 64,
66 .max_geometry_output_components = 128,
67 .max_fragment_input_components = 128,
69 .max_combined_image_units_and_fragment_outputs = 8,
70 .max_combined_shader_output_resources = 8,
71 .max_image_samples = 0,
72 .max_vertex_image_uniforms = 0,
73 .max_tess_control_image_uniforms = 0,
74 .max_tess_evaluation_image_uniforms = 0,
75 .max_geometry_image_uniforms = 0,
76 .max_fragment_image_uniforms = 8,
77 .max_combined_image_uniforms = 8,
78 .max_geometry_texture_image_units = 16,
79 .max_geometry_output_vertices = 256,
80 .max_geometry_total_output_components = 1024,
81 .max_geometry_uniform_components = 1024,
82 .max_geometry_varying_components = 64,
83 .max_tess_control_input_components = 128,
84 .max_tess_control_output_components = 128,
85 .max_tess_control_texture_image_units = 16,
86 .max_tess_control_uniform_components = 1024,
87 .max_tess_control_total_output_components = 4096,
88 .max_tess_evaluation_input_components = 128,
89 .max_tess_evaluation_output_components = 128,
90 .max_tess_evaluation_texture_image_units = 16,
91 .max_tess_evaluation_uniform_components = 1024,
92 .max_tess_patch_components = 120,
93 .max_patch_vertices = 32,
94 .max_tess_gen_level = 64,
96 .max_vertex_atomic_counters = 0,
97 .max_tess_control_atomic_counters = 0,
98 .max_tess_evaluation_atomic_counters = 0,
99 .max_geometry_atomic_counters = 0,
100 .max_fragment_atomic_counters = 8,
101 .max_combined_atomic_counters = 8,
102 .max_atomic_counter_bindings = 1,
103 .max_vertex_atomic_counter_buffers = 0,
104 .max_tess_control_atomic_counter_buffers = 0,
105 .max_tess_evaluation_atomic_counter_buffers = 0,
106 .max_geometry_atomic_counter_buffers = 0,
107 .max_fragment_atomic_counter_buffers = 1,
108 .max_combined_atomic_counter_buffers = 1,
109 .max_atomic_counter_buffer_size = 16384,
110 .max_transform_feedback_buffers = 4,
111 .max_transform_feedback_interleaved_components = 64,
112 .max_cull_distances = 8,
113 .max_combined_clip_and_cull_distances = 8,
115 .max_mesh_output_vertices_nv = 256,
116 .max_mesh_output_primitives_nv = 512,
117 .max_mesh_work_group_size_x_nv = 32,
118 .max_mesh_work_group_size_y_nv = 1,
119 .max_mesh_work_group_size_z_nv = 1,
120 .max_task_work_group_size_x_nv = 32,
121 .max_task_work_group_size_y_nv = 1,
122 .max_task_work_group_size_z_nv = 1,
123 .max_mesh_view_count_nv = 4,
124 .maxDualSourceDrawBuffersEXT = 1,
127 .non_inductive_for_loops = 1,
130 .general_uniform_indexing = 1,
131 .general_attribute_matrix_vector_indexing = 1,
132 .general_varying_indexing = 1,
133 .general_sampler_indexing = 1,
134 .general_variable_indexing = 1,
135 .general_constant_matrix_vector_indexing = 1,
141 size_t *
size,
const char *entrypoint,
144 const char *messages;
145 glslang_shader_t *glslc_shader;
146 glslang_program_t *glslc_program;
148 static const glslang_stage_t glslc_stage[] = {
149 [VK_SHADER_STAGE_VERTEX_BIT] = GLSLANG_STAGE_VERTEX,
150 [VK_SHADER_STAGE_FRAGMENT_BIT] = GLSLANG_STAGE_FRAGMENT,
151 [VK_SHADER_STAGE_COMPUTE_BIT] = GLSLANG_STAGE_COMPUTE,
154 const glslang_input_t glslc_input = {
155 .language = GLSLANG_SOURCE_GLSL,
156 .stage = glslc_stage[shd->
shader.stage],
157 .client = GLSLANG_CLIENT_VULKAN,
159 #if (((GLSLANG_VERSION_MAJOR) > 11) || ((GLSLANG_VERSION_MAJOR) == 11 && \
160 (((GLSLANG_VERSION_MINOR) > 6) || ((GLSLANG_VERSION_MINOR) == 6 && \
161 ((GLSLANG_VERSION_PATCH) > 0)))))
162 .client_version = GLSLANG_TARGET_VULKAN_1_2,
163 .target_language_version = GLSLANG_TARGET_SPV_1_5,
165 .client_version = GLSLANG_TARGET_VULKAN_1_1,
166 .target_language_version = GLSLANG_TARGET_SPV_1_3,
168 .target_language = GLSLANG_TARGET_SPV,
169 .code = shd->
src.str,
170 .default_version = 460,
171 .default_profile = GLSLANG_NO_PROFILE,
172 .force_default_version_and_profile =
false,
173 .forward_compatible =
false,
174 .messages = GLSLANG_MSG_DEFAULT_BIT,
182 if (!(glslc_shader = glslang_shader_create(&glslc_input)))
185 if (!glslang_shader_preprocess(glslc_shader, &glslc_input)) {
188 glslang_shader_get_info_log(glslc_shader),
189 glslang_shader_get_info_debug_log(glslc_shader));
190 glslang_shader_delete(glslc_shader);
194 if (!glslang_shader_parse(glslc_shader, &glslc_input)) {
197 glslang_shader_get_info_log(glslc_shader),
198 glslang_shader_get_info_debug_log(glslc_shader));
199 glslang_shader_delete(glslc_shader);
203 if (!(glslc_program = glslang_program_create())) {
204 glslang_shader_delete(glslc_shader);
208 glslang_program_add_shader(glslc_program, glslc_shader);
210 if (!glslang_program_link(glslc_program, GLSLANG_MSG_SPV_RULES_BIT |
211 GLSLANG_MSG_VULKAN_RULES_BIT)) {
214 glslang_program_get_info_log(glslc_program),
215 glslang_program_get_info_debug_log(glslc_program));
216 glslang_program_delete(glslc_program);
217 glslang_shader_delete(glslc_shader);
221 glslang_program_SPIRV_generate(glslc_program, glslc_input.stage);
223 messages = glslang_program_SPIRV_get_messages(glslc_program);
231 glslang_shader_delete(glslc_shader);
233 *
size = glslang_program_SPIRV_get_size(glslc_program) *
sizeof(
unsigned int);
234 *
data = (
void *)glslang_program_SPIRV_get_ptr(glslc_program);
235 *opaque = glslc_program;
242 if (!opaque || !*opaque)
246 glslang_program_delete(*opaque);
257 glslang_finalize_process();
275 if (!glslang_initialize_process()) {