[14/17] gallium: add transition_resource call

Submitted by Andres Rodriguez on Nov. 2, 2017, 3:57 a.m.

Details

Message ID 20171102035720.6839-15-andresx7@gmail.com
State New
Headers show
Series "Add support for GL_EXT_semaphore" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Andres Rodriguez Nov. 2, 2017, 3:57 a.m.
This operation is meant to transition resource in and out of optimized
layouts for compatibility with external clients.

Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
---
 src/gallium/auxiliary/util/u_threaded_context.c    | 27 ++++++++++++++++++++++
 .../auxiliary/util/u_threaded_context_calls.h      |  1 +
 src/gallium/include/pipe/p_context.h               | 10 ++++++++
 src/gallium/include/pipe/p_defines.h               | 11 +++++++++
 4 files changed, 49 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c
index 272d846..881f886 100644
--- a/src/gallium/auxiliary/util/u_threaded_context.c
+++ b/src/gallium/auxiliary/util/u_threaded_context.c
@@ -2086,6 +2086,32 @@  tc_invalidate_resource(struct pipe_context *_pipe,
    tc_set_resource_reference(&payload->resource, resource);
 }
 
+struct tc_transition_resource {
+   struct pipe_resource *resource;
+   enum pipe_layout layout;
+};
+
+static void
+tc_call_transition_resource(struct pipe_context *pipe, union tc_payload *payload)
+{
+   struct tc_transition_resource *p = (struct tc_transition_resource *)payload;
+   pipe->transition_resource(pipe, p->resource, p->layout);
+   tc_set_resource_reference(&p->resource, NULL);
+}
+
+static void
+tc_transition_resource(struct pipe_context *pipe,
+                       struct pipe_resource *resource,
+                       enum pipe_layout layout)
+{
+   struct threaded_context *tc = threaded_context(pipe);
+   struct tc_transition_resource *p = tc_add_struct_typed_call(tc,
+                                                               TC_CALL_transition_resource,
+                                                               tc_transition_resource);
+   tc_set_resource_reference(&p->resource, resource);
+   p->layout = layout;
+}
+
 struct tc_clear {
    unsigned buffers;
    union pipe_color_union color;
@@ -2380,6 +2406,7 @@  threaded_context_create(struct pipe_context *pipe,
    CTX_INIT(clear_buffer);
    CTX_INIT(clear_texture);
    CTX_INIT(flush_resource);
+   CTX_INIT(transition_resource);
    CTX_INIT(generate_mipmap);
    CTX_INIT(render_condition);
    CTX_INIT(create_query);
diff --git a/src/gallium/auxiliary/util/u_threaded_context_calls.h b/src/gallium/auxiliary/util/u_threaded_context_calls.h
index 546819a..0fbebf8 100644
--- a/src/gallium/auxiliary/util/u_threaded_context_calls.h
+++ b/src/gallium/auxiliary/util/u_threaded_context_calls.h
@@ -28,6 +28,7 @@  CALL(blit)
 CALL(generate_mipmap)
 CALL(flush_resource)
 CALL(invalidate_resource)
+CALL(transition_resource)
 CALL(clear)
 CALL(clear_buffer)
 CALL(clear_texture)
diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h
index 0e3e930..f386230 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -714,6 +714,16 @@  struct pipe_context {
                           struct pipe_resource *resource);
 
    /**
+    * Transition a resource to a different layout so it can be used by
+    * an external client.
+    *
+    * Note: The layout definitions across clients must be consistent.
+    */
+   void (*transition_resource)(struct pipe_context *ctx,
+                               struct pipe_resource *resource,
+                               enum pipe_layout layout);
+
+   /**
     * Invalidate the contents of the resource. This is used to
     *
     * (1) implement EGL's semantic of undefined depth/stencil
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 66e9444..95ebbaa 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -578,6 +578,17 @@  enum pipe_swizzle {
    PIPE_SWIZZLE_MAX, /**< Number of enums counter (must be last) */
 };
 
+enum pipe_layout
+{
+   PIPE_LAYOUT_GENERAL_EXT,
+   PIPE_LAYOUT_COLOR_ATTACHMENT,
+   PIPE_LAYOUT_DEPTH_STENCIL_ATTACHMENT,
+   PIPE_LAYOUT_DEPTH_STENCIL_READ_ONLY,
+   PIPE_LAYOUT_SHADER_READ_ONLY,
+   PIPE_LAYOUT_TRANSFER_SRC,
+   PIPE_LAYOUT_TRANSFER_DST,
+};
+
 #define PIPE_TIMEOUT_INFINITE 0xffffffffffffffffull