-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The 'while' function doesn’t generate correct GLSL code #75
Comments
The culprit function with a "Bug" comment near the problematic part. If someone has any idea to fix this problem (which, by design, seems specific to this only place where GPipe creates a loop), I would be happy to hear it! while :: forall a x. (ShaderType a x) => (a -> S x Bool) -> (a -> a) -> a -> a
while c f i = fromBase x $ while_ (c . fromBase x) (toBase x . f . fromBase x) (toBase x i)
where
x = undefined :: x
while_
:: (ShaderBase (ShaderBaseType a) x -> S x Bool)
-> (ShaderBase (ShaderBaseType a) x -> ShaderBase (ShaderBaseType a) x)
-> ShaderBase (ShaderBaseType a) x -> ShaderBase (ShaderBaseType a) x
while_ bool loopF a =
let whileM = memoizeM $ do
(lifted, decls) <- runWriterT $ shaderbaseDeclare (toBase x (errShaderType :: a))
void $ evalStateT (shaderbaseAssign a) decls
boolDecl <- tellAssignment STypeBool (unS $ bool a)
T.lift $ T.lift $ tell $ mconcat ["while(", boolDecl, "){\n" ]
let looped = loopF lifted
scopedM $ do
-- Bug: reassigning back to the same var (in decls) breaks the functional referential transparency.
void $ evalStateT (shaderbaseAssign looped) decls
loopedBoolStr <- unS $ bool looped
tellAssignment' boolDecl loopedBoolStr
T.lift $ T.lift $ tell "}\n"
return decls
in evalState (runReaderT (shaderbaseReturn (toBase x (errShaderType :: a))) whileM) 0 |
I've ended up with this solution to fix the issue: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See for yourself:
Working around this issue is easy, but the resulting code obviously doesn’t look right from the Haskell side.
The text was updated successfully, but these errors were encountered: