egl+libsync: Add helper to complain about invalid fence fd's
Debugging fd lifetime issues can be hard. Add a helper for debug builds to print out an error if an fd is not a fence fd, and sprinkle it around Signed-off-by: Rob Clark <robdclark@chromium.org> Reviewed-by: Emma Anholt <emma@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15094>
This commit is contained in:
parent
1e25f3b282
commit
d2e498b6a5
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include "util/compiler.h"
|
||||
#include "util/os_file.h"
|
||||
#include "util/libsync.h"
|
||||
|
||||
#include "loader.h"
|
||||
#include "egl_dri2.h"
|
||||
|
@ -470,6 +471,8 @@ handle_in_fence_fd(struct dri2_egl_surface *dri2_surf, __DRIimage *img)
|
|||
if (dri2_surf->in_fence_fd < 0)
|
||||
return;
|
||||
|
||||
validate_fence_fd(dri2_surf->in_fence_fd);
|
||||
|
||||
if (dri2_dpy->image->base.version >= 21 &&
|
||||
dri2_dpy->image->setInFenceFd != NULL) {
|
||||
dri2_dpy->image->setInFenceFd(img, dri2_surf->in_fence_fd);
|
||||
|
@ -481,6 +484,7 @@ handle_in_fence_fd(struct dri2_egl_surface *dri2_surf, __DRIimage *img)
|
|||
static void
|
||||
close_in_fence_fd(struct dri2_egl_surface *dri2_surf)
|
||||
{
|
||||
validate_fence_fd(dri2_surf->in_fence_fd);
|
||||
if (dri2_surf->in_fence_fd >= 0)
|
||||
close(dri2_surf->in_fence_fd);
|
||||
dri2_surf->in_fence_fd = -1;
|
||||
|
@ -497,6 +501,8 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
|
|||
|
||||
close_in_fence_fd(dri2_surf);
|
||||
|
||||
validate_fence_fd(fence_fd);
|
||||
|
||||
dri2_surf->in_fence_fd = fence_fd;
|
||||
|
||||
/* Record all the buffers created by ANativeWindow and update back buffer
|
||||
|
@ -1448,6 +1454,7 @@ droid_display_shared_buffer(__DRIdrawable *driDrawable, int fence_fd,
|
|||
}
|
||||
|
||||
close_in_fence_fd(dri2_surf);
|
||||
validate_fence_fd(fence_fd);
|
||||
dri2_surf->in_fence_fd = fence_fd;
|
||||
handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back);
|
||||
}
|
||||
|
|
|
@ -391,6 +391,8 @@ dri2_release_buffer(__DRIscreen *sPriv, __DRIbuffer *bPriv)
|
|||
static void
|
||||
dri2_set_in_fence_fd(__DRIimage *img, int fd)
|
||||
{
|
||||
validate_fence_fd(fd);
|
||||
validate_fence_fd(img->in_fence_fd);
|
||||
sync_accumulate("dri", &img->in_fence_fd, fd);
|
||||
}
|
||||
|
||||
|
@ -405,6 +407,8 @@ handle_in_fence(__DRIcontext *context, __DRIimage *img)
|
|||
if (fd == -1)
|
||||
return;
|
||||
|
||||
validate_fence_fd(fd);
|
||||
|
||||
img->in_fence_fd = -1;
|
||||
|
||||
pipe->create_fence_fd(pipe, &fence, fd, PIPE_FD_TYPE_NATIVE_SYNC);
|
||||
|
|
|
@ -199,6 +199,19 @@ static inline int sync_accumulate(const char *name, int *fd1, int fd2)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Helper macro to complain if fd is non-negative and not a valid fence fd.
|
||||
* Sprinkle this around to help catch fd lifetime issues.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
# include "util/log.h"
|
||||
# define validate_fence_fd(fd) do { \
|
||||
if (((fd) >= 0) && !sync_valid_fd(fd)) \
|
||||
mesa_loge("%s:%d: invalid fence fd: %d", __func__, __LINE__, (fd)); \
|
||||
} while (0)
|
||||
#else
|
||||
# define validate_fence_fd(fd) do {} while (0)
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue