diff options
author | Marek Olšák <[email protected]> | 2013-07-15 02:42:44 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2013-07-15 23:45:16 +0200 |
commit | 22427640b248aeb9875b40b216d27bedb13a1db8 (patch) | |
tree | 4f252a192c1885752e55616886e2727f0f1f514e | |
parent | c889df3fbed64be8669d21e3d3c5d6db913255da (diff) |
r300g/swtcl: fix geometry corruption by uploading indices to a buffer
The splitting of a draw call into several draw commands was broken, because
the split sometimes took place in the middle of a primitive. The splitting
was supposed to be dealing with the case when there are more indices than
the maximum size of a CS.
This commit throws that code away and uses a real index buffer instead.
https://bugs.freedesktop.org/show_bug.cgi?id=66558
Cc: [email protected]
-rw-r--r-- | src/gallium/drivers/r300/r300_context.c | 6 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_render.c | 63 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_screen_buffer.c | 7 |
3 files changed, 31 insertions, 45 deletions
diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 7647f9e2aa0..a808eb98d40 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -412,10 +412,8 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, r300->context.create_video_decoder = vl_create_decoder; r300->context.create_video_buffer = vl_video_buffer_create; - if (r300screen->caps.has_tcl) { - r300->uploader = u_upload_create(&r300->context, 256 * 1024, 4, - PIPE_BIND_INDEX_BUFFER); - } + r300->uploader = u_upload_create(&r300->context, 256 * 1024, 4, + PIPE_BIND_CUSTOM); r300->blitter = util_blitter_create(&r300->context); if (r300->blitter == NULL) diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 1e79970ed0d..5416c3a7495 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -1005,60 +1005,45 @@ static void r300_render_draw_elements(struct vbuf_render* render, { struct r300_render* r300render = r300_render(render); struct r300_context* r300 = r300render->r300; - struct radeon_winsys_cs *cs = r300->cs; - unsigned end_cs_dwords; unsigned max_index = (r300->vbo->size - r300->draw_vbo_offset) / (r300render->r300->vertex_info.size * 4) - 1; - unsigned short_count; - unsigned free_dwords; + struct pipe_resource *index_buffer = NULL; + unsigned index_buffer_offset; CS_LOCALS(r300); DBG(r300, DBG_DRAW, "r300: render_draw_elements (count: %d)\n", count); + u_upload_data(r300->uploader, 0, count * 2, indices, + &index_buffer_offset, &index_buffer); + if (!index_buffer) { + return; + } + if (!r300_prepare_for_rendering(r300, PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL | PREP_INDEXED, - NULL, 256, 0, 0, -1)) { + index_buffer, 12, 0, 0, -1)) { + pipe_resource_reference(&index_buffer, NULL); return; } - /* Below we manage the CS space manually because there may be more - * indices than it can fit in CS. */ - - end_cs_dwords = r300_get_num_cs_end_dwords(r300); - - while (count) { - free_dwords = - RADEON_MAX_CMDBUF_DWORDS - r300->cs->cdw - end_cs_dwords - 6; - - short_count = MIN2(count, free_dwords * 2); - - BEGIN_CS(6); - OUT_CS_REG(R300_GA_COLOR_CONTROL, - r300_provoking_vertex_fixes(r300, r300render->prim)); - OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, max_index); - OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (short_count+1)/2); - OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (short_count << 16) | - r300render->hwprim); - END_CS; - - memcpy(cs->buf+cs->cdw, indices, short_count * 2); - cs->cdw += (short_count + 1) / 2; + BEGIN_CS(12); + OUT_CS_REG(R300_GA_COLOR_CONTROL, + r300_provoking_vertex_fixes(r300, r300render->prim)); + OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, max_index); - /* OK now subtract the emitted indices and see if we need to emit - * another draw packet. */ - indices += short_count; - count -= short_count; + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0); + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | + r300render->hwprim); - if (count) { - if (!r300_prepare_for_rendering(r300, - PREP_EMIT_VARRAYS_SWTCL | PREP_INDEXED, - NULL, 256, 0, 0, -1)) - return; + OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2); + OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2)); + OUT_CS(index_buffer_offset); + OUT_CS((count + 1) / 2); + OUT_CS_RELOC(r300_resource(index_buffer)); + END_CS; - end_cs_dwords = r300_get_num_cs_end_dwords(r300); - } - } + pipe_resource_reference(&index_buffer, NULL); } static void r300_render_destroy(struct vbuf_render* render) diff --git a/src/gallium/drivers/r300/r300_screen_buffer.c b/src/gallium/drivers/r300/r300_screen_buffer.c index e2312d058ed..86e4478d637 100644 --- a/src/gallium/drivers/r300/r300_screen_buffer.c +++ b/src/gallium/drivers/r300/r300_screen_buffer.c @@ -172,9 +172,12 @@ struct pipe_resource *r300_buffer_create(struct pipe_screen *screen, rbuf->buf = NULL; rbuf->malloced_buffer = NULL; - /* Alloc constant buffers and SWTCL buffers in RAM. */ + /* Allocate constant buffers and SWTCL vertex and index buffers in RAM. + * Note that uploaded index buffers use the flag PIPE_BIND_CUSTOM, so that + * we can distinguish them from user-created buffers. + */ if (templ->bind & PIPE_BIND_CONSTANT_BUFFER || - !r300screen->caps.has_tcl) { + (!r300screen->caps.has_tcl && !(templ->bind & PIPE_BIND_CUSTOM))) { rbuf->malloced_buffer = align_malloc(templ->width0, 64); return &rbuf->b.b; } |