1bf215546Sopenharmony_cicopyright = ''' 2bf215546Sopenharmony_ci/* 3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 9bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 10bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 11bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 12bf215546Sopenharmony_ci * 13bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 14bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 15bf215546Sopenharmony_ci * Software. 16bf215546Sopenharmony_ci * 17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 20bf215546Sopenharmony_ci * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 21bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 22bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 23bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 24bf215546Sopenharmony_ci */ 25bf215546Sopenharmony_ci''' 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ciGENERATE, UBYTE, USHORT, UINT = 'generate', 'ubyte', 'ushort', 'uint' 28bf215546Sopenharmony_ciFIRST, LAST = 'first', 'last' 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ciINTYPES = (GENERATE, UBYTE, USHORT, UINT) 31bf215546Sopenharmony_ciOUTTYPES = (USHORT, UINT) 32bf215546Sopenharmony_ciPRIMS=('tris', 33bf215546Sopenharmony_ci 'trifan', 34bf215546Sopenharmony_ci 'tristrip', 35bf215546Sopenharmony_ci 'quads', 36bf215546Sopenharmony_ci 'quadstrip', 37bf215546Sopenharmony_ci 'polygon', 38bf215546Sopenharmony_ci 'trisadj', 39bf215546Sopenharmony_ci 'tristripadj') 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ciLONGPRIMS=('PIPE_PRIM_TRIANGLES', 42bf215546Sopenharmony_ci 'PIPE_PRIM_TRIANGLE_FAN', 43bf215546Sopenharmony_ci 'PIPE_PRIM_TRIANGLE_STRIP', 44bf215546Sopenharmony_ci 'PIPE_PRIM_QUADS', 45bf215546Sopenharmony_ci 'PIPE_PRIM_QUAD_STRIP', 46bf215546Sopenharmony_ci 'PIPE_PRIM_POLYGON', 47bf215546Sopenharmony_ci 'PIPE_PRIM_TRIANGLES_ADJACENCY', 48bf215546Sopenharmony_ci 'PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY') 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_cilongprim = dict(zip(PRIMS, LONGPRIMS)) 51bf215546Sopenharmony_ciintype_idx = dict(ubyte='IN_UBYTE', ushort='IN_USHORT', uint='IN_UINT') 52bf215546Sopenharmony_ciouttype_idx = dict(ushort='OUT_USHORT', uint='OUT_UINT') 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_cidef prolog(): 56bf215546Sopenharmony_ci print('''/* File automatically generated by u_unfilled_gen.py */''') 57bf215546Sopenharmony_ci print(copyright) 58bf215546Sopenharmony_ci print(r''' 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci/** 61bf215546Sopenharmony_ci * @file 62bf215546Sopenharmony_ci * Functions to translate and generate index lists 63bf215546Sopenharmony_ci */ 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci#include "indices/u_indices.h" 66bf215546Sopenharmony_ci#include "indices/u_indices_priv.h" 67bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 68bf215546Sopenharmony_ci#include "util/u_debug.h" 69bf215546Sopenharmony_ci#include "pipe/p_defines.h" 70bf215546Sopenharmony_ci#include "util/u_memory.h" 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_cistatic unsigned out_size_idx( unsigned index_size ) 74bf215546Sopenharmony_ci{ 75bf215546Sopenharmony_ci switch (index_size) { 76bf215546Sopenharmony_ci case 4: return OUT_UINT; 77bf215546Sopenharmony_ci case 2: return OUT_USHORT; 78bf215546Sopenharmony_ci default: assert(0); return OUT_USHORT; 79bf215546Sopenharmony_ci } 80bf215546Sopenharmony_ci} 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_cistatic unsigned in_size_idx( unsigned index_size ) 83bf215546Sopenharmony_ci{ 84bf215546Sopenharmony_ci switch (index_size) { 85bf215546Sopenharmony_ci case 4: return IN_UINT; 86bf215546Sopenharmony_ci case 2: return IN_USHORT; 87bf215546Sopenharmony_ci case 1: return IN_UBYTE; 88bf215546Sopenharmony_ci default: assert(0); return IN_UBYTE; 89bf215546Sopenharmony_ci } 90bf215546Sopenharmony_ci} 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_cistatic u_generate_func generate_line[OUT_COUNT][PRIM_COUNT]; 94bf215546Sopenharmony_cistatic u_translate_func translate_line[IN_COUNT][OUT_COUNT][PRIM_COUNT]; 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci''') 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_cidef vert( intype, outtype, v0 ): 99bf215546Sopenharmony_ci if intype == GENERATE: 100bf215546Sopenharmony_ci return '(' + outtype + ')(' + v0 + ')' 101bf215546Sopenharmony_ci else: 102bf215546Sopenharmony_ci return '(' + outtype + ')in[' + v0 + ']' 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_cidef line( intype, outtype, ptr, v0, v1 ): 105bf215546Sopenharmony_ci print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';') 106bf215546Sopenharmony_ci print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';') 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci# XXX: have the opportunity here to avoid over-drawing shared lines in 109bf215546Sopenharmony_ci# tristrips, fans, etc, by integrating this into the calling functions 110bf215546Sopenharmony_ci# and only emitting each line at most once. 111bf215546Sopenharmony_ci# 112bf215546Sopenharmony_cidef do_tri( intype, outtype, ptr, v0, v1, v2 ): 113bf215546Sopenharmony_ci line( intype, outtype, ptr, v0, v1 ) 114bf215546Sopenharmony_ci line( intype, outtype, ptr + '+2', v1, v2 ) 115bf215546Sopenharmony_ci line( intype, outtype, ptr + '+4', v2, v0 ) 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_cidef do_quad( intype, outtype, ptr, v0, v1, v2, v3 ): 118bf215546Sopenharmony_ci line( intype, outtype, ptr, v0, v1 ) 119bf215546Sopenharmony_ci line( intype, outtype, ptr + '+2', v1, v2 ) 120bf215546Sopenharmony_ci line( intype, outtype, ptr + '+4', v2, v3 ) 121bf215546Sopenharmony_ci line( intype, outtype, ptr + '+6', v3, v0 ) 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_cidef name(intype, outtype, prim): 124bf215546Sopenharmony_ci if intype == GENERATE: 125bf215546Sopenharmony_ci return 'generate_' + prim + '_' + outtype 126bf215546Sopenharmony_ci else: 127bf215546Sopenharmony_ci return 'translate_' + prim + '_' + intype + '2' + outtype 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_cidef preamble(intype, outtype, prim): 130bf215546Sopenharmony_ci print('static void ' + name( intype, outtype, prim ) + '(') 131bf215546Sopenharmony_ci if intype != GENERATE: 132bf215546Sopenharmony_ci print(' const void * _in,') 133bf215546Sopenharmony_ci print(' unsigned start,') 134bf215546Sopenharmony_ci if intype != GENERATE: 135bf215546Sopenharmony_ci print(' unsigned in_nr,') 136bf215546Sopenharmony_ci print(' unsigned out_nr,') 137bf215546Sopenharmony_ci if intype != GENERATE: 138bf215546Sopenharmony_ci print(' unsigned restart_index,') 139bf215546Sopenharmony_ci print(' void *_out )') 140bf215546Sopenharmony_ci print('{') 141bf215546Sopenharmony_ci if intype != GENERATE: 142bf215546Sopenharmony_ci print(' const ' + intype + '*in = (const ' + intype + '*)_in;') 143bf215546Sopenharmony_ci print(' ' + outtype + ' *out = (' + outtype + '*)_out;') 144bf215546Sopenharmony_ci print(' unsigned i, j;') 145bf215546Sopenharmony_ci print(' (void)j;') 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_cidef postamble(): 148bf215546Sopenharmony_ci print('}') 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci 151bf215546Sopenharmony_cidef tris(intype, outtype): 152bf215546Sopenharmony_ci preamble(intype, outtype, prim='tris') 153bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=6, i+=3) { ') 154bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'i', 'i+1', 'i+2' ); 155bf215546Sopenharmony_ci print(' }') 156bf215546Sopenharmony_ci postamble() 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_cidef tristrip(intype, outtype): 160bf215546Sopenharmony_ci preamble(intype, outtype, prim='tristrip') 161bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ') 162bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' ); 163bf215546Sopenharmony_ci print(' }') 164bf215546Sopenharmony_ci postamble() 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_cidef trifan(intype, outtype): 168bf215546Sopenharmony_ci preamble(intype, outtype, prim='trifan') 169bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ') 170bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2' ); 171bf215546Sopenharmony_ci print(' }') 172bf215546Sopenharmony_ci postamble() 173bf215546Sopenharmony_ci 174bf215546Sopenharmony_ci 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_cidef polygon(intype, outtype): 177bf215546Sopenharmony_ci preamble(intype, outtype, prim='polygon') 178bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=2, i++) { ') 179bf215546Sopenharmony_ci line( intype, outtype, 'out+j', 'i', '(i+1)%(out_nr/2)' ) 180bf215546Sopenharmony_ci print(' }') 181bf215546Sopenharmony_ci postamble() 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_ci 184bf215546Sopenharmony_cidef quads(intype, outtype): 185bf215546Sopenharmony_ci preamble(intype, outtype, prim='quads') 186bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=8, i+=4) { ') 187bf215546Sopenharmony_ci do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' ); 188bf215546Sopenharmony_ci print(' }') 189bf215546Sopenharmony_ci postamble() 190bf215546Sopenharmony_ci 191bf215546Sopenharmony_ci 192bf215546Sopenharmony_cidef quadstrip(intype, outtype): 193bf215546Sopenharmony_ci preamble(intype, outtype, prim='quadstrip') 194bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=8, i+=2) { ') 195bf215546Sopenharmony_ci do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' ); 196bf215546Sopenharmony_ci print(' }') 197bf215546Sopenharmony_ci postamble() 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_cidef trisadj(intype, outtype): 201bf215546Sopenharmony_ci preamble(intype, outtype, prim='trisadj') 202bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=6, i+=6) { ') 203bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'i', 'i+2', 'i+4' ); 204bf215546Sopenharmony_ci print(' }') 205bf215546Sopenharmony_ci postamble() 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_ci 208bf215546Sopenharmony_cidef tristripadj(intype, outtype): 209bf215546Sopenharmony_ci preamble(intype, outtype, prim='tristripadj') 210bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { ') 211bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'i', 'i+2', 'i+4' ); 212bf215546Sopenharmony_ci print(' }') 213bf215546Sopenharmony_ci postamble() 214bf215546Sopenharmony_ci 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_cidef emit_funcs(): 217bf215546Sopenharmony_ci for intype in INTYPES: 218bf215546Sopenharmony_ci for outtype in OUTTYPES: 219bf215546Sopenharmony_ci tris(intype, outtype) 220bf215546Sopenharmony_ci tristrip(intype, outtype) 221bf215546Sopenharmony_ci trifan(intype, outtype) 222bf215546Sopenharmony_ci quads(intype, outtype) 223bf215546Sopenharmony_ci quadstrip(intype, outtype) 224bf215546Sopenharmony_ci polygon(intype, outtype) 225bf215546Sopenharmony_ci trisadj(intype, outtype) 226bf215546Sopenharmony_ci tristripadj(intype, outtype) 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_cidef init(intype, outtype, prim): 229bf215546Sopenharmony_ci if intype == GENERATE: 230bf215546Sopenharmony_ci print(('generate_line[' + 231bf215546Sopenharmony_ci outtype_idx[outtype] + 232bf215546Sopenharmony_ci '][' + longprim[prim] + 233bf215546Sopenharmony_ci '] = ' + name( intype, outtype, prim ) + ';')) 234bf215546Sopenharmony_ci else: 235bf215546Sopenharmony_ci print(('translate_line[' + 236bf215546Sopenharmony_ci intype_idx[intype] + 237bf215546Sopenharmony_ci '][' + outtype_idx[outtype] + 238bf215546Sopenharmony_ci '][' + longprim[prim] + 239bf215546Sopenharmony_ci '] = ' + name( intype, outtype, prim ) + ';')) 240bf215546Sopenharmony_ci 241bf215546Sopenharmony_ci 242bf215546Sopenharmony_cidef emit_all_inits(): 243bf215546Sopenharmony_ci for intype in INTYPES: 244bf215546Sopenharmony_ci for outtype in OUTTYPES: 245bf215546Sopenharmony_ci for prim in PRIMS: 246bf215546Sopenharmony_ci init(intype, outtype, prim) 247bf215546Sopenharmony_ci 248bf215546Sopenharmony_cidef emit_init(): 249bf215546Sopenharmony_ci print('void u_unfilled_init( void )') 250bf215546Sopenharmony_ci print('{') 251bf215546Sopenharmony_ci print(' static int firsttime = 1;') 252bf215546Sopenharmony_ci print(' if (!firsttime) return;') 253bf215546Sopenharmony_ci print(' firsttime = 0;') 254bf215546Sopenharmony_ci emit_all_inits() 255bf215546Sopenharmony_ci print('}') 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_cidef epilog(): 261bf215546Sopenharmony_ci print('#include "indices/u_unfilled_indices.c"') 262bf215546Sopenharmony_ci 263bf215546Sopenharmony_ci 264bf215546Sopenharmony_cidef main(): 265bf215546Sopenharmony_ci prolog() 266bf215546Sopenharmony_ci emit_funcs() 267bf215546Sopenharmony_ci emit_init() 268bf215546Sopenharmony_ci epilog() 269bf215546Sopenharmony_ci 270bf215546Sopenharmony_ci 271bf215546Sopenharmony_ciif __name__ == '__main__': 272bf215546Sopenharmony_ci main() 273