Code Monkey home page Code Monkey logo

vulkan_minimal_compute's Introduction

Vulkan Minimal Compute

This is a simple demo that demonstrates how to use Vulkan for compute operations only. In other words, this demo does nothing related to graphics, and only uses Vulkan to execute some computation on the GPU. For this demo, Vulkan is used to render the Mandelbrot set on the GPU. The demo is very simple, and is only ~400LOC. The code is heavily commented, so it should be useful for people interested in learning Vulkan.

The only depdendencies are Vulkan and lodepng. lodepng is simply used for png encoding. Vulkan can be installed from lunarg.com

Demo

The application launches a compute shader that renders the mandelbrot set, by rendering it into a storage buffer. The storage buffer is then read from the GPU, and saved as .png. Check the source code comments for further info.

Building

The project uses CMake, and all dependencies are included, so you should use CMake to generate a "Visual Studio Solution"/makefile, and then use that to compile the program. If you then run the program, a file named mandelbrot.png should be created. This is a Mandelbrot set that has been rendered by using Vulkan.

vulkan_minimal_compute's People

Contributors

1ace avatar erkaman avatar ristovski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vulkan_minimal_compute's Issues

Cosmetic issue with the mandelbrot set definition

Mandelbrot set is usually rendered with 2 set as a divergence threshold, the example shader in the repo actually uses sqrt(2) -- what comes from the vector dot-product is a squared distance. Suggest this fix to prevent naming confusion:

diff --git a/shaders/shader.comp b/shaders/shader.comp
index a03f4a0..ca26283 100644
--- a/shaders/shader.comp
+++ b/shaders/shader.comp
@@ -38,7 +38,7 @@ void main() {
   for (int i = 0; i<M; i++)
   {
     z = vec2(z.x*z.x - z.y*z.y, 2.*z.x*z.y) + c;
-    if (dot(z, z) > 2) break;
+    if (dot(z, z) > 4) break;
     n++;
   }

As a result, the image becomes slightly neater.

Anyway, thanks a lot for packing the compute stuff in one repo, this has saved me a day of documentation crunching.

Creating commandbuffer is failing

priyesh@priyesh-Blade:~/Downloads/vulkan_minimal_compute-master$ ./vulkan_minimal_compute
Fatal : VkResult is -2 in /home/priyesh/Downloads/vulkan_minimal_compute-master/src/main.cpp at line 485
vulkan_minimal_compute: /home/priyesh/Downloads/vulkan_minimal_compute-master/src/main.cpp:485: void ComputeApplication::createBuffer(): Assertion `res == VK_SUCCESS' failed.
Aborted (core dumped)

Creating buffer seems to fail on my end. Any clue what might be causing this?

Layer VK_LAYER_LUNARG_standard_validation not supported

I can build the binary, but it fails to run for me:

$ ./vulkan_minimal_compute 
Layer VK_LAYER_LUNARG_standard_validation not supported

I have validation layers Ubuntu package installed:

bram@deca:~/src/vulkan_minimal_compute/build$ ./vulkan_minimal_compute 
Layer VK_LAYER_LUNARG_standard_validation not supported

bram@deca:~/src/vulkan_minimal_compute/build$ dpkg --list | grep vulkan
ii  libvulkan-dev:amd64                        1.3.204.1-2                             amd64        Vulkan loader library -- development files
ii  libvulkan1:amd64                           1.3.204.1-2                             amd64        Vulkan loader library
ii  mesa-vulkan-drivers:amd64                  22.0.1-1ubuntu2                         amd64        Mesa Vulkan graphics drivers
ii  vulkan-tools                               1.3.204.0+dfsg1-1                       amd64        Miscellaneous Vulkan utilities
ii  vulkan-validationlayers:amd64              1.3.204.1-2                             amd64        Vulkan validation layers
ii  vulkan-validationlayers-dev:amd64          1.3.204.1-2                             amd64        Vulkan validation layers -- development files

Is this issue caused by the fact that I use Integrated Graphics (Alderlake?)

I notice that the vulkaninfo tool does show an alternate validation layer called VK_LAYER_KHRONOS_validation instead of VK_LAYER_LUNARG_standard_validation.

Layers: count = 3
=================
VK_LAYER_KHRONOS_validation (Khronos Validation Layer) Vulkan version 1.3.204, layer version 1:
        Layer Extensions: count = 3
                VK_EXT_debug_report        : extension revision 9
                VK_EXT_debug_utils         : extension revision 1
                VK_EXT_validation_features : extension revision 2
        Devices: count = 2
                GPU id = 0 (llvmpipe (LLVM 13.0.1, 256 bits))
                Layer-Device Extensions: count = 3
                        VK_EXT_debug_marker     : extension revision 4
                        VK_EXT_tooling_info     : extension revision 1
                        VK_EXT_validation_cache : extension revision 1

                GPU id = 1 (Intel(R) Graphics (ADL-S GT1))
                Layer-Device Extensions: count = 3
                        VK_EXT_debug_marker     : extension revision 4
                        VK_EXT_tooling_info     : extension revision 1
                        VK_EXT_validation_cache : extension revision 1

VK_LAYER_MESA_device_select (Linux device selection layer) Vulkan version 1.2.73, layer version 1:
        Layer Extensions: count = 0
        Devices: count = 2
                GPU id = 0 (llvmpipe (LLVM 13.0.1, 256 bits))
                Layer-Device Extensions: count = 0

                GPU id = 1 (Intel(R) Graphics (ADL-S GT1))
                Layer-Device Extensions: count = 0

VK_LAYER_MESA_overlay (Mesa Overlay layer) Vulkan version 1.2.199, layer version 1:
        Layer Extensions: count = 0
        Devices: count = 2
                GPU id = 0 (llvmpipe (LLVM 13.0.1, 256 bits))
                Layer-Device Extensions: count = 0

                GPU id = 1 (Intel(R) Graphics (ADL-S GT1))
                Layer-Device Extensions: count = 0

NOTE: vkcube runs fine on this machine.

OS: Ubuntu 22.04

GPU: AlderLake-S GT1

Kernel: 5.18.0-rc6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.