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

Expose Vulkan dynamic rendering #205

Merged
merged 2 commits into from
Jun 23, 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
14 changes: 8 additions & 6 deletions examples/vulkan/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,16 @@ app = do
, device
, queueFamily
, queue
, pipelineCache = Vulkan.NULL_HANDLE
, descriptorPool = imGuiDescriptorPool
, subpass = 0
, pipelineCache = Vulkan.NULL_HANDLE
, descriptorPool = imGuiDescriptorPool
, subpass = 0
, minImageCount
, imageCount
, msaaSamples = Vulkan.SAMPLE_COUNT_1_BIT
, mbAllocator = Nothing
, checkResult = \case { Vulkan.SUCCESS -> pure (); e -> throw $ Vulkan.VulkanException e }
, msaaSamples = Vulkan.SAMPLE_COUNT_1_BIT
, mbAllocator = Nothing
, useDynamicRendering = False
, colorAttachmentFormat = Nothing
, checkResult = \case { Vulkan.SUCCESS -> pure (); e -> throw $ Vulkan.VulkanException e }
}

logDebug "Initialising ImGui SDL2 for Vulkan"
Expand Down
38 changes: 23 additions & 15 deletions src/DearImGui/Vulkan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import Data.Word
( Word32 )
import Foreign.Marshal.Alloc
( alloca )
import Foreign.Marshal.Utils
( fromBool )
import Foreign.Ptr
( FunPtr, Ptr, freeHaskellFunPtr, nullPtr )
import Foreign.Storable
Expand Down Expand Up @@ -70,19 +72,21 @@ Cpp.using "namespace ImGui"

data InitInfo =
InitInfo
{ instance' :: !Vulkan.Instance
, physicalDevice :: !Vulkan.PhysicalDevice
, device :: !Vulkan.Device
, queueFamily :: !Word32
, queue :: !Vulkan.Queue
, pipelineCache :: !Vulkan.PipelineCache
, descriptorPool :: !Vulkan.DescriptorPool
, subpass :: !Word32
, minImageCount :: !Word32
, imageCount :: !Word32
, msaaSamples :: !Vulkan.SampleCountFlagBits
, mbAllocator :: Maybe Vulkan.AllocationCallbacks
, checkResult :: Vulkan.Result -> IO ()
{ instance' :: !Vulkan.Instance
, physicalDevice :: !Vulkan.PhysicalDevice
, device :: !Vulkan.Device
, queueFamily :: !Word32
, queue :: !Vulkan.Queue
, pipelineCache :: !Vulkan.PipelineCache
, descriptorPool :: !Vulkan.DescriptorPool
, subpass :: !Word32
, minImageCount :: !Word32
, imageCount :: !Word32
, msaaSamples :: !Vulkan.SampleCountFlagBits
, colorAttachmentFormat :: !(Maybe Vulkan.Format)
, useDynamicRendering :: !Bool
, mbAllocator :: Maybe Vulkan.AllocationCallbacks
, checkResult :: Vulkan.Result -> IO ()
}

-- | Wraps @ImGui_ImplVulkan_Init@ and @ImGui_ImplVulkan_Shutdown@.
Expand Down Expand Up @@ -112,6 +116,10 @@ vulkanInit ( InitInfo {..} ) renderPass = do
withCallbacks f = case mbAllocator of
Nothing -> f nullPtr
Just callbacks -> alloca ( \ ptr -> poke ptr callbacks *> f ptr )
useDynamicRendering' :: Cpp.CBool
useDynamicRendering' = fromBool useDynamicRendering
colorAttachmentFormat' :: Vulkan.Format
colorAttachmentFormat' = fromMaybe Vulkan.FORMAT_UNDEFINED colorAttachmentFormat
liftIO do
checkResultFunPtr <- $( C.mkFunPtr [t| Vulkan.Result -> IO () |] ) checkResult
initResult <- withCallbacks \ callbacksPtr ->
Expand All @@ -134,8 +142,8 @@ vulkanInit ( InitInfo {..} ) renderPass = do
initInfo.MSAASamples = $(VkSampleCountFlagBits msaaSamples);
initInfo.Allocator = $(VkAllocationCallbacks* callbacksPtr);
initInfo.CheckVkResultFn = $( void (*checkResultFunPtr)(VkResult) );
initInfo.UseDynamicRendering = false;
// TODO: initInfo.ColorAttachmentFormat
initInfo.UseDynamicRendering = $(bool useDynamicRendering');
initInfo.ColorAttachmentFormat = $(VkFormat colorAttachmentFormat');
return ImGui_ImplVulkan_Init(&initInfo, $(VkRenderPass renderPass) );
}|]
pure ( checkResultFunPtr, initResult /= 0 )
Expand Down
1 change: 1 addition & 0 deletions src/DearImGui/Vulkan/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ vulkanTypesTable = Map.fromList
, ( C.TypeName "VkImageView" , [t| Vulkan.ImageView |] )
, ( C.TypeName "VkImageLayout" , [t| Vulkan.ImageLayout |] )
, ( C.TypeName "VkDescriptorSet" , [t| Vulkan.DescriptorSet |] )
, ( C.TypeName "VkFormat" , [t| Vulkan.Format |])
]

vulkanCtx :: C.Context
Expand Down
Loading