Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fillBufferWithShaderFileContents :: FilePath -> ResIO (CSize, Ptr Word8)
- fillBufferWithShaderFileContents path = do
- (bufferPtr, alignedSize, bytesRead) <- runResourceT $ do
- handle <- allocate_ (openBinaryFile path ReadMode) hClose
- fileSize <- liftIO $ hFileSize handle
- -- Vulkan requires SPIR-V bytecode to have an alignment of 4 bytes.
- let alignedSize = fromIntegral . (4 *) . (`div` 4) . (3 +) $ fileSize
- bufferPtr <- lift $ allocate_ (mallocArray @Word8 alignedSize) free
- bytesRead <- liftIO $ hGetBuf handle bufferPtr alignedSize
- return (bufferPtr, alignedSize, bytesRead)
- liftIO $ pokeArray (castPtr @_ @Word8 . plusPtr bufferPtr $ bytesRead) $ replicate (alignedSize - bytesRead) 0
- return (fromIntegral alignedSize, bufferPtr)
Add Comment
Please, Sign In to add comment