asahi: Use pixel table in is_format_supported
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 31 May 2021 19:34:40 +0000 (15:34 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 1 Jun 2021 01:31:02 +0000 (01:31 +0000)
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11086>

src/asahi/lib/agx_formats.h
src/gallium/drivers/asahi/agx_pipe.c

index 052e30d..2ed84a1 100644 (file)
@@ -28,9 +28,6 @@
 #include "util/format/u_format.h"
 #include "asahi/compiler/agx_compile.h"
 
-/* N.b. hardware=0 corresponds to R8 UNORM, which is renderable. So a zero
- * entry indicates an invalid format. */
-
 struct agx_pixel_format_entry {
    uint16_t hw;
    bool renderable : 1;
@@ -39,4 +36,14 @@ struct agx_pixel_format_entry {
 extern const struct agx_pixel_format_entry agx_pixel_format[PIPE_FORMAT_COUNT];
 extern const enum agx_format agx_vertex_format[PIPE_FORMAT_COUNT];
 
+/* N.b. hardware=0 corresponds to R8 UNORM, which is renderable. So a zero
+ * entry indicates an invalid format. */
+
+static inline bool
+agx_is_valid_pixel_format(enum pipe_format format)
+{
+   struct agx_pixel_format_entry entry = agx_pixel_format[format];
+   return (entry.hw != 0) || entry.renderable;
+}
+
 #endif
index e306375..17dd911 100644 (file)
@@ -43,6 +43,7 @@
 #include "asahi/compiler/agx_compile.h"
 #include "asahi/lib/decode.h"
 #include "asahi/lib/tiling.h"
+#include "asahi/lib/agx_formats.h"
 
 static const struct debug_named_value agx_debug_options[] = {
    {"trace",     AGX_DBG_TRACE,    "Trace the command stream"},
@@ -904,9 +905,15 @@ agx_is_format_supported(struct pipe_screen* pscreen,
    if (MAX2(sample_count, 1) != MAX2(storage_sample_count, 1))
       return false;
 
-   /* TODO: formats */
-   if (usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW))
-      return (format == PIPE_FORMAT_B8G8R8A8_UNORM);
+   if (usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) {
+      struct agx_pixel_format_entry ent = agx_pixel_format[format];
+
+      if (!agx_is_valid_pixel_format(format))
+         return false;
+
+      if ((usage & PIPE_BIND_RENDER_TARGET) && !ent.renderable)
+         return false;
+   }
 
    /* TODO: formats */
    if (usage & PIPE_BIND_VERTEX_BUFFER) {