Top Related Projects
One stop solution for all Vulkan samples
C++ examples for the Vulkan graphics API
Ray tracing examples and tutorials using VK_KHR_ray_tracing
A beginner-friendly Vulkan path tracing tutorial in under 300 lines of C++.
Quick Overview
LunarG/VulkanSamples is a GitHub repository containing sample applications and code for the Vulkan graphics API. It provides developers with practical examples and best practices for implementing various Vulkan features, serving as a valuable resource for learning and understanding Vulkan development.
Pros
- Comprehensive collection of Vulkan samples covering a wide range of features and techniques
- Well-documented code with explanatory comments, making it easier for developers to understand and learn
- Regularly updated to incorporate new Vulkan features and best practices
- Supported by LunarG, a respected company in the Vulkan ecosystem
Cons
- May be overwhelming for beginners due to the complexity of Vulkan itself
- Some samples might require specific hardware or driver support
- Limited to C++ implementations, which may not be ideal for developers using other languages
- Requires a good understanding of graphics programming concepts
Code Examples
- Initializing a Vulkan instance:
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Hello Triangle";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.apiVersion = VK_API_VERSION_1_0;
VkInstanceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
VkInstance instance;
vkCreateInstance(&createInfo, nullptr, &instance);
- Creating a Vulkan device:
float queuePriority = 1.0f;
VkDeviceQueueCreateInfo queueCreateInfo = {};
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queueCreateInfo.queueFamilyIndex = queueFamily;
queueCreateInfo.queueCount = 1;
queueCreateInfo.pQueuePriorities = &queuePriority;
VkPhysicalDeviceFeatures deviceFeatures = {};
VkDeviceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
createInfo.pQueueCreateInfos = &queueCreateInfo;
createInfo.queueCreateInfoCount = 1;
createInfo.pEnabledFeatures = &deviceFeatures;
VkDevice device;
vkCreateDevice(physicalDevice, &createInfo, nullptr, &device);
- Creating a Vulkan command buffer:
VkCommandBufferAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = commandPool;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandBufferCount = 1;
VkCommandBuffer commandBuffer;
vkAllocateCommandBuffers(device, &allocInfo, &commandBuffer);
Getting Started
-
Clone the repository:
git clone https://github.com/LunarG/VulkanSamples.git
-
Install the Vulkan SDK from the official website.
-
Build the samples using CMake:
cd VulkanSamples mkdir build && cd build cmake .. cmake --build .
-
Run a sample application:
./samples/triangle
Competitor Comparisons
One stop solution for all Vulkan samples
Pros of Vulkan-Samples
- More comprehensive and up-to-date collection of Vulkan samples
- Better documentation and explanations for each sample
- Actively maintained by the Khronos Group, ensuring alignment with the latest Vulkan standards
Cons of Vulkan-Samples
- Larger repository size, which may be overwhelming for beginners
- More complex build system and dependencies
- Some samples may be too advanced for newcomers to Vulkan
Code Comparison
VulkanSamples (basic triangle rendering):
void initVulkan() {
createInstance();
setupDebugMessenger();
createSurface();
pickPhysicalDevice();
createLogicalDevice();
createSwapChain();
}
Vulkan-Samples (basic triangle rendering):
void VulkanSample::prepare(vkb::Platform& platform)
{
auto& config = platform.get_configuration();
config.insert<vkb::IntSetting>(0, "sample_number", 0);
config.insert<vkb::BoolSetting>(1, "enable_validation_layers", true);
VulkanSample::prepare(platform);
}
The Vulkan-Samples code demonstrates a more structured approach with additional configuration options, while VulkanSamples provides a simpler, more straightforward implementation.
C++ examples for the Vulkan graphics API
Pros of Vulkan
- More extensive collection of samples covering a wider range of Vulkan features
- Regularly updated with new samples and improvements
- Includes advanced rendering techniques and compute shader examples
Cons of Vulkan
- May be more complex for beginners due to its comprehensive nature
- Requires additional setup steps and dependencies
- Larger repository size due to the extensive collection of samples
Code Comparison
Vulkan sample initialization:
void VulkanExample::prepare()
{
VulkanExampleBase::prepare();
loadAssets();
prepareUniformBuffers();
setupDescriptorSetLayout();
preparePipelines();
setupDescriptorPool();
setupDescriptorSet();
buildCommandBuffers();
prepared = true;
}
VulkanSamples initialization:
void Sample::prepare(vk::Device &device)
{
initSwapchain(device);
initDepthBuffer();
initUniformBuffer();
initDescriptorAndPipelineLayouts();
initRenderPass();
initPipelines();
initFramebuffers();
initVertexBuffers();
initDescriptorPool();
initDescriptorSet();
buildCmdBuffer();
}
Both repositories provide valuable resources for learning Vulkan, with VulkanSamples offering a more focused approach and Vulkan providing a broader range of examples. The choice between them depends on the user's experience level and specific learning goals.
Ray tracing examples and tutorials using VK_KHR_ray_tracing
Pros of vk_raytracing_tutorial_KHR
- Focuses specifically on ray tracing, providing in-depth examples and tutorials
- Utilizes the latest Vulkan ray tracing extensions (KHR)
- Includes more advanced rendering techniques and optimizations
Cons of vk_raytracing_tutorial_KHR
- Limited scope compared to VulkanSamples, which covers a broader range of Vulkan features
- May be more challenging for beginners due to its focus on advanced ray tracing concepts
- Less frequently updated than VulkanSamples
Code Comparison
VulkanSamples (basic triangle rendering):
void draw() {
vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, VK_SUBPASS_CONTENTS_INLINE);
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphics_pipeline);
vkCmdDraw(command_buffer, 3, 1, 0, 0);
vkCmdEndRenderPass(command_buffer);
}
vk_raytracing_tutorial_KHR (ray tracing pipeline setup):
void createRtPipeline() {
VkRayTracingPipelineCreateInfoKHR rayPipelineInfo{};
rayPipelineInfo.sType = VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR;
rayPipelineInfo.stageCount = static_cast<uint32_t>(stages.size());
rayPipelineInfo.pStages = stages.data();
vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayPipelineInfo, nullptr, &rtPipeline);
}
A beginner-friendly Vulkan path tracing tutorial in under 300 lines of C++.
Pros of vk_mini_path_tracer
- Focuses specifically on path tracing, providing a more specialized and in-depth example for this technique
- Includes NVIDIA-specific optimizations, potentially offering better performance on NVIDIA hardware
- Offers a compact, single-file implementation, making it easier to understand the entire pipeline
Cons of vk_mini_path_tracer
- Less comprehensive in covering general Vulkan concepts compared to VulkanSamples
- May not be as portable or vendor-neutral as VulkanSamples
- Limited to path tracing, while VulkanSamples covers a broader range of graphics techniques
Code Comparison
VulkanSamples (initialization):
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Vulkan Sample";
appInfo.applicationVersion = 1;
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = 1;
appInfo.apiVersion = VK_API_VERSION_1_0;
vk_mini_path_tracer (initialization):
VkApplicationInfo app_info{VK_STRUCTURE_TYPE_APPLICATION_INFO};
app_info.pApplicationName = "vk_mini_path_tracer";
app_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1);
app_info.pEngineName = "vk_mini_path_tracer";
app_info.engineVersion = VK_MAKE_VERSION(0, 0, 1);
app_info.apiVersion = VK_API_VERSION_1_2;
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Vulkan Samples
- This repository is a collection of Vulkan C++ sample applications.
- These samples were developed in the early days of Vulkan and are no longer enhanced or maintained. Refer to the KhronosGroup/Vulkan-Samples repository for newer samples that are enhanced and maintained.
- Run the following script to obtain a short description of all or a
specific sample:
$ API-Samples/get-short-descripts.sh
- Run the following script to obtain a more detailed description of all
samples with a long description set:
$ API-Samples/get-descripts.sh
CI Build Status
Platform | Build Status |
---|---|
Linux/Android | |
Windows |
Structure
Vulkan Samples
- The Vulkan Samples repo is a set of source and data files in a specific
directory hierarchy:
- API-Samples - Samples that demonstrate the use of various aspects of the Vulkan API
- Vulkan Tutorial - Steps you through the process of creating a simple Vulkan application, learning the basics along the way. This Vulkan Tutorial link allows you to view the Vulkan Tutorial on LunarXchange as well.
- Sample-Programs - Samples that are more functional and go deeper than simple API use.
Sample progression
- In general, the samples are not interrelated, but there is a progression among some of the samples that lead to drawing a cube. Start with the instance sample, then enumerate-adv, device, initcommandbuffer, initswapchain, initdepthbuffer, inituniformbuffer, descriptor_pipeline_layouts, initrenderpass, initshaders, initframebuffers, vertexbuffer, allocdescriptorsets, initpipeline, and they culminate in the drawcube sample. Each sample uses utility routines from the code from previous samples to get to the point to show something new. The drawtexturedcube sample takes all of the drawcube code and adds texturing.
Contributing
Refer to the README.contrib file for specific info regarding contributing to the Vulkan samples creation effort.
Contact Information
Information for Developing or Contributing:
Please see the CONTRIBUTING.md file in this repository for more details.
How to Build and Run
BUILD.md Includes directions for building all components as well as running validation tests and demo applications.
Version Tagging Scheme
Updates to the LunarG-VulkanSamples
repository which correspond to a new Vulkan specification release are tagged using the following format: v<
version
>
(e.g., v1.1.96
).
Note: Marked version releases have undergone thorough testing but do not imply the same quality level as SDK tags. SDK tags follow the sdk-<
version
>.<
patch
>
format (e.g., sdk-1.1.92.0
).
This scheme was adopted following the 1.1.96 Vulkan specification release.
License
This work is released as open source under a Apache-style license. See LICENSE.txt for full license.
See COPYRIGHT.txt for a full list of licenses used in this repository.
Acknowledgements
While this project has been developed primarily by LunarG, Inc., there are many other companies and individuals making this possible: Valve Corporation, funding project development; Google providing significant contributions to the samples.
Top Related Projects
One stop solution for all Vulkan samples
C++ examples for the Vulkan graphics API
Ray tracing examples and tutorials using VK_KHR_ray_tracing
A beginner-friendly Vulkan path tracing tutorial in under 300 lines of C++.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot