From c89306983c07e5a88c0d636267e5ccf263cb4213 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 7 Aug 2014 20:07:25 -0700 Subject: [PATCH] i965: Calculate start/base_vertex_location after preparing vertices. Signed-off-by: Kenneth Graunke Reviewed-by: Ian Romanick --- src/mesa/drivers/dri/i965/brw_context.h | 8 ++++++++ src/mesa/drivers/dri/i965/brw_draw.c | 17 ++++++++--------- src/mesa/drivers/dri/i965/brw_draw.h | 2 ++ src/mesa/drivers/dri/i965/brw_draw_upload.c | 12 ++++++++++++ src/mesa/drivers/dri/i965/brw_state_upload.c | 6 +++--- src/mesa/drivers/dri/i965/gen8_draw_upload.c | 1 + 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index 3bc1ea5d696..25b3298235a 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -1061,6 +1061,14 @@ struct brw_context /* Whether the last depth/stencil packets were both NULL. */ bool no_depth_or_stencil; + struct { + /** Does the current draw use the index buffer? */ + bool indexed; + + int start_vertex_location; + int base_vertex_location; + } draw; + struct { struct brw_vertex_element inputs[VERT_ATTRIB_MAX]; struct brw_vertex_buffer buffers[VERT_ATTRIB_MAX]; diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c index 0fa7b6bdf3f..c2866d0dacc 100644 --- a/src/mesa/drivers/dri/i965/brw_draw.c +++ b/src/mesa/drivers/dri/i965/brw_draw.c @@ -176,26 +176,19 @@ static void brw_emit_prim(struct brw_context *brw, { int verts_per_instance; int vertex_access_type; - int start_vertex_location; - int base_vertex_location; int indirect_flag; DBG("PRIM: %s %d %d\n", _mesa_lookup_enum_by_nr(prim->mode), prim->start, prim->count); - start_vertex_location = prim->start; - base_vertex_location = prim->basevertex; if (prim->indexed) { vertex_access_type = brw->gen >= 7 ? GEN7_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM : GEN4_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM; - start_vertex_location += brw->ib.start_vertex_offset; - base_vertex_location += brw->vb.start_vertex_bias; } else { vertex_access_type = brw->gen >= 7 ? GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL : GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL; - start_vertex_location += brw->vb.start_vertex_bias; } /* We only need to trim the primitive count on pre-Gen6. */ @@ -270,10 +263,10 @@ static void brw_emit_prim(struct brw_context *brw, vertex_access_type); } OUT_BATCH(verts_per_instance); - OUT_BATCH(start_vertex_location); + OUT_BATCH(brw->draw.start_vertex_location); OUT_BATCH(prim->num_instances); OUT_BATCH(prim->base_instance); - OUT_BATCH(base_vertex_location); + OUT_BATCH(brw->draw.base_vertex_location); ADVANCE_BATCH(); /* Only used on Sandybridge; harmless to set elsewhere. */ @@ -436,12 +429,18 @@ static bool brw_try_draw_prims( struct gl_context *ctx, brw_merge_inputs(brw, arrays); } } + + brw->draw.indexed = prims[i].indexed; + brw->draw.start_vertex_location = prims[i].start; + brw->draw.base_vertex_location = prims[i].basevertex; + if (brw->gen < 6) brw_set_prim(brw, &prims[i]); else gen6_set_prim(brw, &prims[i]); retry: + /* Note that before the loop, brw->state.dirty.brw was set to != 0, and * that the state updated in the loop outside of this block is that in * *_set_prim or intel_batchbuffer_flush(), which only impacts diff --git a/src/mesa/drivers/dri/i965/brw_draw.h b/src/mesa/drivers/dri/i965/brw_draw.h index 774f1d4684a..fc83dcdd0bb 100644 --- a/src/mesa/drivers/dri/i965/brw_draw.h +++ b/src/mesa/drivers/dri/i965/brw_draw.h @@ -47,6 +47,8 @@ void brw_draw_prims( struct gl_context *ctx, void brw_draw_init( struct brw_context *brw ); void brw_draw_destroy( struct brw_context *brw ); +void brw_prepare_shader_draw_parameters(struct brw_context *); + /* brw_primitive_restart.c */ GLboolean brw_handle_primitive_restart(struct gl_context *ctx, diff --git a/src/mesa/drivers/dri/i965/brw_draw_upload.c b/src/mesa/drivers/dri/i965/brw_draw_upload.c index 5d6b766ebc5..38b108751ce 100644 --- a/src/mesa/drivers/dri/i965/brw_draw_upload.c +++ b/src/mesa/drivers/dri/i965/brw_draw_upload.c @@ -604,12 +604,24 @@ brw_prepare_vertices(struct brw_context *brw) brw->vb.nr_buffers = j; } +void +brw_prepare_shader_draw_parameters(struct brw_context *brw) +{ + if (brw->draw.indexed) { + brw->draw.start_vertex_location += brw->ib.start_vertex_offset; + brw->draw.base_vertex_location += brw->vb.start_vertex_bias; + } else { + brw->draw.start_vertex_location += brw->vb.start_vertex_bias; + } +} + static void brw_emit_vertices(struct brw_context *brw) { struct gl_context *ctx = &brw->ctx; GLuint i, nr_elements; brw_prepare_vertices(brw); + brw_prepare_shader_draw_parameters(brw); brw_emit_query_begin(brw); diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c b/src/mesa/drivers/dri/i965/brw_state_upload.c index 3a452c3a586..e9466212280 100644 --- a/src/mesa/drivers/dri/i965/brw_state_upload.c +++ b/src/mesa/drivers/dri/i965/brw_state_upload.c @@ -98,7 +98,7 @@ static const struct brw_tracked_state *gen4_atoms[] = &brw_psp_urb_cbs, &brw_drawing_rect, - &brw_indices, + &brw_indices, /* must come before brw_vertices */ &brw_index_buffer, &brw_vertices, @@ -169,7 +169,7 @@ static const struct brw_tracked_state *gen6_atoms[] = &brw_drawing_rect, - &brw_indices, + &brw_indices, /* must come before brw_vertices */ &brw_index_buffer, &brw_vertices, }; @@ -244,7 +244,7 @@ static const struct brw_tracked_state *gen7_atoms[] = &brw_drawing_rect, - &brw_indices, + &brw_indices, /* must come before brw_vertices */ &brw_index_buffer, &brw_vertices, diff --git a/src/mesa/drivers/dri/i965/gen8_draw_upload.c b/src/mesa/drivers/dri/i965/gen8_draw_upload.c index 4d627399ec4..8e4fe5d3bb0 100644 --- a/src/mesa/drivers/dri/i965/gen8_draw_upload.c +++ b/src/mesa/drivers/dri/i965/gen8_draw_upload.c @@ -41,6 +41,7 @@ gen8_emit_vertices(struct brw_context *brw) struct gl_context *ctx = &brw->ctx; brw_prepare_vertices(brw); + brw_prepare_shader_draw_parameters(brw); if (brw->vs.prog_data->uses_vertexid) { unsigned vue = brw->vb.nr_enabled; -- 2.30.2