llvmpipe: do not leak map of display target in fs setup
For fragment shader textures that are backed by a display target, do not leak the mapped pointer, but unmap before unref'ing its associated pipe_resource instances. Also, make sure that the pointer that's mapped into a jit texture stays valid while rasterization works on a jit context copy by mapping the display target again during scene setup, and unmapping when finalizing rasterization. v2 (Daniel Stone): - remove redundant helper function for [un]mapping DT, use llvmpipe_resource_[un]map right away v3 (Emil Velikov): - add comment in lp_setup_set_fragment_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:
parent
8192ffe3be
commit
3e8c6b7ae2
|
@ -278,6 +278,7 @@ lp_scene_end_rasterization(struct lp_scene *scene )
|
|||
ref->resource[i]->height0,
|
||||
llvmpipe_resource_size(ref->resource[i]));
|
||||
j++;
|
||||
llvmpipe_resource_unmap(ref->resource[i], 0, 0);
|
||||
pipe_resource_reference(&ref->resource[i], NULL);
|
||||
}
|
||||
}
|
||||
|
@ -439,6 +440,12 @@ lp_scene_add_resource_reference(struct lp_scene *scene,
|
|||
memset(ref, 0, sizeof *ref);
|
||||
}
|
||||
|
||||
/* Map resource again to increment the map count. We likely use the
|
||||
* already-mapped pointer in a texture of the jit context, and that pointer
|
||||
* needs to stay mapped during rasterization. This map is unmap'ed when
|
||||
* finalizing scene rasterization. */
|
||||
llvmpipe_resource_map(resource, 0, 0, LP_TEX_USAGE_READ);
|
||||
|
||||
/* Append the reference to the reference block.
|
||||
*/
|
||||
pipe_resource_reference(&ref->resource[ref->count++], resource);
|
||||
|
|
|
@ -898,6 +898,12 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
|
|||
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 (setup->fs.current_tex[i])
|
||||
llvmpipe_resource_unmap(setup->fs.current_tex[i], 0, 0);
|
||||
|
||||
if (view) {
|
||||
struct pipe_resource *res = view->texture;
|
||||
struct llvmpipe_resource *lp_tex = llvmpipe_resource(res);
|
||||
|
@ -1002,13 +1008,7 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
|
|||
}
|
||||
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;
|
||||
|
@ -1419,7 +1419,10 @@ lp_setup_destroy( struct lp_setup_context *setup )
|
|||
util_unreference_framebuffer_state(&setup->fb);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(setup->fs.current_tex); i++) {
|
||||
pipe_resource_reference(&setup->fs.current_tex[i], NULL);
|
||||
struct pipe_resource **res_ptr = &setup->fs.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(setup->constants); i++) {
|
||||
|
|
Loading…
Reference in New Issue