Skip to content

Commit

Permalink
Add MoltenVK compat to vulkan example
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwiz committed Jun 23, 2024
1 parent 92a3cc5 commit 40a6654
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dear-imgui.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ library
other-modules:
DearImGui.Vulkan.Types
build-depends:
vulkan
vulkan >= 3.20
, unliftio
cxx-sources:
imgui/backends/imgui_impl_vulkan.cpp
Expand Down Expand Up @@ -415,7 +415,7 @@ executable vulkan
, vector
>= 0.12.1.2 && < 0.14
, vulkan
>= 3.12
>= 3.20
, vulkan-utils
>= 0.5
, VulkanMemoryAllocator
Expand Down
17 changes: 10 additions & 7 deletions examples/vulkan/Backend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
Expand Down Expand Up @@ -99,6 +100,7 @@ import qualified Data.Vector as Boxed.Vector

-- vulkan
import qualified Vulkan
import Vulkan.Core10.DeviceInitialization (pattern INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR)
import qualified Vulkan.CStruct.Extends as Vulkan
import qualified Vulkan.Requirement as Vulkan
import qualified Vulkan.Zero as Vulkan
Expand Down Expand Up @@ -156,9 +158,10 @@ data InstanceType

data VulkanRequirements =
VulkanRequirements
{ instanceRequirements :: [ Vulkan.InstanceRequirement ]
, deviceRequirements :: [ Vulkan.DeviceRequirement ]
, queueFlags :: Vulkan.QueueFlags
{ instanceRequirements :: [ Vulkan.InstanceRequirement ]
, instanceRequirementsOpt :: [ Vulkan.InstanceRequirement ]
, deviceRequirements :: [ Vulkan.DeviceRequirement ]
, queueFlags :: Vulkan.QueueFlags
}

data ValidationLayerName
Expand All @@ -167,12 +170,12 @@ data ValidationLayerName
deriving stock ( Eq, Show )

initialiseVulkanContext :: MonadVulkan m => InstanceType -> ByteString -> VulkanRequirements -> m VulkanContext
initialiseVulkanContext instanceType appName ( VulkanRequirements { instanceRequirements, deviceRequirements, queueFlags } ) = do
initialiseVulkanContext instanceType appName ( VulkanRequirements { instanceRequirements, instanceRequirementsOpt, deviceRequirements, queueFlags } ) = do
logDebug "Creating Vulkan instance"
instanceInfo <- vulkanInstanceInfo appName
instance' <- case instanceType of
NormalInstance -> Vulkan.Utils.createInstanceFromRequirements instanceRequirements [] instanceInfo
DebugInstance -> Vulkan.Utils.createDebugInstanceFromRequirements instanceRequirements [] instanceInfo
NormalInstance -> Vulkan.Utils.createInstanceFromRequirements instanceRequirements instanceRequirementsOpt instanceInfo
DebugInstance -> Vulkan.Utils.createDebugInstanceFromRequirements instanceRequirements instanceRequirementsOpt instanceInfo
physicalDevice <- logDebug "Creating physical device" *> createPhysicalDevice instance'
queueFamily <- logDebug "Finding suitable queue family" *> findQueueFamilyIndex physicalDevice queueFlags
let
Expand Down Expand Up @@ -236,7 +239,7 @@ vulkanInstanceInfo appName = do
createInfo =
Vulkan.InstanceCreateInfo
{ Vulkan.next = ()
, Vulkan.flags = Vulkan.zero
, Vulkan.flags = INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR
, Vulkan.applicationInfo = Just appInfo
, Vulkan.enabledLayerNames = Boxed.Vector.fromList enabledLayers
, Vulkan.enabledExtensionNames = mempty
Expand Down
4 changes: 4 additions & 0 deletions examples/vulkan/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ app = do
, mouseMode = SDL.AbsoluteLocation
}
let
compatExtensions =
[ Vulkan.KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME
]
vulkanReqs :: VulkanRequirements
vulkanReqs =
VulkanRequirements
{ instanceRequirements = instanceExtensions windowExtensions
, instanceRequirementsOpt = instanceExtensions compatExtensions
, deviceRequirements = []
, queueFlags = Vulkan.QUEUE_GRAPHICS_BIT
}
Expand Down

0 comments on commit 40a6654

Please sign in to comment.