summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_core/engines/shader_bytecode.h24
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp48
2 files changed, 67 insertions, 5 deletions
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h
index 6cfdb6e27..9176a8dbc 100644
--- a/src/video_core/engines/shader_bytecode.h
+++ b/src/video_core/engines/shader_bytecode.h
@@ -536,6 +536,16 @@ union Instruction {
536 union { 536 union {
537 BitField<28, 1, u64> array; 537 BitField<28, 1, u64> array;
538 BitField<29, 2, TextureType> texture_type; 538 BitField<29, 2, TextureType> texture_type;
539 BitField<31, 4, u64> component_mask;
540
541 bool IsComponentEnabled(size_t component) const {
542 return ((1ull << component) & component_mask) != 0;
543 }
544 } tmml;
545
546 union {
547 BitField<28, 1, u64> array;
548 BitField<29, 2, TextureType> texture_type;
539 BitField<56, 2, u64> component; 549 BitField<56, 2, u64> component;
540 } tld4; 550 } tld4;
541 551
@@ -685,11 +695,13 @@ public:
685 LDG, // Load from global memory 695 LDG, // Load from global memory
686 STG, // Store in global memory 696 STG, // Store in global memory
687 TEX, 697 TEX,
688 TXQ, // Texture Query 698 TXQ, // Texture Query
689 TEXS, // Texture Fetch with scalar/non-vec4 source/destinations 699 TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
690 TLDS, // Texture Load with scalar/non-vec4 source/destinations 700 TLDS, // Texture Load with scalar/non-vec4 source/destinations
691 TLD4, // Texture Load 4 701 TLD4, // Texture Load 4
692 TLD4S, // Texture Load 4 with scalar / non - vec4 source / destinations 702 TLD4S, // Texture Load 4 with scalar / non - vec4 source / destinations
703 TMML_B, // Texture Mip Map Level
704 TMML, // Texture Mip Map Level
693 EXIT, 705 EXIT,
694 IPA, 706 IPA,
695 FFMA_IMM, // Fused Multiply and Add 707 FFMA_IMM, // Fused Multiply and Add
@@ -914,6 +926,8 @@ private:
914 INST("1101101---------", Id::TLDS, Type::Memory, "TLDS"), 926 INST("1101101---------", Id::TLDS, Type::Memory, "TLDS"),
915 INST("110010----111---", Id::TLD4, Type::Memory, "TLD4"), 927 INST("110010----111---", Id::TLD4, Type::Memory, "TLD4"),
916 INST("1101111100------", Id::TLD4S, Type::Memory, "TLD4S"), 928 INST("1101111100------", Id::TLD4S, Type::Memory, "TLD4S"),
929 INST("110111110110----", Id::TMML_B, Type::Memory, "TMML_B"),
930 INST("1101111101011---", Id::TMML, Type::Memory, "TMML"),
917 INST("111000110000----", Id::EXIT, Type::Trivial, "EXIT"), 931 INST("111000110000----", Id::EXIT, Type::Trivial, "EXIT"),
918 INST("11100000--------", Id::IPA, Type::Trivial, "IPA"), 932 INST("11100000--------", Id::IPA, Type::Trivial, "IPA"),
919 INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"), 933 INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"),
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 034b9459c..762e58aad 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -1945,6 +1945,54 @@ private:
1945 } 1945 }
1946 break; 1946 break;
1947 } 1947 }
1948 case OpCode::Id::TMML: {
1949 const std::string op_a = regs.GetRegisterAsFloat(instr.gpr8);
1950 const std::string op_b = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
1951 const bool is_array = instr.tmml.array != 0;
1952 auto texture_type = instr.tmml.texture_type.Value();
1953 const std::string sampler = GetSampler(instr.sampler, texture_type, is_array);
1954
1955 // TODO: add coordinates for different samplers once other texture types are
1956 // implemented.
1957 std::string coord;
1958 switch (texture_type) {
1959 case Tegra::Shader::TextureType::Texture1D: {
1960 std::string x = regs.GetRegisterAsFloat(instr.gpr8);
1961 coord = "float coords = " + x + ';';
1962 break;
1963 }
1964 case Tegra::Shader::TextureType::Texture2D: {
1965 std::string x = regs.GetRegisterAsFloat(instr.gpr8);
1966 std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
1967 coord = "vec2 coords = vec2(" + x + ", " + y + ");";
1968 break;
1969 }
1970 default:
1971 LOG_CRITICAL(HW_GPU, "Unhandled texture type {}",
1972 static_cast<u32>(texture_type));
1973 UNREACHABLE();
1974
1975 // Fallback to interpreting as a 2D texture for now
1976 std::string x = regs.GetRegisterAsFloat(instr.gpr8);
1977 std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
1978 coord = "vec2 coords = vec2(" + x + ", " + y + ");";
1979 texture_type = Tegra::Shader::TextureType::Texture2D;
1980 }
1981 // Add an extra scope and declare the texture coords inside to prevent
1982 // overwriting them in case they are used as outputs of the texs instruction.
1983 shader.AddLine('{');
1984 ++shader.scope;
1985 shader.AddLine(coord);
1986 const std::string texture = "textureQueryLod(" + sampler + ", coords)";
1987 const std::string tmp = "vec2 tmp = " + texture + "*vec2(256.0, 256.0);";
1988 shader.AddLine(tmp);
1989
1990 regs.SetRegisterToInteger(instr.gpr0, true, 0, "int(tmp.y)", 1, 1);
1991 regs.SetRegisterToInteger(instr.gpr0.Value() + 1, false, 0, "uint(tmp.x)", 1, 1);
1992 --shader.scope;
1993 shader.AddLine('}');
1994 break;
1995 }
1948 default: { 1996 default: {
1949 LOG_CRITICAL(HW_GPU, "Unhandled memory instruction: {}", opcode->GetName()); 1997 LOG_CRITICAL(HW_GPU, "Unhandled memory instruction: {}", opcode->GetName());
1950 UNREACHABLE(); 1998 UNREACHABLE();