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