From: Kristian H. Kristensen Date: Wed, 5 Feb 2020 01:46:10 +0000 (-0800) Subject: freedreno: Add layout_resource_for_modifier screen vfunc X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d233c8c914ce819147197b9327bc22d1ea58b2fb;p=mesa.git freedreno: Add layout_resource_for_modifier screen vfunc This function is responsible for completing the layout for an imported resource with the given modifier. Returns 0 on success or -1 If the modifier is unsupported, invalid or the input parameters are not compatible with the modifier. Part-of: --- diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index 54bf359a0cc..56f5c478b27 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -1023,26 +1023,6 @@ fd_resource_create(struct pipe_screen *pscreen, return fd_resource_create_with_modifiers(pscreen, tmpl, &mod, 1); } -static bool -is_supported_modifier(struct pipe_screen *pscreen, enum pipe_format pfmt, - uint64_t mod) -{ - int count; - - /* Get the count of supported modifiers: */ - pscreen->query_dmabuf_modifiers(pscreen, pfmt, 0, NULL, NULL, &count); - - /* Get the supported modifiers: */ - uint64_t modifiers[count]; - pscreen->query_dmabuf_modifiers(pscreen, pfmt, count, modifiers, NULL, &count); - - for (int i = 0; i < count; i++) - if (modifiers[i] == mod) - return true; - - return false; -} - /** * Create a texture from a winsys_handle. The handle is often created in * another process by first creating a pipe texture and then calling @@ -1091,20 +1071,11 @@ fd_resource_from_handle(struct pipe_screen *pscreen, (slice->pitch & (pitchalign - 1))) goto fail; - if (handle->modifier == DRM_FORMAT_MOD_QCOM_COMPRESSED) { - if (!is_supported_modifier(pscreen, tmpl->format, - DRM_FORMAT_MOD_QCOM_COMPRESSED)) { - DBG("bad modifier: %"PRIx64, handle->modifier); - goto fail; - } - /* XXX UBWC setup */ - } else if (handle->modifier && - (handle->modifier != DRM_FORMAT_MOD_INVALID)) { - goto fail; - } - assert(rsc->layout.cpp); + if (screen->layout_resource_for_modifier(rsc, handle->modifier) < 0) + goto fail; + if (screen->ro) { rsc->scanout = renderonly_create_gpu_import_for_resource(prsc, screen->ro, NULL); @@ -1210,6 +1181,17 @@ static const uint64_t supported_modifiers[] = { DRM_FORMAT_MOD_LINEAR, }; +static int +fd_layout_resource_for_modifier(struct fd_resource *rsc, uint64_t modifier) +{ + switch (modifier) { + case DRM_FORMAT_MOD_LINEAR: + return 0; + default: + return -1; + } +} + void fd_resource_screen_init(struct pipe_screen *pscreen) { @@ -1230,6 +1212,8 @@ fd_resource_screen_init(struct pipe_screen *pscreen) if (!screen->setup_slices) screen->setup_slices = fd_setup_slices; + if (!screen->layout_resource_for_modifier) + screen->layout_resource_for_modifier = fd_layout_resource_for_modifier; if (!screen->supported_modifiers) { screen->supported_modifiers = supported_modifiers; screen->num_supported_modifiers = ARRAY_SIZE(supported_modifiers); diff --git a/src/gallium/drivers/freedreno/freedreno_screen.h b/src/gallium/drivers/freedreno/freedreno_screen.h index b5730da0297..534d0a2f859 100644 --- a/src/gallium/drivers/freedreno/freedreno_screen.h +++ b/src/gallium/drivers/freedreno/freedreno_screen.h @@ -93,6 +93,7 @@ struct fd_screen { uint32_t (*setup_slices)(struct fd_resource *rsc); unsigned (*tile_mode)(const struct pipe_resource *prsc); + int (*layout_resource_for_modifier)(struct fd_resource *rsc, uint64_t modifier); /* constant emit: (note currently not used/needed for a2xx) */ void (*emit_const)(struct fd_ringbuffer *ring, gl_shader_stage type,