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 3fa57f16ff4db64aa7274baad0a09acd35226a72..3a3a63a3327e00f39b834ce73c07a918353aebc2 100644 (file)
@@ -1547,6 +1547,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 b1bc0813442d3578b572653c228fdf5af833d765..3a4e808f0c049ee467313075d53079c17c3310cc 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 0edd01f3f5d5a6bf3afd98a7bc73a3ec7470aeae..610cedbd1b3f49b27eee4939c08c73eb4242c2c7 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 0d032124115554cbfd14feb768e028403b91ae76..710909b71e221beea192c2b69c3ff1411843fa15 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;