gallium/dri: Allow use of R8G8_R8B8 for YUYV and G8R8_B8R8 for UYVY
v2: Add missing FALLTHROUGH. Caught by CI. Reviewed-by: Emma Anholt <emma@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9610>
This commit is contained in:
parent
880b00dc59
commit
f57c074270
|
@ -739,6 +739,24 @@ static const struct dri2_format_mapping r8_g8b8_mapping = {
|
||||||
{ 1, 1, 1, __DRI_IMAGE_FORMAT_GR88 } }
|
{ 1, 1, 1, __DRI_IMAGE_FORMAT_GR88 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct dri2_format_mapping r8g8_r8b8_mapping = {
|
||||||
|
DRM_FORMAT_YUYV,
|
||||||
|
__DRI_IMAGE_FORMAT_NONE,
|
||||||
|
__DRI_IMAGE_COMPONENTS_Y_XUXV,
|
||||||
|
PIPE_FORMAT_R8G8_R8B8_UNORM, 2,
|
||||||
|
{ { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88 },
|
||||||
|
{ 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888 } }
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct dri2_format_mapping g8r8_b8r8_mapping = {
|
||||||
|
DRM_FORMAT_UYVY,
|
||||||
|
__DRI_IMAGE_FORMAT_NONE,
|
||||||
|
__DRI_IMAGE_COMPONENTS_Y_XUXV,
|
||||||
|
PIPE_FORMAT_G8R8_B8R8_UNORM, 2,
|
||||||
|
{ { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88 },
|
||||||
|
{ 0, 1, 0, __DRI_IMAGE_FORMAT_ABGR8888 } }
|
||||||
|
};
|
||||||
|
|
||||||
static __DRIimage *
|
static __DRIimage *
|
||||||
dri2_create_image_from_winsys(__DRIscreen *_screen,
|
dri2_create_image_from_winsys(__DRIscreen *_screen,
|
||||||
int width, int height, const struct dri2_format_mapping *map,
|
int width, int height, const struct dri2_format_mapping *map,
|
||||||
|
@ -772,6 +790,23 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
|
||||||
tex_usage |= PIPE_BIND_SAMPLER_VIEW;
|
tex_usage |= PIPE_BIND_SAMPLER_VIEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the hardware supports R8G8_R8B8 style subsampled RGB formats, these
|
||||||
|
* can be used for YUYV and UYVY formats.
|
||||||
|
*/
|
||||||
|
if (!tex_usage && map->pipe_format == PIPE_FORMAT_YUYV &&
|
||||||
|
pscreen->is_format_supported(pscreen, PIPE_FORMAT_R8G8_R8B8_UNORM,
|
||||||
|
screen->target, 0, 0, PIPE_BIND_SAMPLER_VIEW)) {
|
||||||
|
map = &r8g8_r8b8_mapping;
|
||||||
|
tex_usage |= PIPE_BIND_SAMPLER_VIEW;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tex_usage && map->pipe_format == PIPE_FORMAT_UYVY &&
|
||||||
|
pscreen->is_format_supported(pscreen, PIPE_FORMAT_G8R8_B8R8_UNORM,
|
||||||
|
screen->target, 0, 0, PIPE_BIND_SAMPLER_VIEW)) {
|
||||||
|
map = &g8r8_b8r8_mapping;
|
||||||
|
tex_usage |= PIPE_BIND_SAMPLER_VIEW;
|
||||||
|
}
|
||||||
|
|
||||||
if (!tex_usage && util_format_is_yuv(map->pipe_format)) {
|
if (!tex_usage && util_format_is_yuv(map->pipe_format)) {
|
||||||
/* YUV format sampling can be emulated by the GL gallium frontend by
|
/* YUV format sampling can be emulated by the GL gallium frontend by
|
||||||
* using multiple samplers of varying formats.
|
* using multiple samplers of varying formats.
|
||||||
|
|
|
@ -363,6 +363,12 @@ update_shader_samplers(struct st_context *st,
|
||||||
case PIPE_FORMAT_Y216:
|
case PIPE_FORMAT_Y216:
|
||||||
case PIPE_FORMAT_YUYV:
|
case PIPE_FORMAT_YUYV:
|
||||||
case PIPE_FORMAT_UYVY:
|
case PIPE_FORMAT_UYVY:
|
||||||
|
if (stObj->pt->format == PIPE_FORMAT_R8G8_R8B8_UNORM ||
|
||||||
|
stObj->pt->format == PIPE_FORMAT_G8R8_B8R8_UNORM) {
|
||||||
|
/* no additional views needed */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* we need one additional sampler: */
|
/* we need one additional sampler: */
|
||||||
extra = u_bit_scan(&free_slots);
|
extra = u_bit_scan(&free_slots);
|
||||||
states[extra] = sampler;
|
states[extra] = sampler;
|
||||||
|
|
|
@ -221,6 +221,10 @@ update_textures(struct st_context *st,
|
||||||
pipe->create_sampler_view(pipe, stObj->pt->next->next, &tmpl);
|
pipe->create_sampler_view(pipe, stObj->pt->next->next, &tmpl);
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_YUYV:
|
case PIPE_FORMAT_YUYV:
|
||||||
|
if (stObj->pt->format == PIPE_FORMAT_R8G8_R8B8_UNORM)
|
||||||
|
/* no additional views needed */
|
||||||
|
break;
|
||||||
|
|
||||||
/* we need one additional BGRA8888 view: */
|
/* we need one additional BGRA8888 view: */
|
||||||
tmpl.format = PIPE_FORMAT_BGRA8888_UNORM;
|
tmpl.format = PIPE_FORMAT_BGRA8888_UNORM;
|
||||||
tmpl.swizzle_b = PIPE_SWIZZLE_Z;
|
tmpl.swizzle_b = PIPE_SWIZZLE_Z;
|
||||||
|
@ -230,6 +234,10 @@ update_textures(struct st_context *st,
|
||||||
pipe->create_sampler_view(pipe, stObj->pt->next, &tmpl);
|
pipe->create_sampler_view(pipe, stObj->pt->next, &tmpl);
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_UYVY:
|
case PIPE_FORMAT_UYVY:
|
||||||
|
if (stObj->pt->format == PIPE_FORMAT_G8R8_B8R8_UNORM)
|
||||||
|
/* no additional views needed */
|
||||||
|
break;
|
||||||
|
|
||||||
/* we need one additional RGBA8888 view: */
|
/* we need one additional RGBA8888 view: */
|
||||||
tmpl.format = PIPE_FORMAT_RGBA8888_UNORM;
|
tmpl.format = PIPE_FORMAT_RGBA8888_UNORM;
|
||||||
tmpl.swizzle_b = PIPE_SWIZZLE_Z;
|
tmpl.swizzle_b = PIPE_SWIZZLE_Z;
|
||||||
|
|
|
@ -101,20 +101,26 @@ is_format_supported(struct pipe_screen *screen, enum pipe_format format,
|
||||||
nr_storage_samples, usage);
|
nr_storage_samples, usage);
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_YUYV:
|
case PIPE_FORMAT_YUYV:
|
||||||
supported = screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
|
supported = screen->is_format_supported(screen, PIPE_FORMAT_R8G8_R8B8_UNORM,
|
||||||
PIPE_TEXTURE_2D, nr_samples,
|
PIPE_TEXTURE_2D, nr_samples,
|
||||||
nr_storage_samples, usage) &&
|
nr_storage_samples, usage) ||
|
||||||
screen->is_format_supported(screen, PIPE_FORMAT_BGRA8888_UNORM,
|
(screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
|
||||||
PIPE_TEXTURE_2D, nr_samples,
|
PIPE_TEXTURE_2D, nr_samples,
|
||||||
nr_storage_samples, usage);
|
nr_storage_samples, usage) &&
|
||||||
|
screen->is_format_supported(screen, PIPE_FORMAT_BGRA8888_UNORM,
|
||||||
|
PIPE_TEXTURE_2D, nr_samples,
|
||||||
|
nr_storage_samples, usage));
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_UYVY:
|
case PIPE_FORMAT_UYVY:
|
||||||
supported = screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
|
supported = screen->is_format_supported(screen, PIPE_FORMAT_G8R8_B8R8_UNORM,
|
||||||
PIPE_TEXTURE_2D, nr_samples,
|
PIPE_TEXTURE_2D, nr_samples,
|
||||||
nr_storage_samples, usage) &&
|
nr_storage_samples, usage) ||
|
||||||
screen->is_format_supported(screen, PIPE_FORMAT_RGBA8888_UNORM,
|
(screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
|
||||||
PIPE_TEXTURE_2D, nr_samples,
|
PIPE_TEXTURE_2D, nr_samples,
|
||||||
nr_storage_samples, usage);
|
nr_storage_samples, usage) &&
|
||||||
|
screen->is_format_supported(screen, PIPE_FORMAT_RGBA8888_UNORM,
|
||||||
|
PIPE_TEXTURE_2D, nr_samples,
|
||||||
|
nr_storage_samples, usage));
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_AYUV:
|
case PIPE_FORMAT_AYUV:
|
||||||
supported = screen->is_format_supported(screen, PIPE_FORMAT_RGBA8888_UNORM,
|
supported = screen->is_format_supported(screen, PIPE_FORMAT_RGBA8888_UNORM,
|
||||||
|
@ -327,8 +333,16 @@ st_bind_egl_image(struct gl_context *ctx,
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_YUYV:
|
case PIPE_FORMAT_YUYV:
|
||||||
case PIPE_FORMAT_UYVY:
|
case PIPE_FORMAT_UYVY:
|
||||||
texFormat = MESA_FORMAT_RG_UNORM8;
|
if (stimg->texture->format == PIPE_FORMAT_R8G8_R8B8_UNORM) {
|
||||||
texObj->RequiredTextureImageUnits = 2;
|
texFormat = MESA_FORMAT_RG_RB_UNORM8;
|
||||||
|
texObj->RequiredTextureImageUnits = 1;
|
||||||
|
} else if (stimg->texture->format == PIPE_FORMAT_G8R8_B8R8_UNORM) {
|
||||||
|
texFormat = MESA_FORMAT_GR_BR_UNORM8;
|
||||||
|
texObj->RequiredTextureImageUnits = 1;
|
||||||
|
} else {
|
||||||
|
texFormat = MESA_FORMAT_RG_UNORM8;
|
||||||
|
texObj->RequiredTextureImageUnits = 2;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_AYUV:
|
case PIPE_FORMAT_AYUV:
|
||||||
texFormat = MESA_FORMAT_R8G8B8A8_UNORM;
|
texFormat = MESA_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
|
|
@ -1455,7 +1455,8 @@ st_create_fp_variant(struct st_context *st,
|
||||||
if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv ||
|
if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv ||
|
||||||
key->external.lower_xy_uxvx || key->external.lower_yx_xuxv ||
|
key->external.lower_xy_uxvx || key->external.lower_yx_xuxv ||
|
||||||
key->external.lower_ayuv || key->external.lower_xyuv ||
|
key->external.lower_ayuv || key->external.lower_xyuv ||
|
||||||
key->external.lower_yuv || key->external.lower_y41x)) {
|
key->external.lower_yuv || key->external.lower_yu_yv ||
|
||||||
|
key->external.lower_y41x)) {
|
||||||
|
|
||||||
st_nir_lower_samplers(st->screen, state.ir.nir,
|
st_nir_lower_samplers(st->screen, state.ir.nir,
|
||||||
stfp->shader_program, &stfp->Base);
|
stfp->shader_program, &stfp->Base);
|
||||||
|
@ -1468,6 +1469,7 @@ st_create_fp_variant(struct st_context *st,
|
||||||
options.lower_ayuv_external = key->external.lower_ayuv;
|
options.lower_ayuv_external = key->external.lower_ayuv;
|
||||||
options.lower_xyuv_external = key->external.lower_xyuv;
|
options.lower_xyuv_external = key->external.lower_xyuv;
|
||||||
options.lower_yuv_external = key->external.lower_yuv;
|
options.lower_yuv_external = key->external.lower_yuv;
|
||||||
|
options.lower_yu_yv_external = key->external.lower_yu_yv;
|
||||||
options.lower_y41x_external = key->external.lower_y41x;
|
options.lower_y41x_external = key->external.lower_y41x;
|
||||||
NIR_PASS_V(state.ir.nir, nir_lower_tex, &options);
|
NIR_PASS_V(state.ir.nir, nir_lower_tex, &options);
|
||||||
finalize = true;
|
finalize = true;
|
||||||
|
|
|
@ -58,6 +58,7 @@ struct st_external_sampler_key
|
||||||
GLuint lower_ayuv;
|
GLuint lower_ayuv;
|
||||||
GLuint lower_xyuv;
|
GLuint lower_xyuv;
|
||||||
GLuint lower_yuv;
|
GLuint lower_yuv;
|
||||||
|
GLuint lower_yu_yv;
|
||||||
GLuint lower_y41x;
|
GLuint lower_y41x;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -95,12 +96,21 @@ st_get_external_sampler_key(struct st_context *st, struct gl_program *prog)
|
||||||
key.lower_iyuv |= (1 << unit);
|
key.lower_iyuv |= (1 << unit);
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_YUYV:
|
case PIPE_FORMAT_YUYV:
|
||||||
|
if (stObj->pt->format == PIPE_FORMAT_R8G8_R8B8_UNORM) {
|
||||||
|
key.lower_yu_yv |= (1 << unit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
FALLTHROUGH;
|
||||||
case PIPE_FORMAT_Y210:
|
case PIPE_FORMAT_Y210:
|
||||||
case PIPE_FORMAT_Y212:
|
case PIPE_FORMAT_Y212:
|
||||||
case PIPE_FORMAT_Y216:
|
case PIPE_FORMAT_Y216:
|
||||||
key.lower_yx_xuxv |= (1 << unit);
|
key.lower_yx_xuxv |= (1 << unit);
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_UYVY:
|
case PIPE_FORMAT_UYVY:
|
||||||
|
if (stObj->pt->format == PIPE_FORMAT_G8R8_B8R8_UNORM) {
|
||||||
|
key.lower_yu_yv |= (1 << unit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
key.lower_xy_uxvx |= (1 << unit);
|
key.lower_xy_uxvx |= (1 << unit);
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_AYUV:
|
case PIPE_FORMAT_AYUV:
|
||||||
|
|
|
@ -525,6 +525,11 @@ get_sampler_view_format(struct st_context *st,
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_YUYV:
|
case PIPE_FORMAT_YUYV:
|
||||||
case PIPE_FORMAT_UYVY:
|
case PIPE_FORMAT_UYVY:
|
||||||
|
if (stObj->pt->format == PIPE_FORMAT_R8G8_R8B8_UNORM ||
|
||||||
|
stObj->pt->format == PIPE_FORMAT_G8R8_B8R8_UNORM) {
|
||||||
|
format = stObj->pt->format;
|
||||||
|
break;
|
||||||
|
}
|
||||||
format = PIPE_FORMAT_R8G8_UNORM;
|
format = PIPE_FORMAT_R8G8_UNORM;
|
||||||
break;
|
break;
|
||||||
case PIPE_FORMAT_AYUV:
|
case PIPE_FORMAT_AYUV:
|
||||||
|
|
Loading…
Reference in New Issue