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

Maarten Lankhorst m.b.lankhorst at gmail.com
Wed Dec 7 03:19:31 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>

---
Changes since v1:
- increase nouveau_video_buffer sampler_view_planes array size to 3,
  which is the only valid size, since all planes are tested against null
- Fixed vl_mc_render_ref

 src/gallium/auxiliary/vl/vl_compositor.c     |   36 ++++++++++++++-----
 src/gallium/auxiliary/vl/vl_compositor.h     |    2 +-
 src/gallium/auxiliary/vl/vl_mc.c             |   29 +++++++++++++---
 src/gallium/auxiliary/vl/vl_mc.h             |    4 +-
 src/gallium/auxiliary/vl/vl_mpeg12_decoder.c |    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  |    5 +--
 src/gallium/include/pipe/p_video_decoder.h   |    5 ---
 10 files changed, 66 insertions(+), 112 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_mc.c b/src/gallium/auxiliary/vl/vl_mc.c
index 9534a8f..c371dea 100644
--- a/src/gallium/auxiliary/vl/vl_mc.c
+++ b/src/gallium/auxiliary/vl/vl_mc.c
@@ -31,6 +31,7 @@
 
 #include "util/u_sampler.h"
 #include "util/u_draw.h"
+#include "util/u_format.h"
 
 #include "tgsi/tgsi_ureg.h"
 
@@ -153,7 +154,7 @@ create_ref_vert_shader(struct vl_mc *r)
 }
 
 static void *
-create_ref_frag_shader(struct vl_mc *r)
+create_ref_frag_shader(struct vl_mc *r, unsigned cbcr)
 {
    const float y_scale =
       r->buffer_height / 2 *
@@ -211,7 +212,15 @@ create_ref_frag_shader(struct vl_mc *r)
    ureg_fixup_label(shader, label, ureg_get_instruction_number(shader));
    ureg_ENDIF(shader);
 
-   ureg_TEX(shader, ureg_writemask(fragment, TGSI_WRITEMASK_XYZ), TGSI_TEXTURE_2D, ureg_src(ref), sampler);
+   if (!cbcr) {
+      ureg_TEX(shader, ureg_writemask(fragment, TGSI_WRITEMASK_XYZ), TGSI_TEXTURE_2D, ureg_src(ref), sampler);
+   } else {
+      struct ureg_dst color = ureg_DECL_temporary(shader);
+      ureg_TEX(shader, ureg_writemask(color, TGSI_WRITEMASK_YZ), TGSI_TEXTURE_2D, ureg_src(ref), sampler);
+      ureg_MOV(shader, ureg_writemask(color, TGSI_WRITEMASK_XY),
+               ureg_swizzle(ureg_src(ref), TGSI_SWIZZLE_Y, TGSI_SWIZZLE_Z, TGSI_SWIZZLE_Z, TGSI_SWIZZLE_Z));
+      ureg_release_temporary(shader, color);
+   }
 
    ureg_release_temporary(shader, ref);
 
@@ -499,9 +508,12 @@ vl_mc_init(struct vl_mc *renderer, struct pipe_context *pipe,
    if (!renderer->vs_ycbcr)
       goto error_vs_ycbcr;
 
-   renderer->fs_ref = create_ref_frag_shader(renderer);
+   renderer->fs_ref = create_ref_frag_shader(renderer, 0);
    if (!renderer->fs_ref)
       goto error_fs_ref;
+   renderer->fs_ref_cbcr = create_ref_frag_shader(renderer, 1);
+   if (!renderer->fs_ref_cbcr)
+      goto error_fs_ref_cbcr;
 
    renderer->fs_ycbcr = create_ycbcr_frag_shader(renderer, scale, false, fs_callback, callback_priv);
    if (!renderer->fs_ycbcr)
@@ -516,6 +528,9 @@ vl_mc_init(struct vl_mc *renderer, struct pipe_context *pipe,
 error_fs_ycbcr_sub:
    renderer->pipe->delete_fs_state(renderer->pipe, renderer->fs_ycbcr);
 
+error_fs_ref_cbcr:
+   renderer->pipe->delete_fs_state(renderer->pipe, renderer->fs_ref_cbcr);
+
 error_fs_ycbcr:
    renderer->pipe->delete_fs_state(renderer->pipe, renderer->fs_ref);
 
@@ -541,6 +556,7 @@ vl_mc_cleanup(struct vl_mc *renderer)
 
    renderer->pipe->delete_vs_state(renderer->pipe, renderer->vs_ref);
    renderer->pipe->delete_vs_state(renderer->pipe, renderer->vs_ycbcr);
+   renderer->pipe->delete_fs_state(renderer->pipe, renderer->fs_ref_cbcr);
    renderer->pipe->delete_fs_state(renderer->pipe, renderer->fs_ref);
    renderer->pipe->delete_fs_state(renderer->pipe, renderer->fs_ycbcr);
    renderer->pipe->delete_fs_state(renderer->pipe, renderer->fs_ycbcr_sub);
@@ -607,7 +623,7 @@ prepare_pipe_4_rendering(struct vl_mc_buffer *buffer, unsigned mask)
 }
 
 void
-vl_mc_render_ref(struct vl_mc_buffer *buffer, struct pipe_sampler_view *ref)
+vl_mc_render_ref(struct vl_mc_buffer *buffer, struct pipe_sampler_view *ref, unsigned plane)
 {
    struct vl_mc *renderer;
 
@@ -618,7 +634,10 @@ vl_mc_render_ref(struct vl_mc_buffer *buffer, struct pipe_sampler_view *ref)
    renderer = buffer->renderer;
 
    renderer->pipe->bind_vs_state(renderer->pipe, renderer->vs_ref);
-   renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs_ref);
+   if (plane == 1 && util_format_get_nr_components(ref->format) == 2)
+      renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs_ref_cbcr);
+   else
+      renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs_ref);
 
    renderer->pipe->set_fragment_sampler_views(renderer->pipe, 1, &ref);
    renderer->pipe->bind_fragment_sampler_states(renderer->pipe, 1, &renderer->sampler_ref);
diff --git a/src/gallium/auxiliary/vl/vl_mc.h b/src/gallium/auxiliary/vl/vl_mc.h
index 081562a..3f67810 100644
--- a/src/gallium/auxiliary/vl/vl_mc.h
+++ b/src/gallium/auxiliary/vl/vl_mc.h
@@ -53,7 +53,7 @@ struct vl_mc
    void *blend_add[VL_MC_NUM_BLENDERS];
    void *blend_sub[VL_MC_NUM_BLENDERS];
    void *vs_ref, *vs_ycbcr;
-   void *fs_ref, *fs_ycbcr, *fs_ycbcr_sub;
+   void *fs_ref, *fs_ref_cbcr, *fs_ycbcr, *fs_ycbcr_sub;
    void *sampler_ref;
 };
 
@@ -92,7 +92,7 @@ void vl_mc_cleanup_buffer(struct vl_mc_buffer *buffer);
 
 void vl_mc_set_surface(struct vl_mc_buffer *buffer, struct pipe_surface *surface);
 
-void vl_mc_render_ref(struct vl_mc_buffer *buffer, struct pipe_sampler_view *ref);
+void vl_mc_render_ref(struct vl_mc_buffer *buffer, struct pipe_sampler_view *ref, unsigned plane);
 
 void vl_mc_render_ycbcr(struct vl_mc_buffer *buffer, unsigned component, unsigned num_instances);
 
diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
index 2442d78..6216d5e 100644
--- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
+++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
@@ -744,7 +744,7 @@ vl_mpeg12_end_frame(struct pipe_video_decoder *decoder)
          vb[2] = vl_vb_get_mv(&buf->vertex_stream, j);;
          dec->base.context->set_vertex_buffers(dec->base.context, 3, vb);
 
-         vl_mc_render_ref(&buf->mc[i], dec->ref_frames[j][i]);
+         vl_mc_render_ref(&buf->mc[i], dec->ref_frames[j][i], i);
       }
    }
 
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..489ff5b 100644
--- a/src/gallium/drivers/nouveau/nouveau_video.h
+++ b/src/gallium/drivers/nouveau/nouveau_video.h
@@ -8,9 +8,8 @@ struct nouveau_video_buffer {
    struct pipe_video_buffer base;
    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];
+   struct pipe_sampler_view *sampler_view_planes[3];
+   struct pipe_surface      *surfaces[3];
 };
 
 struct nouveau_decoder {
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.4





More information about the mesa-dev mailing list