brw_draw.c File Reference

Include dependency graph for brw_draw.c:

Go to the source code of this file.

Functions

static void brw_set_prim (struct brw_context *brw, int prim)
static unsigned trim (int prim, unsigned length)
static boolean brw_emit_prim (struct brw_context *brw, boolean indexed, unsigned start, unsigned count)
static boolean brw_try_draw_elements (struct pipe_context *pipe, struct pipe_buffer *index_buffer, unsigned index_size, unsigned mode, unsigned start, unsigned count)
static boolean brw_draw_elements (struct pipe_context *pipe, struct pipe_buffer *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count)
static boolean brw_draw_arrays (struct pipe_context *pipe, unsigned mode, unsigned start, unsigned count)
void brw_init_draw_functions (struct brw_context *brw)

Variables

static unsigned hw_prim [PIPE_PRIM_POLYGON+1]
static const int reduced_prim [PIPE_PRIM_POLYGON+1]


Function Documentation

static boolean brw_draw_arrays ( struct pipe_context pipe,
unsigned  mode,
unsigned  start,
unsigned  count 
) [static]

Definition at line 214 of file brw_draw.c.

References assert, brw_try_draw_elements(), FALSE, and TRUE.

00218 {
00219    if (!brw_try_draw_elements( pipe, NULL, 0, mode, start, count )) {
00220       /* flush ? */
00221 
00222       if (!brw_try_draw_elements( pipe, NULL, 0, mode, start, count )) {
00223          assert(0);
00224          return FALSE;
00225       }
00226    }
00227    
00228    return TRUE;
00229 }

static boolean brw_draw_elements ( struct pipe_context pipe,
struct pipe_buffer indexBuffer,
unsigned  indexSize,
unsigned  mode,
unsigned  start,
unsigned  count 
) [static]

Definition at line 185 of file brw_draw.c.

References assert, brw_try_draw_elements(), FALSE, and TRUE.

00191 {
00192    if (!brw_try_draw_elements( pipe,
00193                                indexBuffer,
00194                                indexSize,
00195                                mode, start, count ))
00196    {
00197       /* flush ? */
00198 
00199       if (!brw_try_draw_elements( pipe,
00200                                   indexBuffer,
00201                                   indexSize,
00202                                   mode, start,
00203                                   count )) {
00204          assert(0);
00205          return FALSE;
00206       }
00207    }
00208 
00209    return TRUE;
00210 }

static boolean brw_emit_prim ( struct brw_context brw,
boolean  indexed,
unsigned  start,
unsigned  count 
) [static]

Definition at line 111 of file brw_draw.c.

References brw_3d_primitive::base_vert_location, brw_batchbuffer_data(), BRW_DEBUG, CMD_3D_PRIM, DEBUG_PRIMS, brw_3d_primitive::header, hw_prim, brw_3d_primitive::indexed, brw_3d_primitive::instance_count, brw_3d_primitive::length, brw_3d_primitive::opcode, brw_3d_primitive::pad, brw_context::primitive, PRINT, brw_3d_primitive::start_instance_location, brw_3d_primitive::start_vert_location, brw_3d_primitive::topology, trim(), TRUE, brw_3d_primitive::verts_per_instance, and brw_context::winsys.

00116 {
00117    struct brw_3d_primitive prim_packet;
00118 
00119    if (BRW_DEBUG & DEBUG_PRIMS)
00120       PRINT("PRIM: %d %d %d\n",  brw->primitive, start, count);
00121 
00122    prim_packet.header.opcode = CMD_3D_PRIM;
00123    prim_packet.header.length = sizeof(prim_packet)/4 - 2;
00124    prim_packet.header.pad = 0;
00125    prim_packet.header.topology = hw_prim[brw->primitive];
00126    prim_packet.header.indexed = indexed;
00127 
00128    prim_packet.verts_per_instance = trim(brw->primitive, count);
00129    prim_packet.start_vert_location = start;
00130    prim_packet.instance_count = 1;
00131    prim_packet.start_instance_location = 0;
00132    prim_packet.base_vert_location = 0;
00133 
00134    if (prim_packet.verts_per_instance == 0)
00135       return TRUE;
00136 
00137    return brw_batchbuffer_data( brw->winsys,
00138                                 &prim_packet,
00139                                 sizeof(prim_packet) );
00140 }

void brw_init_draw_functions ( struct brw_context brw  ) 

Definition at line 233 of file brw_draw.c.

References brw_draw_arrays(), brw_draw_elements(), pipe_context::draw_arrays, pipe_context::draw_elements, and brw_context::pipe.

00234 {
00235    brw->pipe.draw_arrays = brw_draw_arrays;
00236    brw->pipe.draw_elements = brw_draw_elements;
00237 }

static void brw_set_prim ( struct brw_context brw,
int  prim 
) [static]

Definition at line 72 of file brw_draw.c.

References brw_context::attribs, brw_state_flags::brw, BRW_NEW_PRIMITIVE, BRW_NEW_REDUCED_PRIMITIVE, brw_validate_state(), brw_context::dirty, pipe_rasterizer_state::fill_ccw, pipe_rasterizer_state::fill_cw, pipe_rasterizer_state::flatshade, PIPE_POLYGON_MODE_FILL, PIPE_PRIM_QUAD_STRIP, PIPE_PRIM_TRIANGLE_STRIP, brw_context::primitive, PRINT, brw_context::Raster, reduced_prim, brw_context::reduced_primitive, and brw_context::state.

00073 {
00074    PRINT("PRIM: %d\n", prim);
00075 
00076    /* Slight optimization to avoid the GS program when not needed:
00077     */
00078    if (prim == PIPE_PRIM_QUAD_STRIP &&
00079        brw->attribs.Raster->flatshade &&
00080        brw->attribs.Raster->fill_cw == PIPE_POLYGON_MODE_FILL &&
00081        brw->attribs.Raster->fill_ccw == PIPE_POLYGON_MODE_FILL)
00082       prim = PIPE_PRIM_TRIANGLE_STRIP;
00083 
00084    if (prim != brw->primitive) {
00085       brw->primitive = prim;
00086       brw->state.dirty.brw |= BRW_NEW_PRIMITIVE;
00087 
00088       if (reduced_prim[prim] != brw->reduced_primitive) {
00089          brw->reduced_primitive = reduced_prim[prim];
00090          brw->state.dirty.brw |= BRW_NEW_REDUCED_PRIMITIVE;
00091       }
00092 
00093       brw_validate_state(brw);
00094    }
00095 
00096 }

static boolean brw_try_draw_elements ( struct pipe_context pipe,
struct pipe_buffer index_buffer,
unsigned  index_size,
unsigned  mode,
unsigned  start,
unsigned  count 
) [static]

Definition at line 146 of file brw_draw.c.

References brw_state_flags::brw, brw_context(), brw_emit_prim(), brw_set_prim(), brw_upload_indices(), brw_upload_vertex_buffers(), brw_upload_vertex_elements(), brw_validate_state(), brw_context::dirty, FALSE, brw_context::state, and TRUE.

00152 {
00153    struct brw_context *brw = brw_context(pipe);
00154 
00155    /* Set the first primitive ahead of validate_state:
00156     */
00157    brw_set_prim(brw, mode);
00158 
00159    /* Upload index, vertex data:
00160     */
00161    if (index_buffer &&
00162        !brw_upload_indices( brw, index_buffer, index_size, start, count ))
00163       return FALSE;
00164 
00165    if (!brw_upload_vertex_buffers(brw))
00166       return FALSE;
00167 
00168    if (!brw_upload_vertex_elements( brw ))
00169       return FALSE;
00170 
00171    /* XXX:  Need to separate validate and upload of state.
00172     */
00173    if (brw->state.dirty.brw)
00174       brw_validate_state( brw );
00175 
00176    if (!brw_emit_prim(brw, index_buffer != NULL,
00177                       start, count))
00178       return FALSE;
00179 
00180    return TRUE;
00181 }

static unsigned trim ( int  prim,
unsigned  length 
) [static]

Definition at line 99 of file brw_draw.c.

References PIPE_PRIM_QUAD_STRIP, and PIPE_PRIM_QUADS.

00100 {
00101    if (prim == PIPE_PRIM_QUAD_STRIP)
00102       return length > 3 ? (length - length % 2) : 0;
00103    else if (prim == PIPE_PRIM_QUADS)
00104       return length - length % 4;
00105    else
00106       return length;
00107 }


Variable Documentation

unsigned hw_prim[PIPE_PRIM_POLYGON+1] [static]

Initial value:

 {
    0x01 ,
    0x02 ,
    0x10 ,
    0x03 ,
    0x04 ,
    0x05 ,
    0x06 ,
    0x07 ,
    0x08 ,
    0x0E 
}

Definition at line 39 of file brw_draw.c.

const int reduced_prim[PIPE_PRIM_POLYGON+1] [static]

Initial value:

 {
   PIPE_PRIM_POINTS,
   PIPE_PRIM_LINES,
   PIPE_PRIM_LINES,
   PIPE_PRIM_LINES,
   PIPE_PRIM_TRIANGLES,
   PIPE_PRIM_TRIANGLES,
   PIPE_PRIM_TRIANGLES,
   PIPE_PRIM_TRIANGLES,
   PIPE_PRIM_TRIANGLES,
   PIPE_PRIM_TRIANGLES
}

Definition at line 53 of file brw_draw.c.


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