[Mesa-dev] [PATCH 3/4] gallium/u_threaded: add a fast path for unbinding shader images

Marek Olšák maraeo at gmail.com
Wed May 17 19:14:21 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/auxiliary/util/u_threaded_context.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c
index 50cb820..e33c846 100644
--- a/src/gallium/auxiliary/util/u_threaded_context.c
+++ b/src/gallium/auxiliary/util/u_threaded_context.c
@@ -148,21 +148,21 @@ tc_add_sized_call(struct threaded_context *tc, enum tc_call_id id,
    return &call->payload;
 }
 
 #define tc_add_struct_typed_call(tc, execute, type) \
    ((struct type*)tc_add_sized_call(tc, execute, sizeof(struct type)))
 
 #define tc_add_slot_based_call(tc, execute, type, num_slots) \
    ((struct type*)tc_add_sized_call(tc, execute, \
                                     sizeof(struct type) + \
                                     sizeof(((struct type*)NULL)->slot[0]) * \
-                                    num_slots))
+                                    (num_slots)))
 
 static union tc_payload *
 tc_add_small_call(struct threaded_context *tc, enum tc_call_id id)
 {
    return tc_add_sized_call(tc, id, 0);
 }
 
 static void
 _tc_sync(struct threaded_context *tc, const char *info, const char *func)
 {
@@ -757,69 +757,75 @@ tc_set_sampler_views(struct pipe_context *_pipe,
          p->slot[i] = NULL;
          pipe_sampler_view_reference(&p->slot[i], views[i]);
       }
    } else {
       memset(p->slot, 0, count * sizeof(views[0]));
    }
 }
 
 struct tc_shader_images {
    ubyte shader, start, count;
+   bool unbind;
    struct pipe_image_view slot[0]; /* more will be allocated if needed */
 };
 
 static void
 tc_call_set_shader_images(struct pipe_context *pipe, union tc_payload *payload)
 {
    struct tc_shader_images *p = (struct tc_shader_images *)payload;
    unsigned count = p->count;
 
+   if (p->unbind) {
+      pipe->set_shader_images(pipe, p->shader, p->start, p->count, NULL);
+      return;
+   }
+
    pipe->set_shader_images(pipe, p->shader, p->start, p->count, p->slot);
 
    for (unsigned i = 0; i < count; i++)
       pipe_resource_reference(&p->slot[i].resource, NULL);
 }
 
 static void
 tc_set_shader_images(struct pipe_context *_pipe,
                      enum pipe_shader_type shader,
                      unsigned start, unsigned count,
                      const struct pipe_image_view *images)
 {
    if (!count)
       return;
 
    struct threaded_context *tc = threaded_context(_pipe);
    struct tc_shader_images *p =
-      tc_add_slot_based_call(tc, TC_CALL_set_shader_images, tc_shader_images, count);
+      tc_add_slot_based_call(tc, TC_CALL_set_shader_images, tc_shader_images,
+                             images ? count : 0);
 
    p->shader = shader;
    p->start = start;
    p->count = count;
+   p->unbind = images == NULL;
 
    if (images) {
       for (unsigned i = 0; i < count; i++) {
          tc_set_resource_reference(&p->slot[i].resource, images[i].resource);
 
          if (images[i].access & PIPE_IMAGE_ACCESS_WRITE &&
              images[i].resource &&
              images[i].resource->target == PIPE_BUFFER) {
             struct threaded_resource *tres =
                threaded_resource(images[i].resource);
 
             util_range_add(&tres->valid_buffer_range, images[i].u.buf.offset,
                            images[i].u.buf.offset + images[i].u.buf.size);
          }
       }
       memcpy(p->slot, images, count * sizeof(images[0]));
-   } else {
-      memset(p->slot, 0, count * sizeof(images[0]));
    }
 }
 
 struct tc_shader_buffers {
    ubyte shader, start, count;
    struct pipe_shader_buffer slot[0]; /* more will be allocated if needed */
 };
 
 static void
 tc_call_set_shader_buffers(struct pipe_context *pipe, union tc_payload *payload)
-- 
2.7.4



More information about the mesa-dev mailing list