diff options
| author | 2021-05-21 02:00:12 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:35 -0400 | |
| commit | e221baccddea3c0802c97e7f6f60c0c3e6a72b60 (patch) | |
| tree | 4a94c1d2b662b2d7ace703334c41c575fc644510 /src/shader_recompiler/backend | |
| parent | glsl: Fix program linking and cbuf (diff) | |
| download | yuzu-e221baccddea3c0802c97e7f6f60c0c3e6a72b60.tar.gz yuzu-e221baccddea3c0802c97e7f6f60c0c3e6a72b60.tar.xz yuzu-e221baccddea3c0802c97e7f6f60c0c3e6a72b60.zip | |
glsl: Reusable typed variables. IADD32
Diffstat (limited to 'src/shader_recompiler/backend')
6 files changed, 311 insertions, 203 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.h b/src/shader_recompiler/backend/glsl/emit_context.h index 8d093a853..81b970c14 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.h +++ b/src/shader_recompiler/backend/glsl/emit_context.h | |||
| @@ -31,9 +31,33 @@ class EmitContext { | |||
| 31 | public: | 31 | public: |
| 32 | explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_); | 32 | explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_); |
| 33 | 33 | ||
| 34 | // template <typename... Args> | ||
| 35 | // void Add(const char* format_str, IR::Inst& inst, Args&&... args) { | ||
| 36 | // code += fmt::format(format_str, reg_alloc.Define(inst), std::forward<Args>(args)...); | ||
| 37 | // // TODO: Remove this | ||
| 38 | // code += '\n'; | ||
| 39 | // } | ||
| 40 | |||
| 41 | template <typename... Args> | ||
| 42 | void AddU32(const char* format_str, IR::Inst& inst, Args&&... args) { | ||
| 43 | code += | ||
| 44 | fmt::format(format_str, reg_alloc.Define(inst, Type::U32), std::forward<Args>(args)...); | ||
| 45 | // TODO: Remove this | ||
| 46 | code += '\n'; | ||
| 47 | } | ||
| 48 | |||
| 49 | template <typename... Args> | ||
| 50 | void AddS32(const char* format_str, IR::Inst& inst, Args&&... args) { | ||
| 51 | code += | ||
| 52 | fmt::format(format_str, reg_alloc.Define(inst, Type::S32), std::forward<Args>(args)...); | ||
| 53 | // TODO: Remove this | ||
| 54 | code += '\n'; | ||
| 55 | } | ||
| 56 | |||
| 34 | template <typename... Args> | 57 | template <typename... Args> |
| 35 | void Add(const char* format_str, IR::Inst& inst, Args&&... args) { | 58 | void AddF32(const char* format_str, IR::Inst& inst, Args&&... args) { |
| 36 | code += fmt::format(format_str, reg_alloc.Define(inst), std::forward<Args>(args)...); | 59 | code += |
| 60 | fmt::format(format_str, reg_alloc.Define(inst, Type::F32), std::forward<Args>(args)...); | ||
| 37 | // TODO: Remove this | 61 | // TODO: Remove this |
| 38 | code += '\n'; | 62 | code += '\n'; |
| 39 | } | 63 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp index 73f0faf35..ff04cffd2 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp | |||
| @@ -33,8 +33,8 @@ void EmitGetCbufS16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR | |||
| 33 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst* inst, const IR::Value& binding, | 33 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst* inst, const IR::Value& binding, |
| 34 | const IR::Value& offset) { | 34 | const IR::Value& offset) { |
| 35 | const auto u32_offset{offset.U32()}; | 35 | const auto u32_offset{offset.U32()}; |
| 36 | ctx.Add("uint {}=floatBitsToUint(cbuf{}[{}][{}]);", *inst, binding.U32(), u32_offset / 16, | 36 | ctx.AddU32("{}=floatBitsToUint(cbuf{}[{}][{}]);", *inst, binding.U32(), u32_offset / 16, |
| 37 | (u32_offset / 4) % 4); | 37 | (u32_offset / 4) % 4); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | void EmitGetCbufF32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, | 40 | void EmitGetCbufF32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp index e69de29bb..6977f74f9 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp | |||
| @@ -0,0 +1,221 @@ | |||
| 1 | |||
| 2 | // Copyright 2021 yuzu Emulator Project | ||
| 3 | // Licensed under GPLv2 or any later version | ||
| 4 | // Refer to the license.txt file included. | ||
| 5 | |||
| 6 | #include <string_view> | ||
| 7 | |||
| 8 | #include "shader_recompiler/backend/glsl/emit_context.h" | ||
| 9 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | ||
| 10 | #include "shader_recompiler/frontend/ir/value.h" | ||
| 11 | #include "shader_recompiler/profile.h" | ||
| 12 | |||
| 13 | namespace Shader::Backend::GLSL { | ||
| 14 | void EmitIAdd32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst* inst, | ||
| 15 | [[maybe_unused]] std::string a, [[maybe_unused]] std::string b) { | ||
| 16 | ctx.AddU32("{}={}+{};", *inst, a, b); | ||
| 17 | } | ||
| 18 | |||
| 19 | void EmitIAdd64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string a, | ||
| 20 | [[maybe_unused]] std::string b) { | ||
| 21 | throw NotImplementedException("GLSL Instruction"); | ||
| 22 | } | ||
| 23 | |||
| 24 | void EmitISub32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string a, | ||
| 25 | [[maybe_unused]] std::string b) { | ||
| 26 | throw NotImplementedException("GLSL Instruction"); | ||
| 27 | } | ||
| 28 | |||
| 29 | void EmitISub64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string a, | ||
| 30 | [[maybe_unused]] std::string b) { | ||
| 31 | throw NotImplementedException("GLSL Instruction"); | ||
| 32 | } | ||
| 33 | |||
| 34 | void EmitIMul32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string a, | ||
| 35 | [[maybe_unused]] std::string b) { | ||
| 36 | throw NotImplementedException("GLSL Instruction"); | ||
| 37 | } | ||
| 38 | |||
| 39 | void EmitINeg32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string value) { | ||
| 40 | throw NotImplementedException("GLSL Instruction"); | ||
| 41 | } | ||
| 42 | |||
| 43 | void EmitINeg64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string value) { | ||
| 44 | throw NotImplementedException("GLSL Instruction"); | ||
| 45 | } | ||
| 46 | |||
| 47 | void EmitIAbs32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string value) { | ||
| 48 | throw NotImplementedException("GLSL Instruction"); | ||
| 49 | } | ||
| 50 | |||
| 51 | void EmitIAbs64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string value) { | ||
| 52 | throw NotImplementedException("GLSL Instruction"); | ||
| 53 | } | ||
| 54 | |||
| 55 | void EmitShiftLeftLogical32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string base, | ||
| 56 | [[maybe_unused]] std::string shift) { | ||
| 57 | throw NotImplementedException("GLSL Instruction"); | ||
| 58 | } | ||
| 59 | |||
| 60 | void EmitShiftLeftLogical64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string base, | ||
| 61 | [[maybe_unused]] std::string shift) { | ||
| 62 | throw NotImplementedException("GLSL Instruction"); | ||
| 63 | } | ||
| 64 | |||
| 65 | void EmitShiftRightLogical32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string base, | ||
| 66 | [[maybe_unused]] std::string shift) { | ||
| 67 | throw NotImplementedException("GLSL Instruction"); | ||
| 68 | } | ||
| 69 | |||
| 70 | void EmitShiftRightLogical64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string base, | ||
| 71 | [[maybe_unused]] std::string shift) { | ||
| 72 | throw NotImplementedException("GLSL Instruction"); | ||
| 73 | } | ||
| 74 | |||
| 75 | void EmitShiftRightArithmetic32([[maybe_unused]] EmitContext& ctx, | ||
| 76 | [[maybe_unused]] std::string base, | ||
| 77 | [[maybe_unused]] std::string shift) { | ||
| 78 | throw NotImplementedException("GLSL Instruction"); | ||
| 79 | } | ||
| 80 | |||
| 81 | void EmitShiftRightArithmetic64([[maybe_unused]] EmitContext& ctx, | ||
| 82 | [[maybe_unused]] std::string base, | ||
| 83 | [[maybe_unused]] std::string shift) { | ||
| 84 | throw NotImplementedException("GLSL Instruction"); | ||
| 85 | } | ||
| 86 | |||
| 87 | void EmitBitwiseAnd32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst* inst, | ||
| 88 | [[maybe_unused]] std::string a, [[maybe_unused]] std::string b) { | ||
| 89 | throw NotImplementedException("GLSL Instruction"); | ||
| 90 | } | ||
| 91 | |||
| 92 | void EmitBitwiseOr32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst* inst, | ||
| 93 | [[maybe_unused]] std::string a, [[maybe_unused]] std::string b) { | ||
| 94 | throw NotImplementedException("GLSL Instruction"); | ||
| 95 | } | ||
| 96 | |||
| 97 | void EmitBitwiseXor32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst* inst, | ||
| 98 | [[maybe_unused]] std::string a, [[maybe_unused]] std::string b) { | ||
| 99 | throw NotImplementedException("GLSL Instruction"); | ||
| 100 | } | ||
| 101 | |||
| 102 | void EmitBitFieldInsert([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string base, | ||
| 103 | [[maybe_unused]] std::string insert, [[maybe_unused]] std::string offset, | ||
| 104 | std::string count) { | ||
| 105 | throw NotImplementedException("GLSL Instruction"); | ||
| 106 | } | ||
| 107 | |||
| 108 | void EmitBitFieldSExtract([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst* inst, | ||
| 109 | [[maybe_unused]] std::string base, [[maybe_unused]] std::string offset, | ||
| 110 | std::string count) { | ||
| 111 | throw NotImplementedException("GLSL Instruction"); | ||
| 112 | } | ||
| 113 | |||
| 114 | void EmitBitFieldUExtract([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst* inst, | ||
| 115 | [[maybe_unused]] std::string base, [[maybe_unused]] std::string offset, | ||
| 116 | std::string count) { | ||
| 117 | throw NotImplementedException("GLSL Instruction"); | ||
| 118 | } | ||
| 119 | |||
| 120 | void EmitBitReverse32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string value) { | ||
| 121 | throw NotImplementedException("GLSL Instruction"); | ||
| 122 | } | ||
| 123 | |||
| 124 | void EmitBitCount32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string value) { | ||
| 125 | throw NotImplementedException("GLSL Instruction"); | ||
| 126 | } | ||
| 127 | |||
| 128 | void EmitBitwiseNot32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string value) { | ||
| 129 | throw NotImplementedException("GLSL Instruction"); | ||
| 130 | } | ||
| 131 | |||
| 132 | void EmitFindSMsb32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string value) { | ||
| 133 | throw NotImplementedException("GLSL Instruction"); | ||
| 134 | } | ||
| 135 | |||
| 136 | void EmitFindUMsb32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string value) { | ||
| 137 | throw NotImplementedException("GLSL Instruction"); | ||
| 138 | } | ||
| 139 | |||
| 140 | void EmitSMin32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string a, | ||
| 141 | [[maybe_unused]] std::string b) { | ||
| 142 | throw NotImplementedException("GLSL Instruction"); | ||
| 143 | } | ||
| 144 | |||
| 145 | void EmitUMin32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string a, | ||
| 146 | [[maybe_unused]] std::string b) { | ||
| 147 | throw NotImplementedException("GLSL Instruction"); | ||
| 148 | } | ||
| 149 | |||
| 150 | void EmitSMax32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string a, | ||
| 151 | [[maybe_unused]] std::string b) { | ||
| 152 | throw NotImplementedException("GLSL Instruction"); | ||
| 153 | } | ||
| 154 | |||
| 155 | void EmitUMax32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string a, | ||
| 156 | [[maybe_unused]] std::string b) { | ||
| 157 | throw NotImplementedException("GLSL Instruction"); | ||
| 158 | } | ||
| 159 | |||
| 160 | void EmitSClamp32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst* inst, | ||
| 161 | [[maybe_unused]] std::string value, [[maybe_unused]] std::string min, | ||
| 162 | std::string max) { | ||
| 163 | throw NotImplementedException("GLSL Instruction"); | ||
| 164 | } | ||
| 165 | |||
| 166 | void EmitUClamp32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst* inst, | ||
| 167 | [[maybe_unused]] std::string value, [[maybe_unused]] std::string min, | ||
| 168 | std::string max) { | ||
| 169 | throw NotImplementedException("GLSL Instruction"); | ||
| 170 | } | ||
| 171 | |||
| 172 | void EmitSLessThan([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 173 | [[maybe_unused]] std::string rhs) { | ||
| 174 | throw NotImplementedException("GLSL Instruction"); | ||
| 175 | } | ||
| 176 | |||
| 177 | void EmitULessThan([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 178 | [[maybe_unused]] std::string rhs) { | ||
| 179 | throw NotImplementedException("GLSL Instruction"); | ||
| 180 | } | ||
| 181 | |||
| 182 | void EmitIEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 183 | [[maybe_unused]] std::string rhs) { | ||
| 184 | throw NotImplementedException("GLSL Instruction"); | ||
| 185 | } | ||
| 186 | |||
| 187 | void EmitSLessThanEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 188 | [[maybe_unused]] std::string rhs) { | ||
| 189 | throw NotImplementedException("GLSL Instruction"); | ||
| 190 | } | ||
| 191 | |||
| 192 | void EmitULessThanEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 193 | [[maybe_unused]] std::string rhs) { | ||
| 194 | throw NotImplementedException("GLSL Instruction"); | ||
| 195 | } | ||
| 196 | |||
| 197 | void EmitSGreaterThan([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 198 | [[maybe_unused]] std::string rhs) { | ||
| 199 | throw NotImplementedException("GLSL Instruction"); | ||
| 200 | } | ||
| 201 | |||
| 202 | void EmitUGreaterThan([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 203 | [[maybe_unused]] std::string rhs) { | ||
| 204 | throw NotImplementedException("GLSL Instruction"); | ||
| 205 | } | ||
| 206 | |||
| 207 | void EmitINotEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 208 | [[maybe_unused]] std::string rhs) { | ||
| 209 | throw NotImplementedException("GLSL Instruction"); | ||
| 210 | } | ||
| 211 | |||
| 212 | void EmitSGreaterThanEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 213 | [[maybe_unused]] std::string rhs) { | ||
| 214 | throw NotImplementedException("GLSL Instruction"); | ||
| 215 | } | ||
| 216 | |||
| 217 | void EmitUGreaterThanEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string lhs, | ||
| 218 | [[maybe_unused]] std::string rhs) { | ||
| 219 | throw NotImplementedException("GLSL Instruction"); | ||
| 220 | } | ||
| 221 | } // namespace Shader::Backend::GLSL | ||
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp index cbac59ff0..f39c1fff0 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp | |||
| @@ -979,179 +979,6 @@ void EmitFPIsNan64(EmitContext& ctx, std::string value) { | |||
| 979 | NotImplemented(); | 979 | NotImplemented(); |
| 980 | } | 980 | } |
| 981 | 981 | ||
| 982 | void EmitIAdd32(EmitContext& ctx, IR::Inst* inst, std::string a, std::string b) { | ||
| 983 | NotImplemented(); | ||
| 984 | } | ||
| 985 | |||
| 986 | void EmitIAdd64(EmitContext& ctx, std::string a, std::string b) { | ||
| 987 | NotImplemented(); | ||
| 988 | } | ||
| 989 | |||
| 990 | void EmitISub32(EmitContext& ctx, std::string a, std::string b) { | ||
| 991 | NotImplemented(); | ||
| 992 | } | ||
| 993 | |||
| 994 | void EmitISub64(EmitContext& ctx, std::string a, std::string b) { | ||
| 995 | NotImplemented(); | ||
| 996 | } | ||
| 997 | |||
| 998 | void EmitIMul32(EmitContext& ctx, std::string a, std::string b) { | ||
| 999 | NotImplemented(); | ||
| 1000 | } | ||
| 1001 | |||
| 1002 | void EmitINeg32(EmitContext& ctx, std::string value) { | ||
| 1003 | NotImplemented(); | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | void EmitINeg64(EmitContext& ctx, std::string value) { | ||
| 1007 | NotImplemented(); | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | void EmitIAbs32(EmitContext& ctx, std::string value) { | ||
| 1011 | NotImplemented(); | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | void EmitIAbs64(EmitContext& ctx, std::string value) { | ||
| 1015 | NotImplemented(); | ||
| 1016 | } | ||
| 1017 | |||
| 1018 | void EmitShiftLeftLogical32(EmitContext& ctx, std::string base, std::string shift) { | ||
| 1019 | NotImplemented(); | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | void EmitShiftLeftLogical64(EmitContext& ctx, std::string base, std::string shift) { | ||
| 1023 | NotImplemented(); | ||
| 1024 | } | ||
| 1025 | |||
| 1026 | void EmitShiftRightLogical32(EmitContext& ctx, std::string base, std::string shift) { | ||
| 1027 | NotImplemented(); | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | void EmitShiftRightLogical64(EmitContext& ctx, std::string base, std::string shift) { | ||
| 1031 | NotImplemented(); | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | void EmitShiftRightArithmetic32(EmitContext& ctx, std::string base, std::string shift) { | ||
| 1035 | NotImplemented(); | ||
| 1036 | } | ||
| 1037 | |||
| 1038 | void EmitShiftRightArithmetic64(EmitContext& ctx, std::string base, std::string shift) { | ||
| 1039 | NotImplemented(); | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | void EmitBitwiseAnd32(EmitContext& ctx, IR::Inst* inst, std::string a, std::string b) { | ||
| 1043 | NotImplemented(); | ||
| 1044 | } | ||
| 1045 | |||
| 1046 | void EmitBitwiseOr32(EmitContext& ctx, IR::Inst* inst, std::string a, std::string b) { | ||
| 1047 | NotImplemented(); | ||
| 1048 | } | ||
| 1049 | |||
| 1050 | void EmitBitwiseXor32(EmitContext& ctx, IR::Inst* inst, std::string a, std::string b) { | ||
| 1051 | NotImplemented(); | ||
| 1052 | } | ||
| 1053 | |||
| 1054 | void EmitBitFieldInsert(EmitContext& ctx, std::string base, std::string insert, std::string offset, | ||
| 1055 | std::string count) { | ||
| 1056 | NotImplemented(); | ||
| 1057 | } | ||
| 1058 | |||
| 1059 | void EmitBitFieldSExtract(EmitContext& ctx, IR::Inst* inst, std::string base, std::string offset, | ||
| 1060 | std::string count) { | ||
| 1061 | NotImplemented(); | ||
| 1062 | } | ||
| 1063 | |||
| 1064 | void EmitBitFieldUExtract(EmitContext& ctx, IR::Inst* inst, std::string base, std::string offset, | ||
| 1065 | std::string count) { | ||
| 1066 | NotImplemented(); | ||
| 1067 | } | ||
| 1068 | |||
| 1069 | void EmitBitReverse32(EmitContext& ctx, std::string value) { | ||
| 1070 | NotImplemented(); | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | void EmitBitCount32(EmitContext& ctx, std::string value) { | ||
| 1074 | NotImplemented(); | ||
| 1075 | } | ||
| 1076 | |||
| 1077 | void EmitBitwiseNot32(EmitContext& ctx, std::string value) { | ||
| 1078 | NotImplemented(); | ||
| 1079 | } | ||
| 1080 | |||
| 1081 | void EmitFindSMsb32(EmitContext& ctx, std::string value) { | ||
| 1082 | NotImplemented(); | ||
| 1083 | } | ||
| 1084 | |||
| 1085 | void EmitFindUMsb32(EmitContext& ctx, std::string value) { | ||
| 1086 | NotImplemented(); | ||
| 1087 | } | ||
| 1088 | |||
| 1089 | void EmitSMin32(EmitContext& ctx, std::string a, std::string b) { | ||
| 1090 | NotImplemented(); | ||
| 1091 | } | ||
| 1092 | |||
| 1093 | void EmitUMin32(EmitContext& ctx, std::string a, std::string b) { | ||
| 1094 | NotImplemented(); | ||
| 1095 | } | ||
| 1096 | |||
| 1097 | void EmitSMax32(EmitContext& ctx, std::string a, std::string b) { | ||
| 1098 | NotImplemented(); | ||
| 1099 | } | ||
| 1100 | |||
| 1101 | void EmitUMax32(EmitContext& ctx, std::string a, std::string b) { | ||
| 1102 | NotImplemented(); | ||
| 1103 | } | ||
| 1104 | |||
| 1105 | void EmitSClamp32(EmitContext& ctx, IR::Inst* inst, std::string value, std::string min, | ||
| 1106 | std::string max) { | ||
| 1107 | NotImplemented(); | ||
| 1108 | } | ||
| 1109 | |||
| 1110 | void EmitUClamp32(EmitContext& ctx, IR::Inst* inst, std::string value, std::string min, | ||
| 1111 | std::string max) { | ||
| 1112 | NotImplemented(); | ||
| 1113 | } | ||
| 1114 | |||
| 1115 | void EmitSLessThan(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1116 | NotImplemented(); | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | void EmitULessThan(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1120 | NotImplemented(); | ||
| 1121 | } | ||
| 1122 | |||
| 1123 | void EmitIEqual(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1124 | NotImplemented(); | ||
| 1125 | } | ||
| 1126 | |||
| 1127 | void EmitSLessThanEqual(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1128 | NotImplemented(); | ||
| 1129 | } | ||
| 1130 | |||
| 1131 | void EmitULessThanEqual(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1132 | NotImplemented(); | ||
| 1133 | } | ||
| 1134 | |||
| 1135 | void EmitSGreaterThan(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1136 | NotImplemented(); | ||
| 1137 | } | ||
| 1138 | |||
| 1139 | void EmitUGreaterThan(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1140 | NotImplemented(); | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | void EmitINotEqual(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1144 | NotImplemented(); | ||
| 1145 | } | ||
| 1146 | |||
| 1147 | void EmitSGreaterThanEqual(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1148 | NotImplemented(); | ||
| 1149 | } | ||
| 1150 | |||
| 1151 | void EmitUGreaterThanEqual(EmitContext& ctx, std::string lhs, std::string rhs) { | ||
| 1152 | NotImplemented(); | ||
| 1153 | } | ||
| 1154 | |||
| 1155 | void EmitSharedAtomicIAdd32(EmitContext& ctx, std::string pointer_offset, std::string value) { | 982 | void EmitSharedAtomicIAdd32(EmitContext& ctx, std::string pointer_offset, std::string value) { |
| 1156 | NotImplemented(); | 983 | NotImplemented(); |
| 1157 | } | 984 | } |
diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.cpp b/src/shader_recompiler/backend/glsl/reg_alloc.cpp index 5fdad5acb..5ad1872db 100644 --- a/src/shader_recompiler/backend/glsl/reg_alloc.cpp +++ b/src/shader_recompiler/backend/glsl/reg_alloc.cpp | |||
| @@ -13,7 +13,6 @@ | |||
| 13 | #pragma optimize("", off) | 13 | #pragma optimize("", off) |
| 14 | namespace Shader::Backend::GLSL { | 14 | namespace Shader::Backend::GLSL { |
| 15 | namespace { | 15 | namespace { |
| 16 | constexpr std::string_view SWIZZLE = "xyzw"; | ||
| 17 | 16 | ||
| 18 | std::string Representation(Id id) { | 17 | std::string Representation(Id id) { |
| 19 | if (id.is_condition_code != 0) { | 18 | if (id.is_condition_code != 0) { |
| @@ -22,7 +21,6 @@ std::string Representation(Id id) { | |||
| 22 | if (id.is_spill != 0) { | 21 | if (id.is_spill != 0) { |
| 23 | throw NotImplementedException("Spilling"); | 22 | throw NotImplementedException("Spilling"); |
| 24 | } | 23 | } |
| 25 | const u32 num_elements{id.num_elements_minus_one + 1}; | ||
| 26 | const u32 index{static_cast<u32>(id.index)}; | 24 | const u32 index{static_cast<u32>(id.index)}; |
| 27 | return fmt::format("R{}", index); | 25 | return fmt::format("R{}", index); |
| 28 | } | 26 | } |
| @@ -45,10 +43,11 @@ std::string MakeImm(const IR::Value& value) { | |||
| 45 | } | 43 | } |
| 46 | } // Anonymous namespace | 44 | } // Anonymous namespace |
| 47 | 45 | ||
| 48 | std::string RegAlloc::Define(IR::Inst& inst, u32 num_elements, u32 alignment) { | 46 | std::string RegAlloc::Define(IR::Inst& inst, Type type) { |
| 49 | const Id id{Alloc(num_elements, alignment)}; | 47 | const Id id{Alloc()}; |
| 48 | const auto type_str{GetType(type, id.index)}; | ||
| 50 | inst.SetDefinition<Id>(id); | 49 | inst.SetDefinition<Id>(id); |
| 51 | return Representation(id); | 50 | return type_str + Representation(id); |
| 52 | } | 51 | } |
| 53 | 52 | ||
| 54 | std::string RegAlloc::Consume(const IR::Value& value) { | 53 | std::string RegAlloc::Consume(const IR::Value& value) { |
| @@ -65,20 +64,37 @@ std::string RegAlloc::Consume(IR::Inst& inst) { | |||
| 65 | return Representation(inst.Definition<Id>()); | 64 | return Representation(inst.Definition<Id>()); |
| 66 | } | 65 | } |
| 67 | 66 | ||
| 68 | Id RegAlloc::Alloc(u32 num_elements, [[maybe_unused]] u32 alignment) { | 67 | std::string RegAlloc::GetType(Type type, u32 index) { |
| 69 | for (size_t reg = 0; reg < NUM_REGS; ++reg) { | 68 | if (register_defined[index]) { |
| 70 | if (register_use[reg]) { | 69 | return ""; |
| 71 | continue; | 70 | } |
| 71 | register_defined[index] = true; | ||
| 72 | switch (type) { | ||
| 73 | case Type::U32: | ||
| 74 | return "uint "; | ||
| 75 | case Type::S32: | ||
| 76 | return "int "; | ||
| 77 | case Type::F32: | ||
| 78 | return "float "; | ||
| 79 | default: | ||
| 80 | return ""; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | Id RegAlloc::Alloc() { | ||
| 85 | if (num_used_registers < NUM_REGS) { | ||
| 86 | for (size_t reg = 0; reg < NUM_REGS; ++reg) { | ||
| 87 | if (register_use[reg]) { | ||
| 88 | continue; | ||
| 89 | } | ||
| 90 | register_use[reg] = true; | ||
| 91 | Id ret{}; | ||
| 92 | ret.index.Assign(static_cast<u32>(reg)); | ||
| 93 | ret.is_long.Assign(0); | ||
| 94 | ret.is_spill.Assign(0); | ||
| 95 | ret.is_condition_code.Assign(0); | ||
| 96 | return ret; | ||
| 72 | } | 97 | } |
| 73 | num_used_registers = std::max(num_used_registers, reg + 1); | ||
| 74 | register_use[reg] = true; | ||
| 75 | return Id{ | ||
| 76 | .base_element = 0, | ||
| 77 | .num_elements_minus_one = num_elements - 1, | ||
| 78 | .index = static_cast<u32>(reg), | ||
| 79 | .is_spill = 0, | ||
| 80 | .is_condition_code = 0, | ||
| 81 | }; | ||
| 82 | } | 98 | } |
| 83 | throw NotImplementedException("Register spilling"); | 99 | throw NotImplementedException("Register spilling"); |
| 84 | } | 100 | } |
diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.h b/src/shader_recompiler/backend/glsl/reg_alloc.h index a777cbbd2..9b98aab39 100644 --- a/src/shader_recompiler/backend/glsl/reg_alloc.h +++ b/src/shader_recompiler/backend/glsl/reg_alloc.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <bitset> | 7 | #include <bitset> |
| 8 | 8 | ||
| 9 | #include "common/bit_field.h" | ||
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 10 | 11 | ||
| 11 | namespace Shader::IR { | 12 | namespace Shader::IR { |
| @@ -14,18 +15,36 @@ class Value; | |||
| 14 | } // namespace Shader::IR | 15 | } // namespace Shader::IR |
| 15 | 16 | ||
| 16 | namespace Shader::Backend::GLSL { | 17 | namespace Shader::Backend::GLSL { |
| 18 | enum class Type : u32 { | ||
| 19 | U32, | ||
| 20 | S32, | ||
| 21 | F32, | ||
| 22 | U64, | ||
| 23 | F64, | ||
| 24 | Void, | ||
| 25 | }; | ||
| 17 | 26 | ||
| 18 | struct Id { | 27 | struct Id { |
| 19 | u32 base_element : 2; | 28 | union { |
| 20 | u32 num_elements_minus_one : 2; | 29 | u32 raw; |
| 21 | u32 index : 26; | 30 | BitField<0, 29, u32> index; |
| 22 | u32 is_spill : 1; | 31 | BitField<29, 1, u32> is_long; |
| 23 | u32 is_condition_code : 1; | 32 | BitField<30, 1, u32> is_spill; |
| 33 | BitField<31, 1, u32> is_condition_code; | ||
| 34 | }; | ||
| 35 | |||
| 36 | bool operator==(Id rhs) const noexcept { | ||
| 37 | return raw == rhs.raw; | ||
| 38 | } | ||
| 39 | bool operator!=(Id rhs) const noexcept { | ||
| 40 | return !operator==(rhs); | ||
| 41 | } | ||
| 24 | }; | 42 | }; |
| 43 | static_assert(sizeof(Id) == sizeof(u32)); | ||
| 25 | 44 | ||
| 26 | class RegAlloc { | 45 | class RegAlloc { |
| 27 | public: | 46 | public: |
| 28 | std::string Define(IR::Inst& inst, u32 num_elements = 1, u32 alignment = 1); | 47 | std::string Define(IR::Inst& inst, Type type = Type::Void); |
| 29 | 48 | ||
| 30 | std::string Consume(const IR::Value& value); | 49 | std::string Consume(const IR::Value& value); |
| 31 | 50 | ||
| @@ -40,13 +59,14 @@ private: | |||
| 40 | static constexpr size_t NUM_ELEMENTS = 4; | 59 | static constexpr size_t NUM_ELEMENTS = 4; |
| 41 | 60 | ||
| 42 | std::string Consume(IR::Inst& inst); | 61 | std::string Consume(IR::Inst& inst); |
| 62 | std::string GetType(Type type, u32 index); | ||
| 43 | 63 | ||
| 44 | Id Alloc(u32 num_elements, u32 alignment); | 64 | Id Alloc(); |
| 45 | |||
| 46 | void Free(Id id); | 65 | void Free(Id id); |
| 47 | 66 | ||
| 48 | size_t num_used_registers{}; | 67 | size_t num_used_registers{}; |
| 49 | std::bitset<NUM_REGS> register_use{}; | 68 | std::bitset<NUM_REGS> register_use{}; |
| 69 | std::bitset<NUM_REGS> register_defined{}; | ||
| 50 | }; | 70 | }; |
| 51 | 71 | ||
| 52 | } // namespace Shader::Backend::GLSL | 72 | } // namespace Shader::Backend::GLSL |