150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell/************************************************************************** 250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * 350beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. 450beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * All Rights Reserved. 550beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * 650beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 750beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * copy of this software and associated documentation files (the 850beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * "Software"), to deal in the Software without restriction, including 950beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 1050beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 1150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to 1250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * the following conditions: 1350beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * 1450beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * The above copyright notice and this permission notice (including the 1550beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * next paragraph) shall be included in all copies or substantial portions 1650beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * of the Software. 1750beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * 1850beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1950beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2050beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 2150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 2250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 2350beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2450beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2550beb86ce399534b049322f1074365ed03395ab2Keith Whitwell * 2650beb86ce399534b049322f1074365ed03395ab2Keith Whitwell **************************************************************************/ 2750beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 2850beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 2950beb86ce399534b049322f1074365ed03395ab2Keith Whitwell#ifndef U_BLIT_H 3050beb86ce399534b049322f1074365ed03395ab2Keith Whitwell#define U_BLIT_H 3150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 3250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 33e0da333d6b5027609579110b3df8d5ad2127307aJosé Fonseca#include "pipe/p_defines.h" 34e0da333d6b5027609579110b3df8d5ad2127307aJosé Fonseca#include "util/u_debug.h" 35e0da333d6b5027609579110b3df8d5ad2127307aJosé Fonseca 3650beb86ce399534b049322f1074365ed03395ab2Keith Whitwell#ifdef __cplusplus 3750beb86ce399534b049322f1074365ed03395ab2Keith Whitwellextern "C" { 3850beb86ce399534b049322f1074365ed03395ab2Keith Whitwell#endif 3950beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 4050beb86ce399534b049322f1074365ed03395ab2Keith Whitwellstatic INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr ) 4150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell{ 4250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell boolean ok = TRUE; 4350beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 4450beb86ce399534b049322f1074365ed03395ab2Keith Whitwell switch (pipe_prim) { 4550beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_POINTS: 4650beb86ce399534b049322f1074365ed03395ab2Keith Whitwell ok = (nr >= 1); 4750beb86ce399534b049322f1074365ed03395ab2Keith Whitwell break; 4850beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_LINES: 4950beb86ce399534b049322f1074365ed03395ab2Keith Whitwell ok = (nr >= 2); 5050beb86ce399534b049322f1074365ed03395ab2Keith Whitwell break; 5150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_LINE_STRIP: 5250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_LINE_LOOP: 5350beb86ce399534b049322f1074365ed03395ab2Keith Whitwell ok = (nr >= 2); 5450beb86ce399534b049322f1074365ed03395ab2Keith Whitwell break; 5550beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_TRIANGLES: 5650beb86ce399534b049322f1074365ed03395ab2Keith Whitwell ok = (nr >= 3); 5750beb86ce399534b049322f1074365ed03395ab2Keith Whitwell break; 5850beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_TRIANGLE_STRIP: 5950beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_TRIANGLE_FAN: 6050beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_POLYGON: 6150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell ok = (nr >= 3); 6250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell break; 6350beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_QUADS: 6450beb86ce399534b049322f1074365ed03395ab2Keith Whitwell ok = (nr >= 4); 6550beb86ce399534b049322f1074365ed03395ab2Keith Whitwell break; 6650beb86ce399534b049322f1074365ed03395ab2Keith Whitwell case PIPE_PRIM_QUAD_STRIP: 6750beb86ce399534b049322f1074365ed03395ab2Keith Whitwell ok = (nr >= 4); 6850beb86ce399534b049322f1074365ed03395ab2Keith Whitwell break; 6950beb86ce399534b049322f1074365ed03395ab2Keith Whitwell default: 7050beb86ce399534b049322f1074365ed03395ab2Keith Whitwell ok = 0; 7150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell break; 7250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell } 7350beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 7450beb86ce399534b049322f1074365ed03395ab2Keith Whitwell return ok; 7550beb86ce399534b049322f1074365ed03395ab2Keith Whitwell} 7650beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 7750beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 7850beb86ce399534b049322f1074365ed03395ab2Keith Whitwellstatic INLINE boolean u_trim_pipe_prim( unsigned pipe_prim, unsigned *nr ) 7950beb86ce399534b049322f1074365ed03395ab2Keith Whitwell{ 8050beb86ce399534b049322f1074365ed03395ab2Keith Whitwell boolean ok = TRUE; 816246c217ec1d00bf94a121508802eb7e49d5b61eJosé Fonseca const static unsigned values[][2] = { 82970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 1, 0 }, /* PIPE_PRIM_POINTS */ 83970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 2, 2 }, /* PIPE_PRIM_LINES */ 84970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 2, 0 }, /* PIPE_PRIM_LINE_LOOP */ 85970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 2, 0 }, /* PIPE_PRIM_LINE_STRIP */ 86970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 3, 3 }, /* PIPE_PRIM_TRIANGLES */ 87970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 3, 0 }, /* PIPE_PRIM_TRIANGLE_STRIP */ 88970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 3, 0 }, /* PIPE_PRIM_TRIANGLE_FAN */ 89970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 4, 4 }, /* PIPE_PRIM_TRIANGLE_QUADS */ 90970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 4, 2 }, /* PIPE_PRIM_TRIANGLE_QUAD_STRIP */ 91970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 3, 0 }, /* PIPE_PRIM_TRIANGLE_POLYGON */ 92970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 4, 4 }, /* PIPE_PRIM_LINES_ADJACENCY */ 93970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 4, 0 }, /* PIPE_PRIM_LINE_STRIP_ADJACENCY */ 94970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 6, 5 }, /* PIPE_PRIM_TRIANGLES_ADJACENCY */ 95970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie { 4, 0 }, /* PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY */ 96970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie }; 97970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie 98970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie if (unlikely(pipe_prim >= PIPE_PRIM_MAX)) { 99970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie *nr = 0; 100970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie return FALSE; 10150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell } 10250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 103970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie ok = (*nr >= values[pipe_prim][0]); 104970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie if (values[pipe_prim][1]) 105970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie *nr -= (*nr % values[pipe_prim][1]); 106970726dd6f9d5361cf7a4002d65ba24ac8baec20Dave Airlie 10750beb86ce399534b049322f1074365ed03395ab2Keith Whitwell if (!ok) 10850beb86ce399534b049322f1074365ed03395ab2Keith Whitwell *nr = 0; 10950beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 11050beb86ce399534b049322f1074365ed03395ab2Keith Whitwell return ok; 11150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell} 11250beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 11350beb86ce399534b049322f1074365ed03395ab2Keith Whitwell 114157d52143a2b541ca9552de2e3323261fc0238cbBrian Paulstatic INLINE unsigned u_reduced_prim( unsigned pipe_prim ) 115bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell{ 116bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell switch (pipe_prim) { 117bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell case PIPE_PRIM_POINTS: 118bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell return PIPE_PRIM_POINTS; 119bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell 120bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell case PIPE_PRIM_LINES: 121bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell case PIPE_PRIM_LINE_STRIP: 122bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell case PIPE_PRIM_LINE_LOOP: 123bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell return PIPE_PRIM_LINES; 124bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell 125bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell default: 126bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell return PIPE_PRIM_TRIANGLES; 127bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell } 128bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell} 129bc0e00ad42ee651701ef1e211d36ee92acf18d6fKeith Whitwell 130a00da63e6612607044e93f2900fba21bddfd0cadZack Rusinstatic INLINE unsigned 131a00da63e6612607044e93f2900fba21bddfd0cadZack Rusinu_vertices_per_prim(int primitive) 132a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin{ 133a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin switch(primitive) { 134a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_POINTS: 135a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin return 1; 136a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_LINES: 137a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_LINE_LOOP: 138a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_LINE_STRIP: 139a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin return 2; 140a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_TRIANGLES: 141a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_TRIANGLE_STRIP: 142a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_TRIANGLE_FAN: 143a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin return 3; 144a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_LINES_ADJACENCY: 145a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_LINE_STRIP_ADJACENCY: 146a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin return 4; 147a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_TRIANGLES_ADJACENCY: 148a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: 149a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin return 6; 150a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin 151a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin /* following primitives should never be used 152a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin * with geometry shaders abd their size is 153a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin * undefined */ 154a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_POLYGON: 155a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_QUADS: 156a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin case PIPE_PRIM_QUAD_STRIP: 157a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin default: 158a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin debug_printf("Unrecognized geometry shader primitive"); 159a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin return 3; 160a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin } 161a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin} 162a00da63e6612607044e93f2900fba21bddfd0cadZack Rusin 1634d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin/** 1644d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin * Returns the number of decomposed primitives for the given 1654d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin * vertex count. 1664d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin * Geometry shader is invoked once for each triangle in 1674d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin * triangle strip, triangle fans and triangles and once 1684d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin * for each line in line strip, line loop, lines. 1694d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin */ 1704d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusinstatic INLINE unsigned 1714d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusinu_gs_prims_for_vertices(int primitive, int vertices) 1724d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin{ 1734d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin switch(primitive) { 1744d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_POINTS: 1754d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices; 1764d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_LINES: 1774d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices / 2; 1784d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_LINE_LOOP: 1794d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices; 1804d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_LINE_STRIP: 1814d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices - 1; 1824d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_TRIANGLES: 1834d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices / 3; 1844d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_TRIANGLE_STRIP: 1854d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices - 2; 1864d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_TRIANGLE_FAN: 1874d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices - 2; 1884d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_LINES_ADJACENCY: 1894d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices / 2; 1904d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_LINE_STRIP_ADJACENCY: 1914d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices - 1; 1924d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_TRIANGLES_ADJACENCY: 1934d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices / 3; 1944d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: 1954d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return vertices - 2; 1964d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin 1974d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin /* following primitives should never be used 1984d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin * with geometry shaders abd their size is 1994d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin * undefined */ 2004d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_POLYGON: 2014d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_QUADS: 2024d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin case PIPE_PRIM_QUAD_STRIP: 2034d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin default: 2044d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin debug_printf("Unrecognized geometry shader primitive"); 2054d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin return 3; 2064d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin } 2074d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin} 2084d0baa73c9e1a40b4ac089c786af79dc7f1ff219Zack Rusin 2094dd2f6640b70e2313f8771f7588aa49a861153aaKeith Whitwellconst char *u_prim_name( unsigned pipe_prim ); 2104dd2f6640b70e2313f8771f7588aa49a861153aaKeith Whitwell 21150beb86ce399534b049322f1074365ed03395ab2Keith Whitwell#endif 212