From 3eb557778376bcbbc6f25da88ffbaa269607254c Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Fri, 16 Jul 2010 12:53:40 +0200 Subject: r300g: do not make copies of constant buffers, emit them directly --- src/gallium/drivers/r300/r300_context.h | 4 ++-- src/gallium/drivers/r300/r300_emit.c | 16 ++++++++-------- src/gallium/drivers/r300/r300_screen_buffer.c | 21 +++++++++++++-------- src/gallium/drivers/r300/r300_screen_buffer.h | 1 + src/gallium/drivers/r300/r300_state.c | 20 +++----------------- src/gallium/winsys/radeon/drm/radeon_r300.c | 11 +---------- src/gallium/winsys/radeon/drm/radeon_winsys.h | 2 -- 7 files changed, 28 insertions(+), 47 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 55cec881490..d2b8aa10284 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -247,8 +247,8 @@ struct r300_ztop_state { struct r300_constant_buffer { /* Buffer of constants */ - uint32_t constants[256][4]; - /* Total number of constants */ + uint32_t *ptr; + /* Total number of vec4s */ unsigned count; }; diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 10d9e675ac0..349f3912d13 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -171,6 +171,7 @@ void r300_emit_fs_constants(struct r300_context* r300, unsigned size, void *stat struct r300_fragment_shader *fs = r300_fs(r300); struct r300_constant_buffer *buf = (struct r300_constant_buffer*)state; unsigned count = fs->shader->externals_count * 4; + unsigned i, j; CS_LOCALS(r300); if (count == 0) @@ -178,7 +179,9 @@ void r300_emit_fs_constants(struct r300_context* r300, unsigned size, void *stat BEGIN_CS(size); OUT_CS_REG_SEQ(R300_PFS_PARAM_0_X, count); - OUT_CS_TABLE(buf->constants, count); + for (i = 0; i < count; i++) + for (j = 0; j < 4; j++) + OUT_CS(pack_float24(buf->ptr[i*4+j])); END_CS; } @@ -190,7 +193,6 @@ void r300_emit_fs_rc_constant_state(struct r300_context* r300, unsigned size, vo unsigned count = fs->shader->rc_state_count; unsigned first = fs->shader->externals_count; unsigned end = constants->Count; - uint32_t cdata[4]; unsigned j; CS_LOCALS(r300); @@ -203,11 +205,9 @@ void r300_emit_fs_rc_constant_state(struct r300_context* r300, unsigned size, vo const float *data = get_rc_constant_state(r300, &constants->Constants[i]); - for (j = 0; j < 4; j++) - cdata[j] = pack_float24(data[j]); - OUT_CS_REG_SEQ(R300_PFS_PARAM_0_X + i * 16, 4); - OUT_CS_TABLE(cdata, 4); + for (j = 0; j < 4; j++) + OUT_CS(pack_float24(data[j])); } } END_CS; @@ -234,7 +234,7 @@ void r500_emit_fs_constants(struct r300_context* r300, unsigned size, void *stat BEGIN_CS(size); OUT_CS_REG(R500_GA_US_VECTOR_INDEX, R500_GA_US_VECTOR_INDEX_TYPE_CONST); OUT_CS_ONE_REG(R500_GA_US_VECTOR_DATA, count); - OUT_CS_TABLE(buf->constants, count); + OUT_CS_TABLE(buf->ptr, count); END_CS; } @@ -926,7 +926,7 @@ void r300_emit_vs_constants(struct r300_context* r300, (r300->screen->caps.is_r500 ? R500_PVS_CONST_START : R300_PVS_CONST_START)); OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, count * 4); - OUT_CS_TABLE(buf->constants, count * 4); + OUT_CS_TABLE(buf->ptr, count * 4); END_CS; } diff --git a/src/gallium/drivers/r300/r300_screen_buffer.c b/src/gallium/drivers/r300/r300_screen_buffer.c index 15d3f25c776..51d044af71e 100644 --- a/src/gallium/drivers/r300/r300_screen_buffer.c +++ b/src/gallium/drivers/r300/r300_screen_buffer.c @@ -136,6 +136,9 @@ static void r300_buffer_destroy(struct pipe_screen *screen, struct r300_screen *r300screen = r300_screen(screen); struct r300_buffer *rbuf = r300_buffer(buf); + if (rbuf->constant_buffer) + FREE(rbuf->constant_buffer); + r300_winsys_buffer_destroy(r300screen, rbuf); FREE(rbuf); } @@ -154,10 +157,8 @@ r300_buffer_transfer_map( struct pipe_context *pipe, if (rbuf->user_buffer) return (uint8_t *) rbuf->user_buffer + transfer->box.x; - - if (rbuf->b.b.bind & PIPE_BIND_CONSTANT_BUFFER) { - goto just_map; - } + if (rbuf->constant_buffer) + return (uint8_t *) rbuf->constant_buffer + transfer->box.x; /* check if the mapping is to a range we already flushed */ if (transfer->usage & PIPE_TRANSFER_DISCARD) { @@ -182,7 +183,6 @@ r300_buffer_transfer_map( struct pipe_context *pipe, } } -just_map: map = rws->buffer_map(rws, rbuf->buf, r300->cs, transfer->usage); if (map == NULL) @@ -208,9 +208,8 @@ static void r300_buffer_transfer_flush_region( struct pipe_context *pipe, if (rbuf->user_buffer) return; - - if (rbuf->b.b.bind & PIPE_BIND_CONSTANT_BUFFER) - return; + if (rbuf->constant_buffer) + return; /* mark the range as used */ for(i = 0; i < rbuf->num_ranges; ++i) { @@ -270,6 +269,12 @@ struct pipe_resource *r300_buffer_create(struct pipe_screen *screen, rbuf->b.b.screen = screen; rbuf->domain = R300_DOMAIN_GTT; + /* Alloc constant buffers in RAM. */ + if (templ->bind & PIPE_BIND_CONSTANT_BUFFER) { + rbuf->constant_buffer = MALLOC(templ->width0); + return &rbuf->b.b; + } + rbuf->buf = r300screen->rws->buffer_create(r300screen->rws, rbuf->b.b.width0, alignment, diff --git a/src/gallium/drivers/r300/r300_screen_buffer.h b/src/gallium/drivers/r300/r300_screen_buffer.h index 4f7c0ec87e5..fdd5d875d90 100644 --- a/src/gallium/drivers/r300/r300_screen_buffer.h +++ b/src/gallium/drivers/r300/r300_screen_buffer.h @@ -55,6 +55,7 @@ struct r300_buffer enum r300_buffer_domain domain; void *user_buffer; + void *constant_buffer; struct r300_buffer_range ranges[R300_BUFFER_MAX_RANGES]; unsigned num_ranges; }; diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 8214bcc2464..8d849cd2442 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1738,8 +1738,7 @@ static void r300_set_constant_buffer(struct pipe_context *pipe, { struct r300_context* r300 = r300_context(pipe); struct r300_constant_buffer *cbuf; - struct pipe_transfer *tr; - float *mapped; + uint32_t *mapped = r300_buffer(buf)->user_buffer; int max_size = 0, max_size_bytes = 0, clamped_size = 0; switch (shader) { @@ -1762,8 +1761,7 @@ static void r300_set_constant_buffer(struct pipe_context *pipe, max_size_bytes = max_size * 4 * sizeof(float); if (buf == NULL || buf->width0 == 0 || - (mapped = pipe_buffer_map(pipe, buf, PIPE_TRANSFER_READ, &tr)) == NULL) - { + (mapped = r300_buffer(buf)->constant_buffer) == NULL) { cbuf->count = 0; return; } @@ -1781,17 +1779,7 @@ static void r300_set_constant_buffer(struct pipe_context *pipe, clamped_size = MIN2(buf->width0, max_size_bytes); cbuf->count = clamped_size / (4 * sizeof(float)); - - if (shader == PIPE_SHADER_FRAGMENT && !r300->screen->caps.is_r500) { - unsigned i,j; - - /* Convert constants to float24. */ - for (i = 0; i < cbuf->count; i++) - for (j = 0; j < 4; j++) - cbuf->constants[i][j] = pack_float24(mapped[i*4+j]); - } else { - memcpy(cbuf->constants, mapped, clamped_size); - } + cbuf->ptr = mapped; } if (shader == PIPE_SHADER_VERTEX) { @@ -1807,8 +1795,6 @@ static void r300_set_constant_buffer(struct pipe_context *pipe, } else if (shader == PIPE_SHADER_FRAGMENT) { r300->fs_constants.dirty = TRUE; } - - pipe_buffer_unmap(pipe, buf, tr); } void r300_init_state_functions(struct r300_context* r300) diff --git a/src/gallium/winsys/radeon/drm/radeon_r300.c b/src/gallium/winsys/radeon/drm/radeon_r300.c index 4e89c070831..effa27f5c72 100644 --- a/src/gallium/winsys/radeon/drm/radeon_r300.c +++ b/src/gallium/winsys/radeon/drm/radeon_r300.c @@ -83,9 +83,7 @@ radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws, desc.usage = get_pb_usage_from_create_flags(bind, usage, domain); /* Assign a buffer manager. */ - if (bind & PIPE_BIND_CONSTANT_BUFFER) - provider = ws->mman; - else if (bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER)) + if (bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER)) provider = ws->cman; else provider = ws->kman; @@ -251,7 +249,6 @@ static void radeon_winsys_destroy(struct r300_winsys_screen *rws) ws->cman->destroy(ws->cman); ws->kman->destroy(ws->kman); - ws->mman->destroy(ws->mman); radeon_bo_manager_gem_dtor(ws->bom); radeon_cs_manager_gem_dtor(ws->csm); @@ -273,10 +270,6 @@ boolean radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* ws) if (!ws->cman) goto fail; - ws->mman = pb_malloc_bufmgr_create(); - if (!ws->mman) - goto fail; - ws->base.destroy = radeon_winsys_destroy; ws->base.get_value = radeon_get_value; @@ -312,8 +305,6 @@ fail: ws->cman->destroy(ws->cman); if (ws->kman) ws->kman->destroy(ws->kman); - if (ws->mman) - ws->mman->destroy(ws->mman); return FALSE; } diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h index 9a25e7679c9..533b7b2e2d2 100644 --- a/src/gallium/winsys/radeon/drm/radeon_winsys.h +++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h @@ -40,8 +40,6 @@ struct radeon_libdrm_winsys { struct pb_manager *cman; - struct pb_manager *mman; - /* PCI ID */ uint32_t pci_id; -- cgit v1.2.3