{-# LINE 1 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# OPTIONS_HADDOCK prune #-}
module Foreign.CUDA.Driver.Texture (
Texture(..), Format(..), AddressMode(..), FilterMode(..), ReadMode(..),
bind, bind2D,
getAddressMode, getFilterMode, getFormat,
setAddressMode, setFilterMode, setFormat, setReadMode,
create, destroy,
peekTex
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
{-# LINE 31 "src/Foreign/CUDA/Driver/Texture.chs" #-}
import Foreign.CUDA.Ptr
import Foreign.CUDA.Driver.Error
import Foreign.CUDA.Driver.Marshal
import Foreign.CUDA.Internal.C2HS
import Foreign
import Foreign.C
import Control.Monad
{-# DEPRECATED create, destroy "as of CUDA version 3.2" #-}
newtype Texture = Texture { useTexture :: ((C2HSImp.Ptr ()))}
deriving (Eq, Show)
instance Storable Texture where
sizeOf _ = sizeOf (undefined :: ((C2HSImp.Ptr ())))
alignment _ = alignment (undefined :: ((C2HSImp.Ptr ())))
peek p = Texture `fmap` peek (castPtr p)
poke p t = poke (castPtr p) (useTexture t)
data AddressMode = Wrap
| Clamp
| Mirror
| Border
deriving (Eq,Show)
instance Enum AddressMode where
succ Wrap = Clamp
succ Clamp = Mirror
succ Mirror = Border
succ Border = error "AddressMode.succ: Border has no successor"
pred Clamp = Wrap
pred Mirror = Clamp
pred Border = Mirror
pred Wrap = error "AddressMode.pred: Wrap has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Border
fromEnum Wrap = 0
fromEnum Clamp = 1
fromEnum Mirror = 2
fromEnum Border = 3
toEnum 0 = Wrap
toEnum 1 = Clamp
toEnum 2 = Mirror
toEnum 3 = Border
toEnum unmatched = error ("AddressMode.toEnum: Cannot match " ++ show unmatched)
{-# LINE 70 "src/Foreign/CUDA/Driver/Texture.chs" #-}
data FilterMode = Point
| Linear
deriving (Eq,Show)
instance Enum FilterMode where
succ Point = Linear
succ Linear = error "FilterMode.succ: Linear has no successor"
pred Linear = Point
pred Point = error "FilterMode.pred: Point has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Linear
fromEnum Point = 0
fromEnum Linear = 1
toEnum 0 = Point
toEnum 1 = Linear
toEnum unmatched = error ("FilterMode.toEnum: Cannot match " ++ show unmatched)
{-# LINE 77 "src/Foreign/CUDA/Driver/Texture.chs" #-}
data ReadMode = ReadAsInteger
| NormalizedCoordinates
| SRGB
deriving (Eq,Show)
instance Enum ReadMode where
succ ReadAsInteger = NormalizedCoordinates
succ NormalizedCoordinates = SRGB
succ SRGB = error "ReadMode.succ: SRGB has no successor"
pred NormalizedCoordinates = ReadAsInteger
pred SRGB = NormalizedCoordinates
pred ReadAsInteger = error "ReadMode.pred: ReadAsInteger has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from SRGB
fromEnum ReadAsInteger = 1
fromEnum NormalizedCoordinates = 2
fromEnum SRGB = 16
toEnum 1 = ReadAsInteger
toEnum 2 = NormalizedCoordinates
toEnum 16 = SRGB
toEnum unmatched = error ("ReadMode.toEnum: Cannot match " ++ show unmatched)
{-# LINE 92 "src/Foreign/CUDA/Driver/Texture.chs" #-}
data Format = Word8
| Word16
| Word32
| Int8
| Int16
| Int32
| Half
| Float
deriving (Eq,Show)
instance Enum Format where
succ Word8 = Word16
succ Word16 = Word32
succ Word32 = Int8
succ Int8 = Int16
succ Int16 = Int32
succ Int32 = Half
succ Half = Float
succ Float = error "Format.succ: Float has no successor"
pred Word16 = Word8
pred Word32 = Word16
pred Int8 = Word32
pred Int16 = Int8
pred Int32 = Int16
pred Half = Int32
pred Float = Half
pred Word8 = error "Format.pred: Word8 has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Float
fromEnum Word8 = 1
fromEnum Word16 = 2
fromEnum Word32 = 3
fromEnum Int8 = 8
fromEnum Int16 = 9
fromEnum Int32 = 10
fromEnum Half = 16
fromEnum Float = 32
toEnum 1 = Word8
toEnum 2 = Word16
toEnum 3 = Word32
toEnum 8 = Int8
toEnum 9 = Int16
toEnum 10 = Int32
toEnum 16 = Half
toEnum 32 = Float
toEnum unmatched = error ("Format.toEnum: Cannot match " ++ show unmatched)
{-# LINE 105 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE create #-}
create :: IO Texture
create = resultIfOk =<< cuTexRefCreate
{-# INLINE cuTexRefCreate #-}
cuTexRefCreate :: IO ((Status), (Texture))
cuTexRefCreate =
alloca $ \a1' ->
cuTexRefCreate'_ a1' >>= \res ->
let {res' = cToEnum res} in
peekTex a1'>>= \a1'' ->
return (res', a1'')
{-# LINE 126 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE destroy #-}
destroy :: Texture -> IO ()
destroy !tex = nothingIfOk =<< cuTexRefDestroy tex
{-# INLINE cuTexRefDestroy #-}
cuTexRefDestroy :: (Texture) -> IO ((Status))
cuTexRefDestroy a1 =
let {a1' = useTexture a1} in
cuTexRefDestroy'_ a1' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 140 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE bind #-}
bind :: Texture -> DevicePtr a -> Int64 -> IO ()
bind !tex !dptr !bytes = nothingIfOk =<< cuTexRefSetAddress tex dptr bytes
{-# INLINE cuTexRefSetAddress #-}
cuTexRefSetAddress :: (Texture) -> (DevicePtr a) -> (Int64) -> IO ((Status))
cuTexRefSetAddress a2 a3 a4 =
alloca $ \a1' ->
let {a2' = useTexture a2} in
let {a3' = useDeviceHandle a3} in
let {a4' = fromIntegral a4} in
cuTexRefSetAddress'_ a1' a2' a3' a4' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 158 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE bind2D #-}
bind2D :: Texture -> Format -> Int -> DevicePtr a -> (Int,Int) -> Int64 -> IO ()
bind2D !tex !fmt !chn !dptr (!width,!height) !pitch =
nothingIfOk =<< cuTexRefSetAddress2DSimple tex fmt chn dptr width height pitch
{-# INLINE cuTexRefSetAddress2DSimple #-}
cuTexRefSetAddress2DSimple :: (Texture) -> (Format) -> (Int) -> (DevicePtr a) -> (Int) -> (Int) -> (Int64) -> IO ((Status))
cuTexRefSetAddress2DSimple a1 a2 a3 a4 a5 a6 a7 =
let {a1' = useTexture a1} in
let {a2' = cFromEnum a2} in
let {a3' = fromIntegral a3} in
let {a4' = useDeviceHandle a4} in
let {a5' = fromIntegral a5} in
let {a6' = fromIntegral a6} in
let {a7' = fromIntegral a7} in
cuTexRefSetAddress2DSimple'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 182 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE getAddressMode #-}
getAddressMode :: Texture -> Int -> IO AddressMode
getAddressMode !tex !dim = resultIfOk =<< cuTexRefGetAddressMode tex dim
{-# INLINE cuTexRefGetAddressMode #-}
cuTexRefGetAddressMode :: (Texture) -> (Int) -> IO ((Status), (AddressMode))
cuTexRefGetAddressMode a2 a3 =
alloca $ \a1' ->
let {a2' = useTexture a2} in
let {a3' = fromIntegral a3} in
cuTexRefGetAddressMode'_ a1' a2' a3' >>= \res ->
let {res' = cToEnum res} in
peekEnum a1'>>= \a1'' ->
return (res', a1'')
{-# LINE 199 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE getFilterMode #-}
getFilterMode :: Texture -> IO FilterMode
getFilterMode !tex = resultIfOk =<< cuTexRefGetFilterMode tex
{-# INLINE cuTexRefGetFilterMode #-}
cuTexRefGetFilterMode :: (Texture) -> IO ((Status), (FilterMode))
cuTexRefGetFilterMode a2 =
alloca $ \a1' ->
let {a2' = useTexture a2} in
cuTexRefGetFilterMode'_ a1' a2' >>= \res ->
let {res' = cToEnum res} in
peekEnum a1'>>= \a1'' ->
return (res', a1'')
{-# LINE 214 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE getFormat #-}
getFormat :: Texture -> IO (Format, Int)
getFormat !tex = do
(!status,!fmt,!dim) <- cuTexRefGetFormat tex
resultIfOk (status,(fmt,dim))
{-# INLINE cuTexRefGetFormat #-}
cuTexRefGetFormat :: (Texture) -> IO ((Status), (Format), (Int))
cuTexRefGetFormat a3 =
alloca $ \a1' ->
alloca $ \a2' ->
let {a3' = useTexture a3} in
cuTexRefGetFormat'_ a1' a2' a3' >>= \res ->
let {res' = cToEnum res} in
peekEnum a1'>>= \a1'' ->
peekIntConv a2'>>= \a2'' ->
return (res', a1'', a2'')
{-# LINE 232 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE setAddressMode #-}
setAddressMode :: Texture -> Int -> AddressMode -> IO ()
setAddressMode !tex !dim !mode = nothingIfOk =<< cuTexRefSetAddressMode tex dim mode
{-# INLINE cuTexRefSetAddressMode #-}
cuTexRefSetAddressMode :: (Texture) -> (Int) -> (AddressMode) -> IO ((Status))
cuTexRefSetAddressMode a1 a2 a3 =
let {a1' = useTexture a1} in
let {a2' = fromIntegral a2} in
let {a3' = cFromEnum a3} in
cuTexRefSetAddressMode'_ a1' a2' a3' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 248 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE setFilterMode #-}
setFilterMode :: Texture -> FilterMode -> IO ()
setFilterMode !tex !mode = nothingIfOk =<< cuTexRefSetFilterMode tex mode
{-# INLINE cuTexRefSetFilterMode #-}
cuTexRefSetFilterMode :: (Texture) -> (FilterMode) -> IO ((Status))
cuTexRefSetFilterMode a1 a2 =
let {a1' = useTexture a1} in
let {a2' = cFromEnum a2} in
cuTexRefSetFilterMode'_ a1' a2' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 264 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE setReadMode #-}
setReadMode :: Texture -> ReadMode -> IO ()
setReadMode !tex !mode = nothingIfOk =<< cuTexRefSetFlags tex mode
{-# INLINE cuTexRefSetFlags #-}
cuTexRefSetFlags :: (Texture) -> (ReadMode) -> IO ((Status))
cuTexRefSetFlags a1 a2 =
let {a1' = useTexture a1} in
let {a2' = cFromEnum a2} in
cuTexRefSetFlags'_ a1' a2' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 280 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINEABLE setFormat #-}
setFormat :: Texture -> Format -> Int -> IO ()
setFormat !tex !fmt !chn = nothingIfOk =<< cuTexRefSetFormat tex fmt chn
{-# INLINE cuTexRefSetFormat #-}
cuTexRefSetFormat :: (Texture) -> (Format) -> (Int) -> IO ((Status))
cuTexRefSetFormat a1 a2 a3 =
let {a1' = useTexture a1} in
let {a2' = cFromEnum a2} in
let {a3' = fromIntegral a3} in
cuTexRefSetFormat'_ a1' a2' a3' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 297 "src/Foreign/CUDA/Driver/Texture.chs" #-}
{-# INLINE peekTex #-}
peekTex :: Ptr ((C2HSImp.Ptr ())) -> IO Texture
peekTex = liftM Texture . peek
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefCreate"
cuTexRefCreate'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefDestroy"
cuTexRefDestroy'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefSetAddress"
cuTexRefSetAddress'_ :: ((C2HSImp.Ptr C2HSImp.CULong) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULLong -> (C2HSImp.CULong -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefSetAddress2DSimple"
cuTexRefSetAddress2DSimple'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CULLong -> (C2HSImp.CULong -> (C2HSImp.CULong -> (C2HSImp.CULong -> (IO C2HSImp.CInt))))))))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefGetAddressMode"
cuTexRefGetAddressMode'_ :: ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefGetFilterMode"
cuTexRefGetFilterMode'_ :: ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefGetFormat"
cuTexRefGetFormat'_ :: ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefSetAddressMode"
cuTexRefSetAddressMode'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefSetFilterMode"
cuTexRefSetFilterMode'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefSetFlags"
cuTexRefSetFlags'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/Driver/Texture.chs.h cuTexRefSetFormat"
cuTexRefSetFormat'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))