r600g: put constant buffer state into an array indexed by shader type

to easily and robustly handle multiple shader stages

Reviewed-by: Jerome Glisse <jglisse@redhat.com>
This commit is contained in:
Marek Olšák 2012-09-10 00:56:45 +02:00
parent 3bffd8a5eb
commit 1bce17ee01
6 changed files with 32 additions and 39 deletions

View file

@ -2057,14 +2057,14 @@ static void evergreen_emit_constant_buffers(struct r600_context *rctx,
static void evergreen_emit_vs_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
{
evergreen_emit_constant_buffers(rctx, &rctx->vs_constbuf_state, 176,
evergreen_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX], 176,
R_028180_ALU_CONST_BUFFER_SIZE_VS_0,
R_028980_ALU_CONST_CACHE_VS_0);
}
static void evergreen_emit_ps_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
{
evergreen_emit_constant_buffers(rctx, &rctx->ps_constbuf_state, 0,
evergreen_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT], 0,
R_028140_ALU_CONST_BUFFER_SIZE_PS_0,
R_028940_ALU_CONST_CACHE_PS_0);
}
@ -2179,8 +2179,8 @@ void evergreen_init_state_functions(struct r600_context *rctx)
*/
/* shader const */
r600_init_atom(rctx, &rctx->vs_constbuf_state.atom, id++, evergreen_emit_vs_constant_buffers, 0);
r600_init_atom(rctx, &rctx->ps_constbuf_state.atom, id++, evergreen_emit_ps_constant_buffers, 0);
r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX].atom, id++, evergreen_emit_vs_constant_buffers, 0);
r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT].atom, id++, evergreen_emit_ps_constant_buffers, 0);
/* shader program */
r600_init_atom(rctx, &rctx->cs_shader_state.atom, id++, evergreen_emit_cs_shader, 0);
/* sampler */

View file

@ -65,21 +65,25 @@ static struct pipe_transfer *r600_get_transfer(struct pipe_context *ctx,
}
static void r600_set_constants_dirty_if_bound(struct r600_context *rctx,
struct r600_constbuf_state *state,
struct r600_resource *rbuffer)
{
bool found = false;
uint32_t mask = state->enabled_mask;
unsigned shader;
while (mask) {
unsigned i = u_bit_scan(&mask);
if (state->cb[i].buffer == &rbuffer->b.b) {
found = true;
state->dirty_mask |= 1 << i;
for (shader = 0; shader < PIPE_SHADER_TYPES; shader++) {
struct r600_constbuf_state *state = &rctx->constbuf_state[shader];
bool found = false;
uint32_t mask = state->enabled_mask;
while (mask) {
unsigned i = u_bit_scan(&mask);
if (state->cb[i].buffer == &rbuffer->b.b) {
found = true;
state->dirty_mask |= 1 << i;
}
}
if (found) {
r600_constant_buffers_dirty(rctx, state);
}
}
if (found) {
r600_constant_buffers_dirty(rctx, state);
}
}
@ -126,8 +130,7 @@ static void *r600_buffer_transfer_map(struct pipe_context *pipe,
}
}
/* Constant buffers. */
r600_set_constants_dirty_if_bound(rctx, &rctx->vs_constbuf_state, rbuffer);
r600_set_constants_dirty_if_bound(rctx, &rctx->ps_constbuf_state, rbuffer);
r600_set_constants_dirty_if_bound(rctx, rbuffer);
}
}
#if 0 /* this is broken (see Bug 53130) */

View file

@ -989,6 +989,7 @@ void r600_context_flush(struct r600_context *ctx, unsigned flags)
bool timer_queries_suspended = false;
bool nontimer_queries_suspended = false;
bool streamout_suspended = false;
unsigned shader;
if (cs->cdw == ctx->start_cs_cmd.atom.num_dw)
return;
@ -1053,10 +1054,11 @@ void r600_context_flush(struct r600_context *ctx, unsigned flags)
ctx->vertex_buffer_state.dirty_mask = ctx->vertex_buffer_state.enabled_mask;
r600_vertex_buffers_dirty(ctx);
ctx->vs_constbuf_state.dirty_mask = ctx->vs_constbuf_state.enabled_mask;
ctx->ps_constbuf_state.dirty_mask = ctx->ps_constbuf_state.enabled_mask;
r600_constant_buffers_dirty(ctx, &ctx->vs_constbuf_state);
r600_constant_buffers_dirty(ctx, &ctx->ps_constbuf_state);
for (shader = 0; shader < PIPE_SHADER_TYPES; shader++) {
struct r600_constbuf_state *state = &ctx->constbuf_state[shader];
state->dirty_mask = state->enabled_mask;
r600_constant_buffers_dirty(ctx, state);
}
ctx->vs_samplers.views.dirty_mask = ctx->vs_samplers.views.enabled_mask;
ctx->ps_samplers.views.dirty_mask = ctx->ps_samplers.views.enabled_mask;

View file

@ -372,8 +372,7 @@ struct r600_context {
struct r600_vertexbuf_state vertex_buffer_state;
/** Vertex buffers for compute shaders */
struct r600_vertexbuf_state cs_vertex_buffer_state;
struct r600_constbuf_state vs_constbuf_state;
struct r600_constbuf_state ps_constbuf_state;
struct r600_constbuf_state constbuf_state[PIPE_SHADER_TYPES];
struct r600_textures_info vs_samplers;
struct r600_textures_info ps_samplers;
struct r600_seamless_cube_map seamless_cube_map;

View file

@ -1909,14 +1909,14 @@ static void r600_emit_constant_buffers(struct r600_context *rctx,
static void r600_emit_vs_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
{
r600_emit_constant_buffers(rctx, &rctx->vs_constbuf_state, 160,
r600_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX], 160,
R_028180_ALU_CONST_BUFFER_SIZE_VS_0,
R_028980_ALU_CONST_CACHE_VS_0);
}
static void r600_emit_ps_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
{
r600_emit_constant_buffers(rctx, &rctx->ps_constbuf_state, 0,
r600_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT], 0,
R_028140_ALU_CONST_BUFFER_SIZE_PS_0,
R_028940_ALU_CONST_CACHE_PS_0);
}
@ -2054,8 +2054,8 @@ void r600_init_state_functions(struct r600_context *rctx)
*/
/* shader const */
r600_init_atom(rctx, &rctx->vs_constbuf_state.atom, id++, r600_emit_vs_constant_buffers, 0);
r600_init_atom(rctx, &rctx->ps_constbuf_state.atom, id++, r600_emit_ps_constant_buffers, 0);
r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX].atom, id++, r600_emit_vs_constant_buffers, 0);
r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT].atom, id++, r600_emit_ps_constant_buffers, 0);
/* sampler must be emited before TA_CNTL_AUX otherwise DISABLE_CUBE_WRAP change
* does not take effect (TA_CNTL_AUX emited by r600_emit_seamless_cube_map)

View file

@ -864,21 +864,10 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
struct pipe_constant_buffer *input)
{
struct r600_context *rctx = (struct r600_context *)ctx;
struct r600_constbuf_state *state;
struct r600_constbuf_state *state = &rctx->constbuf_state[shader];
struct pipe_constant_buffer *cb;
const uint8_t *ptr;
switch (shader) {
case PIPE_SHADER_VERTEX:
state = &rctx->vs_constbuf_state;
break;
case PIPE_SHADER_FRAGMENT:
state = &rctx->ps_constbuf_state;
break;
default:
return;
}
/* Note that the state tracker can unbind constant buffers by
* passing NULL here.
*/