[Mesa-dev] [PATCH 1/2] gallium/pp: use user constant buffers

Ilia Mirkin imirkin at alum.mit.edu
Wed Apr 4 21:41:09 UTC 2018


While I don't see anything obviously wrong in this patch, I also don't
see any issues in the old code. What API misuse is this dealing with?

On Wed, Apr 4, 2018 at 4:11 PM, Marek Olšák <maraeo at gmail.com> wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> This fixes a radeonsi crash.
> ---
>  src/gallium/auxiliary/cso_cache/cso_context.c  | 17 ++++++++++++
>  src/gallium/auxiliary/cso_cache/cso_context.h  |  3 +++
>  src/gallium/auxiliary/postprocess/pp_mlaa.c    | 37 ++++----------------------
>  src/gallium/auxiliary/postprocess/pp_private.h |  1 -
>  4 files changed, 25 insertions(+), 33 deletions(-)
>
> diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
> index 3fa57f16ff4..3a3a63a3327 100644
> --- a/src/gallium/auxiliary/cso_cache/cso_context.c
> +++ b/src/gallium/auxiliary/cso_cache/cso_context.c
> @@ -1540,20 +1540,37 @@ cso_set_constant_buffer_resource(struct cso_context *cso,
>        cb.buffer = buffer;
>        cb.buffer_offset = 0;
>        cb.buffer_size = buffer->width0;
>        cb.user_buffer = NULL;
>        cso_set_constant_buffer(cso, shader_stage, index, &cb);
>     } else {
>        cso_set_constant_buffer(cso, shader_stage, index, NULL);
>     }
>  }
>
> +void
> +cso_set_constant_user_buffer(struct cso_context *cso,
> +                             enum pipe_shader_type shader_stage,
> +                             unsigned index, void *ptr, unsigned size)
> +{
> +   if (ptr) {
> +      struct pipe_constant_buffer cb;
> +      cb.buffer = NULL;
> +      cb.buffer_offset = 0;
> +      cb.buffer_size = size;
> +      cb.user_buffer = ptr;
> +      cso_set_constant_buffer(cso, shader_stage, index, &cb);
> +   } else {
> +      cso_set_constant_buffer(cso, shader_stage, index, NULL);
> +   }
> +}
> +
>  void
>  cso_save_constant_buffer_slot0(struct cso_context *cso,
>                                 enum pipe_shader_type shader_stage)
>  {
>     util_copy_constant_buffer(&cso->aux_constbuf_saved[shader_stage],
>                               &cso->aux_constbuf_current[shader_stage]);
>  }
>
>  void
>  cso_restore_constant_buffer_slot0(struct cso_context *cso,
> diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h
> index b1bc0813442..3a4e808f0c0 100644
> --- a/src/gallium/auxiliary/cso_cache/cso_context.h
> +++ b/src/gallium/auxiliary/cso_cache/cso_context.h
> @@ -207,20 +207,23 @@ cso_set_shader_images(struct cso_context *cso,
>
>  /* constant buffers */
>
>  void cso_set_constant_buffer(struct cso_context *cso,
>                               enum pipe_shader_type shader_stage,
>                               unsigned index, struct pipe_constant_buffer *cb);
>  void cso_set_constant_buffer_resource(struct cso_context *cso,
>                                        enum pipe_shader_type shader_stage,
>                                        unsigned index,
>                                        struct pipe_resource *buffer);
> +void cso_set_constant_user_buffer(struct cso_context *cso,
> +                                  enum pipe_shader_type shader_stage,
> +                                  unsigned index, void *ptr, unsigned size);
>  void cso_save_constant_buffer_slot0(struct cso_context *cso,
>                                      enum pipe_shader_type shader_stage);
>  void cso_restore_constant_buffer_slot0(struct cso_context *cso,
>                                         enum pipe_shader_type shader_stage);
>
>
>  /* drawing */
>
>  void
>  cso_draw_vbo(struct cso_context *cso,
> diff --git a/src/gallium/auxiliary/postprocess/pp_mlaa.c b/src/gallium/auxiliary/postprocess/pp_mlaa.c
> index 0edd01f3f5d..610cedbd1b3 100644
> --- a/src/gallium/auxiliary/postprocess/pp_mlaa.c
> +++ b/src/gallium/auxiliary/postprocess/pp_mlaa.c
> @@ -50,76 +50,64 @@
>  #include "util/u_inlines.h"
>  #include "util/u_memory.h"
>  #include "util/u_string.h"
>  #include "pipe/p_screen.h"
>
>  #define IMM_SPACE 80
>
>  static float constants[] = { 1, 1, 0, 0 };
>  static unsigned int dimensions[2] = { 0, 0 };
>
> -/** Upload the constants. */
> -static void
> -up_consts(struct pp_queue_t *ppq)
> -{
> -   struct pipe_context *pipe = ppq->p->pipe;
> -
> -   pipe->buffer_subdata(pipe, ppq->constbuf, PIPE_TRANSFER_WRITE,
> -                        0, sizeof(constants), constants);
> -}
> -
>  /** Run function of the MLAA filter. */
>  static void
>  pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
>                     struct pipe_resource *out, unsigned int n, bool iscolor)
>  {
>
>     struct pp_program *p = ppq->p;
>
>     struct pipe_depth_stencil_alpha_state mstencil;
>     struct pipe_sampler_view v_tmp, *arr[3];
>
>     unsigned int w = 0;
>     unsigned int h = 0;
>
>     const struct pipe_stencil_ref ref = { {1} };
>
>     /* Insufficient initialization checks. */
>     assert(p);
>     assert(ppq);
> -   assert(ppq->constbuf);
>     assert(ppq->areamaptex);
>     assert(ppq->inner_tmp);
>     assert(ppq->shaders[n]);
>
>     w = p->framebuffer.width;
>     h = p->framebuffer.height;
>
>     memset(&mstencil, 0, sizeof(mstencil));
>
>     cso_set_stencil_ref(p->cso, &ref);
>
>     /* Init the pixel size constant */
>     if (dimensions[0] != p->framebuffer.width ||
>         dimensions[1] != p->framebuffer.height) {
>        constants[0] = 1.0f / p->framebuffer.width;
>        constants[1] = 1.0f / p->framebuffer.height;
>
> -      up_consts(ppq);
>        dimensions[0] = p->framebuffer.width;
>        dimensions[1] = p->framebuffer.height;
>     }
>
> -   cso_set_constant_buffer_resource(p->cso, PIPE_SHADER_VERTEX,
> -                                    0, ppq->constbuf);
> -   cso_set_constant_buffer_resource(p->cso, PIPE_SHADER_FRAGMENT,
> -                                    0, ppq->constbuf);
> +   cso_set_constant_user_buffer(p->cso, PIPE_SHADER_VERTEX,
> +                                0, constants, sizeof(constants));
> +   cso_set_constant_user_buffer(p->cso, PIPE_SHADER_FRAGMENT,
> +                                0, constants, sizeof(constants));
>
>     mstencil.stencil[0].enabled = 1;
>     mstencil.stencil[0].valuemask = mstencil.stencil[0].writemask = ~0;
>     mstencil.stencil[0].func = PIPE_FUNC_ALWAYS;
>     mstencil.stencil[0].fail_op = PIPE_STENCIL_OP_KEEP;
>     mstencil.stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP;
>     mstencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
>
>     p->framebuffer.zsbuf = ppq->stencils;
>
> @@ -232,29 +220,20 @@ pp_jimenezmlaa_init_run(struct pp_queue_t *ppq, unsigned int n,
>     char *tmp_text = NULL;
>
>     tmp_text = CALLOC(sizeof(blend2fs_1) + sizeof(blend2fs_2) +
>                       IMM_SPACE, sizeof(char));
>
>     if (!tmp_text) {
>        pp_debug("Failed to allocate shader space\n");
>        return FALSE;
>     }
>
> -   ppq->constbuf = pipe_buffer_create(ppq->p->screen,
> -                                      PIPE_BIND_CONSTANT_BUFFER,
> -                                      PIPE_USAGE_DEFAULT,
> -                                      sizeof(constants));
> -   if (ppq->constbuf == NULL) {
> -      pp_debug("Failed to allocate constant buffer\n");
> -      goto fail;
> -   }
> -
>     pp_debug("mlaa: using %u max search steps\n", val);
>
>     util_sprintf(tmp_text, "%s"
>                  "IMM FLT32 {    %.8f,     0.0000,     0.0000,     0.0000}\n"
>                  "%s\n", blend2fs_1, (float) val, blend2fs_2);
>
>     memset(&res, 0, sizeof(res));
>
>     res.target = PIPE_TEXTURE_2D;
>     res.format = PIPE_FORMAT_R8G8_UNORM;
> @@ -345,19 +324,13 @@ pp_jimenezmlaa_color(struct pp_queue_t *ppq, struct pipe_resource *in,
>  }
>
>
>  /**
>   * Short wrapper to free the mlaa filter resources. Shaders are freed in
>   * the common code in pp_free.
>   */
>  void
>  pp_jimenezmlaa_free(struct pp_queue_t *ppq, unsigned int n)
>  {
> -   if (ppq->areamaptex) {
> -      pipe_resource_reference(&ppq->areamaptex, NULL);
> -   }
> -
> -   if (ppq->constbuf) {
> -      pipe_resource_reference(&ppq->constbuf, NULL);
> -   }
> +   pipe_resource_reference(&ppq->areamaptex, NULL);
>  }
>
> diff --git a/src/gallium/auxiliary/postprocess/pp_private.h b/src/gallium/auxiliary/postprocess/pp_private.h
> index 0d032124115..710909b71e2 100644
> --- a/src/gallium/auxiliary/postprocess/pp_private.h
> +++ b/src/gallium/auxiliary/postprocess/pp_private.h
> @@ -69,21 +69,20 @@ struct pp_queue_t
>     pp_func *pp_queue;           /* An array of pp_funcs */
>     unsigned int n_filters;      /* Number of enabled filters */
>
>     struct pipe_resource *tmp[2];        /* Two temp FBOs for the queue */
>     struct pipe_resource *inner_tmp[3];  /* Three for filter use */
>
>     unsigned int n_tmp, n_inner_tmp;
>
>     struct pipe_resource *depth; /* depth of original input */
>     struct pipe_resource *stencil;       /* stencil shared by inner_tmps */
> -   struct pipe_resource *constbuf;      /* MLAA constant buffer */
>     struct pipe_resource *areamaptex;    /* MLAA area map texture */
>
>     struct pipe_surface *tmps[2], *inner_tmps[3], *stencils;
>
>     void ***shaders;             /* Shaders in TGSI form */
>     unsigned int *filters;       /* Active filter to filters.h mapping. */
>     struct pp_program *p;
>
>     bool fbos_init;
>  };
> --
> 2.15.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list