+static bool
+is_format_supported(struct pipe_screen *screen, enum pipe_format format,
+ unsigned nr_samples, unsigned usage)
+{
+ bool supported = screen->is_format_supported(screen, format, PIPE_TEXTURE_2D,
+ nr_samples, usage);
+
+ /* for sampling, some formats can be emulated.. it doesn't matter that
+ * the surface will have a format that the driver can't cope with because
+ * we'll give it sampler view formats that it can deal with and generate
+ * a shader variant that converts.
+ */
+ if ((usage == PIPE_BIND_SAMPLER_VIEW) && !supported) {
+ if (format == PIPE_FORMAT_IYUV) {
+ supported = screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM,
+ PIPE_TEXTURE_2D, nr_samples,
+ usage);
+ } else if (format == PIPE_FORMAT_NV12) {
+ supported = screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM,
+ PIPE_TEXTURE_2D, nr_samples,
+ usage) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM,
+ PIPE_TEXTURE_2D, nr_samples,
+ usage);
+ }
+ }
+
+ return supported;
+}