Skip to content

Commit 10cca44

Browse files
authored
Expose Vulkan dynamic rendering (#205)
* expose useDynamicRendering * add color attachment format
1 parent 92a3cc5 commit 10cca44

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

examples/vulkan/Main.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,16 @@ app = do
387387
, device
388388
, queueFamily
389389
, queue
390-
, pipelineCache = Vulkan.NULL_HANDLE
391-
, descriptorPool = imGuiDescriptorPool
392-
, subpass = 0
390+
, pipelineCache = Vulkan.NULL_HANDLE
391+
, descriptorPool = imGuiDescriptorPool
392+
, subpass = 0
393393
, minImageCount
394394
, imageCount
395-
, msaaSamples = Vulkan.SAMPLE_COUNT_1_BIT
396-
, mbAllocator = Nothing
397-
, checkResult = \case { Vulkan.SUCCESS -> pure (); e -> throw $ Vulkan.VulkanException e }
395+
, msaaSamples = Vulkan.SAMPLE_COUNT_1_BIT
396+
, mbAllocator = Nothing
397+
, useDynamicRendering = False
398+
, colorAttachmentFormat = Nothing
399+
, checkResult = \case { Vulkan.SUCCESS -> pure (); e -> throw $ Vulkan.VulkanException e }
398400
}
399401

400402
logDebug "Initialising ImGui SDL2 for Vulkan"

src/DearImGui/Vulkan.hs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import Data.Word
3131
( Word32 )
3232
import Foreign.Marshal.Alloc
3333
( alloca )
34+
import Foreign.Marshal.Utils
35+
( fromBool )
3436
import Foreign.Ptr
3537
( FunPtr, Ptr, freeHaskellFunPtr, nullPtr )
3638
import Foreign.Storable
@@ -70,19 +72,21 @@ Cpp.using "namespace ImGui"
7072

7173
data InitInfo =
7274
InitInfo
73-
{ instance' :: !Vulkan.Instance
74-
, physicalDevice :: !Vulkan.PhysicalDevice
75-
, device :: !Vulkan.Device
76-
, queueFamily :: !Word32
77-
, queue :: !Vulkan.Queue
78-
, pipelineCache :: !Vulkan.PipelineCache
79-
, descriptorPool :: !Vulkan.DescriptorPool
80-
, subpass :: !Word32
81-
, minImageCount :: !Word32
82-
, imageCount :: !Word32
83-
, msaaSamples :: !Vulkan.SampleCountFlagBits
84-
, mbAllocator :: Maybe Vulkan.AllocationCallbacks
85-
, checkResult :: Vulkan.Result -> IO ()
75+
{ instance' :: !Vulkan.Instance
76+
, physicalDevice :: !Vulkan.PhysicalDevice
77+
, device :: !Vulkan.Device
78+
, queueFamily :: !Word32
79+
, queue :: !Vulkan.Queue
80+
, pipelineCache :: !Vulkan.PipelineCache
81+
, descriptorPool :: !Vulkan.DescriptorPool
82+
, subpass :: !Word32
83+
, minImageCount :: !Word32
84+
, imageCount :: !Word32
85+
, msaaSamples :: !Vulkan.SampleCountFlagBits
86+
, colorAttachmentFormat :: !(Maybe Vulkan.Format)
87+
, useDynamicRendering :: !Bool
88+
, mbAllocator :: Maybe Vulkan.AllocationCallbacks
89+
, checkResult :: Vulkan.Result -> IO ()
8690
}
8791

8892
-- | Wraps @ImGui_ImplVulkan_Init@ and @ImGui_ImplVulkan_Shutdown@.
@@ -112,6 +116,10 @@ vulkanInit ( InitInfo {..} ) renderPass = do
112116
withCallbacks f = case mbAllocator of
113117
Nothing -> f nullPtr
114118
Just callbacks -> alloca ( \ ptr -> poke ptr callbacks *> f ptr )
119+
useDynamicRendering' :: Cpp.CBool
120+
useDynamicRendering' = fromBool useDynamicRendering
121+
colorAttachmentFormat' :: Vulkan.Format
122+
colorAttachmentFormat' = fromMaybe Vulkan.FORMAT_UNDEFINED colorAttachmentFormat
115123
liftIO do
116124
checkResultFunPtr <- $( C.mkFunPtr [t| Vulkan.Result -> IO () |] ) checkResult
117125
initResult <- withCallbacks \ callbacksPtr ->
@@ -134,8 +142,8 @@ vulkanInit ( InitInfo {..} ) renderPass = do
134142
initInfo.MSAASamples = $(VkSampleCountFlagBits msaaSamples);
135143
initInfo.Allocator = $(VkAllocationCallbacks* callbacksPtr);
136144
initInfo.CheckVkResultFn = $( void (*checkResultFunPtr)(VkResult) );
137-
initInfo.UseDynamicRendering = false;
138-
// TODO: initInfo.ColorAttachmentFormat
145+
initInfo.UseDynamicRendering = $(bool useDynamicRendering');
146+
initInfo.ColorAttachmentFormat = $(VkFormat colorAttachmentFormat');
139147
return ImGui_ImplVulkan_Init(&initInfo, $(VkRenderPass renderPass) );
140148
}|]
141149
pure ( checkResultFunPtr, initResult /= 0 )

src/DearImGui/Vulkan/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ vulkanTypesTable = Map.fromList
3535
, ( C.TypeName "VkImageView" , [t| Vulkan.ImageView |] )
3636
, ( C.TypeName "VkImageLayout" , [t| Vulkan.ImageLayout |] )
3737
, ( C.TypeName "VkDescriptorSet" , [t| Vulkan.DescriptorSet |] )
38+
, ( C.TypeName "VkFormat" , [t| Vulkan.Format |])
3839
]
3940

4041
vulkanCtx :: C.Context

0 commit comments

Comments
 (0)