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@snap.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11741>
This commit is contained in:
Heinrich Fink
2021-07-01 11:26:57 +02:00
committed by Marge Bot
parent 3e8c6b7ae2
commit 9d070de5a5
+11 -8
View File
@@ -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);