Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MoltenVK compat to vulkan example #200

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading