ilo: add emit_SURFACE_STATE() for sampler views
authorChia-I Wu <olvaffe@gmail.com>
Thu, 6 Jun 2013 03:28:02 +0000 (11:28 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Fri, 7 Jun 2013 03:13:16 +0000 (11:13 +0800)
Introduce ilo_view_cso and initialize it in create_sampler_view().  Add
emit_SURFACE_STATE() to GPE, which can emit SURFACE_STATE from
ilo_view_surface.

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_shader.c
src/gallium/drivers/ilo/ilo_state.c

index 9aa39bfb17e3aaa0ec64509c4e073c0db1648a32..800a3396c72d08ee640822479ca0a011ac085daa 100644 (file)
@@ -133,8 +133,8 @@ struct ilo_3d_pipeline {
    GEN6_EMIT(DEPTH_STENCIL_STATE);
    GEN6_EMIT(SCISSOR_RECT);
    GEN6_EMIT(BINDING_TABLE_STATE);
+   GEN6_EMIT(SURFACE_STATE);
    GEN6_EMIT(surf_SURFACE_STATE);
-   GEN6_EMIT(view_SURFACE_STATE);
    GEN6_EMIT(cbuf_SURFACE_STATE);
    GEN6_EMIT(so_SURFACE_STATE);
    GEN6_EMIT(SAMPLER_STATE);
index 7b6181457b118eb18071b9d46ee6f6b28965f027..0ac9bcd6f9bbd260584bae752ab271eed6e44858 100644 (file)
@@ -937,7 +937,7 @@ gen6_pipeline_state_surfaces_view(struct ilo_3d_pipeline *p,
                                   int shader_type,
                                   struct gen6_pipeline_session *session)
 {
-   const struct pipe_sampler_view **views =
+   const struct pipe_sampler_view * const *views =
       (const struct pipe_sampler_view **) ilo->view[shader_type].states;
    const int num_views = ilo->view[shader_type].count;
    uint32_t *surface_state;
@@ -978,8 +978,11 @@ gen6_pipeline_state_surfaces_view(struct ilo_3d_pipeline *p,
 
    for (i = 0; i < num_views; i++) {
       if (views[i]) {
+         const struct ilo_view_cso *cso =
+            (const struct ilo_view_cso *) views[i];
+
          surface_state[i] =
-            p->gen6_view_SURFACE_STATE(p->dev, views[i], p->cp);
+            p->gen6_SURFACE_STATE(p->dev, &cso->surface, false, p->cp);
       }
       else {
          surface_state[i] = 0;
@@ -1120,7 +1123,7 @@ gen6_pipeline_state_samplers(struct ilo_3d_pipeline *p,
 {
    const struct ilo_sampler_cso * const *samplers =
       ilo->sampler[shader_type].cso;
-   const struct pipe_sampler_view **views =
+   const struct pipe_sampler_view * const *views =
       (const struct pipe_sampler_view **) ilo->view[shader_type].states;
    const int num_samplers = ilo->sampler[shader_type].count;
    const int num_views = ilo->view[shader_type].count;
@@ -1637,8 +1640,8 @@ ilo_3d_pipeline_init_gen6(struct ilo_3d_pipeline *p)
    GEN6_USE(p, DEPTH_STENCIL_STATE, gen6);
    GEN6_USE(p, SCISSOR_RECT, gen6);
    GEN6_USE(p, BINDING_TABLE_STATE, gen6);
+   GEN6_USE(p, SURFACE_STATE, gen6);
    GEN6_USE(p, surf_SURFACE_STATE, gen6);
-   GEN6_USE(p, view_SURFACE_STATE, gen6);
    GEN6_USE(p, cbuf_SURFACE_STATE, gen6);
    GEN6_USE(p, so_SURFACE_STATE, gen6);
    GEN6_USE(p, SAMPLER_STATE, gen6);
index 21932c877778404ed244cf6fb0893e58677efd43..850475a3501b20618d5a6cf6a1db04890e112cd7 100644 (file)
@@ -828,8 +828,8 @@ ilo_3d_pipeline_init_gen7(struct ilo_3d_pipeline *p)
    GEN6_USE(p, DEPTH_STENCIL_STATE, gen7);
    GEN6_USE(p, SCISSOR_RECT, gen7);
    GEN6_USE(p, BINDING_TABLE_STATE, gen7);
+   GEN6_USE(p, SURFACE_STATE, gen7);
    GEN6_USE(p, surf_SURFACE_STATE, gen7);
-   GEN6_USE(p, view_SURFACE_STATE, gen7);
    GEN6_USE(p, cbuf_SURFACE_STATE, gen7);
    GEN6_USE(p, SAMPLER_STATE, gen7);
    GEN6_USE(p, SAMPLER_BORDER_COLOR_STATE, gen7);
index ccb4ebc1f0e2f5f1966010bef4e9ea518eb32cf3..1b5a38f5d3c8e88a80498c0f20f862865b0544b9 100644 (file)
@@ -168,6 +168,12 @@ struct ilo_view_surface {
    struct intel_bo *bo;
 };
 
+struct ilo_view_cso {
+   struct pipe_sampler_view base;
+
+   struct ilo_view_surface surface;
+};
+
 struct ilo_view_state {
    struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
    unsigned count;
index f6d2fab27864fda25ea8fe53dfd8360ef531f8f5..5eb797cef16bcfc317096881788c08a550d8fe78 100644 (file)
@@ -4149,11 +4149,11 @@ gen6_emit_SURFACE_STATE(const struct ilo_dev_info *dev,
                         struct ilo_cp *cp)
 {
    const int state_align = 32 / 4;
-   const int state_len = 6;
+   const int state_len = (dev->gen >= ILO_GEN(7)) ? 8 : 6;
    uint32_t state_offset;
    uint32_t read_domains, write_domain;
 
-   ILO_GPE_VALID_GEN(dev, 6, 6);
+   ILO_GPE_VALID_GEN(dev, 6, 7);
 
    if (for_render) {
       read_domains = INTEL_DOMAIN_RENDER;
@@ -4166,6 +4166,8 @@ gen6_emit_SURFACE_STATE(const struct ilo_dev_info *dev,
 
    ilo_cp_steal(cp, "SURFACE_STATE", state_len, state_align, &state_offset);
 
+   STATIC_ASSERT(Elements(surf->payload) >= 8);
+
    ilo_cp_write(cp, surf->payload[0]);
    ilo_cp_write_bo(cp, surf->payload[1],
          surf->bo, read_domains, write_domain);
@@ -4174,6 +4176,11 @@ gen6_emit_SURFACE_STATE(const struct ilo_dev_info *dev,
    ilo_cp_write(cp, surf->payload[4]);
    ilo_cp_write(cp, surf->payload[5]);
 
+   if (dev->gen >= ILO_GEN(7)) {
+      ilo_cp_write(cp, surf->payload[6]);
+      ilo_cp_write(cp, surf->payload[7]);
+   }
+
    ilo_cp_end(cp);
 
    return state_offset;
@@ -4209,39 +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_view_SURFACE_STATE(const struct ilo_dev_info *dev,
-                             const struct pipe_sampler_view *view,
-                             struct ilo_cp *cp)
-{
-   struct ilo_view_surface surf;
-
-   ILO_GPE_VALID_GEN(dev, 6, 6);
-
-   if (view->texture->target == PIPE_BUFFER) {
-      const unsigned elem_size = util_format_get_blocksize(view->format);
-      const unsigned first_elem = view->u.buf.first_element;
-      const unsigned num_elems = view->u.buf.last_element - first_elem + 1;
-      struct ilo_buffer *buf = ilo_buffer(view->texture);
-
-      ilo_gpe_init_view_surface_for_buffer_gen6(dev, buf,
-            first_elem * elem_size, num_elems * elem_size,
-            elem_size, view->format, false, false, &surf);
-   }
-   else {
-      struct ilo_texture *tex = ilo_texture(view->texture);
-
-      ilo_gpe_init_view_surface_for_texture_gen6(dev, tex, view->format,
-            view->u.tex.first_level,
-            view->u.tex.last_level - view->u.tex.first_level + 1,
-            view->u.tex.first_layer,
-            view->u.tex.last_layer - view->u.tex.first_layer + 1,
-            false, false, &surf);
-   }
-
-   return gen6_emit_SURFACE_STATE(dev, &surf, false, cp);
-}
-
 static uint32_t
 gen6_emit_cbuf_SURFACE_STATE(const struct ilo_dev_info *dev,
                              const struct pipe_constant_buffer *cbuf,
@@ -4664,7 +4638,7 @@ ilo_gpe_init_sampler_cso(const struct ilo_dev_info *dev,
 static uint32_t
 gen6_emit_SAMPLER_STATE(const struct ilo_dev_info *dev,
                         const struct ilo_sampler_cso * const *samplers,
-                        const struct pipe_sampler_view * const *sampler_views,
+                        const struct pipe_sampler_view * const *views,
                         const uint32_t *sampler_border_colors,
                         int num_samplers,
                         struct ilo_cp *cp)
@@ -4691,7 +4665,7 @@ gen6_emit_SAMPLER_STATE(const struct ilo_dev_info *dev,
 
    for (i = 0; i < num_samplers; i++) {
       const struct ilo_sampler_cso *sampler = samplers[i];
-      const struct pipe_sampler_view *view = sampler_views[i];
+      const struct pipe_sampler_view *view = views[i];
       const uint32_t border_color = sampler_border_colors[i];
       uint32_t dw_filter, dw_wrap;
 
@@ -4986,8 +4960,8 @@ static const struct ilo_gpe_gen6 gen6_gpe = {
    GEN6_SET(DEPTH_STENCIL_STATE),
    GEN6_SET(SCISSOR_RECT),
    GEN6_SET(BINDING_TABLE_STATE),
+   GEN6_SET(SURFACE_STATE),
    GEN6_SET(surf_SURFACE_STATE),
-   GEN6_SET(view_SURFACE_STATE),
    GEN6_SET(cbuf_SURFACE_STATE),
    GEN6_SET(so_SURFACE_STATE),
    GEN6_SET(SAMPLER_STATE),
index a3489c8d8f7134fb9818fbf259b1aa5e6abf75a3..64893b55bf052dc2e9f1a519e9d55f6a254384d5 100644 (file)
@@ -423,13 +423,14 @@ typedef uint32_t
                                     struct ilo_cp *cp);
 
 typedef uint32_t
-(*ilo_gpe_gen6_surf_SURFACE_STATE)(const struct ilo_dev_info *dev,
-                                   const struct pipe_surface *surface,
-                                   struct ilo_cp *cp);
+(*ilo_gpe_gen6_SURFACE_STATE)(const struct ilo_dev_info *dev,
+                              const struct ilo_view_surface *surface,
+                              bool for_render,
+                              struct ilo_cp *cp);
 
 typedef uint32_t
-(*ilo_gpe_gen6_view_SURFACE_STATE)(const struct ilo_dev_info *dev,
-                                   const struct pipe_sampler_view *view,
+(*ilo_gpe_gen6_surf_SURFACE_STATE)(const struct ilo_dev_info *dev,
+                                   const struct pipe_surface *surface,
                                    struct ilo_cp *cp);
 
 typedef uint32_t
@@ -447,7 +448,7 @@ typedef uint32_t
 typedef uint32_t
 (*ilo_gpe_gen6_SAMPLER_STATE)(const struct ilo_dev_info *dev,
                               const struct ilo_sampler_cso * const *samplers,
-                              const struct pipe_sampler_view * const *sampler_views,
+                              const struct pipe_sampler_view * const *views,
                               const uint32_t *sampler_border_colors,
                               int num_samplers,
                               struct ilo_cp *cp);
@@ -528,8 +529,8 @@ struct ilo_gpe_gen6 {
    GEN6_EMIT(DEPTH_STENCIL_STATE);
    GEN6_EMIT(SCISSOR_RECT);
    GEN6_EMIT(BINDING_TABLE_STATE);
+   GEN6_EMIT(SURFACE_STATE);
    GEN6_EMIT(surf_SURFACE_STATE);
-   GEN6_EMIT(view_SURFACE_STATE);
    GEN6_EMIT(cbuf_SURFACE_STATE);
    GEN6_EMIT(so_SURFACE_STATE);
    GEN6_EMIT(SAMPLER_STATE);
index 43b76628d66c459b3b7d8ad5609c88daf26543ff..5dd75bc3171cb2caca07b76b82587a5ccbc0b179 100644 (file)
@@ -1717,39 +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_view_SURFACE_STATE(const struct ilo_dev_info *dev,
-                             const struct pipe_sampler_view *view,
-                             struct ilo_cp *cp)
-{
-   struct ilo_view_surface surf;
-
-   ILO_GPE_VALID_GEN(dev, 7, 7);
-
-   if (view->texture->target == PIPE_BUFFER) {
-      const unsigned elem_size = util_format_get_blocksize(view->format);
-      const unsigned first_elem = view->u.buf.first_element;
-      const unsigned num_elems = view->u.buf.last_element - first_elem + 1;
-      struct ilo_buffer *buf = ilo_buffer(view->texture);
-
-      ilo_gpe_init_view_surface_for_buffer_gen7(dev, buf,
-            first_elem * elem_size, num_elems * elem_size,
-            elem_size, view->format, false, false, &surf);
-   }
-   else {
-      struct ilo_texture *tex = ilo_texture(view->texture);
-
-      ilo_gpe_init_view_surface_for_texture_gen7(dev, tex, view->format,
-            view->u.tex.first_level,
-            view->u.tex.last_level - view->u.tex.first_level + 1,
-            view->u.tex.first_layer,
-            view->u.tex.last_layer - view->u.tex.first_layer + 1,
-            false, false, &surf);
-   }
-
-   return gen7_emit_SURFACE_STATE(dev, &surf, false, cp);
-}
-
 static uint32_t
 gen7_emit_cbuf_SURFACE_STATE(const struct ilo_dev_info *dev,
                              const struct pipe_constant_buffer *cbuf,
@@ -1993,8 +1960,8 @@ gen7_init(struct ilo_gpe_gen7 *gen7)
    GEN7_USE(gen7, DEPTH_STENCIL_STATE, gen6);
    GEN7_USE(gen7, SCISSOR_RECT, gen6);
    GEN7_USE(gen7, BINDING_TABLE_STATE, gen6);
+   GEN7_USE(gen7, SURFACE_STATE, gen6);
    GEN7_SET(gen7, surf_SURFACE_STATE);
-   GEN7_SET(gen7, view_SURFACE_STATE);
    GEN7_SET(gen7, cbuf_SURFACE_STATE);
    GEN7_USE(gen7, SAMPLER_STATE, gen6);
    GEN7_USE(gen7, SAMPLER_BORDER_COLOR_STATE, gen6);
index 5cc1fb1aaf86f1dbc249374162e853e47d84f4f0..552b217224708d3823db65c62835816f4eb56dbc 100644 (file)
@@ -385,8 +385,8 @@ typedef ilo_gpe_gen6_BLEND_STATE ilo_gpe_gen7_BLEND_STATE;
 typedef ilo_gpe_gen6_DEPTH_STENCIL_STATE ilo_gpe_gen7_DEPTH_STENCIL_STATE;
 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_view_SURFACE_STATE ilo_gpe_gen7_view_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;
@@ -483,8 +483,8 @@ struct ilo_gpe_gen7 {
    GEN7_EMIT(DEPTH_STENCIL_STATE);
    GEN7_EMIT(SCISSOR_RECT);
    GEN7_EMIT(BINDING_TABLE_STATE);
+   GEN7_EMIT(SURFACE_STATE);
    GEN7_EMIT(surf_SURFACE_STATE);
-   GEN7_EMIT(view_SURFACE_STATE);
    GEN7_EMIT(cbuf_SURFACE_STATE);
    GEN7_EMIT(SAMPLER_STATE);
    GEN7_EMIT(SAMPLER_BORDER_COLOR_STATE);
index 754b59baec23fdca5a0fc616c67ed5774e4bb574..9c692f26e60f89db7918097d2eca06a32c987aee 100644 (file)
@@ -77,10 +77,8 @@ ilo_shader_variant_init(struct ilo_shader_variant *variant,
 
    variant->num_sampler_views = info->num_samplers;
    for (i = 0; i < info->num_samplers; i++) {
-      const struct pipe_sampler_view *view =
-         ilo->view[info->type].states[i];
-      const struct ilo_sampler_cso *sampler =
-         ilo->sampler[info->type].cso[i];
+      const struct pipe_sampler_view *view = ilo->view[info->type].states[i];
+      const struct ilo_sampler_cso *sampler = ilo->sampler[info->type].cso[i];
 
       if (view) {
          variant->sampler_view_swizzles[i].r = view->swizzle_r;
index b154ece5a1e062a76affa7844ede9debb02a93d0..a88d643a3bf038163c5c2f6a7acee9edf946689f 100644 (file)
@@ -29,6 +29,7 @@
 #include "util/u_helpers.h"
 
 #include "ilo_context.h"
+#include "ilo_resource.h"
 #include "ilo_shader.h"
 #include "ilo_state.h"
 
@@ -845,18 +846,38 @@ ilo_create_sampler_view(struct pipe_context *pipe,
                         struct pipe_resource *res,
                         const struct pipe_sampler_view *templ)
 {
-   struct pipe_sampler_view *view;
+   struct ilo_context *ilo = ilo_context(pipe);
+   struct ilo_view_cso *view;
 
-   view = MALLOC_STRUCT(pipe_sampler_view);
+   view = MALLOC_STRUCT(ilo_view_cso);
    assert(view);
 
-   *view = *templ;
-   pipe_reference_init(&view->reference, 1);
-   view->texture = NULL;
-   pipe_resource_reference(&view->texture, res);
-   view->context = pipe;
+   view->base = *templ;
+   pipe_reference_init(&view->base.reference, 1);
+   view->base.texture = NULL;
+   pipe_resource_reference(&view->base.texture, res);
+   view->base.context = pipe;
+
+   if (res->target == PIPE_BUFFER) {
+      const unsigned elem_size = util_format_get_blocksize(templ->format);
+      const unsigned first_elem = templ->u.buf.first_element;
+      const unsigned num_elems = templ->u.buf.last_element - first_elem + 1;
+
+      ilo_gpe_init_view_surface_for_buffer(ilo->dev, ilo_buffer(res),
+            first_elem * elem_size, num_elems * elem_size,
+            elem_size, templ->format, false, false, &view->surface);
+   }
+   else {
+      ilo_gpe_init_view_surface_for_texture(ilo->dev, ilo_texture(res),
+            templ->format,
+            templ->u.tex.first_level,
+            templ->u.tex.last_level - templ->u.tex.first_level + 1,
+            templ->u.tex.first_layer,
+            templ->u.tex.last_layer - templ->u.tex.first_layer + 1,
+            false, false, &view->surface);
+   }
 
-   return view;
+   return &view->base;
 }
 
 static void