[Mesa-dev] [PATCH 2/6] vl: Get rid of video_buffer.sampler_view_components

Maarten Lankhorst m.b.lankhorst at gmail.com
Thu Dec 1 16:03:00 PST 2011


No point in having it when just having sampler_view_planes is good enough. :-)

Signed-off-by: Maarten Lankhorst <m.b.lankhorst at gmail.com>
---
 src/gallium/auxiliary/vl/vl_compositor.c    |   36 ++++++++++++++-----
 src/gallium/auxiliary/vl/vl_compositor.h    |    2 +-
 src/gallium/auxiliary/vl/vl_video_buffer.c  |   46 +++-----------------------
 src/gallium/auxiliary/vl/vl_video_buffer.h  |    1 -
 src/gallium/drivers/nouveau/nouveau_video.c |   48 +++------------------------
 src/gallium/drivers/nouveau/nouveau_video.h |    1 -
 src/gallium/include/pipe/p_video_decoder.h  |    5 ---
 7 files changed, 37 insertions(+), 102 deletions(-)

diff --git a/src/gallium/auxiliary/vl/vl_compositor.c b/src/gallium/auxiliary/vl/vl_compositor.c
index 322ef8e..fff4340 100644
--- a/src/gallium/auxiliary/vl/vl_compositor.c
+++ b/src/gallium/auxiliary/vl/vl_compositor.c
@@ -71,7 +71,7 @@ create_vert_shader(struct vl_compositor *c)
 }
 
 static void *
-create_frag_shader_video_buffer(struct vl_compositor *c)
+create_frag_shader_video_buffer(struct vl_compositor *c, unsigned planes)
 {
    struct ureg_program *shader;
    struct ureg_src tc;
@@ -88,7 +88,8 @@ create_frag_shader_video_buffer(struct vl_compositor *c)
    tc = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, 1, TGSI_INTERPOLATE_LINEAR);
    for (i = 0; i < 3; ++i) {
       csc[i] = ureg_DECL_constant(shader, i);
-      sampler[i] = ureg_DECL_sampler(shader, i);
+      if (i < planes)
+         sampler[i] = ureg_DECL_sampler(shader, i);
    }
    texel = ureg_DECL_temporary(shader);
    fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
@@ -97,8 +98,13 @@ create_frag_shader_video_buffer(struct vl_compositor *c)
     * texel.xyz = tex(tc, sampler[i])
     * fragment = csc * texel
     */
-   for (i = 0; i < 3; ++i)
-      ureg_TEX(shader, ureg_writemask(texel, TGSI_WRITEMASK_X << i), TGSI_TEXTURE_2D, tc, sampler[i]);
+   if (planes == 2) {
+      ureg_TEX(shader, ureg_writemask(texel, TGSI_WRITEMASK_X), TGSI_TEXTURE_2D, tc, sampler[0]);
+      ureg_TEX(shader, ureg_writemask(texel, TGSI_WRITEMASK_Y|TGSI_WRITEMASK_Z), TGSI_TEXTURE_2D, tc, sampler[1]);
+   } else {
+      for (i = 0; i < 3; ++i)
+         ureg_TEX(shader, ureg_writemask(texel, TGSI_WRITEMASK_X << i), TGSI_TEXTURE_2D, tc, sampler[i]);
+   }
 
    ureg_MOV(shader, ureg_writemask(texel, TGSI_WRITEMASK_W), ureg_imm1f(shader, 1.0f));
 
@@ -198,9 +204,14 @@ init_shaders(struct vl_compositor *c)
       return false;
    }
 
-   c->fs_video_buffer = create_frag_shader_video_buffer(c);
-   if (!c->fs_video_buffer) {
-      debug_printf("Unable to create YCbCr-to-RGB fragment shader.\n");
+   c->fs_video_buffer2 = create_frag_shader_video_buffer(c, 2);
+   if (!c->fs_video_buffer2) {
+      debug_printf("Unable to create YCbCr-to-RGB fragment shader for 2 planes.\n");
+      return false;
+   }
+   c->fs_video_buffer3 = create_frag_shader_video_buffer(c, 3);
+   if (!c->fs_video_buffer3) {
+      debug_printf("Unable to create YCbCr-to-RGB fragment shader for 3 planes.\n");
       return false;
    }
 
@@ -230,7 +241,8 @@ static void cleanup_shaders(struct vl_compositor *c)
    assert(c);
 
    c->pipe->delete_vs_state(c->pipe, c->vs);
-   c->pipe->delete_fs_state(c->pipe, c->fs_video_buffer);
+   c->pipe->delete_fs_state(c->pipe, c->fs_video_buffer2);
+   c->pipe->delete_fs_state(c->pipe, c->fs_video_buffer3);
    c->pipe->delete_fs_state(c->pipe, c->fs_palette.yuv);
    c->pipe->delete_fs_state(c->pipe, c->fs_palette.rgb);
    c->pipe->delete_fs_state(c->pipe, c->fs_rgba);
@@ -644,13 +656,17 @@ vl_compositor_set_buffer_layer(struct vl_compositor *c,
    assert(layer < VL_COMPOSITOR_MAX_LAYERS);
 
    c->used_layers |= 1 << layer;
-   c->layers[layer].fs = c->fs_video_buffer;
 
-   sampler_views = buffer->get_sampler_view_components(buffer);
+   sampler_views = buffer->get_sampler_view_planes(buffer);
    for (i = 0; i < 3; ++i) {
       c->layers[layer].samplers[i] = c->sampler_linear;
       pipe_sampler_view_reference(&c->layers[layer].sampler_views[i], sampler_views[i]);
    }
+   if (sampler_views[2])
+      c->layers[layer].fs = c->fs_video_buffer3;
+   else
+      c->layers[layer].fs = c->fs_video_buffer2;
+   assert(sampler_views[1]);
 
    calc_src_and_dst(&c->layers[layer], buffer->width, buffer->height,
                     src_rect ? *src_rect : default_rect(&c->layers[layer]),
diff --git a/src/gallium/auxiliary/vl/vl_compositor.h b/src/gallium/auxiliary/vl/vl_compositor.h
index f60f7da..cc91c2b 100644
--- a/src/gallium/auxiliary/vl/vl_compositor.h
+++ b/src/gallium/auxiliary/vl/vl_compositor.h
@@ -73,7 +73,7 @@ struct vl_compositor
    void *vertex_elems_state;
 
    void *vs;
-   void *fs_video_buffer;
+   void *fs_video_buffer2, *fs_video_buffer3;
    void *fs_rgba;
 
    struct {
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c
index 6d714d4..a95a1dd 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.c
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.c
@@ -109,7 +109,6 @@ vl_video_buffer_destroy(struct pipe_video_buffer *buffer)
    for (i = 0; i < VL_MAX_PLANES; ++i) {
       pipe_surface_reference(&buf->surfaces[i], NULL);
       pipe_sampler_view_reference(&buf->sampler_view_planes[i], NULL);
-      pipe_sampler_view_reference(&buf->sampler_view_components[i], NULL);
       pipe_resource_reference(&buf->resources[i], NULL);
    }
 
@@ -135,6 +134,11 @@ vl_video_buffer_sampler_view_planes(struct pipe_video_buffer *buffer)
 
          if (util_format_get_nr_components(buf->resources[i]->format) == 1)
             sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = sv_templ.swizzle_a = PIPE_SWIZZLE_RED;
+         else if (buf->resources[i]->format == PIPE_FORMAT_R8G8_UNORM) {
+            sv_templ.swizzle_b = sv_templ.swizzle_g;
+            sv_templ.swizzle_g = sv_templ.swizzle_r;
+            assert(i == 1);
+         }
 
          buf->sampler_view_planes[i] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ);
          if (!buf->sampler_view_planes[i])
@@ -151,45 +155,6 @@ error:
    return NULL;
 }
 
-static struct pipe_sampler_view **
-vl_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer)
-{
-   struct vl_video_buffer *buf = (struct vl_video_buffer *)buffer;
-   struct pipe_sampler_view sv_templ;
-   struct pipe_context *pipe;
-   unsigned i, j, component;
-
-   assert(buf);
-
-   pipe = buf->base.context;
-
-   for (component = 0, i = 0; i < buf->num_planes; ++i ) {
-      unsigned nr_components = util_format_get_nr_components(buf->resources[i]->format);
-
-      for (j = 0; j < nr_components; ++j, ++component) {
-         assert(component < VL_MAX_PLANES);
-
-         if (!buf->sampler_view_components[component]) {
-            memset(&sv_templ, 0, sizeof(sv_templ));
-            u_sampler_view_default_template(&sv_templ, buf->resources[i], buf->resources[i]->format);
-            sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = PIPE_SWIZZLE_RED + j;
-            sv_templ.swizzle_a = PIPE_SWIZZLE_ONE;
-            buf->sampler_view_components[component] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ);
-            if (!buf->sampler_view_components[component])
-               goto error;
-         }
-      }
-   }
-
-   return buf->sampler_view_components;
-
-error:
-   for (i = 0; i < VL_MAX_PLANES; ++i )
-      pipe_sampler_view_reference(&buf->sampler_view_components[i], NULL);
-
-   return NULL;
-}
-
 static struct pipe_surface **
 vl_video_buffer_surfaces(struct pipe_video_buffer *buffer)
 {
@@ -279,7 +244,6 @@ vl_video_buffer_create_ex(struct pipe_context *pipe,
    buffer->base.context = pipe;
    buffer->base.destroy = vl_video_buffer_destroy;
    buffer->base.get_sampler_view_planes = vl_video_buffer_sampler_view_planes;
-   buffer->base.get_sampler_view_components = vl_video_buffer_sampler_view_components;
    buffer->base.get_surfaces = vl_video_buffer_surfaces;
    buffer->base.chroma_format = chroma_format;
    buffer->base.width = width;
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.h b/src/gallium/auxiliary/vl/vl_video_buffer.h
index 8c80b36..c07cfce 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.h
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.h
@@ -44,7 +44,6 @@ struct vl_video_buffer
    unsigned                 num_planes;
    struct pipe_resource     *resources[VL_MAX_PLANES];
    struct pipe_sampler_view *sampler_view_planes[VL_MAX_PLANES];
-   struct pipe_sampler_view *sampler_view_components[VL_MAX_PLANES];
    struct pipe_surface      *surfaces[VL_MAX_PLANES];
 };
 
diff --git a/src/gallium/drivers/nouveau/nouveau_video.c b/src/gallium/drivers/nouveau/nouveau_video.c
index 162e1aa..1144be2 100644
--- a/src/gallium/drivers/nouveau/nouveau_video.c
+++ b/src/gallium/drivers/nouveau/nouveau_video.c
@@ -668,6 +668,11 @@ nouveau_video_buffer_sampler_view_planes(struct pipe_video_buffer *buffer)
 
          if (util_format_get_nr_components(buf->resources[i]->format) == 1)
             sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = sv_templ.swizzle_a = PIPE_SWIZZLE_RED;
+         else {
+            sv_templ.swizzle_b = sv_templ.swizzle_g;
+            sv_templ.swizzle_g = sv_templ.swizzle_r;
+            assert(i == 1);
+         }
 
          buf->sampler_view_planes[i] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ);
          if (!buf->sampler_view_planes[i])
@@ -684,45 +689,6 @@ error:
    return NULL;
 }
 
-static struct pipe_sampler_view **
-nouveau_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer)
-{
-   struct nouveau_video_buffer *buf = (struct nouveau_video_buffer *)buffer;
-   struct pipe_sampler_view sv_templ;
-   struct pipe_context *pipe;
-   unsigned i, j, component;
-
-   assert(buf);
-
-   pipe = buf->base.context;
-
-   for (component = 0, i = 0; i < buf->num_planes; ++i ) {
-      unsigned nr_components = util_format_get_nr_components(buf->resources[i]->format);
-
-      for (j = 0; j < nr_components; ++j, ++component) {
-         assert(component < VL_MAX_PLANES);
-
-         if (!buf->sampler_view_components[component]) {
-            memset(&sv_templ, 0, sizeof(sv_templ));
-            u_sampler_view_default_template(&sv_templ, buf->resources[i], buf->resources[i]->format);
-            sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = PIPE_SWIZZLE_RED + j;
-            sv_templ.swizzle_a = PIPE_SWIZZLE_ONE;
-            buf->sampler_view_components[component] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ);
-            if (!buf->sampler_view_components[component])
-               goto error;
-         }
-      }
-   }
-
-   return buf->sampler_view_components;
-
-error:
-   for (i = 0; i < 3; ++i )
-      pipe_sampler_view_reference(&buf->sampler_view_components[i], NULL);
-
-   return NULL;
-}
-
 static struct pipe_surface **
 nouveau_video_buffer_surfaces(struct pipe_video_buffer *buffer)
 {
@@ -766,11 +732,8 @@ nouveau_video_buffer_destroy(struct pipe_video_buffer *buffer)
    for (i = 0; i < buf->num_planes; ++i) {
       pipe_surface_reference(&buf->surfaces[i], NULL);
       pipe_sampler_view_reference(&buf->sampler_view_planes[i], NULL);
-      pipe_sampler_view_reference(&buf->sampler_view_components[i], NULL);
       pipe_resource_reference(&buf->resources[i], NULL);
    }
-   for (;i < 3;++i)
-      pipe_sampler_view_reference(&buf->sampler_view_components[i], NULL);
 
    FREE(buffer);
 }
@@ -804,7 +767,6 @@ nouveau_video_buffer_create(struct pipe_context *pipe,
    buffer->base.context = pipe;
    buffer->base.destroy = nouveau_video_buffer_destroy;
    buffer->base.get_sampler_view_planes = nouveau_video_buffer_sampler_view_planes;
-   buffer->base.get_sampler_view_components = nouveau_video_buffer_sampler_view_components;
    buffer->base.get_surfaces = nouveau_video_buffer_surfaces;
    buffer->base.chroma_format = chroma_format;
    buffer->base.width = width;
diff --git a/src/gallium/drivers/nouveau/nouveau_video.h b/src/gallium/drivers/nouveau/nouveau_video.h
index c6875c3..fb22253 100644
--- a/src/gallium/drivers/nouveau/nouveau_video.h
+++ b/src/gallium/drivers/nouveau/nouveau_video.h
@@ -9,7 +9,6 @@ struct nouveau_video_buffer {
    unsigned num_planes;
    struct pipe_resource     *resources[2];
    struct pipe_sampler_view *sampler_view_planes[2];
-   struct pipe_sampler_view *sampler_view_components[3];
    struct pipe_surface      *surfaces[2];
 };
 
diff --git a/src/gallium/include/pipe/p_video_decoder.h b/src/gallium/include/pipe/p_video_decoder.h
index 40b7dcd..034b860 100644
--- a/src/gallium/include/pipe/p_video_decoder.h
+++ b/src/gallium/include/pipe/p_video_decoder.h
@@ -153,11 +153,6 @@ struct pipe_video_buffer
    struct pipe_sampler_view **(*get_sampler_view_planes)(struct pipe_video_buffer *buffer);
 
    /**
-    * get a individual sampler view for each component
-    */
-   struct pipe_sampler_view **(*get_sampler_view_components)(struct pipe_video_buffer *buffer);
-
-   /**
     * get a individual surfaces for each plane
     */
    struct pipe_surface **(*get_surfaces)(struct pipe_video_buffer *buffer);
-- 
1.7.7.3





More information about the mesa-dev mailing list