From 6569b4449ba524f9271a965896731de9db7d36f2 Mon Sep 17 00:00:00 2001 From: Tristan de Cacqueray Date: Sun, 12 May 2024 10:17:15 +0000 Subject: [PATCH 1/4] Adjust vulkan text constraint for ghc-9.8 (#203) This change relax the vulkan executable constraint to match the one of the library. --- dear-imgui.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dear-imgui.cabal b/dear-imgui.cabal index d058911..fa290eb 100644 --- a/dear-imgui.cabal +++ b/dear-imgui.cabal @@ -405,7 +405,7 @@ executable vulkan , sdl2 >= 2.5.3.0 && < 2.6 , text - >= 1.2.4 && < 2.1 + >= 1.2.4 && < 2.2 , transformers >= 0.5.6 && < 0.7 , unliftio From d8194102541d9ffc9e6ff7deeba042e572128d47 Mon Sep 17 00:00:00 2001 From: Tristan de Cacqueray Date: Sun, 12 May 2024 10:21:29 +0000 Subject: [PATCH 2/4] Set proper sdl2 min bound (#204) This change prevents building against sdl2 version 1 which does not have the necessary exposed modules. --- dear-imgui.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dear-imgui.cabal b/dear-imgui.cabal index fa290eb..1411d01 100644 --- a/dear-imgui.cabal +++ b/dear-imgui.cabal @@ -252,7 +252,7 @@ library exposed-modules: DearImGui.SDL build-depends: - sdl2 + sdl2 >= 2 cxx-sources: imgui/backends/imgui_impl_sdl2.cpp From 92a3cc53ab6eed5a5d38319bca9bf8d07b18d8e8 Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Sun, 23 Jun 2024 22:42:43 +0300 Subject: [PATCH 3/4] Bump haskell.nix (#201) * Bump haskell.nix * Bump cachix actions * Bump nixpkgs to 2405 --- .github/workflows/build.yaml | 4 +- default.nix | 2 +- nix/sources.json | 28 ++++----- nix/sources.nix | 118 +++++++++++++++++++++-------------- 4 files changed, 88 insertions(+), 64 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6316335..e0ccac4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,11 +9,11 @@ jobs: persist-credentials: false submodules: true - - uses: cachix/install-nix-action@v20 + - uses: cachix/install-nix-action@v27 with: nix_path: nixpkgs=channel:nixos-unstable - - uses: cachix/cachix-action@v12 + - uses: cachix/cachix-action@v15 with: name: hs-dear-imgui authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' diff --git a/default.nix b/default.nix index 0e9bba3..cc0ee4e 100644 --- a/default.nix +++ b/default.nix @@ -4,7 +4,7 @@ haskellNix ? (import (import ./nix/sources.nix)."haskell.nix" { }) # haskell.nix provides access to the nixpkgs pins which are used by our CI, # hence you will be more likely to get cache hits when using these. # But you can also just use your own, e.g. ''. -, nixpkgsSrc ? haskellNix.sources.nixpkgs-2105 +, nixpkgsSrc ? haskellNix.sources.nixpkgs-2305 # haskell.nix provides some arguments to be passed to nixpkgs, including some # patches and also the haskell.nix functionality itself as an overlay. diff --git a/nix/sources.json b/nix/sources.json index 858ff2a..af58d57 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -1,14 +1,14 @@ { "haskell.nix": { - "branch": "master", + "branch": "2024.06.16", "description": "Alternative Haskell Infrastructure for Nixpkgs", "homepage": "https://input-output-hk.github.io/haskell.nix", "owner": "input-output-hk", "repo": "haskell.nix", - "rev": "970c84ad19e84d4ae42075cfe283022394f6effa", - "sha256": "01afbcas324n7j2bpfib7b4fazg5y6k7b74803c0i9ayrs6sgav6", + "rev": "83f1cb67cb3c97553815d5562d070ac754c25686", + "sha256": "1ggs13zdg8c3s9l6m6qd91zghjkxc0vy96vq0zfvpb5sc6bm2fhy", "type": "tarball", - "url": "https://github.com/input-output-hk/haskell.nix/archive/970c84ad19e84d4ae42075cfe283022394f6effa.tar.gz", + "url": "https://github.com/input-output-hk/haskell.nix/archive/83f1cb67cb3c97553815d5562d070ac754c25686.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "niv": { @@ -17,22 +17,22 @@ "homepage": "https://github.com/nmattia/niv", "owner": "nmattia", "repo": "niv", - "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070", - "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx", + "rev": "f7c538837892dd2eb83567c9f380a11efb59b53f", + "sha256": "0xl33k24vfc29cg9lnp95kvcq69qbq5fzb7jk9ig4lgrhaarh651", "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz", + "url": "https://github.com/nmattia/niv/archive/f7c538837892dd2eb83567c9f380a11efb59b53f.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { - "branch": "nixos-19.09", - "description": "DEPRECATED! This is an obsolete, read-only mirror of the NixOS/nixpkgs repository.", - "homepage": "https://github.com/NixOS/nixpkgs", + "branch": "24.05", + "description": "Nix Packages collection & NixOS", + "homepage": "", "owner": "NixOS", - "repo": "nixpkgs-channels", - "rev": "75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1", - "sha256": "157c64220lf825ll4c0cxsdwg7cxqdx4z559fdp7kpz0g6p8fhhr", + "repo": "nixpkgs", + "rev": "63dacb46bf939521bdc93981b4cbb7ecb58427a0", + "sha256": "1lr1h35prqkd1mkmzriwlpvxcb34kmhc9dnr48gkm8hh089hifmx", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs-channels/archive/75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/63dacb46bf939521bdc93981b4cbb7ecb58427a0.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/nix/sources.nix b/nix/sources.nix index 1938409..fe3dadf 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -10,29 +10,50 @@ let let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; fetch_tarball = pkgs: name: spec: let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; fetch_git = name: spec: let ref = - if spec ? ref then spec.ref else + spec.ref or ( if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); fetch_local = spec: spec.path; @@ -66,16 +87,16 @@ let hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = == ./.; in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: @@ -95,13 +116,13 @@ let # the path directly as opposed to the fetched source. replace = name: drv: let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions @@ -112,7 +133,7 @@ let ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); @@ -123,43 +144,46 @@ let concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; + optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix builtins_fetchTarball = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix builtins_fetchurl = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; # The "config" used by the fetchers mkConfig = { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) , system ? builtins.currentSystem , pkgs ? mkPkgs sources system }: rec { @@ -171,4 +195,4 @@ let }; in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } From 10cca449b332be9dbb1438ccab50fa513d63f220 Mon Sep 17 00:00:00 2001 From: Jeremy Nuttall Date: Sun, 23 Jun 2024 15:42:10 -0500 Subject: [PATCH 4/4] Expose Vulkan dynamic rendering (#205) * expose useDynamicRendering * add color attachment format --- examples/vulkan/Main.hs | 14 +++++++------ src/DearImGui/Vulkan.hs | 38 +++++++++++++++++++++-------------- src/DearImGui/Vulkan/Types.hs | 1 + 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/examples/vulkan/Main.hs b/examples/vulkan/Main.hs index 6c0ffd6..47e3a8f 100644 --- a/examples/vulkan/Main.hs +++ b/examples/vulkan/Main.hs @@ -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" diff --git a/src/DearImGui/Vulkan.hs b/src/DearImGui/Vulkan.hs index 3c63cb6..8a8b9f9 100644 --- a/src/DearImGui/Vulkan.hs +++ b/src/DearImGui/Vulkan.hs @@ -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 @@ -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@. @@ -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 -> @@ -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 ) diff --git a/src/DearImGui/Vulkan/Types.hs b/src/DearImGui/Vulkan/Types.hs index 3200d9d..930a1d9 100644 --- a/src/DearImGui/Vulkan/Types.hs +++ b/src/DearImGui/Vulkan/Types.hs @@ -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