diff --git a/src/gallium/frontends/clover/spirv/invocation.cpp b/src/gallium/frontends/clover/spirv/invocation.cpp index 38b1c6398b0..dd698829a16 100644 --- a/src/gallium/frontends/clover/spirv/invocation.cpp +++ b/src/gallium/frontends/clover/spirv/invocation.cpp @@ -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(binary.data())[0u]; + return (first_word == SpvMagicNumber) || + (util_bswap32(first_word) == SpvMagicNumber); +} + module clover::spirv::compile_program(const std::vector &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 &/*binary*/, const cl_version opencl_version, diff --git a/src/gallium/frontends/clover/spirv/invocation.hpp b/src/gallium/frontends/clover/spirv/invocation.hpp index 559260627c1..8d81a08143b 100644 --- a/src/gallium/frontends/clover/spirv/invocation.hpp +++ b/src/gallium/frontends/clover/spirv/invocation.hpp @@ -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. //