Mesa (master): clover/llvm: Use the highest supported SPIR-V version (v4)
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Aug 20 20:07:33 UTC 2020
Module: Mesa
Branch: master
Commit: 2402466a08c370adb19319162ee67ead9024d57b
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2402466a08c370adb19319162ee67ead9024d57b
Author: Pierre Moreau <dev at pmoreau.org>
Date: Mon May 18 18:08:37 2020 +0200
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 at pmoreau.org>
Reviewed-by: Karol Herbst <kherbst at redhat.com>
Reviewed-by: Francisco Jerez <currojerez at riseup.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5038>
---
src/gallium/frontends/clover/llvm/invocation.cpp | 16 +++++++++++++++-
src/gallium/frontends/clover/spirv/invocation.cpp | 16 ++++++++++++++++
src/gallium/frontends/clover/spirv/invocation.hpp | 4 ++++
3 files changed, 35 insertions(+), 1 deletion(-)
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();
}
}
More information about the mesa-commit
mailing list