diff options
| author | 2018-05-31 23:22:21 -0400 | |
|---|---|---|
| committer | 2018-05-31 23:36:45 -0400 | |
| commit | 888eb345c0d06c58da40afa5619fe6a0da10ffa5 (patch) | |
| tree | 7a736b1976d2248c5f620686a70fdc3d6aff310d /src | |
| parent | gl_shader_decompiler: Support multi-destination for TEXS. (diff) | |
| download | yuzu-888eb345c0d06c58da40afa5619fe6a0da10ffa5.tar.gz yuzu-888eb345c0d06c58da40afa5619fe6a0da10ffa5.tar.xz yuzu-888eb345c0d06c58da40afa5619fe6a0da10ffa5.zip | |
gl_shader_decompiler: Implement TEX instruction.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/engines/shader_bytecode.h | 10 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 27 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index 79adcc535..4ed918a76 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h | |||
| @@ -262,6 +262,14 @@ union Instruction { | |||
| 262 | } conversion; | 262 | } conversion; |
| 263 | 263 | ||
| 264 | union { | 264 | union { |
| 265 | BitField<31, 4, u64> component_mask; | ||
| 266 | |||
| 267 | bool IsComponentEnabled(size_t component) const { | ||
| 268 | return ((1 << component) & component_mask) != 0; | ||
| 269 | } | ||
| 270 | } tex; | ||
| 271 | |||
| 272 | union { | ||
| 265 | // TODO(bunnei): This is just a guess, needs to be verified | 273 | // TODO(bunnei): This is just a guess, needs to be verified |
| 266 | BitField<52, 1, u64> enable_g_component; | 274 | BitField<52, 1, u64> enable_g_component; |
| 267 | } texs; | 275 | } texs; |
| @@ -286,6 +294,7 @@ public: | |||
| 286 | KIL, | 294 | KIL, |
| 287 | LD_A, | 295 | LD_A, |
| 288 | ST_A, | 296 | ST_A, |
| 297 | TEX, | ||
| 289 | TEXQ, // Texture Query | 298 | TEXQ, // Texture Query |
| 290 | TEXS, // Texture Fetch with scalar/non-vec4 source/destinations | 299 | TEXS, // Texture Fetch with scalar/non-vec4 source/destinations |
| 291 | TLDS, // Texture Load with scalar/non-vec4 source/destinations | 300 | TLDS, // Texture Load with scalar/non-vec4 source/destinations |
| @@ -447,6 +456,7 @@ private: | |||
| 447 | INST("111000110011----", Id::KIL, Type::Flow, "KIL"), | 456 | INST("111000110011----", Id::KIL, Type::Flow, "KIL"), |
| 448 | INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"), | 457 | INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"), |
| 449 | INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"), | 458 | INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"), |
| 459 | INST("1100000000111---", Id::TEX, Type::Memory, "TEX"), | ||
| 450 | INST("1101111101001---", Id::TEXQ, Type::Memory, "TEXQ"), | 460 | INST("1101111101001---", Id::TEXQ, Type::Memory, "TEXQ"), |
| 451 | INST("1101100---------", Id::TEXS, Type::Memory, "TEXS"), | 461 | INST("1101100---------", Id::TEXS, Type::Memory, "TEXS"), |
| 452 | INST("1101101---------", Id::TLDS, Type::Memory, "TLDS"), | 462 | INST("1101101---------", Id::TLDS, Type::Memory, "TLDS"), |
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index f6a60c920..88502a8a7 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -891,6 +891,32 @@ private: | |||
| 891 | instr.gpr0); | 891 | instr.gpr0); |
| 892 | break; | 892 | break; |
| 893 | } | 893 | } |
| 894 | case OpCode::Id::TEX: { | ||
| 895 | ASSERT_MSG(instr.attribute.fmt20.size == 4, "untested"); | ||
| 896 | const std::string op_a = regs.GetRegisterAsFloat(instr.gpr8); | ||
| 897 | const std::string op_b = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1); | ||
| 898 | const std::string sampler = GetSampler(instr.sampler); | ||
| 899 | const std::string coord = "vec2 coords = vec2(" + op_a + ", " + op_b + ");"; | ||
| 900 | // Add an extra scope and declare the texture coords inside to prevent overwriting | ||
| 901 | // them in case they are used as outputs of the texs instruction. | ||
| 902 | shader.AddLine("{"); | ||
| 903 | ++shader.scope; | ||
| 904 | shader.AddLine(coord); | ||
| 905 | const std::string texture = "texture(" + sampler + ", coords)"; | ||
| 906 | |||
| 907 | size_t dest_elem{}; | ||
| 908 | for (size_t elem = 0; elem < instr.attribute.fmt20.size; ++elem) { | ||
| 909 | if (!instr.tex.IsComponentEnabled(elem)) { | ||
| 910 | // Skip disabled components | ||
| 911 | continue; | ||
| 912 | } | ||
| 913 | regs.SetRegisterToFloat(instr.gpr0, elem, texture, 1, 4, false, dest_elem); | ||
| 914 | ++dest_elem; | ||
| 915 | } | ||
| 916 | --shader.scope; | ||
| 917 | shader.AddLine("}"); | ||
| 918 | break; | ||
| 919 | } | ||
| 894 | case OpCode::Id::TEXS: { | 920 | case OpCode::Id::TEXS: { |
| 895 | ASSERT_MSG(instr.attribute.fmt20.size == 4, "untested"); | 921 | ASSERT_MSG(instr.attribute.fmt20.size == 4, "untested"); |
| 896 | const std::string op_a = regs.GetRegisterAsFloat(instr.gpr8); | 922 | const std::string op_a = regs.GetRegisterAsFloat(instr.gpr8); |
| @@ -921,7 +947,6 @@ private: | |||
| 921 | } | 947 | } |
| 922 | offset += 2; | 948 | offset += 2; |
| 923 | } | 949 | } |
| 924 | |||
| 925 | --shader.scope; | 950 | --shader.scope; |
| 926 | shader.AddLine("}"); | 951 | shader.AddLine("}"); |
| 927 | break; | 952 | break; |