summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp223
-rw-r--r--src/video_core/debug_utils/debug_utils.h6
2 files changed, 114 insertions, 115 deletions
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
index 790a2789a..871368323 100644
--- a/src/video_core/debug_utils/debug_utils.cpp
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -696,130 +696,125 @@ finalise:
696#endif 696#endif
697} 697}
698 698
699void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages) 699static std::string ReplacePattern(const std::string& input, const std::string& pattern, const std::string& replacement) {
700{ 700 size_t start = input.find(pattern);
701 if (start == std::string::npos)
702 return input;
703
704 std::string ret = input;
705 ret.replace(start, pattern.length(), replacement);
706 return ret;
707}
708
709static std::string GetTevStageConfigSourceString(const Pica::Regs::TevStageConfig::Source& source) {
701 using Source = Pica::Regs::TevStageConfig::Source; 710 using Source = Pica::Regs::TevStageConfig::Source;
711 static const std::map<Source, std::string> source_map = {
712 { Source::PrimaryColor, "PrimaryColor" },
713 { Source::PrimaryFragmentColor, "PrimaryFragmentColor" },
714 { Source::SecondaryFragmentColor, "SecondaryFragmentColor" },
715 { Source::Texture0, "Texture0" },
716 { Source::Texture1, "Texture1" },
717 { Source::Texture2, "Texture2" },
718 { Source::Texture3, "Texture3" },
719 { Source::PreviousBuffer, "PreviousBuffer" },
720 { Source::Constant, "Constant" },
721 { Source::Previous, "Previous" },
722 };
723
724 const auto src_it = source_map.find(source);
725 if (src_it == source_map.end())
726 return "Unknown";
727
728 return src_it->second;
729}
730
731static std::string GetTevStageConfigColorSourceString(const Pica::Regs::TevStageConfig::Source& source, const Pica::Regs::TevStageConfig::ColorModifier modifier) {
702 using ColorModifier = Pica::Regs::TevStageConfig::ColorModifier; 732 using ColorModifier = Pica::Regs::TevStageConfig::ColorModifier;
733 static const std::map<ColorModifier, std::string> color_modifier_map = {
734 { ColorModifier::SourceColor, "%source.rgb" },
735 { ColorModifier::OneMinusSourceColor, "(1.0 - %source.rgb)" },
736 { ColorModifier::SourceAlpha, "%source.aaa" },
737 { ColorModifier::OneMinusSourceAlpha, "(1.0 - %source.aaa)" },
738 { ColorModifier::SourceRed, "%source.rrr" },
739 { ColorModifier::OneMinusSourceRed, "(1.0 - %source.rrr)" },
740 { ColorModifier::SourceGreen, "%source.ggg" },
741 { ColorModifier::OneMinusSourceGreen, "(1.0 - %source.ggg)" },
742 { ColorModifier::SourceBlue, "%source.bbb" },
743 { ColorModifier::OneMinusSourceBlue, "(1.0 - %source.bbb)" },
744 };
745
746 auto src_str = GetTevStageConfigSourceString(source);
747 auto modifier_it = color_modifier_map.find(modifier);
748 std::string modifier_str = "%source.????";
749 if (modifier_it != color_modifier_map.end())
750 modifier_str = modifier_it->second;
751
752 return ReplacePattern(modifier_str, "%source", src_str);
753}
754
755static std::string GetTevStageConfigAlphaSourceString(const Pica::Regs::TevStageConfig::Source& source, const Pica::Regs::TevStageConfig::AlphaModifier modifier) {
703 using AlphaModifier = Pica::Regs::TevStageConfig::AlphaModifier; 756 using AlphaModifier = Pica::Regs::TevStageConfig::AlphaModifier;
704 using Operation = Pica::Regs::TevStageConfig::Operation; 757 static const std::map<AlphaModifier, std::string> alpha_modifier_map = {
758 { AlphaModifier::SourceAlpha, "%source.a" },
759 { AlphaModifier::OneMinusSourceAlpha, "(1.0 - %source.a)" },
760 { AlphaModifier::SourceRed, "%source.r" },
761 { AlphaModifier::OneMinusSourceRed, "(1.0 - %source.r)" },
762 { AlphaModifier::SourceGreen, "%source.g" },
763 { AlphaModifier::OneMinusSourceGreen, "(1.0 - %source.g)" },
764 { AlphaModifier::SourceBlue, "%source.b" },
765 { AlphaModifier::OneMinusSourceBlue, "(1.0 - %source.b)" },
766 };
705 767
706 std::string stage_info = "Tev setup:\n"; 768 auto src_str = GetTevStageConfigSourceString(source);
707 for (size_t index = 0; index < stages.size(); ++index) { 769 auto modifier_it = alpha_modifier_map.find(modifier);
708 const auto& tev_stage = stages[index]; 770 std::string modifier_str = "%source.????";
771 if (modifier_it != alpha_modifier_map.end())
772 modifier_str = modifier_it->second;
709 773
710 static const std::map<Source, std::string> source_map = { 774 return ReplacePattern(modifier_str, "%source", src_str);
711 { Source::PrimaryColor, "PrimaryColor" }, 775}
712 { Source::PrimaryFragmentColor, "PrimaryFragmentColor" },
713 { Source::SecondaryFragmentColor, "SecondaryFragmentColor" },
714 { Source::Texture0, "Texture0" },
715 { Source::Texture1, "Texture1" },
716 { Source::Texture2, "Texture2" },
717 { Source::Texture3, "Texture3" },
718 { Source::PreviousBuffer, "PreviousBuffer" },
719 { Source::Constant, "Constant" },
720 { Source::Previous, "Previous" },
721 };
722 776
723 static const std::map<ColorModifier, std::string> color_modifier_map = { 777static std::string GetTevStageConfigOperationString(const Pica::Regs::TevStageConfig::Operation& operation) {
724 { ColorModifier::SourceColor, "%source.rgb" }, 778 using Operation = Pica::Regs::TevStageConfig::Operation;
725 { ColorModifier::OneMinusSourceColor, "(1.0 - %source.rgb)" }, 779 static const std::map<Operation, std::string> combiner_map = {
726 { ColorModifier::SourceAlpha, "%source.aaa" }, 780 { Operation::Replace, "%source1" },
727 { ColorModifier::OneMinusSourceAlpha, "(1.0 - %source.aaa)" }, 781 { Operation::Modulate, "(%source1 * %source2)" },
728 { ColorModifier::SourceRed, "%source.rrr" }, 782 { Operation::Add, "(%source1 + %source2)" },
729 { ColorModifier::OneMinusSourceRed, "(1.0 - %source.rrr)" }, 783 { Operation::AddSigned, "(%source1 + %source2) - 0.5" },
730 { ColorModifier::SourceGreen, "%source.ggg" }, 784 { Operation::Lerp, "lerp(%source1, %source2, %source3)" },
731 { ColorModifier::OneMinusSourceGreen, "(1.0 - %source.ggg)" }, 785 { Operation::Subtract, "(%source1 - %source2)" },
732 { ColorModifier::SourceBlue, "%source.bbb" }, 786 { Operation::Dot3_RGB, "dot(%source1, %source2)" },
733 { ColorModifier::OneMinusSourceBlue, "(1.0 - %source.bbb)" }, 787 { Operation::MultiplyThenAdd, "((%source1 * %source2) + %source3)" },
734 }; 788 { Operation::AddThenMultiply, "((%source1 + %source2) * %source3)" },
789 };
735 790
736 static const std::map<AlphaModifier, std::string> alpha_modifier_map = { 791 const auto op_it = combiner_map.find(operation);
737 { AlphaModifier::SourceAlpha, "%source.a" }, 792 if (op_it == combiner_map.end())
738 { AlphaModifier::OneMinusSourceAlpha, "(1.0 - %source.a)" }, 793 return "Unknown op (%source1, %source2, %source3)";
739 { AlphaModifier::SourceRed, "%source.r" },
740 { AlphaModifier::OneMinusSourceRed, "(1.0 - %source.r)" },
741 { AlphaModifier::SourceGreen, "%source.g" },
742 { AlphaModifier::OneMinusSourceGreen, "(1.0 - %source.g)" },
743 { AlphaModifier::SourceBlue, "%source.b" },
744 { AlphaModifier::OneMinusSourceBlue, "(1.0 - %source.b)" },
745 };
746 794
747 static const std::map<Operation, std::string> combiner_map = { 795 return op_it->second;
748 { Operation::Replace, "%source1" }, 796}
749 { Operation::Modulate, "(%source1 * %source2)" },
750 { Operation::Add, "(%source1 + %source2)" },
751 { Operation::AddSigned, "(%source1 + %source2) - 0.5" },
752 { Operation::Lerp, "lerp(%source1, %source2, %source3)" },
753 { Operation::Subtract, "(%source1 - %source2)" },
754 { Operation::Dot3_RGB, "dot(%source1, %source2)" },
755 { Operation::MultiplyThenAdd, "((%source1 * %source2) + %source3)" },
756 { Operation::AddThenMultiply, "((%source1 + %source2) * %source3)" },
757 };
758 797
759 static auto ReplacePattern = 798std::string GetTevStageConfigColorCombinerString(const Pica::Regs::TevStageConfig& tev_stage) {
760 [](const std::string& input, const std::string& pattern, const std::string& replacement) -> std::string { 799 auto op_str = GetTevStageConfigOperationString(tev_stage.color_op);
761 size_t start = input.find(pattern); 800 op_str = ReplacePattern(op_str, "%source1", GetTevStageConfigColorSourceString(tev_stage.color_source1, tev_stage.color_modifier1));
762 if (start == std::string::npos) 801 op_str = ReplacePattern(op_str, "%source2", GetTevStageConfigColorSourceString(tev_stage.color_source2, tev_stage.color_modifier2));
763 return input; 802 return ReplacePattern(op_str, "%source3", GetTevStageConfigColorSourceString(tev_stage.color_source3, tev_stage.color_modifier3));
764 803}
765 std::string ret = input; 804
766 ret.replace(start, pattern.length(), replacement); 805std::string GetTevStageConfigAlphaCombinerString(const Pica::Regs::TevStageConfig& tev_stage) {
767 return ret; 806 auto op_str = GetTevStageConfigOperationString(tev_stage.alpha_op);
768 }; 807 op_str = ReplacePattern(op_str, "%source1", GetTevStageConfigAlphaSourceString(tev_stage.alpha_source1, tev_stage.alpha_modifier1));
769 static auto GetColorSourceStr = 808 op_str = ReplacePattern(op_str, "%source2", GetTevStageConfigAlphaSourceString(tev_stage.alpha_source2, tev_stage.alpha_modifier2));
770 [](const Source& src, const ColorModifier& modifier) { 809 return ReplacePattern(op_str, "%source3", GetTevStageConfigAlphaSourceString(tev_stage.alpha_source3, tev_stage.alpha_modifier3));
771 auto src_it = source_map.find(src); 810}
772 std::string src_str = "Unknown";
773 if (src_it != source_map.end())
774 src_str = src_it->second;
775
776 auto modifier_it = color_modifier_map.find(modifier);
777 std::string modifier_str = "%source.????";
778 if (modifier_it != color_modifier_map.end())
779 modifier_str = modifier_it->second;
780
781 return ReplacePattern(modifier_str, "%source", src_str);
782 };
783 static auto GetColorCombinerStr =
784 [](const Regs::TevStageConfig& tev_stage) {
785 auto op_it = combiner_map.find(tev_stage.color_op);
786 std::string op_str = "Unknown op (%source1, %source2, %source3)";
787 if (op_it != combiner_map.end())
788 op_str = op_it->second;
789
790 op_str = ReplacePattern(op_str, "%source1", GetColorSourceStr(tev_stage.color_source1, tev_stage.color_modifier1));
791 op_str = ReplacePattern(op_str, "%source2", GetColorSourceStr(tev_stage.color_source2, tev_stage.color_modifier2));
792 return ReplacePattern(op_str, "%source3", GetColorSourceStr(tev_stage.color_source3, tev_stage.color_modifier3));
793 };
794 static auto GetAlphaSourceStr =
795 [](const Source& src, const AlphaModifier& modifier) {
796 auto src_it = source_map.find(src);
797 std::string src_str = "Unknown";
798 if (src_it != source_map.end())
799 src_str = src_it->second;
800
801 auto modifier_it = alpha_modifier_map.find(modifier);
802 std::string modifier_str = "%source.????";
803 if (modifier_it != alpha_modifier_map.end())
804 modifier_str = modifier_it->second;
805
806 return ReplacePattern(modifier_str, "%source", src_str);
807 };
808 static auto GetAlphaCombinerStr =
809 [](const Regs::TevStageConfig& tev_stage) {
810 auto op_it = combiner_map.find(tev_stage.alpha_op);
811 std::string op_str = "Unknown op (%source1, %source2, %source3)";
812 if (op_it != combiner_map.end())
813 op_str = op_it->second;
814
815 op_str = ReplacePattern(op_str, "%source1", GetAlphaSourceStr(tev_stage.alpha_source1, tev_stage.alpha_modifier1));
816 op_str = ReplacePattern(op_str, "%source2", GetAlphaSourceStr(tev_stage.alpha_source2, tev_stage.alpha_modifier2));
817 return ReplacePattern(op_str, "%source3", GetAlphaSourceStr(tev_stage.alpha_source3, tev_stage.alpha_modifier3));
818 };
819
820 stage_info += "Stage " + std::to_string(index) + ": " + GetColorCombinerStr(tev_stage) + " " + GetAlphaCombinerStr(tev_stage) + "\n";
821 }
822 811
812void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig, 6>& stages) {
813 std::string stage_info = "Tev setup:\n";
814 for (size_t index = 0; index < stages.size(); ++index) {
815 const auto& tev_stage = stages[index];
816 stage_info += "Stage " + std::to_string(index) + ": " + GetTevStageConfigColorCombinerString(tev_stage) + " " + GetTevStageConfigAlphaCombinerString(tev_stage) + "\n";
817 }
823 LOG_TRACE(HW_GPU, "%s", stage_info.c_str()); 818 LOG_TRACE(HW_GPU, "%s", stage_info.c_str());
824} 819}
825 820
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h
index f628292a4..92e9734ae 100644
--- a/src/video_core/debug_utils/debug_utils.h
+++ b/src/video_core/debug_utils/debug_utils.h
@@ -224,7 +224,11 @@ const Math::Vec4<u8> LookupTexture(const u8* source, int s, int t, const Texture
224 224
225void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data); 225void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data);
226 226
227void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages); 227std::string GetTevStageConfigColorCombinerString(const Pica::Regs::TevStageConfig& tev_stage);
228std::string GetTevStageConfigAlphaCombinerString(const Pica::Regs::TevStageConfig& tev_stage);
229
230/// Dumps the Tev stage config to log at trace level
231void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig, 6>& stages);
228 232
229/** 233/**
230 * Used in the vertex loader to merge access records. TODO: Investigate if actually useful. 234 * Used in the vertex loader to merge access records. TODO: Investigate if actually useful.