Closed zeux closed 5 years ago
Ok, reproduced. I believe this is because a use of OpAccessChain does not propagate an expression use to its dependent expressions.
On deeper analysis it's more complicated than that. This affects OpLoad as well. I'm working on adding a more robust expression tracking flow for cases like Load/AccessChain where subexpressions are embedded into another expression and we need to track expression reads independently.
Should be fixed now. If you still see similar cases for more complex shaders, please create a new issue.
I'm not sure whether this affects performance - if the Metal compiler does LICM perfectly then it shouldn't - but it definitely affects readability and I don't feel safe trusting that LICM for specifically texture reads works correctly :)
On a simple shader like this:
Compiling the shader as follows:
I get the following output:
Instead of this I'm expecting that
tex.read
results will be stored into a local variable.