From e1dfa195b7cb1b335f801b6b43f90083e90cc665 Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 2 Dec 2022 02:57:00 +0100 Subject: [PATCH] finish up memory allocator --- src/Memory.hs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Memory.hs b/src/Memory.hs index 3c446da..be94627 100644 --- a/src/Memory.hs +++ b/src/Memory.hs @@ -3,10 +3,15 @@ {-# LANGUAGE DataKinds #-} module Memory where +import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.Resource +import Foreign.Ptr +import Foreign.Storable + import qualified VulkanMemoryAllocator as VMA import qualified Vulkan.Core10 as Vk +import qualified Vulkan.Dynamic as Vk import qualified Vulkan.Zero as Vk initAllocator @@ -16,10 +21,18 @@ initAllocator -> Vk.Instance -> m VMA.Allocator 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 - { VMA.physicalDevice = Vk.physicalDeviceHandle physicalDevice - , VMA.device = Vk.deviceHandle device - , VMA.instance' = Vk.instanceHandle instance' + { VMA.physicalDevice = Vk.physicalDeviceHandle physicalDevice + , VMA.device = Vk.deviceHandle device + , VMA.instance' = Vk.instanceHandle instance' + , VMA.vulkanFunctions = Just (Vk.zero + { VMA.vkGetInstanceProcAddr = instanceProcAddr + , VMA.vkGetDeviceProcAddr = deviceProcAddr + } :: VMA.VulkanFunctions) } :: VMA.AllocatorCreateInfo (_, allocator) <- allocate