- /* Internally, formats that are depth/stencil renderable are limited.
- *
- * In particular: Z16, Z24, Z24S8, S8 are all identical from the GPU
- * rendering perspective. That is, we render to Z24S8 (which we can
- * AFBC compress), ignore the different when texturing (who cares?),
- * and then in the off-chance there's a CPU read we blit back to
- * staging.
- *
- * ...alternatively, we can make the state tracker deal with that. */
-
- if (bind & PIPE_BIND_DEPTH_STENCIL) {
- switch (format) {
- case PIPE_FORMAT_Z24_UNORM_S8_UINT:
- case PIPE_FORMAT_Z24X8_UNORM:
- case PIPE_FORMAT_Z32_UNORM:
- case PIPE_FORMAT_Z32_FLOAT:
- case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
- return true;
-
- default:
- return false;
+ return fmt.hw && ((relevant_bind & ~fmt.bind) == 0);
+}
+
+/* We always support linear and tiled operations, both external and internal.
+ * We support AFBC for a subset of formats, and colourspace transform for a
+ * subset of those. */
+
+static void
+panfrost_query_dmabuf_modifiers(struct pipe_screen *screen,
+ enum pipe_format format, int max, uint64_t *modifiers, unsigned
+ int *external_only, int *out_count)
+{
+ /* Query AFBC status */
+ bool afbc = panfrost_format_supports_afbc(format);
+ bool ytr = panfrost_afbc_can_ytr(format);
+
+ /* Don't advertise AFBC before T760 */
+ struct panfrost_device *dev = pan_device(screen);
+ afbc &= !(dev->quirks & MIDGARD_NO_AFBC);
+
+ /* XXX: AFBC scanout is broken on mainline RK3399 with older kernels */
+ afbc &= (dev->debug & PAN_DBG_AFBC);
+
+ unsigned count = 0;
+
+ for (unsigned i = 0; i < PAN_MODIFIER_COUNT; ++i) {
+ if (drm_is_afbc(pan_best_modifiers[i]) && !afbc)
+ continue;
+
+ if ((pan_best_modifiers[i] & AFBC_FORMAT_MOD_YTR) && !ytr)
+ continue;
+
+ count++;
+
+ if (max > (int) count) {
+ modifiers[count] = pan_best_modifiers[i];
+
+ if (external_only)
+ external_only[count] = false;