clover/spirv: Add function checking whether a binary contains SPIR-V
v2: Change API to take a std::string Reviewed-by: Karol Herbst <kherbst@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:
parent
47feba98f3
commit
a1db84be7a
|
@ -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
|
||||
clover::spirv::compile_program(const std::vector<char> &binary,
|
||||
const device &dev, std::string &r_log,
|
||||
|
@ -850,6 +864,12 @@ clover::spirv::to_spirv_version_encoding(cl_version version) {
|
|||
}
|
||||
|
||||
#else
|
||||
bool
|
||||
clover::spirv::is_binary_spirv(const std::string &binary)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
clover::spirv::is_valid_spirv(const std::vector<char> &/*binary*/,
|
||||
const cl_version opencl_version,
|
||||
|
|
|
@ -31,6 +31,12 @@
|
|||
|
||||
namespace clover {
|
||||
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
|
||||
// OpenCL version.
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue