Reader small image

You're reading from  The Modern Vulkan Cookbook

Product typeBook
Published inApr 2024
Reading LevelN/a
PublisherPackt
ISBN-139781803239989
Edition1st Edition
Languages
Concepts
Right arrow
Authors (2):
Preetish Kakkar
Preetish Kakkar
author image
Preetish Kakkar

Preetish Kakkar is a senior computer graphics engineer with Adobe and works on the rendering engine that powers products such as Aero, Stager, and After Effects. He has worked at Microsoft, MathWorks, and Stryker, where he co-authored various rendering engines as well as using other engines such as Unreal and Unity. He has more than 15 years of software development experience along with 10+ years in 3D graphics, scientific visualization, and medical imaging.
Read more about Preetish Kakkar

Mauricio Maurer
Mauricio Maurer
author image
Mauricio Maurer

Mauricio Maurer is a computer graphics engineer with nearly 20 years of experience working with 2D and 3D rendering, computational geometry, and rasterization in the fields of scientific visualization, CAD/CAM, and social networking. He is currently a graphics software engineer at Meta, helping to develop the next generation of AR/VR devices. Mauricio holds two master's degrees in computer science with a specialization in computer graphics from SUNY Stony Brook, NY, and the Federal University of Parana, Brazil.
Read more about Mauricio Maurer

View More author details
Right arrow

Preface

This book is designed for experienced computer graphics software engineers who might be well versed in older graphics APIs such as OpenGL and DirectX 10 but are relatively new to modern graphics APIs. Like you, we found ourselves needing to learn Vulkan but struggling to implement practical solutions because we didn’t understand the basic concepts of Vulkan, which is, in itself, a complicated and vast API. The goal of this book is to introduce you to the essential concepts of the API and then walk you through hand-picked, tried-and-true algorithms that show you the new and nuanced aspects of Vulkan in each recipe.

This book is divided into five parts and covers, in this order, the following:

  • Basic Vulkan concepts, how and why to use them, and how they fit into the bigger picture of writing an application using the Vulkan API
  • General graphics algorithms implemented using Vulkan, including their features and how they can be used to achieve all sorts of tasks relevant to graphics applications
  • Using Vulkan to build a GPU ray tracer and a hybrid renderer
  • How to use Vulkan and OpenXR to write applications for the incredible new world of VR, MR, and AR
  • Ways to debug and profile your Vulkan implementation

There are many resources that cover the first part of what this book explores, but in this book, we offer a two-part story that progressively helps you understand the basic Vulkan concepts by providing easy and practical examples. The subsequent parts present implementations that work and can be used as a reference for the implementation of your own graphics engine.

The main goal of the repository provided with this book was not to achieve the highest performance, find clever ways to implement things, or even implement the shiniest new algorithm shown at last year’s GDC or SIGGRAPH. It was simplicity and completeness. We offer tips and tricks on how some Vulkan features can and/or must be used, and most recipes have been tested and debugged and provide you with a self-contained working solution that you can improve and use in your own code base. Each recipe is its own executable and can be inspected independently from the others, making them easy to read. That also makes it easy to understand all the details of each algorithm from beginning to end.

Vulkan is the future de-facto graphics API for all devices and types of applications. It’s a mature, feature-rich, and maintained API, supported by all GPU vendors, operating systems, frameworks, and languages. If you intend to write graphics applications or write one that uses only the compute facilities of Vulkan, getting to know the API is a must, and you need to learn it right now!

Who this book is for

This book has been written for experienced graphics software engineers who would like to learn more about Vulkan. Knowing at least one other graphics API, such as OpenGL, and one of its variants, such as WebGL, OpenGL ES, or DirectX (up to version 9 or 10), is suggested but not strictly necessary. It is important to know graphics principles, such as transformations, graphics pipelines, shaders, lighting, the basics of ray tracing, and depth and stencil buffers, to name a few. More advanced topics, such as PBR and all its concepts, aren’t necessary but may be helpful.

Finally, the code has been written entirely in C++, as it is the most widely used programming language for writing graphics applications. Even though some C++20 features are used in the book because they help reduce Vulkan’s verbosity, you are not expected to have intimate knowledge of the newest C++ features.

What this book covers

Chapter 1, Vulkan Core Concepts, provides a walk-through of the most basic Vulkan concepts and objects and how to create and use them. The chapter covers how Vulkan can be used and initialized and how its objects interplay and are managed from the application. At the end of the chapter, we present a recipe for how those concepts can be used to create the simplest graphics application in Vulkan.

Chapter 2, Working with Modern Vulkan, presents more advanced Vulkan concepts and objects, such as barriers, descriptors, and pipelines, that allow you to start using resources other than just data provided directly in the shader code. This chapter also offers a brief overview of modern rendering techniques, such as Programmable Vertex Pulling (PVP) and Multidraw Indirect (MDI).

Chapter 3, Implementing GPU-Driven Rendering, has recipes that implement what is called GPU-driven rendering: techniques that generate data directly from shaders with little or no input from the CPU. The generated data remains in the GPU after being generated and can be used to direct how to render a scene; or, the data can be presented directly on screen as debug information.

Chapter 4, Exploring Techniques for Lighting, Shading, and Shadows, explores known graphics techniques but from a Vulkan perspective. Recipes include implementations of deferred rendering, screen-space reflections, shadow maps, and screen-space ambient occlusion, demonstrating how to achieve practical results while navigating the complexity of Vulkan.

Chapter 5, Deciphering Order-Independent Transparency, contains recipes for implementing transparency using Vulkan, all the way from simpler algorithms, such as depth-peeling and dual depth-peeling, to more advanced and physically correct implementations, such as order-independent transparency, that run exclusively on the GPU. While some of those recipes may seem old, they really show the power of the Vulkan API.

Chapter 6, Anti-Aliasing Techniques, provides a comprehensive list of anti-aliasing techniques that can be used with Vulkan. The first recipe uses the multisample anti-aliasing feature provided by Vulkan, while the others offer alternate ways to provide antialiasing without using the facilities provided by the API.

Chapter 7, Ray Tracing and Hybrid Rendering, is an introduction to ray tracing with Vulkan and uses the new Vulkan ray tracing extensions. Most of the chapter will walk you through how to implement a path tracer in your application and use it to render a ray-traced scene and display it on screen. The chapter spends the last few pages demonstrating how to use a hybrid approach in your existing rasterization engine to make it pop with a few ray-traced features.

Chapter 8, Extended Reality with OpenXR, introduces you to the realm of extended reality, which encompasses virtual, mixed, and augmented reality. The chapter introduces OpenXR, including its main features and how to use it. The chapter then explains how to improve your rendering engine’s performance using Vulkan and OpenXR features, such as multiview rendering and dynamic foveation.

Chapter 9, Debugging and Performance Measurement Techniques, concludes the book by guiding you through some ways to debug your Vulkan application and how to measure its performance.

To get the most out of this book

You will need a computer with a recent graphics card (to use some of the newer extensions, such as ray tracing, for example, you will need a card equivalent to NVIDIA’s 3050). The code in the repository and in this book has been compiled and tested with Visual Studio 2022 and the Vulkan SDK 1.3.268.

Software/hardware covered in the book

Operating system requirements

Vulkan SDK

Windows; Android for Quest devices

CMake and Visual Studio 2022

Windows

Android Studio Hedgehog 2023.1.1

Windows

RenderDoc

Windows

Tracy Profiler 0.9.1

Windows

We advise you to clone the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to copying and pasting of code.

Important note:

This book contains many horizontally long screenshots. These have been captured to provide you with an overview of the execution plans for various Vulkan concepts. As a result, the text in these images may appear small at 100% zoom.

Download the example code files

You can clone the example code files for this book from GitHub at https://github.com/PacktPublishing/The-Modern-Vulkan-Cookbook. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “For host-visible memory, it’s enough to retrieve a pointer to the destination using vmaMapMemory and copy the data using memcpy.”

A block of code is set as follows:

const VmaAllocationCreateInfo allocCreateInfo = {
    .flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT,
    .usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
    .priority = 1.0f,
};

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

samplerShadowMap_ = context.createSampler(
    VK_FILTER_NEAREST, VK_FILTER_NEAREST,
    VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
    VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
    VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, 1.0f,
    true, VK_COMPARE_OP_LESS_OR_EQUAL,
    "lighting pass shadow");

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “To guarantee that partial updates work, we need to copy the last active buffer, Buffer 0, into Buffer 1 first, and then update viewport matrix.”

Tips or important notes

Appear like this.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it..., How it works..., There’s more..., and See also).

To give clear instructions on how to complete a recipe, use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There’s more…

This section consists of additional information about the recipe in order to make you more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

Share Your Thoughts

Once you’ve read The Modern Vulkan Cookbook, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your e-book purchase not compatible with the device of your choice?

Don’t worry!, Now with every Packt book, you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the following link:

https://packt.link/free-ebook/9781803239989

  1. Submit your proof of purchase.
  2. That’s it! We’ll send your free PDF and other benefits to your email directly.
lock icon
The rest of the chapter is locked
You have been reading a chapter from
The Modern Vulkan Cookbook
Published in: Apr 2024Publisher: PacktISBN-13: 9781803239989
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Preetish Kakkar

Preetish Kakkar is a senior computer graphics engineer with Adobe and works on the rendering engine that powers products such as Aero, Stager, and After Effects. He has worked at Microsoft, MathWorks, and Stryker, where he co-authored various rendering engines as well as using other engines such as Unreal and Unity. He has more than 15 years of software development experience along with 10+ years in 3D graphics, scientific visualization, and medical imaging.
Read more about Preetish Kakkar

author image
Mauricio Maurer

Mauricio Maurer is a computer graphics engineer with nearly 20 years of experience working with 2D and 3D rendering, computational geometry, and rasterization in the fields of scientific visualization, CAD/CAM, and social networking. He is currently a graphics software engineer at Meta, helping to develop the next generation of AR/VR devices. Mauricio holds two master's degrees in computer science with a specialization in computer graphics from SUNY Stony Brook, NY, and the Federal University of Parana, Brazil.
Read more about Mauricio Maurer