Inline fold sub-functions for speed
This commit is contained in:
@@ -142,7 +142,6 @@ drawTextureOnFramebuffer fs fbo to = do
|
|||||||
drawShader fs 4
|
drawShader fs 4
|
||||||
|
|
||||||
pokeBindFoldable
|
pokeBindFoldable
|
||||||
-- :: Foldable f
|
|
||||||
:: RenderData
|
:: RenderData
|
||||||
-> [Verx]
|
-> [Verx]
|
||||||
-> IO (PicShads Int)
|
-> IO (PicShads Int)
|
||||||
|
|||||||
+107
-36
@@ -6,11 +6,7 @@ module Shader.Poke
|
|||||||
, pokePoint3s
|
, pokePoint3s
|
||||||
, pokePoint33s
|
, pokePoint33s
|
||||||
, pokeVerxs
|
, pokeVerxs
|
||||||
, pokeLayVerxs
|
|
||||||
, pokeLayVerxsFold
|
, pokeLayVerxsFold
|
||||||
, pokeLayVerxsPart
|
|
||||||
, pokeLayVerxsPartM
|
|
||||||
, pokeLayVerxsM
|
|
||||||
, poke224s
|
, poke224s
|
||||||
) where
|
) where
|
||||||
import Shader.Data
|
import Shader.Data
|
||||||
@@ -23,7 +19,7 @@ import Layers
|
|||||||
--import Data.Maybe
|
--import Data.Maybe
|
||||||
--import Data.List
|
--import Data.List
|
||||||
import Foreign
|
import Foreign
|
||||||
import Control.Monad
|
--import Control.Monad
|
||||||
import qualified Control.Foldl as F
|
import qualified Control.Foldl as F
|
||||||
--import qualified Data.IntMap.Strict as IM
|
--import qualified Data.IntMap.Strict as IM
|
||||||
--import Control.Lens
|
--import Control.Lens
|
||||||
@@ -40,7 +36,7 @@ pokeVerxs vbos = F.foldM $ F.FoldM
|
|||||||
|
|
||||||
-- this is very brittle, but want to optimise speed if possible here
|
-- this is very brittle, but want to optimise speed if possible here
|
||||||
pokeVerx :: PicShads VBO -> PicShads Int -> Verx -> IO ()
|
pokeVerx :: PicShads VBO -> PicShads Int -> Verx -> IO ()
|
||||||
{-# INLINE pokeVerx #-}
|
--{-# INLINE pokeVerx #-}
|
||||||
pokeVerx vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxType=theType} = case theType of
|
pokeVerx vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxType=theType} = case theType of
|
||||||
PolyV -> poke34 (plusPtr (_vboPtr $ _psPoly vbos) (_psPoly offsets * 7 * floatSize)) thePos theCol
|
PolyV -> poke34 (plusPtr (_vboPtr $ _psPoly vbos) (_psPoly offsets * 7 * floatSize)) thePos theCol
|
||||||
PolyzV x -> poke34 thePtr thePos theCol
|
PolyzV x -> poke34 thePtr thePos theCol
|
||||||
@@ -67,8 +63,10 @@ pokeVerx vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxType=theType} = case t
|
|||||||
thePtr = plusPtr (_vboPtr $ _psArc vbos) (_psArc offsets * 10 * floatSize)
|
thePtr = plusPtr (_vboPtr $ _psArc vbos) (_psArc offsets * 10 * floatSize)
|
||||||
EllV -> poke34 (plusPtr (_vboPtr $ _psEll vbos) (_psEll offsets * 7 * floatSize)) thePos theCol
|
EllV -> poke34 (plusPtr (_vboPtr $ _psEll vbos) (_psEll offsets * 7 * floatSize)) thePos theCol
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
poke34 :: Ptr Float -> Point3 -> Point4 -> IO ()
|
poke34 :: Ptr Float -> Point3 -> Point4 -> IO ()
|
||||||
--{-# INLINE poke34 #-}
|
{-# INLINE poke34 #-}
|
||||||
poke34 ptr (V3 a b c) (V4 d e f g) = do
|
poke34 ptr (V3 a b c) (V4 d e f g) = do
|
||||||
pokeElemOff ptr 0 a
|
pokeElemOff ptr 0 a
|
||||||
pokeElemOff ptr 1 b
|
pokeElemOff ptr 1 b
|
||||||
@@ -78,8 +76,25 @@ poke34 ptr (V3 a b c) (V4 d e f g) = do
|
|||||||
pokeElemOff ptr 5 f
|
pokeElemOff ptr 5 f
|
||||||
pokeElemOff ptr 6 g
|
pokeElemOff ptr 6 g
|
||||||
|
|
||||||
|
addCountVerx' :: VertexType -> PicShads Int -> PicShads Int
|
||||||
|
{-# INLINE addCountVerx' #-}
|
||||||
|
addCountVerx' theType !ps@PicShads
|
||||||
|
{ _psPoly = sPoly
|
||||||
|
, _psPolyz = sPolyz
|
||||||
|
, _psBez = sBez
|
||||||
|
, _psText = sText
|
||||||
|
, _psArc = sArc
|
||||||
|
, _psEll = sEll
|
||||||
|
} = case theType of
|
||||||
|
PolyV -> ps {_psPoly = sPoly + 1}
|
||||||
|
PolyzV _ -> ps {_psPolyz = sPolyz + 1}
|
||||||
|
BezV _ -> ps {_psBez = sBez + 1}
|
||||||
|
TextV _ -> ps {_psText = sText + 1}
|
||||||
|
ArcV _ -> ps {_psArc = sArc + 1}
|
||||||
|
EllV -> ps {_psEll = sEll + 1}
|
||||||
|
|
||||||
addCountVerx :: PicShads Int -> Verx -> PicShads Int
|
addCountVerx :: PicShads Int -> Verx -> PicShads Int
|
||||||
--{-# INLINE addCountVerx #-}
|
{-# INLINE addCountVerx #-}
|
||||||
addCountVerx !ps@PicShads
|
addCountVerx !ps@PicShads
|
||||||
{ _psPoly = sPoly
|
{ _psPoly = sPoly
|
||||||
, _psPolyz = sPolyz
|
, _psPolyz = sPolyz
|
||||||
@@ -127,37 +142,70 @@ pokePoint3s ptr vals0 = go vals0 0
|
|||||||
where
|
where
|
||||||
off i = n*3 + i
|
off i = n*3 + i
|
||||||
|
|
||||||
|
comLayVerx :: PicShads VBO -> Layers (PicShads Int) -> Verx -> IO (Layers (PicShads Int))
|
||||||
|
{-# INLINE comLayVerx #-}
|
||||||
|
comLayVerx vbos counts vx = do
|
||||||
|
poke34 thePtr thePos theCol
|
||||||
|
pokeVerxType thePtr theType
|
||||||
|
return $ addLayCountVerx' counts theLayer theType
|
||||||
|
where
|
||||||
|
theLayer = _vxLayer vx
|
||||||
|
layCounts = getLay theLayer counts
|
||||||
|
theType = _vxType vx
|
||||||
|
thePos = _vxPos vx
|
||||||
|
theCol = _vxCol vx
|
||||||
|
basePtr = _vboPtr $ vboFromType vbos theType
|
||||||
|
layOff = theLayer * numSubElements
|
||||||
|
thePtr = plusPtr basePtr ((intFromType layCounts theType + layOff) * theStride * floatSize)
|
||||||
|
theStride = pokeStride theType
|
||||||
|
|
||||||
|
pokeVerxType :: Ptr Float -> VertexType -> IO ()
|
||||||
|
pokeVerxType thePtr vt = case vt of
|
||||||
|
PolyzV x -> pokeElemOff thePtr 7 x
|
||||||
|
BezV (V4 x y z w) -> pokeElemOff thePtr 7 x >> pokeElemOff thePtr 8 y
|
||||||
|
>> pokeElemOff thePtr 9 z >> pokeElemOff thePtr 10 w
|
||||||
|
TextV (V2 x y) -> pokeElemOff thePtr 7 x >> pokeElemOff thePtr 8 y
|
||||||
|
ArcV (V3 x y z) -> pokeElemOff thePtr 7 x >> pokeElemOff thePtr 8 y
|
||||||
|
>> pokeElemOff thePtr 9 z
|
||||||
|
_ -> return ()
|
||||||
|
|
||||||
|
|
||||||
|
intFromType :: PicShads Int -> VertexType -> Int
|
||||||
|
intFromType ps vt = case vt of
|
||||||
|
PolyV -> _psPoly ps
|
||||||
|
PolyzV{} -> _psPolyz ps
|
||||||
|
BezV{} -> _psBez ps
|
||||||
|
TextV{} -> _psText ps
|
||||||
|
ArcV{} -> _psArc ps
|
||||||
|
EllV -> _psEll ps
|
||||||
|
|
||||||
|
vboFromType :: PicShads VBO -> VertexType -> VBO
|
||||||
|
vboFromType ps vt = case vt of
|
||||||
|
PolyV -> _psPoly ps
|
||||||
|
PolyzV{} -> _psPolyz ps
|
||||||
|
BezV{} -> _psBez ps
|
||||||
|
TextV{} -> _psText ps
|
||||||
|
ArcV{} -> _psArc ps
|
||||||
|
EllV -> _psEll ps
|
||||||
|
|
||||||
pokeLayVerxsFold :: PicShads VBO -> [Verx] -> IO (Layers (PicShads Int))
|
pokeLayVerxsFold :: PicShads VBO -> [Verx] -> IO (Layers (PicShads Int))
|
||||||
pokeLayVerxsFold !vbos = F.foldM $ F.FoldM
|
pokeLayVerxsFold vbos = F.foldM $ F.FoldM
|
||||||
(\counts vx -> pokeLayVerx vbos counts vx >> return (addLayCountVerx counts vx))
|
--(\counts vx -> pokeLayVerx vbos counts vx >> return (addLayCountVerx counts vx))
|
||||||
(pure $ pure $ pure 0)
|
(comLayVerx vbos)
|
||||||
|
(pure . pure $ pure 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
pokeLayVerxsM :: PicShads VBO -> [Verx] -> IO (Layers (PicShads Int))
|
pokeStride :: VertexType -> Int
|
||||||
pokeLayVerxsM !vbos = foldM f (pure $ pure 0)
|
pokeStride PolyV = 7
|
||||||
where
|
pokeStride PolyzV{} = 8
|
||||||
f counts vx = pokeLayVerx vbos counts vx >> return (addLayCountVerx counts vx)
|
pokeStride BezV{} = 11
|
||||||
|
pokeStride TextV{} = 9
|
||||||
pokeLayVerxsPartM :: PicShads VBO -> [Verx] -> Layers (PicShads Int) -> IO (Layers (PicShads Int))
|
pokeStride ArcV{} = 10
|
||||||
pokeLayVerxsPartM !vbos vxs0 count0 = foldM f count0 vxs0
|
pokeStride EllV = 7
|
||||||
where
|
|
||||||
f counts vx = pokeLayVerx vbos counts vx >> return (addLayCountVerx counts vx)
|
|
||||||
|
|
||||||
pokeLayVerxsPart :: PicShads VBO -> [Verx] -> Layers (PicShads Int) -> IO (Layers (PicShads Int))
|
|
||||||
pokeLayVerxsPart !vbos vxs0 count0 = go vxs0 count0
|
|
||||||
where
|
|
||||||
go [] count = return count
|
|
||||||
go (!vx:vxs) !count = pokeLayVerx vbos count vx >> (go vxs $! addLayCountVerx count vx)
|
|
||||||
|
|
||||||
pokeLayVerxs :: PicShads VBO -> [Verx] -> IO (Layers (PicShads Int))
|
|
||||||
pokeLayVerxs !vbos vxs0 = go vxs0 (pure (pure 0))
|
|
||||||
where
|
|
||||||
go [] count = return count
|
|
||||||
go (!vx:vxs) !count = pokeLayVerx vbos count vx >> (go vxs $! addLayCountVerx count vx)
|
|
||||||
|
|
||||||
-- this is very brittle, but want to optimise speed if possible here
|
-- this is very brittle, but want to optimise speed if possible here
|
||||||
pokeLayVerx :: PicShads VBO -> Layers (PicShads Int) -> Verx -> IO ()
|
pokeLayVerx :: PicShads VBO -> Layers (PicShads Int) -> Verx -> IO ()
|
||||||
--{-# INLINE pokeLayVerx #-}
|
{-# INLINE pokeLayVerx #-}
|
||||||
pokeLayVerx vbos imoffsets Verx{_vxPos=thePos,_vxCol=theCol,_vxType=theType, _vxLayer = theLay} = case theType of
|
pokeLayVerx vbos imoffsets Verx{_vxPos=thePos,_vxCol=theCol,_vxType=theType, _vxLayer = theLay} = case theType of
|
||||||
PolyV -> poke34 (plusPtr (_vboPtr $ _psPoly vbos) ((_psPoly offsets + layOff) * 7 * floatSize)) thePos theCol
|
PolyV -> poke34 (plusPtr (_vboPtr $ _psPoly vbos) ((_psPoly offsets + layOff) * 7 * floatSize)) thePos theCol
|
||||||
PolyzV x -> poke34 thePtr thePos theCol
|
PolyzV x -> poke34 thePtr thePos theCol
|
||||||
@@ -188,7 +236,7 @@ pokeLayVerx vbos imoffsets Verx{_vxPos=thePos,_vxCol=theCol,_vxType=theType, _vx
|
|||||||
offsets = getLay theLay imoffsets
|
offsets = getLay theLay imoffsets
|
||||||
|
|
||||||
addLayCountVerx :: Layers (PicShads Int) -> Verx -> Layers (PicShads Int)
|
addLayCountVerx :: Layers (PicShads Int) -> Verx -> Layers (PicShads Int)
|
||||||
--{-# INLINE addLayCountVerx #-}
|
{-# INLINE addLayCountVerx #-}
|
||||||
addLayCountVerx !m@Layers
|
addLayCountVerx !m@Layers
|
||||||
{ _lay0 = a0
|
{ _lay0 = a0
|
||||||
, _lay1 = a1
|
, _lay1 = a1
|
||||||
@@ -197,7 +245,30 @@ addLayCountVerx !m@Layers
|
|||||||
, _lay4 = a4
|
, _lay4 = a4
|
||||||
, _lay5 = a5
|
, _lay5 = a5
|
||||||
}
|
}
|
||||||
!vx = case _vxLayer vx of
|
vx = case _vxLayer vx of
|
||||||
|
0 -> m { _lay0 = f $! a0 }
|
||||||
|
1 -> m { _lay1 = f $! a1 }
|
||||||
|
2 -> m { _lay2 = f $! a2 }
|
||||||
|
3 -> m { _lay3 = f $! a3 }
|
||||||
|
4 -> m { _lay4 = f $! a4 }
|
||||||
|
5 -> m { _lay5 = f $! a5 }
|
||||||
|
_ -> undefined
|
||||||
|
where
|
||||||
|
f = flip addCountVerx vx
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
addLayCountVerx' :: Layers (PicShads Int) -> Int -> VertexType -> Layers (PicShads Int)
|
||||||
|
{-# INLINE addLayCountVerx' #-}
|
||||||
|
addLayCountVerx' m@Layers
|
||||||
|
{ _lay0 = a0
|
||||||
|
, _lay1 = a1
|
||||||
|
, _lay2 = a2
|
||||||
|
, _lay3 = a3
|
||||||
|
, _lay4 = a4
|
||||||
|
, _lay5 = a5
|
||||||
|
}
|
||||||
|
lay vt = case lay of
|
||||||
0 -> m { _lay0 = f a0 }
|
0 -> m { _lay0 = f a0 }
|
||||||
1 -> m { _lay1 = f a1 }
|
1 -> m { _lay1 = f a1 }
|
||||||
2 -> m { _lay2 = f a2 }
|
2 -> m { _lay2 = f a2 }
|
||||||
@@ -206,7 +277,7 @@ addLayCountVerx !m@Layers
|
|||||||
5 -> m { _lay5 = f a5 }
|
5 -> m { _lay5 = f a5 }
|
||||||
_ -> undefined
|
_ -> undefined
|
||||||
where
|
where
|
||||||
f = flip addCountVerx vx
|
f = addCountVerx' vt
|
||||||
|
|
||||||
poke224s :: Ptr Float -> [((Point2,Point2),Point4)] -> IO Int
|
poke224s :: Ptr Float -> [((Point2,Point2),Point4)] -> IO Int
|
||||||
poke224s ptr vals0 = go vals0 0
|
poke224s ptr vals0 = go vals0 0
|
||||||
|
|||||||
Reference in New Issue
Block a user