]> git.tdb.fi Git - libs/gl.git/commitdiff
Block further inlining of a variable after component assignment
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Nov 2021 00:09:11 +0000 (02:09 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Nov 2021 01:46:27 +0000 (03:46 +0200)
source/glsl/optimize.cpp
source/glsl/optimize.h
tests/glsl/member_assignment.glsl

index a7f29a16f8991c6342b6e3dcc1de6882da695a7b..c9d3c33a543830f3618a6d2e337d92519026de6c 100644 (file)
@@ -356,7 +356,7 @@ void ExpressionInliner::visit(RefPtr<Expression> &expr)
                ExpressionUse use;
                use.reference = &expr;
                use.ref_scope = current_block;
-               use.blocked = access_write;
+               use.blocked = access_write || r_ref_info->blocked;
 
                if(iteration_body && !r_ref_info->trivial)
                {
@@ -428,10 +428,10 @@ void ExpressionInliner::visit(Assignment &assign)
        r_trivial = true;
        visit(assign.right);
 
-       auto i = assignments.find(assign.target);
+       auto i = assignments.find(assign.target.declaration);
        if(i!=assignments.end())
        {
-               if(iteration_body && i->second->expression)
+               if(iteration_body && i->second && i->second->expression)
                {
                        /* Block inlining into previous references within the iteration
                        statement.  On iterations after the first they would refer to the
@@ -441,6 +441,10 @@ void ExpressionInliner::visit(Assignment &assign)
                                        u.blocked = (k==iteration_body);
                }
 
+               for(; (i!=assignments.end() && i->first.declaration==assign.target.declaration); ++i)
+                       if(targets_overlap(i->first, assign.target))
+                               i->second->blocked = true;
+
                expressions.push_back(ExpressionInfo());
                ExpressionInfo &info = expressions.back();
                info.target = assign.target;
@@ -450,7 +454,7 @@ void ExpressionInliner::visit(Assignment &assign)
                info.assign_scope = current_block;
                info.trivial = r_trivial;
 
-               i->second = &info;
+               assignments[assign.target] = &info;
        }
 
        r_trivial = false;
index 9b7b7affecf58035f19c2457cbd08c8c4adddf3d..82fc78cc546e562b5c77ea096112ae2ec59fab38 100644 (file)
@@ -122,6 +122,7 @@ private:
                Block *assign_scope = 0;
                std::vector<ExpressionUse> uses;
                bool trivial = false;
+               bool blocked = false;
        };
 
        std::list<ExpressionInfo> expressions;
index 8444cfcad76eee26845efe554fde55167967c383..77451db0b77c0e188b3e9bc1ecf6df07767289a6 100644 (file)
@@ -1,9 +1,8 @@
 #pragma MSP stage(vertex)
 void main()
 {
-       vec4 p;
+       vec4 p = vec4(0.0);
        p.x = 1.0;
-       p.y = 0.0;
        p.z = 2.0;
        p.w = 1.0;
        gl_Position = p;
@@ -12,9 +11,8 @@ void main()
 /* Expected output: vertex
 void main()
 {
-       vec4 p;
+       vec4 p = vec4(0.0);
        p.x = 1.0;
-       p.y = 0.0;
        p.z = 2.0;
        p.w = 1.0;
        gl_Position = p;