ilo: use emit_SURFACE_STATE() for constant buffers
authorChia-I Wu <olvaffe@gmail.com>
Mon, 3 Jun 2013 07:25:48 +0000 (15:25 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Fri, 7 Jun 2013 03:13:16 +0000 (11:13 +0800)
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
src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c
src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c
src/gallium/drivers/ilo/ilo_gpe.h
src/gallium/drivers/ilo/ilo_gpe_gen6.c
src/gallium/drivers/ilo/ilo_gpe_gen6.h
src/gallium/drivers/ilo/ilo_gpe_gen7.c
src/gallium/drivers/ilo/ilo_gpe_gen7.h
src/gallium/drivers/ilo/ilo_state.c

index 800a3396c72d08ee640822479ca0a011ac085daa..132aa955d2598f828a7825d3afbfd0ff84340ad0 100644 (file)
@@ -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);
index 0ac9bcd6f9bbd260584bae752ab271eed6e44858..ac217f550860cad63d40a92796148849dc17b20d 100644 (file)
@@ -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);
index 850475a3501b20618d5a6cf6a1db04890e112cd7..33f6ece0d601a6a1e33cccb0a4074ca4956fbb24 100644 (file)
@@ -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);
index 1b5a38f5d3c8e88a80498c0f20f862865b0544b9..9103b261c2058ac5945f1df732f1b203dd737664 100644 (file)
@@ -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;
 };
 
index 5eb797cef16bcfc317096881788c08a550d8fe78..082cb38a4fc6da1ed76edf348a1d1410fd4766cd 100644 (file)
@@ -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),
index 64893b55bf052dc2e9f1a519e9d55f6a254384d5..306f264e0bf00ca8c62d42955892a711dd1603de 100644 (file)
@@ -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);
index 5dd75bc3171cb2caca07b76b82587a5ccbc0b179..3612166474df57f506b594a519596c3688f18aa2 100644 (file)
@@ -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);
index 552b217224708d3823db65c62835816f4eb56dbc..e3f6adb685c86f6cece182fee3d1387da2736569 100644 (file)
@@ -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);
index a88d643a3bf038163c5c2f6a7acee9edf946689f..35e2e85e4e460dbbe3eaa0c30f42634f2d6bfb98 100644 (file)
@@ -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() */