summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Moreau <dev@pmoreau.org>2020-11-12 20:08:45 +0100
committerPierre Moreau <dev@pmoreau.org>2021-01-01 21:56:29 +0100
commit47feba98f3833801ec2e8fdd018081897af6c510 (patch)
tree1d70d3eae5f436fa6e0749a214fe416e4c4d8c19
parent7de14689322bf4d51ce963cb056606da4a716103 (diff)
clover/spirv: Add version conversion utilities
SPIR-V and OpenCL encodes differently version numbers and since SPIR-V version numbers are reported in OpenCL, there is a need for utilities to convert back and forth. Reviewed-by: Dave Airlie <airlied@redhat.com> Reviewed-by: Francisco Jerez <currojerez@riseup.net> Signed-off-by: Pierre Moreau <dev@pmoreau.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2078>
-rw-r--r--src/gallium/frontends/clover/spirv/invocation.cpp22
-rw-r--r--src/gallium/frontends/clover/spirv/invocation.hpp6
2 files changed, 28 insertions, 0 deletions
diff --git a/src/gallium/frontends/clover/spirv/invocation.cpp b/src/gallium/frontends/clover/spirv/invocation.cpp
index a755df18055..38b1c6398b0 100644
--- a/src/gallium/frontends/clover/spirv/invocation.cpp
+++ b/src/gallium/frontends/clover/spirv/invocation.cpp
@@ -837,6 +837,18 @@ clover::spirv::supported_versions() {
return { make_spirv_version(1u, 0u) };
}
+cl_version
+clover::spirv::to_opencl_version_encoding(uint32_t version) {
+ return CL_MAKE_VERSION((version >> 16u) & 0xff,
+ (version >> 8u) & 0xff, 0u);
+}
+
+uint32_t
+clover::spirv::to_spirv_version_encoding(cl_version version) {
+ return ((CL_VERSION_MAJOR(version) & 0xff) << 16u) |
+ ((CL_VERSION_MINOR(version) & 0xff) << 8u);
+}
+
#else
bool
clover::spirv::is_valid_spirv(const std::vector<char> &/*binary*/,
@@ -876,4 +888,14 @@ std::vector<uint32_t>
clover::spirv::supported_versions() {
return {};
}
+
+cl_version
+clover::spirv::to_opencl_version_encoding(uint32_t version) {
+ return CL_MAKE_VERSION(0u, 0u, 0u);
+}
+
+uint32_t
+clover::spirv::to_spirv_version_encoding(cl_version version) {
+ return 0u;
+}
#endif
diff --git a/src/gallium/frontends/clover/spirv/invocation.hpp b/src/gallium/frontends/clover/spirv/invocation.hpp
index f4ef93151d8..559260627c1 100644
--- a/src/gallium/frontends/clover/spirv/invocation.hpp
+++ b/src/gallium/frontends/clover/spirv/invocation.hpp
@@ -60,6 +60,12 @@ namespace clover {
// Returns a vector (sorted in increasing order) of supported SPIR-V
// versions.
std::vector<uint32_t> supported_versions();
+
+ // Converts a version number from SPIR-V's encoding to OpenCL's one.
+ cl_version to_opencl_version_encoding(uint32_t version);
+
+ // Converts a version number from OpenCL's encoding to SPIR-V's one.
+ uint32_t to_spirv_version_encoding(cl_version version);
}
}