Git Product home page Git Product logo

vk_mini_samples's Introduction

Vulkan Samples

This repository contains many examples showing different aspects of Vulkan, debugging tips, and using other Nvidia tools. See the samples section below.

Each sample has its own documentation that describes the functionality and where to get more information.

Dependencies

  • nvpro_core : Vulkan helper classes and other small utilities.

Build

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

Generate solution

cd vk_mini_samples
mkdir build
cd build
cmake ..

Extra SDK

The Aftermath sample requires to download the SDK separately: Nsight Aftermath SDK

GLSL, HLSL or SLANG

By default, the samples are created using GLSL. However, many of them also have equivalent shaders written in HLSL and SLANG. To switch between them, select either USE_HLSL or USE_SLANG. Afterward, regenerate CMake and the solution will update with compatible projects and their respective shaders.

img

Samples

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

Name Description Image GLSL HLSL Slang
solid_color Set a user custom color to a pixel wide texture and display it. [x] [x] [x]
rectangle Render a 2D rectangle to GBuffer. [x] [x] [x]
aftermath Integrate the Nsight Aftermath SDK to an existing application [x] [x] [ ]
image_ktx Display KTX image and apply tonemap post processing [x] [x] [x]
image_viewer Load an image, allow to zoom and pan under mouse cursor [x] [x] [x]
mm_displacement Micro-mesh displacement [x] [x] [x]
mm_opacity Micromap opacity [x] [x] [x]
msaa Hardware Multi-Sampling Anti-Aliasing [x] [x] [x]
shader_printf Add printf to shader and display in a log window [x] [x] [x]
ray_trace Simple ray tracer using metalic-roughness shading, reflection and shadows and simple sky shader. [x] [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] [x]
simple_polygons Rasterizing multiple polygonal objects. [x] [x] [x]
offscreen Render without window context and save image to disk. [x] [x] [x]
tiny_shader_toy Compile shader on the fly, diplay compilation errors, multiple pipeline stages. [x] [ ] [ ]
barycentric_wireframe Draw wifreframe in a a single pass using gl_BaryCoordNV [x] [x] [x]
texture 3d Create a 3D texture and do ray marching. [x] [x] [x]
position fetch Using VK_KHR_ray_tracing_position_fetch. [x] [ ] [x]
ray_query Doing inline raytracing in a compute shader [x] [x] [x]
ray_query_position_fetch Using VK_KHR_ray_tracing_position_fetch in ray quary [x] [ ] [x]
shader_object Using shader object and dynamic pipline [x] [x] [x]
compute_only Simple compute and display example [x] [x] [x]
gpu_monitor Showing GPU usage [x] [x] [x]
realtime_analysis Displaying in realtime GPU informations [x] [ ] [x]
motion_blur Tracing object having motion, using the NVIDIA raytrace extension [x] [ ] [x]

Application Class

The examples utilize many helpers from the nvpro_core repository. Each sample's core 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 (in order) with:

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

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

application-loop

Shader Languages

Instead of directly consuming shaders in a human-readable text format, Vulkan uses SPIR-V as an intermediate representation. This allows the use of shader languages other than GLSL as long as they can target the Vulkan SPIR-V environment.

The samples can use any of the shader languages, and the CMake option is : USE_SLANG our USE_HLSL. Only one of the two can be true and if both are false, it default to using GLSL.

Slang

Slang is a high-level based shader language, similar to C++. It is one of the primary language used by researchers at NVIDIA, as it can generate not only Spir-V, but also DX12, CUDA, CPP.

Note: To change the version of the Slang compiler, select the path to SLANG_COMPILER in CMake.

HLSL

Microsoft's High Level Shading Language (HLSL), used by DirectX, can generate Spir-V code. The DXC compiler comes by default with recent Vulkan SDK.

Note: To use a different dxc binary, open Vulkan and change the path to Vulkan_dxc_EXECUTABLE.

Resources:

HLSL

SLANG

Spir-V intrinsics

LICENSE

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

vk_mini_samples's People

Contributors

mklefrancois avatar nvmheyer avatar iesser avatar nbickford-nv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.