Mesa (master): vc4: Use runtime CPU detection for whether NEON is available.

Eric Anholt anholt at kemper.freedesktop.org
Tue May 2 20:36:43 UTC 2017


Module: Mesa
Branch: master
Commit: ece06defe77a77d2db40abeddee5a2e0e45654ce
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ece06defe77a77d2db40abeddee5a2e0e45654ce

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Apr 13 11:48:22 2017 -0700

vc4: Use runtime CPU detection for whether NEON is available.

This will allow Raspbian's ARMv6 builds to take advantage of the new NEON
code, and could prevent problems if vc4 ends up getting used on a v7 CPU
without NEON.

v2: Drop dead NEON_SUFFIX (noted by Erik Faye-Lund)

---

 src/gallium/drivers/vc4/vc4_screen.c |  3 +++
 src/gallium/drivers/vc4/vc4_tiling.h | 27 +++++++++++++--------------
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/src/gallium/drivers/vc4/vc4_screen.c b/src/gallium/drivers/vc4/vc4_screen.c
index 5bc0141c72..d116748324 100644
--- a/src/gallium/drivers/vc4/vc4_screen.c
+++ b/src/gallium/drivers/vc4/vc4_screen.c
@@ -27,6 +27,7 @@
 #include "pipe/p_screen.h"
 #include "pipe/p_state.h"
 
+#include "util/u_cpu_detect.h"
 #include "util/u_debug.h"
 #include "util/u_memory.h"
 #include "util/u_format.h"
@@ -629,6 +630,8 @@ vc4_screen_create(int fd)
         if (!vc4_get_chip_info(screen))
                 goto fail;
 
+        util_cpu_detect();
+
         slab_create_parent(&screen->transfer_pool, sizeof(struct vc4_transfer), 16);
 
         vc4_fence_init(screen);
diff --git a/src/gallium/drivers/vc4/vc4_tiling.h b/src/gallium/drivers/vc4/vc4_tiling.h
index ba1ad6fb3f..3168ec20a6 100644
--- a/src/gallium/drivers/vc4/vc4_tiling.h
+++ b/src/gallium/drivers/vc4/vc4_tiling.h
@@ -27,6 +27,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include "util/macros.h"
+#include "util/u_cpu_detect.h"
 
 /** Return the width in pixels of a 64-byte microtile. */
 static inline uint32_t
@@ -83,23 +84,18 @@ void vc4_store_tiled_image(void *dst, uint32_t dst_stride,
                            uint8_t tiling_format, int cpp,
                            const struct pipe_box *box);
 
-/* If we're building for ARMv7 (Pi 2+), assume it has NEON.  For Raspbian we
- * should extend this to have some runtime detection of being built for ARMv6
- * on a Pi 2+.
- */
-#if defined(__ARM_ARCH) && __ARM_ARCH == 7
-#define NEON_SUFFIX(x) x ## _neon
-#else
-#define NEON_SUFFIX(x) x ## _base
-#endif
-
 static inline void
 vc4_load_lt_image(void *dst, uint32_t dst_stride,
                   void *src, uint32_t src_stride,
                   int cpp, const struct pipe_box *box)
 {
-        NEON_SUFFIX(vc4_load_lt_image)(dst, dst_stride, src, src_stride,
+        if (util_cpu_caps.has_neon) {
+                vc4_load_lt_image_neon(dst, dst_stride, src, src_stride,
                                        cpp, box);
+        } else {
+                vc4_load_lt_image_base(dst, dst_stride, src, src_stride,
+                                       cpp, box);
+        }
 }
 
 static inline void
@@ -107,10 +103,13 @@ vc4_store_lt_image(void *dst, uint32_t dst_stride,
                    void *src, uint32_t src_stride,
                    int cpp, const struct pipe_box *box)
 {
-        NEON_SUFFIX(vc4_store_lt_image)(dst, dst_stride, src, src_stride,
+        if (util_cpu_caps.has_neon) {
+                vc4_store_lt_image_neon(dst, dst_stride, src, src_stride,
                                         cpp, box);
+        } else {
+                vc4_store_lt_image_base(dst, dst_stride, src, src_stride,
+                                        cpp, box);
+        }
 }
 
-#undef NEON_SUFFIX
-
 #endif /* VC4_TILING_H */




More information about the mesa-commit mailing list