glsl: Put `sample`-qualified varyings in their own packing classes
[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 <string.h>
34 #include "ralloc.h"
35
36 void
37 _mesa_warning(struct gl_context *ctx, const char *fmt, ...)
38 {
39 va_list vargs;
40 (void) ctx;
41
42 va_start(vargs, fmt);
43
44 /* This output is not thread-safe, but that's good enough for the
45 * standalone compiler.
46 */
47 fprintf(stderr, "Mesa warning: ");
48 vfprintf(stderr, fmt, vargs);
49 fprintf(stderr, "\n");
50
51 va_end(vargs);
52 }
53
54 void
55 _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
56 struct gl_shader *sh)
57 {
58 (void) ctx;
59 *ptr = sh;
60 }
61
62 void
63 _mesa_shader_debug(struct gl_context *, GLenum, GLuint *id,
64 const char *, int)
65 {
66 }
67
68 struct gl_shader *
69 _mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type)
70 {
71 struct gl_shader *shader;
72
73 (void) ctx;
74
75 assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER);
76 shader = rzalloc(NULL, struct gl_shader);
77 if (shader) {
78 shader->Type = type;
79 shader->Name = name;
80 shader->RefCount = 1;
81 }
82 return shader;
83 }
84
85 void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
86 {
87 memset(ctx, 0, sizeof(*ctx));
88
89 ctx->API = api;
90
91 ctx->Extensions.dummy_false = false;
92 ctx->Extensions.dummy_true = true;
93 ctx->Extensions.ARB_conservative_depth = true;
94 ctx->Extensions.ARB_draw_instanced = true;
95 ctx->Extensions.ARB_ES2_compatibility = true;
96 ctx->Extensions.ARB_ES3_compatibility = true;
97 ctx->Extensions.ARB_explicit_attrib_location = true;
98 ctx->Extensions.ARB_fragment_coord_conventions = true;
99 ctx->Extensions.ARB_gpu_shader5 = true;
100 ctx->Extensions.ARB_sample_shading = true;
101 ctx->Extensions.ARB_shader_bit_encoding = true;
102 ctx->Extensions.ARB_shader_stencil_export = true;
103 ctx->Extensions.ARB_shader_texture_lod = true;
104 ctx->Extensions.ARB_shading_language_420pack = true;
105 ctx->Extensions.ARB_shading_language_packing = true;
106 ctx->Extensions.ARB_texture_cube_map_array = true;
107 ctx->Extensions.ARB_texture_gather = true;
108 ctx->Extensions.ARB_texture_multisample = true;
109 ctx->Extensions.ARB_texture_query_levels = true;
110 ctx->Extensions.ARB_texture_query_lod = true;
111 ctx->Extensions.ARB_uniform_buffer_object = true;
112
113 ctx->Extensions.OES_EGL_image_external = true;
114 ctx->Extensions.OES_standard_derivatives = true;
115
116 ctx->Extensions.EXT_shader_integer_mix = true;
117 ctx->Extensions.EXT_texture3D = true;
118 ctx->Extensions.EXT_texture_array = true;
119
120 ctx->Extensions.NV_texture_rectangle = true;
121
122 ctx->Const.GLSLVersion = 120;
123
124 /* 1.20 minimums. */
125 ctx->Const.MaxLights = 8;
126 ctx->Const.MaxClipPlanes = 6;
127 ctx->Const.MaxTextureUnits = 2;
128 ctx->Const.MaxTextureCoordUnits = 2;
129 ctx->Const.VertexProgram.MaxAttribs = 16;
130
131 ctx->Const.VertexProgram.MaxUniformComponents = 512;
132 ctx->Const.VertexProgram.MaxOutputComponents = 32;
133 ctx->Const.MaxVarying = 8; /* == gl_MaxVaryingFloats / 4 */
134 ctx->Const.VertexProgram.MaxTextureImageUnits = 0;
135 ctx->Const.MaxCombinedTextureImageUnits = 2;
136 ctx->Const.FragmentProgram.MaxTextureImageUnits = 2;
137 ctx->Const.FragmentProgram.MaxUniformComponents = 64;
138 ctx->Const.FragmentProgram.MaxInputComponents = 32;
139
140 ctx->Const.MaxDrawBuffers = 1;
141
142 /* Set up default shader compiler options. */
143 struct gl_shader_compiler_options options;
144 memset(&options, 0, sizeof(options));
145 options.MaxUnrollIterations = 32;
146 options.MaxIfDepth = UINT_MAX;
147
148 /* Default pragma settings */
149 options.DefaultPragmas.Optimize = true;
150
151 for (int sh = 0; sh < MESA_SHADER_TYPES; ++sh)
152 memcpy(&ctx->ShaderCompilerOptions[sh], &options, sizeof(options));
153 }