From 5354dc742899c498a97fe6f64cc5d9237beb1e9f Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 3 Jun 2013 15:25:48 +0800 Subject: [PATCH] ilo: use emit_SURFACE_STATE() for constant buffers Introduce ilo_cbuf_cso and initialize it in set_constant_buffer(). As ilo_view_surface is embedded in ilo_cbuf_cso, switch to emit_SURFACE_STATE() for constant buffers and remove emit_cbuf_SURFACE_STATE(). --- src/gallium/drivers/ilo/ilo_3d_pipeline.h | 1 - .../drivers/ilo/ilo_3d_pipeline_gen6.c | 10 +++---- .../drivers/ilo/ilo_3d_pipeline_gen7.c | 1 - src/gallium/drivers/ilo/ilo_gpe.h | 7 ++++- src/gallium/drivers/ilo/ilo_gpe_gen6.c | 20 ------------- src/gallium/drivers/ilo/ilo_gpe_gen6.h | 6 ---- src/gallium/drivers/ilo/ilo_gpe_gen7.c | 20 ------------- src/gallium/drivers/ilo/ilo_gpe_gen7.h | 2 -- src/gallium/drivers/ilo/ilo_state.c | 29 ++++++++++--------- 9 files changed, 26 insertions(+), 70 deletions(-) diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline.h b/src/gallium/drivers/ilo/ilo_3d_pipeline.h index 800a3396c72..132aa955d25 100644 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline.h +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline.h @@ -135,7 +135,6 @@ struct ilo_3d_pipeline { GEN6_EMIT(BINDING_TABLE_STATE); GEN6_EMIT(SURFACE_STATE); GEN6_EMIT(surf_SURFACE_STATE); - GEN6_EMIT(cbuf_SURFACE_STATE); GEN6_EMIT(so_SURFACE_STATE); GEN6_EMIT(SAMPLER_STATE); GEN6_EMIT(SAMPLER_BORDER_COLOR_STATE); diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c index 0ac9bcd6f9b..ac217f55086 100644 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c @@ -1001,8 +1001,7 @@ gen6_pipeline_state_surfaces_const(struct ilo_3d_pipeline *p, int shader_type, struct gen6_pipeline_session *session) { - const struct pipe_constant_buffer *buffers = - ilo->cbuf[shader_type].states; + const struct ilo_cbuf_cso *buffers = ilo->cbuf[shader_type].cso; const int num_buffers = ilo->cbuf[shader_type].count; uint32_t *surface_state; int offset, i; @@ -1041,9 +1040,11 @@ gen6_pipeline_state_surfaces_const(struct ilo_3d_pipeline *p, return; for (i = 0; i < num_buffers; i++) { - if (buffers[i].buffer) { + if (buffers[i].resource) { + const struct ilo_view_surface *surf = &buffers[i].surface; + surface_state[i] = - p->gen6_cbuf_SURFACE_STATE(p->dev, &buffers[i], p->cp); + p->gen6_SURFACE_STATE(p->dev, surf, false, p->cp); } else { surface_state[i] = 0; @@ -1642,7 +1643,6 @@ ilo_3d_pipeline_init_gen6(struct ilo_3d_pipeline *p) GEN6_USE(p, BINDING_TABLE_STATE, gen6); GEN6_USE(p, SURFACE_STATE, gen6); GEN6_USE(p, surf_SURFACE_STATE, gen6); - GEN6_USE(p, cbuf_SURFACE_STATE, gen6); GEN6_USE(p, so_SURFACE_STATE, gen6); GEN6_USE(p, SAMPLER_STATE, gen6); GEN6_USE(p, SAMPLER_BORDER_COLOR_STATE, gen6); diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c index 850475a3501..33f6ece0d60 100644 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c @@ -830,7 +830,6 @@ ilo_3d_pipeline_init_gen7(struct ilo_3d_pipeline *p) GEN6_USE(p, BINDING_TABLE_STATE, gen7); GEN6_USE(p, SURFACE_STATE, gen7); GEN6_USE(p, surf_SURFACE_STATE, gen7); - GEN6_USE(p, cbuf_SURFACE_STATE, gen7); GEN6_USE(p, SAMPLER_STATE, gen7); GEN6_USE(p, SAMPLER_BORDER_COLOR_STATE, gen7); GEN6_USE(p, push_constant_buffer, gen7); diff --git a/src/gallium/drivers/ilo/ilo_gpe.h b/src/gallium/drivers/ilo/ilo_gpe.h index 1b5a38f5d3c..9103b261c20 100644 --- a/src/gallium/drivers/ilo/ilo_gpe.h +++ b/src/gallium/drivers/ilo/ilo_gpe.h @@ -179,8 +179,13 @@ struct ilo_view_state { unsigned count; }; +struct ilo_cbuf_cso { + struct pipe_resource *resource; + struct ilo_view_surface surface; +}; + struct ilo_cbuf_state { - struct pipe_constant_buffer states[ILO_MAX_CONST_BUFFERS]; + struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS]; unsigned count; }; diff --git a/src/gallium/drivers/ilo/ilo_gpe_gen6.c b/src/gallium/drivers/ilo/ilo_gpe_gen6.c index 5eb797cef16..082cb38a4fc 100644 --- a/src/gallium/drivers/ilo/ilo_gpe_gen6.c +++ b/src/gallium/drivers/ilo/ilo_gpe_gen6.c @@ -4216,25 +4216,6 @@ gen6_emit_surf_SURFACE_STATE(const struct ilo_dev_info *dev, return gen6_emit_SURFACE_STATE(dev, &surf, true, cp); } -static uint32_t -gen6_emit_cbuf_SURFACE_STATE(const struct ilo_dev_info *dev, - const struct pipe_constant_buffer *cbuf, - struct ilo_cp *cp) -{ - const enum pipe_format elem_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - struct ilo_buffer *buf = ilo_buffer(cbuf->buffer); - struct ilo_view_surface surf; - - ILO_GPE_VALID_GEN(dev, 6, 6); - - ilo_gpe_init_view_surface_for_buffer_gen6(dev, buf, - cbuf->buffer_offset, cbuf->buffer_size, - util_format_get_blocksize(elem_format), elem_format, - false, false, &surf); - - return gen6_emit_SURFACE_STATE(dev, &surf, false, cp); -} - static uint32_t gen6_emit_so_SURFACE_STATE(const struct ilo_dev_info *dev, const struct pipe_stream_output_target *so, @@ -4962,7 +4943,6 @@ static const struct ilo_gpe_gen6 gen6_gpe = { GEN6_SET(BINDING_TABLE_STATE), GEN6_SET(SURFACE_STATE), GEN6_SET(surf_SURFACE_STATE), - GEN6_SET(cbuf_SURFACE_STATE), GEN6_SET(so_SURFACE_STATE), GEN6_SET(SAMPLER_STATE), GEN6_SET(SAMPLER_BORDER_COLOR_STATE), diff --git a/src/gallium/drivers/ilo/ilo_gpe_gen6.h b/src/gallium/drivers/ilo/ilo_gpe_gen6.h index 64893b55bf0..306f264e0bf 100644 --- a/src/gallium/drivers/ilo/ilo_gpe_gen6.h +++ b/src/gallium/drivers/ilo/ilo_gpe_gen6.h @@ -433,11 +433,6 @@ typedef uint32_t const struct pipe_surface *surface, struct ilo_cp *cp); -typedef uint32_t -(*ilo_gpe_gen6_cbuf_SURFACE_STATE)(const struct ilo_dev_info *dev, - const struct pipe_constant_buffer *cbuf, - struct ilo_cp *cp); - typedef uint32_t (*ilo_gpe_gen6_so_SURFACE_STATE)(const struct ilo_dev_info *dev, const struct pipe_stream_output_target *so, @@ -531,7 +526,6 @@ struct ilo_gpe_gen6 { GEN6_EMIT(BINDING_TABLE_STATE); GEN6_EMIT(SURFACE_STATE); GEN6_EMIT(surf_SURFACE_STATE); - GEN6_EMIT(cbuf_SURFACE_STATE); GEN6_EMIT(so_SURFACE_STATE); GEN6_EMIT(SAMPLER_STATE); GEN6_EMIT(SAMPLER_BORDER_COLOR_STATE); diff --git a/src/gallium/drivers/ilo/ilo_gpe_gen7.c b/src/gallium/drivers/ilo/ilo_gpe_gen7.c index 5dd75bc3171..3612166474d 100644 --- a/src/gallium/drivers/ilo/ilo_gpe_gen7.c +++ b/src/gallium/drivers/ilo/ilo_gpe_gen7.c @@ -1717,25 +1717,6 @@ gen7_emit_surf_SURFACE_STATE(const struct ilo_dev_info *dev, return gen7_emit_SURFACE_STATE(dev, &surf, true, cp); } -static uint32_t -gen7_emit_cbuf_SURFACE_STATE(const struct ilo_dev_info *dev, - const struct pipe_constant_buffer *cbuf, - struct ilo_cp *cp) -{ - const enum pipe_format elem_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - struct ilo_buffer *buf = ilo_buffer(cbuf->buffer); - struct ilo_view_surface surf; - - ILO_GPE_VALID_GEN(dev, 7, 7); - - ilo_gpe_init_view_surface_for_buffer_gen7(dev, buf, - cbuf->buffer_offset, cbuf->buffer_size, - util_format_get_blocksize(elem_format), elem_format, - false, false, &surf); - - return gen7_emit_SURFACE_STATE(dev, &surf, false, cp); -} - static int gen7_estimate_command_size(const struct ilo_dev_info *dev, enum ilo_gpe_gen7_command cmd, @@ -1962,7 +1943,6 @@ gen7_init(struct ilo_gpe_gen7 *gen7) GEN7_USE(gen7, BINDING_TABLE_STATE, gen6); GEN7_USE(gen7, SURFACE_STATE, gen6); GEN7_SET(gen7, surf_SURFACE_STATE); - GEN7_SET(gen7, cbuf_SURFACE_STATE); GEN7_USE(gen7, SAMPLER_STATE, gen6); GEN7_USE(gen7, SAMPLER_BORDER_COLOR_STATE, gen6); GEN7_USE(gen7, push_constant_buffer, gen6); diff --git a/src/gallium/drivers/ilo/ilo_gpe_gen7.h b/src/gallium/drivers/ilo/ilo_gpe_gen7.h index 552b2172247..e3f6adb685c 100644 --- a/src/gallium/drivers/ilo/ilo_gpe_gen7.h +++ b/src/gallium/drivers/ilo/ilo_gpe_gen7.h @@ -387,7 +387,6 @@ typedef ilo_gpe_gen6_SCISSOR_RECT ilo_gpe_gen7_SCISSOR_RECT; typedef ilo_gpe_gen6_BINDING_TABLE_STATE ilo_gpe_gen7_BINDING_TABLE_STATE; typedef ilo_gpe_gen6_SURFACE_STATE ilo_gpe_gen7_SURFACE_STATE; typedef ilo_gpe_gen6_surf_SURFACE_STATE ilo_gpe_gen7_surf_SURFACE_STATE; -typedef ilo_gpe_gen6_cbuf_SURFACE_STATE ilo_gpe_gen7_cbuf_SURFACE_STATE; typedef ilo_gpe_gen6_SAMPLER_STATE ilo_gpe_gen7_SAMPLER_STATE; typedef ilo_gpe_gen6_SAMPLER_BORDER_COLOR_STATE ilo_gpe_gen7_SAMPLER_BORDER_COLOR_STATE; typedef ilo_gpe_gen6_push_constant_buffer ilo_gpe_gen7_push_constant_buffer; @@ -485,7 +484,6 @@ struct ilo_gpe_gen7 { GEN7_EMIT(BINDING_TABLE_STATE); GEN7_EMIT(SURFACE_STATE); GEN7_EMIT(surf_SURFACE_STATE); - GEN7_EMIT(cbuf_SURFACE_STATE); GEN7_EMIT(SAMPLER_STATE); GEN7_EMIT(SAMPLER_BORDER_COLOR_STATE); GEN7_EMIT(push_constant_buffer); diff --git a/src/gallium/drivers/ilo/ilo_state.c b/src/gallium/drivers/ilo/ilo_state.c index a88d643a3bf..35e2e85e4e4 100644 --- a/src/gallium/drivers/ilo/ilo_state.c +++ b/src/gallium/drivers/ilo/ilo_state.c @@ -131,11 +131,11 @@ finalize_constant_buffers(struct ilo_context *ilo) return; for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) { - int last_cbuf = Elements(ilo->cbuf[sh].states) - 1; + int last_cbuf = Elements(ilo->cbuf[sh].cso) - 1; /* find the last cbuf */ while (last_cbuf >= 0 && - !ilo->cbuf[sh].states[last_cbuf].buffer) + !ilo->cbuf[sh].cso[last_cbuf].resource) last_cbuf--; ilo->cbuf[sh].count = last_cbuf + 1; @@ -519,25 +519,26 @@ ilo_set_constant_buffer(struct pipe_context *pipe, struct pipe_constant_buffer *buf) { struct ilo_context *ilo = ilo_context(pipe); - struct pipe_constant_buffer *cbuf; + struct ilo_cbuf_cso *cbuf; assert(shader < Elements(ilo->cbuf)); - assert(index < Elements(ilo->cbuf[shader].states)); + assert(index < Elements(ilo->cbuf[shader].cso)); - cbuf = &ilo->cbuf[shader].states[index]; - - pipe_resource_reference(&cbuf->buffer, NULL); + cbuf = &ilo->cbuf[shader].cso[index]; if (buf) { - pipe_resource_reference(&cbuf->buffer, buf->buffer); - cbuf->buffer_offset = buf->buffer_offset; - cbuf->buffer_size = buf->buffer_size; - cbuf->user_buffer = buf->user_buffer; + const enum pipe_format elem_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + pipe_resource_reference(&cbuf->resource, buf->buffer); + + ilo_gpe_init_view_surface_for_buffer(ilo->dev, ilo_buffer(buf->buffer), + buf->buffer_offset, buf->buffer_size, + util_format_get_blocksize(elem_format), elem_format, + false, false, &cbuf->surface); } else { - cbuf->buffer_offset = 0; - cbuf->buffer_size = 0; - cbuf->user_buffer = 0; + pipe_resource_reference(&cbuf->resource, NULL); + cbuf->surface.bo = NULL; } /* the correct value will be set in ilo_finalize_states() */ -- 2.30.2