dri: Unify createImage and createImageWithModifiers

There's no real reason for the two to exist separately. Nuke the old
createImage in favour of just having createImageWithModifiers.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30245>
This commit is contained in:
Daniel Stone
2024-06-05 18:56:54 +01:00
committed by Marge Bot
parent 4072809149
commit 361f362258
9 changed files with 54 additions and 82 deletions

View File

@@ -2885,7 +2885,7 @@ dri2_create_drm_image_mesa(_EGLDisplay *disp, const EGLint *attr_list)
dri2_img->dri_image =
dri2_dpy->image->createImage(dri2_dpy->dri_screen_render_gpu, attrs.Width,
attrs.Height, format, dri_use, dri2_img);
attrs.Height, format, NULL, 0, dri_use, dri2_img);
if (dri2_img->dri_image == NULL) {
free(dri2_img);
_eglError(EGL_BAD_ALLOC, "dri2_create_drm_image_mesa");

View File

@@ -492,7 +492,7 @@ get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
} else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
dri2_surf->dri_image_front = dri2_dpy->image->createImage(
dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
dri2_surf->base.Height, format, 0, NULL);
dri2_surf->base.Height, format, NULL, 0, 0, NULL);
if (!dri2_surf->dri_image_front) {
_eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
return -1;

View File

@@ -50,7 +50,7 @@ device_alloc_image(struct dri2_egl_display *dri2_dpy,
{
return dri2_dpy->image->createImage(
dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
dri2_surf->base.Height, dri2_surf->visual, 0, NULL);
dri2_surf->base.Height, dri2_surf->visual, NULL, 0, 0, NULL);
}
static void

View File

@@ -45,7 +45,7 @@ surfaceless_alloc_image(struct dri2_egl_display *dri2_dpy,
{
return dri2_dpy->image->createImage(
dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
dri2_surf->base.Height, dri2_surf->visual, 0, NULL);
dri2_surf->base.Height, dri2_surf->visual, NULL, 0, 0, NULL);
}
static void

View File

@@ -1148,12 +1148,13 @@ dri2_get_modifier_num_planes(__DRIscreen *_screen,
}
static __DRIimage *
dri2_create_image_common(__DRIscreen *_screen,
int width, int height,
int format, unsigned int use,
const uint64_t *modifiers,
const unsigned count,
void *loaderPrivate)
dri2_create_image(__DRIscreen *_screen,
int width, int height,
int format,
const uint64_t *modifiers,
const unsigned _count,
unsigned int use,
void *loaderPrivate)
{
const struct dri2_format_mapping *map = dri2_get_mapping_by_format(format);
struct dri_screen *screen = dri_screen(_screen);
@@ -1161,10 +1162,25 @@ dri2_create_image_common(__DRIscreen *_screen,
__DRIimage *img;
struct pipe_resource templ;
unsigned tex_usage = 0;
unsigned count = _count;
if (!map)
return NULL;
if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID) {
count = 0;
modifiers = NULL;
} else if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_LINEAR &&
!pscreen->resource_create_with_modifiers) {
count = 0;
modifiers = NULL;
use |= __DRI_IMAGE_USE_LINEAR;
}
else if ((count > 1 || modifiers) &&
!pscreen->resource_create_with_modifiers) {
return NULL;
}
if (pscreen->is_format_supported(pscreen, map->pipe_format, screen->target,
0, 0, PIPE_BIND_RENDER_TARGET))
tex_usage |= PIPE_BIND_RENDER_TARGET;
@@ -1235,27 +1251,6 @@ dri2_create_image_common(__DRIscreen *_screen,
return img;
}
static __DRIimage *
dri2_create_image(__DRIscreen *_screen,
int width, int height, int format,
unsigned int use, void *loaderPrivate)
{
return dri2_create_image_common(_screen, width, height, format, use,
NULL /* modifiers */, 0 /* count */,
loaderPrivate);
}
static __DRIimage *
dri2_create_image_with_modifiers(__DRIscreen *dri_screen,
int width, int height, int format,
const uint64_t *modifiers,
const unsigned count, unsigned int use,
void *loaderPrivate)
{
return dri2_create_image_common(dri_screen, width, height, format, use,
modifiers, count, loaderPrivate);
}
static bool
dri2_query_image_common(__DRIimage *image, int attrib, int *value)
{
@@ -1932,7 +1927,6 @@ static const __DRIimageExtension dri2ImageExtensionTempl = {
.getCapabilities = dri2_get_capabilities,
.mapImage = dri2_map_image,
.unmapImage = dri2_unmap_image,
.createImageWithModifiers = NULL,
.queryDmaBufFormats = NULL,
.queryDmaBufModifiers = NULL,
.queryDmaBufFormatModifierAttribs = NULL,
@@ -1957,7 +1951,6 @@ const __DRIimageExtension driVkImageExtension = {
.getCapabilities = dri2_get_capabilities,
.mapImage = dri2_map_image,
.unmapImage = dri2_unmap_image,
.createImageWithModifiers = dri2_create_image_with_modifiers,
.queryDmaBufFormats = dri2_query_dma_buf_formats,
.queryDmaBufModifiers = dri2_query_dma_buf_modifiers,
.queryDmaBufFormatModifierAttribs = dri2_query_dma_buf_format_modifier_attribs,
@@ -2209,10 +2202,6 @@ dri2_init_screen_extensions(struct dri_screen *screen,
nExt = &screen->screen_extensions[ARRAY_SIZE(dri_screen_extensions_base)];
screen->image_extension = dri2ImageExtensionTempl;
if (pscreen->resource_create_with_modifiers) {
screen->image_extension.createImageWithModifiers =
dri2_create_image_with_modifiers;
}
if (pscreen->get_param(pscreen, PIPE_CAP_NATIVE_FENCE_FD)) {
screen->image_extension.setInFenceFd = dri2_set_in_fence_fd;

View File

@@ -1429,11 +1429,6 @@ struct __DRIimageExtensionRec {
void (*destroyImage)(__DRIimage *image);
__DRIimage *(*createImage)(__DRIscreen *screen,
int width, int height, int format,
unsigned int use,
void *loaderPrivate);
unsigned char (*queryImage)(__DRIimage *image, int attrib, int *value);
/**
@@ -1635,6 +1630,10 @@ struct __DRIimageExtensionRec {
* Creates an image with implementation's favorite modifiers and the
* provided usage flags.
*
* Passing either zero modifiers, or a modifier list consisting only
* of DRM_FORMAT_MOD_INVALID, allows the implementation to select a
* layout with implicit modifiers.
*
* The created image should be destroyed with destroyImage().
*
* Returns the new DRIimage. The chosen modifier can be obtained later on
@@ -1644,12 +1643,12 @@ struct __DRIimageExtensionRec {
*
* \since 19
*/
__DRIimage *(*createImageWithModifiers)(__DRIscreen *screen,
int width, int height, int format,
const uint64_t *modifiers,
const unsigned int modifier_count,
unsigned int use,
void *loaderPrivate);
__DRIimage *(*createImage)(__DRIscreen *screen,
int width, int height, int format,
const uint64_t *modifiers,
const unsigned int modifier_count,
unsigned int use,
void *loaderPrivate);
/**
* Set an in-fence-fd on the image. If a fence-fd is already set

View File

@@ -972,11 +972,6 @@ gbm_dri_bo_create(struct gbm_device *gbm,
/* Gallium drivers requires shared in order to get the handle/stride */
dri_use |= __DRI_IMAGE_USE_SHARE;
if (modifiers && !dri->image->createImageWithModifiers) {
errno = ENOSYS;
goto failed;
}
/* If the driver supports fixed-rate compression, filter the acceptable
* modifiers by the compression rate. */
if (modifiers && dri->image->queryCompressionModifiers) {
@@ -1154,14 +1149,8 @@ gbm_dri_surface_create(struct gbm_device *gbm,
uint32_t format, uint32_t flags,
const uint64_t *modifiers, const unsigned count)
{
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_surface *surf;
if (modifiers && !dri->image->createImageWithModifiers) {
errno = ENOSYS;
return NULL;
}
if (count)
assert(modifiers);

View File

@@ -1462,8 +1462,7 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
if (draw->dri_screen_render_gpu == draw->dri_screen_display_gpu) {
#ifdef HAVE_DRI3_MODIFIERS
if (draw->multiplanes_available &&
draw->ext->image->queryDmaBufModifiers &&
draw->ext->image->createImageWithModifiers) {
draw->ext->image->queryDmaBufModifiers) {
xcb_dri3_get_supported_modifiers_cookie_t mod_cookie;
xcb_dri3_get_supported_modifiers_reply_t *mod_reply;
xcb_generic_error_t *error = NULL;
@@ -1528,11 +1527,10 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
if (!buffer->image)
goto no_image;
} else {
buffer->image = draw->ext->image->createImage(draw->dri_screen_render_gpu,
width, height,
format,
0,
buffer);
buffer->image =
draw->ext->image->createImage(draw->dri_screen_render_gpu,
width, height, format,
NULL, 0, 0, buffer);
if (!buffer->image)
goto no_image;
@@ -1546,6 +1544,7 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
draw->ext->image->createImage(draw->dri_screen_display_gpu,
width, height,
dri3_linear_format_for_format(draw, format),
NULL, 0,
__DRI_IMAGE_USE_SHARE |
__DRI_IMAGE_USE_LINEAR |
__DRI_IMAGE_USE_BACKBUFFER |
@@ -1557,14 +1556,15 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
if (!pixmap_buffer) {
buffer->linear_buffer =
draw->ext->image->createImage(draw->dri_screen_render_gpu,
width, height,
dri3_linear_format_for_format(draw, format),
__DRI_IMAGE_USE_SHARE |
__DRI_IMAGE_USE_LINEAR |
__DRI_IMAGE_USE_BACKBUFFER |
__DRI_IMAGE_USE_SCANOUT |
__DRI_IMAGE_USE_PRIME_BUFFER,
buffer);
width, height,
dri3_linear_format_for_format(draw, format),
NULL, 0,
__DRI_IMAGE_USE_SHARE |
__DRI_IMAGE_USE_LINEAR |
__DRI_IMAGE_USE_BACKBUFFER |
__DRI_IMAGE_USE_SCANOUT |
__DRI_IMAGE_USE_PRIME_BUFFER,
buffer);
pixmap_buffer = buffer->linear_buffer;
if (!buffer->linear_buffer) {

View File

@@ -38,7 +38,7 @@ __DRIimage *loader_dri_create_image(__DRIscreen *screen,
unsigned int modifiers_count,
void *loaderPrivate)
{
if (modifiers && modifiers_count > 0 && image->createImageWithModifiers) {
if (modifiers && modifiers_count > 0) {
bool has_valid_modifier = false;
int i;
@@ -56,15 +56,10 @@ __DRIimage *loader_dri_create_image(__DRIscreen *screen,
}
if (!has_valid_modifier)
return NULL;
return image->createImageWithModifiers(screen, width, height,
dri_format, modifiers,
modifiers_count, dri_usage,
loaderPrivate);
}
/* No modifier given or fallback to the legacy createImage allowed */
return image->createImage(screen, width, height, dri_format, dri_usage,
return image->createImage(screen, width, height, dri_format,
modifiers, modifiers_count, dri_usage,
loaderPrivate);
}