From dc78561c209a1e7361d760dcf3e206633de7769a Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 25 Jun 2022 14:18:53 +0100 Subject: [PATCH] Parallelize poking --- src/Geometry/Zone.hs | 1 + src/Shader/Poke.hs | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Geometry/Zone.hs b/src/Geometry/Zone.hs index 5bf076c6c..523875189 100644 --- a/src/Geometry/Zone.hs +++ b/src/Geometry/Zone.hs @@ -157,6 +157,7 @@ ddaStreamY :: Float -> Point2 -> Point2 -> Stream (Of (V2 Int)) Identity () ddaStreamY s sp ep = S.map (sizeZoneOfPoint' s) $ yIntercepts s sp ep xIntercepts :: Float -> Point2 -> Point2 -> Stream (Of Point2) Identity () +{-# INLINE xIntercepts #-} xIntercepts s (V2 sx sy) (V2 ex ey) | xdx == 0 = mempty | xdx > 0 = S.each $ zipWith V2 [sx',sx'+xdx*50..ex] [sy',sy'+ydx*50..ey] diff --git a/src/Shader/Poke.hs b/src/Shader/Poke.hs index 065ce40f7..ae3341c05 100644 --- a/src/Shader/Poke.hs +++ b/src/Shader/Poke.hs @@ -20,6 +20,7 @@ import qualified Data.Vector.Unboxed.Mutable as UMV import qualified Data.Vector.Mutable as MV import qualified Data.Vector.Fusion.Stream.Monadic as VS import Control.Monad.Primitive +import qualified Control.Monad.Parallel as MP pokeVerxs :: MV.MVector (PrimState IO) FullShader @@ -105,10 +106,10 @@ pokeTopPrism :: Int -> Ptr Float -> Ptr GLushort -> IO () pokeTopPrism size ptr iptr ieptr counts svs = do nv <- UMV.unsafeRead counts 0 --- MP.bindM3 (\_ _ _ -> return ()) - UV.mapM_ (pokeTopPrismIndex nv iptr counts) (memoTopPrismIndices V.! size) - UV.mapM_ (pokeTopPrismEdgeIndex nv ieptr counts) (memoTopPrismEdgeIndices V.! size) - VS.mapM_ (pokeJustV ptr counts) (VS.fromList svs) + MP.bindM3 (\_ _ _ -> return ()) + (UV.mapM_ (pokeTopPrismIndex nv iptr counts) (memoTopPrismIndices V.! size)) + (UV.mapM_ (pokeTopPrismEdgeIndex nv ieptr counts) (memoTopPrismEdgeIndices V.! size)) + (VS.mapM_ (pokeJustV ptr counts) (VS.fromList svs) ) pokeTopPrismEdgeIndex :: Int -> Ptr GLushort -> UMV.MVector (PrimState IO) Int