Mesa (main): llvmpipe: do not leak display target mapped ptr in cs setup

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jul 9 16:17:35 UTC 2021


Module: Mesa
Branch: main
Commit: 9d070de5a59c8d3b93fe0e2b0255e770a1651ab4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9d070de5a59c8d3b93fe0e2b0255e770a1651ab4

Author: Heinrich Fink <hfink at snap.com>
Date:   Thu Jul  1 11:26:57 2021 +0200

llvmpipe: do not leak display target mapped ptr in cs setup

For compute shader textures that are backed by a display target, do not
leak the mapped pointer and unmap when access to the mapped resource is
not needed anymore.

Also use llvmpipe_resource_[un]map instead of calling winsys map
functions directly.

v2:
    - use llvmpipe_resource_[un]map directly instead of winsys DT map
    func and unneeded helper function for unmapping.

v3 (Emil Velikov):
    - add comment in lp_csctx_set_sampler_views to explain
    unmapping current texture early in the loop.

Signed-off-by: Heinrich Fink <hfink at snap.com>
Reviewed-by: Emil Velikov <emil.velikov at collabora.com>
Reviewed-by: Roland Scheidegger <sroland at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11741>

---

 src/gallium/drivers/llvmpipe/lp_state_cs.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c
index c18889350ff..93e5d0cca6f 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_cs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c
@@ -895,6 +895,12 @@ lp_csctx_set_sampler_views(struct lp_cs_context *csctx,
    for (i = 0; i < max_tex_num; i++) {
       struct pipe_sampler_view *view = i < num ? views[i] : NULL;
 
+      /* We are going to overwrite/unref the current texture further below. If
+       * set, make sure to unmap its resource to avoid leaking previous
+       * mapping.  */
+      if (csctx->cs.current_tex[i])
+         llvmpipe_resource_unmap(csctx->cs.current_tex[i], 0, 0);
+
       if (view) {
          struct pipe_resource *res = view->texture;
          struct llvmpipe_resource *lp_tex = llvmpipe_resource(res);
@@ -997,13 +1003,7 @@ lp_csctx_set_sampler_views(struct lp_cs_context *csctx,
          }
          else {
             /* display target texture/surface */
-            /*
-             * XXX: Where should this be unmapped?
-             */
-            struct llvmpipe_screen *screen = llvmpipe_screen(res->screen);
-            struct sw_winsys *winsys = screen->winsys;
-            jit_tex->base = winsys->displaytarget_map(winsys, lp_tex->dt,
-                                                         PIPE_MAP_READ);
+            jit_tex->base = llvmpipe_resource_map(res, 0, 0, LP_TEX_USAGE_READ);
             jit_tex->row_stride[0] = lp_tex->row_stride[0];
             jit_tex->img_stride[0] = lp_tex->img_stride[0];
             jit_tex->mip_offsets[0] = 0;
@@ -1428,7 +1428,10 @@ lp_csctx_destroy(struct lp_cs_context *csctx)
 {
    unsigned i;
    for (i = 0; i < ARRAY_SIZE(csctx->cs.current_tex); i++) {
-      pipe_resource_reference(&csctx->cs.current_tex[i], NULL);
+      struct pipe_resource **res_ptr = &csctx->cs.current_tex[i];
+      if (*res_ptr)
+         llvmpipe_resource_unmap(*res_ptr, 0, 0);
+      pipe_resource_reference(res_ptr, NULL);
    }
    for (i = 0; i < ARRAY_SIZE(csctx->constants); i++) {
       pipe_resource_reference(&csctx->constants[i].current.buffer, NULL);



More information about the mesa-commit mailing list