2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 /* This file declares stripped-down versions of functions that
25 * normally exist outside of the glsl folder, so that they can be used
26 * when running the GLSL compiler standalone (for unit testing or
27 * compiling builtins).
30 #include "standalone_scaffolding.h"
35 #include "util/ralloc.h"
36 #include "util/strtod.h"
39 _mesa_warning(struct gl_context *ctx, const char *fmt, ...)
46 /* This output is not thread-safe, but that's good enough for the
47 * standalone compiler.
49 fprintf(stderr, "Mesa warning: ");
50 vfprintf(stderr, fmt, vargs);
51 fprintf(stderr, "\n");
57 _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
65 _mesa_reference_program_(struct gl_context *ctx, struct gl_program **ptr,
66 struct gl_program *prog)
73 _mesa_shader_debug(struct gl_context *, GLenum, GLuint *,
79 _mesa_new_shader(GLuint name, gl_shader_stage stage)
81 struct gl_shader *shader;
83 assert(stage == MESA_SHADER_FRAGMENT || stage == MESA_SHADER_VERTEX);
84 shader = rzalloc(NULL, struct gl_shader);
86 shader->Stage = stage;
93 struct gl_linked_shader *
94 _mesa_new_linked_shader(gl_shader_stage stage)
96 struct gl_linked_shader *shader;
98 assert(stage == MESA_SHADER_FRAGMENT || stage == MESA_SHADER_VERTEX);
99 shader = rzalloc(NULL, struct gl_linked_shader);
101 shader->Stage = stage;
107 _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
113 _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
119 _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh)
121 free((void *)sh->Source);
127 _mesa_delete_linked_shader(struct gl_context *ctx,
128 struct gl_linked_shader *sh)
134 _mesa_clear_shader_program_data(struct gl_context *ctx,
135 struct gl_shader_program *shProg)
137 for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
138 if (shProg->_LinkedShaders[i] != NULL) {
139 _mesa_delete_linked_shader(ctx, shProg->_LinkedShaders[i]);
140 shProg->_LinkedShaders[i] = NULL;
144 shProg->NumUniformStorage = 0;
145 shProg->UniformStorage = NULL;
146 shProg->NumUniformRemapTable = 0;
147 shProg->UniformRemapTable = NULL;
148 shProg->UniformHash = NULL;
150 ralloc_free(shProg->InfoLog);
151 shProg->InfoLog = ralloc_strdup(shProg, "");
153 ralloc_free(shProg->UniformBlocks);
154 shProg->UniformBlocks = NULL;
155 shProg->NumUniformBlocks = 0;
157 ralloc_free(shProg->ShaderStorageBlocks);
158 shProg->ShaderStorageBlocks = NULL;
159 shProg->NumShaderStorageBlocks = 0;
161 ralloc_free(shProg->AtomicBuffers);
162 shProg->AtomicBuffers = NULL;
163 shProg->NumAtomicBuffers = 0;
166 void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
168 memset(ctx, 0, sizeof(*ctx));
172 ctx->Extensions.dummy_false = false;
173 ctx->Extensions.dummy_true = true;
174 ctx->Extensions.ARB_compute_shader = true;
175 ctx->Extensions.ARB_compute_variable_group_size = true;
176 ctx->Extensions.ARB_conservative_depth = true;
177 ctx->Extensions.ARB_draw_instanced = true;
178 ctx->Extensions.ARB_ES2_compatibility = true;
179 ctx->Extensions.ARB_ES3_compatibility = true;
180 ctx->Extensions.ARB_explicit_attrib_location = true;
181 ctx->Extensions.ARB_fragment_coord_conventions = true;
182 ctx->Extensions.ARB_fragment_layer_viewport = true;
183 ctx->Extensions.ARB_gpu_shader5 = true;
184 ctx->Extensions.ARB_gpu_shader_fp64 = true;
185 ctx->Extensions.ARB_sample_shading = true;
186 ctx->Extensions.ARB_shader_bit_encoding = true;
187 ctx->Extensions.ARB_shader_draw_parameters = true;
188 ctx->Extensions.ARB_shader_stencil_export = true;
189 ctx->Extensions.ARB_shader_subroutine = true;
190 ctx->Extensions.ARB_shader_texture_lod = true;
191 ctx->Extensions.ARB_shading_language_420pack = true;
192 ctx->Extensions.ARB_shading_language_packing = true;
193 ctx->Extensions.ARB_tessellation_shader = true;
194 ctx->Extensions.ARB_texture_cube_map_array = true;
195 ctx->Extensions.ARB_texture_gather = true;
196 ctx->Extensions.ARB_texture_multisample = true;
197 ctx->Extensions.ARB_texture_query_levels = true;
198 ctx->Extensions.ARB_texture_query_lod = true;
199 ctx->Extensions.ARB_uniform_buffer_object = true;
200 ctx->Extensions.ARB_viewport_array = true;
201 ctx->Extensions.ARB_cull_distance = true;
203 ctx->Extensions.OES_EGL_image_external = true;
204 ctx->Extensions.OES_standard_derivatives = true;
206 ctx->Extensions.EXT_shader_integer_mix = true;
207 ctx->Extensions.EXT_texture_array = true;
209 ctx->Extensions.MESA_shader_integer_functions = true;
211 ctx->Extensions.NV_texture_rectangle = true;
213 ctx->Const.GLSLVersion = 120;
216 ctx->Const.MaxLights = 8;
217 ctx->Const.MaxClipPlanes = 6;
218 ctx->Const.MaxTextureUnits = 2;
219 ctx->Const.MaxTextureCoordUnits = 2;
220 ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs = 16;
222 ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 512;
223 ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = 32;
224 ctx->Const.MaxVarying = 8; /* == gl_MaxVaryingFloats / 4 */
225 ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 0;
226 ctx->Const.MaxCombinedTextureImageUnits = 2;
227 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = 2;
228 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 64;
229 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = 32;
231 ctx->Const.MaxDrawBuffers = 1;
232 ctx->Const.MaxComputeWorkGroupCount[0] = 65535;
233 ctx->Const.MaxComputeWorkGroupCount[1] = 65535;
234 ctx->Const.MaxComputeWorkGroupCount[2] = 65535;
235 ctx->Const.MaxComputeWorkGroupSize[0] = 1024;
236 ctx->Const.MaxComputeWorkGroupSize[1] = 1024;
237 ctx->Const.MaxComputeWorkGroupSize[2] = 64;
238 ctx->Const.MaxComputeWorkGroupInvocations = 1024;
239 ctx->Const.MaxComputeVariableGroupSize[0] = 512;
240 ctx->Const.MaxComputeVariableGroupSize[1] = 512;
241 ctx->Const.MaxComputeVariableGroupSize[2] = 64;
242 ctx->Const.MaxComputeVariableGroupInvocations = 512;
243 ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits = 16;
244 ctx->Const.Program[MESA_SHADER_COMPUTE].MaxUniformComponents = 1024;
245 ctx->Const.Program[MESA_SHADER_COMPUTE].MaxInputComponents = 0; /* not used */
246 ctx->Const.Program[MESA_SHADER_COMPUTE].MaxOutputComponents = 0; /* not used */
248 /* Set up default shader compiler options. */
249 struct gl_shader_compiler_options options;
250 memset(&options, 0, sizeof(options));
251 options.MaxUnrollIterations = 32;
252 options.MaxIfDepth = UINT_MAX;
254 for (int sh = 0; sh < MESA_SHADER_STAGES; ++sh)
255 memcpy(&ctx->Const.ShaderCompilerOptions[sh], &options, sizeof(options));