diff options
Diffstat (limited to 'src/gallium/frontends/clover/spirv/invocation.cpp')
-rw-r--r-- | src/gallium/frontends/clover/spirv/invocation.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/gallium/frontends/clover/spirv/invocation.cpp b/src/gallium/frontends/clover/spirv/invocation.cpp index c3404f38b80..d86ff4cf905 100644 --- a/src/gallium/frontends/clover/spirv/invocation.cpp +++ b/src/gallium/frontends/clover/spirv/invocation.cpp @@ -569,10 +569,11 @@ namespace { module clover::spirv::compile_program(const std::vector<char> &binary, - const device &dev, std::string &r_log) { + const device &dev, std::string &r_log, + bool validate) { std::vector<char> source = spirv_to_cpu(binary); - if (!is_valid_spirv(source, dev.device_version(), r_log)) + if (!is_valid_spirv(source, dev.device_version(), r_log, validate)) throw build_error(); if (!check_capabilities(dev, source, r_log)) @@ -626,7 +627,6 @@ clover::spirv::link_program(const std::vector<module> &modules, const char *message) { r_log += format_validator_msg(level, source, position, message); }; - for (const auto &mod : modules) { const auto &msec = find([](const module::section &sec) { return sec.type == module::section::text_intermediate || @@ -675,7 +675,8 @@ clover::spirv::link_program(const std::vector<module> &modules, bool clover::spirv::is_valid_spirv(const std::vector<char> &binary, const std::string &opencl_version, - std::string &r_log) { + std::string &r_log, + bool validate) { auto const validator_consumer = [&r_log](spv_message_level_t level, const char *source, const spv_position_t &position, const char *message) { @@ -687,6 +688,8 @@ clover::spirv::is_valid_spirv(const std::vector<char> &binary, spvtools::SpirvTools spvTool(target_env); spvTool.SetMessageConsumer(validator_consumer); + if (!validate) + return true; return spvTool.Validate(reinterpret_cast<const uint32_t *>(binary.data()), binary.size() / 4u); } @@ -731,13 +734,14 @@ clover::spirv::supported_versions() { bool clover::spirv::is_valid_spirv(const std::vector<char> &/*binary*/, const std::string &/*opencl_version*/, - std::string &/*r_log*/) { + std::string &/*r_log*/, bool /*validate*/) { return false; } module clover::spirv::compile_program(const std::vector<char> &binary, - const device &dev, std::string &r_log) { + const device &dev, std::string &r_log, + bool validate) { r_log += "SPIR-V support in clover is not enabled.\n"; throw build_error(); } @@ -766,3 +770,26 @@ clover::spirv::supported_versions() { return {}; } #endif + +module +clover::spirv::load_clc(const device &dev) +{ + std::vector<char> ilfile; + std::ifstream file; + std::string name32 = "spirv-mesa3d-.spv"; + std::string name64 = "spirv64-mesa3d-.spv"; + file.open(LIBCLC_LIBEXECDIR + (dev.address_bits() == 64 ? name64 : name32), std::ifstream::in | std::ifstream::binary); + if (!file.good()) + throw error(CL_COMPILER_NOT_AVAILABLE); + + file.seekg(0, std::ios::end); + std::streampos length(file.tellg()); + if (length) { + file.seekg(0, std::ios::beg); + ilfile.resize(static_cast<std::size_t>(length)); + file.read(&ilfile.front(), static_cast<std::size_t>(length)); + } + + std::string log; + return spirv::compile_program(ilfile, dev, log, false); +} |