mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 02:10:11 +01:00
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>
This commit is contained in:
parent
6ed87594b1
commit
2402466a08
3 changed files with 35 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue