{-# LINE 1 "src/Gpu/Vulkan/Sample/Middle/Internal.hsc" #-}
{-# LANGUAGE BlockArguments, LambdaCase #-}
{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}

module Gpu.Vulkan.Sample.Middle.Internal where

import Foreign.Ptr
import Foreign.Marshal.Array
import Foreign.Storable.PeekPoke
import Data.Bits
import Data.Word

import Gpu.Vulkan.Sample.Enum



data CountAndMask = CountAndMask CountFlagBits (Maybe Mask) deriving Int -> CountAndMask -> ShowS
[CountAndMask] -> ShowS
CountAndMask -> String
(Int -> CountAndMask -> ShowS)
-> (CountAndMask -> String)
-> ([CountAndMask] -> ShowS)
-> Show CountAndMask
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CountAndMask -> ShowS
showsPrec :: Int -> CountAndMask -> ShowS
$cshow :: CountAndMask -> String
show :: CountAndMask -> String
$cshowList :: [CountAndMask] -> ShowS
showList :: [CountAndMask] -> ShowS
Show

newtype Mask = Mask Integer deriving Int -> Mask -> ShowS
[Mask] -> ShowS
Mask -> String
(Int -> Mask -> ShowS)
-> (Mask -> String) -> ([Mask] -> ShowS) -> Show Mask
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Mask -> ShowS
showsPrec :: Int -> Mask -> ShowS
$cshow :: Mask -> String
show :: Mask -> String
$cshowList :: [Mask] -> ShowS
showList :: [Mask] -> ShowS
Show

countAndMaskToCore ::
	CountAndMask -> ((CountFlagBits, Ptr Word32) -> IO a) -> IO a
{-# LINE 22 "src/Gpu/Vulkan/Sample/Middle/Internal.hsc" #-}
countAndMaskToCore foo f = case foo of
	CountAndMask cfb Nothing -> f (cfb, NullPtr)
	CountAndMask cfb@(CountFlagBits c) (Just (Mask m)) ->
		allocaArray ln \pm ->
		pokeArray pm (integerToWord32s ln m) >>
		f (cfb, pm)
		where ln = fromIntegral $ (c - 1) `div` 32 + 1

integerToWord32s :: Int -> Integer -> [Word32]
integerToWord32s :: Int -> Integer -> [Word32]
integerToWord32s Int
ln Integer
_ | Int
ln Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
1 = []
integerToWord32s Int
ln Integer
n =
	Integer -> Word32
forall a. Num a => Integer -> a
fromInteger (Integer
n Integer -> Integer -> Integer
forall a. Bits a => a -> a -> a
.&. Integer
0xffffffff) Word32 -> [Word32] -> [Word32]
forall a. a -> [a] -> [a]
:
	Int -> Integer -> [Word32]
integerToWord32s (Int
ln Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Integer
n Integer -> Int -> Integer
forall a. Bits a => a -> Int -> a
`shiftR` Int
32)