www.xbdev.net
xbdev - software development
Wednesday July 9, 2025
Home | Contact | Support | Vulkan.. Vulkan is doing all the hard work ... | Vulkan Compute Accessing the raw power of the GPU ...
>>
     
 

Vulkan Compute

Accessing the raw power of the GPU ...

 


Vulkan Compute


High-Performance Compute Programming with Vulkan & Compute Shaders.

Vulkan brings the power of modern GPUs to compute, enabling unmatched performance for intensive parallel processing and high-performance computation tasks.

Aim of this text:

• Feed your curiosity and have fun learning about 'compute'
• Master compute programming using the Vulkan API
• Focus on compute (not the graphics)
• Perform compute tasks (without using any graphical output)
• Let about setting up/debugging/workign with compute
• Look at a range of practical compute examples


To help make the practical exercises accessable - they'll be hosted on VulkanLab - so you can view all of the code/setup files- including the output logs/debug information. Easy to download the entire code (including the Visual Studio files) - that you can compile and run the examples on your own machine with little effort.



Compute Examples - Vulkan Compute (Samples C/C++/Visual Studio/Windows)



The compute pipeline is a game changer for accessing the GPU! It means you can perform complex calculations on the GPU using the large number of threads - very easily! You can use the compute power of Vulkan while having nothing to do with graphics!!




Raw Data In/Out - These compute examples are raw in/out - copying to/from the GPU (no francy graphics just raw power!)

  Array with Contant Numbers (On GPU) 346900 bytes Source Code
  Compute Add Array of Numbers 226590 bytes Source Code
  Compute Matrix Multiplication 338130 bytes Source Code



Static Win64 BitBlt Copy Back (not animated) - copy the 'raw' bytes/pixels back to the CPU (array of floats) - and use a windows BitBlt to draw them. Not animated - but lets us draw the raw data on the screen (check any graphical calculations on the GPU).

  Image Loaded and Passed to Compute Manipulation (Raw Bytes) (Win64/BitBlt) 209800 bytes Source Code
  Ray Traced SDF Shapes (Unions) 196900 bytes Source Code
  Ray Tracked SDF Shapes (Unions) + Uniform 566900 bytes Source Code
  Fractal Pattern (Mandelbrot set) 646100 bytes Source Code


Animated Win64 BitBlt Copy Back - copy the 'raw' bytes/pixels back to the CPU (array of floats) - and use a windows BitBlt to draw them. We have a windows reflesh loop - which we call the compute execute on each time - so we can animate the compute (call it again and again with a changing value).

  Animated Metaballs (Win64 BitBlt) 126900 bytes Source Code



Vulkan Compute 'AND' Render Pipeline - Create a 'Vulkan' graphics pipeline (hpp) - and instead of working with 'raw' data - we create a 'VkImage' - which we write to in the compute shader - and pass the handle to the graphics pipeline - we don't need to copy the data back as it's already on the GPU. Piggy back onto the end of the compute code a dirty little 'render' function which initializes a vulkan render pipeline and uses a glfw window. The function takes a 'callback' so it can call the compute update for each render update. It's not pretty - but it was done this way to keep the code simple but also seperate the compute from the graphics. The graphics part can be disabled using a 'ifdef' preprocessor - so you can see which code is getting used for the graphics and which is for the raw compute.

  Animated Metaballs (Vulkan Graphics Pipeline/GLFW) 256900 bytes Source Code


Vulkan Compute 'AND' Render Pipeline - Same as above - but instead of working with an image - we work with instances - e.g., particles - hundreds of thousands of particles - each particle's information is updated on the compute - while the vulkan graphics pipeline is used to render the particles. They're animated - constantly updated in the render loop (compute and graphics output).

  Particles (Vulkan Graphics Pipeline/GLFW) 312600 bytes Source Code







Feel free to get in touch if you notice any issue or bugs - or just want to say hi ;) Happing coding and remember the most important thing - have fun!






Other Related Texts You Might Find Interesting

 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.