gallium/pp: use user constant buffers
authorMarek Olšák <marek.olsak@amd.com>
Wed, 4 Apr 2018 20:04:30 +0000 (16:04 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 5 Apr 2018 00:01:43 +0000 (20:01 -0400)
This fixes a radeonsi crash.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=105026

src/gallium/auxiliary/cso_cache/cso_context.c
src/gallium/auxiliary/cso_cache/cso_context.h
src/gallium/auxiliary/postprocess/pp_mlaa.c
src/gallium/auxiliary/postprocess/pp_private.h

index 3fa57f1..3a3a63a 100644 (file)
@@ -1548,6 +1548,23 @@ cso_set_constant_buffer_resource(struct cso_context *cso,
 }
 
 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)
 {
index b1bc081..3a4e808 100644 (file)
@@ -214,6 +214,9 @@ 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,
index 0edd01f..610cedb 100644 (file)
 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,
@@ -86,7 +76,6 @@ pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
    /* Insufficient initialization checks. */
    assert(p);
    assert(ppq);
-   assert(ppq->constbuf);
    assert(ppq->areamaptex);
    assert(ppq->inner_tmp);
    assert(ppq->shaders[n]);
@@ -104,15 +93,14 @@ pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
       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;
@@ -239,15 +227,6 @@ pp_jimenezmlaa_init_run(struct pp_queue_t *ppq, unsigned int 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"
@@ -352,12 +331,6 @@ pp_jimenezmlaa_color(struct pp_queue_t *ppq, struct pipe_resource *in,
 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);
 }
 
index 0d03212..710909b 100644 (file)
@@ -76,7 +76,6 @@ struct pp_queue_t
 
    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;