diff options
5 files changed, 32 insertions, 25 deletions
diff --git a/src/gallium/state_trackers/clover/core/compiler.hpp b/src/gallium/state_trackers/clover/core/compiler.hpp index c68aa39db85..207641785ca 100644 --- a/src/gallium/state_trackers/clover/core/compiler.hpp +++ b/src/gallium/state_trackers/clover/core/compiler.hpp @@ -37,7 +37,8 @@ namespace clover { const std::string &opts, std::string &r_log); - module compile_program_tgsi(const std::string &source); + module compile_program_tgsi(const std::string &source, + std::string &r_log); } #endif diff --git a/src/gallium/state_trackers/clover/core/error.hpp b/src/gallium/state_trackers/clover/core/error.hpp index 780b973383a..59a5af4c799 100644 --- a/src/gallium/state_trackers/clover/core/error.hpp +++ b/src/gallium/state_trackers/clover/core/error.hpp @@ -65,9 +65,9 @@ namespace clover { cl_int code; }; - class build_error : public error { + class compile_error : public error { public: - build_error(const std::string &what = "") : + compile_error(const std::string &what = "") : error(CL_COMPILE_PROGRAM_FAILURE, what) { } }; diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp index 0d6cc402db7..6eebd9c5cda 100644 --- a/src/gallium/state_trackers/clover/core/program.cpp +++ b/src/gallium/state_trackers/clover/core/program.cpp @@ -56,14 +56,14 @@ program::build(const ref_vector<device> &devs, const char *opts, try { auto module = (dev.ir_format() == PIPE_SHADER_IR_TGSI ? - compile_program_tgsi(_source) : + compile_program_tgsi(_source, log) : compile_program_llvm(_source, headers, dev.ir_format(), dev.ir_target(), build_opts(dev), log)); _binaries.insert({ &dev, module }); _logs.insert({ &dev, log }); - } catch (const build_error &) { + } catch (const error &) { _logs.insert({ &dev, log }); throw; } diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp index 9b91fee9032..967284d8094 100644 --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp @@ -108,7 +108,7 @@ namespace { name, llvm::MemoryBuffer::getMemBuffer(source)); if (!c.ExecuteAction(act)) - throw build_error(log); + throw compile_error(log); } module @@ -256,7 +256,7 @@ namespace { r_log = log; if (!ExecSuccess) - throw build_error(); + throw compile_error(); // Get address spaces map to be able to find kernel argument address space memcpy(address_spaces, c.getTarget().getAddressSpaceMap(), @@ -485,7 +485,7 @@ namespace { LLVMDisposeMessage(err_message); if (err) { - throw build_error(); + throw compile_error(); } } @@ -505,7 +505,7 @@ namespace { if (LLVMGetTargetFromTriple(triple.c_str(), &target, &error_message)) { r_log = std::string(error_message); LLVMDisposeMessage(error_message); - throw build_error(); + throw compile_error(); } LLVMTargetMachineRef tm = LLVMCreateTargetMachine( @@ -514,7 +514,7 @@ namespace { if (!tm) { r_log = "Could not create TargetMachine: " + triple; - throw build_error(); + throw compile_error(); } if (dump_asm) { @@ -567,7 +567,7 @@ namespace { const char *name; if (gelf_getshdr(section, &symtab_header) != &symtab_header) { r_log = "Failed to read ELF section header."; - throw build_error(); + throw compile_error(); } name = elf_strptr(elf, section_str_index, symtab_header.sh_name); if (!strcmp(name, ".symtab")) { @@ -577,9 +577,9 @@ namespace { } if (!symtab) { r_log = "Unable to find symbol table."; - throw build_error(); + throw compile_error(); } - } catch (build_error &e) { + } catch (compile_error &e) { elf_end(elf); throw e; } @@ -650,7 +650,7 @@ namespace { stream.flush(); *(std::string*)data = message; - throw build_error(); + throw compile_error(); } } diff --git a/src/gallium/state_trackers/clover/tgsi/compiler.cpp b/src/gallium/state_trackers/clover/tgsi/compiler.cpp index b70104e7604..54cb747e6fb 100644 --- a/src/gallium/state_trackers/clover/tgsi/compiler.cpp +++ b/src/gallium/state_trackers/clover/tgsi/compiler.cpp @@ -32,7 +32,7 @@ using namespace clover; namespace { void - read_header(const std::string &header, module &m) { + read_header(const std::string &header, module &m, std::string &r_log) { std::istringstream ls(header); std::string line; @@ -45,8 +45,10 @@ namespace { if (!(ts >> name)) continue; - if (!(ts >> offset)) - throw build_error("invalid kernel start address"); + if (!(ts >> offset)) { + r_log = "invalid kernel start address"; + throw compile_error(); + } while (ts >> tok) { if (tok == "scalar") @@ -67,8 +69,10 @@ namespace { args.push_back({ module::argument::image3d_wr, 4 }); else if (tok == "sampler") args.push_back({ module::argument::sampler, 0 }); - else - throw build_error("invalid kernel argument"); + else { + r_log = "invalid kernel argument"; + throw compile_error(); + } } m.syms.push_back({ name, 0, offset, args }); @@ -76,11 +80,13 @@ namespace { } void - read_body(const char *source, module &m) { + read_body(const char *source, module &m, std::string &r_log) { tgsi_token prog[1024]; - if (!tgsi_text_translate(source, prog, Elements(prog))) - throw build_error("translate failed"); + if (!tgsi_text_translate(source, prog, Elements(prog))) { + r_log = "translate failed"; + throw compile_error(); + } unsigned sz = tgsi_num_tokens(prog) * sizeof(tgsi_token); std::vector<char> data( (char *)prog, (char *)prog + sz ); @@ -89,13 +95,13 @@ namespace { } module -clover::compile_program_tgsi(const std::string &source) { +clover::compile_program_tgsi(const std::string &source, std::string &r_log) { const size_t body_pos = source.find("COMP\n"); const char *body = &source[body_pos]; module m; - read_header({ source.begin(), source.begin() + body_pos }, m); - read_body(body, m); + read_header({ source.begin(), source.begin() + body_pos }, m, r_log); + read_body(body, m, r_log); return m; } |