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_init.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 'vtxfmt': None, 37 'dlist': '_mesa_', 38 'mesa': '_mesa_', 39 'skip': None, 40 } 41 42 43header = """/** 44 * \\file api_exec_init.c 45 * Initialize dispatch table. 46 */ 47 48 49#include "api_exec_decl.h" 50#include "glapi/glapi.h" 51#include "main/context.h" 52#include "main/dispatch.h" 53 54 55/** 56 * Initialize a context's exec table with pointers to Mesa's supported 57 * GL functions. 58 * 59 * This function depends on ctx->Version. 60 * 61 * \param ctx GL context to which \c exec belongs. 62 */ 63void 64_mesa_initialize_exec_table(struct gl_context *ctx) 65{ 66 struct _glapi_table *exec; 67 68 exec = ctx->Exec; 69 assert(exec != NULL); 70 71 assert(ctx->Version > 0); 72""" 73 74 75footer = """ 76} 77""" 78 79 80class PrintCode(gl_XML.gl_print_base): 81 82 def __init__(self): 83 gl_XML.gl_print_base.__init__(self) 84 85 self.name = 'api_exec_init.py' 86 self.license = license.bsd_license_template % ( 87 'Copyright (C) 2012 Intel Corporation', 88 'Intel Corporation') 89 90 def printRealHeader(self): 91 print(header) 92 93 def printRealFooter(self): 94 print(footer) 95 96 def printBody(self, api): 97 # Collect SET_* calls by the condition under which they should 98 # be called. 99 settings_by_condition = collections.defaultdict(lambda: []) 100 for f in api.functionIterateAll(): 101 if f.exec_flavor not in exec_flavor_map: 102 raise Exception( 103 'Unrecognized exec flavor {0!r}'.format(f.exec_flavor)) 104 condition = apiexec.get_api_condition(f) 105 if not condition: 106 continue 107 prefix = exec_flavor_map[f.exec_flavor] 108 if prefix is None: 109 # This function is not implemented, or is dispatched 110 # via vtxfmt. 111 continue 112 if f.has_no_error_variant: 113 no_error_condition = '_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition) 114 error_condition = '!_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition) 115 settings_by_condition[no_error_condition].append( 116 'SET_{0}(exec, {1}{0}_no_error);'.format(f.name, prefix, f.name)) 117 settings_by_condition[error_condition].append( 118 'SET_{0}(exec, {1}{0});'.format(f.name, prefix, f.name)) 119 else: 120 settings_by_condition[condition].append( 121 'SET_{0}(exec, {1}{0});'.format(f.name, prefix, f.name)) 122 # Print out an if statement for each unique condition, with 123 # the SET_* calls nested inside it. 124 for condition in sorted(settings_by_condition.keys()): 125 print(' if ({0}) {{'.format(condition)) 126 for setting in sorted(settings_by_condition[condition]): 127 print(' {0}'.format(setting)) 128 print(' }') 129 130 131if __name__ == '__main__': 132 apiexec.print_glapi_file(PrintCode()) 133