From 32bc3fc4b4d79286be978046aca2ed8f3e3f0205 Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 15 May 2023 14:20:18 +0200 Subject: [PATCH] fix initialization --- src/Textures.hs | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/Textures.hs b/src/Textures.hs index 52b1abd..f914d10 100644 --- a/src/Textures.hs +++ b/src/Textures.hs @@ -10,6 +10,7 @@ import Control.Monad.Reader import Control.Monad.Trans.Resource import qualified Data.Map.Strict as M import qualified Data.Vector as V +import qualified Data.Vector.Storable as VS import Foreign hiding (void) import qualified Control.Concurrent.STM as STM import qualified Vulkan as Vk @@ -50,32 +51,22 @@ loadImageFromFile allocator uploadContext queue device file = do let dataPtr = VMA.mappedData (bufferInfo stagingBuffer) - liftIO $ V.mapM_ - (\(idx, px) -> - poke - (castPtr dataPtr `plusPtr` (idx * sizeOf px)) - px - ) - (V.zip - (V.fromList [0..]) - (V.convert $ P.imageData pixels) - ) + liftIO $ pokeArray (castPtr dataPtr) (VS.toList $ P.imageData pixels) let imageExtent = Vk.Extent3D - { width = fromIntegral $ texWidth - , height = fromIntegral $ texHeight + { width = fromIntegral texWidth + , height = fromIntegral texHeight , depth = 1 } - dImgCreateInfo = Vk.zero - { Vk.format = imageFormat - , Vk.usage = Vk.IMAGE_USAGE_SAMPLED_BIT .|. Vk.IMAGE_USAGE_TRANSFER_DST_BIT - , Vk.extent = imageExtent - } dImgAllocCreateInfo = Vk.zero { VMA.usage = VMA.MEMORY_USAGE_GPU_ONLY } :: VMA.AllocationCreateInfo + dImgCreateInfo = imageCreate + imageFormat + imageExtent + (Vk.IMAGE_USAGE_SAMPLED_BIT .|. Vk.IMAGE_USAGE_TRANSFER_DST_BIT) - (newImage, allocation, _) <- snd <$> + (newImage, newAllocation, _) <- snd <$> VMA.withImage allocator dImgCreateInfo dImgAllocCreateInfo allocate immediateSubmit @@ -95,7 +86,7 @@ loadImageFromFile allocator uploadContext queue device file = do , Vk.newLayout = Vk.IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL , Vk.image = newImage , Vk.subresourceRange = range - , Vk.srcAccessMask = bit 0 + -- , Vk.srcAccessMask = bit 0 , Vk.dstAccessMask = Vk.ACCESS_TRANSFER_WRITE_BIT } :: Vk.ImageMemoryBarrier '[]) @@ -149,7 +140,7 @@ loadImageFromFile allocator uploadContext queue device file = do return $ AllocatedImage { image = newImage - , allocation = allocation + , allocation = newAllocation } loadImages