<div dir="ltr">"The GL state tracker, which is the only one that runs into the multi-context subtleties (due to share groups), already guarantees that sampler views are destroyed before their context of creation is destroyed."<div><br></div><div>How does the GL state tracker guarantee this?  Does this guarantee also apply to pipe_surfaces?  Context: ChromiumOS previously ran into an issue where sampler_views and pipe_surfaces outlived the context that created them [1], and we have technical debt [2][3][4] emanating from this.  It would be great to remove this, if things have changed in the Gallium code.  </div><div><br></div><div>[1] <a href="https://lists.freedesktop.org/archives/mesa-dev/2011-September/011578.html">https://lists.freedesktop.org/archives/mesa-dev/2011-September/011578.html</a></div><div>[2] <a href="https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/media-libs/mesa/files/10.3-state_tracker-gallium-fix-crash-with-st_renderbuffer.patch">https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/media-libs/mesa/files/10.3-state_tracker-gallium-fix-crash-with-st_renderbuffer.patch</a></div><div>[3] <a href="https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/media-libs/mesa/files/10.3-state_tracker-gallium-fix-crash-with-st_renderbuffer-freedreno.patch">https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/media-libs/mesa/files/10.3-state_tracker-gallium-fix-crash-with-st_renderbuffer-freedreno.patch</a></div><div>[4] <a href="https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/media-libs/mesa/files/12.1-radeonsi-sampler_view_destroy.patch">https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/media-libs/mesa/files/12.1-radeonsi-sampler_view_destroy.patch</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 10, 2017 at 2:42 PM, Nicolai Hähnle <span dir="ltr"><<a href="mailto:nhaehnle@gmail.com" target="_blank">nhaehnle@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Same as on IRC:<span class=""><br>
<br>
On 10.10.2017 04:06, Marek Olšák wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Is there any difference with piglit/drawoverhead?<br>
</blockquote>
<br></span>
Yes, there is.<span class=""><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If yes, would this be useful?<br>
<a href="https://patchwork.freedesktop.org/patch/41241/" rel="noreferrer" target="_blank">https://patchwork.freedesktop.<wbr>org/patch/41241/</a><br>
</blockquote>
<br></span>
Surprisingly, not that much. I'm going to think though a couple of other options, but want to already push patch #3; I sent a version that is rebased on master and disentangled from the locking stuff.<br>
<br>
Cheers,<br>
Nicolai<div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Marek<br>
<br>
<br>
On Fri, Oct 6, 2017 at 10:38 PM, Nicolai Hähnle <<a href="mailto:nhaehnle@gmail.com" target="_blank">nhaehnle@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
From: Nicolai Hähnle <<a href="mailto:nicolai.haehnle@amd.com" target="_blank">nicolai.haehnle@amd.com</a>><br>
<br>
r600 expects the context that created the sampler view to still be alive<br>
(there is a per-context list of sampler views).<br>
<br>
svga currently bails when the context of destruction is not the same as<br>
creation.<br>
<br>
The GL state tracker, which is the only one that runs into the<br>
multi-context subtleties (due to share groups), already guarantees that<br>
sampler views are destroyed before their context of creation is destroyed.<br>
<br>
Most drivers are context-agnostic, so the warning message in<br>
pipe_sampler_view_release doesn't really make sense.<br>
---<br>
  src/gallium/auxiliary/util/u_i<wbr>nlines.h   | 16 ++++++++++------<br>
  src/gallium/include/pipe/p_con<wbr>text.h     | 10 ++++++++++<br>
  src/mesa/state_tracker/st_samp<wbr>ler_view.c |  1 -<br>
  3 files changed, 20 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/src/gallium/auxiliary/util/u<wbr>_inlines.h b/src/gallium/auxiliary/util/u<wbr>_inlines.h<br>
index 79f62c32266..790352d7800 100644<br>
--- a/src/gallium/auxiliary/util/u<wbr>_inlines.h<br>
+++ b/src/gallium/auxiliary/util/u<wbr>_inlines.h<br>
@@ -142,45 +142,49 @@ pipe_resource_reference(struct pipe_resource **ptr, struct pipe_resource *tex)<br>
           struct pipe_resource *next = old_tex->next;<br>
<br>
           old_tex->screen->resource_des<wbr>troy(old_tex->screen, old_tex);<br>
           old_tex = next;<br>
        } while (pipe_reference_described(&old<wbr>_tex->reference, NULL,<br>
                                          (debug_reference_descriptor)de<wbr>bug_describe_resource));<br>
     }<br>
     *ptr = tex;<br>
  }<br>
<br>
+/**<br>
+ * Set *ptr to \p view with proper reference counting.<br>
+ *<br>
+ * The caller must guarantee that \p view and *ptr must have been created in<br>
+ * the same context (if they exist), and that this must be the current context.<br>
+ */<br>
  static inline void<br>
  pipe_sampler_view_reference(st<wbr>ruct pipe_sampler_view **ptr, struct pipe_sampler_view *view)<br>
  {<br>
     struct pipe_sampler_view *old_view = *ptr;<br>
<br>
     if (pipe_reference_described(&(*p<wbr>tr)->reference, &view->reference,<br>
                                  (debug_reference_descriptor)de<wbr>bug_describe_sampler_view))<br>
        old_view->context->sampler_vie<wbr>w_destroy(old_view->context, old_view);<br>
     *ptr = view;<br>
  }<br>
<br>
  /**<br>
   * Similar to pipe_sampler_view_reference() but always set the pointer to<br>
- * NULL and pass in an explicit context.  Passing an explicit context is a<br>
- * work-around for fixing a dangling context pointer problem when textures<br>
- * are shared by multiple contexts.  XXX fix this someday.<br>
+ * NULL and pass in the current context explicitly.<br>
+ *<br>
+ * If *ptr is non-NULL, it may refer to a view that was created in a different<br>
+ * context (however, that context must still be alive).<br>
   */<br>
  static inline void<br>
  pipe_sampler_view_release(stru<wbr>ct pipe_context *ctx,<br>
                            struct pipe_sampler_view **ptr)<br>
  {<br>
     struct pipe_sampler_view *old_view = *ptr;<br>
-   if (*ptr && (*ptr)->context != ctx) {<br>
-      debug_printf_once(("context mis-match in pipe_sampler_view_release()\n"<wbr>));<br>
-   }<br>
     if (pipe_reference_described(&(*p<wbr>tr)->reference, NULL,<br>
                      (debug_reference_descriptor)de<wbr>bug_describe_sampler_view)) {<br>
        ctx->sampler_view_destroy(ctx, old_view);<br>
     }<br>
     *ptr = NULL;<br>
  }<br>
<br>
  static inline void<br>
  pipe_so_target_reference(struc<wbr>t pipe_stream_output_target **ptr,<br>
                           struct pipe_stream_output_target *target)<br>
diff --git a/src/gallium/include/pipe/p_c<wbr>ontext.h b/src/gallium/include/pipe/p_c<wbr>ontext.h<br>
index 4609d4dbf23..087836d1c0c 100644<br>
--- a/src/gallium/include/pipe/p_c<wbr>ontext.h<br>
+++ b/src/gallium/include/pipe/p_c<wbr>ontext.h<br>
@@ -501,20 +501,30 @@ struct pipe_context {<br>
     void (*fence_server_sync)(struct pipe_context *pipe,<br>
                               struct pipe_fence_handle *fence);<br>
<br>
     /**<br>
      * Create a view on a texture to be used by a shader stage.<br>
      */<br>
     struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,<br>
                                                       struct pipe_resource *texture,<br>
                                                       const struct pipe_sampler_view *templat);<br>
<br>
+   /**<br>
+    * Destroy a view on a texture.<br>
+    *<br>
+    * \param ctx the current context<br>
+    * \param view the view to be destroyed<br>
+    *<br>
+    * \note The current context may not be the context in which the view was<br>
+    *       created (view->context). However, the caller must guarantee that<br>
+    *       the context which created the view is still alive.<br>
+    */<br>
     void (*sampler_view_destroy)(struct pipe_context *ctx,<br>
                                  struct pipe_sampler_view *view);<br>
<br>
<br>
     /**<br>
      * Get a surface which is a "view" into a resource, used by<br>
      * render target / depth stencil stages.<br>
      */<br>
     struct pipe_surface *(*create_surface)(struct pipe_context *ctx,<br>
                                            struct pipe_resource *resource,<br>
diff --git a/src/mesa/state_tracker/st_sa<wbr>mpler_view.c b/src/mesa/state_tracker/st_sa<wbr>mpler_view.c<br>
index fbf0aaeb03a..d1715a888d9 100644<br>
--- a/src/mesa/state_tracker/st_sa<wbr>mpler_view.c<br>
+++ b/src/mesa/state_tracker/st_sa<wbr>mpler_view.c<br>
@@ -109,21 +109,20 @@ st_texture_release_sampler_vie<wbr>w(struct st_context *st,<br>
  /**<br>
   * Release all sampler views attached to the given texture object, regardless<br>
   * of the context.<br>
   */<br>
  void<br>
  st_texture_release_all_sampler<wbr>_views(struct st_context *st,<br>
                                       struct st_texture_object *stObj)<br>
  {<br>
     GLuint i;<br>
<br>
-   /* XXX This should use sampler_views[i]->pipe, not st->pipe */<br>
     for (i = 0; i < stObj->num_sampler_views; ++i)<br>
        pipe_sampler_view_release(st-><wbr>pipe, &stObj->sampler_views[i]);<br>
  }<br>
<br>
<br>
  void<br>
  st_texture_free_sampler_views(<wbr>struct st_texture_object *stObj)<br>
  {<br>
     free(stObj->sampler_views);<br>
     stObj->sampler_views = NULL;<br>
--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></blockquote>
<br>
<br></div></div><span class="HOEnZb"><font color="#888888">
-- <br>
Lerne, wie die Welt wirklich ist,<br>
Aber vergiss niemals, wie sie sein sollte.</font></span><div class="HOEnZb"><div class="h5"><br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div>