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