Convert Figma logo to code with AI

Overv logoVulkanTutorial

Tutorial for the Vulkan graphics and compute API

3,128
513
3,128
63

Top Related Projects

One stop solution for all Vulkan samples

10,285

C++ examples for the Vulkan graphics API

Awesome Vulkan ecosystem

Ray tracing examples and tutorials using VK_KHR_ray_tracing

Quick Overview

Overv/VulkanTutorial is a comprehensive guide to learning Vulkan, a modern, low-overhead graphics API. This repository contains a step-by-step tutorial that covers the basics of Vulkan, from setting up a development environment to rendering complex 3D scenes.

Pros

  • Detailed explanations of Vulkan concepts and API usage
  • Incremental approach, building complexity gradually
  • Includes code samples and complete project files
  • Regularly updated to reflect changes in the Vulkan API

Cons

  • May be overwhelming for complete beginners to graphics programming
  • Focuses primarily on C++, which might not be ideal for users of other languages
  • Some advanced topics are not covered in great depth

Code Examples

This is not a code library, but rather a tutorial repository. However, here are a few short code snippets from the tutorial to illustrate key concepts:

  1. Creating a Vulkan instance:
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;

VkResult result = vkCreateInstance(&createInfo, nullptr, &instance);
  1. Setting up a debug messenger:
VkDebugUtilsMessengerCreateInfoEXT createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
createInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
createInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
createInfo.pfnUserCallback = debugCallback;
  1. Creating a shader module:
VkShaderModuleCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
createInfo.codeSize = code.size();
createInfo.pCode = reinterpret_cast<const uint32_t*>(code.data());

VkShaderModule shaderModule;
vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule);

Getting Started

To get started with the Vulkan Tutorial:

  1. Clone the repository: git clone https://github.com/Overv/VulkanTutorial.git
  2. Install the Vulkan SDK from the official website
  3. Set up your development environment (Visual Studio, GCC, or Clang)
  4. Follow the tutorial chapters in order, starting from "Introduction"
  5. Compile and run the example code provided in each chapter

For detailed setup instructions, refer to the "Development environment" section in the repository's README.

Competitor Comparisons

One stop solution for all Vulkan samples

Pros of Vulkan-Samples

  • Comprehensive collection of Vulkan samples covering various advanced topics
  • Officially maintained by Khronos Group, ensuring up-to-date and accurate implementations
  • Includes performance best practices and optimizations for different platforms

Cons of Vulkan-Samples

  • May be overwhelming for beginners due to its extensive coverage of advanced topics
  • Requires more setup and configuration compared to VulkanTutorial
  • Less focused on step-by-step learning, more on demonstrating specific features

Code Comparison

VulkanTutorial:

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";

Vulkan-Samples:

vkb::ApplicationInfo app_info;
app_info.app_name = "Vulkan Sample";
app_info.engine_name = "Vulkan Samples Framework";
app_info.api_version = VK_API_VERSION_1_0;

VulkanTutorial focuses on a more direct approach to Vulkan API usage, while Vulkan-Samples utilizes a framework to simplify some aspects of Vulkan development. The Vulkan-Samples code is more abstracted, potentially making it easier to use but less transparent for learning the raw API.

10,285

C++ examples for the Vulkan graphics API

Pros of Vulkan

  • More comprehensive and advanced examples covering a wider range of Vulkan features
  • Includes performance optimizations and best practices for real-world applications
  • Offers a larger collection of samples, providing a broader learning experience

Cons of Vulkan

  • May be overwhelming for beginners due to its complexity and depth
  • Less structured as a step-by-step tutorial, requiring more self-guided exploration
  • Examples might be more challenging to understand without prior Vulkan knowledge

Code Comparison

VulkanTutorial (Basic triangle rendering):

void drawFrame() {
    vkWaitForFences(device, 1, &inFlightFence, VK_TRUE, UINT64_MAX);
    vkResetFences(device, 1, &inFlightFence);
    vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex);
    // ... (command buffer recording and submission)
}

Vulkan (Advanced rendering with multiple passes):

void buildCommandBuffers() {
    VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
    for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) {
        vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo);
        // ... (multiple render pass setup and drawing commands)
    }
}

Awesome Vulkan ecosystem

Pros of awesome-vulkan

  • Comprehensive collection of Vulkan resources, including tutorials, libraries, and tools
  • Regularly updated with new Vulkan-related content
  • Covers a wide range of topics and skill levels

Cons of awesome-vulkan

  • Less structured learning path compared to VulkanTutorial
  • May be overwhelming for beginners due to the sheer amount of information
  • Lacks hands-on coding examples and step-by-step instructions

Code comparison

VulkanTutorial provides detailed code examples, while awesome-vulkan primarily links to external resources. Here's a sample from VulkanTutorial:

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";

awesome-vulkan doesn't include direct code examples but links to various tutorials and projects that contain code samples.

Summary

VulkanTutorial offers a structured, step-by-step approach to learning Vulkan with detailed code examples. awesome-vulkan provides a comprehensive collection of Vulkan resources, covering a broader range of topics but with less direct guidance. VulkanTutorial is better suited for beginners looking for a hands-on learning experience, while awesome-vulkan is an excellent reference for developers at all levels seeking a wide variety of Vulkan-related information and tools.

Ray tracing examples and tutorials using VK_KHR_ray_tracing

Pros of vk_raytracing_tutorial_KHR

  • Focuses specifically on ray tracing in Vulkan, providing in-depth coverage of this advanced topic
  • Includes NVIDIA-specific optimizations and best practices for ray tracing
  • Offers more recent and up-to-date content, reflecting the latest developments in Vulkan ray tracing

Cons of vk_raytracing_tutorial_KHR

  • Less comprehensive for general Vulkan learning, as it's specialized for ray tracing
  • May be more challenging for beginners due to its focus on advanced techniques
  • Potentially less portable across different hardware vendors, given its NVIDIA-centric approach

Code Comparison

VulkanTutorial (basic triangle rendering):

vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
vkCmdEndRenderPass(commandBuffer);

vk_raytracing_tutorial_KHR (ray tracing pipeline setup):

VkRayTracingPipelineCreateInfoKHR rayPipelineInfo{VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR};
rayPipelineInfo.stageCount = static_cast<uint32_t>(stages.size());
rayPipelineInfo.pStages = stages.data();
rayPipelineInfo.groupCount = static_cast<uint32_t>(groups.size());
rayPipelineInfo.pGroups = groups.data();
vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayPipelineInfo, nullptr, &pipeline);

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Vulkan tutorial

This repository hosts the contents of vulkan-tutorial.com. The website itself is based on daux.io, which supports GitHub flavored Markdown. The actual site runs daux.io with a custom theme and a few modifications (https://github.com/Overv/daux.io) and this is built into a Docker image.

Use issues and pull requests to provide feedback related to the website. If you have a problem with your code, then use the comments section in the related chapter to ask a question. Please provide your operating system, graphics card, driver version, source code, expected behaviour and actual behaviour.

E-book

This guide is now available in e-book formats as well:

The e-book can be built from the existing content by running:

 python3 build_ebook.py

This script depends on the following utilities being available on the path:

  • inkscape: SVG to PNG conversion (tested with version 1.0.2)
  • pandoc: Building a PDF and EPUB from the Markdown code (tested with version 2.13)

You also need to install a LaTeX distribution for PDF generation.

Changing code across chapters

It is sometimes necessary to change code that is reused across many chapters, for example a function like createBuffer. If you make such a change, then you should update the code files using the following steps:

  • Update any chapters that reference the modified code.
  • Make a copy of the first file that uses it and modify the code there, e.g. base_code_fixed.cpp.
  • Create a patch using diff -Naur base_code.cpp base_code_fixed.cpp > patch.txt.
  • Apply the patch to the specified code file and all files in later chapters using the incremental_patch.sh script. Run it like this: ./incremental_patch.sh base_code.cpp patch.txt.
  • Clean up the base_code_fixed.cpp and patch.txt files.
  • Commit.

Rendering the tutorial

To render the tutorial (i.e. convert the markdown to html), you have two options:

  1. Serve rendered files on the fly using a web server that has php installed
  2. Generate static html files that you can view locally or put on a server

For either of these options, you'll need php and a patch'ed daux.

PHP

  1. Make sure PHP is installed (Daux is written in PHP)
    1. Both the php_mbstring and php_openssl extensions need to be enabled
    2. The phar.readonly setting needs to be set to Off (to be able to rebuild Daux)
  2. Make sure Composer is installed, a php dependency manager that Daux uses

Clone, patch, and rebuild daux

  1. Clone daux
    • git clone https://github.com/dauxio/daux.io.git
  2. Make a new branch at the older revision that the VulkanTutorial patch is against:
    • git checkout d45ccff -b vtpatch
    • Making a new branch isn't strictly necessary, as you could reset master, but this keeps master intact.
  3. Copy over the daux.patch file into the daux.io directory, make sure line endings are UNIX style (in case you're using Windows), and apply the patch. It should apply cleanly.
    • git am daux.patch
  4. Run composer in the daux.io directory so that it downloads the dependencies Daux needs in order to be built
    • composer install
  5. Rebuild Daux
    • php bin/compile (this can take a while)
    • A newly made daux.phar will now be in your base directory

Using Daux to serve rendered files on the fly

Once you've completed the above, follow the instructions on the daux site for how to run daux using a web server.

As a simple option considering you have php installed, you can also use php's built in development web server if you just need to locally see what things look like:

  1. In the daux.io directory, edit global.json so that the docs_directory option points at your VulkanTutorial directory
    • "docs_directory": "../VulkanTutorial",
  2. In the daux.io directory, run
    • php -S localhost:8080 index.php
  3. Type localhost:8080 in your web browser URL bar and hit enter. You should now see the VulkanTutorial front page.

Using Daux to statically generate html files

Before we generate the static files, we need to tweak daux and the tutorial setup to prevent it from trying to load a few outside resources (which will stall your browser when trying to load the otherwise static page)

  1. In the VulkanTutorial directory, edit config.json and remove the google_analytics line so daux doesn't try to load that.
  2. In the daux.io directory, edit themes/daux/config.json and remove the font line so that daux doesn't try to load an external font.
  3. Rebuild daux according to the earlier instructions so it picks up the theme changes.

We're working on improvements so in the future the above steps won't be necessary.

Now with the above done, we can generate the static files. Asuming the daux.io and VulkanTutorial directories are next to each other, go into the daux.io directory and run a command similar to: php generate -s ../VulkanTutorial -d ../VulkanTutorial/out.

-s tells it where to find the documentation, while -d tells it where to put the generated files.

Note: if you want to generate the docs again, delete the out directory first or daux will make a new out directory within the existing out directory.

License

The contents of this repository are licensed as CC BY-SA 4.0, unless stated otherwise. By contributing to this repository, you agree to license your contributions to the public under that same license.

The code listings in the code directory are licensed as CC0 1.0 Universal. By contributing to that directory, you agree to license your contributions to the public under that same public domain-like license.