[g3dvl] move mc fb and viewport handling into buffer object
authorChristian König <deathsimple@vodafone.de>
Sat, 16 Apr 2011 11:40:19 +0000 (13:40 +0200)
committerChristian König <deathsimple@vodafone.de>
Sat, 16 Apr 2011 11:40:19 +0000 (13:40 +0200)
src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h

index 9e89730a23d91b24c418116ecce774fc402db362..64127cf2d697c9a73b6a82a720199fafb6dbf915 100644 (file)
@@ -480,16 +480,13 @@ vl_mpeg12_decoder_flush_buffer(struct pipe_video_decode_buffer *buffer,
    dec->pipe->set_vertex_buffers(dec->pipe, 2, buf->vertex_bufs.all);
 
    for (i = 0; i < VL_MAX_PLANES; ++i) {
-      bool first = true;
-
-      vl_mc_set_surface(i == 0 ? &dec->mc_y : &dec->mc_c, surfaces[i]);
+      vl_mc_set_surface(&buf->mc[i], surfaces[i]);
 
       for (j = 0; j < 2; ++j) {
          if (sv[j] == NULL) continue;
 
          dec->pipe->bind_vertex_elements_state(dec->pipe, dec->ves_mv[j]);
-         vl_mc_render_ref(&buf->mc[i], sv[j][i], first, ne_start, ne_num, e_start, e_num);
-         first = false;
+         vl_mc_render_ref(&buf->mc[i], sv[j][i], ne_start, ne_num, e_start, e_num);
       }
 
       dec->pipe->bind_blend_state(dec->pipe, dec->blend);
@@ -498,7 +495,7 @@ vl_mpeg12_decoder_flush_buffer(struct pipe_video_decode_buffer *buffer,
       if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT)
          vl_idct_flush(i == 0 ? &dec->idct_y : &dec->idct_c, &buf->idct[i], ne_num);
 
-      vl_mc_render_ycbcr(&buf->mc[i], first, ne_start, ne_num);
+      vl_mc_render_ycbcr(&buf->mc[i], ne_start, ne_num);
 
    }
    dec->pipe->flush(dec->pipe, fence);
index 65909a57b262648b79395e28af80497aa691aa29..8102aed838ec4651d71e826ba40501140a37dcfe 100644 (file)
@@ -366,16 +366,6 @@ init_pipe_state(struct vl_mpeg12_mc_renderer *r)
 
    assert(r);
 
-   r->viewport.scale[2] = 1;
-   r->viewport.scale[3] = 1;
-   r->viewport.translate[0] = 0;
-   r->viewport.translate[1] = 0;
-   r->viewport.translate[2] = 0;
-   r->viewport.translate[3] = 0;
-
-   r->fb_state.nr_cbufs = 1;
-   r->fb_state.zsbuf = NULL;
-
    memset(&sampler, 0, sizeof(sampler));
    sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
    sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
@@ -563,6 +553,16 @@ vl_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_bu
 
    buffer->renderer = renderer;
 
+   buffer->viewport.scale[2] = 1;
+   buffer->viewport.scale[3] = 1;
+   buffer->viewport.translate[0] = 0;
+   buffer->viewport.translate[1] = 0;
+   buffer->viewport.translate[2] = 0;
+   buffer->viewport.translate[3] = 0;
+
+   buffer->fb_state.nr_cbufs = 1;
+   buffer->fb_state.zsbuf = NULL;
+
    pipe_sampler_view_reference(&buffer->source, source);
 
    return true;
@@ -577,21 +577,43 @@ vl_mc_cleanup_buffer(struct vl_mpeg12_mc_buffer *buffer)
 }
 
 void
-vl_mc_set_surface(struct vl_mpeg12_mc_renderer *renderer, struct pipe_surface *surface)
+vl_mc_set_surface(struct vl_mpeg12_mc_buffer *buffer, struct pipe_surface *surface)
+{
+   assert(buffer && surface);
+
+   buffer->surface_cleared = false;
+
+   buffer->viewport.scale[0] = surface->width;
+   buffer->viewport.scale[1] = surface->height;
+
+   buffer->fb_state.width = surface->width;
+   buffer->fb_state.height = surface->height;
+   buffer->fb_state.cbufs[0] = surface;
+}
+
+static void
+prepare_pipe_4_rendering(struct vl_mpeg12_mc_buffer *buffer)
 {
-   assert(renderer && surface);
+   struct vl_mpeg12_mc_renderer *renderer;
+
+   assert(buffer);
 
-   renderer->viewport.scale[0] = surface->width;
-   renderer->viewport.scale[1] = surface->height;
+   renderer = buffer->renderer;
+   renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state);
 
-   renderer->fb_state.width = surface->width;
-   renderer->fb_state.height = surface->height;
-   renderer->fb_state.cbufs[0] = surface;
+   if (buffer->surface_cleared)
+      renderer->pipe->bind_blend_state(renderer->pipe, renderer->blend_add);
+   else {
+      renderer->pipe->bind_blend_state(renderer->pipe, renderer->blend_clear);
+      buffer->surface_cleared = true;
+   }
+
+   renderer->pipe->set_framebuffer_state(renderer->pipe, &buffer->fb_state);
+   renderer->pipe->set_viewport_state(renderer->pipe, &buffer->viewport);
 }
 
 void
-vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer,
-                 struct pipe_sampler_view *ref, bool first,
+vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer, struct pipe_sampler_view *ref,
                  unsigned not_empty_start_instance, unsigned not_empty_num_instances,
                  unsigned empty_start_instance, unsigned empty_num_instances)
 {
@@ -602,11 +624,9 @@ vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer,
    if (not_empty_num_instances == 0 && empty_num_instances == 0)
       return;
 
+   prepare_pipe_4_rendering(buffer);
+
    renderer = buffer->renderer;
-   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);
-   renderer->pipe->bind_blend_state(renderer->pipe, first ? renderer->blend_clear : renderer->blend_add);
 
    renderer->pipe->bind_vs_state(renderer->pipe, renderer->vs_ref);
    renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs_ref);
@@ -624,7 +644,7 @@ vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer,
 }
 
 void
-vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer, bool first,
+vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer,
                    unsigned not_empty_start_instance, unsigned not_empty_num_instances)
 {
    struct vl_mpeg12_mc_renderer *renderer;
@@ -634,11 +654,9 @@ vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer, bool first,
    if (not_empty_num_instances == 0)
       return;
 
+   prepare_pipe_4_rendering(buffer);
+
    renderer = buffer->renderer;
-   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);
-   renderer->pipe->bind_blend_state(renderer->pipe, first ? renderer->blend_clear : renderer->blend_add);
 
    renderer->pipe->bind_vs_state(renderer->pipe, renderer->vs_ycbcr);
    renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs_ycbcr);
index d6561369e28a45bd1916c96b4c4ad3d7de6c13ad..f67f97a71fc22a1228dbabe0e99c4c9a06f55a12 100644 (file)
@@ -41,9 +41,6 @@ struct vl_mpeg12_mc_renderer
    unsigned buffer_width;
    unsigned buffer_height;
 
-   struct pipe_viewport_state viewport;
-   struct pipe_framebuffer_state fb_state;
-
    void *rs_state;
 
    void *blend_clear, *blend_add;
@@ -57,6 +54,12 @@ struct vl_mpeg12_mc_renderer
 struct vl_mpeg12_mc_buffer
 {
    struct vl_mpeg12_mc_renderer *renderer;
+
+   bool surface_cleared;
+
+   struct pipe_viewport_state viewport;
+   struct pipe_framebuffer_state fb_state;
+
    struct pipe_sampler_view *source;
 };
 
@@ -70,14 +73,13 @@ bool vl_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_
 
 void vl_mc_cleanup_buffer(struct vl_mpeg12_mc_buffer *buffer);
 
-void vl_mc_set_surface(struct vl_mpeg12_mc_renderer *renderer, struct pipe_surface *surface);
+void vl_mc_set_surface(struct vl_mpeg12_mc_buffer *buffer, struct pipe_surface *surface);
 
-void vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer,
-                      struct pipe_sampler_view *ref, bool first,
+void vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer, struct pipe_sampler_view *ref,
                       unsigned not_empty_start_instance, unsigned not_empty_num_instances,
                       unsigned empty_start_instance, unsigned empty_num_instances);
 
-void vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer, bool first,
+void vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer,
                         unsigned not_empty_start_instance, unsigned not_empty_num_instances);
 
 #endif /* vl_mpeg12_mc_renderer_h */