From 43390a546d96ac87ce4b5004c425fa61d25922c1 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 7 Oct 2020 09:01:43 +1000 Subject: [PATCH] clover: Use core libclc loader v2 (Jason Ekstrand): - Use the newly added nir_can_find_libclc() helper Reviewed-by: Jason Ekstrand Reviewed-by: Jesse Natalie Part-of: --- src/gallium/frontends/clover/core/device.cpp | 4 +- src/gallium/frontends/clover/core/device.hpp | 1 - .../frontends/clover/nir/invocation.cpp | 59 +++---------------- .../frontends/clover/nir/invocation.hpp | 5 +- .../frontends/clover/spirv/invocation.cpp | 23 -------- .../frontends/clover/spirv/invocation.hpp | 3 - 6 files changed, 14 insertions(+), 81 deletions(-) diff --git a/src/gallium/frontends/clover/core/device.cpp b/src/gallium/frontends/clover/core/device.cpp index dc0766c4243..7d3b0d61a2a 100644 --- a/src/gallium/frontends/clover/core/device.cpp +++ b/src/gallium/frontends/clover/core/device.cpp @@ -55,9 +55,9 @@ device::device(clover::platform &platform, pipe_loader_device *ldev) : return; #ifdef HAVE_CLOVER_SPIRV if (supports_ir(PIPE_SHADER_IR_NIR_SERIALIZED)) { + nir::check_for_libclc(*this); clc_cache = nir::create_clc_disk_cache(); - clc = spirv::load_clc(*this); - clc_nir = lazy>([&] () { std::string log; return std::shared_ptr(nir::libclc_spirv_to_nir(clc, *this, log), ralloc_free); }); + clc_nir = lazy>([&] () { std::string log; return std::shared_ptr(nir::load_libclc_nir(*this, log), ralloc_free); }); return; } #endif diff --git a/src/gallium/frontends/clover/core/device.hpp b/src/gallium/frontends/clover/core/device.hpp index 2599787716a..c681b4c4979 100644 --- a/src/gallium/frontends/clover/core/device.hpp +++ b/src/gallium/frontends/clover/core/device.hpp @@ -106,7 +106,6 @@ namespace clover { return svm_support() & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM; } - module clc; lazy> clc_nir; disk_cache *clc_cache; private: diff --git a/src/gallium/frontends/clover/nir/invocation.cpp b/src/gallium/frontends/clover/nir/invocation.cpp index f3dd26f2016..a5c3f99ad93 100644 --- a/src/gallium/frontends/clover/nir/invocation.cpp +++ b/src/gallium/frontends/clover/nir/invocation.cpp @@ -200,60 +200,19 @@ struct disk_cache *clover::nir::create_clc_disk_cache(void) return disk_cache_create("clover-clc", cache_id, 0); } -nir_shader *clover::nir::libclc_spirv_to_nir(const module &mod, const device &dev, - std::string &r_log) +void clover::nir::check_for_libclc(const device &dev) +{ + if (!nir_can_find_libclc(dev.address_bits())) + throw error(CL_COMPILER_NOT_AVAILABLE); +} + +nir_shader *clover::nir::load_libclc_nir(const device &dev, std::string &r_log) { spirv_to_nir_options spirv_options = create_spirv_options(dev, r_log); - spirv_options.create_library = true; - - auto §ion = mod.secs[0]; - const auto *binary = - reinterpret_cast(section.data.data()); - const uint32_t *data = reinterpret_cast(binary->blob); - const size_t num_words = binary->num_bytes / 4; auto *compiler_options = dev_get_nir_compiler_options(dev); - unsigned char clc_cache_key[20]; - unsigned char sha1[CACHE_KEY_SIZE]; - /* caching ftw. */ - struct mesa_sha1 ctx; - size_t binary_size = 0; - uint8_t *buffer = NULL; - if (dev.clc_cache) { - _mesa_sha1_init(&ctx); - _mesa_sha1_update(&ctx, data, num_words * 4); - _mesa_sha1_final(&ctx, clc_cache_key); - - disk_cache_compute_key(dev.clc_cache, clc_cache_key, 20, sha1); - - buffer = (uint8_t *)disk_cache_get(dev.clc_cache, sha1, &binary_size); - } - - nir_shader *nir; - if (!buffer) { - nir = spirv_to_nir(data, num_words, nullptr, 0, - MESA_SHADER_KERNEL, "clcspirv", - &spirv_options, compiler_options); - nir_validate_shader(nir, "clover-libclc"); - nir->info.internal = true; - NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp); - NIR_PASS_V(nir, nir_lower_returns); - - if (dev.clc_cache) { - struct blob blob = { 0 }; - blob_init(&blob); - nir_serialize(&blob, nir, true); - disk_cache_put(dev.clc_cache, sha1, blob.data, blob.size, NULL); - blob_finish(&blob); - } - } else { - struct blob_reader blob_read; - blob_reader_init(&blob_read, buffer, binary_size); - nir = nir_deserialize(NULL, compiler_options, &blob_read); - free(buffer); - } - - return nir; + return nir_load_libclc_shader(dev.address_bits(), dev.clc_cache, + &spirv_options, compiler_options); } module clover::nir::spirv_to_nir(const module &mod, const device &dev, diff --git a/src/gallium/frontends/clover/nir/invocation.hpp b/src/gallium/frontends/clover/nir/invocation.hpp index 62ae4ecd247..4d2acedc684 100644 --- a/src/gallium/frontends/clover/nir/invocation.hpp +++ b/src/gallium/frontends/clover/nir/invocation.hpp @@ -31,9 +31,10 @@ struct nir_shader; namespace clover { class device; namespace nir { + void check_for_libclc(const device &dev); + // converts libclc spirv into nir - nir_shader *libclc_spirv_to_nir(const module &mod, const device &dev, - std::string &r_log); + nir_shader *load_libclc_nir(const device &dev, std::string &r_log); struct disk_cache *create_clc_disk_cache(void); diff --git a/src/gallium/frontends/clover/spirv/invocation.cpp b/src/gallium/frontends/clover/spirv/invocation.cpp index a460ce17897..2249895802f 100644 --- a/src/gallium/frontends/clover/spirv/invocation.cpp +++ b/src/gallium/frontends/clover/spirv/invocation.cpp @@ -876,26 +876,3 @@ clover::spirv::supported_versions() { return {}; } #endif - -module -clover::spirv::load_clc(const device &dev) -{ - std::vector 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(length)); - file.read(&ilfile.front(), static_cast(length)); - } - - std::string log; - return spirv::compile_program(ilfile, dev, log, false); -} diff --git a/src/gallium/frontends/clover/spirv/invocation.hpp b/src/gallium/frontends/clover/spirv/invocation.hpp index 9d954671183..5fa76cf4c9c 100644 --- a/src/gallium/frontends/clover/spirv/invocation.hpp +++ b/src/gallium/frontends/clover/spirv/invocation.hpp @@ -60,9 +60,6 @@ namespace clover { // Returns a vector (sorted in increasing order) of supported SPIR-V // versions. std::vector supported_versions(); - - // Load the SPIR-V for the CLC module. - module load_clc(const device &dev); } }