finish up memory allocator

This commit is contained in:
nek0 2022-12-02 02:57:00 +01:00
parent 133170f6ad
commit e1dfa195b7

View file

@ -3,10 +3,15 @@
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
module Memory where module Memory where
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Resource import Control.Monad.Trans.Resource
import Foreign.Ptr
import Foreign.Storable
import qualified VulkanMemoryAllocator as VMA import qualified VulkanMemoryAllocator as VMA
import qualified Vulkan.Core10 as Vk import qualified Vulkan.Core10 as Vk
import qualified Vulkan.Dynamic as Vk
import qualified Vulkan.Zero as Vk import qualified Vulkan.Zero as Vk
initAllocator initAllocator
@ -16,10 +21,18 @@ initAllocator
-> Vk.Instance -> Vk.Instance
-> m VMA.Allocator -> m VMA.Allocator
initAllocator physicalDevice device instance' = do initAllocator physicalDevice device instance' = do
instanceProcAddr <- liftIO $ peek $ castFunPtrToPtr $
Vk.pVkGetInstanceProcAddr ((Vk.instanceCmds :: Vk.Instance -> Vk.InstanceCmds) instance')
deviceProcAddr <- liftIO $ peek $ castFunPtrToPtr $
Vk.pVkGetDeviceProcAddr ((Vk.deviceCmds :: Vk.Device -> Vk.DeviceCmds) device)
let allocatorInfo = Vk.zero let allocatorInfo = Vk.zero
{ VMA.physicalDevice = Vk.physicalDeviceHandle physicalDevice { VMA.physicalDevice = Vk.physicalDeviceHandle physicalDevice
, VMA.device = Vk.deviceHandle device , VMA.device = Vk.deviceHandle device
, VMA.instance' = Vk.instanceHandle instance' , VMA.instance' = Vk.instanceHandle instance'
, VMA.vulkanFunctions = Just (Vk.zero
{ VMA.vkGetInstanceProcAddr = instanceProcAddr
, VMA.vkGetDeviceProcAddr = deviceProcAddr
} :: VMA.VulkanFunctions)
} :: VMA.AllocatorCreateInfo } :: VMA.AllocatorCreateInfo
(_, allocator) <- allocate (_, allocator) <- allocate