Open floybix opened 7 years ago
I need this fix as well.
Heads up. I ran in to problems of computational scalability after submitting this pull request. Once I reached some number of inputs or operations it was taking about a minute for gamma's compile to run. I must admit that I didn't test whether that was due to my change or not; I realised that my use case was highly structured so I could easily generate the GLSL myself without using Gamma.
Thanks for the heads up! I ran into the same problem: taking a minute for gamma's compile to run. In addition, it doesn't succeed in compiling. Without nested assignments it is 10 times faster and doesn't give a compile error (but the shader doesn't work, anyway it's a work in progress). I am getting a lot of these errors with nested assignments and sufficient complexity of the shader:
3889: declaration error on: {:tag :declaration, :variable {:tag :variable, :id 11887, :type nil}}
For example the following function makes gamma blow up combinatorially:
(defn swizzle-by-index
[vector4 index]
(g/if
(g/== index 0)
(g/swizzle vector4 :x)
(g/if
(g/== index 1)
(g/swizzle vector4 :y)
(g/if
(g/== index 2)
(g/swizzle vector4 :z)
(g/swizzle vector4 :w)))))
I am still interested in writing my shader using gamma, and have started looking into how the gamma compiler works.
Fixes #36
Here's a one-character fix (after hours of pain and suffering!)... making
insert-assignments
recurse into blocks. Or was there a reason that was commented out?I'm not sure if this is fully general, to recurse only into blocks, or if it should walk everything (by mapping over
:body
). Still hazy about how this all works.Another approach which could also fix my case would be to lift all the assignments to the top level, instead of a local block. I think the downside there is potential inefficiency in case conditional calculations are not used.
I also added a basic test, just covers this one case so far.