summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2018-11-28 02:34:23 -0300
committerGravatar ReinUsesLisp2018-11-28 23:45:53 -0300
commit78fc8f6b66c198c6e33d67c90eb03ff940191927 (patch)
tree01c892a53ada2ae36d52eded5c923869d6f3e9e6 /src
parentgl_shader_decompiler: Clean up texture instructions (diff)
downloadyuzu-78fc8f6b66c198c6e33d67c90eb03ff940191927.tar.gz
yuzu-78fc8f6b66c198c6e33d67c90eb03ff940191927.tar.xz
yuzu-78fc8f6b66c198c6e33d67c90eb03ff940191927.zip
gl_shader_decompiler: Move texture code generation into lambdas
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp175
1 files changed, 78 insertions, 97 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 4ecfef071..7831067d4 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -2674,11 +2674,11 @@ private:
2674 if (is_array) { 2674 if (is_array) {
2675 depth_compare_extra = depth_compare; 2675 depth_compare_extra = depth_compare;
2676 shader.AddLine("vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " + 2676 shader.AddLine("vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " +
2677 array_elem + ");"); 2677 array_elem + ");");
2678 } else { 2678 } else {
2679 if (depth_compare) { 2679 if (depth_compare) {
2680 shader.AddLine("vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " + 2680 shader.AddLine("vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " +
2681 depth_value + ");"); 2681 depth_value + ");");
2682 } else { 2682 } else {
2683 shader.AddLine("vec3 coords = vec3(" + x + ", " + y + ", " + z + ");"); 2683 shader.AddLine("vec3 coords = vec3(" + x + ", " + y + ", " + z + ");");
2684 } 2684 }
@@ -2701,59 +2701,47 @@ private:
2701 // Add an extra scope and declare the texture coords inside to prevent 2701 // Add an extra scope and declare the texture coords inside to prevent
2702 // overwriting them in case they are used as outputs of the texs instruction. 2702 // overwriting them in case they are used as outputs of the texs instruction.
2703 2703
2704 std::string texture; 2704 const std::string texture = [&]() {
2705 2705 switch (instr.tex.GetTextureProcessMode()) {
2706 switch (instr.tex.GetTextureProcessMode()) { 2706 case Tegra::Shader::TextureProcessMode::None:
2707 case Tegra::Shader::TextureProcessMode::None: { 2707 if (depth_compare_extra) {
2708 if (!depth_compare_extra) { 2708 return "texture(" + sampler + ", coords, " + depth_value + ')';
2709 texture = "texture(" + sampler + ", coords)"; 2709 }
2710 } else { 2710 return "texture(" + sampler + ", coords)";
2711 texture = "texture(" + sampler + ", coords, " + depth_value + ')'; 2711 case Tegra::Shader::TextureProcessMode::LZ:
2712 } 2712 if (depth_compare_extra) {
2713 break; 2713 return "texture(" + sampler + ", coords, " + depth_value + ')';
2714 } 2714 }
2715 case Tegra::Shader::TextureProcessMode::LZ: { 2715 return "textureLod(" + sampler + ", coords, 0.0)";
2716 if (!depth_compare_extra) { 2716 case Tegra::Shader::TextureProcessMode::LB:
2717 texture = "textureLod(" + sampler + ", coords, 0.0)"; 2717 case Tegra::Shader::TextureProcessMode::LBA:
2718 } else { 2718 // TODO: Figure if A suffix changes the equation at all.
2719 texture = "texture(" + sampler + ", coords, " + depth_value + ')'; 2719 if (depth_compare_extra) {
2720 } 2720 LOG_WARNING(
2721 break; 2721 HW_GPU,
2722 } 2722 "OpenGL Limitation: can't set bias value along depth compare");
2723 case Tegra::Shader::TextureProcessMode::LB: 2723 return "texture(" + sampler + ", coords, " + depth_value + ')';
2724 case Tegra::Shader::TextureProcessMode::LBA: { 2724 }
2725 // TODO: Figure if A suffix changes the equation at all. 2725 return "texture(" + sampler + ", coords, " + lod_value + ')';
2726 if (!depth_compare_extra) { 2726 case Tegra::Shader::TextureProcessMode::LL:
2727 texture = "texture(" + sampler + ", coords, " + lod_value + ')'; 2727 case Tegra::Shader::TextureProcessMode::LLA:
2728 } else { 2728 // TODO: Figure if A suffix changes the equation at all.
2729 texture = "texture(" + sampler + ", coords, " + depth_value + ')'; 2729 if (depth_compare_extra) {
2730 LOG_WARNING(HW_GPU, 2730 LOG_WARNING(
2731 "OpenGL Limitation: can't set bias value along depth compare"); 2731 HW_GPU,
2732 } 2732 "OpenGL Limitation: can't set lod value along depth compare");
2733 break; 2733 return "texture(" + sampler + ", coords, " + depth_value + ')';
2734 } 2734 }
2735 case Tegra::Shader::TextureProcessMode::LL: 2735 return "textureLod(" + sampler + ", coords, " + lod_value + ')';
2736 case Tegra::Shader::TextureProcessMode::LLA: { 2736 default:
2737 // TODO: Figure if A suffix changes the equation at all. 2737 UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
2738 if (!depth_compare_extra) { 2738 static_cast<u32>(instr.tex.GetTextureProcessMode()));
2739 texture = "textureLod(" + sampler + ", coords, " + lod_value + ')'; 2739 if (depth_compare_extra) {
2740 } else { 2740 return "texture(" + sampler + ", coords, " + depth_value + ')';
2741 texture = "texture(" + sampler + ", coords, " + depth_value + ')'; 2741 }
2742 LOG_WARNING(HW_GPU, 2742 return "texture(" + sampler + ", coords)";
2743 "OpenGL Limitation: can't set lod value along depth compare");
2744 }
2745 break;
2746 }
2747 default: {
2748 if (!depth_compare_extra) {
2749 texture = "texture(" + sampler + ", coords)";
2750 } else {
2751 texture = "texture(" + sampler + ", coords, " + depth_value + ')';
2752 } 2743 }
2753 UNIMPLEMENTED_MSG("Unhandled texture process mode {}", 2744 }();
2754 static_cast<u32>(instr.tex.GetTextureProcessMode()));
2755 }
2756 }
2757 2745
2758 if (depth_compare) { 2746 if (depth_compare) {
2759 regs.SetRegisterToFloat(instr.gpr0, 0, texture, 1, 1, false); 2747 regs.SetRegisterToFloat(instr.gpr0, 0, texture, 1, 1, false);
@@ -2871,34 +2859,29 @@ private:
2871 const std::string sampler = 2859 const std::string sampler =
2872 GetSampler(instr.sampler, texture_type, is_array, depth_compare); 2860 GetSampler(instr.sampler, texture_type, is_array, depth_compare);
2873 2861
2874 std::string texture; 2862 std::string texture = [&]() {
2875 switch (process_mode) { 2863 switch (process_mode) {
2876 case Tegra::Shader::TextureProcessMode::None: { 2864 case Tegra::Shader::TextureProcessMode::None:
2877 texture = "texture(" + sampler + ", coords)"; 2865 return "texture(" + sampler + ", coords)";
2878 break; 2866 case Tegra::Shader::TextureProcessMode::LZ:
2879 } 2867 if (depth_compare && is_array) {
2880 case Tegra::Shader::TextureProcessMode::LZ: { 2868 return "texture(" + sampler + ", coords)";
2881 if (depth_compare && is_array) { 2869 } else {
2882 texture = "texture(" + sampler + ", coords)"; 2870 return "textureLod(" + sampler + ", coords, 0.0)";
2883 } else { 2871 }
2884 texture = "textureLod(" + sampler + ", coords, 0.0)"; 2872 break;
2873 case Tegra::Shader::TextureProcessMode::LL:
2874 return "textureLod(" + sampler + ", coords, lod_value)";
2875 default:
2876 UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
2877 static_cast<u32>(instr.texs.GetTextureProcessMode()));
2878 return "texture(" + sampler + ", coords)";
2885 } 2879 }
2886 break; 2880 }();
2887 }
2888 case Tegra::Shader::TextureProcessMode::LL: {
2889 texture = "textureLod(" + sampler + ", coords, lod_value)";
2890 break;
2891 }
2892 default: {
2893 texture = "texture(" + sampler + ", coords)";
2894 UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
2895 static_cast<u32>(instr.texs.GetTextureProcessMode()));
2896 }
2897 }
2898
2899 if (depth_compare) { 2881 if (depth_compare) {
2900 texture = "vec4(" + texture + ')'; 2882 texture = "vec4(" + texture + ')';
2901 } 2883 }
2884
2902 WriteTexsInstruction(instr, texture); 2885 WriteTexsInstruction(instr, texture);
2903 break; 2886 break;
2904 } 2887 }
@@ -2941,25 +2924,23 @@ private:
2941 } 2924 }
2942 const std::string sampler = 2925 const std::string sampler =
2943 GetSampler(instr.sampler, texture_type, is_array, false); 2926 GetSampler(instr.sampler, texture_type, is_array, false);
2944 std::string texture = "texelFetch(" + sampler + ", coords, 0)"; 2927
2945 switch (instr.tlds.GetTextureProcessMode()) { 2928 const std::string texture = [&]() {
2946 case Tegra::Shader::TextureProcessMode::LZ: { 2929 switch (instr.tlds.GetTextureProcessMode()) {
2947 texture = "texelFetch(" + sampler + ", coords, 0)"; 2930 case Tegra::Shader::TextureProcessMode::LZ:
2948 break; 2931 return "texelFetch(" + sampler + ", coords, 0)";
2949 } 2932 case Tegra::Shader::TextureProcessMode::LL:
2950 case Tegra::Shader::TextureProcessMode::LL: { 2933 shader.AddLine(
2951 shader.AddLine( 2934 "float lod = " +
2952 "float lod = " + 2935 regs.GetRegisterAsInteger(instr.gpr20.Value() + extra_op_offset) + ';');
2953 regs.GetRegisterAsInteger(instr.gpr20.Value() + extra_op_offset) + ';'); 2936 return "texelFetch(" + sampler + ", coords, lod)";
2954 texture = "texelFetch(" + sampler + ", coords, lod)"; 2937 default:
2955 break; 2938 UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
2956 } 2939 static_cast<u32>(instr.tlds.GetTextureProcessMode()));
2957 default: { 2940 return "texelFetch(" + sampler + ", coords, 0)";
2958 texture = "texelFetch(" + sampler + ", coords, 0)"; 2941 }
2959 UNIMPLEMENTED_MSG("Unhandled texture process mode {}", 2942 }();
2960 static_cast<u32>(instr.tlds.GetTextureProcessMode())); 2943
2961 }
2962 }
2963 WriteTexsInstruction(instr, texture); 2944 WriteTexsInstruction(instr, texture);
2964 break; 2945 break;
2965 } 2946 }