From fdc68a7b5840c34f17760da7da27e6103bca6d0b Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 3 Dec 2010 20:53:39 +1000 Subject: [PATCH] r300g: try and use all of vertex constant space. We can set the constant space to use a different area per-call to the shader, we can avoid flushing the PVS as often as we do by spreading out the constants across the whole constant space. Signed-off-by: Dave Airlie --- src/gallium/drivers/r300/r300_context.h | 5 +++++ src/gallium/drivers/r300/r300_emit.c | 17 ++++++++++------- src/gallium/drivers/r300/r300_reg.h | 3 ++- src/gallium/drivers/r300/r300_state.c | 20 +++++++++++++++----- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 93c20a0..050167b 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -258,6 +258,8 @@ struct r300_constant_buffer { uint32_t *ptr; /* Remapping table. */ unsigned *remap_table; + /* const buffer base */ + uint32_t buffer_base; }; /* Query object. @@ -606,6 +608,9 @@ struct r300_context { /* Stat counter. */ uint64_t flush_counter; + + /* const tracking for VS */ + int vs_const_base; }; /* Convenience cast wrappers. */ diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 31c7b38..1c215b1 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -947,12 +947,10 @@ void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state) * R300_VAP_PVS_CONST_CNTL * R300_VAP_PVS_CODE_CNTL_1 * See the r5xx docs for instructions on how to use these. */ - OUT_CS_REG_SEQ(R300_VAP_PVS_CODE_CNTL_0, 3); - OUT_CS(R300_PVS_FIRST_INST(0) | - R300_PVS_XYZW_VALID_INST(instruction_count - 1) | - R300_PVS_LAST_INST(instruction_count - 1)); - OUT_CS(R300_PVS_MAX_CONST_ADDR(code->constants.Count - 1)); - OUT_CS(instruction_count - 1); + OUT_CS_REG(R300_VAP_PVS_CODE_CNTL_0, R300_PVS_FIRST_INST(0) | + R300_PVS_XYZW_VALID_INST(instruction_count - 1) | + R300_PVS_LAST_INST(instruction_count - 1)); + OUT_CS_REG(R300_VAP_PVS_CODE_CNTL_1, instruction_count - 1); OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG, 0); OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, code->length); @@ -1002,15 +1000,20 @@ void r300_emit_vs_constants(struct r300_context* r300, ((struct r300_vertex_shader*)r300->vs_state.state)->externals_count; struct r300_constant_buffer *buf = (struct r300_constant_buffer*)state; unsigned i; + unsigned max_const; CS_LOCALS(r300); if (!count) return; + max_const = (size - 5) / 4; BEGIN_CS(size); + OUT_CS_REG(R300_VAP_PVS_CONST_CNTL, + R300_PVS_CONST_BASE_OFFSET(buf->buffer_base) | + R300_PVS_MAX_CONST_ADDR(max_const - 1)); OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG, (r300->screen->caps.is_r500 ? - R500_PVS_CONST_START : R300_PVS_CONST_START)); + R500_PVS_CONST_START : R300_PVS_CONST_START) + buf->buffer_base); OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, count * 4); if (buf->remap_table){ for (i = 0; i < count; i++) { diff --git a/src/gallium/drivers/r300/r300_reg.h b/src/gallium/drivers/r300/r300_reg.h index 788c513..613186e 100644 --- a/src/gallium/drivers/r300/r300_reg.h +++ b/src/gallium/drivers/r300/r300_reg.h @@ -427,7 +427,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. # define R300_PVS_CONST_START 512 # define R500_PVS_CONST_START 1024 # define R300_MAX_PVS_CONST_VECS 256 -# define R500_MAX_PVS_CONST_VECS 1024 +# define R500_MAX_PVS_CONST_VECS 256 # define R300_PVS_UCP_START 1024 # define R500_PVS_UCP_START 1536 # define R300_POINT_VPORT_SCALE_OFFSET 1030 @@ -553,6 +553,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. /* Addresses are relative to the vertex program parameters area. */ #define R300_VAP_PVS_CONST_CNTL 0x22D4 # define R300_PVS_CONST_BASE_OFFSET_SHIFT 0 +# define R300_PVS_CONST_BASE_OFFSET(x) (x) # define R300_PVS_MAX_CONST_ADDR_SHIFT 16 # define R300_PVS_MAX_CONST_ADDR(x) ((x) << 16) #define R300_VAP_PVS_CODE_CNTL_1 0x22D8 diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 092c032..acb6aa4 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1770,7 +1770,7 @@ static void r300_bind_vs_state(struct pipe_context* pipe, void* shader) if (vs->externals_count) { r300->vs_constants.dirty = TRUE; - r300->vs_constants.size = vs->externals_count * 4 + 3; + r300->vs_constants.size = vs->externals_count * 4 + 5; } else { r300->vs_constants.size = 0; } @@ -1836,10 +1836,20 @@ static void r300_set_constant_buffer(struct pipe_context *pipe, if (shader == PIPE_SHADER_VERTEX) { if (r300->screen->caps.has_tcl) { - if (r300->vs_constants.size) { - r300->vs_constants.dirty = TRUE; - } - r300->pvs_flush.dirty = TRUE; + boolean need_flush = FALSE; + int const_base = r300->vs_const_base; + int max_const = (r300->vs_constants.size - 5) / 4; + r300->vs_const_base += max_const; + if (r300->vs_const_base > R500_MAX_PVS_CONST_VECS) { + r300->vs_const_base = max_const; + const_base = 0; + need_flush = TRUE; + } + cbuf->buffer_base = const_base; + r300->vs_constants.dirty = TRUE; + if (need_flush) { + r300->pvs_flush.dirty = TRUE; + } } else if (r300->draw) { draw_set_mapped_constant_buffer(r300->draw, PIPE_SHADER_VERTEX, 0, mapped, buf->width0); -- 1.7.2.3