From 489131199e48e413e7cadf75a13e421fe88c744c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 16 Sep 2010 02:04:37 +0200 Subject: [PATCH] r300g/swtcl: fix CS overrun https://bugs.freedesktop.org/show_bug.cgi?id=29901 --- src/gallium/drivers/r300/r300_context.h | 1 + src/gallium/drivers/r300/r300_render.c | 35 +++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 34fa8f2..d353e1d 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -464,6 +464,7 @@ struct r300_context { size_t draw_vbo_size; /* Whether the VBO must not be flushed. */ boolean draw_vbo_locked; + boolean draw_first_emitted; /* Accelerated blit support. */ struct blitter_context* blitter; diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 177850d..2f00c87 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -753,6 +753,7 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe, draw_set_mapped_index_buffer(r300->draw, indices); r300->draw_vbo_locked = TRUE; + r300->draw_first_emitted = FALSE; draw_vbo(r300->draw, info); draw_flush(r300->draw); r300->draw_vbo_locked = FALSE; @@ -907,10 +908,17 @@ static void r300_render_draw_arrays(struct vbuf_render* render, DBG(r300, DBG_DRAW, "r300: render_draw_arrays (count: %d)\n", count); - if (!r300_emit_states(r300, - PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL, - NULL, 0, 0)) - return; + if (r300->draw_first_emitted) { + if (!r300_prepare_for_rendering(r300, + PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL, + NULL, 6, 0, 0)) + return; + } else { + if (!r300_emit_states(r300, + PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL, + NULL, 0, 0)) + return; + } /* Uncomment to dump all VBOs rendered through this interface. * Slow and noisy! @@ -937,6 +945,8 @@ static void r300_render_draw_arrays(struct vbuf_render* render, OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | r300render->hwprim); END_CS; + + r300->draw_first_emitted = TRUE; } static void r300_render_draw_elements(struct vbuf_render* render, @@ -955,10 +965,17 @@ static void r300_render_draw_elements(struct vbuf_render* render, CS_LOCALS(r300); DBG(r300, DBG_DRAW, "r300: render_draw_elements (count: %d)\n", count); - if (!r300_emit_states(r300, - PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED, - NULL, 0, 0)) - return; + if (r300->draw_first_emitted) { + if (!r300_prepare_for_rendering(r300, + PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED, + NULL, 256, 0, 0)) + return; + } else { + if (!r300_emit_states(r300, + PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED, + NULL, 0, 0)) + return; + } /* Below we manage the CS space manually because there may be more * indices than it can fit in CS. */ @@ -999,6 +1016,8 @@ static void r300_render_draw_elements(struct vbuf_render* render, end_cs_dwords = r300_get_num_cs_end_dwords(r300); } } + + r300->draw_first_emitted = TRUE; } static void r300_render_destroy(struct vbuf_render* render) -- 1.7.0.4