### Haskell: Safe Resource Management with Bracketing Commands Source: https://hackage.haskell.org/package/vulkan Demonstrates the use of bracketing commands in Haskell for Vulkan resource management, ensuring that creation and destruction functions are paired correctly. These functions, prefixed with `with` or `use`, often leverage `Control.Exception.bracket` or similar mechanisms for safe allocation and deallocation. The example shows `withInstance` for managing Vulkan instances. ```haskell createInstance :: forall a m . (PokeChain a, MonadIO m) => InstanceCreateInfo a -> Maybe AllocationCallbacks -> m Instance destroyInstance :: forall m . MonadIO m => Instance -> Maybe AllocationCallbacks -> m () withInstance :: forall a m r . (PokeChain a, MonadIO m) => InstanceCreateInfo a -> Maybe AllocationCallbacks -> (m Instance -> (Instance -> m ()) -> r) -> r ``` ```haskell import Control.Monad.Trans.Resource (runResourceT, allocate) -- Create an instance and print its value main = runResourceT $ do (instanceReleaseKey, inst) <- withInstance zero Nothing allocate liftIO $ print inst -- Begin a render pass, draw something and end the render pass drawTriangle = cmdUseRenderPass buffer renderPassBeginInfo SUBPASS_CONTENTS_INLINE bracket_ $ do cmdBindPipeline buffer PIPELINE_BIND_POINT_GRAPHICS graphicsPipeline cmdDraw buffer 3 1 0 0 ``` -------------------------------- ### Haskell: Handling Dual-Use Vulkan Commands Source: https://hackage.haskell.org/package/vulkan Illustrates how Haskell bindings handle Vulkan commands that have dual use: they can either return a count of available items or the items themselves. The bindings typically provide functions that automatically fetch all results, simplifying the common Vulkan idiom of querying the count first and then allocating memory to retrieve the data. An example is `enumeratePhysicalDevices`. ```haskell enumeratePhysicalDevices :: MonadIO m => Instance -> m (Result, Vector PhysicalDevice) ``` -------------------------------- ### Construct Vulkan Struct Chain with Pattern Synonyms Source: https://hackage.haskell.org/package/vulkan Demonstrates how to create a Vulkan instance creation info structure with extensions like debug utils and validation features using the `:&` and `()` pattern synonyms to build a struct chain. ```haskell makeInst = do let debugCreateInfo = _ :: DebugUtilsMessengerCreateInfoEXT validationFeatures = ValidationFeaturesEXT [VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT] [] instanceCreateInfo = zero ::& debugCreateInfo :& validationFeatures :& () createInstance instanceCreateInfo Nothing ``` -------------------------------- ### Build Vulkan Packages with Nix Source: https://hackage.haskell.org/package/vulkan Commands to build specific components of the repository using the Nix build tool. ```bash nix-build -A vulkan nix-build -A vulkan-examples ``` -------------------------------- ### Parsing Enums and Bitmasks in Haskell Source: https://hackage.haskell.org/package/vulkan Demonstrates how to use the `Read` and `Show` instances for Vulkan enums and bitmasks in Haskell to parse pattern synonyms. This allows for convenient conversion between string representations and their corresponding Haskell types. ```haskell read @COMPARE_OP "COMPARE_OP_LESS" ``` -------------------------------- ### Evaluate Nix Attribute Set Source: https://hackage.haskell.org/package/vulkan Evaluates the default.nix file to expose the available package set including vulkan, VMA bindings, and utility functions. ```nix default.nix { forShell = false; } ``` -------------------------------- ### Run Generator Program Source: https://hackage.haskell.org/package/vulkan Executes the generator program within a configured shell environment to produce Vulkan source code. ```bash ghci $(HIE_BIOS_OUTPUT=/dev/stdout ./flags.sh $(pwd)/vk/Main.hs) vk/Main.hs +RTS -N16 ``` -------------------------------- ### Deconstruct Vulkan Struct Chain to Check Features Source: https://hackage.haskell.org/package/vulkan Shows how to extract specific features, like Timeline Semaphores, from a Vulkan struct chain returned by `getPhysicalDeviceFeatures2` using pattern matching with `:&` and `()`. ```haskell hasTimelineSemaphores phys = do _ ::& PhysicalDeviceTimelineSemaphoreFeatures hasTimelineSemaphores :& () <- getPhysicalDeviceFeatures2 phys pure hasTimelineSemaphores ``` ```haskell hasTimelineSemaphores phys = do feats <- getPhysicalDeviceFeatures2 phys let _ ::& PhysicalDeviceTimelineSemaphoreFeatures hasTimelineSemaphores :& () = feats pure hasTimelineSemaphores ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.