diff options
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 94 |
1 files changed, 31 insertions, 63 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 647da4eb0..555aa8cc7 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -153,85 +153,54 @@ private: | |||
| 153 | */ | 153 | */ |
| 154 | class GLSLRegister { | 154 | class GLSLRegister { |
| 155 | public: | 155 | public: |
| 156 | GLSLRegister(size_t index, ShaderWriter& shader) | 156 | enum class Type { |
| 157 | : index{index}, shader{shader}, float_str{"freg_" + std::to_string(index)}, | 157 | Float, |
| 158 | integer_str{"ireg_" + std::to_string(index)} {} | 158 | Integer, |
| 159 | }; | ||
| 159 | 160 | ||
| 160 | /// Returns a GLSL string representing the current state of the register | 161 | GLSLRegister(size_t index, ShaderWriter& shader) : index{index}, shader{shader} {} |
| 161 | const std::string& GetActiveString() { | ||
| 162 | declr_type.insert(active_type); | ||
| 163 | 162 | ||
| 164 | switch (active_type) { | 163 | static std::string GetTypeString(Type type) { |
| 164 | switch (type) { | ||
| 165 | case Type::Float: | 165 | case Type::Float: |
| 166 | return float_str; | 166 | return "float"; |
| 167 | case Type::Integer: | ||
| 168 | return integer_str; | ||
| 169 | } | 167 | } |
| 170 | 168 | ||
| 171 | UNREACHABLE(); | 169 | UNREACHABLE(); |
| 172 | return float_str; | 170 | return {}; |
| 173 | } | ||
| 174 | |||
| 175 | /// Returns a GLSL string representing the register as a float | ||
| 176 | const std::string& GetFloatString() const { | ||
| 177 | ASSERT(IsFloatUsed()); | ||
| 178 | return float_str; | ||
| 179 | } | ||
| 180 | |||
| 181 | /// Returns a GLSL string representing the register as an integer | ||
| 182 | const std::string& GetIntegerString() const { | ||
| 183 | ASSERT(IsIntegerUsed()); | ||
| 184 | return integer_str; | ||
| 185 | } | ||
| 186 | |||
| 187 | /// Convert the current register state from float to integer | ||
| 188 | void FloatToInteger() { | ||
| 189 | ASSERT(active_type == Type::Float); | ||
| 190 | |||
| 191 | const std::string src = GetActiveString(); | ||
| 192 | active_type = Type::Integer; | ||
| 193 | const std::string dest = GetActiveString(); | ||
| 194 | |||
| 195 | shader.AddLine(dest + " = floatBitsToInt(" + src + ");"); | ||
| 196 | } | ||
| 197 | |||
| 198 | /// Convert the current register state from integer to float | ||
| 199 | void IntegerToFloat() { | ||
| 200 | ASSERT(active_type == Type::Integer); | ||
| 201 | |||
| 202 | const std::string src = GetActiveString(); | ||
| 203 | active_type = Type::Float; | ||
| 204 | const std::string dest = GetActiveString(); | ||
| 205 | |||
| 206 | shader.AddLine(dest + " = intBitsToFloat(" + src + ");"); | ||
| 207 | } | 171 | } |
| 208 | 172 | ||
| 209 | /// Returns true if the register was ever used as a float, used for register declarations | 173 | static std::string GetPrefixString(Type type) { |
| 210 | bool IsFloatUsed() const { | 174 | return "reg_" + GetTypeString(type) + '_'; |
| 211 | return declr_type.find(Type::Float) != declr_type.end(); | ||
| 212 | } | 175 | } |
| 213 | 176 | ||
| 214 | /// Returns true if the register was ever used as an integer, used for register declarations | 177 | /// Returns a GLSL string representing the current state of the register |
| 215 | bool IsIntegerUsed() const { | 178 | const std::string GetActiveString() { |
| 216 | return declr_type.find(Type::Integer) != declr_type.end(); | 179 | declr_type.insert(active_type); |
| 180 | return GetPrefixString(active_type) + std::to_string(index); | ||
| 217 | } | 181 | } |
| 218 | 182 | ||
| 219 | /// Returns true if the active type is float | 183 | /// Returns true if the active type is a float |
| 220 | bool IsFloat() const { | 184 | bool IsFloat() const { |
| 221 | return active_type == Type::Float; | 185 | return active_type == Type::Float; |
| 222 | } | 186 | } |
| 223 | 187 | ||
| 224 | /// Returns true if the active type is integer | 188 | /// Returns true if the active type is an integer |
| 225 | bool IsInteger() const { | 189 | bool IsInteger() const { |
| 226 | return active_type == Type::Integer; | 190 | return active_type == Type::Integer; |
| 227 | } | 191 | } |
| 228 | 192 | ||
| 229 | private: | 193 | /// Returns the index of the register |
| 230 | enum class Type { | 194 | size_t GetIndex() const { |
| 231 | Float, | 195 | return index; |
| 232 | Integer, | 196 | } |
| 233 | }; | ||
| 234 | 197 | ||
| 198 | /// Returns a set of the declared types of the register | ||
| 199 | const std::set<Type>& DeclaredTypes() const { | ||
| 200 | return declr_type; | ||
| 201 | } | ||
| 202 | |||
| 203 | private: | ||
| 235 | const size_t index; | 204 | const size_t index; |
| 236 | const std::string float_str; | 205 | const std::string float_str; |
| 237 | const std::string integer_str; | 206 | const std::string integer_str; |
| @@ -347,11 +316,10 @@ public: | |||
| 347 | /// Add declarations for registers | 316 | /// Add declarations for registers |
| 348 | void GenerateDeclarations() { | 317 | void GenerateDeclarations() { |
| 349 | for (const auto& reg : regs) { | 318 | for (const auto& reg : regs) { |
| 350 | if (reg.IsFloatUsed()) { | 319 | for (const auto& type : reg.DeclaredTypes()) { |
| 351 | declarations.AddLine("float " + reg.GetFloatString() + " = 0.0;"); | 320 | declarations.AddLine(GLSLRegister::GetTypeString(type) + ' ' + |
| 352 | } | 321 | GLSLRegister::GetPrefixString(type) + |
| 353 | if (reg.IsIntegerUsed()) { | 322 | std::to_string(reg.GetIndex()) + " = 0;"); |
| 354 | declarations.AddLine("int " + reg.GetIntegerString() + " = 0;"); | ||
| 355 | } | 323 | } |
| 356 | } | 324 | } |
| 357 | declarations.AddNewLine(); | 325 | declarations.AddNewLine(); |