summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Moreau <dev@pmoreau.org>2020-05-18 18:08:37 +0200
committerMarge Bot <eric+marge@anholt.net>2020-08-20 19:48:12 +0000
commit2402466a08c370adb19319162ee67ead9024d57b (patch)
tree9aab1ecc65e8fa6f0e5f9deece196c36f7fb5488
parent6ed87594b12e5f794d5b19b197a5013b84cdcba8 (diff)
clover/llvm: Use the highest supported SPIR-V version (v4)
v2: a) Move `supported_spirv_verssions()` to `spirv::` (Francisco Jerez) b) Introduce a `SPV_MAKE_VERSION` macro to avoid making mistakes and making it more readable than its uint representation. v3: Replaced an if-statement with a `std::min()` in `spirv::get_spirv_translator_options()` (Karol Herbst) v4: Turn `SPV_MAKE_VERSION()` into a function (Francisco Jerez) Signed-off-by: Pierre Moreau <dev@pmoreau.org> Reviewed-by: Karol Herbst <kherbst@redhat.com> Reviewed-by: Francisco Jerez <currojerez@riseup.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5038>
-rw-r--r--src/gallium/frontends/clover/llvm/invocation.cpp16
-rw-r--r--src/gallium/frontends/clover/spirv/invocation.cpp16
-rw-r--r--src/gallium/frontends/clover/spirv/invocation.hpp4
3 files changed, 35 insertions, 1 deletions
diff --git a/src/gallium/frontends/clover/llvm/invocation.cpp b/src/gallium/frontends/clover/llvm/invocation.cpp
index 95a9d036622..04db2f90e03 100644
--- a/src/gallium/frontends/clover/llvm/invocation.cpp
+++ b/src/gallium/frontends/clover/llvm/invocation.cpp
@@ -307,6 +307,18 @@ namespace {
return act.takeModule();
}
+
+#ifdef HAVE_CLOVER_SPIRV
+ SPIRV::TranslatorOpts
+ get_spirv_translator_options(const device &dev) {
+ const auto supported_versions = spirv::supported_versions();
+ const auto maximum_spirv_version =
+ std::min(static_cast<SPIRV::VersionNumber>(supported_versions.back()),
+ SPIRV::VersionNumber::MaximumVersion);
+
+ return SPIRV::TranslatorOpts(maximum_spirv_version);
+ }
+#endif
}
module
@@ -438,6 +450,8 @@ clover::llvm::compile_to_spirv(const std::string &source,
if (has_flag(debug::llvm))
debug::log(".ll", print_module_bitcode(*mod));
+ const auto spirv_options = get_spirv_translator_options(dev);
+
std::string error_msg;
if (!::llvm::regularizeLlvmForSpirv(mod.get(), error_msg)) {
r_log += "Failed to regularize LLVM IR for SPIR-V: " + error_msg + ".\n";
@@ -445,7 +459,7 @@ clover::llvm::compile_to_spirv(const std::string &source,
}
std::ostringstream os;
- if (!::llvm::writeSpirv(mod.get(), os, error_msg)) {
+ if (!::llvm::writeSpirv(mod.get(), spirv_options, os, error_msg)) {
r_log += "Translation from LLVM IR to SPIR-V failed: " + error_msg + ".\n";
throw error(CL_INVALID_VALUE);
}
diff --git a/src/gallium/frontends/clover/spirv/invocation.cpp b/src/gallium/frontends/clover/spirv/invocation.cpp
index e4b1565288f..489bb62dde9 100644
--- a/src/gallium/frontends/clover/spirv/invocation.cpp
+++ b/src/gallium/frontends/clover/spirv/invocation.cpp
@@ -49,6 +49,12 @@ using namespace clover;
#ifdef HAVE_CLOVER_SPIRV
namespace {
+ uint32_t
+ make_spirv_version(uint8_t major, uint8_t minor) {
+ return (static_cast<uint32_t>(major) << 16u) |
+ (static_cast<uint32_t>(minor) << 8u);
+ }
+
template<typename T>
T get(const char *source, size_t index) {
const uint32_t *word_ptr = reinterpret_cast<const uint32_t *>(source);
@@ -715,6 +721,11 @@ clover::spirv::supported_extensions() {
};
}
+std::vector<uint32_t>
+clover::spirv::supported_versions() {
+ return { make_spirv_version(1u, 0u) };
+}
+
#else
bool
clover::spirv::is_valid_spirv(const std::vector<char> &/*binary*/,
@@ -748,4 +759,9 @@ std::unordered_set<std::string>
clover::spirv::supported_extensions() {
return {};
}
+
+std::vector<uint32_t>
+clover::spirv::supported_versions() {
+ return {};
+}
#endif
diff --git a/src/gallium/frontends/clover/spirv/invocation.hpp b/src/gallium/frontends/clover/spirv/invocation.hpp
index 49a183ffc04..27f8d8c1934 100644
--- a/src/gallium/frontends/clover/spirv/invocation.hpp
+++ b/src/gallium/frontends/clover/spirv/invocation.hpp
@@ -55,6 +55,10 @@ namespace clover {
// Returns a set of supported SPIR-V extensions.
std::unordered_set<std::string> supported_extensions();
+
+ // Returns a vector (sorted in increasing order) of supported SPIR-V
+ // versions.
+ std::vector<uint32_t> supported_versions();
}
}