├── LICENSE ├── Setup.hs ├── default.nix ├── readme.md ├── shell.nix ├── src └── Main.hs ├── stack.yaml └── vulkan-examples.cabal /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Joe Hermaszewski (c) 2016 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of Joe Hermaszewski nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: 2 | 3 | pkgs.haskell.lib.disableSharedExecutables 4 | (pkgs.haskellPackages.callCabal2nix "vulkan-examples" ./. {}) 5 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # *These examples have moved to the [vulkan repo](https://github.com/expipiplus1/vulkan)* 2 | 3 | 4 | # vulkan-examples 5 | 6 | Some examples for using the 7 | [vulkan](https://hackage.haskell.org/package/vulkan) bindings. 8 | 9 | At the moment it just creates and destroys a Vulkan instance; it'll print '0' 10 | to the terminal if there were no problems. 11 | 12 | ## Building 13 | 14 | This requires GHC 8. 15 | 16 | I've included a couple of `.nix` files to set up this environment. There's no 17 | Nix package for Vulkan at the moment, so you'll have to do a couple of really 18 | horrible things to get this to build. These are the steps on my Linux machine 19 | (having installed the LunarG SDK and vulkan driver) 20 | 21 | nix-shell 22 | cabal configure --extra-lib-dirs=/usr/lib/x86_64-linux-gnu 23 | cabal build 24 | LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu ./dist/build/vulkan-example/vulkan-example 25 | 26 | The `vulkan` package currently takes ages and ages to build without -O0, so you 27 | might want to specify that too. 28 | 29 | ### Building on Ubuntu with Stack 30 | 31 | Note, you need modern drivers to support vulkan api, 32 | e.g. `nvidia-367` that is available at `ppa:graphics-drivers/ppa` currently. 33 | If your drivers are ok, install `libvulkan-dev` and run examples using `stack`: 34 | ```bash 35 | sudo apt-get install libvulkan-dev 36 | # run this from a folder containing cloned vulkan-examples 37 | stack setup 38 | stack install 39 | ``` 40 | 41 | ## Contributing 42 | 43 | It would be awesome if you could try and get this to work on your system and 44 | raise an issue (or if you're amazing a pull request) if it doesn't work for 45 | you. 46 | 47 | I can be reached by email or as `jophish` on Freenode. 48 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: 2 | 3 | (import ./default.nix { inherit pkgs; }).env 4 | -------------------------------------------------------------------------------- /src/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DuplicateRecordFields #-} 2 | {-# LANGUAGE PatternSynonyms #-} 3 | 4 | module Main where 5 | 6 | import Data.Bits 7 | import Foreign.C.String 8 | import Foreign.Marshal.Alloc 9 | import Foreign.Marshal.Array 10 | import Foreign.Marshal.Utils 11 | import Foreign.Ptr 12 | import Foreign.Storable 13 | import Graphics.Vulkan 14 | 15 | main :: IO () 16 | main = do 17 | vulkanInstance <- createInstance 18 | destroyInstance vulkanInstance 19 | 20 | createInstance = withCString "vulkan-example" $ \namePtr -> 21 | with VkApplicationInfo 22 | { vkSType = VK_STRUCTURE_TYPE_APPLICATION_INFO 23 | , vkPNext = nullPtr 24 | , vkPApplicationName = namePtr 25 | , vkApplicationVersion = 1 26 | , vkPEngineName = namePtr 27 | , vkEngineVersion = 0 28 | , vkApiVersion = VK_MAKE_VERSION 1 0 0 29 | } 30 | $ \appInfo -> 31 | with VkInstanceCreateInfo 32 | { vkSType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO 33 | , vkPNext = nullPtr -- castPtr debugInfo 34 | , vkFlags = VkInstanceCreateFlags zeroBits 35 | , vkPApplicationInfo = appInfo 36 | , vkEnabledLayerCount = 0 37 | , vkPPEnabledLayerNames = nullPtr 38 | , vkEnabledExtensionCount = 0 39 | , vkPPEnabledExtensionNames = nullPtr 40 | } 41 | $ \instInfo -> alloca $ \instPtr -> do 42 | err <- vkCreateInstance instInfo nullPtr instPtr 43 | print err 44 | peek instPtr 45 | 46 | destroyInstance inst = vkDestroyInstance inst nullPtr 47 | -------------------------------------------------------------------------------- /stack.yaml: -------------------------------------------------------------------------------- 1 | flags: {} 2 | packages: 3 | - '.' 4 | - location: 5 | git: https://github.com/expipiplus1/vulkan.git 6 | commit: c3006c1d913fc409340b99a6ecfbcb75a1b16296 7 | extra-dep: true 8 | extra-deps: 9 | - primitive-0.6.1.0 10 | - vector-0.11.0.0 11 | - vector-sized-0.3.2.0 12 | 13 | resolver: ghc-8.0.1 14 | -------------------------------------------------------------------------------- /vulkan-examples.cabal: -------------------------------------------------------------------------------- 1 | name: vulkan-examples 2 | version: 0.2.1.0 3 | synopsis: Examples using the vulkan package 4 | description: Please see README.md 5 | homepage: http://github.com/expipiplus1/vulkan-examples#readme 6 | license: BSD3 7 | license-file: LICENSE 8 | author: Joe Hermaszewski 9 | maintainer: haskell@monoid.al 10 | copyright: 2016 Joe Hermaszewski 11 | category: Graphics 12 | build-type: Simple 13 | -- extra-source-files: 14 | cabal-version: >=1.10 15 | 16 | executable vulkan-example 17 | hs-source-dirs: src 18 | main-is: Main.hs 19 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 20 | build-depends: base 21 | , vulkan >= 2.0 22 | default-language: Haskell2010 23 | 24 | source-repository head 25 | type: git 26 | location: https://github.com/expipiplus1/vulkan-examples 27 | --------------------------------------------------------------------------------