2022-07-10 23:58:58 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE DuplicateRecordFields #-}
|
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
module Instance where
|
|
|
|
|
|
|
|
import Control.Monad.IO.Class
|
|
|
|
import Control.Monad.Trans.Resource
|
|
|
|
import qualified Data.ByteString as BS
|
|
|
|
import qualified Data.Vector as V
|
|
|
|
import qualified SDL hiding (V2)
|
|
|
|
import qualified SDL.Video.Vulkan as SDL
|
|
|
|
import qualified Vulkan as Vk
|
2023-01-16 00:10:23 +00:00
|
|
|
import qualified Vulkan.Requirement as Vk
|
2022-07-10 23:58:58 +00:00
|
|
|
import qualified Vulkan.Zero as Vk
|
2023-01-16 00:10:23 +00:00
|
|
|
import qualified Vulkan.Utils.Initialization as VkU
|
2022-07-10 23:58:58 +00:00
|
|
|
|
|
|
|
createInstance :: MonadResource m => SDL.Window -> m Vk.Instance
|
|
|
|
createInstance window = do
|
2023-01-06 23:14:39 +00:00
|
|
|
windowExtensions <-
|
2023-01-16 00:10:23 +00:00
|
|
|
(++)
|
|
|
|
-- [ Vk.KHR_PUSH_DESCRIPTOR_EXTENSION_NAME
|
|
|
|
-- , Vk.EXT_DEBUG_UTILS_EXTENSION_NAME
|
|
|
|
-- ]
|
|
|
|
[ Vk.EXT_DEBUG_UTILS_EXTENSION_NAME
|
|
|
|
]
|
|
|
|
<$>
|
2023-01-06 23:14:39 +00:00
|
|
|
((liftIO . mapM BS.packCString) =<< SDL.vkGetInstanceExtensions window)
|
2023-01-16 00:10:23 +00:00
|
|
|
-- liftIO $ do
|
|
|
|
-- putStrLn "activating followinfg extensions:"
|
|
|
|
-- print windowExtensions
|
2022-07-10 23:58:58 +00:00
|
|
|
let createInfo = Vk.zero
|
2022-07-11 12:04:42 +00:00
|
|
|
{ Vk.applicationInfo = Just Vk.zero
|
|
|
|
{ Vk.applicationName = Just "Haskell ❤️ Vulkan"
|
2023-01-16 00:10:23 +00:00
|
|
|
, Vk.apiVersion = Vk.API_VERSION_1_2
|
2022-07-10 23:58:58 +00:00
|
|
|
}
|
|
|
|
-- enable debug util extension for debugging purposes
|
|
|
|
, Vk.enabledExtensionNames = V.fromList windowExtensions
|
|
|
|
-- enable validation layer for debugging purposes
|
2023-01-16 00:10:23 +00:00
|
|
|
, Vk.enabledLayerNames = V.fromList
|
|
|
|
[ "VK_LAYER_KHRONOS_validation"
|
|
|
|
]
|
2022-07-10 23:58:58 +00:00
|
|
|
}
|
2023-01-16 00:10:23 +00:00
|
|
|
requirements =
|
|
|
|
[ Vk.RequireInstanceExtension
|
|
|
|
{ Vk.instanceExtensionLayerName = Nothing
|
|
|
|
, Vk.instanceExtensionName = Vk.KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME
|
|
|
|
, Vk.instanceExtensionMinVersion = Vk.KHR_GET_DISPLAY_PROPERTIES_2_SPEC_VERSION
|
|
|
|
}
|
|
|
|
, Vk.RequireInstanceExtension
|
|
|
|
{ Vk.instanceExtensionLayerName = Nothing
|
|
|
|
, Vk.instanceExtensionName = Vk.KHR_XLIB_SURFACE_EXTENSION_NAME
|
|
|
|
, Vk.instanceExtensionMinVersion = Vk.KHR_XLIB_SURFACE_SPEC_VERSION
|
|
|
|
}
|
|
|
|
, Vk.RequireInstanceExtension
|
|
|
|
{ Vk.instanceExtensionLayerName = Nothing
|
|
|
|
, Vk.instanceExtensionName = Vk.KHR_DISPLAY_EXTENSION_NAME
|
|
|
|
, Vk.instanceExtensionMinVersion = Vk.KHR_DISPLAY_SPEC_VERSION
|
|
|
|
}
|
|
|
|
, Vk.RequireInstanceExtension
|
|
|
|
{ Vk.instanceExtensionLayerName = Nothing
|
|
|
|
, Vk.instanceExtensionName = Vk.KHR_SURFACE_EXTENSION_NAME
|
|
|
|
, Vk.instanceExtensionMinVersion = Vk.KHR_SURFACE_SPEC_VERSION
|
|
|
|
}
|
|
|
|
, Vk.RequireInstanceExtension
|
|
|
|
{ Vk.instanceExtensionLayerName = Nothing
|
|
|
|
, Vk.instanceExtensionName = Vk.KHR_PUSH_DESCRIPTOR_EXTENSION_NAME
|
|
|
|
, Vk.instanceExtensionMinVersion = Vk.KHR_PUSH_DESCRIPTOR_SPEC_VERSION
|
|
|
|
}
|
|
|
|
]
|
2022-07-10 23:58:58 +00:00
|
|
|
|
2023-01-06 23:14:39 +00:00
|
|
|
SDL.vkLoadLibrary Nothing
|
|
|
|
|
2023-01-16 00:10:23 +00:00
|
|
|
-- VkU.createDebugInstanceFromRequirements requirements [] createInfo
|
2022-07-10 23:58:58 +00:00
|
|
|
(_, inst) <- allocate
|
|
|
|
(Vk.createInstance createInfo Nothing)
|
|
|
|
(\inst -> do
|
2022-07-12 14:31:40 +00:00
|
|
|
putStrLn "destroying instance"
|
2022-07-10 23:58:58 +00:00
|
|
|
Vk.destroyInstance inst Nothing
|
|
|
|
)
|
|
|
|
|
|
|
|
return inst
|