[g3dvl] let mc code work on the different color planes seperately
authorChristian König <deathsimple@vodafone.de>
Tue, 29 Mar 2011 18:01:49 +0000 (20:01 +0200)
committerChristian König <deathsimple@vodafone.de>
Tue, 29 Mar 2011 18:01:49 +0000 (20:01 +0200)
src/gallium/auxiliary/vl/vl_compositor.c
src/gallium/auxiliary/vl/vl_compositor.h
src/gallium/auxiliary/vl/vl_mpeg12_context.c
src/gallium/auxiliary/vl/vl_mpeg12_context.h
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h
src/gallium/auxiliary/vl/vl_ycbcr_buffer.c

index b0e0b3bfa725b9718094e6e8bb5382c5d551b6bb..f62706e5066d531c99ebe6c3620dee324befade3 100644 (file)
@@ -104,8 +104,8 @@ create_frag_shader_ycbcr_2_rgb(struct vl_compositor *c)
 {
    struct ureg_program *shader;
    struct ureg_src tc;
-   struct ureg_src csc[4];
-   struct ureg_src sampler;
+   struct ureg_src csc[3];
+   struct ureg_src sampler[3];
    struct ureg_dst texel;
    struct ureg_dst fragment;
    unsigned i;
@@ -115,19 +115,25 @@ create_frag_shader_ycbcr_2_rgb(struct vl_compositor *c)
       return false;
 
    tc = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, 1, TGSI_INTERPOLATE_LINEAR);
-   for (i = 0; i < 4; ++i)
+   for (i = 0; i < 3; ++i) {
       csc[i] = ureg_DECL_constant(shader, i);
-   sampler = ureg_DECL_sampler(shader, 0);
+      sampler[i] = ureg_DECL_sampler(shader, i);
+   }
    texel = ureg_DECL_temporary(shader);
    fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
 
    /*
-    * texel = tex(tc, sampler)
+    * texel.xyz = tex(tc, sampler[i])
     * fragment = csc * texel
     */
-   ureg_TEX(shader, texel, TGSI_TEXTURE_2D, tc, sampler);
+   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));
+
    for (i = 0; i < 3; ++i)
       ureg_DP4(shader, ureg_writemask(fragment, TGSI_WRITEMASK_X << i), csc[i], ureg_src(texel));
+
    ureg_MOV(shader, ureg_writemask(fragment, TGSI_WRITEMASK_W), ureg_imm1f(shader, 1.0f));
 
    ureg_release_temporary(shader, texel);
@@ -531,7 +537,7 @@ static unsigned gen_data(struct vl_compositor *c,
 }
 
 static void draw_layers(struct vl_compositor *c,
-                        struct pipe_sampler_view *src_surface,
+                        struct vl_ycbcr_sampler_views *src_sampler,
                         struct pipe_video_rect *src_rect,
                         struct pipe_video_rect *dst_rect)
 {
@@ -541,37 +547,39 @@ static void draw_layers(struct vl_compositor *c,
    unsigned i;
 
    assert(c);
-   assert(src_surface);
+   assert(src_sampler);
    assert(src_rect);
    assert(dst_rect);
 
-   num_rects = gen_data(c, src_surface, src_rect, dst_rect, surfaces, frag_shaders);
+   num_rects = gen_data(c, src_sampler->y, src_rect, dst_rect, surfaces, frag_shaders);
 
    c->pipe->bind_blend_state(c->pipe, c->blend);
    for (i = 0; i < num_rects; ++i) {
       c->pipe->bind_fs_state(c->pipe, frag_shaders[i]);
-      c->pipe->set_fragment_sampler_views(c->pipe, surfaces[i][1] ? 2 : 1, &surfaces[i][0]);
+      if (i == 0) {
+         c->pipe->set_fragment_sampler_views(c->pipe, 3, &src_sampler->y);
+      } else {
+         c->pipe->set_fragment_sampler_views(c->pipe, surfaces[i][1] ? 2 : 1, &surfaces[i][0]);
+      }
 
       util_draw_arrays(c->pipe, PIPE_PRIM_QUADS, i * 4, 4);
    }
 }
 
 void vl_compositor_render(struct vl_compositor          *compositor,
-                          struct pipe_sampler_view      *src_surface,
-                          enum pipe_mpeg12_picture_type picture_type,
+                          struct vl_ycbcr_sampler_views *src_sampler,
                           struct pipe_video_rect        *src_area,
                           struct pipe_surface           *dst_surface,
                           struct pipe_video_rect        *dst_area,
                           struct pipe_fence_handle      **fence)
 {
-   void *samplers[2];
+   void *samplers[3];
 
    assert(compositor);
-   assert(src_surface);
+   assert(src_sampler);
    assert(src_area);
    assert(dst_surface);
    assert(dst_area);
-   assert(picture_type == PIPE_MPEG12_PICTURE_TYPE_FRAME);
 
    if (compositor->fb_state.width != dst_surface->width) {
       compositor->fb_inv_size.x = 1.0f / dst_surface->width;
@@ -593,17 +601,17 @@ void vl_compositor_render(struct vl_compositor          *compositor,
    compositor->viewport.translate[2] = 0;
    compositor->viewport.translate[3] = 0;
 
-   samplers[0] = samplers[1] = compositor->sampler;
+   samplers[0] = samplers[1] = samplers[2] = compositor->sampler;
 
    compositor->pipe->set_framebuffer_state(compositor->pipe, &compositor->fb_state);
    compositor->pipe->set_viewport_state(compositor->pipe, &compositor->viewport);
-   compositor->pipe->bind_fragment_sampler_states(compositor->pipe, 2, &samplers[0]);
+   compositor->pipe->bind_fragment_sampler_states(compositor->pipe, 3, &samplers[0]);
    compositor->pipe->bind_vs_state(compositor->pipe, compositor->vertex_shader);
    compositor->pipe->set_vertex_buffers(compositor->pipe, 1, &compositor->vertex_buf);
    compositor->pipe->bind_vertex_elements_state(compositor->pipe, compositor->vertex_elems_state);
    compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_FRAGMENT, 0, compositor->fs_const_buf);
 
-   draw_layers(compositor, src_surface, src_area, dst_area);
+   draw_layers(compositor, src_sampler, src_area, dst_area);
 
    assert(!compositor->dirty_layers);
    compositor->pipe->flush(compositor->pipe, fence);
index 249eb685b40d7e9ca93179d8839dfef7a66607d0..e10a663f86045e00843e90257cd1e720c3653c1e 100644 (file)
@@ -32,6 +32,7 @@
 #include <pipe/p_state.h>
 #include <pipe/p_video_state.h>
 #include "vl_types.h"
+#include "vl_ycbcr_buffer.h"
 
 struct pipe_context;
 struct keymap;
@@ -78,8 +79,7 @@ void vl_compositor_set_layers(struct vl_compositor *compositor,
                               unsigned num_layers);
 
 void vl_compositor_render(struct vl_compositor          *compositor,
-                          struct pipe_sampler_view      *src_surface,
-                          enum pipe_mpeg12_picture_type picture_type,
+                          struct vl_ycbcr_sampler_views *src_sampler,
                           struct pipe_video_rect        *src_area,
                           struct pipe_surface           *dst_surface,
                           struct pipe_video_rect        *dst_area,
index 6388b3e23cbfdefa84c87b4c639cb04a3e459ef7..94ac70e2126364446f537b9eddc9895721500a27 100644 (file)
@@ -89,13 +89,16 @@ vl_mpeg12_buffer_destroy(struct pipe_video_buffer *buffer)
    struct vl_mpeg12_context *ctx = (struct vl_mpeg12_context*)buf->base.context;
    assert(buf && ctx);
 
+   vl_ycbcr_buffer_cleanup(&buf->idct_source);
+   vl_ycbcr_buffer_cleanup(&buf->idct_2_mc);
+   vl_ycbcr_buffer_cleanup(&buf->render_result);
    vl_vb_cleanup(&buf->vertex_stream);
    vl_idct_cleanup_buffer(&ctx->idct_y, &buf->idct_y);
    vl_idct_cleanup_buffer(&ctx->idct_cb, &buf->idct_cb);
    vl_idct_cleanup_buffer(&ctx->idct_cr, &buf->idct_cr);
-   vl_mpeg12_mc_cleanup_buffer(&buf->mc);
-   pipe_surface_reference(&buf->surface, NULL);
-   pipe_sampler_view_reference(&buf->sampler_view, NULL);
+   vl_mpeg12_mc_cleanup_buffer(&buf->mc_y);
+   vl_mpeg12_mc_cleanup_buffer(&buf->mc_cb);
+   vl_mpeg12_mc_cleanup_buffer(&buf->mc_cr);
 
    FREE(buf);
 }
@@ -166,6 +169,10 @@ vl_mpeg12_buffer_flush(struct pipe_video_buffer *buffer,
    struct vl_mpeg12_buffer *past = (struct vl_mpeg12_buffer *)refs[0];
    struct vl_mpeg12_buffer *future = (struct vl_mpeg12_buffer *)refs[1];
 
+   struct vl_ycbcr_surfaces *surfaces;
+   struct vl_ycbcr_sampler_views *sv_past;
+   struct vl_ycbcr_sampler_views *sv_future;
+
    struct pipe_sampler_view *sv_refs[2];
    unsigned ne_start, ne_num, e_start, e_num;
    struct vl_mpeg12_context *ctx;
@@ -184,13 +191,28 @@ vl_mpeg12_buffer_flush(struct pipe_video_buffer *buffer,
    vl_idct_flush(&ctx->idct_cr, &buf->idct_cr, ne_num);
    vl_idct_flush(&ctx->idct_cb, &buf->idct_cb, ne_num);
 
-   sv_refs[0] = past ? past->sampler_view : NULL;
-   sv_refs[1] = future ? future->sampler_view : NULL;
+   surfaces = vl_ycbcr_get_surfaces(&buf->render_result);
+
+   sv_past = past ? vl_ycbcr_get_sampler_views(&past->render_result) : NULL;
+   sv_future = future ? vl_ycbcr_get_sampler_views(&future->render_result) : NULL;
+
+   sv_refs[0] = sv_past ? sv_past->y : NULL;
+   sv_refs[1] = sv_future ? sv_future->y : NULL;
+
+   vl_mpeg12_mc_renderer_flush(&ctx->mc_y, &buf->mc_y, surfaces->y,
+                               sv_refs, ne_start, ne_num, e_start, e_num, fence);
 
-   vl_mpeg12_mc_renderer_flush(&ctx->mc_renderer, &buf->mc,
-                               buf->surface, sv_refs,
-                               ne_start, ne_num, e_start, e_num,
-                               fence);
+   sv_refs[0] = sv_past ? sv_past->cb : NULL;
+   sv_refs[1] = sv_future ? sv_future->cb : NULL;
+
+   vl_mpeg12_mc_renderer_flush(&ctx->mc_cb, &buf->mc_cb, surfaces->cb,
+                               sv_refs, ne_start, ne_num, e_start, e_num, fence);
+
+   sv_refs[0] = sv_past ? sv_past->cr : NULL;
+   sv_refs[1] = sv_future ? sv_future->cr : NULL;
+
+   vl_mpeg12_mc_renderer_flush(&ctx->mc_cr, &buf->mc_cr, surfaces->cr,
+                               sv_refs, ne_start, ne_num, e_start, e_num, fence);
 }
 
 static void
@@ -209,7 +231,9 @@ vl_mpeg12_destroy(struct pipe_video_context *vpipe)
    ctx->pipe->delete_depth_stencil_alpha_state(ctx->pipe, ctx->dsa);
 
    vl_compositor_cleanup(&ctx->compositor);
-   vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
+   vl_mpeg12_mc_renderer_cleanup(&ctx->mc_y);
+   vl_mpeg12_mc_renderer_cleanup(&ctx->mc_cb);
+   vl_mpeg12_mc_renderer_cleanup(&ctx->mc_cr);
    vl_idct_cleanup(&ctx->idct_y);
    vl_idct_cleanup(&ctx->idct_cr);
    vl_idct_cleanup(&ctx->idct_cb);
@@ -270,10 +294,7 @@ vl_mpeg12_create_buffer(struct pipe_video_context *vpipe)
    struct vl_mpeg12_context *ctx = (struct vl_mpeg12_context*)vpipe;
    struct vl_mpeg12_buffer *buffer;
 
-   struct pipe_resource res_template, *resource;
-   struct pipe_surface surf_template;
-   struct pipe_sampler_view sv_template;
-   struct vl_ycbcr_sampler_views *idct_views;
+   struct vl_ycbcr_sampler_views *idct_views, *mc_views;
    struct vl_ycbcr_surfaces *idct_surfaces;
 
    assert(ctx);
@@ -289,41 +310,6 @@ vl_mpeg12_create_buffer(struct pipe_video_context *vpipe)
    buffer->base.unmap = vl_mpeg12_buffer_unmap;
    buffer->base.flush = vl_mpeg12_buffer_flush;
 
-   memset(&res_template, 0, sizeof(res_template));
-   res_template.target = PIPE_TEXTURE_2D;
-   res_template.format = ctx->decode_format;
-   res_template.last_level = 0;
-   res_template.width0 = ctx->buffer_width;
-   res_template.height0 = ctx->buffer_height;
-   res_template.depth0 = 1;
-   res_template.array_size = 1;
-   res_template.usage = PIPE_USAGE_DEFAULT;
-   res_template.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
-   res_template.flags = 0;
-   resource = ctx->pipe->screen->resource_create(ctx->pipe->screen, &res_template);
-   if (!resource) {
-      FREE(buffer);
-      return NULL;
-   }
-
-   memset(&surf_template, 0, sizeof(surf_template));
-   surf_template.format = resource->format;
-   surf_template.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
-   buffer->surface = ctx->pipe->create_surface(ctx->pipe, resource, &surf_template);
-   if (!buffer->surface) {
-      FREE(buffer);
-      return NULL;
-   }
-
-   u_sampler_view_default_template(&sv_template, resource, resource->format);
-   buffer->sampler_view = ctx->pipe->create_sampler_view(ctx->pipe, resource, &sv_template);
-   if (!buffer->sampler_view) {
-      FREE(buffer);
-      return NULL;
-   }
-
-   pipe_resource_reference(&resource, NULL);
-
    buffer->vertex_bufs.individual.quad.stride = ctx->quads.stride;
    buffer->vertex_bufs.individual.quad.buffer_offset = ctx->quads.buffer_offset;
    pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, ctx->quads.buffer);
@@ -349,6 +335,15 @@ vl_mpeg12_create_buffer(struct pipe_video_context *vpipe)
       return NULL;
    }
 
+   if (!vl_ycbcr_buffer_init(&buffer->render_result, ctx->pipe,
+                             ctx->buffer_width, ctx->buffer_height,
+                             ctx->base.chroma_format,
+                             PIPE_FORMAT_R8_SNORM,
+                             PIPE_USAGE_STATIC)) {
+      FREE(buffer);
+      return NULL;
+   }
+
    idct_views = vl_ycbcr_get_sampler_views(&buffer->idct_source);
    idct_surfaces = vl_ycbcr_get_surfaces(&buffer->idct_2_mc);
 
@@ -370,10 +365,19 @@ vl_mpeg12_create_buffer(struct pipe_video_context *vpipe)
       return NULL;
    }
 
-   if(!vl_mpeg12_mc_init_buffer(&ctx->mc_renderer, &buffer->mc,
-                                buffer->idct_2_mc.resources.y,
-                                buffer->idct_2_mc.resources.cb,
-                                buffer->idct_2_mc.resources.cr)) {
+   mc_views = vl_ycbcr_get_sampler_views(&buffer->idct_2_mc);
+
+   if(!vl_mpeg12_mc_init_buffer(&ctx->mc_y, &buffer->mc_y, mc_views->y)) {
+      FREE(buffer);
+      return NULL;
+   }
+
+   if(!vl_mpeg12_mc_init_buffer(&ctx->mc_cb, &buffer->mc_cb, mc_views->cb)) {
+      FREE(buffer);
+      return NULL;
+   }
+
+   if(!vl_mpeg12_mc_init_buffer(&ctx->mc_cr, &buffer->mc_cr, mc_views->cr)) {
       FREE(buffer);
       return NULL;
    }
@@ -477,6 +481,7 @@ vl_mpeg12_render_picture(struct pipe_video_context     *vpipe,
 {
    struct vl_mpeg12_context *ctx = (struct vl_mpeg12_context*)vpipe;
    struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer*)src_surface;
+   struct vl_ycbcr_sampler_views *sampler_views;
 
    assert(vpipe);
    assert(src_surface);
@@ -484,8 +489,9 @@ vl_mpeg12_render_picture(struct pipe_video_context     *vpipe,
    assert(dst_surface);
    assert(dst_area);
 
-   vl_compositor_render(&ctx->compositor, buf->sampler_view,
-                        picture_type, src_area,
+   sampler_views = vl_ycbcr_get_sampler_views(&buf->render_result);
+
+   vl_compositor_render(&ctx->compositor, sampler_views, src_area,
                         dst_surface, dst_area, fence);
 }
 
@@ -631,14 +637,14 @@ init_idct(struct vl_mpeg12_context *ctx, unsigned buffer_width, unsigned buffer_
       chroma_blocks_y = 2;
    }
 
-   if(!vl_idct_init(&ctx->idct_cr, ctx->pipe, chroma_width, chroma_height,
-                    chroma_blocks_x, chroma_blocks_y, TGSI_SWIZZLE_Z, idct_matrix))
-      return false;
-
    if(!vl_idct_init(&ctx->idct_cb, ctx->pipe, chroma_width, chroma_height,
                     chroma_blocks_x, chroma_blocks_y, TGSI_SWIZZLE_Y, idct_matrix))
       return false;
 
+   if(!vl_idct_init(&ctx->idct_cr, ctx->pipe, chroma_width, chroma_height,
+                    chroma_blocks_x, chroma_blocks_y, TGSI_SWIZZLE_Z, idct_matrix))
+      return false;
+
    return true;
 }
 
@@ -701,9 +707,31 @@ vl_create_mpeg12_context(struct pipe_context *pipe,
       return NULL;
    }
 
-   if (!vl_mpeg12_mc_renderer_init(&ctx->mc_renderer, ctx->pipe,
+   if (!vl_mpeg12_mc_renderer_init(&ctx->mc_y, ctx->pipe,
+                                   ctx->buffer_width, ctx->buffer_height,
+                                   chroma_format, TGSI_SWIZZLE_X)) {
+      vl_idct_cleanup(&ctx->idct_y);
+      vl_idct_cleanup(&ctx->idct_cr);
+      vl_idct_cleanup(&ctx->idct_cb);
+      ctx->pipe->destroy(ctx->pipe);
+      FREE(ctx);
+      return NULL;
+   }
+
+   if (!vl_mpeg12_mc_renderer_init(&ctx->mc_cb, ctx->pipe,
+                                   ctx->buffer_width, ctx->buffer_height,
+                                   chroma_format, TGSI_SWIZZLE_Y)) {
+      vl_idct_cleanup(&ctx->idct_y);
+      vl_idct_cleanup(&ctx->idct_cr);
+      vl_idct_cleanup(&ctx->idct_cb);
+      ctx->pipe->destroy(ctx->pipe);
+      FREE(ctx);
+      return NULL;
+   }
+
+   if (!vl_mpeg12_mc_renderer_init(&ctx->mc_cr, ctx->pipe,
                                    ctx->buffer_width, ctx->buffer_height,
-                                   chroma_format)) {
+                                   chroma_format, TGSI_SWIZZLE_Z)) {
       vl_idct_cleanup(&ctx->idct_y);
       vl_idct_cleanup(&ctx->idct_cr);
       vl_idct_cleanup(&ctx->idct_cb);
@@ -716,7 +744,9 @@ vl_create_mpeg12_context(struct pipe_context *pipe,
       vl_idct_cleanup(&ctx->idct_y);
       vl_idct_cleanup(&ctx->idct_cr);
       vl_idct_cleanup(&ctx->idct_cb);
-      vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
+      vl_mpeg12_mc_renderer_cleanup(&ctx->mc_y);
+      vl_mpeg12_mc_renderer_cleanup(&ctx->mc_cb);
+      vl_mpeg12_mc_renderer_cleanup(&ctx->mc_cr);
       ctx->pipe->destroy(ctx->pipe);
       FREE(ctx);
       return NULL;
@@ -726,7 +756,9 @@ vl_create_mpeg12_context(struct pipe_context *pipe,
       vl_idct_cleanup(&ctx->idct_y);
       vl_idct_cleanup(&ctx->idct_cr);
       vl_idct_cleanup(&ctx->idct_cb);
-      vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
+      vl_mpeg12_mc_renderer_cleanup(&ctx->mc_y);
+      vl_mpeg12_mc_renderer_cleanup(&ctx->mc_cb);
+      vl_mpeg12_mc_renderer_cleanup(&ctx->mc_cr);
       vl_compositor_cleanup(&ctx->compositor);
       ctx->pipe->destroy(ctx->pipe);
       FREE(ctx);
index d1af5cd2ac378f182bf62cefa45d493bdbb59ffc..f84e23508edbfe94dc4ec555aee196c6dfc41f50 100644 (file)
@@ -51,8 +51,8 @@ struct vl_mpeg12_context
    unsigned vertex_buffer_size;
    void *vertex_elems_state;
 
-   struct vl_idct idct_y, idct_cr, idct_cb;
-   struct vl_mpeg12_mc_renderer mc_renderer;
+   struct vl_idct idct_y, idct_cb, idct_cr;
+   struct vl_mpeg12_mc_renderer mc_y, mc_cb, mc_cr;
    struct vl_compositor compositor;
 
    void *rast;
@@ -66,9 +66,7 @@ struct vl_mpeg12_buffer
 
    struct vl_ycbcr_buffer idct_source;
    struct vl_ycbcr_buffer idct_2_mc;
-
-   struct pipe_surface *surface;
-   struct pipe_sampler_view *sampler_view;
+   struct vl_ycbcr_buffer render_result;
 
    struct vl_vertex_buffer vertex_stream;
 
@@ -81,8 +79,7 @@ struct vl_mpeg12_buffer
    } vertex_bufs;
 
    struct vl_idct_buffer idct_y, idct_cb, idct_cr;
-
-   struct vl_mpeg12_mc_buffer mc;
+   struct vl_mpeg12_mc_buffer mc_y, mc_cb, mc_cr;
 };
 
 /* drivers can call this function in their pipe_video_context constructors and pass it
index d2ed7470598001159b4f496c08a28c227959c92c..7c3fea557abca104dc0614d34bcc94b9c5efaf72 100644 (file)
@@ -217,11 +217,11 @@ calc_field(struct ureg_program *shader)
 }
 
 static struct ureg_dst
-fetch_ycbcr(struct vl_mpeg12_mc_renderer *r, struct ureg_program *shader, struct ureg_dst field)
+fetch_ycbcr(struct vl_mpeg12_mc_renderer *r, struct ureg_program *shader, struct ureg_dst field, unsigned color_swizzle)
 {
-   struct ureg_src tc[3], sampler[3], eb[2];
+   struct ureg_src tc[3], sampler, eb[2];
    struct ureg_dst texel, t_tc, t_eb_info;
-   unsigned i, label;
+   unsigned label;
 
    texel = ureg_DECL_temporary(shader);
    t_tc = ureg_DECL_temporary(shader);
@@ -234,9 +234,10 @@ fetch_ycbcr(struct vl_mpeg12_mc_renderer *r, struct ureg_program *shader, struct
    eb[0] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_EB_0, TGSI_INTERPOLATE_CONSTANT);
    eb[1] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_EB_1, TGSI_INTERPOLATE_CONSTANT);
 
-   for (i = 0; i < 3; ++i)  {
-      sampler[i] = ureg_DECL_sampler(shader, i);
-   }
+   //for (i = 0; i < 3; ++i)  {
+   //   sampler[i] = ureg_DECL_sampler(shader, i);
+   //}
+   sampler = ureg_DECL_sampler(shader, 0);
 
    /*
     * texel.y  = tex(field.y ? tc[1] : tc[0], sampler[0])
@@ -256,19 +257,16 @@ fetch_ycbcr(struct vl_mpeg12_mc_renderer *r, struct ureg_program *shader, struct
    ureg_SLT(shader, ureg_writemask(t_eb_info, TGSI_WRITEMASK_XYZ), ureg_src(t_eb_info), ureg_imm1f(shader, 0.5f));
 
    ureg_MOV(shader, ureg_writemask(texel, TGSI_WRITEMASK_XYZ), ureg_imm1f(shader, 0.0f));
-   for (i = 0; i < 3; ++i) {
-      ureg_IF(shader, ureg_scalar(ureg_src(t_eb_info), TGSI_SWIZZLE_X + i), &label);
+   ureg_IF(shader, ureg_scalar(ureg_src(t_eb_info), color_swizzle), &label);
 
-         /* Nouveau can't writemask tex dst regs (yet?), so this won't work anymore on nvidia hardware */
-         if(i==0 || r->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444) {
-            ureg_TEX(shader, ureg_writemask(texel, TGSI_WRITEMASK_X << i), TGSI_TEXTURE_3D, ureg_src(t_tc), sampler[i]);
-         } else {
-            ureg_TEX(shader, ureg_writemask(texel, TGSI_WRITEMASK_X << i), TGSI_TEXTURE_3D, tc[2], sampler[i]);
-         }
+      if(color_swizzle==TGSI_SWIZZLE_X || r->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444) {
+         ureg_TEX(shader, texel, TGSI_TEXTURE_3D, ureg_src(t_tc), sampler);
+      } else {
+         ureg_TEX(shader, texel, TGSI_TEXTURE_3D, tc[2], sampler);
+      }
 
-      ureg_fixup_label(shader, label, ureg_get_instruction_number(shader));
-      ureg_ENDIF(shader);
-   }
+   ureg_fixup_label(shader, label, ureg_get_instruction_number(shader));
+   ureg_ENDIF(shader);
 
    ureg_release_temporary(shader, t_tc);
    ureg_release_temporary(shader, t_eb_info);
@@ -290,13 +288,13 @@ fetch_ref(struct ureg_program *shader, struct ureg_dst field)
       tc[i] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_MV0 + i, TGSI_INTERPOLATE_LINEAR);
 
    for (i = 0; i < 2; ++i) {
-      sampler[i] = ureg_DECL_sampler(shader, i + 3);
+      sampler[i] = ureg_DECL_sampler(shader, i + 1);
       ref[i] = ureg_DECL_temporary(shader);
    }
 
    result = ureg_DECL_temporary(shader);
 
-   ureg_MOV(shader, ureg_writemask(result, TGSI_WRITEMASK_XYZ), ureg_imm1f(shader, 0.5f));
+   ureg_MOV(shader, result, ureg_imm1f(shader, 0.5f));
 
    ureg_IF(shader, ureg_scalar(info, TGSI_SWIZZLE_X), &intra_label);
       /*
@@ -316,7 +314,7 @@ fetch_ref(struct ureg_program *shader, struct ureg_dst field)
       ureg_TEX(shader, ref[0], TGSI_TEXTURE_2D, ureg_src(ref[0]), sampler[0]);
       ureg_TEX(shader, ref[1], TGSI_TEXTURE_2D, ureg_src(ref[1]), sampler[1]);
 
-      ureg_LRP(shader, ureg_writemask(result, TGSI_WRITEMASK_XYZ),
+      ureg_LRP(shader, result,
                ureg_scalar(info, TGSI_SWIZZLE_Y),
                ureg_src(ref[1]), ureg_src(ref[0]));
 
@@ -330,7 +328,7 @@ fetch_ref(struct ureg_program *shader, struct ureg_dst field)
 }
 
 static void *
-create_frag_shader(struct vl_mpeg12_mc_renderer *r)
+create_frag_shader(struct vl_mpeg12_mc_renderer *r, unsigned color_swizzle)
 {
    struct ureg_program *shader;
    struct ureg_dst result;
@@ -344,11 +342,11 @@ create_frag_shader(struct vl_mpeg12_mc_renderer *r)
    fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
 
    field = calc_field(shader);
-   texel = fetch_ycbcr(r, shader, field);
+   texel = fetch_ycbcr(r, shader, field, color_swizzle);
 
    result = fetch_ref(shader, field);
 
-   ureg_ADD(shader, ureg_writemask(fragment, TGSI_WRITEMASK_XYZ), ureg_src(texel), ureg_src(result));
+   ureg_ADD(shader, fragment, ureg_src(texel), ureg_src(result));
 
    ureg_release_temporary(shader, field);
    ureg_release_temporary(shader, texel);
@@ -363,13 +361,11 @@ init_pipe_state(struct vl_mpeg12_mc_renderer *r)
 {
    struct pipe_sampler_state sampler;
    struct pipe_rasterizer_state rs_state;
-   unsigned filters[5];
+   unsigned filters[3];
    unsigned i;
 
    assert(r);
 
-   r->viewport.scale[0] = r->buffer_width;
-   r->viewport.scale[1] = r->buffer_height;
    r->viewport.scale[2] = 1;
    r->viewport.scale[3] = 1;
    r->viewport.translate[0] = 0;
@@ -377,27 +373,17 @@ init_pipe_state(struct vl_mpeg12_mc_renderer *r)
    r->viewport.translate[2] = 0;
    r->viewport.translate[3] = 0;
 
-   r->fb_state.width = r->buffer_width;
-   r->fb_state.height = r->buffer_height;
    r->fb_state.nr_cbufs = 1;
    r->fb_state.zsbuf = NULL;
 
-   /* Luma filter */
+   /* source filter */
    filters[0] = PIPE_TEX_FILTER_NEAREST;
-   /* Chroma filters */
-   if (r->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444 || true) { //TODO
-      filters[1] = PIPE_TEX_FILTER_NEAREST;
-      filters[2] = PIPE_TEX_FILTER_NEAREST;
-   }
-   else {
-      filters[1] = PIPE_TEX_FILTER_LINEAR;
-      filters[2] = PIPE_TEX_FILTER_LINEAR;
-   }
+
    /* Fwd, bkwd ref filters */
-   filters[3] = PIPE_TEX_FILTER_LINEAR;
-   filters[4] = PIPE_TEX_FILTER_LINEAR;
+   filters[1] = PIPE_TEX_FILTER_LINEAR;
+   filters[2] = PIPE_TEX_FILTER_LINEAR;
 
-   for (i = 0; i < 5; ++i) {
+   for (i = 0; i < 3; ++i) {
       memset(&sampler, 0, sizeof(sampler));
       sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
       sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
@@ -448,7 +434,7 @@ cleanup_pipe_state(struct vl_mpeg12_mc_renderer *r)
 
    assert(r);
 
-   for (i = 0; i < 5; ++i)
+   for (i = 0; i < 3; ++i)
       r->pipe->delete_sampler_state(r->pipe, r->samplers.all[i]);
 
    r->pipe->delete_rasterizer_state(r->pipe, r->rs_state);
@@ -459,7 +445,8 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
                            struct pipe_context *pipe,
                            unsigned buffer_width,
                            unsigned buffer_height,
-                           enum pipe_video_chroma_format chroma_format)
+                           enum pipe_video_chroma_format chroma_format,
+                           unsigned color_swizzle)
 {
    struct pipe_resource tex_templ, *tex_dummy;
    struct pipe_sampler_view sampler_view;
@@ -481,7 +468,7 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
    if (!renderer->vs)
       goto error_vs_shaders;
 
-   renderer->fs = create_frag_shader(renderer);
+   renderer->fs = create_frag_shader(renderer, color_swizzle);
    if (!renderer->fs)
       goto error_fs_shaders;
 
@@ -539,40 +526,14 @@ vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer)
 
 bool
 vl_mpeg12_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer,
-                         struct pipe_resource *y, struct pipe_resource *cb, struct pipe_resource *cr)
+                         struct pipe_sampler_view *source)
 {
-   struct pipe_sampler_view sampler_view;
-   struct pipe_resource *res[3];
-
-   unsigned i;
-
    assert(renderer && buffer);
-   assert(y && cb && cr);
+   assert(source);
 
-   res[0] = y;
-   res[1] = cb;
-   res[2] = cr;
-
-   for (i = 0; i < 3; ++i) {
-      memset(&sampler_view, 0, sizeof(sampler_view));
-      u_sampler_view_default_template(&sampler_view, res[i], res[i]->format);
-      sampler_view.swizzle_r = i == 0 ? PIPE_SWIZZLE_RED : PIPE_SWIZZLE_ZERO;
-      sampler_view.swizzle_g = i == 1 ? PIPE_SWIZZLE_RED : PIPE_SWIZZLE_ZERO;
-      sampler_view.swizzle_b = i == 2 ? PIPE_SWIZZLE_RED : PIPE_SWIZZLE_ZERO;
-      sampler_view.swizzle_a = PIPE_SWIZZLE_ONE;
-      buffer->sampler_views.all[i] = renderer->pipe->create_sampler_view(
-         renderer->pipe, res[i], &sampler_view);
-      if (!buffer->sampler_views.all[i])
-         goto error_samplers;
-   }
+   pipe_sampler_view_reference(&buffer->sampler_views.individual.source, source);
 
    return true;
-
-error_samplers:
-   for (i = 0; i < 3; ++i)
-      pipe_sampler_view_reference(&buffer->sampler_views.all[i], NULL);
-
-   return false;
 }
 
 void
@@ -582,7 +543,7 @@ vl_mpeg12_mc_cleanup_buffer(struct vl_mpeg12_mc_buffer *buffer)
 
    assert(buffer);
 
-   for (i = 0; i < 5; ++i)
+   for (i = 0; i < 3; ++i)
       pipe_sampler_view_reference(&buffer->sampler_views.all[i], NULL);
 }
 
@@ -599,7 +560,14 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mp
    if (not_empty_num_instances == 0 && empty_num_instances == 0)
       return;
 
+   renderer->viewport.scale[0] = surface->width;
+   renderer->viewport.scale[1] = surface->height;
+
+   renderer->fb_state.width = surface->width;
+   renderer->fb_state.height = surface->height;
    renderer->fb_state.cbufs[0] = surface;
+
+
    renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state);
    renderer->pipe->set_framebuffer_state(renderer->pipe, &renderer->fb_state);
    renderer->pipe->set_viewport_state(renderer->pipe, &renderer->viewport);
@@ -610,8 +578,8 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mp
    pipe_sampler_view_reference(&buffer->sampler_views.individual.ref[1],
                                ref[1] ? ref[1] : renderer->dummy);
 
-   renderer->pipe->set_fragment_sampler_views(renderer->pipe, 5, buffer->sampler_views.all);
-   renderer->pipe->bind_fragment_sampler_states(renderer->pipe, 5, renderer->samplers.all);
+   renderer->pipe->set_fragment_sampler_views(renderer->pipe, 3, buffer->sampler_views.all);
+   renderer->pipe->bind_fragment_sampler_states(renderer->pipe, 3, renderer->samplers.all);
 
    renderer->pipe->bind_vs_state(renderer->pipe, renderer->vs);
    renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs);
index 0bb17ef487b691cbd3bef0cbe6020c682cee4bcc..0a204d637b048bf2ddfb1dbc81308334727450ec 100644 (file)
@@ -53,8 +53,8 @@ struct vl_mpeg12_mc_renderer
 
    union
    {
-      void *all[5];
-      struct { void *y, *cb, *cr, *ref[2]; } individual;
+      void *all[3];
+      struct { void *source, *ref[2]; } individual;
    } samplers;
 
    struct pipe_sampler_view *dummy;
@@ -64,8 +64,8 @@ struct vl_mpeg12_mc_buffer
 {
    union
    {
-      struct pipe_sampler_view *all[5];
-      struct { struct pipe_sampler_view *y, *cb, *cr, *ref[2]; } individual;
+      struct pipe_sampler_view *all[3];
+      struct { struct pipe_sampler_view *source, *ref[2]; } individual;
    } sampler_views;
 };
 
@@ -73,12 +73,13 @@ bool vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
                                 struct pipe_context *pipe,
                                 unsigned picture_width,
                                 unsigned picture_height,
-                                enum pipe_video_chroma_format chroma_format);
+                                enum pipe_video_chroma_format chroma_format,
+                                unsigned color_swizzle);
 
 void vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer);
 
 bool vl_mpeg12_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer,
-                              struct pipe_resource *y, struct pipe_resource *cb, struct pipe_resource *cr);
+                              struct pipe_sampler_view *source);
 
 void vl_mpeg12_mc_cleanup_buffer(struct vl_mpeg12_mc_buffer *buffer);
 
index 56183891f9b9015481e9b71a5cac16aeb7a1dcfc..846e1cda1ae23deb762e2bd163a8b036e4cbb720 100644 (file)
@@ -97,25 +97,29 @@ struct vl_ycbcr_sampler_views *vl_ycbcr_get_sampler_views(struct vl_ycbcr_buffer
 
    pipe = buffer->pipe;
 
+   memset(&sv_templ, 0, sizeof(sv_templ));
+   u_sampler_view_default_template(&sv_templ, buffer->resources.y, buffer->resources.y->format);
+
+   // Workaround
+   if (util_format_get_nr_components(buffer->resources.y->format) == 1) {
+      sv_templ.swizzle_r = PIPE_SWIZZLE_RED;
+      sv_templ.swizzle_g = PIPE_SWIZZLE_RED;
+      sv_templ.swizzle_b = PIPE_SWIZZLE_RED;
+   }
+
    if (!buffer->sampler_views.y) {
-      memset(&sv_templ, 0, sizeof(sv_templ));
-      u_sampler_view_default_template(&sv_templ, buffer->resources.y, buffer->resources.y->format);
       buffer->sampler_views.y = pipe->create_sampler_view(pipe, buffer->resources.y, &sv_templ);
       if (!buffer->sampler_views.y)
          goto error;
    }
 
    if (!buffer->sampler_views.cb) {
-      memset(&sv_templ, 0, sizeof(sv_templ));
-      u_sampler_view_default_template(&sv_templ, buffer->resources.cb, buffer->resources.cb->format);
       buffer->sampler_views.cb = pipe->create_sampler_view(pipe, buffer->resources.cb, &sv_templ);
       if (!buffer->sampler_views.cb)
          goto error;
    }
 
    if (!buffer->sampler_views.cr) {
-      memset(&sv_templ, 0, sizeof(sv_templ));
-      u_sampler_view_default_template(&sv_templ, buffer->resources.cr, buffer->resources.cr->format);
       buffer->sampler_views.cr = pipe->create_sampler_view(pipe, buffer->resources.cr, &sv_templ);
       if (!buffer->sampler_views.cr)
          goto error;