mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-02 10:08:08 +02:00
util/indicies: convert u_unfilled_gen.py to write a file
Which avoids meson needing to wrap the generator to capture the output, and makes it 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:
parent
090e71e0bf
commit
c6aca79f63
2 changed files with 122 additions and 116 deletions
|
|
@ -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'
|
||||
|
|
@ -54,10 +56,10 @@ intype_idx = dict(ubyte='IN_UBYTE', ushort='IN_USHORT', uint='IN_UINT')
|
|||
outtype_idx = dict(ushort='OUT_USHORT', uint='OUT_UINT')
|
||||
|
||||
|
||||
def prolog():
|
||||
print('''/* File automatically generated by u_unfilled_gen.py */''')
|
||||
print(copyright)
|
||||
print(r'''
|
||||
def prolog(f: 'T.TextIO'):
|
||||
f.write('/* File automatically generated by u_unfilled_gen.py */\n')
|
||||
f.write(copyright)
|
||||
f.write(r'''
|
||||
|
||||
/**
|
||||
* @file
|
||||
|
|
@ -82,24 +84,24 @@ def vert( intype, outtype, v0 ):
|
|||
else:
|
||||
return '(' + outtype + ')in[' + v0 + ']'
|
||||
|
||||
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')
|
||||
|
||||
# XXX: have the opportunity here to avoid over-drawing shared lines in
|
||||
# tristrips, fans, etc, by integrating this into the calling functions
|
||||
# and only emitting each line at most once.
|
||||
#
|
||||
def do_tri( intype, outtype, ptr, v0, v1, v2 ):
|
||||
line( intype, outtype, ptr, v0, v1 )
|
||||
line( intype, outtype, ptr + '+2', v1, v2 )
|
||||
line( intype, outtype, ptr + '+4', v2, v0 )
|
||||
def do_tri(f: 'T.TextIO', intype, outtype, ptr, v0, v1, v2 ):
|
||||
line(f, intype, outtype, ptr, v0, v1 )
|
||||
line(f, intype, outtype, ptr + '+2', v1, v2 )
|
||||
line(f, intype, outtype, ptr + '+4', v2, v0 )
|
||||
|
||||
def do_quad( intype, outtype, ptr, v0, v1, v2, v3 ):
|
||||
line( intype, outtype, ptr, v0, v1 )
|
||||
line( intype, outtype, ptr + '+2', v1, v2 )
|
||||
line( intype, outtype, ptr + '+4', v2, v3 )
|
||||
line( intype, outtype, ptr + '+6', v3, v0 )
|
||||
def do_quad(f: 'T.TextIO', intype, outtype, ptr, v0, v1, v2, v3 ):
|
||||
line(f, intype, outtype, ptr, v0, v1 )
|
||||
line(f, intype, outtype, ptr + '+2', v1, v2 )
|
||||
line(f, intype, outtype, ptr + '+4', v2, v3 )
|
||||
line(f, intype, outtype, ptr + '+6', v3, v0 )
|
||||
|
||||
def name(intype, outtype, prim):
|
||||
if intype == GENERATE:
|
||||
|
|
@ -107,143 +109,148 @@ def name(intype, outtype, prim):
|
|||
else:
|
||||
return 'translate_' + prim + '_' + intype + '2' + outtype
|
||||
|
||||
def preamble(intype, outtype, prim):
|
||||
print('static void ' + name( intype, outtype, prim ) + '(')
|
||||
def preamble(f: 'T.TextIO', intype, outtype, prim):
|
||||
f.write('static void ' + name( intype, outtype, prim ) + '(\n')
|
||||
if intype != GENERATE:
|
||||
print(' const void * _in,')
|
||||
print(' unsigned start,')
|
||||
f.write(' const void * _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 *_out )')
|
||||
print('{')
|
||||
f.write(' unsigned restart_index,\n')
|
||||
f.write(' void *_out )\n')
|
||||
f.write('{\n')
|
||||
if intype != GENERATE:
|
||||
print(' const ' + intype + '*in = (const ' + intype + '*)_in;')
|
||||
print(' ' + outtype + ' *out = (' + outtype + '*)_out;')
|
||||
print(' unsigned i, j;')
|
||||
print(' (void)j;')
|
||||
f.write(' const ' + intype + '*in = (const ' + intype + '*)_in;\n')
|
||||
f.write(' ' + outtype + ' *out = (' + outtype + '*)_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 tris(intype, outtype):
|
||||
preamble(intype, outtype, prim='tris')
|
||||
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=3) { ')
|
||||
do_tri( intype, outtype, 'out+j', 'i', 'i+1', 'i+2' );
|
||||
print(' }')
|
||||
postamble()
|
||||
def tris(f: 'T.TextIO', intype, outtype):
|
||||
preamble(f, intype, outtype, prim='tris')
|
||||
f.write(' for (i = start, j = 0; j < out_nr; j+=6, i+=3) {\n')
|
||||
do_tri(f, intype, outtype, 'out+j', 'i', 'i+1', 'i+2' );
|
||||
f.write(' }\n')
|
||||
postamble(f)
|
||||
|
||||
|
||||
def tristrip(intype, outtype):
|
||||
preamble(intype, outtype, prim='tristrip')
|
||||
print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ')
|
||||
do_tri( intype, outtype, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' );
|
||||
print(' }')
|
||||
postamble()
|
||||
def tristrip(f: 'T.TextIO', intype, outtype):
|
||||
preamble(f, intype, outtype, prim='tristrip')
|
||||
f.write(' for (i = start, j = 0; j < out_nr; j+=6, i++) {\n')
|
||||
do_tri(f, intype, outtype, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' );
|
||||
f.write(' }\n')
|
||||
postamble(f)
|
||||
|
||||
|
||||
def trifan(intype, outtype):
|
||||
preamble(intype, outtype, prim='trifan')
|
||||
print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ')
|
||||
do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2' );
|
||||
print(' }')
|
||||
postamble()
|
||||
def trifan(f: 'T.TextIO', intype, outtype):
|
||||
preamble(f, intype, outtype, prim='trifan')
|
||||
f.write(' for (i = start, j = 0; j < out_nr; j+=6, i++) {\n')
|
||||
do_tri(f, intype, outtype, 'out+j', '0', 'i+1', 'i+2' );
|
||||
f.write(' }\n')
|
||||
postamble(f)
|
||||
|
||||
|
||||
|
||||
def polygon(intype, outtype):
|
||||
preamble(intype, outtype, prim='polygon')
|
||||
print(' for (i = start, j = 0; j < out_nr; j+=2, i++) { ')
|
||||
line( intype, outtype, 'out+j', 'i', '(i+1)%(out_nr/2)' )
|
||||
print(' }')
|
||||
postamble()
|
||||
def polygon(f: 'T.TextIO', intype, outtype):
|
||||
preamble(f, intype, outtype, prim='polygon')
|
||||
f.write(' for (i = start, j = 0; j < out_nr; j+=2, i++) {\n')
|
||||
line(f, intype, outtype, 'out+j', 'i', '(i+1)%(out_nr/2)\n' )
|
||||
f.write(' }\n')
|
||||
postamble(f)
|
||||
|
||||
|
||||
def quads(intype, outtype):
|
||||
preamble(intype, outtype, prim='quads')
|
||||
print(' for (i = start, j = 0; j < out_nr; j+=8, i+=4) { ')
|
||||
do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' );
|
||||
print(' }')
|
||||
postamble()
|
||||
def quads(f: 'T.TextIO', intype, outtype):
|
||||
preamble(f, intype, outtype, prim='quads')
|
||||
f.write(' for (i = start, j = 0; j < out_nr; j+=8, i+=4) {\n')
|
||||
do_quad(f, intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' );
|
||||
f.write(' }\n')
|
||||
postamble(f)
|
||||
|
||||
|
||||
def quadstrip(intype, outtype):
|
||||
preamble(intype, outtype, prim='quadstrip')
|
||||
print(' for (i = start, j = 0; j < out_nr; j+=8, i+=2) { ')
|
||||
do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' );
|
||||
print(' }')
|
||||
postamble()
|
||||
def quadstrip(f: 'T.TextIO', intype, outtype):
|
||||
preamble(f, intype, outtype, prim='quadstrip')
|
||||
f.write(' for (i = start, j = 0; j < out_nr; j+=8, i+=2) {\n')
|
||||
do_quad(f, intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' );
|
||||
f.write(' }\n')
|
||||
postamble(f)
|
||||
|
||||
|
||||
def trisadj(intype, outtype):
|
||||
preamble(intype, outtype, prim='trisadj')
|
||||
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=6) { ')
|
||||
do_tri( intype, outtype, 'out+j', 'i', 'i+2', 'i+4' );
|
||||
print(' }')
|
||||
postamble()
|
||||
def trisadj(f: 'T.TextIO', intype, outtype):
|
||||
preamble(f, intype, outtype, prim='trisadj')
|
||||
f.write(' for (i = start, j = 0; j < out_nr; j+=6, i+=6) {\n')
|
||||
do_tri(f, intype, outtype, 'out+j', 'i', 'i+2', 'i+4' );
|
||||
f.write(' }\n')
|
||||
postamble(f)
|
||||
|
||||
|
||||
def tristripadj(intype, outtype):
|
||||
preamble(intype, outtype, prim='tristripadj')
|
||||
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { ')
|
||||
do_tri( intype, outtype, 'out+j', 'i', 'i+2', 'i+4' );
|
||||
print(' }')
|
||||
postamble()
|
||||
def tristripadj(f: 'T.TextIO', intype, outtype):
|
||||
preamble(f, intype, outtype, prim='tristripadj')
|
||||
f.write(' for (i = start, j = 0; j < out_nr; j+=6, i+=2) {\n')
|
||||
do_tri(f, intype, outtype, 'out+j', 'i', 'i+2', 'i+4' );
|
||||
f.write(' }\n')
|
||||
postamble(f)
|
||||
|
||||
|
||||
def emit_funcs():
|
||||
def emit_funcs(f: 'T.TextIO'):
|
||||
for intype, outtype in itertools.product(INTYPES, OUTTYPES):
|
||||
tris(intype, outtype)
|
||||
tristrip(intype, outtype)
|
||||
trifan(intype, outtype)
|
||||
quads(intype, outtype)
|
||||
quadstrip(intype, outtype)
|
||||
polygon(intype, outtype)
|
||||
trisadj(intype, outtype)
|
||||
tristripadj(intype, outtype)
|
||||
tris(f, intype, outtype)
|
||||
tristrip(f, intype, outtype)
|
||||
trifan(f, intype, outtype)
|
||||
quads(f, intype, outtype)
|
||||
quadstrip(f, intype, outtype)
|
||||
polygon(f, intype, outtype)
|
||||
trisadj(f, intype, outtype)
|
||||
tristripadj(f, intype, outtype)
|
||||
|
||||
def init(intype, outtype, prim):
|
||||
def init(f: 'T.TextIO', intype, outtype, prim):
|
||||
if intype == GENERATE:
|
||||
print(('generate_line[' +
|
||||
outtype_idx[outtype] +
|
||||
'][' + longprim[prim] +
|
||||
'] = ' + name( intype, outtype, prim ) + ';'))
|
||||
f.write('generate_line[' +
|
||||
outtype_idx[outtype] +
|
||||
'][' + longprim[prim] +
|
||||
'] = ' + name( intype, outtype, prim ) + ';\n')
|
||||
else:
|
||||
print(('translate_line[' +
|
||||
intype_idx[intype] +
|
||||
'][' + outtype_idx[outtype] +
|
||||
'][' + longprim[prim] +
|
||||
'] = ' + name( intype, outtype, prim ) + ';'))
|
||||
f.write('translate_line[' +
|
||||
intype_idx[intype] +
|
||||
'][' + outtype_idx[outtype] +
|
||||
'][' + longprim[prim] +
|
||||
'] = ' + name( intype, outtype, prim ) + ';\n')
|
||||
|
||||
|
||||
def emit_all_inits():
|
||||
def emit_all_inits(f: 'T.TextIO'):
|
||||
for intype, outtype, prim in itertools.product(INTYPES, OUTTYPES, PRIMS):
|
||||
init(intype, outtype, prim)
|
||||
init(f, intype, outtype, prim)
|
||||
|
||||
def emit_init():
|
||||
print('void u_unfilled_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_unfilled_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_unfilled_indices.c"')
|
||||
def epilog(f: 'T.TextIO'):
|
||||
f.write('#include "indices/u_unfilled_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__':
|
||||
|
|
|
|||
|
|
@ -255,8 +255,7 @@ u_unfilled_gen_c = custom_target(
|
|||
'u_unfilled_gen.c',
|
||||
input : 'indices/u_unfilled_gen.py',
|
||||
output : 'u_unfilled_gen.c',
|
||||
command : [prog_python, '@INPUT@'],
|
||||
capture : true,
|
||||
command : [prog_python, '@INPUT@', '@OUTPUT@'],
|
||||
)
|
||||
|
||||
libmesa_util_sse41 = static_library(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue