diff options
| author | 2021-05-27 17:51:00 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:34 -0400 | |
| commit | b7764c3a796e53ac74009bc7d7cd153c64b6d743 (patch) | |
| tree | 592a8be7cd43349cbabfc3d84693b443ddc0b5d8 /src/shader_recompiler | |
| parent | glasm: Use integer lod for TXQ (diff) | |
| download | yuzu-b7764c3a796e53ac74009bc7d7cd153c64b6d743.tar.gz yuzu-b7764c3a796e53ac74009bc7d7cd153c64b6d743.tar.xz yuzu-b7764c3a796e53ac74009bc7d7cd153c64b6d743.zip | |
shader: Handle host exceptions
Diffstat (limited to 'src/shader_recompiler')
| -rw-r--r-- | src/shader_recompiler/exception.h | 40 | ||||
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/opcodes.cpp | 2 | ||||
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/program.cpp | 1 | ||||
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate/translate.cpp | 13 |
4 files changed, 43 insertions, 13 deletions
diff --git a/src/shader_recompiler/exception.h b/src/shader_recompiler/exception.h index 6fe620801..013d7b1bf 100644 --- a/src/shader_recompiler/exception.h +++ b/src/shader_recompiler/exception.h | |||
| @@ -5,38 +5,62 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <stdexcept> | 7 | #include <stdexcept> |
| 8 | #include <string> | ||
| 9 | #include <string_view> | ||
| 8 | #include <utility> | 10 | #include <utility> |
| 9 | 11 | ||
| 10 | #include <fmt/format.h> | 12 | #include <fmt/format.h> |
| 11 | 13 | ||
| 12 | namespace Shader { | 14 | namespace Shader { |
| 13 | 15 | ||
| 14 | class LogicError : public std::logic_error { | 16 | class Exception : public std::exception { |
| 17 | public: | ||
| 18 | explicit Exception(std::string message_) noexcept : message{std::move(message_)} {} | ||
| 19 | |||
| 20 | const char* what() const override { | ||
| 21 | return message.c_str(); | ||
| 22 | } | ||
| 23 | |||
| 24 | void Prepend(std::string_view prepend) { | ||
| 25 | message.insert(0, prepend); | ||
| 26 | } | ||
| 27 | |||
| 28 | void Append(std::string_view append) { | ||
| 29 | message += append; | ||
| 30 | } | ||
| 31 | |||
| 32 | private: | ||
| 33 | std::string message; | ||
| 34 | }; | ||
| 35 | |||
| 36 | class LogicError : public Exception { | ||
| 15 | public: | 37 | public: |
| 16 | template <typename... Args> | 38 | template <typename... Args> |
| 17 | LogicError(const char* message, Args&&... args) | 39 | LogicError(const char* message, Args&&... args) |
| 18 | : std::logic_error{fmt::format(message, std::forward<Args>(args)...)} {} | 40 | : Exception{fmt::format(message, std::forward<Args>(args)...)} {} |
| 19 | }; | 41 | }; |
| 20 | 42 | ||
| 21 | class RuntimeError : public std::runtime_error { | 43 | class RuntimeError : public Exception { |
| 22 | public: | 44 | public: |
| 23 | template <typename... Args> | 45 | template <typename... Args> |
| 24 | RuntimeError(const char* message, Args&&... args) | 46 | RuntimeError(const char* message, Args&&... args) |
| 25 | : std::runtime_error{fmt::format(message, std::forward<Args>(args)...)} {} | 47 | : Exception{fmt::format(message, std::forward<Args>(args)...)} {} |
| 26 | }; | 48 | }; |
| 27 | 49 | ||
| 28 | class NotImplementedException : public std::logic_error { | 50 | class NotImplementedException : public Exception { |
| 29 | public: | 51 | public: |
| 30 | template <typename... Args> | 52 | template <typename... Args> |
| 31 | NotImplementedException(const char* message, Args&&... args) | 53 | NotImplementedException(const char* message, Args&&... args) |
| 32 | : std::logic_error{fmt::format(message, std::forward<Args>(args)...)} {} | 54 | : Exception{fmt::format(message, std::forward<Args>(args)...)} { |
| 55 | Append(" is not implemented"); | ||
| 56 | } | ||
| 33 | }; | 57 | }; |
| 34 | 58 | ||
| 35 | class InvalidArgument : public std::invalid_argument { | 59 | class InvalidArgument : public Exception { |
| 36 | public: | 60 | public: |
| 37 | template <typename... Args> | 61 | template <typename... Args> |
| 38 | InvalidArgument(const char* message, Args&&... args) | 62 | InvalidArgument(const char* message, Args&&... args) |
| 39 | : std::invalid_argument{fmt::format(message, std::forward<Args>(args)...)} {} | 63 | : Exception{fmt::format(message, std::forward<Args>(args)...)} {} |
| 40 | }; | 64 | }; |
| 41 | 65 | ||
| 42 | } // namespace Shader | 66 | } // namespace Shader |
diff --git a/src/shader_recompiler/frontend/maxwell/opcodes.cpp b/src/shader_recompiler/frontend/maxwell/opcodes.cpp index 12ddf2ac9..ccc40c20c 100644 --- a/src/shader_recompiler/frontend/maxwell/opcodes.cpp +++ b/src/shader_recompiler/frontend/maxwell/opcodes.cpp | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | namespace Shader::Maxwell { | 10 | namespace Shader::Maxwell { |
| 11 | namespace { | 11 | namespace { |
| 12 | constexpr std::array NAME_TABLE{ | 12 | constexpr std::array NAME_TABLE{ |
| 13 | #define INST(name, cute, encode) #cute, | 13 | #define INST(name, cute, encode) cute, |
| 14 | #include "maxwell.inc" | 14 | #include "maxwell.inc" |
| 15 | #undef INST | 15 | #undef INST |
| 16 | }; | 16 | }; |
diff --git a/src/shader_recompiler/frontend/maxwell/program.cpp b/src/shader_recompiler/frontend/maxwell/program.cpp index ccdab1dad..900fc7ab1 100644 --- a/src/shader_recompiler/frontend/maxwell/program.cpp +++ b/src/shader_recompiler/frontend/maxwell/program.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <ranges> | 7 | #include <ranges> |
| 8 | #include <vector> | 8 | #include <vector> |
| 9 | 9 | ||
| 10 | #include "shader_recompiler/exception.h" | ||
| 10 | #include "shader_recompiler/frontend/ir/basic_block.h" | 11 | #include "shader_recompiler/frontend/ir/basic_block.h" |
| 11 | #include "shader_recompiler/frontend/ir/post_order.h" | 12 | #include "shader_recompiler/frontend/ir/post_order.h" |
| 12 | #include "shader_recompiler/frontend/maxwell/program.h" | 13 | #include "shader_recompiler/frontend/maxwell/program.h" |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/translate.cpp b/src/shader_recompiler/frontend/maxwell/translate/translate.cpp index 0f4e7a251..8e3c4c5d5 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/translate.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/translate.cpp | |||
| @@ -30,16 +30,21 @@ void Translate(Environment& env, IR::Block* block, u32 location_begin, u32 locat | |||
| 30 | TranslatorVisitor visitor{env, *block}; | 30 | TranslatorVisitor visitor{env, *block}; |
| 31 | for (Location pc = location_begin; pc != location_end; ++pc) { | 31 | for (Location pc = location_begin; pc != location_end; ++pc) { |
| 32 | const u64 insn{env.ReadInstruction(pc.Offset())}; | 32 | const u64 insn{env.ReadInstruction(pc.Offset())}; |
| 33 | const Opcode opcode{Decode(insn)}; | 33 | try { |
| 34 | switch (opcode) { | 34 | const Opcode opcode{Decode(insn)}; |
| 35 | switch (opcode) { | ||
| 35 | #define INST(name, cute, mask) \ | 36 | #define INST(name, cute, mask) \ |
| 36 | case Opcode::name: \ | 37 | case Opcode::name: \ |
| 37 | Invoke<&TranslatorVisitor::name>(visitor, pc, insn); \ | 38 | Invoke<&TranslatorVisitor::name>(visitor, pc, insn); \ |
| 38 | break; | 39 | break; |
| 39 | #include "shader_recompiler/frontend/maxwell/maxwell.inc" | 40 | #include "shader_recompiler/frontend/maxwell/maxwell.inc" |
| 40 | #undef OPCODE | 41 | #undef OPCODE |
| 41 | default: | 42 | default: |
| 42 | throw LogicError("Invalid opcode {}", opcode); | 43 | throw LogicError("Invalid opcode {}", opcode); |
| 44 | } | ||
| 45 | } catch (Exception& exception) { | ||
| 46 | exception.Prepend(fmt::format("Translate {}: ", Decode(insn))); | ||
| 47 | throw; | ||
| 43 | } | 48 | } |
| 44 | } | 49 | } |
| 45 | } | 50 | } |