[Mesa-dev] [PATCH 7/7] vl: fix a buffer leak in the bicubic filter by using an uploader
Nicolai Hähnle
nhaehnle at gmail.com
Thu Feb 16 14:58:24 UTC 2017
On 16.02.2017 13:52, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> there's no error checking, because the previous code didn't do it either.
> ---
> src/gallium/auxiliary/vl/vl_bicubic_filter.c | 27 +++++++++++----------------
> 1 file changed, 11 insertions(+), 16 deletions(-)
>
> diff --git a/src/gallium/auxiliary/vl/vl_bicubic_filter.c b/src/gallium/auxiliary/vl/vl_bicubic_filter.c
> index 774702c..d300034 100644
> --- a/src/gallium/auxiliary/vl/vl_bicubic_filter.c
> +++ b/src/gallium/auxiliary/vl/vl_bicubic_filter.c
> @@ -28,20 +28,21 @@
> #include <stdio.h>
>
> #include "pipe/p_context.h"
>
> #include "tgsi/tgsi_ureg.h"
>
> #include "util/u_draw.h"
> #include "util/u_memory.h"
> #include "util/u_math.h"
> #include "util/u_rect.h"
> +#include "util/u_upload_mgr.h"
>
> #include "vl_types.h"
> #include "vl_vertex_buffers.h"
> #include "vl_bicubic_filter.h"
>
> enum VS_OUTPUT
> {
> VS_O_VPOS = 0,
> VS_O_VTEX = 0
> };
> @@ -377,78 +378,72 @@ void
> vl_bicubic_filter_render(struct vl_bicubic_filter *filter,
> struct pipe_sampler_view *src,
> struct pipe_surface *dst,
> struct u_rect *dst_area,
> struct u_rect *dst_clip)
> {
> struct pipe_viewport_state viewport;
> struct pipe_framebuffer_state fb_state;
> struct pipe_scissor_state scissor;
> union pipe_color_union clear_color;
> - struct pipe_transfer *buf_transfer;
> - struct pipe_resource *surface_size;
> +
> assert(filter && src && dst);
>
> if (dst_clip) {
> scissor.minx = dst_clip->x0;
> scissor.miny = dst_clip->y0;
> scissor.maxx = dst_clip->x1;
> scissor.maxy = dst_clip->y1;
> } else {
> scissor.minx = 0;
> scissor.miny = 0;
> scissor.maxx = dst->width;
> scissor.maxy = dst->height;
> }
>
> clear_color.f[0] = clear_color.f[1] = 0.0f;
> clear_color.f[2] = clear_color.f[3] = 0.0f;
> - surface_size = pipe_buffer_create
> - (
> - filter->pipe->screen,
> - PIPE_BIND_CONSTANT_BUFFER,
> - PIPE_USAGE_DEFAULT,
> - 2*sizeof(float)
> - );
> -
>
> memset(&viewport, 0, sizeof(viewport));
> if(dst_area){
> viewport.scale[0] = dst_area->x1 - dst_area->x0;
> viewport.scale[1] = dst_area->y1 - dst_area->y0;
> viewport.translate[0] = dst_area->x0;
> viewport.translate[1] = dst_area->y0;
> } else {
> viewport.scale[0] = dst->width;
> viewport.scale[1] = dst->height;
> }
> viewport.scale[2] = 1;
>
> - float *ptr = pipe_buffer_map(filter->pipe, surface_size,
> - PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE,
> - &buf_transfer);
> + struct pipe_constant_buffer cb = {};
> + float *ptr;
> +
> + u_upload_alloc(filter->pipe->const_uploader, 0, 2 * sizeof(float), 256,
> + &cb.buffer_offset, &cb.buffer, (void**)&ptr);
> + cb.buffer_size = cb.buffer->width0 - cb.buffer_offset;
2 * sizeof(float)
With that, the series is
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
>
> ptr[0] = 0.5f/viewport.scale[0];
> ptr[1] = 0.5f/viewport.scale[1];
> -
> - pipe_buffer_unmap(filter->pipe, buf_transfer);
> + u_upload_unmap(filter->pipe->const_uploader);
>
> memset(&fb_state, 0, sizeof(fb_state));
> fb_state.width = dst->width;
> fb_state.height = dst->height;
> fb_state.nr_cbufs = 1;
> fb_state.cbufs[0] = dst;
>
> filter->pipe->set_scissor_states(filter->pipe, 0, 1, &scissor);
> filter->pipe->clear_render_target(filter->pipe, dst, &clear_color,
> 0, 0, dst->width, dst->height, false);
> - pipe_set_constant_buffer(filter->pipe, PIPE_SHADER_FRAGMENT, 0, surface_size);
> + filter->pipe->set_constant_buffer(filter->pipe, PIPE_SHADER_FRAGMENT,
> + 0, &cb);
> filter->pipe->bind_rasterizer_state(filter->pipe, filter->rs_state);
> filter->pipe->bind_blend_state(filter->pipe, filter->blend);
> filter->pipe->bind_sampler_states(filter->pipe, PIPE_SHADER_FRAGMENT,
> 0, 1, &filter->sampler);
> filter->pipe->set_sampler_views(filter->pipe, PIPE_SHADER_FRAGMENT,
> 0, 1, &src);
> filter->pipe->bind_vs_state(filter->pipe, filter->vs);
> filter->pipe->bind_fs_state(filter->pipe, filter->fs);
> filter->pipe->set_framebuffer_state(filter->pipe, &fb_state);
> filter->pipe->set_viewport_states(filter->pipe, 0, 1, &viewport);
>
More information about the mesa-dev
mailing list