Mastering Graphics Programming with Vulkan

Book description

Develop a rendering framework in this part-color guide by implementing next-generation 3D graphics, leveraging advanced Vulkan features, and getting familiar with efficient real-time ray tracing techniques uncovered by leading industry veterans, Marco Castorina and Gabriel Sassone

Key Features

  • Use a pre-built "Raptor" engine to abstract tedious aspects like file systems, memory allocation, and utility functions
  • Delve into advanced graphics programming by taking advantage of Vulkan's cutting-edge features, including mesh shaders and ray tracing
  • Optimize your engine without reinventing the wheel
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

Vulkan is now an established and flexible multi-platform graphics API. It has been adopted in many industries, including game development, medical imaging, movie productions, and media playback but learning it can be a daunting challenge due to its low-level, complex nature. Mastering Graphics Programming with Vulkan is designed to help you overcome this difficulty, providing a practical approach to learning one of the most advanced graphics APIs.

In Mastering Graphics Programming with Vulkan, you’ll focus on building a high-performance rendering engine from the ground up. You’ll explore Vulkan’s advanced features, such as pipeline layouts, resource barriers, and GPU-driven rendering, to automate tedious tasks and create efficient workflows. Additionally, you'll delve into cutting-edge techniques like mesh shaders and real-time ray tracing, elevating your graphics programming to the next level.

By the end of this book, you’ll have a thorough understanding of modern rendering engines to confidently handle large-scale projects. Whether you're developing games, simulations, or visual effects, this guide will equip you with the skills and knowledge to harness Vulkan’s full potential.

What you will learn

  • Understand resources management and modern bindless techniques
  • Get comfortable with how a frame graph works and know its advantages
  • Explore how to render efficiently with many light sources
  • Discover how to integrate variable rate shading
  • Understand the benefits and limitations of temporal anti-aliasing
  • Get to grips with how GPU-driven rendering works
  • Explore and leverage ray tracing to improve render quality

Who this book is for

This book is for professional graphics and game developers who want to gain in-depth knowledge about how to write a modern and performant rendering engine in Vulkan. Familiarity with basic concepts of graphics programming (i.e. matrices, vectors, etc.) and fundamental knowledge of Vulkan are required.

Table of contents

  1. Mastering Graphics Programming with Vulkan
  2. Acknowledgments
  3. Contributors
  4. About the authors
  5. About the reviewer
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  7. Part 1: Foundations of a Modern Rendering Engine
  8. Chapter 1: Introducing the Raptor Engine and Hydra
    1. Technical requirements
      1. Windows
      2. Linux
      3. macOS
    2. How to read this book
    3. Understanding the code structure
      1. Layers of code
    4. Understanding the glTF scene format
    5. PBR in a nutshell
    6. A word on GPU debugging
    7. Summary
    8. Further reading
  9. Chapter 2: Improving Resources Management
    1. Technical requirements
    2. Unlocking and implementing bindless rendering
      1. Checking for support
      2. Creating the descriptor pool
      3. Updating the descriptor set
      4. Update to shader code
    3. Automating pipeline layout generation
      1. Compiling GLSL to SPIR-V
      2. Understanding the SPIR-V output
      3. From SPIR-V to pipeline layout
    4. Improving load times with a pipeline cache
    5. Summary
    6. Further reading
  10. Chapter 3: Unlocking Multi-Threading
    1. Technical requirements
    2. Task-based multi-threading using enkiTS
      1. Why task-based parallelism?
      2. Using the enkiTS (Task-Scheduler) library
    3. Asynchronous loading
      1. Creating the I/O thread and tasks
      2. Vulkan queues and the first parallel command generation
      3. The AsynchronousLoader class
    4. Recording commands on multiple threads
      1. The allocation strategy
      2. Command buffer recycling
      3. Primary versus secondary command buffers
      4. Drawing using primary command buffers
      5. Drawing using secondary command buffers
      6. Spawning multiple tasks to record command buffers
    5. Summary
    6. Further reading
  11. Chapter 4: Implementing a Frame Graph
    1. Technical requirements
    2. Understanding frame graphs
      1. Building a graph
      2. A data-driven approach
      3. Implementing the frame graph
      4. Implementing topological sort
      5. Driving rendering with the frame graph
    3. Summary
    4. Further reading
  12. Chapter 5: Unlocking Async Compute
    1. Technical requirements
    2. Replacing multiple fences with a single timeline semaphore
      1. Enabling the timeline semaphore extension
      2. Creating a timeline semaphore
      3. Waiting for a timeline semaphore on the CPU
      4. Using a timeline semaphore on the GPU
    3. Adding a separate queue for async compute
      1. Submitting work on separate queues
    4. Implementing cloth simulation using async compute
      1. Benefits of using compute shaders
      2. Compute shaders overview
      3. Writing compute shaders
    5. Summary
    6. Further reading
  13. Part 2: GPU-Driven Rendering
  14. Chapter 6: GPU-Driven Rendering
    1. Technical requirements
    2. Breaking down large meshes into meshlets
      1. Generating meshlets
    3. Understanding task and mesh shaders
      1. Implementing task shaders
      2. Implementing mesh shaders
    4. GPU culling using compute
      1. Depth pyramid generation
      2. Occlusion culling
    5. Summary
    6. Further reading
  15. Chapter 7: Rendering Many Lights with Clustered Deferred Rendering
    1. Technical requirements
    2. A brief history of clustered lighting
      1. Differences between forward and deferred techniques
    3. Implementing a G-buffer
    4. Implementing light clusters
      1. CPU lights assignment
      2. GPU light processing
    5. Summary
    6. Further reading
  16. Chapter 8: Adding Shadows Using Mesh Shaders
    1. Technical requirements
    2. A brief history of shadow techniques
      1. Shadow volumes
      2. Shadow mapping
      3. Raytraced shadows
    3. Implementing shadow mapping using mesh shaders
      1. Overview
      2. Cubemap shadows
      3. A note about multiview rendering
      4. Per-light mesh instance culling
      5. Indirect draw commands generation
      6. Shadow cubemap face culling
      7. Meshlet shadow rendering – task shader
      8. Meshlet shadow rendering – mesh shader
      9. Shadow map sampling
    4. Improving shadow memory with Vulkan’s sparse resources
      1. Creating and allocating sparse textures
      2. Choosing per-light shadow memory usage
      3. Rendering into a sparse shadow map
    5. Summary
    6. Further reading
  17. Chapter 9: Implementing Variable Rate Shading
    1. Technical requirements
    2. Introducing variable rate shading
      1. Determining the shading rate
    3. Integrating variable rate shading using Vulkan
    4. Taking advantage of specialization constants
    5. Summary
    6. Further reading
  18. Chapter 10: Adding Volumetric Fog
    1. Technical requirements
    2. Introducing Volumetric Fog Rendering
      1. Volumetric Rendering
      2. Volumetric Fog
    3. Implementing Volumetric Fog Rendering
      1. Data injection
      2. Calculating the lighting contribution
      3. Integrating scattering and extinction
      4. Applying Volumetric Fog to the scene
      5. Adding filters
      6. Volumetric noise generation
      7. Blue noise
    4. Summary
    5. Further reading
  19. Part 3: Advanced Rendering Techniques
  20. Chapter 11: Temporal Anti-Aliasing
    1. Technical requirements
    2. Overview
    3. The simplest TAA implementation
      1. Jittering the camera
      2. Choosing jittering sequences
      3. Adding motion vectors
      4. First implementation code
    4. Improving TAA
      1. Reprojection
      2. History sampling
      3. Scene sampling
      4. The history constraint
      5. Resolve
    5. Sharpening the image
      1. Sharpness post-processing
      2. Negative mip bias
      3. Unjitter texture UVs
    6. Improving banding
    7. Summary
    8. Further reading
  21. Chapter 12: Getting Started with Ray Tracing
    1. Technical requirements
    2. Introduction to ray tracing in Vulkan
    3. Building the BLAS and TLAS
    4. Defining and creating a ray tracing pipeline
    5. Summary
    6. Further reading
  22. Chapter 13: Revisiting Shadows with Ray Tracing
    1. Technical requirements
    2. Implementing simple ray-traced shadows
    3. Improving ray-traced shadows
      1. Motion vectors
      2. Computing visibility variance
      3. Computing visibility
      4. Computing filtered visibility
      5. Using the filtered visibility
    4. Summary
    5. Further reading
  23. Chapter 14: Adding Dynamic Diffuse Global Illumination with Ray Tracing
    1. Technical requirements
    2. Introduction to indirect lighting
    3. Introduction to Dynamic Diffuse Global Illumination (DDGI)
      1. Ray tracing for each probe
      2. Probes offsetting
      3. Probes irradiance and visibility updates
      4. Probes sampling
    4. Implementing DDGI
      1. Ray-generation shader
      2. Ray-hit shader
      3. Ray-miss shader
      4. Updating probes irradiance and visibility shaders
      5. Indirect lighting sampling
      6. Modifications to the calculate_lighting method
      7. Probe offsets shader
    5. Summary
    6. Further reading
  24. Chapter 15: Adding Reflections with Ray Tracing
    1. Technical requirements
    2. How screen-space reflections work
    3. Implementing ray-traced reflections
    4. Implementing a denoiser
    5. Summary
    6. Further reading
  25. Index
    1. Why subscribe?
  26. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Mastering Graphics Programming with Vulkan
  • Author(s): Marco Castorina, Gabriel Sassone
  • Release date: February 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781803244792