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