From 928eb2f57ff358ee2bdb6ffbf352fe7b9e4a09d1 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 18 Nov 2010 20:31:31 +1000 Subject: [PATCH] gallium/r300g: add new set constant interface don't think this will work. --- src/gallium/drivers/r300/r300_state.c | 43 ++++++++++++++++++++ src/gallium/include/pipe/p_context.h | 4 ++ src/mesa/state_tracker/st_atom_constbuf.c | 62 +++++++++++++++++----------- src/mesa/state_tracker/st_context.h | 3 + src/mesa/state_tracker/st_draw_feedback.c | 33 ++++++++++------ 5 files changed, 109 insertions(+), 36 deletions(-) diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index bd08bf2..7020ab0 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1783,6 +1783,48 @@ static void r300_delete_vs_state(struct pipe_context* pipe, void* shader) FREE(shader); } +static void r300_set_constants(struct pipe_context *pipe, + uint shader, uint index, + uint num_consts, float *consts[4]) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_constant_buffer *cbuf; + switch (shader) { + case PIPE_SHADER_VERTEX: + cbuf = (struct r300_constant_buffer*)r300->vs_constants.state; + break; + case PIPE_SHADER_FRAGMENT: + cbuf = (struct r300_constant_buffer*)r300->fs_constants.state; + break; + default: + assert(0); + return; + } + if (num_consts == 0 || consts == NULL) { + cbuf->ptr = NULL; + cbuf->remap_table = NULL; + } + + if (shader == PIPE_SHADER_FRAGMENT || + (shader == PIPE_SHADER_VERTEX && r300->screen->caps.has_tcl)) { + cbuf->ptr = consts; + } + + 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; + } else if (r300->draw) { + draw_set_mapped_constant_buffer(r300->draw, PIPE_SHADER_VERTEX, + 0, consts, num_consts * sizeof(float) * 4); + } + } else if (shader == PIPE_SHADER_FRAGMENT) { + r300->fs_constants.dirty = TRUE; + } +} + static void r300_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, struct pipe_resource *buf) @@ -1840,6 +1882,7 @@ void r300_init_state_functions(struct r300_context* r300) r300->context.set_clip_state = r300_set_clip_state; r300->context.set_sample_mask = r300_set_sample_mask; + r300->context.set_constants = r300_set_constants; r300->context.set_constant_buffer = r300_set_constant_buffer; r300->context.create_depth_stencil_alpha_state = r300_create_dsa_state; diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index 0e53aef..4a37f86 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -201,6 +201,10 @@ struct pipe_context { uint shader, uint index, struct pipe_resource *buf ); + void (*set_constants)( struct pipe_context *, + uint shader, uint index, + uint num_consts, float *consts[4]); + void (*set_framebuffer_state)( struct pipe_context *, const struct pipe_framebuffer_state * ); diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index 8d1dc79..b248fd5 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -64,37 +64,51 @@ void st_upload_constants( struct st_context *st, /* update constants */ if (params && params->NumParameters) { - const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4; _mesa_load_state_parameters(st->ctx, params); - /* We always need to get a new buffer, to keep the drivers simple and - * avoid gratuitous rendering synchronization. - */ - pipe_resource_reference(cbuf, NULL ); - *cbuf = pipe_buffer_create(pipe->screen, - PIPE_BIND_CONSTANT_BUFFER, - paramBytes ); - - if (ST_DEBUG & DEBUG_CONSTANTS) { - debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n", - __FUNCTION__, shader_type, params->NumParameters, - params->StateFlags); - _mesa_print_parameter_list(params); + if (st->pipe->set_constants) { + st->pipe->set_constants(st->pipe, shader_type, 0, params->NumParameters, + (float **)params->ParameterValues); + st->state.num_consts = params->NumParameters; + st->state.f_constants = params->ParameterValues; + } else { + const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4; + + st->state.use_const_buf = TRUE; + /* We always need to get a new buffer, to keep the drivers simple and + * avoid gratuitous rendering synchronization. + */ + pipe_resource_reference(cbuf, NULL ); + *cbuf = pipe_buffer_create(pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, + paramBytes ); + + if (ST_DEBUG & DEBUG_CONSTANTS) { + debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n", + __FUNCTION__, shader_type, params->NumParameters, + params->StateFlags); + _mesa_print_parameter_list(params); + } + /* load Mesa constants into the constant buffer */ + pipe_buffer_write(st->pipe, *cbuf, + 0, paramBytes, + params->ParameterValues); + + st->pipe->set_constant_buffer(st->pipe, shader_type, 0, *cbuf); } - - /* load Mesa constants into the constant buffer */ - pipe_buffer_write(st->pipe, *cbuf, - 0, paramBytes, - params->ParameterValues); - - st->pipe->set_constant_buffer(st->pipe, shader_type, 0, *cbuf); } - else if (*cbuf) { + else { st->constants.tracked_state[shader_type].dirty.mesa = 0x0; - pipe_resource_reference(cbuf, NULL); - st->pipe->set_constant_buffer(st->pipe, shader_type, 0, NULL); + if (st->pipe->set_constants) { + st->pipe->set_constants(st->pipe, shader_type, 0, 0, NULL); + st->state.num_consts = 0; + st->state.f_constants = NULL; + } else if (*cbuf) { + pipe_resource_reference(cbuf, NULL); + st->pipe->set_constant_buffer(st->pipe, shader_type, 0, NULL); + } } } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index d342c0c..a7d58a0 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -104,6 +104,9 @@ struct st_context GLuint num_textures; GLuint poly_stipple[32]; /**< In OpenGL's bottom-to-top order */ + GLfloat **f_constants; + GLuint num_consts; + GLboolean use_const_buf; } state; struct { diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c index 7f392fc..13b91e0 100644 --- a/src/mesa/state_tracker/st_draw_feedback.c +++ b/src/mesa/state_tracker/st_draw_feedback.c @@ -109,11 +109,11 @@ st_feedback_draw_vbo(struct gl_context *ctx, struct pipe_index_buffer ibuffer; struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS]; struct pipe_transfer *ib_transfer = NULL; - struct pipe_transfer *cb_transfer; + struct pipe_transfer *cb_transfer = NULL; GLuint attr, i; ubyte *mapped_constants; const void *mapped_indices = NULL; - + int const_width; assert(draw); st_validate_state(st); @@ -242,14 +242,21 @@ st_feedback_draw_vbo(struct gl_context *ctx, draw_set_mapped_index_buffer(draw, mapped_indices); } - /* map constant buffers */ - mapped_constants = pipe_buffer_map(pipe, - st->state.constants[PIPE_SHADER_VERTEX], - PIPE_TRANSFER_READ, - &cb_transfer); + if (st->state.use_const_buf) { + /* map constant buffers */ + mapped_constants = pipe_buffer_map(pipe, + st->state.constants[PIPE_SHADER_VERTEX], + PIPE_TRANSFER_READ, + &cb_transfer); + const_width = st->state.constants[PIPE_SHADER_VERTEX]->width0; + } else { + mapped_constants = (void *)st->state.f_constants; + const_width = st->state.num_consts * sizeof(GLfloat) * 4; + } + draw_set_mapped_constant_buffer(st->draw, PIPE_SHADER_VERTEX, 0, - mapped_constants, - st->state.constants[PIPE_SHADER_VERTEX]->width0); + mapped_constants, const_width); + /* draw here */ @@ -258,9 +265,11 @@ st_feedback_draw_vbo(struct gl_context *ctx, } - /* unmap constant buffers */ - pipe_buffer_unmap(pipe, st->state.constants[PIPE_SHADER_VERTEX], - cb_transfer); + if (st->state.use_const_buf) { + /* unmap constant buffers */ + pipe_buffer_unmap(pipe, st->state.constants[PIPE_SHADER_VERTEX], + cb_transfer); + } /* * unmap vertex/index buffers -- 1.7.2.3