summaryrefslogtreecommitdiff
path: root/src/shader_recompiler
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-05-27 17:51:00 -0300
committerGravatar ameerj2021-07-22 21:51:34 -0400
commitb7764c3a796e53ac74009bc7d7cd153c64b6d743 (patch)
tree592a8be7cd43349cbabfc3d84693b443ddc0b5d8 /src/shader_recompiler
parentglasm: Use integer lod for TXQ (diff)
downloadyuzu-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.h40
-rw-r--r--src/shader_recompiler/frontend/maxwell/opcodes.cpp2
-rw-r--r--src/shader_recompiler/frontend/maxwell/program.cpp1
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/translate.cpp13
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
12namespace Shader { 14namespace Shader {
13 15
14class LogicError : public std::logic_error { 16class Exception : public std::exception {
17public:
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
32private:
33 std::string message;
34};
35
36class LogicError : public Exception {
15public: 37public:
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
21class RuntimeError : public std::runtime_error { 43class RuntimeError : public Exception {
22public: 44public:
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
28class NotImplementedException : public std::logic_error { 50class NotImplementedException : public Exception {
29public: 51public:
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
35class InvalidArgument : public std::invalid_argument { 59class InvalidArgument : public Exception {
36public: 60public:
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 @@
10namespace Shader::Maxwell { 10namespace Shader::Maxwell {
11namespace { 11namespace {
12constexpr std::array NAME_TABLE{ 12constexpr 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}