OSDN Git Service

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 9aa39bf..800a339 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 7b61814..0ac9bcd 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 21932c8..850475a 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 ccb4ebc..1b5a38f 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 f6d2fab..5eb797c 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;
@@ -4210,39 +4217,6 @@ gen6_emit_surf_SURFACE_STATE(const struct ilo_dev_info *dev,
 }
 
 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,
                              struct ilo_cp *cp)
@@ -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 a3489c8..64893b5 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 43b7662..5dd75bc 100644 (file)
@@ -1718,39 +1718,6 @@ gen7_emit_surf_SURFACE_STATE(const struct ilo_dev_info *dev,
 }
 
 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,
                              struct ilo_cp *cp)
@@ -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 5cc1fb1..552b217 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 754b59b..9c692f2 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 b154ece..a88d643 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