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);