From fe7996a5985e8e7064004d2f42758d89ebf54b57 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 6 Apr 2021 12:48:44 +0300 Subject: [PATCH] Leave no-op constructors as they are In particular, don't break a matrix down into columns and construct it again. These could just be removed from the AST entirely, but the expression resolver currently does not do node replacement and it's easier to just skip this in the backend. --- source/glsl/resolve.cpp | 2 ++ tests/glsl/no_op_conversion.glsl | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/glsl/no_op_conversion.glsl diff --git a/source/glsl/resolve.cpp b/source/glsl/resolve.cpp index 3201ea1b..2b18c84b 100644 --- a/source/glsl/resolve.cpp +++ b/source/glsl/resolve.cpp @@ -883,6 +883,8 @@ void ExpressionResolver::visit_constructor(FunctionCall &call) map::const_iterator i = stage->types.find(call.name); if(i==stage->types.end()) return; + else if(call.arguments.size()==1 && i->second==call.arguments[0]->type) + ; else if(BasicTypeDeclaration *basic = dynamic_cast(i->second)) { BasicTypeDeclaration *elem = get_element_type(*basic); diff --git a/tests/glsl/no_op_conversion.glsl b/tests/glsl/no_op_conversion.glsl new file mode 100644 index 00000000..2e3ff57b --- /dev/null +++ b/tests/glsl/no_op_conversion.glsl @@ -0,0 +1,17 @@ +uniform mat4 mvp; + +#pragma MSP stage(vertex) +layout(location=0) in vec4 position; +int main() +{ + gl_Position = mat4(mvp)*vec4(position); +} + +/* Expected output: vertex +layout(location=0) uniform mat4 mvp; +layout(location=0) in vec4 position; +int main() +{ + gl_Position = mat4(mvp)*vec4(position); +} +*/ -- 2.45.2