This repository contains numerous examples demonstrating various aspects of Vulkan, debugging techniques, and integration with other NVIDIA tools. For a comprehensive list, refer to the Samples section below.
Each sample is accompanied by its own documentation detailing functionality and providing references for further information.
- nvpro_core: A collection of Vulkan helper classes and utilities.
git clone --recursive --shallow-submodules https://github.com/nvpro-samples/nvpro_core.git
git clone https://github.com/nvpro-samples/vk_mini_samples.git
cd vk_mini_samples
mkdir build
cd build
cmake ..
The Aftermath sample requires the separate download of the Nsight Aftermath SDK.
By default, samples use GLSL shaders. However, many also offer equivalent shaders in HLSL and SLANG. To switch between them, select the desired shader language and regenerate the CMake configuration. The solution will update accordingly with compatible projects and their respective shaders.
For those new to this repository, the solid color and rectangle samples are recommended starting points to better understand the framework.
Name | Description | Image | GLSL | HLSL | Slang |
---|---|---|---|---|---|
barycentric_wireframe | Single-pass solid-wireframe rendering using gl_BaryCoordNV |
![]() |
[x] | [x] | [x] |
compute_only | Basic compute and display example | ![]() |
[x] | [x] | [x] |
crash_aftermath | Integration of Nsight Aftermath SDK into an existing application | ![]() |
[x] | [x] | [x] |
gltf_raytrace | glTF scene loading with path-tracing renderer | ![]() |
[x] | [x] | [x] |
gpu_monitor | GPU usage visualization | ![]() |
[x] | [x] | [x] |
image_ktx | KTX image display with tonemapping post-processing | ![]() |
[x] | [x] | [x] |
image_viewer | Image loading with zoom and pan functionality | ![]() |
[x] | [x] | [x] |
line_stipple | Dashed line rendering with stipple pattern | ![]() |
[x] | [x] | [x] |
memory_budget | Dynamic memory allocation within budget constraints | ![]() |
[x] | [x] | [x] |
mm_displacement | Micro-mesh displacement techniques | ![]() |
[x] | [x] | [x] |
mm_opacity | Micromap opacity implementation | ![]() |
[x] | [x] | [x] |
msaa | Hardware Multi-Sampling Anti-Aliasing demonstration | ![]() |
[x] | [x] | [x] |
offscreen | Windowless rendering with image save functionality. | ![]() |
[x] | [x] | [x] |
ray_query | Inline raytracing in compute shaders | ![]() |
[x] | [x] | [x] |
ray_query_position_fetch | Using VK_KHR_ray_tracing_position_fetch usage in ray query | ![]() |
[x] | [ ] | [x] |
ray_trace | Basic ray tracer with metallic-roughness shading, reflections, shadows, and sky shader. | ![]() |
[x] | [x] | [x] |
ray_trace_motion_blur | Motion blur for dynamic objects using NVIDIA raytracing extension | ![]() |
[x] | [ ] | [x] |
ray_tracing_position_fetch | VK_KHR_ray_tracing_position_fetch implementation. | ![]() |
[x] | [ ] | [x] |
realtime_analysis | Real-time GPU information display | ![]() |
[x] | [ ] | [x] |
rectangle | 2D rectangle rendering to GBuffer. | ![]() |
[x] | [x] | [x] |
ser_pathtrace | Shading Execution Reordering (SER) for optimized GPU usage. | ![]() |
[x] | [x] | [x] |
shader_object | Shader object and dynamic pipeline usage | ![]() |
[x] | [x] | [x] |
shader_printf | Shader debugging with printf functionality | ![]() |
[x] | [x] | [x] |
simple_polygons | Multi-polygon object rasterization. | ![]() |
[x] | [x] | [x] |
solid_color | Single-pixel texture creation and display. | ![]() |
[x] | [x] | [x] |
texture 3d | 3D texture creation and ray marching. | ![]() |
[x] | [x] | [x] |
tiny_shader_toy | Real-time shader compilation with error display and multi-stage pipelines. | ![]() |
[x] | [ ] | [ ] |
Those samples demonstrates an indirect rendering approach, diverging from direct swapchain image rendering. The rendering pipeline is structured as follows:
- Off-screen Rendering: The sample renders its content to an off-screen image buffer rather than directly to the swapchain image.
- GUI Integration: The rendered off-screen image is incorporated as an element within the GUI layout.
- Composite Rendering: The
nvvkhl::Application
framework manages the final composition step. It combines the GUI elements (including the embedded rendered image) into a unified layout. - Swapchain Presentation: The composite result from step 3 is then rendered to the swapchain image for final presentation.
This architecture provides several advantages:
- Decouples the sample's rendering from the final presentation
- Allows for flexible GUI integration of rendered content
- Facilitates additional post-processing or compositing operations
Developers should note that the actual swapchain image rendering is abstracted away within the nvvkhl::Application
class, providing a clean separation of concerns between sample-specific rendering and final frame composition.
The examples in this repository leverage various utilities from the nvpro_core framework. Central to each sample's implementation is the Application
class, which provides core functionality for:
- Window creation and management
- User interface (UI) initialization
- Swapchain setup integrated with the ImGui framework
The Application
class is an enhanced derivative of the Dear ImGui Vulkan example, optimized for our use cases.
Samples are implemented as Elements
and attached to the Application
instance. This modular approach allows for:
- Separation of concerns between core application logic and sample-specific code
- Consistent handling of UI rendering and frame operations across different samples
The init()
method orchestrates the following setup procedures:
- GLFW window initialization
- Swapchain setup through
ImplVulkanH_CreateOrResizeWindow
The run()
method implements the main application loop, continuing until a termination event is triggered. Each iteration of this loop invokes the following methods on attached Elements
, in sequence:
onResize
: Handles viewport dimension changesonUIMenu
: Facilitates additions to the menu baronUIRender
: Manages UI-related rendering tasksonRender
: Executes sample-specific rendering operations within the current frame's command buffer
Post-element processing, each frame concludes with:
frameRender()
: Finalizes the frame's rendering operationsframePresent()
: Submits the completed frame for presentation
This architecture provides a robust and flexible framework for implementing diverse Vulkan-based graphical samples while maintaining a consistent application structure.
Vulkan utilizes SPIR-V as its intermediate shader representation, diverging from the direct consumption of human-readable shader text. This architectural decision enables support for multiple high-level shader languages, provided they can target the Vulkan SPIR-V environment.
The samples in this repository are designed to accommodate multiple shader languages. Language selection is controlled via CMake options:
USE_GLSL
: Enables GLSL shader compilationUSE_SLANG
: Enables Slang shader compilationUSE_HLSL
: Enables HLSL shader compilation
Slang is a high-level shader language with syntax resembling C++. It is extensively used in NVIDIA research due to its versatility in targeting multiple backends:
- SPIR-V (Vulkan)
- DirectX 12
- CUDA
- C++
To specify a custom Slang compiler version, modify the Slang_VERSION
CMakeLists.txt.
Microsoft's HLSL, primarily associated with DirectX, has been extended to support SPIR-V code generation. Recent versions of the Vulkan SDK include the DXC compiler by default, facilitating HLSL to SPIR-V compilation.
To use a non-default dxc
binary, modify the Vulkan_dxc_EXECUTABLE
path in the Vulkan
CMake configuration.
GLSL (OpenGL Shading Language) serves as the default shader language when neither Slang nor HLSL is explicitly enabled. It is natively supported by the Vulkan ecosystem.
This multi-language support strategy offers developers flexibility in shader authoring while maintaining compatibility with Vulkan's SPIR-V requirements.
- HLSL to SPIR-V: Feature Mapping Manual
- Ray Tracing: HLSL
- Porting to HLSL:
- GitHub Repository
- Releases
- Getting Started Guide
- User Guide
- Documentation
- GLSL and SPIR-V Interoperability
Copyright 2024 NVIDIA CORPORATION. Released under Apache License, Version 2.0. See "LICENSE" file for details.