Mesa (master): clover/spirv: rework handling of spirv extensions

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 20 20:07:33 UTC 2020


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

Author: Karol Herbst <kherbst at redhat.com>
Date:   Sat Aug 15 13:19:52 2020 +0200

clover/spirv: rework handling of spirv extensions

What extensions we support depends on spirv_to_nir but it doesn't give us a
list. So hardcode one and add extensions we know we support and hit in the
wild.

v2: move into spirv lib

Signed-off-by: Karol Herbst <kherbst at redhat.com>
Reviewed-by: Pierre Moreau <dev at pmoreau.org>
Reviewed-by: Francisco Jerez <currojerez at riseup.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5038>

---

 src/gallium/frontends/clover/spirv/invocation.cpp | 25 +++++++++++++++--------
 src/gallium/frontends/clover/spirv/invocation.hpp |  5 +++++
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/gallium/frontends/clover/spirv/invocation.cpp b/src/gallium/frontends/clover/spirv/invocation.cpp
index 01ced45c13b..9353b56d326 100644
--- a/src/gallium/frontends/clover/spirv/invocation.cpp
+++ b/src/gallium/frontends/clover/spirv/invocation.cpp
@@ -433,6 +433,7 @@ namespace {
                     std::string &r_log) {
       const size_t length = source.size() / sizeof(uint32_t);
       size_t i = SPIRV_HEADER_WORD_SIZE; // Skip header
+      const auto spirv_extensions = spirv::supported_extensions();
 
       while (i < length) {
          const auto desc_word = get<uint32_t>(source.data(), i);
@@ -446,14 +447,9 @@ namespace {
          if (opcode != SpvOpExtension)
             break;
 
-         const char *extension = source.data() + (i + 1u) * sizeof(uint32_t);
-         const std::string device_extensions = dev.supported_extensions();
-         const std::string platform_extensions =
-            dev.platform.supported_extensions();
-         if (device_extensions.find(extension) == std::string::npos &&
-             platform_extensions.find(extension) == std::string::npos) {
-            r_log += "Extension '" + std::string(extension) +
-                     "' is not supported.\n";
+         const std::string extension = source.data() + (i + 1u) * sizeof(uint32_t);
+         if (spirv_extensions.count(extension) == 0) {
+            r_log += "Extension '" + extension + "' is not supported.\n";
             return false;
          }
 
@@ -709,6 +705,14 @@ clover::spirv::print_module(const std::vector<char> &binary,
    return disassemblyStr;
 }
 
+std::unordered_set<std::string>
+clover::spirv::supported_extensions() {
+   return {
+      /* this is only a hint so all devices support that */
+      "SPV_KHR_no_integer_wrap_decoration"
+   };
+}
+
 #else
 bool
 clover::spirv::is_valid_spirv(const std::vector<char> &/*binary*/,
@@ -737,4 +741,9 @@ clover::spirv::print_module(const std::vector<char> &binary,
                             const std::string &opencl_version) {
    return std::string();
 }
+
+std::unordered_set<std::string>
+clover::spirv::supported_extensions() {
+   return {};
+}
 #endif
diff --git a/src/gallium/frontends/clover/spirv/invocation.hpp b/src/gallium/frontends/clover/spirv/invocation.hpp
index 472d8c0de71..49a183ffc04 100644
--- a/src/gallium/frontends/clover/spirv/invocation.hpp
+++ b/src/gallium/frontends/clover/spirv/invocation.hpp
@@ -23,6 +23,8 @@
 #ifndef CLOVER_SPIRV_INVOCATION_HPP
 #define CLOVER_SPIRV_INVOCATION_HPP
 
+#include <unordered_set>
+
 #include "core/context.hpp"
 #include "core/module.hpp"
 #include "core/program.hpp"
@@ -50,6 +52,9 @@ namespace clover {
       // Returns a textual representation of the given binary.
       std::string print_module(const std::vector<char> &binary,
                                const std::string &opencl_version);
+
+      // Returns a set of supported SPIR-V extensions.
+      std::unordered_set<std::string> supported_extensions();
    }
 }
 



More information about the mesa-commit mailing list