mesa: add support for AlphaToCoverageDitherControlNV
[mesa.git] / src / mapi / glapi / gen / gl_genexec.py
1
2 # Copyright (C) 2012 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 DEALINGS
21 # IN THE SOFTWARE.
22
23 # This script generates the file api_exec.c, which contains
24 # _mesa_initialize_exec_table(). It is responsible for populating all
25 # entries in the "exec" dispatch table that aren't dynamic.
26
27 from __future__ import print_function
28
29 import argparse
30 import collections
31 import license
32 import gl_XML
33 import sys
34 import apiexec
35
36
37 exec_flavor_map = {
38 'dynamic': None,
39 'mesa': '_mesa_',
40 'skip': None,
41 }
42
43
44 header = """/**
45 * \\file api_exec.c
46 * Initialize dispatch table.
47 */
48
49
50 #include "main/accum.h"
51 #include "main/api_loopback.h"
52 #include "main/api_exec.h"
53 #include "main/arbprogram.h"
54 #include "main/atifragshader.h"
55 #include "main/attrib.h"
56 #include "main/blend.h"
57 #include "main/blit.h"
58 #include "main/bufferobj.h"
59 #include "main/arrayobj.h"
60 #include "main/bbox.h"
61 #include "main/buffers.h"
62 #include "main/clear.h"
63 #include "main/clip.h"
64 #include "main/colortab.h"
65 #include "main/compute.h"
66 #include "main/condrender.h"
67 #include "main/conservativeraster.h"
68 #include "main/context.h"
69 #include "main/convolve.h"
70 #include "main/copyimage.h"
71 #include "main/depth.h"
72 #include "main/debug_output.h"
73 #include "main/dlist.h"
74 #include "main/draw.h"
75 #include "main/drawpix.h"
76 #include "main/drawtex.h"
77 #include "main/rastpos.h"
78 #include "main/enable.h"
79 #include "main/errors.h"
80 #include "main/es1_conversion.h"
81 #include "main/eval.h"
82 #include "main/externalobjects.h"
83 #include "main/get.h"
84 #include "main/glspirv.h"
85 #include "main/feedback.h"
86 #include "main/fog.h"
87 #include "main/fbobject.h"
88 #include "main/framebuffer.h"
89 #include "main/genmipmap.h"
90 #include "main/hint.h"
91 #include "main/histogram.h"
92 #include "main/light.h"
93 #include "main/lines.h"
94 #include "main/matrix.h"
95 #include "main/multisample.h"
96 #include "main/objectlabel.h"
97 #include "main/objectpurge.h"
98 #include "main/performance_monitor.h"
99 #include "main/performance_query.h"
100 #include "main/pipelineobj.h"
101 #include "main/pixel.h"
102 #include "main/pixelstore.h"
103 #include "main/points.h"
104 #include "main/polygon.h"
105 #include "main/program_resource.h"
106 #include "main/querymatrix.h"
107 #include "main/queryobj.h"
108 #include "main/readpix.h"
109 #include "main/samplerobj.h"
110 #include "main/scissor.h"
111 #include "main/stencil.h"
112 #include "main/texenv.h"
113 #include "main/texgetimage.h"
114 #include "main/teximage.h"
115 #include "main/texgen.h"
116 #include "main/texobj.h"
117 #include "main/texparam.h"
118 #include "main/texstate.h"
119 #include "main/texstorage.h"
120 #include "main/barrier.h"
121 #include "main/texturebindless.h"
122 #include "main/textureview.h"
123 #include "main/transformfeedback.h"
124 #include "main/mtypes.h"
125 #include "main/varray.h"
126 #include "main/viewport.h"
127 #include "main/shaderapi.h"
128 #include "main/shaderimage.h"
129 #include "main/uniforms.h"
130 #include "main/syncobj.h"
131 #include "main/formatquery.h"
132 #include "main/dispatch.h"
133 #include "main/vdpau.h"
134
135
136 /**
137 * Initialize a context's exec table with pointers to Mesa's supported
138 * GL functions.
139 *
140 * This function depends on ctx->Version.
141 *
142 * \param ctx GL context to which \c exec belongs.
143 */
144 void
145 _mesa_initialize_exec_table(struct gl_context *ctx)
146 {
147 struct _glapi_table *exec;
148
149 exec = ctx->Exec;
150 assert(exec != NULL);
151
152 assert(ctx->Version > 0);
153
154 _mesa_initialize_exec_dispatch(ctx, exec);
155 """
156
157
158 footer = """
159 }
160 """
161
162
163 class PrintCode(gl_XML.gl_print_base):
164
165 def __init__(self):
166 gl_XML.gl_print_base.__init__(self)
167
168 self.name = 'gl_genexec.py'
169 self.license = license.bsd_license_template % (
170 'Copyright (C) 2012 Intel Corporation',
171 'Intel Corporation')
172
173 def printRealHeader(self):
174 print(header)
175
176 def printRealFooter(self):
177 print(footer)
178
179 def printBody(self, api):
180 # Collect SET_* calls by the condition under which they should
181 # be called.
182 settings_by_condition = collections.defaultdict(lambda: [])
183 for f in api.functionIterateAll():
184 if f.exec_flavor not in exec_flavor_map:
185 raise Exception(
186 'Unrecognized exec flavor {0!r}'.format(f.exec_flavor))
187 condition_parts = []
188 if f.name in apiexec.functions:
189 ex = apiexec.functions[f.name]
190 unconditional_count = 0
191
192 if ex.compatibility is not None:
193 condition_parts.append('ctx->API == API_OPENGL_COMPAT')
194 unconditional_count += 1
195
196 if ex.core is not None:
197 condition_parts.append('ctx->API == API_OPENGL_CORE')
198 unconditional_count += 1
199
200 if ex.es1 is not None:
201 condition_parts.append('ctx->API == API_OPENGLES')
202 unconditional_count += 1
203
204 if ex.es2 is not None:
205 if ex.es2 > 20:
206 condition_parts.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(ex.es2))
207 else:
208 condition_parts.append('ctx->API == API_OPENGLES2')
209 unconditional_count += 1
210
211 # If the function is unconditionally available in all four
212 # APIs, then it is always available. Replace the complex
213 # tautology condition with "true" and let GCC do the right
214 # thing.
215 if unconditional_count == 4:
216 condition_parts = ['true']
217 else:
218 if f.desktop:
219 if f.deprecated:
220 condition_parts.append('ctx->API == API_OPENGL_COMPAT')
221 else:
222 condition_parts.append('_mesa_is_desktop_gl(ctx)')
223 if 'es1' in f.api_map:
224 condition_parts.append('ctx->API == API_OPENGLES')
225 if 'es2' in f.api_map:
226 if f.api_map['es2'] > 2.0:
227 condition_parts.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(int(f.api_map['es2'] * 10)))
228 else:
229 condition_parts.append('ctx->API == API_OPENGLES2')
230
231 if not condition_parts:
232 # This function does not exist in any API.
233 continue
234 condition = ' || '.join(condition_parts)
235 prefix = exec_flavor_map[f.exec_flavor]
236 if prefix is None:
237 # This function is not implemented, or is dispatched
238 # dynamically.
239 continue
240 if f.has_no_error_variant:
241 no_error_condition = '_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition)
242 error_condition = '!_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition)
243 settings_by_condition[no_error_condition].append(
244 'SET_{0}(exec, {1}{0}_no_error);'.format(f.name, prefix, f.name))
245 settings_by_condition[error_condition].append(
246 'SET_{0}(exec, {1}{0});'.format(f.name, prefix, f.name))
247 else:
248 settings_by_condition[condition].append(
249 'SET_{0}(exec, {1}{0});'.format(f.name, prefix, f.name))
250 # Print out an if statement for each unique condition, with
251 # the SET_* calls nested inside it.
252 for condition in sorted(settings_by_condition.keys()):
253 print(' if ({0}) {{'.format(condition))
254 for setting in sorted(settings_by_condition[condition]):
255 print(' {0}'.format(setting))
256 print(' }')
257
258
259 def _parser():
260 """Parse arguments and return namespace."""
261 parser = argparse.ArgumentParser()
262 parser.add_argument('-f',
263 dest='filename',
264 default='gl_and_es_API.xml',
265 help='an xml file describing an API')
266 return parser.parse_args()
267
268
269 def main():
270 """Main function."""
271 args = _parser()
272 printer = PrintCode()
273 api = gl_XML.parse_GL_API(args.filename)
274 printer.Print(api)
275
276
277 if __name__ == '__main__':
278 main()