2009-03-04 21:35:17 +00:00
|
|
|
copyright = '''
|
|
|
|
/*
|
|
|
|
* Copyright 2009 VMware, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* on the rights to use, copy, modify, merge, publish, distribute, sub
|
|
|
|
* license, and/or sell copies of the Software, and to permit persons to whom
|
|
|
|
* the Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
'''
|
|
|
|
|
|
|
|
GENERATE, UBYTE, USHORT, UINT = 'generate', 'ubyte', 'ushort', 'uint'
|
|
|
|
FIRST, LAST = 'first', 'last'
|
|
|
|
|
|
|
|
INTYPES = (GENERATE, UBYTE, USHORT, UINT)
|
|
|
|
OUTTYPES = (USHORT, UINT)
|
|
|
|
PRIMS=('tris',
|
|
|
|
'trifan',
|
|
|
|
'tristrip',
|
|
|
|
'quads',
|
|
|
|
'quadstrip',
|
2016-05-25 18:58:29 +01:00
|
|
|
'polygon',
|
|
|
|
'trisadj',
|
|
|
|
'tristripadj')
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
LONGPRIMS=('PIPE_PRIM_TRIANGLES',
|
|
|
|
'PIPE_PRIM_TRIANGLE_FAN',
|
|
|
|
'PIPE_PRIM_TRIANGLE_STRIP',
|
|
|
|
'PIPE_PRIM_QUADS',
|
|
|
|
'PIPE_PRIM_QUAD_STRIP',
|
2016-05-25 18:58:29 +01:00
|
|
|
'PIPE_PRIM_POLYGON',
|
|
|
|
'PIPE_PRIM_TRIANGLES_ADJACENCY',
|
|
|
|
'PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY')
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
longprim = dict(zip(PRIMS, LONGPRIMS))
|
|
|
|
intype_idx = dict(ubyte='IN_UBYTE', ushort='IN_USHORT', uint='IN_UINT')
|
|
|
|
outtype_idx = dict(ushort='OUT_USHORT', uint='OUT_UINT')
|
|
|
|
|
|
|
|
|
|
|
|
def prolog():
|
2018-07-05 14:17:32 +01:00
|
|
|
print('''/* File automatically generated by u_unfilled_gen.py */''')
|
|
|
|
print(copyright)
|
|
|
|
print(r'''
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Functions to translate and generate index lists
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "indices/u_indices.h"
|
|
|
|
#include "indices/u_indices_priv.h"
|
|
|
|
#include "pipe/p_compiler.h"
|
|
|
|
#include "util/u_debug.h"
|
|
|
|
#include "pipe/p_defines.h"
|
|
|
|
#include "util/u_memory.h"
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned out_size_idx( unsigned index_size )
|
|
|
|
{
|
|
|
|
switch (index_size) {
|
|
|
|
case 4: return OUT_UINT;
|
|
|
|
case 2: return OUT_USHORT;
|
|
|
|
default: assert(0); return OUT_USHORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned in_size_idx( unsigned index_size )
|
|
|
|
{
|
|
|
|
switch (index_size) {
|
|
|
|
case 4: return IN_UINT;
|
|
|
|
case 2: return IN_USHORT;
|
|
|
|
case 1: return IN_UBYTE;
|
|
|
|
default: assert(0); return IN_UBYTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static u_generate_func generate_line[OUT_COUNT][PRIM_COUNT];
|
|
|
|
static u_translate_func translate_line[IN_COUNT][OUT_COUNT][PRIM_COUNT];
|
|
|
|
|
2018-07-05 14:17:32 +01:00
|
|
|
''')
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
def vert( intype, outtype, v0 ):
|
|
|
|
if intype == GENERATE:
|
|
|
|
return '(' + outtype + ')(' + v0 + ')'
|
|
|
|
else:
|
|
|
|
return '(' + outtype + ')in[' + v0 + ']'
|
|
|
|
|
|
|
|
def line( intype, outtype, ptr, v0, v1 ):
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';')
|
|
|
|
print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';')
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
# 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_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 name(intype, outtype, prim):
|
|
|
|
if intype == GENERATE:
|
|
|
|
return 'generate_' + prim + '_' + outtype
|
|
|
|
else:
|
|
|
|
return 'translate_' + prim + '_' + intype + '2' + outtype
|
|
|
|
|
|
|
|
def preamble(intype, outtype, prim):
|
2018-07-05 14:17:32 +01:00
|
|
|
print('static void ' + name( intype, outtype, prim ) + '(')
|
2009-03-04 21:35:17 +00:00
|
|
|
if intype != GENERATE:
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' const void * _in,')
|
|
|
|
print(' unsigned start,')
|
2015-03-18 01:46:45 +00:00
|
|
|
if intype != GENERATE:
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' unsigned in_nr,')
|
|
|
|
print(' unsigned out_nr,')
|
2015-03-18 01:46:45 +00:00
|
|
|
if intype != GENERATE:
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' unsigned restart_index,')
|
|
|
|
print(' void *_out )')
|
|
|
|
print('{')
|
2009-03-04 21:35:17 +00:00
|
|
|
if intype != GENERATE:
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' const ' + intype + '*in = (const ' + intype + '*)_in;')
|
|
|
|
print(' ' + outtype + ' *out = (' + outtype + '*)_out;')
|
|
|
|
print(' unsigned i, j;')
|
|
|
|
print(' (void)j;')
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
def postamble():
|
2018-07-05 14:17:32 +01:00
|
|
|
print('}')
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
def tris(intype, outtype):
|
|
|
|
preamble(intype, outtype, prim='tris')
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=3) { ')
|
2009-03-04 21:35:17 +00:00
|
|
|
do_tri( intype, outtype, 'out+j', 'i', 'i+1', 'i+2' );
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' }')
|
2009-03-04 21:35:17 +00:00
|
|
|
postamble()
|
|
|
|
|
|
|
|
|
|
|
|
def tristrip(intype, outtype):
|
|
|
|
preamble(intype, outtype, prim='tristrip')
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ')
|
2009-03-04 21:35:17 +00:00
|
|
|
do_tri( intype, outtype, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' );
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' }')
|
2009-03-04 21:35:17 +00:00
|
|
|
postamble()
|
|
|
|
|
|
|
|
|
|
|
|
def trifan(intype, outtype):
|
|
|
|
preamble(intype, outtype, prim='trifan')
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ')
|
2009-03-04 21:35:17 +00:00
|
|
|
do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2' );
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' }')
|
2009-03-04 21:35:17 +00:00
|
|
|
postamble()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def polygon(intype, outtype):
|
|
|
|
preamble(intype, outtype, prim='polygon')
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' for (i = start, j = 0; j < out_nr; j+=2, i++) { ')
|
2015-03-18 01:46:45 +00:00
|
|
|
line( intype, outtype, 'out+j', 'i', '(i+1)%(out_nr/2)' )
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' }')
|
2009-03-04 21:35:17 +00:00
|
|
|
postamble()
|
|
|
|
|
|
|
|
|
|
|
|
def quads(intype, outtype):
|
|
|
|
preamble(intype, outtype, prim='quads')
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' for (i = start, j = 0; j < out_nr; j+=8, i+=4) { ')
|
2009-03-04 21:35:17 +00:00
|
|
|
do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' );
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' }')
|
2009-03-04 21:35:17 +00:00
|
|
|
postamble()
|
|
|
|
|
|
|
|
|
|
|
|
def quadstrip(intype, outtype):
|
|
|
|
preamble(intype, outtype, prim='quadstrip')
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' for (i = start, j = 0; j < out_nr; j+=8, i+=2) { ')
|
2009-03-04 21:35:17 +00:00
|
|
|
do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' );
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' }')
|
2009-03-04 21:35:17 +00:00
|
|
|
postamble()
|
|
|
|
|
|
|
|
|
2016-05-25 18:58:29 +01:00
|
|
|
def trisadj(intype, outtype):
|
|
|
|
preamble(intype, outtype, prim='trisadj')
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=6) { ')
|
2016-05-25 18:58:29 +01:00
|
|
|
do_tri( intype, outtype, 'out+j', 'i', 'i+2', 'i+4' );
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' }')
|
2016-05-25 18:58:29 +01:00
|
|
|
postamble()
|
|
|
|
|
|
|
|
|
|
|
|
def tristripadj(intype, outtype):
|
|
|
|
preamble(intype, outtype, prim='tristripadj')
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { ')
|
2016-05-25 18:58:29 +01:00
|
|
|
do_tri( intype, outtype, 'out+j', 'i', 'i+2', 'i+4' );
|
2018-07-05 14:17:32 +01:00
|
|
|
print(' }')
|
2016-05-25 18:58:29 +01:00
|
|
|
postamble()
|
|
|
|
|
|
|
|
|
2009-03-04 21:35:17 +00:00
|
|
|
def emit_funcs():
|
|
|
|
for intype in INTYPES:
|
|
|
|
for outtype in OUTTYPES:
|
|
|
|
tris(intype, outtype)
|
|
|
|
tristrip(intype, outtype)
|
|
|
|
trifan(intype, outtype)
|
|
|
|
quads(intype, outtype)
|
|
|
|
quadstrip(intype, outtype)
|
|
|
|
polygon(intype, outtype)
|
2016-05-25 18:58:29 +01:00
|
|
|
trisadj(intype, outtype)
|
|
|
|
tristripadj(intype, outtype)
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
def init(intype, outtype, prim):
|
|
|
|
if intype == GENERATE:
|
2018-07-05 14:17:32 +01:00
|
|
|
print(('generate_line[' +
|
2009-03-04 21:35:17 +00:00
|
|
|
outtype_idx[outtype] +
|
|
|
|
'][' + longprim[prim] +
|
2018-07-05 14:17:32 +01:00
|
|
|
'] = ' + name( intype, outtype, prim ) + ';'))
|
2009-03-04 21:35:17 +00:00
|
|
|
else:
|
2018-07-05 14:17:32 +01:00
|
|
|
print(('translate_line[' +
|
2009-03-04 21:35:17 +00:00
|
|
|
intype_idx[intype] +
|
|
|
|
'][' + outtype_idx[outtype] +
|
|
|
|
'][' + longprim[prim] +
|
2018-07-05 14:17:32 +01:00
|
|
|
'] = ' + name( intype, outtype, prim ) + ';'))
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
def emit_all_inits():
|
|
|
|
for intype in INTYPES:
|
|
|
|
for outtype in OUTTYPES:
|
|
|
|
for prim in PRIMS:
|
|
|
|
init(intype, outtype, prim)
|
|
|
|
|
|
|
|
def emit_init():
|
2018-07-05 14:17:32 +01:00
|
|
|
print('void u_unfilled_init( void )')
|
|
|
|
print('{')
|
|
|
|
print(' static int firsttime = 1;')
|
|
|
|
print(' if (!firsttime) return;')
|
|
|
|
print(' firsttime = 0;')
|
2009-03-04 21:35:17 +00:00
|
|
|
emit_all_inits()
|
2018-07-05 14:17:32 +01:00
|
|
|
print('}')
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def epilog():
|
2018-07-05 14:17:32 +01:00
|
|
|
print('#include "indices/u_unfilled_indices.c"')
|
2009-03-04 21:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
prolog()
|
|
|
|
emit_funcs()
|
|
|
|
emit_init()
|
|
|
|
epilog()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|