fix initialization

This commit is contained in:
nek0 2023-05-15 14:20:18 +02:00
parent 488c32e084
commit 32bc3fc4b4
1 changed files with 11 additions and 20 deletions

View File

@ -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