From f3d1b370aa0fd614cf28f8a609b70906d40da751 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 12 Nov 2019 10:07:22 -0400 Subject: Shader_IR: Implement FLO instruction. --- src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/video_core/renderer_opengl/gl_shader_decompiler.cpp') diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index e56ed51de..b87ee2ae8 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -1472,6 +1472,11 @@ private: return GenerateUnary(operation, "bitCount", type, type); } + template + 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"; @@ -2043,6 +2048,7 @@ private: &GLSLDecompiler::BitfieldInsert, &GLSLDecompiler::BitfieldExtract, &GLSLDecompiler::BitCount, + &GLSLDecompiler::BitMSB, &GLSLDecompiler::Add, &GLSLDecompiler::Mul, @@ -2061,6 +2067,7 @@ private: &GLSLDecompiler::BitfieldInsert, &GLSLDecompiler::BitfieldExtract, &GLSLDecompiler::BitCount, + &GLSLDecompiler::BitMSB, &GLSLDecompiler::Add, &GLSLDecompiler::Mul, -- cgit v1.2.3 From cd0f5dfc17209eab146879faad51186b130c4951 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 12 Nov 2019 13:43:08 -0400 Subject: Shader_IR: Implement TXD instruction. --- .../renderer_opengl/gl_shader_decompiler.cpp | 44 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/video_core/renderer_opengl/gl_shader_decompiler.cpp') diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index b87ee2ae8..49f0b1620 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -44,8 +44,9 @@ using Operation = const OperationNode&; enum class Type { Void, Bool, Bool2, Float, Int, Uint, HalfFloat }; struct TextureAoffi {}; +struct TextureDerivates {}; using TextureArgument = std::pair; -using TextureIR = std::variant; +using TextureIR = std::variant; constexpr u32 MAX_CONSTBUFFER_ELEMENTS = static_cast(Maxwell::MaxConstBufferSize) / (4 * sizeof(float)); @@ -1129,6 +1130,8 @@ private: expr += GenerateTextureArgument(*argument); } else if (std::holds_alternative(variant)) { expr += GenerateTextureAoffi(meta->aoffi); + } else if (std::holds_alternative(variant)) { + expr += GenerateTextureDerivates(meta->derivates); } else { UNREACHABLE(); } @@ -1198,6 +1201,36 @@ private: return expr; } + std::string GenerateTextureDerivates(const std::vector& 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()}; @@ -1777,6 +1810,14 @@ private: return {tmp, Type::Float}; } + Expression TextureGradient(Operation operation) { + const auto meta = std::get_if(&operation.GetMeta()); + ASSERT(meta); + + std::string expr = GenerateTexture(operation, "Grad", {TextureDerivates{}, TextureAoffi{}}); + return {expr + GetSwizzle(meta->element), Type::Float}; + } + Expression ImageLoad(Operation operation) { if (!device.HasImageLoadFormatted()) { LOG_ERROR(Render_OpenGL, @@ -2131,6 +2172,7 @@ private: &GLSLDecompiler::TextureQueryDimensions, &GLSLDecompiler::TextureQueryLod, &GLSLDecompiler::TexelFetch, + &GLSLDecompiler::TextureGradient, &GLSLDecompiler::ImageLoad, &GLSLDecompiler::ImageStore, -- cgit v1.2.3 From c8473f399e745993d2b9980f4ef62fa6a208ec3d Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Mon, 18 Nov 2019 07:34:34 -0400 Subject: Shader_IR: Address Feedback --- src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/video_core/renderer_opengl/gl_shader_decompiler.cpp') diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 49f0b1620..f7b77711a 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -1815,7 +1815,7 @@ private: ASSERT(meta); std::string expr = GenerateTexture(operation, "Grad", {TextureDerivates{}, TextureAoffi{}}); - return {expr + GetSwizzle(meta->element), Type::Float}; + return {std::move(expr) + GetSwizzle(meta->element), Type::Float}; } Expression ImageLoad(Operation operation) { -- cgit v1.2.3