summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-11 19:47:48 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-11 20:02:51 -0400
commit8e3c978fc86c7a7dea0ab7820cb0f81ccd87c706 (patch)
treee015cdf6a872093b9091afd788f9749e6487f2f8
parent34a13ce4cc287aa60124c05cd9c017e586f9c244 (diff)
Enable float/int casts for non-WebGL target.
-rw-r--r--src/LambdaCube/Compiler/CoreToIR.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs
index 45bfa1ad..30353129 100644
--- a/src/LambdaCube/Compiler/CoreToIR.hs
+++ b/src/LambdaCube/Compiler/CoreToIR.hs
@@ -724,7 +724,7 @@ genGLSLs backend
724 | null fsa = return (us, fsb) 724 | null fsa = return (us, fsb)
725 | otherwise = do 725 | otherwise = do
726 (unzip -> (defs, unzip -> (us', fs'))) <- forM fsa $ \(fn, (def, ty, tys)) -> 726 (unzip -> (defs, unzip -> (us', fs'))) <- forM fsa $ \(fn, (def, ty, tys)) ->
727 runWriterT $ genGLSL (reverse $ take (length tys) funArgs) $ removeLams (length tys) def 727 runWriterT $ genGLSL backend (reverse $ take (length tys) funArgs) $ removeLams (length tys) def
728 let fsb' = mconcat (zipWith combine fsa defs) <> fsb 728 let fsb' = mconcat (zipWith combine fsa defs) <> fsb
729 ns' = ns <> Set.fromList (map fst fsa) 729 ns' = ns <> Set.fromList (map fst fsa)
730 fixFuncs (us <> mconcat us') ns' fsb' (mconcat fs' `Map.difference` Map.fromSet (const undefined) ns') 730 fixFuncs (us <> mconcat us') ns' fsb' (mconcat fs' `Map.difference` Map.fromSet (const undefined) ns')
@@ -753,7 +753,7 @@ genGLSLs backend
753 reds (etaReds -> Just (ps, o)) = (ps, o) 753 reds (etaReds -> Just (ps, o)) = (ps, o)
754 reds x = error $ "red: " ++ ppShow x 754 reds x = error $ "red: " ++ ppShow x
755 genGLSL' err vertOuts (ps, o) 755 genGLSL' err vertOuts (ps, o)
756 | length ps == length vertOuts = genGLSL (reverse vertOuts) o 756 | length ps == length vertOuts = genGLSL backend (reverse vertOuts) o
757 | otherwise = error $ "makeSubst illegal input " ++ err ++ " " ++ ppShow ps ++ "\n" ++ ppShow vertOuts 757 | otherwise = error $ "makeSubst illegal input " ++ err ++ " " ++ ppShow ps ++ "\n" ++ ppShow vertOuts
758 758
759 noUnit TTuple0 = False 759 noUnit TTuple0 = False
@@ -814,8 +814,8 @@ simpleExpr = \case
814 _ -> False 814 _ -> False
815 _ -> False 815 _ -> False
816 816
817genGLSL :: [SName] -> ExpTV -> WriterT (Uniforms, Map.Map SName (ExpTV, ExpTV, [ExpTV])) (State [String]) Doc 817genGLSL :: Backend -> [SName] -> ExpTV -> WriterT (Uniforms, Map.Map SName (ExpTV, ExpTV, [ExpTV])) (State [String]) Doc
818genGLSL dns e = case e of 818genGLSL backend dns e = case e of
819 819
820 ELit a -> pure $ pShow a 820 ELit a -> pure $ pShow a
821 Var i _ -> pure $ text $ dns !! i 821 Var i _ -> pure $ text $ dns !! i
@@ -948,12 +948,18 @@ genGLSL dns e = case e of
948 _ -> "" 948 _ -> ""
949 949
950 -- not supported 950 -- not supported
951 n | n `elem` ["primIntToWord", "primIntToFloat", "primCompareInt", "primCompareWord", "primCompareFloat"] -> error $ "WebGL 1 does not support: " ++ ppShow e 951 n | isWebGL && n `elem` ["primIntToWord", "primIntToFloat", "primCompareInt", "primCompareWord", "primCompareFloat"] -> error $ "WebGL 1 does not support: " ++ ppShow e
952 n | n `elem` ["M23F", "M24F", "M32F", "M34F", "M42F", "M43F"] -> error "WebGL 1 does not support matrices with this dimension" 952 n | isWebGL && n `elem` ["M23F", "M24F", "M32F", "M34F", "M42F", "M43F"] -> error "WebGL 1 does not support matrices with this dimension"
953
954 "primIntToFloat" -> call "float" xs
955
953 x -> error $ "GLSL codegen - unsupported function: " ++ ppShow x 956 x -> error $ "GLSL codegen - unsupported function: " ++ ppShow x
954 957
955 x -> error $ "GLSL codegen - unsupported expression: " ++ ppShow x 958 x -> error $ "GLSL codegen - unsupported expression: " ++ ppShow x
956 where 959 where
960 isWebGL = case backend of WebGL1 -> True
961 _ -> False
962
957 newName = gets head <* modify tail 963 newName = gets head <* modify tail
958 964
959 call f xs = case f of 965 call f xs = case f of
@@ -963,7 +969,7 @@ genGLSL dns e = case e of
963 [op, '_'] -> case xs of [a] -> (text [op] <+>) . parens <$> gen a 969 [op, '_'] -> case xs of [a] -> (text [op] <+>) . parens <$> gen a
964 o -> case xs of [a, b] -> hsep <$> sequence [parens <$> gen a, pure $ text o, parens <$> gen b] 970 o -> case xs of [a, b] -> hsep <$> sequence [parens <$> gen a, pure $ text o, parens <$> gen b]
965 971
966 gen = genGLSL dns 972 gen = genGLSL backend dns
967 973
968 isMatrix :: Ty -> Bool 974 isMatrix :: Ty -> Bool
969 isMatrix TMat{} = True 975 isMatrix TMat{} = True