OSDN Git Service

49b4a26dc1255ffb38fe5c1e3c659b688f875f1c
[android-x86/external-mesa.git] / src / compiler / 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 #include "util/strtod.h"
37
38 void
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
57 _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
58                        struct gl_shader *sh)
59 {
60    (void) ctx;
61    *ptr = sh;
62 }
63
64 void
65 _mesa_shader_debug(struct gl_context *, GLenum, GLuint *,
66                    const char *)
67 {
68 }
69
70 struct gl_shader *
71 _mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type)
72 {
73    struct gl_shader *shader;
74
75    (void) ctx;
76
77    assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER);
78    shader = rzalloc(NULL, struct gl_shader);
79    if (shader) {
80       shader->Type = type;
81       shader->Stage = _mesa_shader_enum_to_shader_stage(type);
82       shader->Name = name;
83       shader->RefCount = 1;
84    }
85    return shader;
86 }
87
88 void
89 _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh)
90 {
91    free((void *)sh->Source);
92    free(sh->Label);
93    ralloc_free(sh);
94 }
95
96 void
97 _mesa_clear_shader_program_data(struct gl_shader_program *shProg)
98 {
99    shProg->NumUniformStorage = 0;
100    shProg->UniformStorage = NULL;
101    shProg->NumUniformRemapTable = 0;
102    shProg->UniformRemapTable = NULL;
103    shProg->UniformHash = NULL;
104
105    ralloc_free(shProg->InfoLog);
106    shProg->InfoLog = ralloc_strdup(shProg, "");
107
108    ralloc_free(shProg->BufferInterfaceBlocks);
109    shProg->BufferInterfaceBlocks = NULL;
110    shProg->NumBufferInterfaceBlocks = 0;
111
112    ralloc_free(shProg->UniformBlocks);
113    shProg->UniformBlocks = NULL;
114    shProg->NumUniformBlocks = 0;
115
116    ralloc_free(shProg->ShaderStorageBlocks);
117    shProg->ShaderStorageBlocks = NULL;
118    shProg->NumShaderStorageBlocks = 0;
119
120    ralloc_free(shProg->AtomicBuffers);
121    shProg->AtomicBuffers = NULL;
122    shProg->NumAtomicBuffers = 0;
123 }
124
125 void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
126 {
127    memset(ctx, 0, sizeof(*ctx));
128
129    ctx->API = api;
130
131    ctx->Extensions.dummy_false = false;
132    ctx->Extensions.dummy_true = true;
133    ctx->Extensions.ARB_compute_shader = true;
134    ctx->Extensions.ARB_conservative_depth = true;
135    ctx->Extensions.ARB_draw_instanced = true;
136    ctx->Extensions.ARB_ES2_compatibility = true;
137    ctx->Extensions.ARB_ES3_compatibility = true;
138    ctx->Extensions.ARB_explicit_attrib_location = true;
139    ctx->Extensions.ARB_fragment_coord_conventions = true;
140    ctx->Extensions.ARB_fragment_layer_viewport = true;
141    ctx->Extensions.ARB_gpu_shader5 = true;
142    ctx->Extensions.ARB_gpu_shader_fp64 = true;
143    ctx->Extensions.ARB_sample_shading = true;
144    ctx->Extensions.ARB_shader_bit_encoding = true;
145    ctx->Extensions.ARB_shader_draw_parameters = true;
146    ctx->Extensions.ARB_shader_stencil_export = true;
147    ctx->Extensions.ARB_shader_subroutine = true;
148    ctx->Extensions.ARB_shader_texture_lod = true;
149    ctx->Extensions.ARB_shading_language_420pack = true;
150    ctx->Extensions.ARB_shading_language_packing = true;
151    ctx->Extensions.ARB_tessellation_shader = true;
152    ctx->Extensions.ARB_texture_cube_map_array = true;
153    ctx->Extensions.ARB_texture_gather = true;
154    ctx->Extensions.ARB_texture_multisample = true;
155    ctx->Extensions.ARB_texture_query_levels = true;
156    ctx->Extensions.ARB_texture_query_lod = true;
157    ctx->Extensions.ARB_uniform_buffer_object = true;
158    ctx->Extensions.ARB_viewport_array = true;
159
160    ctx->Extensions.OES_EGL_image_external = true;
161    ctx->Extensions.OES_standard_derivatives = true;
162
163    ctx->Extensions.EXT_shader_integer_mix = true;
164    ctx->Extensions.EXT_texture_array = true;
165
166    ctx->Extensions.NV_texture_rectangle = true;
167
168    ctx->Const.GLSLVersion = 120;
169
170    /* 1.20 minimums. */
171    ctx->Const.MaxLights = 8;
172    ctx->Const.MaxClipPlanes = 6;
173    ctx->Const.MaxTextureUnits = 2;
174    ctx->Const.MaxTextureCoordUnits = 2;
175    ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs = 16;
176
177    ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 512;
178    ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = 32;
179    ctx->Const.MaxVarying = 8; /* == gl_MaxVaryingFloats / 4 */
180    ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 0;
181    ctx->Const.MaxCombinedTextureImageUnits = 2;
182    ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = 2;
183    ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 64;
184    ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = 32;
185
186    ctx->Const.MaxDrawBuffers = 1;
187    ctx->Const.MaxComputeWorkGroupCount[0] = 65535;
188    ctx->Const.MaxComputeWorkGroupCount[1] = 65535;
189    ctx->Const.MaxComputeWorkGroupCount[2] = 65535;
190    ctx->Const.MaxComputeWorkGroupSize[0] = 1024;
191    ctx->Const.MaxComputeWorkGroupSize[1] = 1024;
192    ctx->Const.MaxComputeWorkGroupSize[2] = 64;
193    ctx->Const.MaxComputeWorkGroupInvocations = 1024;
194    ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits = 16;
195    ctx->Const.Program[MESA_SHADER_COMPUTE].MaxUniformComponents = 1024;
196    ctx->Const.Program[MESA_SHADER_COMPUTE].MaxInputComponents = 0; /* not used */
197    ctx->Const.Program[MESA_SHADER_COMPUTE].MaxOutputComponents = 0; /* not used */
198
199    /* Set up default shader compiler options. */
200    struct gl_shader_compiler_options options;
201    memset(&options, 0, sizeof(options));
202    options.MaxUnrollIterations = 32;
203    options.MaxIfDepth = UINT_MAX;
204
205    for (int sh = 0; sh < MESA_SHADER_STAGES; ++sh)
206       memcpy(&ctx->Const.ShaderCompilerOptions[sh], &options, sizeof(options));
207
208    _mesa_locale_init();
209 }