2 # Copyright (C) 2012 Intel Corporation
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:
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
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
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.
27 from __future__
import print_function
46 * Initialize dispatch table.
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"
84 #include "main/glspirv.h"
85 #include "main/feedback.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/imports.h"
93 #include "main/light.h"
94 #include "main/lines.h"
95 #include "main/matrix.h"
96 #include "main/multisample.h"
97 #include "main/objectlabel.h"
98 #include "main/objectpurge.h"
99 #include "main/performance_monitor.h"
100 #include "main/performance_query.h"
101 #include "main/pipelineobj.h"
102 #include "main/pixel.h"
103 #include "main/pixelstore.h"
104 #include "main/points.h"
105 #include "main/polygon.h"
106 #include "main/program_resource.h"
107 #include "main/querymatrix.h"
108 #include "main/queryobj.h"
109 #include "main/readpix.h"
110 #include "main/samplerobj.h"
111 #include "main/scissor.h"
112 #include "main/stencil.h"
113 #include "main/texenv.h"
114 #include "main/texgetimage.h"
115 #include "main/teximage.h"
116 #include "main/texgen.h"
117 #include "main/texobj.h"
118 #include "main/texparam.h"
119 #include "main/texstate.h"
120 #include "main/texstorage.h"
121 #include "main/barrier.h"
122 #include "main/texturebindless.h"
123 #include "main/textureview.h"
124 #include "main/transformfeedback.h"
125 #include "main/mtypes.h"
126 #include "main/varray.h"
127 #include "main/viewport.h"
128 #include "main/shaderapi.h"
129 #include "main/shaderimage.h"
130 #include "main/uniforms.h"
131 #include "main/syncobj.h"
132 #include "main/formatquery.h"
133 #include "main/dispatch.h"
134 #include "main/vdpau.h"
138 * Initialize a context's exec table with pointers to Mesa's supported
141 * This function depends on ctx->Version.
143 * \param ctx GL context to which \c exec belongs.
146 _mesa_initialize_exec_table(struct gl_context *ctx)
148 struct _glapi_table *exec;
151 assert(exec != NULL);
153 assert(ctx->Version > 0);
155 _mesa_initialize_exec_dispatch(ctx, exec);
164 class PrintCode(gl_XML
.gl_print_base
):
167 gl_XML
.gl_print_base
.__init
__(self
)
169 self
.name
= 'gl_genexec.py'
170 self
.license
= license
.bsd_license_template
% (
171 'Copyright (C) 2012 Intel Corporation',
174 def printRealHeader(self
):
177 def printRealFooter(self
):
180 def printBody(self
, api
):
181 # Collect SET_* calls by the condition under which they should
183 settings_by_condition
= collections
.defaultdict(lambda: [])
184 for f
in api
.functionIterateAll():
185 if f
.exec_flavor
not in exec_flavor_map
:
187 'Unrecognized exec flavor {0!r}'.format(f
.exec_flavor
))
189 if f
.name
in apiexec
.functions
:
190 ex
= apiexec
.functions
[f
.name
]
191 unconditional_count
= 0
193 if ex
.compatibility
is not None:
194 condition_parts
.append('ctx->API == API_OPENGL_COMPAT')
195 unconditional_count
+= 1
197 if ex
.core
is not None:
198 condition_parts
.append('ctx->API == API_OPENGL_CORE')
199 unconditional_count
+= 1
201 if ex
.es1
is not None:
202 condition_parts
.append('ctx->API == API_OPENGLES')
203 unconditional_count
+= 1
205 if ex
.es2
is not None:
207 condition_parts
.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(ex
.es2
))
209 condition_parts
.append('ctx->API == API_OPENGLES2')
210 unconditional_count
+= 1
212 # If the function is unconditionally available in all four
213 # APIs, then it is always available. Replace the complex
214 # tautology condition with "true" and let GCC do the right
216 if unconditional_count
== 4:
217 condition_parts
= ['true']
221 condition_parts
.append('ctx->API == API_OPENGL_COMPAT')
223 condition_parts
.append('_mesa_is_desktop_gl(ctx)')
224 if 'es1' in f
.api_map
:
225 condition_parts
.append('ctx->API == API_OPENGLES')
226 if 'es2' in f
.api_map
:
227 if f
.api_map
['es2'] > 2.0:
228 condition_parts
.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(int(f
.api_map
['es2'] * 10)))
230 condition_parts
.append('ctx->API == API_OPENGLES2')
232 if not condition_parts
:
233 # This function does not exist in any API.
235 condition
= ' || '.join(condition_parts
)
236 prefix
= exec_flavor_map
[f
.exec_flavor
]
238 # This function is not implemented, or is dispatched
241 if f
.has_no_error_variant
:
242 no_error_condition
= '_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition
)
243 error_condition
= '!_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition
)
244 settings_by_condition
[no_error_condition
].append(
245 'SET_{0}(exec, {1}{0}_no_error);'.format(f
.name
, prefix
, f
.name
))
246 settings_by_condition
[error_condition
].append(
247 'SET_{0}(exec, {1}{0});'.format(f
.name
, prefix
, f
.name
))
249 settings_by_condition
[condition
].append(
250 'SET_{0}(exec, {1}{0});'.format(f
.name
, prefix
, f
.name
))
251 # Print out an if statement for each unique condition, with
252 # the SET_* calls nested inside it.
253 for condition
in sorted(settings_by_condition
.keys()):
254 print(' if ({0}) {{'.format(condition
))
255 for setting
in sorted(settings_by_condition
[condition
]):
256 print(' {0}'.format(setting
))
261 """Parse arguments and return namespace."""
262 parser
= argparse
.ArgumentParser()
263 parser
.add_argument('-f',
265 default
='gl_and_es_API.xml',
266 help='an xml file describing an API')
267 return parser
.parse_args()
273 printer
= PrintCode()
274 api
= gl_XML
.parse_GL_API(args
.filename
)
278 if __name__
== '__main__':