+static unsigned
+intel_loader_get_cap(const __DRIscreen *dri_screen, enum dri_loader_cap cap)
+{
+ if (dri_screen->dri2.loader && dri_screen->dri2.loader->base.version >= 4 &&
+ dri_screen->dri2.loader->getCapability)
+ return dri_screen->dri2.loader->getCapability(dri_screen->loaderPrivate, cap);
+
+ if (dri_screen->image.loader && dri_screen->image.loader->base.version >= 2 &&
+ dri_screen->image.loader->getCapability)
+ return dri_screen->image.loader->getCapability(dri_screen->loaderPrivate, cap);
+
+ return 0;
+}
+
+static bool
+intel_allowed_format(__DRIscreen *dri_screen, mesa_format format)
+{
+ struct intel_screen *screen = dri_screen->driverPrivate;
+
+ /* Expose only BGRA ordering if the loader doesn't support RGBA ordering. */
+ bool allow_rgba_ordering = intel_loader_get_cap(dri_screen, DRI_LOADER_CAP_RGBA_ORDERING);
+ if (!allow_rgba_ordering &&
+ (format == MESA_FORMAT_R8G8B8A8_UNORM ||
+ format == MESA_FORMAT_R8G8B8X8_UNORM ||
+ format == MESA_FORMAT_R8G8B8A8_SRGB))
+ return false;
+
+ /* Shall we expose 10 bpc formats? */
+ bool allow_rgb10_configs = driQueryOptionb(&screen->optionCache,
+ "allow_rgb10_configs");
+ if (!allow_rgb10_configs &&
+ (format == MESA_FORMAT_B10G10R10A2_UNORM ||
+ format == MESA_FORMAT_B10G10R10X2_UNORM))
+ return false;
+
+ /* Shall we expose 565 formats? */
+ bool allow_rgb565_configs = driQueryOptionb(&screen->optionCache,
+ "allow_rgb565_configs");
+ if (!allow_rgb565_configs && format == MESA_FORMAT_B5G6R5_UNORM)
+ return false;
+
+ /* Shall we expose fp16 formats? */
+ bool allow_fp16_configs = driQueryOptionb(&screen->optionCache,
+ "allow_fp16_configs");
+ allow_fp16_configs &= intel_loader_get_cap(dri_screen, DRI_LOADER_CAP_FP16);
+ if (!allow_fp16_configs &&
+ (format == MESA_FORMAT_RGBA_FLOAT16 ||
+ format == MESA_FORMAT_RGBX_FLOAT16))
+ return false;
+
+ return true;
+}
+