vk/image: Check extent does not exceed surface type limits
[mesa.git] / src / glsl / standalone_scaffolding.cpp
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
37 extern "C" void
38 _mesa_error_no_memory(const char *caller)
39 {
40 fprintf(stderr, "Mesa error: out of memory in %s", caller);
41 }
42
43 void
44 _mesa_warning(struct gl_context *ctx, const char *fmt, ...)
45 {
46 va_list vargs;
47 (void) ctx;
48
49 va_start(vargs, fmt);
50
51 /* This output is not thread-safe, but that's good enough for the
52 * standalone compiler.
53 */
54 fprintf(stderr, "Mesa warning: ");
55 vfprintf(stderr, fmt, vargs);
56 fprintf(stderr, "\n");
57
58 va_end(vargs);
59 }
60
61 void
62 _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
63 struct gl_shader *sh)
64 {
65 (void) ctx;
66 *ptr = sh;
67 }
68
69 void
70 _mesa_shader_debug(struct gl_context *, GLenum, GLuint *id,
71 const char *, int)
72 {
73 }
74
75 struct gl_shader *
76 _mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type)
77 {
78 struct gl_shader *shader;
79
80 (void) ctx;
81
82 assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER);
83 shader = rzalloc(NULL, struct gl_shader);
84 if (shader) {
85 shader->Type = type;
86 shader->Stage = _mesa_shader_enum_to_shader_stage(type);
87 shader->Name = name;
88 shader->RefCount = 1;
89 }
90 return shader;
91 }
92
93 void
94 _mesa_clear_shader_program_data(struct gl_shader_program *shProg)
95 {
96 unsigned i;
97
98 shProg->NumUniformStorage = 0;
99 shProg->UniformStorage = NULL;
100 shProg->NumUniformRemapTable = 0;
101 shProg->UniformRemapTable = NULL;
102 shProg->UniformHash = NULL;
103
104 ralloc_free(shProg->InfoLog);
105 shProg->InfoLog = ralloc_strdup(shProg, "");
106
107 ralloc_free(shProg->UniformBlocks);
108 shProg->UniformBlocks = NULL;
109 shProg->NumUniformBlocks = 0;
110 for (i = 0; i < MESA_SHADER_STAGES; i++) {
111 ralloc_free(shProg->UniformBlockStageIndex[i]);
112 shProg->UniformBlockStageIndex[i] = NULL;
113 }
114
115 ralloc_free(shProg->AtomicBuffers);
116 shProg->AtomicBuffers = NULL;
117 shProg->NumAtomicBuffers = 0;
118 }
119
120 void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
121 {
122 memset(ctx, 0, sizeof(*ctx));
123
124 ctx->API = api;
125
126 ctx->Extensions.dummy_false = false;
127 ctx->Extensions.dummy_true = true;
128 ctx->Extensions.ARB_compute_shader = true;
129 ctx->Extensions.ARB_conservative_depth = true;
130 ctx->Extensions.ARB_draw_instanced = true;
131 ctx->Extensions.ARB_ES2_compatibility = true;
132 ctx->Extensions.ARB_ES3_compatibility = true;
133 ctx->Extensions.ARB_explicit_attrib_location = true;
134 ctx->Extensions.ARB_fragment_coord_conventions = true;
135 ctx->Extensions.ARB_fragment_layer_viewport = true;
136 ctx->Extensions.ARB_gpu_shader5 = true;
137 ctx->Extensions.ARB_gpu_shader_fp64 = true;
138 ctx->Extensions.ARB_sample_shading = true;
139 ctx->Extensions.ARB_shader_bit_encoding = true;
140 ctx->Extensions.ARB_shader_stencil_export = true;
141 ctx->Extensions.ARB_shader_texture_lod = true;
142 ctx->Extensions.ARB_shading_language_420pack = true;
143 ctx->Extensions.ARB_shading_language_packing = true;
144 ctx->Extensions.ARB_texture_cube_map_array = true;
145 ctx->Extensions.ARB_texture_gather = true;
146 ctx->Extensions.ARB_texture_multisample = true;
147 ctx->Extensions.ARB_texture_query_levels = true;
148 ctx->Extensions.ARB_texture_query_lod = true;
149 ctx->Extensions.ARB_uniform_buffer_object = true;
150 ctx->Extensions.ARB_viewport_array = true;
151
152 ctx->Extensions.OES_EGL_image_external = true;
153 ctx->Extensions.OES_standard_derivatives = true;
154
155 ctx->Extensions.EXT_shader_integer_mix = true;
156 ctx->Extensions.EXT_texture3D = true;
157 ctx->Extensions.EXT_texture_array = true;
158
159 ctx->Extensions.NV_texture_rectangle = true;
160
161 ctx->Const.GLSLVersion = 120;
162
163 /* 1.20 minimums. */
164 ctx->Const.MaxLights = 8;
165 ctx->Const.MaxClipPlanes = 6;
166 ctx->Const.MaxTextureUnits = 2;
167 ctx->Const.MaxTextureCoordUnits = 2;
168 ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs = 16;
169
170 ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 512;
171 ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = 32;
172 ctx->Const.MaxVarying = 8; /* == gl_MaxVaryingFloats / 4 */
173 ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 0;
174 ctx->Const.MaxCombinedTextureImageUnits = 2;
175 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = 2;
176 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 64;
177 ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = 32;
178
179 ctx->Const.MaxDrawBuffers = 1;
180 ctx->Const.MaxComputeWorkGroupCount[0] = 65535;
181 ctx->Const.MaxComputeWorkGroupCount[1] = 65535;
182 ctx->Const.MaxComputeWorkGroupCount[2] = 65535;
183 ctx->Const.MaxComputeWorkGroupSize[0] = 1024;
184 ctx->Const.MaxComputeWorkGroupSize[1] = 1024;
185 ctx->Const.MaxComputeWorkGroupSize[2] = 64;
186 ctx->Const.MaxComputeWorkGroupInvocations = 1024;
187 ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits = 16;
188 ctx->Const.Program[MESA_SHADER_COMPUTE].MaxUniformComponents = 1024;
189 ctx->Const.Program[MESA_SHADER_COMPUTE].MaxInputComponents = 0; /* not used */
190 ctx->Const.Program[MESA_SHADER_COMPUTE].MaxOutputComponents = 0; /* not used */
191
192 /* Set up default shader compiler options. */
193 struct gl_shader_compiler_options options;
194 memset(&options, 0, sizeof(options));
195 options.MaxUnrollIterations = 32;
196 options.MaxIfDepth = UINT_MAX;
197
198 for (int sh = 0; sh < MESA_SHADER_STAGES; ++sh)
199 memcpy(&ctx->Const.ShaderCompilerOptions[sh], &options, sizeof(options));
200 }