diff options
author | Brian Paul <[email protected]> | 2019-03-12 09:13:00 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2019-03-17 20:07:22 -0600 |
commit | 593e36f9561d3665cc12ed1fc8a07dd8612c004e (patch) | |
tree | dcd7beb32c9c648947f59aecdc9a9f60377ebe3f /src/mesa/state_tracker/st_context.h | |
parent | e547a1ccb5aa65c1fb6777da2470bd6fd36e6ee9 (diff) |
st/mesa: implement "zombie" sampler views (v2)
When st_texture_release_all_sampler_views() is called the texture may
have sampler views belonging to several contexts. If we unreference a
sampler view and its refcount hits zero, we need to be sure to destroy
the sampler view with the same context which created it.
This was not the case with the previous code which used
pipe_sampler_view_release(). That function could end up freeing a
sampler view with a context different than the one which created it.
In the case of the VMware svga driver, we detected this but leaked the
sampler view. This led to a crash with google-chrome when the kernel
module had too many sampler views. VMware bug 2274734.
Alternately, if we try to delete a sampler view with the correct
context, we may be "reaching into" a context which is active on
another thread. That's not safe.
To fix these issues this patch adds a per-context list of "zombie"
sampler views. These are views which are to be freed at some point
when the context is active. Other contexts may safely add sampler
views to the zombie list at any time (it's mutex protected). This
avoids the context/view ownership mix-ups we had before.
Tested with: google-chrome, google earth, Redway3D Watch/Turbine demos
a few Linux games. If anyone can recomment some other multi-threaded,
multi-context GL apps to test, please let me know.
v2: avoid potential race issue by always adding sampler views to the
zombie list if the view's context doesn't match the current context,
ignoring the refcount.
Reviewed-by: Roland Scheidegger <[email protected]>
Reviewed-by: Neha Bhende <[email protected]>
Reviewed-by: Mathias Fröhlich <[email protected]>
Reviewed-By: Jose Fonseca <[email protected]>
Diffstat (limited to 'src/mesa/state_tracker/st_context.h')
-rw-r--r-- | src/mesa/state_tracker/st_context.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index a3f70ecd510..1106bb628a3 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -37,6 +37,7 @@ #include "util/u_inlines.h" #include "util/list.h" #include "vbo/vbo.h" +#include "util/list.h" #ifdef __cplusplus @@ -95,6 +96,16 @@ struct drawpix_cache_entry }; +/* + * Node for a linked list of dead sampler views. + */ +struct st_zombie_sampler_view_node +{ + struct pipe_sampler_view *view; + struct list_head node; +}; + + struct st_context { struct st_context_iface iface; @@ -306,6 +317,11 @@ struct st_context * the estimated allocated size needed to execute those operations. */ struct util_throttle throttle; + + struct { + struct st_zombie_sampler_view_node list; + mtx_t mutex; + } zombie_sampler_views; }; @@ -334,6 +350,15 @@ extern void st_invalidate_buffers(struct st_context *st); +extern void +st_save_zombie_sampler_view(struct st_context *st, + struct pipe_sampler_view *view); + +void +st_context_free_zombie_objects(struct st_context *st); + + + /** * Wrapper for struct gl_framebuffer. * This is an opaque type to the outside world. |