gallium: move get_canonical_format hook to pipe_screen

pipe_context shouldn't have functions that return values because this
prevent multithreading.

Move this hook to pipe_screen.

Fixes: 606e42027e ("gallium: add hook on getting canonical format")
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16078>
This commit is contained in:
Juan A. Suarez Romero 2022-04-21 09:49:07 +02:00 committed by Marge Bot
parent e293691a99
commit 39cebe24ae
5 changed files with 48 additions and 48 deletions

View File

@ -1156,18 +1156,6 @@ v3d_resource_get_stencil(struct pipe_resource *prsc)
return &rsc->separate_stencil->base;
}
static enum pipe_format
v3d_resource_get_compatible_tlb_format(struct pipe_context *pctx,
enum pipe_format format)
{
switch (format) {
case PIPE_FORMAT_R16G16_UNORM:
return PIPE_FORMAT_R16G16_UINT;
default:
return format;
}
}
static const struct u_transfer_vtbl transfer_vtbl = {
.resource_create = v3d_resource_create,
.resource_destroy = v3d_resource_destroy,
@ -1211,5 +1199,4 @@ v3d_resource_context_init(struct pipe_context *pctx)
pctx->blit = v3d_blit;
pctx->generate_mipmap = v3d_generate_mipmap;
pctx->flush_resource = v3d_flush_resource;
pctx->get_canonical_format = v3d_resource_get_compatible_tlb_format;
}

View File

@ -818,6 +818,18 @@ v3d_screen_is_dmabuf_modifier_supported(struct pipe_screen *pscreen,
return false;
}
static enum pipe_format
v3d_screen_get_compatible_tlb_format(struct pipe_screen *screen,
enum pipe_format format)
{
switch (format) {
case PIPE_FORMAT_R16G16_UNORM:
return PIPE_FORMAT_R16G16_UINT;
default:
return format;
}
}
struct pipe_screen *
v3d_screen_create(int fd, const struct pipe_screen_config *config,
struct renderonly *ro)
@ -834,6 +846,7 @@ v3d_screen_create(int fd, const struct pipe_screen_config *config,
pscreen->get_compute_param = v3d_get_compute_param;
pscreen->context_create = v3d_context_create;
pscreen->is_format_supported = v3d_screen_is_format_supported;
pscreen->get_canonical_format = v3d_screen_get_compatible_tlb_format;
screen->fd = fd;
screen->ro = ro;

View File

@ -999,16 +999,6 @@ struct pipe_context {
bool to_device, bool migrate_content);
/*@}*/
/**
* Return an equivalent canonical format which has the same component sizes
* and swizzles as the original, and it is supported by the driver. Gallium
* already does a first canonicalization step (see get_canonical_format()
* on st_cb_copyimage.c) and it calls this function (if defined) to get an
* alternative format if the picked is not supported by the driver.
*/
enum pipe_format (*get_canonical_format)(struct pipe_context *context,
enum pipe_format format);
/**
* Get the default sample position for an individual sample point.
*

View File

@ -169,6 +169,16 @@ struct pipe_screen {
*/
uint64_t (*get_timestamp)(struct pipe_screen *);
/**
* Return an equivalent canonical format which has the same component sizes
* and swizzles as the original, and it is supported by the driver. Gallium
* already does a first canonicalization step (see get_canonical_format()
* on st_cb_copyimage.c) and it calls this function (if defined) to get an
* alternative format if the picked is not supported by the driver.
*/
enum pipe_format (*get_canonical_format)(struct pipe_screen *,
enum pipe_format format);
/**
* Create a context.
*

View File

@ -54,7 +54,7 @@
* formats are not supported. (same as ARB_copy_image)
*/
static enum pipe_format
get_canonical_format(struct pipe_context *pipe,
get_canonical_format(struct pipe_screen *screen,
enum pipe_format format)
{
const struct util_format_description *desc =
@ -63,7 +63,7 @@ get_canonical_format(struct pipe_context *pipe,
/* Packed formats. Return the equivalent array format. */
if (format == PIPE_FORMAT_R11G11B10_FLOAT ||
format == PIPE_FORMAT_R9G9B9E5_FLOAT)
return get_canonical_format(pipe, PIPE_FORMAT_R8G8B8A8_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R8G8B8A8_UINT);
if (desc->nr_channels == 4 &&
desc->channel[0].size == 10 &&
@ -73,30 +73,30 @@ get_canonical_format(struct pipe_context *pipe,
if (desc->swizzle[0] == PIPE_SWIZZLE_X &&
desc->swizzle[1] == PIPE_SWIZZLE_Y &&
desc->swizzle[2] == PIPE_SWIZZLE_Z)
return get_canonical_format(pipe, PIPE_FORMAT_R8G8B8A8_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R8G8B8A8_UINT);
return PIPE_FORMAT_NONE;
}
#define RETURN_FOR_SWIZZLE1(x, format) \
if (desc->swizzle[0] == PIPE_SWIZZLE_##x) \
return (pipe->get_canonical_format ? \
pipe->get_canonical_format(pipe, format) : \
return (screen->get_canonical_format ? \
screen->get_canonical_format(screen, format) : \
format)
#define RETURN_FOR_SWIZZLE2(x, y, format) \
if (desc->swizzle[0] == PIPE_SWIZZLE_##x && \
desc->swizzle[1] == PIPE_SWIZZLE_##y) \
return (pipe->get_canonical_format ? \
pipe->get_canonical_format(pipe, format) : \
return (screen->get_canonical_format ? \
screen->get_canonical_format(screen, format) : \
format)
#define RETURN_FOR_SWIZZLE3(x, y, z, format) \
if (desc->swizzle[0] == PIPE_SWIZZLE_##x && \
desc->swizzle[1] == PIPE_SWIZZLE_##y && \
desc->swizzle[2] == PIPE_SWIZZLE_##z) \
return (pipe->get_canonical_format ? \
pipe->get_canonical_format(pipe, format) : \
return (screen->get_canonical_format ? \
screen->get_canonical_format(screen, format) : \
format)
#define RETURN_FOR_SWIZZLE4(x, y, z, w, format) \
@ -104,8 +104,8 @@ get_canonical_format(struct pipe_context *pipe,
desc->swizzle[1] == PIPE_SWIZZLE_##y && \
desc->swizzle[2] == PIPE_SWIZZLE_##z && \
desc->swizzle[3] == PIPE_SWIZZLE_##w) \
return (pipe->get_canonical_format ? \
pipe->get_canonical_format(pipe, format) : \
return (screen->get_canonical_format ? \
screen->get_canonical_format(screen, format) : \
format)
/* Array formats. */
@ -217,42 +217,42 @@ has_identity_swizzle(const struct util_format_description *desc)
* Return a canonical format for the given bits and channel size.
*/
static enum pipe_format
canonical_format_from_bits(struct pipe_context *pipe,
canonical_format_from_bits(struct pipe_screen *screen,
unsigned bits,
unsigned channel_size)
{
switch (bits) {
case 8:
if (channel_size == 8)
return get_canonical_format(pipe, PIPE_FORMAT_R8_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R8_UINT);
break;
case 16:
if (channel_size == 8)
return get_canonical_format(pipe, PIPE_FORMAT_R8G8_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R8G8_UINT);
if (channel_size == 16)
return get_canonical_format(pipe, PIPE_FORMAT_R16_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R16_UINT);
break;
case 32:
if (channel_size == 8)
return get_canonical_format(pipe, PIPE_FORMAT_R8G8B8A8_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R8G8B8A8_UINT);
if (channel_size == 16)
return get_canonical_format(pipe, PIPE_FORMAT_R16G16_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R16G16_UINT);
if (channel_size == 32)
return get_canonical_format(pipe, PIPE_FORMAT_R32_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R32_UINT);
break;
case 64:
if (channel_size == 16)
return get_canonical_format(pipe, PIPE_FORMAT_R16G16B16A16_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R16G16B16A16_UINT);
if (channel_size == 32)
return get_canonical_format(pipe, PIPE_FORMAT_R32G32_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R32G32_UINT);
break;
case 128:
if (channel_size == 32)
return get_canonical_format(pipe, PIPE_FORMAT_R32G32B32A32_UINT);
return get_canonical_format(screen, PIPE_FORMAT_R32G32B32A32_UINT);
break;
}
@ -307,8 +307,8 @@ swizzled_copy(struct pipe_context *pipe,
* about the channel type from this point on.
* Only the swizzle and channel size.
*/
blit_src_format = get_canonical_format(pipe, src->format);
blit_dst_format = get_canonical_format(pipe, dst->format);
blit_src_format = get_canonical_format(pipe->screen, src->format);
blit_dst_format = get_canonical_format(pipe->screen, dst->format);
assert(blit_src_format != PIPE_FORMAT_NONE);
assert(blit_dst_format != PIPE_FORMAT_NONE);
@ -329,14 +329,14 @@ swizzled_copy(struct pipe_context *pipe,
* e.g. R32 -> BGRA8 is realized as RGBA8 -> BGRA8
*/
blit_src_format =
canonical_format_from_bits(pipe, bits, dst_desc->channel[0].size);
canonical_format_from_bits(pipe->screen, bits, dst_desc->channel[0].size);
} else if (has_identity_swizzle(dst_desc)) {
/* Dst is unswizzled and src can be swizzled, so dst is typecast
* to an equivalent src-compatible format.
* e.g. BGRA8 -> R32 is realized as BGRA8 -> RGBA8
*/
blit_dst_format =
canonical_format_from_bits(pipe, bits, src_desc->channel[0].size);
canonical_format_from_bits(pipe->screen, bits, src_desc->channel[0].size);
} else {
assert(!"This should have been handled by handle_complex_copy.");
return;