[Mesa-dev] [PATCH] st/vdpau: use temporary buffers while applying filters

Nayan Deshmukh nayan26deshmukh at gmail.com
Tue Aug 16 09:23:29 UTC 2016


We temporary buffers so that we don't read and write to the
same surface at the same time.

Signed-off-by: Nayan Deshmukh <nayan26deshmukh at gmail.com>
---
 src/gallium/state_trackers/vdpau/mixer.c | 54 ++++++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 9 deletions(-)

diff --git a/src/gallium/state_trackers/vdpau/mixer.c b/src/gallium/state_trackers/vdpau/mixer.c
index 56b667d..ff6750f 100644
--- a/src/gallium/state_trackers/vdpau/mixer.c
+++ b/src/gallium/state_trackers/vdpau/mixer.c
@@ -239,9 +239,10 @@ VdpStatus vlVdpVideoMixerRender(VdpVideoMixer mixer,
    enum vl_compositor_deinterlace deinterlace;
    struct u_rect rect, clip, *prect, dirty_area;
    unsigned i, layer = 0;
-   struct pipe_video_buffer *video_buffer;
+   struct pipe_video_buffer *video_buffer, templ, *video_buffer_output, *video_buffer_temp = NULL;
    struct pipe_sampler_view *sampler_view, **sampler_views;
    struct pipe_surface *surface, **surfaces;
+   struct pipe_context *pipe;
 
    vlVdpVideoMixer *vmixer;
    vlVdpSurface *surf;
@@ -325,19 +326,48 @@ VdpStatus vlVdpVideoMixerRender(VdpVideoMixer mixer,
       }
    }
 
-   surfaces = video_buffer->get_surfaces(video_buffer);
-   sampler_views = video_buffer->get_sampler_view_planes(video_buffer);
+   video_buffer_output = video_buffer;
 
-   for(i = 0; i < VL_MAX_SURFACES; ++i) {
-      if(sampler_views[i] != NULL && surfaces[i] != NULL) {
-         if (vmixer->noise_reduction.filter)
+   if (vmixer->noise_reduction.filter || vmixer->sharpness.filter) {
+      pipe = vmixer->device->context;
+
+      memset(&templ, 0, sizeof(templ));
+      templ.buffer_format = video_buffer->buffer_format;
+      templ.chroma_format = video_buffer->chroma_format;
+      templ.width = video_buffer->width;
+      templ.height = video_buffer->height;
+      templ.interlaced = video_buffer->interlaced;
+
+   }
+
+   if (vmixer->noise_reduction.filter) {
+      sampler_views = video_buffer->get_sampler_view_planes(video_buffer_output);
+      video_buffer_output = vl_video_buffer_create(pipe, &templ);
+      surfaces = video_buffer_output->get_surfaces(video_buffer_output);
+
+      for(i = 0; i < VL_MAX_SURFACES; ++i) {
+         if(sampler_views[i] != NULL && surfaces[i] != NULL)
             vl_median_filter_render(vmixer->noise_reduction.filter,
                                     sampler_views[i], surfaces[i]);
+      }
+   }
 
-         if (vmixer->sharpness.filter)
+   if (vmixer->sharpness.filter) {
+      sampler_views = video_buffer_output->get_sampler_view_planes(video_buffer_output);
+      /*
+       * To keep a pointer to the buffer allocated
+       * if noise reduction is enabled so that it
+       * can be destroyed in the end
+       */
+      if (video_buffer_output != video_buffer)
+         video_buffer_temp = video_buffer_output;
+      video_buffer_output = vl_video_buffer_create(pipe, &templ);
+      surfaces = video_buffer_output->get_surfaces(video_buffer_output);
+
+      for (i = 0; i < VL_MAX_SURFACES; ++i) {
+         if (sampler_views[i] != NULL && surfaces[i] != NULL)
             vl_matrix_filter_render(vmixer->sharpness.filter,
                                     sampler_views[i], surfaces[i]);
-
       }
    }
 
@@ -349,7 +379,7 @@ VdpStatus vlVdpVideoMixerRender(VdpVideoMixer mixer,
       rect.y1 = surf->templat.height;
       prect = ▭
    }
-   vl_compositor_set_buffer_layer(&vmixer->cstate, compositor, layer, video_buffer, prect, NULL, deinterlace);
+   vl_compositor_set_buffer_layer(&vmixer->cstate, compositor, layer, video_buffer_output, prect, NULL, deinterlace);
 
    if(vmixer->bicubic.filter) {
       struct pipe_context *pipe;
@@ -421,6 +451,12 @@ VdpStatus vlVdpVideoMixerRender(VdpVideoMixer mixer,
          pipe_surface_reference(&surface, NULL);
       }
    }
+
+   if(video_buffer_output != video_buffer)
+      video_buffer_output->destroy(video_buffer_output);
+   if(video_buffer_temp != NULL)
+      video_buffer_temp->destroy(video_buffer_temp);
+
    pipe_mutex_unlock(vmixer->device->mutex);
 
    return VDP_STATUS_OK;
-- 
2.7.4



More information about the mesa-dev mailing list