Guest User

Untitled

a guest
Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. fillBufferWithShaderFileContents :: FilePath -> ResIO (CSize, Ptr Word8)
  2. fillBufferWithShaderFileContents path = do
  3. (bufferPtr, alignedSize, bytesRead) <- runResourceT $ do
  4. handle <- allocate_ (openBinaryFile path ReadMode) hClose
  5. fileSize <- liftIO $ hFileSize handle
  6.  
  7. -- Vulkan requires SPIR-V bytecode to have an alignment of 4 bytes.
  8. let alignedSize = fromIntegral . (4 *) . (`div` 4) . (3 +) $ fileSize
  9.  
  10. bufferPtr <- lift $ allocate_ (mallocArray @Word8 alignedSize) free
  11. bytesRead <- liftIO $ hGetBuf handle bufferPtr alignedSize
  12. return (bufferPtr, alignedSize, bytesRead)
  13.  
  14. liftIO $ pokeArray (castPtr @_ @Word8 . plusPtr bufferPtr $ bytesRead) $ replicate (alignedSize - bytesRead) 0
  15.  
  16. return (fromIntegral alignedSize, bufferPtr)
Add Comment
Please, Sign In to add comment