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>
This commit is contained in:
Pierre Moreau 2020-11-12 20:08:45 +01:00
parent 7de1468932
commit 47feba98f3
2 changed files with 28 additions and 0 deletions

View file

@ -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

View file

@ -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);
}
}