• Stars
    star
    184
  • Rank 209,187 (Top 5 %)
  • Language HLSL
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Collection of Vulkan samples

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 HLSL Slang
solid_color Set a user custom color to a pixel wide texture and display it. [x] [x]
rectangle Render a 2D rectangle to GBuffer. [x] [x]
aftermath Integrate the Nsight Aftermath SDK to an existing application [x] [ ]
image_ktx Display KTX image and apply tonemap post processing [x] [x]
image_viewer Load an image, allow to zoom and pan under mouse cursor [x] [x]
mm_displacement Micro-mesh displacement [x] [x]
mm_opacity Micromap opacity [x] [x]
msaa Hardware Multi-Sampling Anti-Aliasing [x] [x]
shader_printf Add printf to shader and display in a log window [x] [x]
ray_trace Simple ray tracer using metalic-roughness shading, reflection and shadows and simple sky shader. [x] [x]
shading execution reorder Known also as SER, this shows how to reorder execution rays to gain a better usage of the GPU. [x] [x]
simple_polygons Rasterizing multiple polygonal objects. [x] [x]
offscreen Render without window context and save image to disk. [x] [x]
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 [ ] [x]
texture 3d Create a 3D texture and do ray marching. [x] [x]
position fetch Using VK_KHR_ray_tracing_position_fetch. [ ] [ ]
ray_query Doing inline raytracing in a compute shader [x] [ ]
ray_query_position_fetch Using VK_KHR_ray_tracing_position_fetch in ray quary [ ] [ ]
shader_object Using shader object and dynamic pipline [x] [x]
compute_only Simple compute and display example [x] [x]

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.

More Repositories

1

vk_raytracing_tutorial_KHR

Ray tracing examples and tutorials using VK_KHR_ray_tracing
C++
1,314
star
2

vk_mini_path_tracer

A beginner-friendly Vulkan path tracing tutorial in under 300 lines of C++.
C++
1,098
star
3

vk_raytrace

Ray tracing glTF scene with Vulkan
C++
533
star
4

gl_occlusion_culling

OpenGL sample for shader-based occlusion culling
C++
517
star
5

nvpro_core

shared source code and resources needed for the samples to run
C++
457
star
6

optix_advanced_samples

C
411
star
7

gl_vk_meshlet_cadscene

This OpenGL/Vulkan sample illustrates the use of "mesh shaders" for rendering CAD models.
C++
345
star
8

gl_ssao

optimized screen-space ambient occlusion, cache-aware hbao
C++
343
star
9

build_all

GO HERE FIRST: nvpro-samples overview
Batchfile
312
star
10

vk_order_independent_transparency

Demonstrates seven different techniques for order-independent transparency in Vulkan.
C++
264
star
11

vk_video_samples

Vulkan video samples
C++
239
star
12

gl_vk_chopper

Simple vulkan rendering example.
C++
202
star
13

vk_raytracing_tutorial_NV

Vulkan ray tracing examples and tutorials using VK_NV_ray_tracing
C++
158
star
14

gl_vk_threaded_cadscene

OpenGL and Vulkan comparison on rendering a CAD scene using various techniques
C++
157
star
15

gl_cadscene_rendertechniques

OpenGL sample on various rendering approaches for typical CAD scenes
C++
151
star
16

gl_commandlist_basic

OpenGL sample for NV_command_list
C++
112
star
17

vk_gltf_renderer

Rendering glTF scenes with ray tracer and raster (Vulkan)
C++
102
star
18

vk_displacement_micromaps

This sample showcases rasterizing and ray tracing displaced NVIDIA Micro-Mesh assets in Vulkan with and without the VK_NV_displacement_micromap extension.
C++
92
star
19

vk_denoise

Denoising a Vulkan ray traced image using OptiX denoiser
C++
88
star
20

gl_vk_bk3dthreaded

Vulkan sample rendering 3D with 'worker-threads'
C++
84
star
21

gl_vk_simple_interop

Display an image created by Vulkan compute shader, with OpenGL
C++
76
star
22

vk_toon_shader

Silhouette and toon shading post-processing with Vulkan
C++
74
star
23

gl_dynamic_lod

GPU classifies how to render millions of particles
C++
71
star
24

nvtt_samples

NVIDIA Texture Tools samples for compression, image processing, and decompression.
C++
64
star
25

gl_vk_supersampled

Vulkan sample showing a high quality super-sampled rendering
C++
63
star
26

optix_prime_baking

Shows how to bake ambient occlusion at mesh vertices using OptiX Prime
45
star
27

vk_compute_mipmaps

Customizable compute shader for fast cache-aware mipmap generation
GLSL
41
star
28

vk_async_resources

Sample showcasing lifetime management and resource transfers in Vulkan
C++
32
star
29

gl_vk_raytrace_interop

Adding ray traced ambient occlusion using Vulkan and OpenGL
C++
30
star
30

vk_timeline_semaphore

Vulkan timeline semaphore + async compute performance sample
GLSL
26
star
31

gl_render_vk_ddisplay

OpenGL sample that renders into a Vulkan direct display
C++
26
star
32

gl_multicast

OpenGL sample for the new GL_NVX_linked_gpu_multicast extension
C++
25
star
33

vk_device_generated_cmds

Vulkan sample on VK_NV_device_generated_commands
C++
25
star
34

shared_external

external libraries, needed for the samples (AntTweakBar; ZLib...)
HTML
17
star
35

vk_offline

Rendering offline using Vulkan without opening a window
C++
13
star
36

glsl_indexed_types_generator

GLSL code generator to aid use of Vulkan's descriptor set indexing
Lua
12
star
37

gl_cuda_simple_interop

Sample showing OpenGL and CUDA interop
C++
11
star
38

vk_memory_decompression

Vulkan Memory Decompression (VK_NV_memory_decompression) sample
C++
10
star
39

vk_streamline

DLSS Super Resolution and DLSS Frame Generation via Streamline
C++
10
star
40

vk_idbuffer_rasterization

Vulkan sample to render efficient per-part IDs in CAD models
C++
8
star
41

gl_path_rendering_CMYK

Example of how to use path rendering; and how to use it with CMYK (using multi-render target)
C++
8
star
42

dx12_present_barrier

This sample demonstrates the usage of the new NvAPI interface to synchronize present calls between windows on the same system as well as on distributed systems.
C++
7
star
43

nvml_enterprise_gpu_check

Shows how to check if a GPU is an Enterprise/Quadro GPU using NVML.
C++
4
star
44

vk_raytrace_displacement

C++
3
star
45

gl_vrs

Variable Rate Shading in OpenGL
C++
3
star
46

third_party_binaries

pre-built libraries for the nvpro-samples framework
C
2
star
47

vk_inherited_viewport

VK_NV_inherited_viewport_scissor and secondary subpass command buffer re-use
C++
2
star
48

vk_ddisplay

Sample to demonstrate multi-GPU rendering and presenting to ddisplays, meaning displays that are not part of the Windows desktop and of which an application takes complete control.
C++
2
star