brw_gs_emit.c

Go to the documentation of this file.
00001 /*
00002  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
00003  Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
00004  develop this 3D driver.
00005  
00006  Permission is hereby granted, free of charge, to any person obtaining
00007  a copy of this software and associated documentation files (the
00008  "Software"), to deal in the Software without restriction, including
00009  without limitation the rights to use, copy, modify, merge, publish,
00010  distribute, sublicense, and/or sell copies of the Software, and to
00011  permit persons to whom the Software is furnished to do so, subject to
00012  the following conditions:
00013  
00014  The above copyright notice and this permission notice (including the
00015  next paragraph) shall be included in all copies or substantial
00016  portions of the Software.
00017  
00018  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00021  IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
00022  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00023  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00024  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  
00026  **********************************************************************/
00027  /*
00028   * Authors:
00029   *   Keith Whitwell <keith@tungstengraphics.com>
00030   */
00031 
00032 #include "brw_defines.h"
00033 #include "brw_context.h"
00034 #include "brw_eu.h"
00035 #include "brw_util.h"
00036 #include "brw_gs.h"
00037 
00038 static void brw_gs_alloc_regs( struct brw_gs_compile *c,
00039                                unsigned nr_verts )
00040 {
00041    unsigned i = 0,j;
00042 
00043    /* Register usage is static, precompute here:
00044     */
00045    c->reg.R0 = retype(brw_vec8_grf(i, 0), BRW_REGISTER_TYPE_UD); i++;
00046 
00047    /* Payload vertices plus space for more generated vertices:
00048     */
00049    for (j = 0; j < nr_verts; j++) {
00050       c->reg.vertex[j] = brw_vec4_grf(i, 0);
00051       i += c->nr_regs;
00052    }
00053 
00054    c->prog_data.urb_read_length = c->nr_regs; 
00055    c->prog_data.total_grf = i;
00056 }
00057 
00058 
00059 static void brw_gs_emit_vue(struct brw_gs_compile *c, 
00060                             struct brw_reg vert,
00061                             boolean last,
00062                             unsigned header)
00063 {
00064    struct brw_compile *p = &c->func;
00065    boolean allocate = !last;
00066 
00067    /* Overwrite PrimType and PrimStart in the message header, for
00068     * each vertex in turn:
00069     */
00070    brw_MOV(p, get_element_ud(c->reg.R0, 2), brw_imm_ud(header));
00071 
00072    /* Copy the vertex from vertn into m1..mN+1:
00073     */
00074    brw_copy8(p, brw_message_reg(1), vert, c->nr_regs);
00075 
00076    /* Send each vertex as a seperate write to the urb.  This is
00077     * different to the concept in brw_sf_emit.c, where subsequent
00078     * writes are used to build up a single urb entry.  Each of these
00079     * writes instantiates a seperate urb entry, and a new one must be
00080     * allocated each time.
00081     */
00082    brw_urb_WRITE(p, 
00083                  allocate ? c->reg.R0 : retype(brw_null_reg(), BRW_REGISTER_TYPE_UD),
00084                  0,
00085                  c->reg.R0,
00086                  allocate,
00087                  1,             /* used */
00088                  c->nr_regs + 1, /* msg length */
00089                  allocate ? 1 : 0, /* response length */
00090                  allocate ? 0 : 1, /* eot */
00091                  1,             /* writes_complete */
00092                  0,             /* urb offset */
00093                  BRW_URB_SWIZZLE_NONE);
00094 }
00095 
00096 
00097 
00098 void brw_gs_quads( struct brw_gs_compile *c )
00099 {
00100    brw_gs_alloc_regs(c, 4);
00101    
00102    /* Use polygons for correct edgeflag behaviour. Note that vertex 3
00103     * is the PV for quads, but vertex 0 for polygons:
00104     */
00105    brw_gs_emit_vue(c, c->reg.vertex[3], 0, ((_3DPRIM_POLYGON << 2) | R02_PRIM_START));
00106    brw_gs_emit_vue(c, c->reg.vertex[0], 0, (_3DPRIM_POLYGON << 2));
00107    brw_gs_emit_vue(c, c->reg.vertex[1], 0, (_3DPRIM_POLYGON << 2)); 
00108    brw_gs_emit_vue(c, c->reg.vertex[2], 1, ((_3DPRIM_POLYGON << 2) | R02_PRIM_END));
00109 }
00110 
00111 void brw_gs_quad_strip( struct brw_gs_compile *c )
00112 {
00113    brw_gs_alloc_regs(c, 4);
00114    
00115    brw_gs_emit_vue(c, c->reg.vertex[2], 0, ((_3DPRIM_POLYGON << 2) | R02_PRIM_START));
00116    brw_gs_emit_vue(c, c->reg.vertex[3], 0, (_3DPRIM_POLYGON << 2));
00117    brw_gs_emit_vue(c, c->reg.vertex[0], 0, (_3DPRIM_POLYGON << 2)); 
00118    brw_gs_emit_vue(c, c->reg.vertex[1], 1, ((_3DPRIM_POLYGON << 2) | R02_PRIM_END));
00119 }
00120 
00121 void brw_gs_tris( struct brw_gs_compile *c )
00122 {
00123    brw_gs_alloc_regs(c, 3);
00124    brw_gs_emit_vue(c, c->reg.vertex[0], 0, ((_3DPRIM_TRILIST << 2) | R02_PRIM_START));
00125    brw_gs_emit_vue(c, c->reg.vertex[1], 0, (_3DPRIM_TRILIST << 2));
00126    brw_gs_emit_vue(c, c->reg.vertex[2], 1, ((_3DPRIM_TRILIST << 2) | R02_PRIM_END));
00127 }
00128 
00129 void brw_gs_lines( struct brw_gs_compile *c )
00130 {
00131    brw_gs_alloc_regs(c, 2);
00132    brw_gs_emit_vue(c, c->reg.vertex[0], 0, ((_3DPRIM_LINESTRIP << 2) | R02_PRIM_START));
00133    brw_gs_emit_vue(c, c->reg.vertex[1], 1, ((_3DPRIM_LINESTRIP << 2) | R02_PRIM_END));
00134 }
00135 
00136 void brw_gs_points( struct brw_gs_compile *c )
00137 {
00138    brw_gs_alloc_regs(c, 1);
00139    brw_gs_emit_vue(c, c->reg.vertex[0], 1, ((_3DPRIM_POINTLIST << 2) | R02_PRIM_START | R02_PRIM_END));
00140 }
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 

Generated on Tue Sep 29 06:25:16 2009 for Gallium3D by  doxygen 1.5.4