summaryrefslogtreecommitdiff
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-01-29 04:31:40 -0300
committerGravatar ReinUsesLisp2019-02-07 00:46:13 -0300
commitd62b0a9e2941eb9d43e84ee40fe1531c2dc92eea (patch)
tree0d8d248f88357b72c20a349af1eba6076d9ba9c0 /src/video_core/renderer_opengl
parentMerge pull request #2083 from ReinUsesLisp/shader-ir-cbuf-tracking (diff)
downloadyuzu-d62b0a9e2941eb9d43e84ee40fe1531c2dc92eea.tar.gz
yuzu-d62b0a9e2941eb9d43e84ee40fe1531c2dc92eea.tar.xz
yuzu-d62b0a9e2941eb9d43e84ee40fe1531c2dc92eea.zip
shader_ir: Clean texture management code
Previous code relied on GLSL parameter order (something that's always ill-formed on an IR design). This approach passes spatial coordiantes through operation nodes and array and depth compare values in the the texture metadata. It still contains an "extra" vector containing generic nodes for bias and component index (for example) which is still a bit ill-formed but it should be better than the previous approach.
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp73
1 files changed, 41 insertions, 32 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 70e124dc4..aecd4758a 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -719,45 +719,51 @@ private:
719 constexpr std::array<const char*, 4> coord_constructors = {"float", "vec2", "vec3", "vec4"}; 719 constexpr std::array<const char*, 4> coord_constructors = {"float", "vec2", "vec3", "vec4"};
720 720
721 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta()); 721 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
722 const auto count = static_cast<u32>(operation.GetOperandsCount());
723 ASSERT(meta); 722 ASSERT(meta);
724 723
724 const auto count = static_cast<u32>(operation.GetOperandsCount());
725 const bool has_array = meta->sampler.IsArray();
726 const bool has_shadow = meta->sampler.IsShadow();
727
725 std::string expr = func; 728 std::string expr = func;
726 expr += '('; 729 expr += '(';
727 expr += GetSampler(meta->sampler); 730 expr += GetSampler(meta->sampler);
728 expr += ", "; 731 expr += ", ";
729 732
730 expr += coord_constructors[meta->coords_count - 1]; 733 expr += coord_constructors.at(count + (has_array ? 1 : 0) + (has_shadow ? 1 : 0) - 1);
731 expr += '('; 734 expr += '(';
732 for (u32 i = 0; i < count; ++i) { 735 for (u32 i = 0; i < count; ++i) {
733 const bool is_extra = i >= meta->coords_count; 736 expr += Visit(operation[i]);
734 const bool is_array = i == meta->array_index;
735
736 std::string operand = [&]() {
737 if (is_extra && is_extra_int) {
738 if (const auto immediate = std::get_if<ImmediateNode>(operation[i])) {
739 return std::to_string(static_cast<s32>(immediate->GetValue()));
740 } else {
741 return "ftoi(" + Visit(operation[i]) + ')';
742 }
743 } else {
744 return Visit(operation[i]);
745 }
746 }();
747 if (is_array) {
748 ASSERT(!is_extra);
749 operand = "float(ftoi(" + operand + "))";
750 }
751
752 expr += operand;
753 737
754 if (i + 1 == meta->coords_count) { 738 const u32 next = i + 1;
755 expr += ')'; 739 if (next < count || has_array || has_shadow)
756 } 740 expr += ", ";
757 if (i + 1 < count) { 741 }
742 if (has_array) {
743 expr += "float(ftoi(" + Visit(meta->array) + "))";
744 }
745 if (has_shadow) {
746 if (has_array)
758 expr += ", "; 747 expr += ", ";
748 expr += Visit(meta->depth_compare);
749 }
750 expr += ')';
751
752 for (const Node extra : meta->extras) {
753 expr += ", ";
754 if (is_extra_int) {
755 if (const auto immediate = std::get_if<ImmediateNode>(extra)) {
756 // Inline the string as an immediate integer in GLSL (some extra arguments are
757 // required to be constant)
758 expr += std::to_string(static_cast<s32>(immediate->GetValue()));
759 } else {
760 expr += "ftoi(" + Visit(extra) + ')';
761 }
762 } else {
763 expr += Visit(extra);
759 } 764 }
760 } 765 }
766
761 expr += ')'; 767 expr += ')';
762 return expr; 768 return expr;
763 } 769 }
@@ -1198,26 +1204,29 @@ private:
1198 std::string F4TexelFetch(Operation operation) { 1204 std::string F4TexelFetch(Operation operation) {
1199 constexpr std::array<const char*, 4> constructors = {"int", "ivec2", "ivec3", "ivec4"}; 1205 constexpr std::array<const char*, 4> constructors = {"int", "ivec2", "ivec3", "ivec4"};
1200 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta()); 1206 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
1201 const auto count = static_cast<u32>(operation.GetOperandsCount());
1202 ASSERT(meta); 1207 ASSERT(meta);
1208 UNIMPLEMENTED_IF(meta->sampler.IsArray());
1209 UNIMPLEMENTED_IF(!meta->extras.empty());
1210
1211 const auto count = static_cast<u32>(operation.GetOperandsCount());
1203 1212
1204 std::string expr = "texelFetch("; 1213 std::string expr = "texelFetch(";
1205 expr += GetSampler(meta->sampler); 1214 expr += GetSampler(meta->sampler);
1206 expr += ", "; 1215 expr += ", ";
1207 1216
1208 expr += constructors[meta->coords_count - 1]; 1217 expr += constructors.at(count - 1);
1209 expr += '('; 1218 expr += '(';
1210 for (u32 i = 0; i < count; ++i) { 1219 for (u32 i = 0; i < count; ++i) {
1211 expr += VisitOperand(operation, i, Type::Int); 1220 expr += VisitOperand(operation, i, Type::Int);
1212 1221
1213 if (i + 1 == meta->coords_count) { 1222 const u32 next = i + 1;
1223 if (next == count)
1214 expr += ')'; 1224 expr += ')';
1215 } 1225 if (next < count)
1216 if (i + 1 < count) {
1217 expr += ", "; 1226 expr += ", ";
1218 }
1219 } 1227 }
1220 expr += ')'; 1228 expr += ')';
1229
1221 return expr + GetSwizzle(meta->element); 1230 return expr + GetSwizzle(meta->element);
1222 } 1231 }
1223 1232