<div dir="ltr">I think this would be correct to do and would fix the bug at hand but there may be other bugs lurking deeper.  In particular, if you have multiple shaders for the same stage that share some global variables and get linked together, I think you could run into the same issue only with a read-write global.  If this is indeed possible, then I'm not sure what to do.  We have to run this pass prior to doing any optimization because we depend on it to get precise and invariant correct.  On the other hand, it has to be run after linking. :-/  Maybe we just have to assume precise and invariant for all pre-linking optimizations and then run this post-linking.<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Aug 22, 2018 at 7:51 AM Danylo Piliaiev <<a href="mailto:danylo.piliaiev@gmail.com">danylo.piliaiev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Read-only variables could be considered inherently invariant and precise<br>
since no expression in shader affects them.<br>
Explicitly marking them as such is unnecessary and can cause issues,<br>
e.g. uniform marked as invariant may require the same uniform in other<br>
stage to be invariant too but uniforms cannot have "invariant" qualifier.<br>
<br>
Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=100316" rel="noreferrer" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=100316</a><br>
<br>
Signed-off-by: Danylo Piliaiev <<a href="mailto:danylo.piliaiev@globallogic.com" target="_blank">danylo.piliaiev@globallogic.com</a>><br>
---<br>
My assumption is that variable being read_only means that it either<br>
loads a value from an external source or is initialized from constant value.<br>
>From what I saw in code it's true but it may be wrong to depend on it.<br>
<br>
 src/compiler/glsl/propagate_invariance.cpp | 10 ++++++++++<br>
 1 file changed, 10 insertions(+)<br>
<br>
diff --git a/src/compiler/glsl/propagate_invariance.cpp b/src/compiler/glsl/propagate_invariance.cpp<br>
index b3f1d810cd..0e4233aa9f 100644<br>
--- a/src/compiler/glsl/propagate_invariance.cpp<br>
+++ b/src/compiler/glsl/propagate_invariance.cpp<br>
@@ -96,6 +96,16 @@ ir_invariance_propagation_visitor::visit(ir_dereference_variable *ir)<br>
    if (this->dst_var == NULL)<br>
       return visit_continue;<br>
<br>
+   /* Read-only variables could be considered inherently<br>
+    * invariant and precise since no expression in shader affects them.<br>
+    * Explicitly marking them as such is unnecessary and can cause<br>
+    * issues, e.g. uniform marked as invariant may require the same<br>
+    * uniform in other stage to be invariant too but uniforms cannot<br>
+    * have "invariant" qualifier.<br>
+    */<br>
+   if (ir->var->data.read_only)<br>
+      return visit_continue;<br>
+<br>
    if (this->dst_var->data.invariant) {<br>
       if (!ir->var->data.invariant)<br>
          this->progress = true;<br>
-- <br>
2.18.0<br>
<br>
</blockquote></div>