From: Marek Olšák Date: Fri, 4 Jan 2013 17:00:46 +0000 (+0100) Subject: r300g/swtcl: simplify vertex uploading X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ad1d1a4d9e4cb06424d477ddabac5885fa0613af;p=mesa.git r300g/swtcl: simplify vertex uploading - skip the vertex buffer reallocation in flush and just use the unsynchronized flag to get new memory. - remove the cruft needed to get around the issues with the vertex buffer reallocation in flush - use pb_buffer instead of pipe_resource --- diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 878b52f764f..b7256682b55 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -62,7 +62,7 @@ static void r300_release_referenced_objects(struct r300_context *r300) /* Manually-created vertex buffers. */ pipe_resource_reference(&r300->dummy_vb.buffer, NULL); - pipe_resource_reference(&r300->vbo, NULL); + pb_reference(&r300->vbo, NULL); r300->context.delete_depth_stencil_alpha_state(&r300->context, r300->dsa_decompress_zmask); diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index a1ae86816fb..5f9c2493cec 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -463,13 +463,10 @@ struct r300_context { /* Draw module. Used mostly for SW TCL. */ struct draw_context* draw; /* Vertex buffer for SW TCL. */ - struct pipe_resource* vbo; + struct pb_buffer *vbo; + struct radeon_winsys_cs_handle *vbo_cs; /* Offset and size into the SW TCL VBO. */ size_t draw_vbo_offset; - 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; @@ -721,7 +718,6 @@ void r300_translate_index_buffer(struct r300_context *r300, void r300_plug_in_stencil_ref_fallback(struct r300_context *r300); /* r300_render.c */ -void r300_draw_flush_vbuf(struct r300_context *r300); void r500_emit_index_bias(struct r300_context *r300, int index_bias); void r300_blitter_draw_rectangle(struct blitter_context *blitter, int x1, int y1, int x2, int y2, diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 6ddb5066bb8..51c14b43e41 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -930,7 +930,10 @@ void r300_emit_vertex_arrays_swtcl(struct r300_context *r300, boolean indexed) (r300->vertex_info.size << 8)); OUT_CS(r300->draw_vbo_offset); OUT_CS(0); - OUT_CS_RELOC(r300_resource(r300->vbo)); + + assert(r300->vbo_cs); + cs_winsys->cs_write_reloc(cs_copy, r300->vbo_cs); + CS_USED_DW(2); END_CS; } @@ -1212,10 +1215,9 @@ validate: r300->rws->cs_add_reloc(r300->cs, r300->query_current->cs_buf, RADEON_USAGE_WRITE, RADEON_DOMAIN_GTT); /* ...vertex buffer for SWTCL path... */ - if (r300->vbo) - r300->rws->cs_add_reloc(r300->cs, r300_resource(r300->vbo)->cs_buf, - RADEON_USAGE_READ, - r300_resource(r300->vbo)->domain); + if (r300->vbo_cs) + r300->rws->cs_add_reloc(r300->cs, r300->vbo_cs, + RADEON_USAGE_READ, RADEON_DOMAIN_GTT); /* ...vertex buffers for HWTCL path... */ if (do_validate_vertex_buffers && r300->vertex_arrays_dirty) { struct pipe_vertex_buffer *vbuf = r300->vertex_buffer; diff --git a/src/gallium/drivers/r300/r300_flush.c b/src/gallium/drivers/r300/r300_flush.c index 6d51ee5d528..365dc8c3c11 100644 --- a/src/gallium/drivers/r300/r300_flush.c +++ b/src/gallium/drivers/r300/r300_flush.c @@ -70,9 +70,6 @@ void r300_flush(struct pipe_context *pipe, struct r300_context *r300 = r300_context(pipe); struct pb_buffer **rfence = (struct pb_buffer**)fence; - if (r300->draw && !r300->draw_vbo_locked) - r300_draw_flush_vbuf(r300); - if (r300->screen->info.drm_minor >= 12) { flags |= RADEON_FLUSH_KEEP_TILING_FLAGS; } diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 4a6a6c4d025..d79d2a06329 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -844,7 +844,6 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe, const struct pipe_draw_info *info) { struct r300_context* r300 = r300_context(pipe); - boolean indexed = info->indexed; if (r300->skip_rendering) { return; @@ -852,16 +851,8 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe, r300_update_derived_state(r300); - r300_reserve_cs_dwords(r300, - PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL | - (indexed ? PREP_INDEXED : 0), - indexed ? 256 : 6); - - r300->draw_vbo_locked = TRUE; - r300->draw_first_emitted = FALSE; draw_vbo(r300->draw, info); draw_flush(r300->draw); - r300->draw_vbo_locked = FALSE; } /* Object for rendering using Draw. */ @@ -879,9 +870,7 @@ struct r300_render { /* VBO */ size_t vbo_max_used; - void * vbo_ptr; - - struct pipe_transfer *vbo_transfer; + uint8_t *vbo_ptr; }; static INLINE struct r300_render* @@ -900,30 +889,36 @@ r300_render_get_vertex_info(struct vbuf_render* render) } static boolean r300_render_allocate_vertices(struct vbuf_render* render, - ushort vertex_size, - ushort count) + ushort vertex_size, + ushort count) { struct r300_render* r300render = r300_render(render); struct r300_context* r300 = r300render->r300; - struct pipe_screen* screen = r300->context.screen; + struct radeon_winsys *rws = r300->rws; size_t size = (size_t)vertex_size * (size_t)count; DBG(r300, DBG_DRAW, "r300: render_allocate_vertices (size: %d)\n", size); - if (size + r300->draw_vbo_offset > r300->draw_vbo_size) - { - pipe_resource_reference(&r300->vbo, NULL); - r300->vbo = pipe_buffer_create(screen, - PIPE_BIND_CUSTOM, - PIPE_USAGE_STREAM, - R300_MAX_DRAW_VBO_SIZE); + if (!r300->vbo || size + r300->draw_vbo_offset > r300->vbo->size) { + pb_reference(&r300->vbo, NULL); + r300->vbo_cs = NULL; + r300render->vbo_ptr = NULL; + + r300->vbo = rws->buffer_create(rws, + MAX2(R300_MAX_DRAW_VBO_SIZE, size), + R300_BUFFER_ALIGNMENT, TRUE, + RADEON_DOMAIN_GTT); + if (!r300->vbo) { + return FALSE; + } + r300->vbo_cs = rws->buffer_get_cs_handle(r300->vbo); r300->draw_vbo_offset = 0; - r300->draw_vbo_size = R300_MAX_DRAW_VBO_SIZE; + r300render->vbo_ptr = rws->buffer_map(r300->vbo_cs, r300->cs, + PIPE_TRANSFER_WRITE); } r300render->vertex_size = vertex_size; - - return (r300->vbo) ? TRUE : FALSE; + return TRUE; } static void* r300_render_map_vertices(struct vbuf_render* render) @@ -931,19 +926,10 @@ static void* r300_render_map_vertices(struct vbuf_render* render) struct r300_render* r300render = r300_render(render); struct r300_context* r300 = r300render->r300; - assert(!r300render->vbo_transfer); - DBG(r300, DBG_DRAW, "r300: render_map_vertices\n"); - r300render->vbo_ptr = pipe_buffer_map(&r300render->r300->context, - r300->vbo, - PIPE_TRANSFER_WRITE | - PIPE_TRANSFER_UNSYNCHRONIZED, - &r300render->vbo_transfer); - assert(r300render->vbo_ptr); - - return ((uint8_t*)r300render->vbo_ptr + r300->draw_vbo_offset); + return r300render->vbo_ptr + r300->draw_vbo_offset; } static void r300_render_unmap_vertices(struct vbuf_render* render, @@ -951,18 +937,12 @@ static void r300_render_unmap_vertices(struct vbuf_render* render, ushort max) { struct r300_render* r300render = r300_render(render); - struct pipe_context* context = &r300render->r300->context; struct r300_context* r300 = r300render->r300; - assert(r300render->vbo_transfer); - DBG(r300, DBG_DRAW, "r300: render_unmap_vertices\n"); r300render->vbo_max_used = MAX2(r300render->vbo_max_used, r300render->vertex_size * (max + 1)); - pipe_buffer_unmap(context, r300render->vbo_transfer); - - r300render->vbo_transfer = NULL; } static void r300_render_release_vertices(struct vbuf_render* render) @@ -1000,16 +980,10 @@ static void r300_render_draw_arrays(struct vbuf_render* render, DBG(r300, DBG_DRAW, "r300: render_draw_arrays (count: %d)\n", count); - if (r300->draw_first_emitted) { - if (!r300_prepare_for_rendering(r300, - PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL, - NULL, dwords, 0, 0, -1)) - return; - } else { - if (!r300_emit_states(r300, - PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL, - NULL, 0, 0, -1)) - return; + if (!r300_prepare_for_rendering(r300, + PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL, + NULL, dwords, 0, 0, -1)) { + return; } BEGIN_CS(dwords); @@ -1020,8 +994,6 @@ 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, @@ -1032,7 +1004,7 @@ static void r300_render_draw_elements(struct vbuf_render* render, struct r300_context* r300 = r300render->r300; int i; unsigned end_cs_dwords; - unsigned max_index = (r300->draw_vbo_size - r300->draw_vbo_offset) / + unsigned max_index = (r300->vbo->size - r300->draw_vbo_offset) / (r300render->r300->vertex_info.size * 4) - 1; unsigned short_count; unsigned free_dwords; @@ -1040,16 +1012,11 @@ 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->draw_first_emitted) { - if (!r300_prepare_for_rendering(r300, - PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL | PREP_INDEXED, - NULL, 256, 0, 0, -1)) - return; - } else { - if (!r300_emit_states(r300, - PREP_EMIT_STATES | PREP_EMIT_VARRAYS_SWTCL | PREP_INDEXED, - NULL, 0, 0, -1)) - return; + if (!r300_prepare_for_rendering(r300, + PREP_EMIT_STATES | + PREP_EMIT_VARRAYS_SWTCL | PREP_INDEXED, + NULL, 256, 0, 0, -1)) { + return; } /* Below we manage the CS space manually because there may be more @@ -1091,8 +1058,6 @@ 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) @@ -1106,7 +1071,7 @@ static struct vbuf_render* r300_render_create(struct r300_context* r300) r300render->r300 = r300; - r300render->base.max_vertex_buffer_bytes = 1024 * 1024; + r300render->base.max_vertex_buffer_bytes = R300_MAX_DRAW_VBO_SIZE; r300render->base.max_indices = 16 * 1024; r300render->base.get_vertex_info = r300_render_get_vertex_info; @@ -1145,12 +1110,6 @@ struct draw_stage* r300_draw_stage(struct r300_context* r300) return stage; } -void r300_draw_flush_vbuf(struct r300_context *r300) -{ - pipe_resource_reference(&r300->vbo, NULL); - r300->draw_vbo_size = 0; -} - /**************************************************************************** * End of SW TCL functions * ***************************************************************************/