mesa: Separate INTEL_performance_query frontend
[mesa.git] / src / mapi / glapi / gen / gl_genexec.py
1 #!/usr/bin/env python
2
3 # Copyright (C) 2012 Intel Corporation
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 # IN THE SOFTWARE.
23
24 # This script generates the file api_exec.c, which contains
25 # _mesa_initialize_exec_table(). It is responsible for populating all
26 # entries in the "exec" dispatch table that aren't dynamic.
27
28 import argparse
29 import collections
30 import license
31 import gl_XML
32 import sys
33 import apiexec
34
35
36 exec_flavor_map = {
37 'dynamic': None,
38 'mesa': '_mesa_',
39 'skip': None,
40 }
41
42
43 header = """/**
44 * \\file api_exec.c
45 * Initialize dispatch table.
46 */
47
48
49 #include "main/accum.h"
50 #include "main/api_loopback.h"
51 #include "main/api_exec.h"
52 #include "main/arbprogram.h"
53 #include "main/atifragshader.h"
54 #include "main/attrib.h"
55 #include "main/blend.h"
56 #include "main/blit.h"
57 #include "main/bufferobj.h"
58 #include "main/arrayobj.h"
59 #include "main/bbox.h"
60 #include "main/buffers.h"
61 #include "main/clear.h"
62 #include "main/clip.h"
63 #include "main/colortab.h"
64 #include "main/compute.h"
65 #include "main/condrender.h"
66 #include "main/context.h"
67 #include "main/convolve.h"
68 #include "main/copyimage.h"
69 #include "main/depth.h"
70 #include "main/debug_output.h"
71 #include "main/dlist.h"
72 #include "main/drawpix.h"
73 #include "main/drawtex.h"
74 #include "main/rastpos.h"
75 #include "main/enable.h"
76 #include "main/errors.h"
77 #include "main/es1_conversion.h"
78 #include "main/eval.h"
79 #include "main/get.h"
80 #include "main/feedback.h"
81 #include "main/fog.h"
82 #include "main/fbobject.h"
83 #include "main/framebuffer.h"
84 #include "main/genmipmap.h"
85 #include "main/hint.h"
86 #include "main/histogram.h"
87 #include "main/imports.h"
88 #include "main/light.h"
89 #include "main/lines.h"
90 #include "main/matrix.h"
91 #include "main/multisample.h"
92 #include "main/objectlabel.h"
93 #include "main/objectpurge.h"
94 #include "main/performance_monitor.h"
95 #include "main/performance_query.h"
96 #include "main/pipelineobj.h"
97 #include "main/pixel.h"
98 #include "main/pixelstore.h"
99 #include "main/points.h"
100 #include "main/polygon.h"
101 #include "main/program_resource.h"
102 #include "main/querymatrix.h"
103 #include "main/queryobj.h"
104 #include "main/readpix.h"
105 #include "main/samplerobj.h"
106 #include "main/scissor.h"
107 #include "main/stencil.h"
108 #include "main/texenv.h"
109 #include "main/texgetimage.h"
110 #include "main/teximage.h"
111 #include "main/texgen.h"
112 #include "main/texobj.h"
113 #include "main/texparam.h"
114 #include "main/texstate.h"
115 #include "main/texstorage.h"
116 #include "main/barrier.h"
117 #include "main/textureview.h"
118 #include "main/transformfeedback.h"
119 #include "main/mtypes.h"
120 #include "main/varray.h"
121 #include "main/viewport.h"
122 #include "main/shaderapi.h"
123 #include "main/shaderimage.h"
124 #include "main/uniforms.h"
125 #include "main/syncobj.h"
126 #include "main/formatquery.h"
127 #include "main/dispatch.h"
128 #include "main/vdpau.h"
129 #include "vbo/vbo.h"
130
131
132 /**
133 * Initialize a context's exec table with pointers to Mesa's supported
134 * GL functions.
135 *
136 * This function depends on ctx->Version.
137 *
138 * \param ctx GL context to which \c exec belongs.
139 */
140 void
141 _mesa_initialize_exec_table(struct gl_context *ctx)
142 {
143 struct _glapi_table *exec;
144
145 exec = ctx->Exec;
146 assert(exec != NULL);
147
148 assert(ctx->Version > 0);
149
150 vbo_initialize_exec_dispatch(ctx, exec);
151 """
152
153
154 footer = """
155 }
156 """
157
158
159 class PrintCode(gl_XML.gl_print_base):
160
161 def __init__(self):
162 gl_XML.gl_print_base.__init__(self)
163
164 self.name = 'gl_genexec.py'
165 self.license = license.bsd_license_template % (
166 'Copyright (C) 2012 Intel Corporation',
167 'Intel Corporation')
168
169 def printRealHeader(self):
170 print header
171
172 def printRealFooter(self):
173 print footer
174
175 def printBody(self, api):
176 # Collect SET_* calls by the condition under which they should
177 # be called.
178 settings_by_condition = collections.defaultdict(lambda: [])
179 for f in api.functionIterateAll():
180 if f.exec_flavor not in exec_flavor_map:
181 raise Exception(
182 'Unrecognized exec flavor {0!r}'.format(f.exec_flavor))
183 condition_parts = []
184 if f.name in apiexec.functions:
185 ex = apiexec.functions[f.name]
186 unconditional_count = 0
187
188 if ex.compatibility is not None:
189 condition_parts.append('ctx->API == API_OPENGL_COMPAT')
190 unconditional_count += 1
191
192 if ex.core is not None:
193 condition_parts.append('ctx->API == API_OPENGL_CORE')
194 unconditional_count += 1
195
196 if ex.es1 is not None:
197 condition_parts.append('ctx->API == API_OPENGLES')
198 unconditional_count += 1
199
200 if ex.es2 is not None:
201 if ex.es2 > 20:
202 condition_parts.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(ex.es2))
203 else:
204 condition_parts.append('ctx->API == API_OPENGLES2')
205 unconditional_count += 1
206
207 # If the function is unconditionally available in all four
208 # APIs, then it is always available. Replace the complex
209 # tautology condition with "true" and let GCC do the right
210 # thing.
211 if unconditional_count == 4:
212 condition_parts = ['true']
213 else:
214 if f.desktop:
215 if f.deprecated:
216 condition_parts.append('ctx->API == API_OPENGL_COMPAT')
217 else:
218 condition_parts.append('_mesa_is_desktop_gl(ctx)')
219 if 'es1' in f.api_map:
220 condition_parts.append('ctx->API == API_OPENGLES')
221 if 'es2' in f.api_map:
222 if f.api_map['es2'] > 2.0:
223 condition_parts.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(int(f.api_map['es2'] * 10)))
224 else:
225 condition_parts.append('ctx->API == API_OPENGLES2')
226
227 if not condition_parts:
228 # This function does not exist in any API.
229 continue
230 condition = ' || '.join(condition_parts)
231 prefix = exec_flavor_map[f.exec_flavor]
232 if prefix is None:
233 # This function is not implemented, or is dispatched
234 # dynamically.
235 continue
236 settings_by_condition[condition].append(
237 'SET_{0}(exec, {1}{0});'.format(f.name, prefix, f.name))
238 # Print out an if statement for each unique condition, with
239 # the SET_* calls nested inside it.
240 for condition in sorted(settings_by_condition.keys()):
241 print ' if ({0}) {{'.format(condition)
242 for setting in sorted(settings_by_condition[condition]):
243 print ' {0}'.format(setting)
244 print ' }'
245
246
247 def _parser():
248 """Parse arguments and return namespace."""
249 parser = argparse.ArgumentParser()
250 parser.add_argument('-f',
251 dest='filename',
252 default='gl_and_es_API.xml',
253 help='an xml file describing an API')
254 return parser.parse_args()
255
256
257 def main():
258 """Main function."""
259 args = _parser()
260 printer = PrintCode()
261 api = gl_XML.parse_GL_API(args.filename)
262 printer.Print(api)
263
264
265 if __name__ == '__main__':
266 main()