Home

Awesome

Vulkan Samples

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.

Dependencies

Build Instructions

Cloning Repositories

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

Generating Solution

cd vk_mini_samples
mkdir build
cd build
cmake ..

Additional SDKs

The Aftermath sample requires the separate download of the Nsight Aftermath SDK.

Shader Language Options: GLSL, HLSL, or SLANG

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.

Shader Language Selection

Samples

For those new to this repository, the solid color and rectangle samples are recommended starting points to better understand the framework.

NameDescriptionImageGLSLHLSLSlang
barycentric_wireframeSingle-pass solid-wireframe rendering using gl_BaryCoordNV[x][x][x]
compute_multi_threadedExecuting a compute shader in a separate thread faster than the main thread.[x][x][x]
compute_onlyBasic compute and display example[x][x][x]
crash_aftermathIntegration of Nsight Aftermath SDK into an existing application[x][x][x]
gltf_raytraceglTF scene loading with path-tracing renderer[x][x][x]
gpu_monitorGPU usage visualization[x][x][x]
image_ktxKTX image display with tonemapping post-processing[x][x][x]
image_viewerImage loading with zoom and pan functionality[x][x][x]
line_stippleDashed line rendering with stipple pattern[x][x][x]
memory_budgetDynamic memory allocation within budget constraints[x][x][x]
mm_displacementMicro-mesh displacement techniques[x][x][x]
mm_opacityMicromap opacity implementation[x][x][x]
msaaHardware Multi-Sampling Anti-Aliasing demonstration[x][x][x]
offscreenWindowless rendering with image save functionality.[x][x][x]
ray_queryInline raytracing in compute shaders[x][x][x]
ray_query_position_fetchUsing VK_KHR_ray_tracing_position_fetch usage in ray query[x][ ][x]
ray_traceBasic ray tracer with metallic-roughness shading, reflections, shadows, and sky shader.[x][x][x]
ray_trace_motion_blurMotion blur for dynamic objects using NVIDIA raytracing extension[x][ ][x]
ray_tracing_position_fetchVK_KHR_ray_tracing_position_fetch implementation.[x][ ][x]
realtime_analysisReal-time GPU information display[x][ ][x]
rectangle2D rectangle rendering to GBuffer.[x][x][x]
ser_pathtraceShading Execution Reordering (SER) for optimized GPU usage.[x][x][x]
shader_objectShader object and dynamic pipeline usage[x][x][x]
shader_printfShader debugging with printf functionality[x][x][x]
simple_polygonsMulti-polygon object rasterization.[x][x][x]
solid_colorSingle-pixel texture creation and display.[x][x][x]
texture 3d3D texture creation and ray marching.[x][x][x]
tiny_shader_toyReal-time shader compilation with error display and multi-stage pipelines.[x][ ][ ]

Rendering Architecture

Those samples demonstrates an indirect rendering approach, diverging from direct swapchain image rendering. The rendering pipeline is structured as follows:

  1. Off-screen Rendering: The sample renders its content to an off-screen image buffer rather than directly to the swapchain image.
  2. GUI Integration: The rendered off-screen image is incorporated as an element within the GUI layout.
  3. 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.
  4. Swapchain Presentation: The composite result from step 3 is then rendered to the swapchain image for final presentation.

This architecture provides several advantages:

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.

Application Architecture

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:

The Application class is an enhanced derivative of the Dear ImGui Vulkan example, optimized for our use cases.

Modular Design

Samples are implemented as Elements and attached to the Application instance. This modular approach allows for:

  1. Separation of concerns between core application logic and sample-specific code
  2. Consistent handling of UI rendering and frame operations across different samples

Initialization Process

The init() method orchestrates the following setup procedures:

  1. GLFW window initialization
  2. Swapchain setup through ImplVulkanH_CreateOrResizeWindow

Execution Cycle

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:

  1. onResize: Handles viewport dimension changes
  2. onUIMenu: Facilitates additions to the menu bar
  3. onUIRender: Manages UI-related rendering tasks
  4. onRender: Executes sample-specific rendering operations within the current frame's command buffer

Post-element processing, each frame concludes with:

This architecture provides a robust and flexible framework for implementing diverse Vulkan-based graphical samples while maintaining a consistent application structure.

application-loop

Shader Language Support

SPIR-V Intermediate Representation

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.

Configuration Options

The samples in this repository are designed to accommodate multiple shader languages. Language selection is controlled via CMake options:

Supported Languages

Slang

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:

To specify a custom Slang compiler version, modify the Slang_VERSION CMakeLists.txt.

HLSL (High Level Shading Language)

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 (Default)

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.

Resources

HLSL

SLANG

SPIR-V Intrinsics

LICENSE

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