• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2011 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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.
22  */
23 
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).
28  */
29 
30 #include "standalone_scaffolding.h"
31 
32 #include <assert.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include "util/ralloc.h"
36 #include "util/strtod.h"
37 
38 void
_mesa_warning(struct gl_context * ctx,const char * fmt,...)39 _mesa_warning(struct gl_context *ctx, const char *fmt, ...)
40 {
41     va_list vargs;
42     (void) ctx;
43 
44     va_start(vargs, fmt);
45 
46     /* This output is not thread-safe, but that's good enough for the
47      * standalone compiler.
48      */
49     fprintf(stderr, "Mesa warning: ");
50     vfprintf(stderr, fmt, vargs);
51     fprintf(stderr, "\n");
52 
53     va_end(vargs);
54 }
55 
56 void
_mesa_reference_shader_program_data(struct gl_context * ctx,struct gl_shader_program_data ** ptr,struct gl_shader_program_data * data)57 _mesa_reference_shader_program_data(struct gl_context *ctx,
58                                     struct gl_shader_program_data **ptr,
59                                     struct gl_shader_program_data *data)
60 {
61    (void) ctx;
62    *ptr = data;
63 }
64 
65 void
_mesa_reference_shader(struct gl_context * ctx,struct gl_shader ** ptr,struct gl_shader * sh)66 _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
67                        struct gl_shader *sh)
68 {
69    (void) ctx;
70    *ptr = sh;
71 }
72 
73 void
_mesa_reference_program_(struct gl_context * ctx,struct gl_program ** ptr,struct gl_program * prog)74 _mesa_reference_program_(struct gl_context *ctx, struct gl_program **ptr,
75                          struct gl_program *prog)
76 {
77    (void) ctx;
78    *ptr = prog;
79 }
80 
81 void
_mesa_shader_debug(struct gl_context *,GLenum,GLuint *,const char *)82 _mesa_shader_debug(struct gl_context *, GLenum, GLuint *,
83                    const char *)
84 {
85 }
86 
87 struct gl_shader *
_mesa_new_shader(GLuint name,gl_shader_stage stage)88 _mesa_new_shader(GLuint name, gl_shader_stage stage)
89 {
90    struct gl_shader *shader;
91 
92    assert(stage == MESA_SHADER_FRAGMENT || stage == MESA_SHADER_VERTEX);
93    shader = rzalloc(NULL, struct gl_shader);
94    if (shader) {
95       shader->Stage = stage;
96       shader->Name = name;
97       shader->RefCount = 1;
98    }
99    return shader;
100 }
101 
102 GLbitfield
_mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])103 _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
104 {
105    return 0;
106 }
107 
108 char *
_mesa_program_state_string(const gl_state_index state[STATE_LENGTH])109 _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
110 {
111    return NULL;
112 }
113 
114 void
_mesa_delete_shader(struct gl_context * ctx,struct gl_shader * sh)115 _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh)
116 {
117    free((void *)sh->Source);
118    free(sh->Label);
119    ralloc_free(sh);
120 }
121 
122 void
_mesa_delete_linked_shader(struct gl_context * ctx,struct gl_linked_shader * sh)123 _mesa_delete_linked_shader(struct gl_context *ctx,
124                            struct gl_linked_shader *sh)
125 {
126    ralloc_free(sh);
127 }
128 
129 void
_mesa_clear_shader_program_data(struct gl_context * ctx,struct gl_shader_program * shProg)130 _mesa_clear_shader_program_data(struct gl_context *ctx,
131                                 struct gl_shader_program *shProg)
132 {
133    for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
134       if (shProg->_LinkedShaders[i] != NULL) {
135          _mesa_delete_linked_shader(ctx, shProg->_LinkedShaders[i]);
136          shProg->_LinkedShaders[i] = NULL;
137       }
138    }
139 
140    shProg->data->NumUniformStorage = 0;
141    shProg->data->UniformStorage = NULL;
142    shProg->NumUniformRemapTable = 0;
143    shProg->UniformRemapTable = NULL;
144    shProg->UniformHash = NULL;
145 
146    ralloc_free(shProg->data->InfoLog);
147    shProg->data->InfoLog = ralloc_strdup(shProg->data, "");
148 
149    ralloc_free(shProg->data->UniformBlocks);
150    shProg->data->UniformBlocks = NULL;
151    shProg->data->NumUniformBlocks = 0;
152 
153    ralloc_free(shProg->data->ShaderStorageBlocks);
154    shProg->data->ShaderStorageBlocks = NULL;
155    shProg->data->NumShaderStorageBlocks = 0;
156 
157    ralloc_free(shProg->data->AtomicBuffers);
158    shProg->data->AtomicBuffers = NULL;
159    shProg->data->NumAtomicBuffers = 0;
160 }
161 
initialize_context_to_defaults(struct gl_context * ctx,gl_api api)162 void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
163 {
164    memset(ctx, 0, sizeof(*ctx));
165 
166    ctx->API = api;
167 
168    ctx->Extensions.dummy_false = false;
169    ctx->Extensions.dummy_true = true;
170    ctx->Extensions.ARB_compute_shader = true;
171    ctx->Extensions.ARB_compute_variable_group_size = true;
172    ctx->Extensions.ARB_conservative_depth = true;
173    ctx->Extensions.ARB_draw_instanced = true;
174    ctx->Extensions.ARB_ES2_compatibility = true;
175    ctx->Extensions.ARB_ES3_compatibility = true;
176    ctx->Extensions.ARB_explicit_attrib_location = true;
177    ctx->Extensions.ARB_fragment_coord_conventions = true;
178    ctx->Extensions.ARB_fragment_layer_viewport = true;
179    ctx->Extensions.ARB_gpu_shader5 = true;
180    ctx->Extensions.ARB_gpu_shader_fp64 = true;
181    ctx->Extensions.ARB_sample_shading = true;
182    ctx->Extensions.ARB_shader_bit_encoding = true;
183    ctx->Extensions.ARB_shader_draw_parameters = true;
184    ctx->Extensions.ARB_shader_stencil_export = true;
185    ctx->Extensions.ARB_shader_subroutine = true;
186    ctx->Extensions.ARB_shader_texture_lod = true;
187    ctx->Extensions.ARB_shading_language_420pack = true;
188    ctx->Extensions.ARB_shading_language_packing = true;
189    ctx->Extensions.ARB_tessellation_shader = true;
190    ctx->Extensions.ARB_texture_cube_map_array = true;
191    ctx->Extensions.ARB_texture_gather = true;
192    ctx->Extensions.ARB_texture_multisample = true;
193    ctx->Extensions.ARB_texture_query_levels = true;
194    ctx->Extensions.ARB_texture_query_lod = true;
195    ctx->Extensions.ARB_uniform_buffer_object = true;
196    ctx->Extensions.ARB_viewport_array = true;
197    ctx->Extensions.ARB_cull_distance = true;
198 
199    ctx->Extensions.OES_EGL_image_external = true;
200    ctx->Extensions.OES_standard_derivatives = true;
201 
202    ctx->Extensions.EXT_shader_integer_mix = true;
203    ctx->Extensions.EXT_texture_array = true;
204 
205    ctx->Extensions.MESA_shader_integer_functions = true;
206 
207    ctx->Extensions.NV_texture_rectangle = true;
208 
209    ctx->Const.GLSLVersion = 120;
210 
211    /* 1.20 minimums. */
212    ctx->Const.MaxLights = 8;
213    ctx->Const.MaxClipPlanes = 6;
214    ctx->Const.MaxTextureUnits = 2;
215    ctx->Const.MaxTextureCoordUnits = 2;
216    ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs = 16;
217 
218    ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 512;
219    ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = 32;
220    ctx->Const.MaxVarying = 8; /* == gl_MaxVaryingFloats / 4 */
221    ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 0;
222    ctx->Const.MaxCombinedTextureImageUnits = 2;
223    ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = 2;
224    ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 64;
225    ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = 32;
226 
227    ctx->Const.MaxDrawBuffers = 1;
228    ctx->Const.MaxComputeWorkGroupCount[0] = 65535;
229    ctx->Const.MaxComputeWorkGroupCount[1] = 65535;
230    ctx->Const.MaxComputeWorkGroupCount[2] = 65535;
231    ctx->Const.MaxComputeWorkGroupSize[0] = 1024;
232    ctx->Const.MaxComputeWorkGroupSize[1] = 1024;
233    ctx->Const.MaxComputeWorkGroupSize[2] = 64;
234    ctx->Const.MaxComputeWorkGroupInvocations = 1024;
235    ctx->Const.MaxComputeVariableGroupSize[0] = 512;
236    ctx->Const.MaxComputeVariableGroupSize[1] = 512;
237    ctx->Const.MaxComputeVariableGroupSize[2] = 64;
238    ctx->Const.MaxComputeVariableGroupInvocations = 512;
239    ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits = 16;
240    ctx->Const.Program[MESA_SHADER_COMPUTE].MaxUniformComponents = 1024;
241    ctx->Const.Program[MESA_SHADER_COMPUTE].MaxInputComponents = 0; /* not used */
242    ctx->Const.Program[MESA_SHADER_COMPUTE].MaxOutputComponents = 0; /* not used */
243 
244    /* Set up default shader compiler options. */
245    struct gl_shader_compiler_options options;
246    memset(&options, 0, sizeof(options));
247    options.MaxUnrollIterations = 32;
248    options.MaxIfDepth = UINT_MAX;
249 
250    for (int sh = 0; sh < MESA_SHADER_STAGES; ++sh)
251       memcpy(&ctx->Const.ShaderCompilerOptions[sh], &options, sizeof(options));
252 
253    _mesa_locale_init();
254 }
255