Skip to content

udemegane/vk_mini_samples

 
 

Repository files navigation

Vulkan Samples

This repository holds many samples, showing various aspect of Vulkan, debugging tips and usage of other Nvidia tools. It has a dependency on nvpro_core for some core Vulkan helper classes and other small utilities. All projects are using GLFW and Dear ImGui

Each sample have its own documentation written in Markdown describing what was done and where to get more information.

Build

Easy Method (Windows)

Clone this repository

git clone https://github.com/nvpro-samples/vk_mini_samples.git
  1. Deploy.bat : pull and update all dependencies.
  2. Build.bat : build all projects in release and optionally to debug.
  3. Install.bat : copy the binaries and dlls to the _Install directory.

Hand Made

git clone --recursive --shallow-submodules https://github.com/nvpro-samples/nvpro_core.git
git clone https://github.com/nvpro-samples/vk_mini_samples.git

Generate solution

cd vk_mini_samples
mkdir build
cd build
cmake ..

Note: If there are missing dependencies in nvpro_core, run the following command in nvpro_core directory.

git submodule update --init --recursive --checkout --force

HLSL or SLANG

The samples can use two other shading languages besides GLSL, HLSL and SLANG. To switch between them, select one of option: USE_HLSL or USE_SLANG. Then regenerate CMake and the solution will be updated with compatible projects and their shaders.

img

Extra SDK

Some samples depend on other SDKs. They are only required if you intend to build these projects.

Samples

Application Class

The examples uses many helper from nvpro_core: https://github.com/nvpro-samples/nvpro_core repository. The core of each sample uses the Application class to create a window, initialize the UI, and create a swapchain with the ImGui framework. The Application class is a modified version of the Dear ImGui Vulkan example.

Samples are attached to the Application class as Engines. While the application is running, the sample will be called to render its UI or to perform rendering operations in the current frame.

Init

The init() function will create the Vulkan context using nvvk::Context, create the GLFW window and create the swapchains by calling ImGui_ImplVulkanH_CreateOrResizeWindow.

Run

The run() function is an infinite loop until the close event is triggered. Within the loop, each engine will be called with:

  • onResize : Called when the viewport size is changing
  • onUIRender : Called for anything related to UI
  • onRender : For anything to render within a frame, with the command buffer of the frame.
  • onUIMenu : To add functions to the menubar

At the end of each loop the frame is rendered with frameRender() then the frame is presented with framePresent().

Samples

If you are new to this repository, the first samples to read to better understand the framwork are solid color and rectangle.

Name Description Image
solid_color Set a user custom color to a pixel wide texture and display it.
rectangle Render a 2D rectangle to GBuffer.
aftermath Integrate the Nsight Aftermath SDK to an existing application
image_ktx Display KTX image and apply tonemap post processing
image_viewer Load an image, allow to zoom and pan under mouse cursor
mm_displacement Micro-mesh displacement
mm_opacity Micromap opacity
msaa Hardware Multi-Sampling Anti-Aliasing
shader_printf Add printf to shader and display in a log window
ray_trace Simple ray tracer using metalic-roughness shading, reflection and shadows and simple sky shader.
shading execution reorder Known also as SER, this shows how to reorder execution rays to gain a better usage of the GPU.
simple_polygons Rasterizing multiple polygonal objects.
offscreen Render without window context and save image to disk.
tiny_shader_toy Compile shader on the fly, diplay compilation errors, multiple pipeline stages.
barycentric_wireframe Draw wifreframe in a a single pass using gl_BaryCoordNV
texture 3d Create a 3D texture and do ray marching.
position fetch Using VK_KHR_ray_tracing_position_fetch.
ray_query Doing inline raytracing in a compute shader

HLSL

The two main shading languages that are used with Vulkan are:

  • GLSL (OpenGL Shading Language)
  • HLSL (High Level Shading Language)

Both GLSL and HLSL are supported by the samples. To switch between then, open CMake and under USE, toggle the USE_HLSL.

Note: it is also possible to use a different dxc binary. By default, it uses the one coming with the Vulkan SDK, but there is the option to use the one of your choice. Open Vulkan and change the path to Vulkan_dxc_EXECUTABLE. If you do not see Vulkan, make sure the Advanced option is selected.

Note: To compile all samples with dxc, the Preview Release for June 2023 is needed.

Feature GLSL HLSL
Ease of use Easier to learn More difficult to learn
Feature set Less powerful More powerful
Support More widely supported Less widely supported

Resources:

Spir-V intrinsics

Releases:

Slang

Some samples have also been converted to use Slang. When configurating CMake, it should download automatically one of the release. To change the version of the Slang compiler, select the path to SLANG_EXE in CMake.

To use Slang, check USE_SLANG then re-configure and re-generate.

Resources

LICENSE

Copyright 2023 NVIDIA CORPORATION. Released under Apache License, Version 2.0. See "LICENSE" file for details.

About

Collection of Vulkan samples

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HLSL 31.0%
  • CMake 29.5%
  • C++ 28.4%
  • Python 8.7%
  • Batchfile 2.4%