]> git.tdb.fi Git - libs/gl.git/commitdiff
Leave no-op constructors as they are
authorMikko Rasa <tdb@tdb.fi>
Tue, 6 Apr 2021 09:48:44 +0000 (12:48 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 6 Apr 2021 09:57:39 +0000 (12:57 +0300)
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
tests/glsl/no_op_conversion.glsl [new file with mode: 0644]

index 3201ea1bb2a70665507dd64469916fb0b09daa5c..2b18c84b653bbbc1195f30a69c362137ec5754db 100644 (file)
@@ -883,6 +883,8 @@ void ExpressionResolver::visit_constructor(FunctionCall &call)
        map<string, TypeDeclaration *>::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<BasicTypeDeclaration *>(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 (file)
index 0000000..2e3ff57
--- /dev/null
@@ -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);
+}
+*/