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