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"
34 #include "util/ralloc.h"
37 _mesa_warning(struct gl_context
*ctx
, const char *fmt
, ...)
44 /* This output is not thread-safe, but that's good enough for the
45 * standalone compiler.
47 fprintf(stderr
, "Mesa warning: ");
48 vfprintf(stderr
, fmt
, vargs
);
49 fprintf(stderr
, "\n");
55 _mesa_reference_shader(struct gl_context
*ctx
, struct gl_shader
**ptr
,
63 _mesa_shader_debug(struct gl_context
*, GLenum
, GLuint
*id
,
69 _mesa_new_shader(struct gl_context
*ctx
, GLuint name
, GLenum type
)
71 struct gl_shader
*shader
;
75 assert(type
== GL_FRAGMENT_SHADER
|| type
== GL_VERTEX_SHADER
);
76 shader
= rzalloc(NULL
, struct gl_shader
);
79 shader
->Stage
= _mesa_shader_enum_to_shader_stage(type
);
87 _mesa_clear_shader_program_data(struct gl_shader_program
*shProg
)
91 shProg
->NumUserUniformStorage
= 0;
92 shProg
->UniformStorage
= NULL
;
93 shProg
->NumUniformRemapTable
= 0;
94 shProg
->UniformRemapTable
= NULL
;
95 shProg
->UniformHash
= NULL
;
97 ralloc_free(shProg
->InfoLog
);
98 shProg
->InfoLog
= ralloc_strdup(shProg
, "");
100 ralloc_free(shProg
->UniformBlocks
);
101 shProg
->UniformBlocks
= NULL
;
102 shProg
->NumUniformBlocks
= 0;
103 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
104 ralloc_free(shProg
->UniformBlockStageIndex
[i
]);
105 shProg
->UniformBlockStageIndex
[i
] = NULL
;
108 ralloc_free(shProg
->AtomicBuffers
);
109 shProg
->AtomicBuffers
= NULL
;
110 shProg
->NumAtomicBuffers
= 0;
113 void initialize_context_to_defaults(struct gl_context
*ctx
, gl_api api
)
115 memset(ctx
, 0, sizeof(*ctx
));
119 ctx
->Extensions
.dummy_false
= false;
120 ctx
->Extensions
.dummy_true
= true;
121 ctx
->Extensions
.ARB_compute_shader
= true;
122 ctx
->Extensions
.ARB_conservative_depth
= true;
123 ctx
->Extensions
.ARB_draw_instanced
= true;
124 ctx
->Extensions
.ARB_ES2_compatibility
= true;
125 ctx
->Extensions
.ARB_ES3_compatibility
= true;
126 ctx
->Extensions
.ARB_explicit_attrib_location
= true;
127 ctx
->Extensions
.ARB_fragment_coord_conventions
= true;
128 ctx
->Extensions
.ARB_fragment_layer_viewport
= true;
129 ctx
->Extensions
.ARB_gpu_shader5
= true;
130 ctx
->Extensions
.ARB_sample_shading
= true;
131 ctx
->Extensions
.ARB_shader_bit_encoding
= true;
132 ctx
->Extensions
.ARB_shader_stencil_export
= true;
133 ctx
->Extensions
.ARB_shader_texture_lod
= true;
134 ctx
->Extensions
.ARB_shading_language_420pack
= true;
135 ctx
->Extensions
.ARB_shading_language_packing
= true;
136 ctx
->Extensions
.ARB_texture_cube_map_array
= true;
137 ctx
->Extensions
.ARB_texture_gather
= true;
138 ctx
->Extensions
.ARB_texture_multisample
= true;
139 ctx
->Extensions
.ARB_texture_query_levels
= true;
140 ctx
->Extensions
.ARB_texture_query_lod
= true;
141 ctx
->Extensions
.ARB_uniform_buffer_object
= true;
142 ctx
->Extensions
.ARB_viewport_array
= true;
144 ctx
->Extensions
.OES_EGL_image_external
= true;
145 ctx
->Extensions
.OES_standard_derivatives
= true;
147 ctx
->Extensions
.EXT_shader_integer_mix
= true;
148 ctx
->Extensions
.EXT_texture3D
= true;
149 ctx
->Extensions
.EXT_texture_array
= true;
151 ctx
->Extensions
.NV_texture_rectangle
= true;
153 ctx
->Const
.GLSLVersion
= 120;
156 ctx
->Const
.MaxLights
= 8;
157 ctx
->Const
.MaxClipPlanes
= 6;
158 ctx
->Const
.MaxTextureUnits
= 2;
159 ctx
->Const
.MaxTextureCoordUnits
= 2;
160 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
162 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 512;
163 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 32;
164 ctx
->Const
.MaxVarying
= 8; /* == gl_MaxVaryingFloats / 4 */
165 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 0;
166 ctx
->Const
.MaxCombinedTextureImageUnits
= 2;
167 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 2;
168 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 64;
169 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
= 32;
171 ctx
->Const
.MaxDrawBuffers
= 1;
172 ctx
->Const
.MaxComputeWorkGroupCount
[0] = 65535;
173 ctx
->Const
.MaxComputeWorkGroupCount
[1] = 65535;
174 ctx
->Const
.MaxComputeWorkGroupCount
[2] = 65535;
175 ctx
->Const
.MaxComputeWorkGroupSize
[0] = 1024;
176 ctx
->Const
.MaxComputeWorkGroupSize
[1] = 1024;
177 ctx
->Const
.MaxComputeWorkGroupSize
[2] = 64;
178 ctx
->Const
.MaxComputeWorkGroupInvocations
= 1024;
179 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxTextureImageUnits
= 16;
180 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxUniformComponents
= 1024;
181 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxInputComponents
= 0; /* not used */
182 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxOutputComponents
= 0; /* not used */
184 /* Set up default shader compiler options. */
185 struct gl_shader_compiler_options options
;
186 memset(&options
, 0, sizeof(options
));
187 options
.MaxUnrollIterations
= 32;
188 options
.MaxIfDepth
= UINT_MAX
;
190 /* Default pragma settings */
191 options
.DefaultPragmas
.Optimize
= true;
193 for (int sh
= 0; sh
< MESA_SHADER_STAGES
; ++sh
)
194 memcpy(&ctx
->Const
.ShaderCompilerOptions
[sh
], &options
, sizeof(options
));