summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-02-12 17:02:59 -0300
committerGravatar ReinUsesLisp2019-02-12 17:03:07 -0300
commite60d4d70bc10cf78ab607f26ea835bce6c79f186 (patch)
tree5d3a0b86b67fc7d0ed6f6b1cbe928760d02b9f30
parentMerge pull request #2108 from FernandoS27/fix-cc (diff)
downloadyuzu-e60d4d70bc10cf78ab607f26ea835bce6c79f186.tar.gz
yuzu-e60d4d70bc10cf78ab607f26ea835bce6c79f186.tar.xz
yuzu-e60d4d70bc10cf78ab607f26ea835bce6c79f186.zip
gl_shader_decompiler: Re-implement TLDS lod
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp55
-rw-r--r--src/video_core/shader/decode/memory.cpp2
2 files changed, 35 insertions, 22 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index b39bb4843..db18f4dbe 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -616,17 +616,8 @@ private:
616 616
617 std::string VisitOperand(Operation operation, std::size_t operand_index, Type type) { 617 std::string VisitOperand(Operation operation, std::size_t operand_index, Type type) {
618 std::string value = VisitOperand(operation, operand_index); 618 std::string value = VisitOperand(operation, operand_index);
619
620 switch (type) { 619 switch (type) {
621 case Type::Bool: 620 case Type::HalfFloat: {
622 case Type::Bool2:
623 case Type::Float:
624 return value;
625 case Type::Int:
626 return "ftoi(" + value + ')';
627 case Type::Uint:
628 return "ftou(" + value + ')';
629 case Type::HalfFloat:
630 const auto half_meta = std::get_if<MetaHalfArithmetic>(&operation.GetMeta()); 621 const auto half_meta = std::get_if<MetaHalfArithmetic>(&operation.GetMeta());
631 if (!half_meta) { 622 if (!half_meta) {
632 value = "toHalf2(" + value + ')'; 623 value = "toHalf2(" + value + ')';
@@ -643,6 +634,26 @@ private:
643 return "vec2(toHalf2(" + value + ")[1])"; 634 return "vec2(toHalf2(" + value + ")[1])";
644 } 635 }
645 } 636 }
637 default:
638 return CastOperand(value, type);
639 }
640 }
641
642 std::string CastOperand(const std::string& value, Type type) const {
643 switch (type) {
644 case Type::Bool:
645 case Type::Bool2:
646 case Type::Float:
647 return value;
648 case Type::Int:
649 return "ftoi(" + value + ')';
650 case Type::Uint:
651 return "ftou(" + value + ')';
652 case Type::HalfFloat:
653 // Can't be handled as a stand-alone value
654 UNREACHABLE();
655 return value;
656 }
646 UNREACHABLE(); 657 UNREACHABLE();
647 return value; 658 return value;
648 } 659 }
@@ -650,6 +661,7 @@ private:
650 std::string BitwiseCastResult(std::string value, Type type, bool needs_parenthesis = false) { 661 std::string BitwiseCastResult(std::string value, Type type, bool needs_parenthesis = false) {
651 switch (type) { 662 switch (type) {
652 case Type::Bool: 663 case Type::Bool:
664 case Type::Bool2:
653 case Type::Float: 665 case Type::Float:
654 if (needs_parenthesis) { 666 if (needs_parenthesis) {
655 return '(' + value + ')'; 667 return '(' + value + ')';
@@ -721,7 +733,7 @@ private:
721 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta()); 733 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
722 ASSERT(meta); 734 ASSERT(meta);
723 735
724 const auto count = static_cast<u32>(operation.GetOperandsCount()); 736 const std::size_t count = operation.GetOperandsCount();
725 const bool has_array = meta->sampler.IsArray(); 737 const bool has_array = meta->sampler.IsArray();
726 const bool has_shadow = meta->sampler.IsShadow(); 738 const bool has_shadow = meta->sampler.IsShadow();
727 739
@@ -732,10 +744,10 @@ private:
732 744
733 expr += coord_constructors.at(count + (has_array ? 1 : 0) + (has_shadow ? 1 : 0) - 1); 745 expr += coord_constructors.at(count + (has_array ? 1 : 0) + (has_shadow ? 1 : 0) - 1);
734 expr += '('; 746 expr += '(';
735 for (u32 i = 0; i < count; ++i) { 747 for (std::size_t i = 0; i < count; ++i) {
736 expr += Visit(operation[i]); 748 expr += Visit(operation[i]);
737 749
738 const u32 next = i + 1; 750 const std::size_t next = i + 1;
739 if (next < count || has_array || has_shadow) 751 if (next < count || has_array || has_shadow)
740 expr += ", "; 752 expr += ", ";
741 } 753 }
@@ -1206,25 +1218,26 @@ private:
1206 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta()); 1218 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
1207 ASSERT(meta); 1219 ASSERT(meta);
1208 UNIMPLEMENTED_IF(meta->sampler.IsArray()); 1220 UNIMPLEMENTED_IF(meta->sampler.IsArray());
1209 UNIMPLEMENTED_IF(!meta->extras.empty()); 1221 const std::size_t count = operation.GetOperandsCount();
1210
1211 const auto count = static_cast<u32>(operation.GetOperandsCount());
1212 1222
1213 std::string expr = "texelFetch("; 1223 std::string expr = "texelFetch(";
1214 expr += GetSampler(meta->sampler); 1224 expr += GetSampler(meta->sampler);
1215 expr += ", "; 1225 expr += ", ";
1216 1226
1217 expr += constructors.at(count - 1); 1227 expr += constructors.at(operation.GetOperandsCount() - 1);
1218 expr += '('; 1228 expr += '(';
1219 for (u32 i = 0; i < count; ++i) { 1229 for (std::size_t i = 0; i < count; ++i) {
1220 expr += VisitOperand(operation, i, Type::Int); 1230 expr += VisitOperand(operation, i, Type::Int);
1221 1231 const std::size_t next = i + 1;
1222 const u32 next = i + 1;
1223 if (next == count) 1232 if (next == count)
1224 expr += ')'; 1233 expr += ')';
1225 if (next < count) 1234 else if (next < count)
1226 expr += ", "; 1235 expr += ", ";
1227 } 1236 }
1237 for (std::size_t i = 0; i < meta->extras.size(); ++i) {
1238 expr += ", ";
1239 expr += CastOperand(Visit(meta->extras.at(i)), Type::Int);
1240 }
1228 expr += ')'; 1241 expr += ')';
1229 1242
1230 return expr + GetSwizzle(meta->element); 1243 return expr + GetSwizzle(meta->element);
diff --git a/src/video_core/shader/decode/memory.cpp b/src/video_core/shader/decode/memory.cpp
index 523421794..55ec601ff 100644
--- a/src/video_core/shader/decode/memory.cpp
+++ b/src/video_core/shader/decode/memory.cpp
@@ -429,7 +429,7 @@ u32 ShaderIR::DecodeMemory(NodeBlock& bb, u32 pc) {
429 UNIMPLEMENTED_IF_MSG(instr.tlds.UsesMiscMode(TextureMiscMode::MZ), "MZ is not implemented"); 429 UNIMPLEMENTED_IF_MSG(instr.tlds.UsesMiscMode(TextureMiscMode::MZ), "MZ is not implemented");
430 430
431 if (instr.tlds.UsesMiscMode(TextureMiscMode::NODEP)) { 431 if (instr.tlds.UsesMiscMode(TextureMiscMode::NODEP)) {
432 LOG_WARNING(HW_GPU, "TMML.NODEP implementation is incomplete"); 432 LOG_WARNING(HW_GPU, "TLDS.NODEP implementation is incomplete");
433 } 433 }
434 434
435 WriteTexsInstructionFloat(bb, instr, GetTldsCode(instr, texture_type, is_array)); 435 WriteTexsInstructionFloat(bb, instr, GetTldsCode(instr, texture_type, is_array));