summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-04-28 04:24:53 +0200
committerbunnei <bunneidev@gmail.com>2018-04-29 02:03:19 +0200
commitc691fa4074d27bffa537f0f0da4b8e71a813c594 (patch)
tree233f086d9effbf7c74ad72de6e1334fbc38062e6 /src/video_core/renderer_opengl/gl_shader_decompiler.cpp
parentshader_bytecode: Add decodings for i2i instructions. (diff)
downloadyuzu-c691fa4074d27bffa537f0f0da4b8e71a813c594.tar
yuzu-c691fa4074d27bffa537f0f0da4b8e71a813c594.tar.gz
yuzu-c691fa4074d27bffa537f0f0da4b8e71a813c594.tar.bz2
yuzu-c691fa4074d27bffa537f0f0da4b8e71a813c594.tar.lz
yuzu-c691fa4074d27bffa537f0f0da4b8e71a813c594.tar.xz
yuzu-c691fa4074d27bffa537f0f0da4b8e71a813c594.tar.zst
yuzu-c691fa4074d27bffa537f0f0da4b8e71a813c594.zip
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp94
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:
*/
class GLSLRegister {
public:
- GLSLRegister(size_t index, ShaderWriter& shader)
- : index{index}, shader{shader}, float_str{"freg_" + std::to_string(index)},
- integer_str{"ireg_" + std::to_string(index)} {}
+ enum class Type {
+ Float,
+ Integer,
+ };
- /// Returns a GLSL string representing the current state of the register
- const std::string& GetActiveString() {
- declr_type.insert(active_type);
+ GLSLRegister(size_t index, ShaderWriter& shader) : index{index}, shader{shader} {}
- switch (active_type) {
+ static std::string GetTypeString(Type type) {
+ switch (type) {
case Type::Float:
- return float_str;
- case Type::Integer:
- return integer_str;
+ return "float";
}
UNREACHABLE();
- return float_str;
- }
-
- /// Returns a GLSL string representing the register as a float
- const std::string& GetFloatString() const {
- ASSERT(IsFloatUsed());
- return float_str;
- }
-
- /// Returns a GLSL string representing the register as an integer
- const std::string& GetIntegerString() const {
- ASSERT(IsIntegerUsed());
- return integer_str;
- }
-
- /// Convert the current register state from float to integer
- void FloatToInteger() {
- ASSERT(active_type == Type::Float);
-
- const std::string src = GetActiveString();
- active_type = Type::Integer;
- const std::string dest = GetActiveString();
-
- shader.AddLine(dest + " = floatBitsToInt(" + src + ");");
- }
-
- /// Convert the current register state from integer to float
- void IntegerToFloat() {
- ASSERT(active_type == Type::Integer);
-
- const std::string src = GetActiveString();
- active_type = Type::Float;
- const std::string dest = GetActiveString();
-
- shader.AddLine(dest + " = intBitsToFloat(" + src + ");");
+ return {};
}
- /// Returns true if the register was ever used as a float, used for register declarations
- bool IsFloatUsed() const {
- return declr_type.find(Type::Float) != declr_type.end();
+ static std::string GetPrefixString(Type type) {
+ return "reg_" + GetTypeString(type) + '_';
}
- /// Returns true if the register was ever used as an integer, used for register declarations
- bool IsIntegerUsed() const {
- return declr_type.find(Type::Integer) != declr_type.end();
+ /// Returns a GLSL string representing the current state of the register
+ const std::string GetActiveString() {
+ declr_type.insert(active_type);
+ return GetPrefixString(active_type) + std::to_string(index);
}
- /// Returns true if the active type is float
+ /// Returns true if the active type is a float
bool IsFloat() const {
return active_type == Type::Float;
}
- /// Returns true if the active type is integer
+ /// Returns true if the active type is an integer
bool IsInteger() const {
return active_type == Type::Integer;
}
-private:
- enum class Type {
- Float,
- Integer,
- };
+ /// Returns the index of the register
+ size_t GetIndex() const {
+ return index;
+ }
+ /// Returns a set of the declared types of the register
+ const std::set<Type>& DeclaredTypes() const {
+ return declr_type;
+ }
+
+private:
const size_t index;
const std::string float_str;
const std::string integer_str;
@@ -347,11 +316,10 @@ public:
/// Add declarations for registers
void GenerateDeclarations() {
for (const auto& reg : regs) {
- if (reg.IsFloatUsed()) {
- declarations.AddLine("float " + reg.GetFloatString() + " = 0.0;");
- }
- if (reg.IsIntegerUsed()) {
- declarations.AddLine("int " + reg.GetIntegerString() + " = 0;");
+ for (const auto& type : reg.DeclaredTypes()) {
+ declarations.AddLine(GLSLRegister::GetTypeString(type) + ' ' +
+ GLSLRegister::GetPrefixString(type) +
+ std::to_string(reg.GetIndex()) + " = 0;");
}
}
declarations.AddNewLine();