Commit a1db84be authored by Pierre Moreau's avatar Pierre Moreau
Browse files

clover/spirv: Add function checking whether a binary contains SPIR-V



v2: Change API to take a std::string
Reviewed-by: Karol Herbst's avatarKarol Herbst <kherbst@redhat.com>
Reviewed-by: Francisco Jerez's avatarFrancisco Jerez <currojerez@riseup.net>
Signed-off-by: Pierre Moreau's avatarPierre Moreau <dev@pmoreau.org>
Part-of: <mesa/mesa!2078>
parent 47feba98
...@@ -676,6 +676,20 @@ namespace { ...@@ -676,6 +676,20 @@ namespace {
} }
bool
clover::spirv::is_binary_spirv(const std::string &binary)
{
// A SPIR-V binary is at the very least 5 32-bit words, which represent the
// SPIR-V header.
if (binary.size() < 20u)
return false;
const uint32_t first_word =
reinterpret_cast<const uint32_t *>(binary.data())[0u];
return (first_word == SpvMagicNumber) ||
(util_bswap32(first_word) == SpvMagicNumber);
}
module module
clover::spirv::compile_program(const std::vector<char> &binary, clover::spirv::compile_program(const std::vector<char> &binary,
const device &dev, std::string &r_log, const device &dev, std::string &r_log,
...@@ -850,6 +864,12 @@ clover::spirv::to_spirv_version_encoding(cl_version version) { ...@@ -850,6 +864,12 @@ clover::spirv::to_spirv_version_encoding(cl_version version) {
} }
#else #else
bool
clover::spirv::is_binary_spirv(const std::string &binary)
{
return false;
}
bool bool
clover::spirv::is_valid_spirv(const std::vector<char> &/*binary*/, clover::spirv::is_valid_spirv(const std::vector<char> &/*binary*/,
const cl_version opencl_version, const cl_version opencl_version,
......
...@@ -31,6 +31,12 @@ ...@@ -31,6 +31,12 @@
namespace clover { namespace clover {
namespace spirv { namespace spirv {
// Returns whether the binary starts with the SPIR-V magic word.
//
// The first word is interpreted as little endian and big endian, but
// only one of them has to match.
bool is_binary_spirv(const std::string &binary);
// Returns whether the given binary is considered valid for the given // Returns whether the given binary is considered valid for the given
// OpenCL version. // OpenCL version.
// //
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment