gallium: extend resource_get_param to be as capable as resource_get_handle
authorMarek Olšák <marek.olsak@amd.com>
Fri, 30 Aug 2019 00:35:54 +0000 (20:35 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 18 Sep 2019 18:41:30 +0000 (14:41 -0400)
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/gallium/auxiliary/driver_ddebug/dd_screen.c
src/gallium/auxiliary/driver_noop/noop_pipe.c
src/gallium/auxiliary/driver_rbug/rbug_screen.c
src/gallium/auxiliary/driver_trace/tr_screen.c
src/gallium/drivers/iris/iris_resource.c
src/gallium/include/pipe/p_screen.h
src/gallium/state_trackers/dri/dri2.c

index 25cb20142108b8c958bce62cbd90a8c3e641171f..b66d24babb9d608fb520db96c6b6968107085b41 100644 (file)
@@ -313,14 +313,19 @@ dd_screen_resource_get_handle(struct pipe_screen *_screen,
 
 static bool
 dd_screen_resource_get_param(struct pipe_screen *_screen,
+                             struct pipe_context *_pipe,
                              struct pipe_resource *resource,
-                             unsigned int plane,
+                             unsigned plane,
+                             unsigned layer,
                              enum pipe_resource_param param,
+                             unsigned handle_usage,
                              uint64_t *value)
 {
    struct pipe_screen *screen = dd_screen(_screen)->screen;
+   struct pipe_context *pipe = _pipe ? dd_context(_pipe)->pipe : NULL;
 
-   return screen->resource_get_param(screen, resource, plane, param, value);
+   return screen->resource_get_param(screen, pipe, resource, plane, layer,
+                                     param, handle_usage, value);
 }
 
 static void
index ec619fd33bcc2bfe86e2c854c36be7c8b14548b4..722e15b97c7f88cbb413d6a14c8e7a73c181601f 100644 (file)
@@ -157,9 +157,12 @@ static bool noop_resource_get_handle(struct pipe_screen *pscreen,
 }
 
 static bool noop_resource_get_param(struct pipe_screen *pscreen,
+                                    struct pipe_context *ctx,
                                     struct pipe_resource *resource,
-                                    unsigned int plane,
+                                    unsigned plane,
+                                    unsigned layer,
                                     enum pipe_resource_param param,
+                                    unsigned handle_usage,
                                     uint64_t *value)
 {
    struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)pscreen;
@@ -172,7 +175,8 @@ static bool noop_resource_get_param(struct pipe_screen *pscreen,
    if (!tex)
       return false;
 
-   result = screen->resource_get_param(screen, tex, 0, param, value);
+   result = screen->resource_get_param(screen, NULL, tex, 0, 0, param,
+                                       handle_usage, value);
    pipe_resource_reference(&tex, NULL);
    return result;
 }
index 247745fa533dfbb2468817bb4bdc9d2ef6cad249..a85d4e60e5b7489c5b47284cfc9f7a38024da1a9 100644 (file)
@@ -217,17 +217,23 @@ rbug_screen_resource_get_handle(struct pipe_screen *_screen,
 
 static bool
 rbug_screen_resource_get_param(struct pipe_screen *_screen,
+                               struct pipe_context *_pipe,
                                struct pipe_resource *_resource,
-                               unsigned int plane,
+                               unsigned plane,
+                               unsigned layer,
                                enum pipe_resource_param param,
+                               unsigned handle_usage,
                                uint64_t *value)
 {
    struct rbug_screen *rb_screen = rbug_screen(_screen);
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct rbug_resource *rb_resource = rbug_resource(_resource);
    struct pipe_screen *screen = rb_screen->screen;
    struct pipe_resource *resource = rb_resource->resource;
 
-   return screen->resource_get_param(screen, resource, plane, param, value);
+   return screen->resource_get_param(screen, rb_pipe ? rb_pipe->pipe : NULL,
+                                     resource, plane, layer, param,
+                                     handle_usage, value);
 }
 
 
index 0417e2339c24c359e364a356a42677b59f721d66..380e3ea7511570007acb4226fb149b83b0ce3e37 100644 (file)
@@ -409,17 +409,23 @@ trace_screen_resource_get_handle(struct pipe_screen *_screen,
 
 static bool
 trace_screen_resource_get_param(struct pipe_screen *_screen,
+                                struct pipe_context *_pipe,
                                 struct pipe_resource *resource,
-                                unsigned int plane,
+                                unsigned plane,
+                                unsigned layer,
                                 enum pipe_resource_param param,
+                                unsigned handle_usage,
                                 uint64_t *value)
 {
    struct trace_screen *tr_screen = trace_screen(_screen);
+   struct trace_context *tr_pipe = _pipe ? trace_context(_pipe) : NULL;
    struct pipe_screen *screen = tr_screen->screen;
 
    /* TODO trace call */
 
-   return screen->resource_get_param(screen, resource, plane, param, value);
+   return screen->resource_get_param(screen, tr_pipe ? tr_pipe->pipe : NULL,
+                                     resource, plane, layer, param,
+                                     handle_usage, value);
 }
 
 static void
index 5b1fde7aac65a115b16d0cf005e8adf286c5829e..a140b3f1c6fd46e3580b69fa9d6e6aff9389b4c7 100644 (file)
@@ -1025,9 +1025,12 @@ iris_flush_resource(struct pipe_context *ctx, struct pipe_resource *resource)
 
 static bool
 iris_resource_get_param(struct pipe_screen *screen,
+                        struct pipe_context *context,
                         struct pipe_resource *resource,
-                        unsigned int plane,
+                        unsigned plane,
+                        unsigned layer,
                         enum pipe_resource_param param,
+                        unsigned handle_usage,
                         uint64_t *value)
 {
    struct iris_resource *res = (struct iris_resource *)resource;
index 1d0e5c536681f27ec316d91c464708f0d7da5c35..9a1fc37280e7f6909b779e12666f0378f349e017 100644 (file)
@@ -265,11 +265,20 @@ struct pipe_screen {
    /**
     * Get info for the given pipe resource without the need to get a
     * winsys_handle.
+    *
+    * The context parameter can optionally be used to flush the resource and
+    * the context to make sure the resource is coherent with whatever user
+    * will use it. Some drivers may also use the context to convert
+    * the resource into a format compatible for sharing. The context parameter
+    * is allowed to be NULL.
     */
    bool (*resource_get_param)(struct pipe_screen *screen,
+                              struct pipe_context *context,
                               struct pipe_resource *resource,
-                              unsigned int plane,
+                              unsigned plane,
+                              unsigned layer,
                               enum pipe_resource_param param,
+                              unsigned handle_usage,
                               uint64_t *value);
 
    /**
index 47b9f0f7393fb6986725f7a1d695231d2be85dbf..574ddaea5c78c95e38099e8e80b6c433de642d03 100644 (file)
@@ -1146,14 +1146,15 @@ dri2_query_image_by_resource_handle(__DRIimage *image, int attrib, int *value)
 
 static bool
 dri2_resource_get_param(__DRIimage *image, enum pipe_resource_param param,
-                        uint64_t *value)
+                        unsigned handle_usage, uint64_t *value)
 {
    struct pipe_screen *pscreen = image->texture->screen;
    if (!pscreen->resource_get_param)
       return false;
 
-   return pscreen->resource_get_param(pscreen, image->texture, image->plane,
-                                      param, value);
+   return pscreen->resource_get_param(pscreen, NULL, image->texture,
+                                      image->plane, 0, param, handle_usage,
+                                      value);
 }
 
 static bool
@@ -1161,6 +1162,7 @@ dri2_query_image_by_resource_param(__DRIimage *image, int attrib, int *value)
 {
    enum pipe_resource_param param;
    uint64_t res_param;
+   unsigned handle_usage;
 
    if (!image->texture->screen->resource_get_param)
       return false;
@@ -1192,7 +1194,12 @@ dri2_query_image_by_resource_param(__DRIimage *image, int attrib, int *value)
       return false;
    }
 
-   if (!dri2_resource_get_param(image, param, &res_param))
+   if (image->use & __DRI_IMAGE_USE_BACKBUFFER)
+      handle_usage = PIPE_HANDLE_USAGE_EXPLICIT_FLUSH;
+   else
+      handle_usage = PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE;
+
+   if (!dri2_resource_get_param(image, param, handle_usage, &res_param))
       return false;
 
    switch (attrib) {
@@ -1330,7 +1337,7 @@ dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate)
       return NULL;
    } else if (plane > 0) {
       uint64_t planes;
-      if (!dri2_resource_get_param(image, PIPE_RESOURCE_PARAM_NPLANES,
+      if (!dri2_resource_get_param(image, PIPE_RESOURCE_PARAM_NPLANES, 0,
                                    &planes) ||
           plane >= planes) {
          return NULL;
@@ -1339,7 +1346,7 @@ dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate)
 
    if (image->dri_components == 0) {
       uint64_t modifier;
-      if (!dri2_resource_get_param(image, PIPE_RESOURCE_PARAM_MODIFIER,
+      if (!dri2_resource_get_param(image, PIPE_RESOURCE_PARAM_MODIFIER, 0,
                                    &modifier) ||
           modifier == DRM_FORMAT_MOD_INVALID) {
          return NULL;