diff options
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 0e644564a..3d3cd21f3 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -49,8 +49,9 @@ class ExprDecompiler; enum class Type { Void, Bool, Bool2, Float, Int, Uint, HalfFloat }; struct TextureAoffi {}; +struct TextureDerivates {}; using TextureArgument = std::pair<Type, Node>; -using TextureIR = std::variant<TextureAoffi, TextureArgument>; +using TextureIR = std::variant<TextureAoffi, TextureDerivates, TextureArgument>; constexpr u32 MAX_CONSTBUFFER_ELEMENTS = static_cast<u32>(Maxwell::MaxConstBufferSize) / (4 * sizeof(float)); @@ -1112,6 +1113,8 @@ private: expr += GenerateTextureArgument(*argument); } else if (std::holds_alternative<TextureAoffi>(variant)) { expr += GenerateTextureAoffi(meta->aoffi); + } else if (std::holds_alternative<TextureDerivates>(variant)) { + expr += GenerateTextureDerivates(meta->derivates); } else { UNREACHABLE(); } @@ -1181,6 +1184,36 @@ private: return expr; } + std::string GenerateTextureDerivates(const std::vector<Node>& derivates) { + if (derivates.empty()) { + return {}; + } + constexpr std::array coord_constructors = {"float", "vec2", "vec3"}; + std::string expr = ", "; + const std::size_t components = derivates.size() / 2; + std::string dx = coord_constructors.at(components - 1); + std::string dy = coord_constructors.at(components - 1); + dx += '('; + dy += '('; + + for (std::size_t index = 0; index < components; ++index) { + const auto operand_x{derivates.at(index * 2)}; + const auto operand_y{derivates.at(index * 2 + 1)}; + dx += Visit(operand_x).AsFloat(); + dy += Visit(operand_y).AsFloat(); + + if (index + 1 < components) { + dx += ", "; + dy += ", "; + } + } + dx += ')'; + dy += ')'; + expr += dx + ", " + dy; + + return expr; + } + std::string BuildIntegerCoordinates(Operation operation) { constexpr std::array constructors{"int(", "ivec2(", "ivec3(", "ivec4("}; const std::size_t coords_count{operation.GetOperandsCount()}; @@ -1450,6 +1483,11 @@ private: return GenerateUnary(operation, "bitCount", type, type); } + template <Type type> + Expression BitMSB(Operation operation) { + return GenerateUnary(operation, "findMSB", type, type); + } + Expression HNegate(Operation operation) { const auto GetNegate = [&](std::size_t index) { return VisitOperand(operation, index).AsBool() + " ? -1 : 1"; @@ -1738,6 +1776,14 @@ private: return {std::move(expr), Type::Float}; } + Expression TextureGradient(Operation operation) { + const auto meta = std::get_if<MetaTexture>(&operation.GetMeta()); + ASSERT(meta); + + std::string expr = GenerateTexture(operation, "Grad", {TextureDerivates{}, TextureAoffi{}}); + return {std::move(expr) + GetSwizzle(meta->element), Type::Float}; + } + Expression ImageLoad(Operation operation) { if (!device.HasImageLoadFormatted()) { LOG_ERROR(Render_OpenGL, @@ -2003,6 +2049,7 @@ private: &GLSLDecompiler::BitfieldInsert<Type::Int>, &GLSLDecompiler::BitfieldExtract<Type::Int>, &GLSLDecompiler::BitCount<Type::Int>, + &GLSLDecompiler::BitMSB<Type::Int>, &GLSLDecompiler::Add<Type::Uint>, &GLSLDecompiler::Mul<Type::Uint>, @@ -2021,6 +2068,7 @@ private: &GLSLDecompiler::BitfieldInsert<Type::Uint>, &GLSLDecompiler::BitfieldExtract<Type::Uint>, &GLSLDecompiler::BitCount<Type::Uint>, + &GLSLDecompiler::BitMSB<Type::Uint>, &GLSLDecompiler::Add<Type::HalfFloat>, &GLSLDecompiler::Mul<Type::HalfFloat>, @@ -2084,6 +2132,7 @@ private: &GLSLDecompiler::TextureQueryDimensions, &GLSLDecompiler::TextureQueryLod, &GLSLDecompiler::TexelFetch, + &GLSLDecompiler::TextureGradient, &GLSLDecompiler::ImageLoad, &GLSLDecompiler::ImageStore, |