From: Daniel Stone Date: Tue, 6 Jun 2017 10:53:55 +0000 (+0100) Subject: i965: Move fallback size assignment out of bufmgr X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78703881ffec1a465c04f9490f5192dc51db715b;p=mesa.git i965: Move fallback size assignment out of bufmgr The bufmgr took a mandatory size argument, which would only be used if the kernel size query failed, i.e. an older kernel. It didn't actually check that the BO size was sufficient for use. Pull the check out of the bufmgr, and actually check that the BO is sufficiently-sized for our import one level up. This also resolves a chicken/egg we have when importing bufers without explicit modifiers, namely that we need the tiling mode to calculate the size, but we need the BO imported to query the tiling mode. Reviewed-by: Jason Ekstrand --- diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c b/src/mesa/drivers/dri/i965/brw_bufmgr.c index 9475d2b30ac..2ee57e2a0d3 100644 --- a/src/mesa/drivers/dri/i965/brw_bufmgr.c +++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c @@ -971,8 +971,7 @@ brw_bo_get_tiling(struct brw_bo *bo, uint32_t *tiling_mode, } struct brw_bo * -brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, int prime_fd, - int size) +brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, int prime_fd) { int ret; uint32_t handle; @@ -1013,8 +1012,6 @@ brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, int prime_fd, ret = lseek(prime_fd, 0, SEEK_END); if (ret != -1) bo->size = ret; - else - bo->size = size; bo->bufmgr = bufmgr; diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.h b/src/mesa/drivers/dri/i965/brw_bufmgr.h index a11599ff79b..ec5eb4cd618 100644 --- a/src/mesa/drivers/dri/i965/brw_bufmgr.h +++ b/src/mesa/drivers/dri/i965/brw_bufmgr.h @@ -270,7 +270,7 @@ void brw_destroy_hw_context(struct brw_bufmgr *bufmgr, uint32_t ctx_id); int brw_bo_gem_export_to_prime(struct brw_bo *bo, int *prime_fd); struct brw_bo *brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, - int prime_fd, int size); + int prime_fd); int brw_reg_read(struct brw_bufmgr *bufmgr, uint32_t offset, uint64_t *result); diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c index 07af0633d67..23b7a379e0d 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.c +++ b/src/mesa/drivers/dri/i965/intel_screen.c @@ -845,6 +845,15 @@ intel_create_image_from_fds(__DRIscreen *dri_screen, image->pitch = strides[0]; image->planar_format = f; + + image->bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0]); + if (image->bo == NULL) { + free(image); + return NULL; + } + + image->modifier = tiling_to_modifier(image->bo->tiling_mode); + int size = 0; for (i = 0; i < f->nplanes; i++) { index = f->planes[i].buffer_index; @@ -857,13 +866,15 @@ intel_create_image_from_fds(__DRIscreen *dri_screen, size = end; } - image->bo = brw_bo_gem_create_from_prime(screen->bufmgr, - fds[0], size); - if (image->bo == NULL) { + /* Check that the requested image actually fits within the BO. 'size' + * is already relative to the offsets, so we don't need to add that. */ + if (image->bo->size == 0) { + image->bo->size = size; + } else if (size > image->bo->size) { + brw_bo_unreference(image->bo); free(image); return NULL; } - image->modifier = tiling_to_modifier(image->bo->tiling_mode); if (f->nplanes == 1) { image->offset = image->offsets[0];