diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2018-09-22 11:26:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-22 11:26:15 +0200 |
commit | 65749d86dcc41b7de09d96834411031064bccff6 (patch) | |
tree | ae38d45354c552c5ab09f54e29cb547c22c37b89 | |
parent | f4ad4265e6b6aeedc018f80da4ab39e75b5e16e0 (diff) | |
parent | a153afd1ed674c0a0b8b520b9e5c2b1449f84fb0 (diff) |
Merge pull request #15 from deepfire/integer-image-capability
compValue: allow literal integers to be processed
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | lambdacube-compiler.cabal | 112 | ||||
-rw-r--r-- | lc/Builtins.lc | 1 | ||||
-rw-r--r-- | src/LambdaCube/Compiler.hs | 4 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/CoreToIR.hs | 118 | ||||
-rw-r--r-- | testdata/Builtins.out | 163 | ||||
-rw-r--r-- | testdata/graphics-features/pickInt.lc | 25 | ||||
-rw-r--r-- | testdata/graphics-features/pickInt.out | 111 | ||||
-rw-r--r-- | testdata/graphics-features/pickInt.ppl | 110 |
9 files changed, 520 insertions, 127 deletions
@@ -1,9 +1,12 @@ | |||
1 | *~ | 1 | *~ |
2 | dist | 2 | dist |
3 | dist-newstyle | ||
3 | *.hi | 4 | *.hi |
4 | *.o | 5 | *.o |
5 | lambdacube-compiler-test-suite.prof | 6 | lambdacube-compiler-test-suite.prof |
6 | lambdacube-compiler-test-suite.tix | 7 | lambdacube-compiler-test-suite.tix |
7 | *cabal-sandbox* | 8 | *cabal-sandbox* |
8 | *cabal.sandbox* | 9 | *cabal.sandbox* |
10 | .ghc.environment.* | ||
11 | .dir-locals.el | ||
9 | .stack-work | 12 | .stack-work |
diff --git a/lambdacube-compiler.cabal b/lambdacube-compiler.cabal index 5d57aece..6d47d950 100644 --- a/lambdacube-compiler.cabal +++ b/lambdacube-compiler.cabal | |||
@@ -96,7 +96,7 @@ library | |||
96 | binary, | 96 | binary, |
97 | bytestring, | 97 | bytestring, |
98 | time, | 98 | time, |
99 | aeson >=1.1, | 99 | aeson, |
100 | base >=4.9, | 100 | base >=4.9, |
101 | semigroups, | 101 | semigroups, |
102 | containers >=0.5, | 102 | containers >=0.5, |
@@ -129,12 +129,12 @@ executable lc | |||
129 | 129 | ||
130 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository | 130 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository |
131 | build-depends: | 131 | build-depends: |
132 | base < 5, | 132 | base , |
133 | lambdacube-compiler, | 133 | lambdacube-compiler, |
134 | optparse-applicative >=0.12 && <0.15, | 134 | optparse-applicative >=0.12, |
135 | aeson >=1.1 && <1.3, | 135 | aeson, |
136 | bytestring, | 136 | bytestring, |
137 | filepath >=1.4 && <1.5 | 137 | filepath >=1.4 |
138 | 138 | ||
139 | ------------------------ | 139 | ------------------------ |
140 | -- tests for development | 140 | -- tests for development |
@@ -152,14 +152,14 @@ executable lambdacube-compiler-unit-tests | |||
152 | 152 | ||
153 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository | 153 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository |
154 | build-depends: | 154 | build-depends: |
155 | base < 5, | 155 | base, |
156 | semigroups, | 156 | semigroups, |
157 | containers >=0.5 && <0.6, | 157 | containers >=0.5, |
158 | lambdacube-compiler, | 158 | lambdacube-compiler, |
159 | megaparsec >= 6, | 159 | megaparsec >= 6, |
160 | QuickCheck >= 2.8.2 && <2.11, | 160 | QuickCheck >= 2.8.2, |
161 | tasty >= 0.11 && <0.12, | 161 | tasty >= 0.11, |
162 | tasty-quickcheck >=0.8 && <0.10 | 162 | tasty-quickcheck >=0.8 |
163 | 163 | ||
164 | executable lambdacube-compiler-test-suite | 164 | executable lambdacube-compiler-test-suite |
165 | hs-source-dirs: test | 165 | hs-source-dirs: test |
@@ -178,26 +178,26 @@ executable lambdacube-compiler-test-suite | |||
178 | 178 | ||
179 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository | 179 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository |
180 | build-depends: | 180 | build-depends: |
181 | aeson >=1.1 && <1.3, | 181 | aeson, |
182 | async >= 2.0 && <2.2, | 182 | async >= 2.0, |
183 | base < 5, | 183 | base, |
184 | semigroups, | 184 | semigroups, |
185 | containers >=0.5 && <0.6, | 185 | containers >=0.5, |
186 | deepseq >=1.4 && <1.5, | 186 | deepseq >=1.4, |
187 | directory >=1.3 && <1.4, | 187 | directory >=1.3, |
188 | exceptions >= 0.8 && <0.9, | 188 | exceptions >= 0.8, |
189 | filepath >=1.4 && <1.5, | 189 | filepath >=1.4, |
190 | lambdacube-compiler, | 190 | lambdacube-compiler, |
191 | mtl >=2.2 && <2.3, | 191 | mtl >=2.2, |
192 | monad-control >= 1.0 && <1.1, | 192 | monad-control >= 1.0, |
193 | optparse-applicative >=0.12 && <0.15, | 193 | optparse-applicative >=0.12, |
194 | megaparsec >= 6, | 194 | megaparsec >= 6, |
195 | ansi-wl-pprint >=0.6 && <0.7, | 195 | ansi-wl-pprint >=0.6, |
196 | patience >= 0.1 && < 0.2, | 196 | patience >= 0.1, |
197 | text >= 1.2 && <1.3, | 197 | text >= 1.2, |
198 | time >= 1.5 && <1.9, | 198 | time >= 1.5, |
199 | lambdacube-ir == 0.3.*, | 199 | lambdacube-ir == 0.3.*, |
200 | vector >= 0.12 && <0.13 | 200 | vector >= 0.12 |
201 | 201 | ||
202 | executable lambdacube-compiler-performance-report | 202 | executable lambdacube-compiler-performance-report |
203 | hs-source-dirs: test | 203 | hs-source-dirs: test |
@@ -211,11 +211,11 @@ executable lambdacube-compiler-performance-report | |||
211 | 211 | ||
212 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository | 212 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository |
213 | build-depends: | 213 | build-depends: |
214 | base < 5, | 214 | base, |
215 | directory >=1.3 && <1.4, | 215 | directory >=1.3, |
216 | filepath >=1.4 && <1.5, | 216 | filepath >=1.4, |
217 | containers >=0.5 && <0.6, | 217 | containers >=0.5, |
218 | optparse-applicative >=0.12 && <0.15 | 218 | optparse-applicative >=0.12 |
219 | 219 | ||
220 | executable lambdacube-backend-test-server | 220 | executable lambdacube-backend-test-server |
221 | hs-source-dirs: backendtest | 221 | hs-source-dirs: backendtest |
@@ -231,23 +231,23 @@ executable lambdacube-backend-test-server | |||
231 | 231 | ||
232 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository | 232 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository |
233 | build-depends: | 233 | build-depends: |
234 | base < 5, | 234 | base, |
235 | semigroups, | 235 | semigroups, |
236 | containers >=0.5 && <0.6, | 236 | containers >=0.5, |
237 | text >= 1.2 && <1.3, | 237 | text >= 1.2, |
238 | lambdacube-compiler, | 238 | lambdacube-compiler, |
239 | lambdacube-ir == 0.3.*, | 239 | lambdacube-ir == 0.3.*, |
240 | pretty-show >= 1.6.9, | 240 | pretty-show >= 1.6.9, |
241 | optparse-applicative >=0.12 && <0.15, | 241 | optparse-applicative >=0.12, |
242 | aeson >=1.1 && <1.3, | 242 | aeson, |
243 | bytestring, | 243 | bytestring, |
244 | filepath >=1.4 && <1.5, | 244 | filepath >=1.4, |
245 | directory >=1.3 && <1.4, | 245 | directory >=1.3, |
246 | websockets >= 0.9.6.1, | 246 | websockets >= 0.9.6.1, |
247 | JuicyPixels >=3.2.7 && <3.3, | 247 | JuicyPixels >=3.2.7, |
248 | vect >= 0.4.7, | 248 | vect >= 0.4.7, |
249 | base64-bytestring >= 1.0.0.1, | 249 | base64-bytestring >= 1.0.0.1, |
250 | vector >= 0.12 && <0.13, | 250 | vector >= 0.12, |
251 | process >= 1.2 | 251 | process >= 1.2 |
252 | 252 | ||
253 | executable lambdacube-compiler-coverage-test-suite | 253 | executable lambdacube-compiler-coverage-test-suite |
@@ -267,25 +267,25 @@ executable lambdacube-compiler-coverage-test-suite | |||
267 | 267 | ||
268 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository | 268 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository |
269 | build-depends: | 269 | build-depends: |
270 | aeson >=1.1 && <1.3, | 270 | aeson, |
271 | async >= 2.0 && <2.2, | 271 | async >= 2.0, |
272 | base < 5, | 272 | base, |
273 | bytestring, | 273 | bytestring, |
274 | binary, | 274 | binary, |
275 | semigroups, | 275 | semigroups, |
276 | containers >=0.5 && <0.6, | 276 | containers >=0.5, |
277 | deepseq >=1.4 && <1.5, | 277 | deepseq >=1.4, |
278 | directory >=1.3 && <1.4, | 278 | directory >=1.3, |
279 | exceptions >= 0.8 && <0.9, | 279 | exceptions >= 0.8, |
280 | filepath >=1.4 && <1.5, | 280 | filepath >=1.4, |
281 | lambdacube-ir == 0.3.*, | 281 | lambdacube-ir == 0.3.*, |
282 | mtl >=2.2 && <2.3, | 282 | mtl >=2.2, |
283 | monad-control >= 1.0 && <1.1, | 283 | monad-control >= 1.0, |
284 | optparse-applicative >=0.12 && <0.15, | 284 | optparse-applicative >=0.12, |
285 | megaparsec >= 6, | 285 | megaparsec >= 6, |
286 | ansi-wl-pprint >=0.6 && <0.7, | 286 | ansi-wl-pprint >=0.6, |
287 | pretty-show >= 1.6.9, | 287 | pretty-show >= 1.6.9, |
288 | patience >= 0.1 && < 0.2, | 288 | patience >= 0.1, |
289 | text >= 1.2 && <1.3, | 289 | text >= 1.2, |
290 | time >= 1.5 && <1.9, | 290 | time >= 1.5, |
291 | vector >= 0.12 && <0.13 | 291 | vector >= 0.12 |
diff --git a/lc/Builtins.lc b/lc/Builtins.lc index 03970dbd..15840268 100644 --- a/lc/Builtins.lc +++ b/lc/Builtins.lc | |||
@@ -539,6 +539,7 @@ PrjImageColor :: FrameBuffer 1 '[ 'Depth, 'Color (Vec 4 Float)] -> Image 1 | |||
539 | 539 | ||
540 | data Output where | 540 | data Output where |
541 | ScreenOut :: FrameBuffer a b -> Output | 541 | ScreenOut :: FrameBuffer a b -> Output |
542 | TextureOut :: Vec 2 Int -> FrameBuffer a b -> Output | ||
542 | 543 | ||
543 | renderFrame = ScreenOut | 544 | renderFrame = ScreenOut |
544 | 545 | ||
diff --git a/src/LambdaCube/Compiler.hs b/src/LambdaCube/Compiler.hs index c0fef7a0..6a65c811 100644 --- a/src/LambdaCube/Compiler.hs +++ b/src/LambdaCube/Compiler.hs | |||
@@ -157,9 +157,9 @@ loadModule ex imp mname_ = do | |||
157 | ms <- forM (moduleImports e) $ \(m, is) -> loadModule ex (Just fname) (Right $ sName m) <&> \r -> case r of | 157 | ms <- forM (moduleImports e) $ \(m, is) -> loadModule ex (Just fname) (Right $ sName m) <&> \r -> case r of |
158 | Left err -> Left $ pShow m <+> "is not found" | 158 | Left err -> Left $ pShow m <+> "is not found" |
159 | Right (fb, (src, dsge)) -> | 159 | Right (fb, (src, dsge)) -> |
160 | either (Left . const (pShow m <+> "couldn't be parsed")) | 160 | either (Left . (\errm-> pShow m <+> "couldn't be parsed:\n" <+> errm)) |
161 | (\(pm, x, e) -> either | 161 | (\(pm, x, e) -> either |
162 | (Left . const (pShow m <+> "couldn't be typechecked")) | 162 | (Left . (\errm-> pShow m <+> "couldn't be typechecked:\n" <+> errm)) |
163 | (\(ds, ge) -> Right (ds{-todo: filter-}, Map.filterWithKey (\k _ -> filterImports is k) ge)) | 163 | (\(ds, ge) -> Right (ds{-todo: filter-}, Map.filterWithKey (\k _ -> filterImports is k) ge)) |
164 | e) | 164 | e) |
165 | dsge | 165 | dsge |
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs index 4b75c182..feb1d6e2 100644 --- a/src/LambdaCube/Compiler/CoreToIR.hs +++ b/src/LambdaCube/Compiler/CoreToIR.hs | |||
@@ -21,6 +21,8 @@ import Data.List | |||
21 | import qualified Data.Map as Map | 21 | import qualified Data.Map as Map |
22 | import qualified Data.Set as Set | 22 | import qualified Data.Set as Set |
23 | import qualified Data.Vector as Vector | 23 | import qualified Data.Vector as Vector |
24 | import GHC.Stack | ||
25 | import GHC.Word | ||
24 | import Control.Arrow hiding ((<+>)) | 26 | import Control.Arrow hiding ((<+>)) |
25 | import Control.Monad.Writer | 27 | import Control.Monad.Writer |
26 | import Control.Monad.State | 28 | import Control.Monad.State |
@@ -36,6 +38,8 @@ import LambdaCube.Compiler.Core (Subst(..), down, nType) | |||
36 | import qualified LambdaCube.Compiler.Core as I | 38 | import qualified LambdaCube.Compiler.Core as I |
37 | import LambdaCube.Compiler.Infer (neutType', makeCaseFunPars') | 39 | import LambdaCube.Compiler.Infer (neutType', makeCaseFunPars') |
38 | 40 | ||
41 | import Debug.Trace | ||
42 | |||
39 | import Data.Version | 43 | import Data.Version |
40 | import Paths_lambdacube_compiler (version) | 44 | import Paths_lambdacube_compiler (version) |
41 | 45 | ||
@@ -57,7 +61,12 @@ compilePipeline backend exp = IR.Pipeline | |||
57 | ((subCmds,cmds), (streams, programs, targets, slots, textures)) | 61 | ((subCmds,cmds), (streams, programs, targets, slots, textures)) |
58 | = flip runState ((0, mempty), mempty, (0, mempty), mempty, (0, mempty)) $ case toExp exp of | 62 | = flip runState ((0, mempty), mempty, (0, mempty), mempty, (0, mempty)) $ case toExp exp of |
59 | A1 "ScreenOut" a -> addTarget backend a [IR.TargetItem s $ Just $ IR.Framebuffer s | s <- getSemantics a] | 63 | A1 "ScreenOut" a -> addTarget backend a [IR.TargetItem s $ Just $ IR.Framebuffer s | s <- getSemantics a] |
60 | x -> error $ "ScreenOut expected inststead of " ++ ppShow x | 64 | A2 "TextureOut" rtexDimE rtexE -> do |
65 | let rtexDim = case compValue rtexDimE of | ||
66 | IR.VV2I v -> fromIntegral <$> v | ||
67 | x -> error "Render texture dimensions should be a pair of non-negative integrals." | ||
68 | getTextureRenderTargetCommands backend rtexDim rtexE | ||
69 | x -> error $ "ScreenOut or TextureOut expected inststead of " ++ ppShow x | ||
61 | 70 | ||
62 | type CG = State (List IR.StreamData, Map IR.Program Int, List IR.RenderTarget, Map String (Int, IR.Slot), List IR.TextureDescriptor) | 71 | type CG = State (List IR.StreamData, Map IR.Program Int, List IR.RenderTarget, Map String (Int, IR.Slot), List IR.TextureDescriptor) |
63 | 72 | ||
@@ -77,11 +86,16 @@ addLEq l x = modL l $ \sv -> maybe (let i = length sv in i `seq` (i, Map.insert | |||
77 | 86 | ||
78 | --------------------------------------------------------- | 87 | --------------------------------------------------------- |
79 | 88 | ||
89 | addTarget | ||
90 | :: Backend | ||
91 | -> ExpTV | ||
92 | -> [IR.TargetItem] | ||
93 | -> CG ([IR.Command], [IR.Command]) | ||
80 | addTarget backend a tl = do | 94 | addTarget backend a tl = do |
81 | rt <- addL targetLens $ IR.RenderTarget $ Vector.fromList tl | 95 | rt <- addL targetLens $ IR.RenderTarget $ Vector.fromList tl |
82 | second (IR.SetRenderTarget rt:) <$> getCommands backend a | 96 | second (IR.SetRenderTarget rt:) <$> getCommands backend a |
83 | 97 | ||
84 | getCommands :: Backend -> ExpTV{-FrameBuffer-} -> CG ([IR.Command],[IR.Command]) | 98 | getCommands :: HasCallStack => Backend -> ExpTV{-FrameBuffer-} -> CG ([IR.Command],[IR.Command]) |
85 | getCommands backend e = case e of | 99 | getCommands backend e = case e of |
86 | 100 | ||
87 | A1 "FrameBuffer" (ETuple a) -> return ([], [IR.ClearRenderTarget $ Vector.fromList $ map compFrameBuffer a]) | 101 | A1 "FrameBuffer" (ETuple a) -> return ([], [IR.ClearRenderTarget $ Vector.fromList $ map compFrameBuffer a]) |
@@ -90,7 +104,7 @@ getCommands backend e = case e of | |||
90 | 104 | ||
91 | A3 "foldr" (A0 "++") (A0 "Nil") (A2 "map" (EtaPrim3 "rasterizePrimitive" ints rctx) (getVertexShader -> (vert, input_))) -> mdo | 105 | A3 "foldr" (A0 "++") (A0 "Nil") (A2 "map" (EtaPrim3 "rasterizePrimitive" ints rctx) (getVertexShader -> (vert, input_))) -> mdo |
92 | 106 | ||
93 | let | 107 | let |
94 | (vertexInput, pUniforms, vertSrc, fragSrc) = case backend of | 108 | (vertexInput, pUniforms, vertSrc, fragSrc) = case backend of |
95 | -- disabled DX11 codegen, due to it's incomplete | 109 | -- disabled DX11 codegen, due to it's incomplete |
96 | --IR.DirectX11 -> genHLSLs backend (compRC' rctx) ints vert frag ffilter | 110 | --IR.DirectX11 -> genHLSLs backend (compRC' rctx) ints vert frag ffilter |
@@ -98,11 +112,20 @@ getCommands backend e = case e of | |||
98 | 112 | ||
99 | pUniforms' = snd <$> Map.filter ((\case UTexture2D{} -> False; _ -> True) . fst) pUniforms | 113 | pUniforms' = snd <$> Map.filter ((\case UTexture2D{} -> False; _ -> True) . fst) pUniforms |
100 | 114 | ||
115 | imageSemantics = getSemantics e | ||
116 | imageTypes = getImageInputTypes e | ||
117 | outImageType | ||
118 | = case imageTypes of | ||
119 | [] -> error "Component-free pipelines are not supported." | ||
120 | [x] -> x | ||
121 | xs -> flip fromMaybe (lookup IR.Color $ zip imageSemantics xs) $ | ||
122 | error "Multiple outputs, but no Color buffer?" | ||
123 | |||
101 | prg = IR.Program | 124 | prg = IR.Program |
102 | { IR.programUniforms = pUniforms' | 125 | { IR.programUniforms = pUniforms' |
103 | , IR.programStreams = Map.fromList $ zip vertexInput $ map (uncurry IR.Parameter) input | 126 | , IR.programStreams = Map.fromList $ zip vertexInput $ map (uncurry IR.Parameter) input |
104 | , IR.programInTextures = snd <$> Map.filter ((\case UUniform{} -> False; _ -> True) . fst) pUniforms | 127 | , IR.programInTextures = snd <$> Map.filter ((\case UUniform{} -> False; _ -> True) . fst) pUniforms |
105 | , IR.programOutput = pure $ IR.Parameter "f0" IR.V4F -- TODO | 128 | , IR.programOutput = pure $ IR.Parameter "f0" outImageType |
106 | , IR.vertexShader = show vertSrc | 129 | , IR.vertexShader = show vertSrc |
107 | , IR.geometryShader = mempty -- TODO | 130 | , IR.geometryShader = mempty -- TODO |
108 | , IR.fragmentShader = show fragSrc | 131 | , IR.fragmentShader = show fragSrc |
@@ -168,6 +191,7 @@ getCommands backend e = case e of | |||
168 | let (a, tf) = case img of | 191 | let (a, tf) = case img of |
169 | A1 "PrjImageColor" a -> (,) a $ \[_, x] -> x | 192 | A1 "PrjImageColor" a -> (,) a $ \[_, x] -> x |
170 | A1 "PrjImage" a -> (,) a $ \[x] -> x | 193 | A1 "PrjImage" a -> (,) a $ \[x] -> x |
194 | x -> error $ "Unexpected image: " <> ppShow x | ||
171 | tl <- forM (getSemantics a) $ \semantic -> do | 195 | tl <- forM (getSemantics a) $ \semantic -> do |
172 | texture <- addL textureLens IR.TextureDescriptor | 196 | texture <- addL textureLens IR.TextureDescriptor |
173 | { IR.textureType = IR.Texture2D (if semantic == IR.Color then IR.FloatT IR.RGBA else IR.FloatT IR.Red) 1 | 197 | { IR.textureType = IR.Texture2D (if semantic == IR.Color then IR.FloatT IR.RGBA else IR.FloatT IR.Red) 1 |
@@ -194,6 +218,37 @@ getCommands backend e = case e of | |||
194 | return ([(n, tx)], subCmds ++ cmds) | 218 | return ([(n, tx)], subCmds ++ cmds) |
195 | _ -> return mempty | 219 | _ -> return mempty |
196 | 220 | ||
221 | getTextureRenderTargetCommands :: IR.Backend -> IR.V2 Word32 -> ExpTV -> CG ([IR.Command],[IR.Command]) | ||
222 | getTextureRenderTargetCommands backend dim body = do | ||
223 | let semantics = getSemantics body | ||
224 | imageTypes = getImageTextureTypes body | ||
225 | targetItems <- forM (zip semantics imageTypes) | ||
226 | $ \(semantic, imageType) -> do | ||
227 | texture <- addL textureLens IR.TextureDescriptor | ||
228 | { IR.textureType = IR.Texture2D (if semantic == IR.Color | ||
229 | then imageType IR.RGBA | ||
230 | else IR.FloatT IR.Red) | ||
231 | 1 | ||
232 | , IR.textureSize = IR.VV2U dim | ||
233 | , IR.textureSemantic = semantic | ||
234 | , IR.textureSampler = IR.SamplerDescriptor | ||
235 | { IR.samplerWrapS = IR.Repeat | ||
236 | , IR.samplerWrapT = Just IR.Repeat | ||
237 | , IR.samplerWrapR = Nothing | ||
238 | , IR.samplerMinFilter = IR.Nearest | ||
239 | , IR.samplerMagFilter = IR.Nearest | ||
240 | , IR.samplerBorderColor = IR.VV4F (IR.V4 0 0 0 1) | ||
241 | , IR.samplerMinLod = Nothing | ||
242 | , IR.samplerMaxLod = Nothing | ||
243 | , IR.samplerLodBias = 0 | ||
244 | , IR.samplerCompareFunc = Nothing | ||
245 | } | ||
246 | , IR.textureBaseLevel = 0 | ||
247 | , IR.textureMaxLevel = 0 | ||
248 | } | ||
249 | return $ IR.TargetItem semantic $ Just $ IR.TextureImage texture 0 Nothing | ||
250 | addTarget backend body targetItems | ||
251 | |||
197 | type SamplerBinding = (IR.UniformName,IR.ImageRef) | 252 | type SamplerBinding = (IR.UniformName,IR.ImageRef) |
198 | 253 | ||
199 | ---------------------------------------------------------------- | 254 | ---------------------------------------------------------------- |
@@ -201,7 +256,17 @@ type SamplerBinding = (IR.UniformName,IR.ImageRef) | |||
201 | frameBufferType (A2 "FrameBuffer" _ ty) = ty | 256 | frameBufferType (A2 "FrameBuffer" _ ty) = ty |
202 | frameBufferType x = error $ "illegal target type: " ++ ppShow x | 257 | frameBufferType x = error $ "illegal target type: " ++ ppShow x |
203 | 258 | ||
204 | getSemantics = compSemantics . frameBufferType . tyOf | 259 | getFramebufferType :: ExpTV -> [ExpTV] |
260 | getFramebufferType = compList . frameBufferType . tyOf | ||
261 | |||
262 | getSemantics :: ExpTV -> [IR.ImageSemantic] | ||
263 | getSemantics = map compSemantic . getFramebufferType | ||
264 | |||
265 | getImageTextureTypes :: ExpTV -> [IR.ColorArity -> IR.TextureDataType] | ||
266 | getImageTextureTypes = map (imageInputTypeTextureType . compImageInputType) . getFramebufferType | ||
267 | |||
268 | getImageInputTypes :: ExpTV -> [IR.InputType] | ||
269 | getImageInputTypes = map compImageInputType . getFramebufferType | ||
205 | 270 | ||
206 | getFragFilter (A2 "map" (EtaPrim2 "filterFragment" p) x) = (Just p, x) | 271 | getFragFilter (A2 "map" (EtaPrim2 "filterFragment" p) x) = (Just p, x) |
207 | getFragFilter x = (Nothing, x) | 272 | getFragFilter x = (Nothing, x) |
@@ -226,8 +291,6 @@ compFrameBuffer = \case | |||
226 | A1 "ColorImage" a -> IR.ClearImage IR.Color $ compValue a | 291 | A1 "ColorImage" a -> IR.ClearImage IR.Color $ compValue a |
227 | x -> error $ "compFrameBuffer " ++ ppShow x | 292 | x -> error $ "compFrameBuffer " ++ ppShow x |
228 | 293 | ||
229 | compSemantics = map compSemantic . compList | ||
230 | |||
231 | compList (A2 ":" a x) = a : compList x | 294 | compList (A2 ":" a x) = a : compList x |
232 | compList (A0 "Nil") = [] | 295 | compList (A0 "Nil") = [] |
233 | compList x = error $ "compList: " ++ ppShow x | 296 | compList x = error $ "compList: " ++ ppShow x |
@@ -249,6 +312,34 @@ compSemantic = \case | |||
249 | A1 "Color" _ -> IR.Color | 312 | A1 "Color" _ -> IR.Color |
250 | x -> error $ "compSemantic: " ++ ppShow x | 313 | x -> error $ "compSemantic: " ++ ppShow x |
251 | 314 | ||
315 | imageInputTypeTextureType :: HasCallStack => IR.InputType -> (IR.ColorArity -> IR.TextureDataType) | ||
316 | imageInputTypeTextureType = \case | ||
317 | IR.Float -> IR.FloatT | ||
318 | IR.Int -> IR.IntT | ||
319 | IR.V2I -> IR.IntT | ||
320 | IR.V3I -> IR.IntT | ||
321 | IR.V4I -> IR.IntT | ||
322 | IR.V2F -> IR.FloatT | ||
323 | IR.V3F -> IR.FloatT | ||
324 | IR.V4F -> IR.FloatT | ||
325 | x -> error $ "Unsupported input type: " <> show x | ||
326 | |||
327 | -- mirrors Builtins.lc:imageType | ||
328 | compImageInputType :: HasCallStack => ExpTV -> IR.InputType | ||
329 | compImageInputType = \case | ||
330 | A0 "Depth" -> IR.Float | ||
331 | A0 "Stencil" -> IR.Int | ||
332 | A1 "Color" c -> case c of | ||
333 | (A2 "VecS" x y) -> flip fromMaybe (compInputType_ c) $ | ||
334 | error $ "Unexpected (compInputType) color image element type: " <> ppShow c | ||
335 | -- -> case x of | ||
336 | -- A0 "Float" -> (IR.Float, y) | ||
337 | -- A0 "Int" -> (IR.Int, y) | ||
338 | -- A0 "Word" -> (IR.Int, y) | ||
339 | -- _ -> error $ "Unexpected color image component type: " <> ppShow x | ||
340 | _ -> error $ "Unexpected color image element type: " <> ppShow c | ||
341 | x -> error $ "compImageType: " ++ ppShow x | ||
342 | |||
252 | compAC (ETuple x) = IR.AccumulationContext Nothing $ map compFrag x | 343 | compAC (ETuple x) = IR.AccumulationContext Nothing $ map compFrag x |
253 | 344 | ||
254 | compBlending x = case x of | 345 | compBlending x = case x of |
@@ -359,6 +450,7 @@ showGLSLType msg = \case | |||
359 | 450 | ||
360 | supType = isJust . compInputType_ | 451 | supType = isJust . compInputType_ |
361 | 452 | ||
453 | compInputType_ :: ExpTV -> Maybe IR.InputType | ||
362 | compInputType_ x = case x of | 454 | compInputType_ x = case x of |
363 | TFloat -> Just IR.Float | 455 | TFloat -> Just IR.Float |
364 | TVec 2 TFloat -> Just IR.V2F | 456 | TVec 2 TFloat -> Just IR.V2F |
@@ -428,12 +520,16 @@ compFetchPrimitive x = case x of | |||
428 | A0 "TriangleAdjacency" -> IR.TrianglesAdjacency | 520 | A0 "TriangleAdjacency" -> IR.TrianglesAdjacency |
429 | x -> error $ "compFetchPrimitive " ++ ppShow x | 521 | x -> error $ "compFetchPrimitive " ++ ppShow x |
430 | 522 | ||
523 | compValue :: HasCallStack => ExpTV -> IR.Value | ||
431 | compValue x = case x of | 524 | compValue x = case x of |
432 | EFloat a -> IR.VFloat $ realToFrac a | 525 | EFloat a -> IR.VFloat $ realToFrac a |
433 | EInt a -> IR.VInt $ fromIntegral a | 526 | EInt a -> IR.VInt $ fromIntegral a |
434 | A2 "V2" (EFloat a) (EFloat b) -> IR.VV2F $ IR.V2 (realToFrac a) (realToFrac b) | 527 | A2 "V2" (EFloat a) (EFloat b) -> IR.VV2F $ IR.V2 (realToFrac a) (realToFrac b) |
435 | A3 "V3" (EFloat a) (EFloat b) (EFloat c) -> IR.VV3F $ IR.V3 (realToFrac a) (realToFrac b) (realToFrac c) | 528 | A3 "V3" (EFloat a) (EFloat b) (EFloat c) -> IR.VV3F $ IR.V3 (realToFrac a) (realToFrac b) (realToFrac c) |
436 | A4 "V4" (EFloat a) (EFloat b) (EFloat c) (EFloat d) -> IR.VV4F $ IR.V4 (realToFrac a) (realToFrac b) (realToFrac c) (realToFrac d) | 529 | A4 "V4" (EFloat a) (EFloat b) (EFloat c) (EFloat d) -> IR.VV4F $ IR.V4 (realToFrac a) (realToFrac b) (realToFrac c) (realToFrac d) |
530 | A2 "V2" (EInt a) (EInt b) -> IR.VV2I $ fromIntegral <$> IR.V2 a b | ||
531 | A3 "V3" (EInt a) (EInt b) (EInt c) -> IR.VV3I $ fromIntegral <$> IR.V3 a b c | ||
532 | A4 "V4" (EInt a) (EInt b) (EInt c) (EInt d) -> IR.VV4I $ fromIntegral <$> IR.V4 a b c d | ||
437 | A2 "V2" (EBool a) (EBool b) -> IR.VV2B $ IR.V2 a b | 533 | A2 "V2" (EBool a) (EBool b) -> IR.VV2B $ IR.V2 a b |
438 | A3 "V3" (EBool a) (EBool b) (EBool c) -> IR.VV3B $ IR.V3 a b c | 534 | A3 "V3" (EBool a) (EBool b) (EBool c) -> IR.VV3B $ IR.V3 a b c |
439 | A4 "V4" (EBool a) (EBool b) (EBool c) (EBool d) -> IR.VV4B $ IR.V4 a b c d | 535 | A4 "V4" (EBool a) (EBool b) (EBool c) (EBool d) -> IR.VV4B $ IR.V4 a b c d |
@@ -492,6 +588,14 @@ compPV x = case x of | |||
492 | 588 | ||
493 | --------------------------------------------------------------- GLSL generation | 589 | --------------------------------------------------------------- GLSL generation |
494 | 590 | ||
591 | genGLSLs | ||
592 | :: Backend | ||
593 | -> Maybe ExpTV | ||
594 | -> ExpTV | ||
595 | -> (Maybe ExpTV, ExpTV) | ||
596 | -> (Maybe ExpTV, ExpTV) | ||
597 | -> Maybe ExpTV | ||
598 | -> ([[Char]], Uniforms, Doc, Doc) | ||
495 | genGLSLs backend | 599 | genGLSLs backend |
496 | rp -- program point size | 600 | rp -- program point size |
497 | (ETuple ints) -- interpolations | 601 | (ETuple ints) -- interpolations |
diff --git a/testdata/Builtins.out b/testdata/Builtins.out index 654876f7..13c62398 100644 --- a/testdata/Builtins.out +++ b/testdata/Builtins.out | |||
@@ -1291,6 +1291,8 @@ PrjImageColor | |||
1291 | 1291 | ||
1292 | data Output :: Type where | 1292 | data Output :: Type where |
1293 | ScreenOut :: forall (a :: _) (b :: _) . FrameBuffer a b -> Output | 1293 | ScreenOut :: forall (a :: _) (b :: _) . FrameBuffer a b -> Output |
1294 | TextureOut | ||
1295 | :: forall (c :: _) (d :: _) . Vec (fromInt 2) Int -> FrameBuffer c d -> Output | ||
1294 | 1296 | ||
1295 | renderFrame = _lhs renderFrame (_rhs ScreenOut) | 1297 | renderFrame = _lhs renderFrame (_rhs ScreenOut) |
1296 | 1298 | ||
@@ -1658,7 +1660,8 @@ accumulationContext = _lhs accumulationContext \(a :: _) -> _rhs a | |||
1658 | 'Maybe = <<type constructor with 0 indices; constructors: Nothing, Just>> | 1660 | 'Maybe = <<type constructor with 0 indices; constructors: Nothing, Just>> |
1659 | 1661 | ||
1660 | 'Output :: Type | 1662 | 'Output :: Type |
1661 | 'Output = <<type constructor with 0 indices; constructors: ScreenOut>> | 1663 | 'Output |
1664 | = <<type constructor with 0 indices; constructors: ScreenOut, TextureOut>> | ||
1662 | 1665 | ||
1663 | 'PointSize :: Type -> Type | 1666 | 'PointSize :: Type -> Type |
1664 | 'PointSize | 1667 | 'PointSize |
@@ -2489,6 +2492,10 @@ Texture2D = <<1st constructor of 'Texture>> | |||
2489 | Texture2DSlot :: String -> Texture | 2492 | Texture2DSlot :: String -> Texture |
2490 | Texture2DSlot = <<0th constructor of 'Texture>> | 2493 | Texture2DSlot = <<0th constructor of 'Texture>> |
2491 | 2494 | ||
2495 | TextureOut | ||
2496 | :: forall (a :: Nat) (b :: [ImageKind]) . Vec 2 Int -> FrameBuffer a b -> Output | ||
2497 | TextureOut = <<1st constructor of 'Output>> | ||
2498 | |||
2492 | Triangle :: PrimitiveType | 2499 | Triangle :: PrimitiveType |
2493 | Triangle = <<0th constructor of 'PrimitiveType>> | 2500 | Triangle = <<0th constructor of 'PrimitiveType>> |
2494 | 2501 | ||
@@ -2726,8 +2733,10 @@ case'Output | |||
2726 | :: forall (a :: Output -> Type) | 2733 | :: forall (a :: Output -> Type) |
2727 | -> (forall (b :: Nat) (c :: [ImageKind]) | 2734 | -> (forall (b :: Nat) (c :: [ImageKind]) |
2728 | . forall (d :: FrameBuffer b c) -> a ('ScreenOut b c d)) | 2735 | . forall (d :: FrameBuffer b c) -> a ('ScreenOut b c d)) |
2729 | -> forall (e :: Output) -> a e | 2736 | -> (forall (e :: Nat) (f :: [ImageKind]) |
2730 | case'Output = \a b c -> <<case function of a type with 0 parameters>> | 2737 | . forall (g :: Vec 2 Int) (h :: FrameBuffer e f) -> a ('TextureOut e f g h)) |
2738 | -> forall (i :: Output) -> a i | ||
2739 | case'Output = \a b c d -> <<case function of a type with 0 parameters>> | ||
2731 | 2740 | ||
2732 | case'PointSize | 2741 | case'PointSize |
2733 | :: forall a | 2742 | :: forall a |
@@ -8584,8 +8593,8 @@ zero | |||
8584 | Type | 8593 | Type |
8585 | 540:6-540:12 | 8594 | 540:6-540:12 |
8586 | Type | Type | Type | Type | 8595 | Type | Type | Type | Type |
8587 | 540:6-541:12 | 8596 | 540:6-542:13 |
8588 | Type | 8597 | Type | Type |
8589 | 541:3-541:12 | 8598 | 541:3-541:12 |
8590 | forall (a :: Nat) (b :: [ImageKind]) | 8599 | forall (a :: Nat) (b :: [ImageKind]) |
8591 | . FrameBuffer a b -> Output | Output | Type | Type | Type | Type | 8600 | . FrameBuffer a b -> Output | Output | Type | Type | Type | Type |
@@ -8603,120 +8612,150 @@ zero | |||
8603 | _b | 8612 | _b |
8604 | 541:45-541:51 | 8613 | 541:45-541:51 |
8605 | Type | Type | 8614 | Type | Type |
8606 | 543:1-543:12 | 8615 | 542:3-542:13 |
8616 | forall (a :: Nat) (b :: [ImageKind]) | ||
8617 | . Vec 2 Int | ||
8618 | -> FrameBuffer a b -> Output | Output | Type | Type | Type | Type | Type | ||
8619 | 542:26-542:29 | ||
8620 | Nat -> Type -> Type | ||
8621 | 542:26-542:31 | ||
8622 | Type -> Type | ||
8623 | 542:26-542:35 | ||
8624 | Type | ||
8625 | 542:26-542:64 | ||
8626 | Type | Type | ||
8627 | 542:30-542:31 | ||
8628 | _b | ||
8629 | 542:32-542:35 | ||
8630 | Type | ||
8631 | 542:39-542:50 | ||
8632 | Nat -> [ImageKind] -> Type | ||
8633 | 542:39-542:52 | ||
8634 | [ImageKind] -> Type | ||
8635 | 542:39-542:54 | ||
8636 | Type | ||
8637 | 542:39-542:64 | ||
8638 | Type | ||
8639 | 542:51-542:52 | ||
8640 | _e | ||
8641 | 542:53-542:54 | ||
8642 | _c | ||
8643 | 542:58-542:64 | ||
8644 | Type | Type | ||
8645 | 544:1-544:12 | ||
8607 | forall (a :: Nat) (b :: [ImageKind]) . FrameBuffer a b -> Output | 8646 | forall (a :: Nat) (b :: [ImageKind]) . FrameBuffer a b -> Output |
8608 | 543:15-543:24 | 8647 | 544:15-544:24 |
8609 | forall (a :: Nat) (b :: [ImageKind]) . FrameBuffer a b -> Output | 8648 | forall (a :: Nat) (b :: [ImageKind]) . FrameBuffer a b -> Output |
8610 | 549:6-549:13 | 8649 | 550:6-550:13 |
8611 | Type | Type | Type | Type | 8650 | Type | Type | Type | Type |
8612 | 549:6-553:12 | 8651 | 550:6-554:12 |
8613 | Type | Type | 8652 | Type | Type |
8614 | 550:3-550:16 | 8653 | 551:3-551:16 |
8615 | String -> Texture | Texture | Type | Type | 8654 | String -> Texture | Texture | Type | Type |
8616 | 550:20-550:26 | 8655 | 551:20-551:26 |
8617 | Type | 8656 | Type |
8618 | 551:20-551:27 | 8657 | 552:20-552:27 |
8619 | Type | Type | 8658 | Type | Type |
8620 | 553:3-553:12 | 8659 | 554:3-554:12 |
8621 | Vec 2 Int | 8660 | Vec 2 Int |
8622 | -> Image 1 ('Color (Vec 4 Float)) -> Texture | Texture | Type | Type | Type | 8661 | -> Image 1 ('Color (Vec 4 Float)) -> Texture | Texture | Type | Type | Type |
8623 | 553:20-553:23 | 8662 | 554:20-554:23 |
8624 | Nat -> Type -> Type | 8663 | Nat -> Type -> Type |
8625 | 553:20-553:25 | 8664 | 554:20-554:25 |
8626 | Type -> Type | 8665 | Type -> Type |
8627 | 553:20-553:29 | 8666 | 554:20-554:29 |
8628 | Type | 8667 | Type |
8629 | 553:24-553:25 | 8668 | 554:24-554:25 |
8630 | _b | 8669 | _b |
8631 | 553:26-553:29 | 8670 | 554:26-554:29 |
8632 | Type | 8671 | Type |
8633 | 554:20-554:25 | 8672 | 555:20-555:25 |
8634 | Nat -> ImageKind -> Type | 8673 | Nat -> ImageKind -> Type |
8635 | 554:20-554:27 | 8674 | 555:20-555:27 |
8636 | ImageKind -> Type | 8675 | ImageKind -> Type |
8637 | 554:20-554:49 | 8676 | 555:20-555:49 |
8638 | Type | 8677 | Type |
8639 | 554:20-555:27 | 8678 | 555:20-556:27 |
8640 | Type | 8679 | Type |
8641 | 554:26-554:27 | 8680 | 555:26-555:27 |
8642 | _b | 8681 | _b |
8643 | 554:29-554:34 | 8682 | 555:29-555:34 |
8644 | Type -> ImageKind | 8683 | Type -> ImageKind |
8645 | 554:29-554:48 | 8684 | 555:29-555:48 |
8646 | ImageKind | 8685 | ImageKind |
8647 | 554:36-554:39 | 8686 | 555:36-555:39 |
8648 | Nat -> Type -> Type | 8687 | Nat -> Type -> Type |
8649 | 554:36-554:41 | 8688 | 555:36-555:41 |
8650 | Type -> Type | 8689 | Type -> Type |
8651 | 554:36-554:47 | 8690 | 555:36-555:47 |
8652 | Type | 8691 | Type |
8653 | 554:40-554:41 | 8692 | 555:40-555:41 |
8654 | _b | 8693 | _b |
8655 | 554:42-554:47 | 8694 | 555:42-555:47 |
8656 | Type | 8695 | Type |
8657 | 555:20-555:27 | 8696 | 556:20-556:27 |
8658 | Type | Type | 8697 | Type | Type |
8659 | 557:6-557:12 | 8698 | 558:6-558:12 |
8660 | Type | Type | Type | Type | Type | Type | 8699 | Type | Type | Type | Type | Type | Type |
8661 | 557:6-559:17 | 8700 | 558:6-560:17 |
8662 | Type | Type | 8701 | Type | Type |
8663 | 558:5-558:16 | 8702 | 559:5-559:16 |
8664 | Filter | 8703 | Filter |
8665 | 559:5-559:17 | 8704 | 560:5-560:17 |
8666 | Filter | 8705 | Filter |
8667 | 561:6-561:14 | 8706 | 562:6-562:14 |
8668 | Type | Type | Type | Type | Type | Type | Type | 8707 | Type | Type | Type | Type | Type | Type | Type |
8669 | 561:6-564:16 | 8708 | 562:6-565:16 |
8670 | Type | Type | Type | 8709 | Type | Type | Type |
8671 | 562:5-562:11 | 8710 | 563:5-563:11 |
8672 | EdgeMode | 8711 | EdgeMode |
8673 | 563:5-563:19 | 8712 | 564:5-564:19 |
8674 | EdgeMode | 8713 | EdgeMode |
8675 | 564:5-564:16 | 8714 | 565:5-565:16 |
8676 | EdgeMode | 8715 | EdgeMode |
8677 | 566:6-566:13 | 8716 | 567:6-567:13 |
8678 | Type | Type | Type | Type | Type | Type | 8717 | Type | Type | Type | Type | Type | Type |
8679 | 566:6-566:23 | 8718 | 567:6-567:23 |
8680 | Type | 8719 | Type |
8681 | 566:6-566:47 | 8720 | 567:6-567:47 |
8682 | Type | Type | 8721 | Type | Type |
8683 | 566:16-566:23 | 8722 | 567:16-567:23 |
8684 | Filter -> EdgeMode -> Texture -> Sampler | Sampler | Type | Type | Type | Type | 8723 | Filter -> EdgeMode -> Texture -> Sampler | Sampler | Type | Type | Type | Type |
8685 | 566:24-566:30 | 8724 | 567:24-567:30 |
8686 | Type | 8725 | Type |
8687 | 566:31-566:39 | 8726 | 567:31-567:39 |
8688 | Type | 8727 | Type |
8689 | 566:40-566:47 | 8728 | 567:40-567:47 |
8690 | Type | 8729 | Type |
8691 | 569:1-569:10 | 8730 | 570:1-570:10 |
8692 | Sampler -> Vec 2 Float -> Vec 4 Float | 8731 | Sampler -> Vec 2 Float -> Vec 4 Float |
8693 | 569:14-569:21 | 8732 | 570:14-570:21 |
8694 | Type | 8733 | Type |
8695 | 569:25-569:28 | 8734 | 570:25-570:28 |
8696 | Nat -> Type -> Type | 8735 | Nat -> Type -> Type |
8697 | 569:25-569:30 | 8736 | 570:25-570:30 |
8698 | Type -> Type | 8737 | Type -> Type |
8699 | 569:25-569:36 | 8738 | 570:25-570:36 |
8700 | Type | 8739 | Type |
8701 | 569:25-569:51 | 8740 | 570:25-570:51 |
8702 | Type | 8741 | Type |
8703 | 569:29-569:30 | 8742 | 570:29-570:30 |
8704 | _b | 8743 | _b |
8705 | 569:31-569:36 | 8744 | 570:31-570:36 |
8706 | Type | 8745 | Type |
8707 | 569:40-569:43 | 8746 | 570:40-570:43 |
8708 | Nat -> Type -> Type | 8747 | Nat -> Type -> Type |
8709 | 569:40-569:45 | 8748 | 570:40-570:45 |
8710 | Type -> Type | 8749 | Type -> Type |
8711 | 569:40-569:51 | 8750 | 570:40-570:51 |
8712 | Type | Type | 8751 | Type | Type |
8713 | 569:44-569:45 | 8752 | 570:44-570:45 |
8714 | _b | 8753 | _b |
8715 | 569:46-569:51 | 8754 | 570:46-570:51 |
8716 | Type | 8755 | Type |
8717 | 573:1-573:20 | 8756 | 574:1-574:20 |
8718 | forall a . a -> a | 8757 | forall a . a -> a |
8719 | 573:25-573:26 | 8758 | 574:25-574:26 |
8720 | _b | 8759 | _b |
8721 | ------------ warnings | 8760 | ------------ warnings |
8722 | Uncovered pattern(s) at testdata/Builtins.lc:201:1: | 8761 | Uncovered pattern(s) at testdata/Builtins.lc:201:1: |
diff --git a/testdata/graphics-features/pickInt.lc b/testdata/graphics-features/pickInt.lc new file mode 100644 index 00000000..3c2dba84 --- /dev/null +++ b/testdata/graphics-features/pickInt.lc | |||
@@ -0,0 +1,25 @@ | |||
1 | -- Tests: | ||
2 | -- 1. Pipeline targeting a render texture (TextureOut), instead of a Screenout. | ||
3 | -- 2. Integer color components for the output | ||
4 | |||
5 | type FB = FrameBuffer 1 '[ 'Color (Vec 4 Int)] | ||
6 | |||
7 | scene :: String -> FB -> FB | ||
8 | scene name prevFB = | ||
9 | Accumulate ((ColorOp NoBlending (one :: Vec 4 Bool))) | ||
10 | (mapFragments (\(uv, rgba) -> ((rgba))) | ||
11 | $ rasterizePrimitives (TriangleCtx CullFront PolygonFill NoOffset LastVertex) (Flat, Flat) | ||
12 | $ mapPrimitives | ||
13 | (\(pos, color, id)-> | ||
14 | ( (Uniform "viewProj" :: Mat 4 4 Float) *. (V4 pos%x pos%y 0 1) | ||
15 | , V2 0.0 0.0 | ||
16 | , V4 0 0 0 id)) | ||
17 | $ fetch name ( Attribute "position" :: Vec 3 Float | ||
18 | , Attribute "color" :: Vec 4 Float | ||
19 | , Attribute "id" :: Int)) | ||
20 | prevFB | ||
21 | |||
22 | main :: Output | ||
23 | main = TextureOut (V2 800 600) $ | ||
24 | scene "objects" $ | ||
25 | FrameBuffer ((colorImage1 (V4 0 0 0 0))) | ||
diff --git a/testdata/graphics-features/pickInt.out b/testdata/graphics-features/pickInt.out new file mode 100644 index 00000000..8812744e --- /dev/null +++ b/testdata/graphics-features/pickInt.out | |||
@@ -0,0 +1,111 @@ | |||
1 | Pipeline | ||
2 | { info = "" | ||
3 | , backend = OpenGL33 | ||
4 | , textures = | ||
5 | [ TextureDescriptor | ||
6 | { textureType = Texture2D (IntT RGBA) 1 | ||
7 | , textureSize = VV2U (V2 800 600) | ||
8 | , textureSemantic = Color | ||
9 | , textureSampler = | ||
10 | SamplerDescriptor | ||
11 | { samplerWrapS = Repeat | ||
12 | , samplerWrapT = Just Repeat | ||
13 | , samplerWrapR = Nothing | ||
14 | , samplerMinFilter = Nearest | ||
15 | , samplerMagFilter = Nearest | ||
16 | , samplerBorderColor = VV4F (V4 0.0 0.0 0.0 1.0) | ||
17 | , samplerMinLod = Nothing | ||
18 | , samplerMaxLod = Nothing | ||
19 | , samplerLodBias = 0.0 | ||
20 | , samplerCompareFunc = Nothing | ||
21 | } | ||
22 | , textureBaseLevel = 0 | ||
23 | , textureMaxLevel = 0 | ||
24 | } | ||
25 | ] | ||
26 | , samplers = [] | ||
27 | , targets = | ||
28 | [ RenderTarget | ||
29 | { renderTargets = | ||
30 | [ TargetItem | ||
31 | { targetSemantic = Color | ||
32 | , targetRef = Just (TextureImage 0 0 Nothing) | ||
33 | } | ||
34 | ] | ||
35 | } | ||
36 | ] | ||
37 | , programs = | ||
38 | [ Program | ||
39 | { programUniforms = fromList [ ( "viewProj" , M44F ) ] | ||
40 | , programStreams = | ||
41 | fromList | ||
42 | [ ( "vi1" , Parameter { name = "position" , ty = V3F } ) | ||
43 | , ( "vi2" , Parameter { name = "color" , ty = V4F } ) | ||
44 | , ( "vi3" , Parameter { name = "id" , ty = Int } ) | ||
45 | ] | ||
46 | , programInTextures = fromList [] | ||
47 | , programOutput = [ Parameter { name = "f0" , ty = V4I } ] | ||
48 | , vertexShader = | ||
49 | """ | ||
50 | #version 330 core | ||
51 | vec4 texture2D(sampler2D s,vec2 uv) { | ||
52 | return texture(s,uv); | ||
53 | } | ||
54 | uniform mat4 viewProj; | ||
55 | in vec3 vi1; | ||
56 | in vec4 vi2; | ||
57 | in int vi3; | ||
58 | flat out vec2 vo1; | ||
59 | flat out ivec4 vo2; | ||
60 | void main() { | ||
61 | gl_Position = (viewProj) * (vec4 ((vi1).x,(vi1).y,0.0,1.0)); | ||
62 | vo1 = vec2 (0.0,0.0); | ||
63 | vo2 = ivec4 (0,0,0,vi3); | ||
64 | } | ||
65 | """ | ||
66 | , geometryShader = Nothing | ||
67 | , fragmentShader = | ||
68 | """ | ||
69 | #version 330 core | ||
70 | vec4 texture2D(sampler2D s,vec2 uv) { | ||
71 | return texture(s,uv); | ||
72 | } | ||
73 | flat in vec2 vo1; | ||
74 | flat in ivec4 vo2; | ||
75 | out ivec4 f0; | ||
76 | void main() { | ||
77 | f0 = vo2; | ||
78 | } | ||
79 | """ | ||
80 | } | ||
81 | ] | ||
82 | , slots = | ||
83 | [ Slot | ||
84 | { slotName = "objects" | ||
85 | , slotStreams = | ||
86 | fromList | ||
87 | [ ( "color" , V4F ) , ( "id" , Int ) , ( "position" , V3F ) ] | ||
88 | , slotUniforms = fromList [ ( "viewProj" , M44F ) ] | ||
89 | , slotPrimitive = Triangles | ||
90 | , slotPrograms = [ 0 ] | ||
91 | } | ||
92 | ] | ||
93 | , streams = [] | ||
94 | , commands = | ||
95 | [ SetRenderTarget 0 | ||
96 | , ClearRenderTarget | ||
97 | [ ClearImage | ||
98 | { imageSemantic = Color , clearValue = VV4I (V4 0 0 0 0) } | ||
99 | ] | ||
100 | , SetProgram 0 | ||
101 | , SetRasterContext | ||
102 | (TriangleCtx (CullFront CCW) PolygonFill NoOffset LastVertex) | ||
103 | , SetAccumulationContext | ||
104 | AccumulationContext | ||
105 | { accViewportName = Nothing | ||
106 | , accOperations = | ||
107 | [ ColorOp NoBlending (VV4B (V4 True True True True)) ] | ||
108 | } | ||
109 | , RenderSlot 0 | ||
110 | ] | ||
111 | } \ No newline at end of file | ||
diff --git a/testdata/graphics-features/pickInt.ppl b/testdata/graphics-features/pickInt.ppl new file mode 100644 index 00000000..742549a3 --- /dev/null +++ b/testdata/graphics-features/pickInt.ppl | |||
@@ -0,0 +1,110 @@ | |||
1 | Pipeline | ||
2 | { info = "generated by lambdacube-compiler 0.6.1.0" | ||
3 | , backend = OpenGL33 | ||
4 | , textures = | ||
5 | [ TextureDescriptor | ||
6 | { textureType = Texture2D (IntT RGBA) 1 | ||
7 | , textureSize = VV2U (V2 800 600) | ||
8 | , textureSemantic = Color | ||
9 | , textureSampler = | ||
10 | SamplerDescriptor | ||
11 | { samplerWrapS = Repeat | ||
12 | , samplerWrapT = Just Repeat | ||
13 | , samplerWrapR = Nothing | ||
14 | , samplerMinFilter = Nearest | ||
15 | , samplerMagFilter = Nearest | ||
16 | , samplerBorderColor = VV4F (V4 0.0 0.0 0.0 1.0) | ||
17 | , samplerMinLod = Nothing | ||
18 | , samplerMaxLod = Nothing | ||
19 | , samplerLodBias = 0.0 | ||
20 | , samplerCompareFunc = Nothing | ||
21 | } | ||
22 | , textureBaseLevel = 0 | ||
23 | , textureMaxLevel = 0 | ||
24 | } | ||
25 | ] | ||
26 | , samplers = [] | ||
27 | , targets = | ||
28 | [ RenderTarget | ||
29 | { renderTargets = | ||
30 | [ TargetItem | ||
31 | { targetSemantic = Color | ||
32 | , targetRef = Just (TextureImage 0 0 Nothing) | ||
33 | } | ||
34 | ] | ||
35 | } | ||
36 | ] | ||
37 | , programs = | ||
38 | [ Program | ||
39 | { programUniforms = fromList [ ( "viewProj" , M44F ) ] | ||
40 | , programStreams = | ||
41 | fromList | ||
42 | [ ( "vi1" , Parameter { name = "position" , ty = V3F } ) | ||
43 | , ( "vi2" , Parameter { name = "uv" , ty = V2F } ) | ||
44 | , ( "vi3" , Parameter { name = "id" , ty = Int } ) | ||
45 | ] | ||
46 | , programInTextures = fromList [] | ||
47 | , programOutput = [ Parameter { name = "f0" , ty = V4I } ] | ||
48 | , vertexShader = | ||
49 | """ | ||
50 | #version 330 core | ||
51 | vec4 texture2D(sampler2D s,vec2 uv) { | ||
52 | return texture(s,uv); | ||
53 | } | ||
54 | uniform mat4 viewProj; | ||
55 | in vec3 vi1; | ||
56 | in vec2 vi2; | ||
57 | in int vi3; | ||
58 | flat out vec2 vo1; | ||
59 | flat out ivec4 vo2; | ||
60 | void main() { | ||
61 | gl_Position = (viewProj) * (vec4 ((vi1).x,(vi1).y,0.0,1.0)); | ||
62 | vo1 = vi2; | ||
63 | vo2 = ivec4 (0,0,0,vi3); | ||
64 | } | ||
65 | """ | ||
66 | , geometryShader = Nothing | ||
67 | , fragmentShader = | ||
68 | """ | ||
69 | #version 330 core | ||
70 | vec4 texture2D(sampler2D s,vec2 uv) { | ||
71 | return texture(s,uv); | ||
72 | } | ||
73 | flat in vec2 vo1; | ||
74 | flat in ivec4 vo2; | ||
75 | out ivec4 f0; | ||
76 | void main() { | ||
77 | f0 = vo2; | ||
78 | } | ||
79 | """ | ||
80 | } | ||
81 | ] | ||
82 | , slots = | ||
83 | [ Slot | ||
84 | { slotName = "stream" | ||
85 | , slotStreams = | ||
86 | fromList [ ( "id" , Int ) , ( "position" , V3F ) , ( "uv" , V2F ) ] | ||
87 | , slotUniforms = fromList [ ( "viewProj" , M44F ) ] | ||
88 | , slotPrimitive = Triangles | ||
89 | , slotPrograms = [ 0 ] | ||
90 | } | ||
91 | ] | ||
92 | , streams = [] | ||
93 | , commands = | ||
94 | [ SetRenderTarget 0 | ||
95 | , ClearRenderTarget | ||
96 | [ ClearImage | ||
97 | { imageSemantic = Color , clearValue = VV4I (V4 0 0 0 0) } | ||
98 | ] | ||
99 | , SetProgram 0 | ||
100 | , SetRasterContext | ||
101 | (TriangleCtx (CullFront CCW) PolygonFill NoOffset LastVertex) | ||
102 | , SetAccumulationContext | ||
103 | AccumulationContext | ||
104 | { accViewportName = Nothing | ||
105 | , accOperations = | ||
106 | [ ColorOp NoBlending (VV4B (V4 True True True True)) ] | ||
107 | } | ||
108 | , RenderSlot 0 | ||
109 | ] | ||
110 | } \ No newline at end of file | ||