util/indicies: write a file with u_indicies_gen.py

This avoids meson creating a wrapper to redirect stdout, and makes the
generator faster

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19058>
This commit is contained in:
Dylan Baker 2022-10-12 14:32:01 -07:00 committed by Marge Bot
parent addd4d71fa
commit 1e523f2339
2 changed files with 236 additions and 231 deletions

View File

@ -24,7 +24,9 @@ copyright = '''
*/
'''
import argparse
import itertools
import typing as T
GENERATE, UBYTE, USHORT, UINT = 'generate', 'ubyte', 'ushort', 'uint'
FIRST, LAST = 'first', 'last'
@ -70,10 +72,10 @@ outtype_idx = dict(ushort='OUT_USHORT', uint='OUT_UINT')
pv_idx = dict(first='PV_FIRST', last='PV_LAST')
pr_idx = dict(prdisable='PR_DISABLE', prenable='PR_ENABLE')
def prolog():
print('''/* File automatically generated by u_indices_gen.py */''')
print(copyright)
print(r'''
def prolog(f: 'T.TextIO') -> None:
f.write('/* File automatically generated by u_indices_gen.py */\n')
f.write(copyright)
f.write(r'''
/**
* @file
@ -98,69 +100,68 @@ def vert( intype, outtype, v0 ):
else:
return '(' + outtype + ')in[' + v0 + ']'
def point( intype, outtype, ptr, v0 ):
print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';')
def point(f: 'T.TextIO', intype, outtype, ptr, v0 ):
f.write(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';\n')
def line( intype, outtype, ptr, v0, v1 ):
print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';')
print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';')
def line(f: 'T.TextIO', intype, outtype, ptr, v0, v1 ):
f.write(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';\n')
f.write(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';\n')
def tri( intype, outtype, ptr, v0, v1, v2 ):
print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';')
print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';')
print(' (' + ptr + ')[2] = ' + vert( intype, outtype, v2 ) + ';')
def tri(f: 'T.TextIO', intype, outtype, ptr, v0, v1, v2 ):
f.write(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';\n')
f.write(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';\n')
f.write(' (' + ptr + ')[2] = ' + vert( intype, outtype, v2 ) + ';\n')
def lineadj( intype, outtype, ptr, v0, v1, v2, v3 ):
print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';')
print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';')
print(' (' + ptr + ')[2] = ' + vert( intype, outtype, v2 ) + ';')
print(' (' + ptr + ')[3] = ' + vert( intype, outtype, v3 ) + ';')
def lineadj(f: 'T.TextIO', intype, outtype, ptr, v0, v1, v2, v3 ):
f.write(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';\n')
f.write(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';\n')
f.write(' (' + ptr + ')[2] = ' + vert( intype, outtype, v2 ) + ';\n')
f.write(' (' + ptr + ')[3] = ' + vert( intype, outtype, v3 ) + ';\n')
def triadj( intype, outtype, ptr, v0, v1, v2, v3, v4, v5 ):
print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';')
print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';')
print(' (' + ptr + ')[2] = ' + vert( intype, outtype, v2 ) + ';')
print(' (' + ptr + ')[3] = ' + vert( intype, outtype, v3 ) + ';')
print(' (' + ptr + ')[4] = ' + vert( intype, outtype, v4 ) + ';')
print(' (' + ptr + ')[5] = ' + vert( intype, outtype, v5 ) + ';')
def triadj(f: 'T.TextIO', intype, outtype, ptr, v0, v1, v2, v3, v4, v5 ):
f.write(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';\n')
f.write(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';\n')
f.write(' (' + ptr + ')[2] = ' + vert( intype, outtype, v2 ) + ';\n')
f.write(' (' + ptr + ')[3] = ' + vert( intype, outtype, v3 ) + ';\n')
f.write(' (' + ptr + ')[4] = ' + vert( intype, outtype, v4 ) + ';\n')
f.write(' (' + ptr + ')[5] = ' + vert( intype, outtype, v5 ) + ';\n')
def do_point( intype, outtype, ptr, v0 ):
point( intype, outtype, ptr, v0 )
def do_point(f: 'T.TextIO', intype, outtype, ptr, v0 ):
point(f, intype, outtype, ptr, v0 )
def do_line( intype, outtype, ptr, v0, v1, inpv, outpv ):
def do_line(f: 'T.TextIO', intype, outtype, ptr, v0, v1, inpv, outpv ):
if inpv == outpv:
line( intype, outtype, ptr, v0, v1 )
line(f, intype, outtype, ptr, v0, v1 )
else:
line( intype, outtype, ptr, v1, v0 )
line(f, intype, outtype, ptr, v1, v0 )
def do_tri( intype, outtype, ptr, v0, v1, v2, inpv, outpv ):
def do_tri(f: 'T.TextIO', intype, outtype, ptr, v0, v1, v2, inpv, outpv ):
if inpv == outpv:
tri( intype, outtype, ptr, v0, v1, v2 )
tri(f, intype, outtype, ptr, v0, v1, v2 )
elif inpv == FIRST:
tri(f, intype, outtype, ptr, v1, v2, v0 )
else:
if inpv == FIRST:
tri( intype, outtype, ptr, v1, v2, v0 )
else:
tri( intype, outtype, ptr, v2, v0, v1 )
tri(f, intype, outtype, ptr, v2, v0, v1 )
def do_quad( intype, outtype, ptr, v0, v1, v2, v3, inpv, outpv ):
def do_quad(f: 'T.TextIO', intype, outtype, ptr, v0, v1, v2, v3, inpv, outpv ):
if inpv == LAST:
do_tri( intype, outtype, ptr+'+0', v0, v1, v3, inpv, outpv );
do_tri( intype, outtype, ptr+'+3', v1, v2, v3, inpv, outpv );
do_tri(f, intype, outtype, ptr+'+0', v0, v1, v3, inpv, outpv );
do_tri(f, intype, outtype, ptr+'+3', v1, v2, v3, inpv, outpv );
else:
do_tri( intype, outtype, ptr+'+0', v0, v1, v2, inpv, outpv );
do_tri( intype, outtype, ptr+'+3', v0, v2, v3, inpv, outpv );
do_tri(f, intype, outtype, ptr+'+0', v0, v1, v2, inpv, outpv );
do_tri(f, intype, outtype, ptr+'+3', v0, v2, v3, inpv, outpv );
def do_lineadj( intype, outtype, ptr, v0, v1, v2, v3, inpv, outpv ):
def do_lineadj(f: 'T.TextIO', intype, outtype, ptr, v0, v1, v2, v3, inpv, outpv ):
if inpv == outpv:
lineadj( intype, outtype, ptr, v0, v1, v2, v3 )
lineadj(f, intype, outtype, ptr, v0, v1, v2, v3 )
else:
lineadj( intype, outtype, ptr, v3, v2, v1, v0 )
lineadj(f, intype, outtype, ptr, v3, v2, v1, v0 )
def do_triadj( intype, outtype, ptr, v0, v1, v2, v3, v4, v5, inpv, outpv ):
def do_triadj(f: 'T.TextIO', intype, outtype, ptr, v0, v1, v2, v3, v4, v5, inpv, outpv ):
if inpv == outpv:
triadj( intype, outtype, ptr, v0, v1, v2, v3, v4, v5 )
triadj(f, intype, outtype, ptr, v0, v1, v2, v3, v4, v5 )
else:
triadj( intype, outtype, ptr, v4, v5, v0, v1, v2, v3 )
triadj(f, intype, outtype, ptr, v4, v5, v0, v1, v2, v3 )
def name(intype, outtype, inpv, outpv, pr, prim):
if intype == GENERATE:
@ -168,269 +169,274 @@ def name(intype, outtype, inpv, outpv, pr, prim):
else:
return 'translate_' + prim + '_' + intype + '2' + outtype + '_' + inpv + '2' + outpv + '_' + pr
def preamble(intype, outtype, inpv, outpv, pr, prim):
print('static void ' + name( intype, outtype, inpv, outpv, pr, prim ) + '(')
def preamble(f: 'T.TextIO', intype, outtype, inpv, outpv, pr, prim):
f.write('static void ' + name( intype, outtype, inpv, outpv, pr, prim ) + '(\n')
if intype != GENERATE:
print(' const void * restrict _in,')
print(' unsigned start,')
f.write(' const void * restrict _in,\n')
f.write(' unsigned start,\n')
if intype != GENERATE:
print(' unsigned in_nr,')
print(' unsigned out_nr,')
f.write(' unsigned in_nr,\n')
f.write(' unsigned out_nr,\n')
if intype != GENERATE:
print(' unsigned restart_index,')
print(' void * restrict _out )')
print('{')
f.write(' unsigned restart_index,\n')
f.write(' void * restrict _out )\n')
f.write('{\n')
if intype != GENERATE:
print(' const ' + intype + '* restrict in = (const ' + intype + '* restrict)_in;')
print(' ' + outtype + ' * restrict out = (' + outtype + '* restrict)_out;')
print(' unsigned i, j;')
print(' (void)j;')
f.write(' const ' + intype + '* restrict in = (const ' + intype + '* restrict)_in;\n')
f.write(' ' + outtype + ' * restrict out = (' + outtype + '* restrict)_out;\n')
f.write(' unsigned i, j;\n')
f.write(' (void)j;\n')
def postamble():
print('}')
def postamble(f: 'T.TextIO'):
f.write('}\n')
def prim_restart(in_verts, out_verts, out_prims, close_func = None):
print('restart:')
print(' if (i + ' + str(in_verts) + ' > in_nr) {')
def prim_restart(f: 'T.TextIO', in_verts, out_verts, out_prims, close_func = None):
f.write('restart:\n')
f.write(' if (i + ' + str(in_verts) + ' > in_nr) {\n')
for i, j in itertools.product(range(out_prims), range(out_verts)):
print(' (out+j+' + str(out_verts * i) + ')[' + str(j) + '] = restart_index;')
print(' continue;')
print(' }')
f.write(' (out+j+' + str(out_verts * i) + ')[' + str(j) + '] = restart_index;\n')
f.write(' continue;\n')
f.write(' }\n')
for i in range(in_verts):
print(' if (in[i + ' + str(i) + '] == restart_index) {')
print(' i += ' + str(i + 1) + ';')
f.write(' if (in[i + ' + str(i) + '] == restart_index) {\n')
f.write(' i += ' + str(i + 1) + ';\n')
if close_func is not None:
close_func(i)
print(' goto restart;')
print(' }')
f.write(' goto restart;\n')
f.write(' }\n')
def points(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='points')
print(' for (i = start, j = 0; j < out_nr; j++, i++) { ')
do_point( intype, outtype, 'out+j', 'i' );
print(' }')
postamble()
def points(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='points')
f.write(' for (i = start, j = 0; j < out_nr; j++, i++) {\n')
do_point(f, intype, outtype, 'out+j', 'i' );
f.write(' }\n')
postamble(f)
def lines(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='lines')
print(' for (i = start, j = 0; j < out_nr; j+=2, i+=2) { ')
do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
print(' }')
postamble()
def lines(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='lines')
f.write(' for (i = start, j = 0; j < out_nr; j+=2, i+=2) {\n')
do_line(f, intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
f.write(' }\n')
postamble(f)
def linestrip(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='linestrip')
print(' for (i = start, j = 0; j < out_nr; j+=2, i++) { ')
do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
print(' }')
postamble()
def linestrip(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='linestrip')
f.write(' for (i = start, j = 0; j < out_nr; j+=2, i++) {\n')
do_line(f, intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
f.write(' }\n')
postamble(f)
def lineloop(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='lineloop')
print(' unsigned end = start;')
print(' for (i = start, j = 0; j < out_nr - 2; j+=2, i++) { ')
def lineloop(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='lineloop')
f.write(' unsigned end = start;\n')
f.write(' for (i = start, j = 0; j < out_nr - 2; j+=2, i++) {\n')
if pr == PRENABLE:
def close_func(index):
do_line( intype, outtype, 'out+j', 'end', 'start', inpv, outpv )
print(' start = i;')
print(' end = start;')
print(' j += 2;')
do_line(f, intype, outtype, 'out+j', 'end', 'start', inpv, outpv )
f.write(' start = i;\n')
f.write(' end = start;\n')
f.write(' j += 2;\n')
prim_restart(2, 2, 1, close_func)
prim_restart(f, 2, 2, 1, close_func)
do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
print(' end = i+1;')
print(' }')
do_line( intype, outtype, 'out+j', 'end', 'start', inpv, outpv );
postamble()
do_line(f, intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
f.write(' end = i+1;\n')
f.write(' }\n')
do_line(f, intype, outtype, 'out+j', 'end', 'start', inpv, outpv );
postamble(f)
def tris(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='tris')
print(' for (i = start, j = 0; j < out_nr; j+=3, i+=3) { ')
do_tri( intype, outtype, 'out+j', 'i', 'i+1', 'i+2', inpv, outpv );
print(' }')
postamble()
def tris(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='tris')
f.write(' for (i = start, j = 0; j < out_nr; j+=3, i+=3) {\n')
do_tri(f, intype, outtype, 'out+j', 'i', 'i+1', 'i+2', inpv, outpv );
f.write(' }\n')
postamble(f)
def tristrip(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='tristrip')
print(' for (i = start, j = 0; j < out_nr; j+=3, i++) { ')
def tristrip(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='tristrip')
f.write(' for (i = start, j = 0; j < out_nr; j+=3, i++) {\n')
if inpv == FIRST:
do_tri( intype, outtype, 'out+j', 'i', 'i+1+(i&1)', 'i+2-(i&1)', inpv, outpv );
do_tri(f, intype, outtype, 'out+j', 'i', 'i+1+(i&1)', 'i+2-(i&1)', inpv, outpv );
else:
do_tri( intype, outtype, 'out+j', 'i+(i&1)', 'i+1-(i&1)', 'i+2', inpv, outpv );
print(' }')
postamble()
do_tri(f, intype, outtype, 'out+j', 'i+(i&1)', 'i+1-(i&1)', 'i+2', inpv, outpv );
f.write(' }\n')
postamble(f)
def trifan(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='trifan')
print(' for (i = start, j = 0; j < out_nr; j+=3, i++) { ')
def trifan(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='trifan')
f.write(' for (i = start, j = 0; j < out_nr; j+=3, i++) {\n')
if pr == PRENABLE:
def close_func(index):
print(' start = i;')
prim_restart(3, 3, 1, close_func)
f.write(' start = i;\n')
prim_restart(f, 3, 3, 1, close_func)
if inpv == FIRST:
do_tri( intype, outtype, 'out+j', 'i+1', 'i+2', 'start', inpv, outpv );
do_tri(f, intype, outtype, 'out+j', 'i+1', 'i+2', 'start', inpv, outpv );
else:
do_tri( intype, outtype, 'out+j', 'start', 'i+1', 'i+2', inpv, outpv );
do_tri(f, intype, outtype, 'out+j', 'start', 'i+1', 'i+2', inpv, outpv );
print(' }')
postamble()
f.write(' }')
postamble(f)
def polygon(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='polygon')
print(' for (i = start, j = 0; j < out_nr; j+=3, i++) { ')
def polygon(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='polygon')
f.write(' for (i = start, j = 0; j < out_nr; j+=3, i++) {\n')
if pr == PRENABLE:
def close_func(index):
print(' start = i;')
prim_restart(3, 3, 1, close_func)
f.write(' start = i;\n')
prim_restart(f, 3, 3, 1, close_func)
if inpv == FIRST:
do_tri( intype, outtype, 'out+j', 'start', 'i+1', 'i+2', inpv, outpv );
do_tri(f, intype, outtype, 'out+j', 'start', 'i+1', 'i+2', inpv, outpv );
else:
do_tri( intype, outtype, 'out+j', 'i+1', 'i+2', 'start', inpv, outpv );
print(' }')
postamble()
do_tri(f, intype, outtype, 'out+j', 'i+1', 'i+2', 'start', inpv, outpv );
f.write(' }')
postamble(f)
def quads(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='quads')
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=4) { ')
def quads(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='quads')
f.write(' for (i = start, j = 0; j < out_nr; j+=6, i+=4) {\n')
if pr == PRENABLE:
prim_restart(4, 3, 2)
prim_restart(f, 4, 3, 2)
do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv );
print(' }')
postamble()
do_quad(f, intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv );
f.write(' }\n')
postamble(f)
def quadstrip(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='quadstrip')
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { ')
def quadstrip(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='quadstrip')
f.write(' for (i = start, j = 0; j < out_nr; j+=6, i+=2) {\n')
if pr == PRENABLE:
prim_restart(4, 3, 2)
prim_restart(f, 4, 3, 2)
if inpv == LAST:
do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3', inpv, outpv );
do_quad(f, intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3', inpv, outpv );
else:
do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+3', 'i+2', inpv, outpv );
print(' }')
postamble()
do_quad(f, intype, outtype, 'out+j', 'i+0', 'i+1', 'i+3', 'i+2', inpv, outpv );
f.write(' }\n')
postamble(f)
def linesadj(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='linesadj')
print(' for (i = start, j = 0; j < out_nr; j+=4, i+=4) { ')
do_lineadj( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv )
print(' }')
postamble()
def linesadj(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='linesadj')
f.write(' for (i = start, j = 0; j < out_nr; j+=4, i+=4) {\n')
do_lineadj(f, intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv )
f.write(' }\n')
postamble(f)
def linestripadj(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='linestripadj')
print(' for (i = start, j = 0; j < out_nr; j+=4, i++) {')
do_lineadj( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv )
print(' }')
postamble()
def linestripadj(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='linestripadj')
f.write(' for (i = start, j = 0; j < out_nr; j+=4, i++) {\n')
do_lineadj(f, intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv )
f.write(' }\n')
postamble(f)
def trisadj(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='trisadj')
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=6) { ')
do_triadj( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3',
'i+4', 'i+5', inpv, outpv )
print(' }')
postamble()
def trisadj(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='trisadj')
f.write(' for (i = start, j = 0; j < out_nr; j+=6, i+=6) {\n')
do_triadj(f, intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3',
'i+4', 'i+5', inpv, outpv )
f.write(' }\n')
postamble(f)
def tristripadj(intype, outtype, inpv, outpv, pr):
preamble(intype, outtype, inpv, outpv, pr, prim='tristripadj')
print(' for (i = start, j = 0; j < out_nr; i+=2, j+=6) { ')
print(' if (i % 4 == 0) {')
print(' /* even triangle */')
do_triadj( intype, outtype, 'out+j',
'i+0', 'i+1', 'i+2', 'i+3', 'i+4', 'i+5', inpv, outpv )
print(' } else {')
print(' /* odd triangle */')
do_triadj( intype, outtype, 'out+j',
'i+2', 'i-2', 'i+0', 'i+3', 'i+4', 'i+6', inpv, outpv )
print(' }')
print(' }')
postamble()
def tristripadj(f: 'T.TextIO', intype, outtype, inpv, outpv, pr):
preamble(f, intype, outtype, inpv, outpv, pr, prim='tristripadj')
f.write(' for (i = start, j = 0; j < out_nr; i+=2, j+=6) {\n')
f.write(' if (i % 4 == 0) {\n')
f.write(' /* even triangle */\n')
do_triadj(f, intype, outtype, 'out+j',
'i+0', 'i+1', 'i+2', 'i+3', 'i+4', 'i+5', inpv, outpv )
f.write(' } else {\n')
f.write(' /* odd triangle */\n')
do_triadj(f, intype, outtype, 'out+j',
'i+2', 'i-2', 'i+0', 'i+3', 'i+4', 'i+6', inpv, outpv )
f.write(' }\n')
f.write(' }\n')
postamble(f)
def emit_funcs():
def emit_funcs(f: 'T.TextIO') -> None:
for intype, outtype, inpv, outpv, pr in itertools.product(
INTYPES, OUTTYPES, [FIRST, LAST], [FIRST, LAST], [PRDISABLE, PRENABLE]):
if pr == PRENABLE and intype == GENERATE:
continue
points(intype, outtype, inpv, outpv, pr)
lines(intype, outtype, inpv, outpv, pr)
linestrip(intype, outtype, inpv, outpv, pr)
lineloop(intype, outtype, inpv, outpv, pr)
tris(intype, outtype, inpv, outpv, pr)
tristrip(intype, outtype, inpv, outpv, pr)
trifan(intype, outtype, inpv, outpv, pr)
quads(intype, outtype, inpv, outpv, pr)
quadstrip(intype, outtype, inpv, outpv, pr)
polygon(intype, outtype, inpv, outpv, pr)
linesadj(intype, outtype, inpv, outpv, pr)
linestripadj(intype, outtype, inpv, outpv, pr)
trisadj(intype, outtype, inpv, outpv, pr)
tristripadj(intype, outtype, inpv, outpv, pr)
points(f, intype, outtype, inpv, outpv, pr)
lines(f, intype, outtype, inpv, outpv, pr)
linestrip(f, intype, outtype, inpv, outpv, pr)
lineloop(f, intype, outtype, inpv, outpv, pr)
tris(f, intype, outtype, inpv, outpv, pr)
tristrip(f, intype, outtype, inpv, outpv, pr)
trifan(f, intype, outtype, inpv, outpv, pr)
quads(f, intype, outtype, inpv, outpv, pr)
quadstrip(f, intype, outtype, inpv, outpv, pr)
polygon(f, intype, outtype, inpv, outpv, pr)
linesadj(f, intype, outtype, inpv, outpv, pr)
linestripadj(f, intype, outtype, inpv, outpv, pr)
trisadj(f, intype, outtype, inpv, outpv, pr)
tristripadj(f, intype, outtype, inpv, outpv, pr)
def init(intype, outtype, inpv, outpv, pr, prim):
def init(f: 'T.TextIO', intype, outtype, inpv, outpv, pr, prim):
if intype == GENERATE:
print ('generate[' +
outtype_idx[outtype] +
'][' + pv_idx[inpv] +
'][' + pv_idx[outpv] +
'][' + longprim[prim] +
'] = ' + name( intype, outtype, inpv, outpv, pr, prim ) + ';')
f.write('generate[' +
outtype_idx[outtype] +
'][' + pv_idx[inpv] +
'][' + pv_idx[outpv] +
'][' + longprim[prim] +
'] = ' + name( intype, outtype, inpv, outpv, pr, prim ) + ';\n')
else:
print ('translate[' +
intype_idx[intype] +
'][' + outtype_idx[outtype] +
'][' + pv_idx[inpv] +
'][' + pv_idx[outpv] +
'][' + pr_idx[pr] +
'][' + longprim[prim] +
'] = ' + name( intype, outtype, inpv, outpv, pr, prim ) + ';')
f.write('translate[' +
intype_idx[intype] +
'][' + outtype_idx[outtype] +
'][' + pv_idx[inpv] +
'][' + pv_idx[outpv] +
'][' + pr_idx[pr] +
'][' + longprim[prim] +
'] = ' + name( intype, outtype, inpv, outpv, pr, prim ) + ';\n')
def emit_all_inits():
def emit_all_inits(f: 'T.TextIO'):
for intype, outtype, inpv, outpv, pr, prim in itertools.product(
INTYPES, OUTTYPES, PVS, PVS, PRS, PRIMS):
init(intype, outtype, inpv, outpv, pr, prim)
init(f,intype, outtype, inpv, outpv, pr, prim)
def emit_init():
print('void u_index_init( void )')
print('{')
print(' static int firsttime = 1;')
print(' if (!firsttime) return;')
print(' firsttime = 0;')
emit_all_inits()
print('}')
def emit_init(f: 'T.TextIO'):
f.write('void u_index_init( void )\n')
f.write('{\n')
f.write(' static int firsttime = 1;\n')
f.write(' if (!firsttime) return;\n')
f.write(' firsttime = 0;\n')
emit_all_inits(f)
f.write('}\n')
def epilog():
print('#include "indices/u_indices.c"')
def epilog(f: 'T.TextIO') -> None:
f.write('#include "indices/u_indices.c"\n')
def main():
prolog()
emit_funcs()
emit_init()
epilog()
parser = argparse.ArgumentParser()
parser.add_argument('output')
args = parser.parse_args()
with open(args.output, 'w') as f:
prolog(f)
emit_funcs(f)
emit_init(f)
epilog(f)
if __name__ == '__main__':

View File

@ -248,8 +248,7 @@ u_indices_gen_c = custom_target(
'u_indices_gen.c',
input : 'indices/u_indices_gen.py',
output : 'u_indices_gen.c',
command : [prog_python, '@INPUT@'],
capture : true,
command : [prog_python, '@INPUT@', '@OUTPUT@'],
)
u_unfilled_gen_c = custom_target(