Mastering Graphics Programming with Vulkan - Marco Castorina - E-Book

Mastering Graphics Programming with Vulkan E-Book

Marco Castorina

0,0
32,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 404

Veröffentlichungsjahr: 2023

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Mastering Graphics Programming with Vulkan

Develop a modern rendering engine from first principles to state-of-the-art techniques

Marco Castorina

Gabriel Sassone

BIRMINGHAM—MUMBAI

Mastering Graphics Programming with Vulkan

Copyright © 2023 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Rohit Rajkumar

Publishing Product Manager: Nitin Nainani

Content Development Editor: Abhishek Jadhav

Technical Editor: Simran Ali

Copy Editor: Safis Editing

Project Coordinator: Aishwarya Mohan

Proofreader: Safis Editing

Indexer: Manju Arasan

Production Designer: Vijay Kamble

Marketing Coordinator: Nivedita Pandey

First published: January 2023

Production reference: 1130123

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80324-479-2

www.packt.com

To my parents and my grandma, who taught me to work hard and never give up. To my kids, who remind me daily to look at things differently and always challenge my assumptions. And to my wife – without her support throughout the years, this book wouldn’t exist.

– Marco Castorina

To my mum, dad, and sister who always believed in me and taught me how to strive to be better with an open mind and heart.

To my friend Enrico, for always being an inspiration in all the adventures of my life.

To Gianluca, Piero, Mauro, Roberto, Stefano, Riccardo, Emiliano, Stuart, Federico, Luca, and Stefano for being in my life and supporting me over the years.

To the Belluno crew, colleagues, and friends: Carlo Mangani, Fabio Pagetti, Mattia Poderi, Vittorio Conti, Flavio Bortot, and Luca Marchetti.

To all the Blacksand crew: Marco, Alessandro, Andrea, Gianluca, Alessandra, Elisa, Cinzia, and many more, who made me feel at home even when I was on the other side of the planet.

To all the colleagues that helped me on my journey: Tiziano Lena, Gabriele Barlocci, Alessandro Monopoli, Daniele Pieroni, Francesco Antolini, Andrea Pessino, Simone Kulczycki, Marco Vallario, Nicholas Rathbone, Peter Asberg, Dave Barrett, David Grijns, Christofer Sundberg, David Smethurst, Engin Cilasun, and Gennadiy Korol – you all taught me a lot.

To the awesome rendering community: Matt Pettineo, Natalya Tatarchuk, Inigo Quilez, Jorge Jimenez, Bart Wronski, Alan Wolfe, and many, many more.

And finally to everybody else that crossed my path: in one way or another, you changed my life.

– Gabriel Sassone

Acknowledgments

Like all published works, this book is the effort of many dedicated people. To Chayan Majumdar and Nitin Nainani, who first reached out to us about this project and helped us structure the book. To our editors Abhishek Jadhav and Aamir Ahmed, who helped us find our voice and made sure our content was clear and organized.

To our project managers, Ajesh Devavaram and Aishwarya Mohan, who kept us on track and were understanding when we needed more time. We would also like to thank our technical reviewer, who gave us invaluable feedback to make each chapter clearer and more accessible.

This book wouldn’t exist if it weren’t for the many dedicated graphics and rendering engineers all over the world who keep sharing their work and pushing the field forward. Many of those ideas have made it into this book and we hope we did them justice. The support of the graphics community has been invaluable and kept us motivated throughout the writing process.

I, Marco, would also like to thank AMD and 7th Sense, who have allowed me to work on this project in my spare time. Andy Poole at Samsung first helped me wade through the Vulkan specification. His insight and approach still help me on a daily basis. To Hugh McAtamney and Bryan Duggan from the Dublin Institute of Technology, who inspired me to pursue a career in graphics.

To Eike Anderson from Bournemouth University, who helped me to improve my technical writing and approach things from first principles. To Richard Brown and Alex Hughes at 7th Sense, as my discussions with them challenged me to push Vulkan to its limits and provided insight into improving my code architecture.

Finally, I couldn’t have done it without Gabriel. His tremendous experience and continuous feedback supported me throughout this project. It was a joy working with him and I consider myself lucky that I can now call him a friend.

I, Gabriel, would like to thank The Multiplayer Group, who have allowed me to work on this project and were supportive of it.

To Matt Pettineo at ReadyAtDawn, for being my biggest inspiration in rendering and coding. Without his guidance and teachings, I would not have been able to tackle this project.

To Engin Cilasun, for being my rendering and engine design pal, teaching me a lot about how to think differently and challenging my assumptions to find new ways.

To Codemasters, ReadyAtDawn, Moon Studios, and Avalanche Studios for all the experience and teaching in my career.

Finally, to Marco, who gave me the possibility to work on this project. His deep knowledge and understanding of rendering and GPUs were paramount. His skill at solving complex problems and reading the Vulkan spec gave us the edge on the latest technology. I learned a lot from him and have deep gratitude toward him.

It was incredible working with him, and even better, having a new person to call a friend.

Contributors

About the authors

Marco Castorina first became familiar with Vulkan while working as a driver developer at Samsung. Later, he developed a 2D and 3D renderer in Vulkan from scratch for a leading media server company. He recently joined the games graphics performance team at AMD. In his spare time, he keeps up to date with the latest techniques in real-time graphics. He also likes cooking and playing guitar.

Gabriel Sassone is a rendering enthusiast currently working as a principal rendering engineer at The Multiplayer Group. Previously working for Avalanche Studios, where he first encountered Vulkan, they developed the Vulkan layer for the proprietary Apex Engine and its Google Stadia port. He previously worked at ReadyAtDawn, Codemasters, FrameStudios, and some other non-gaming tech companies. His spare time is filled with music and rendering, gaming, and outdoor activities.

About the reviewer

Victor Blanco Ruiz is an experienced programmer focused on graphics, low level programming, and game engine architecture. He has worked for big name international companies as an engine programmer, has worked on PUBG: Battlegrounds and ported multiple games to PSVR, PS4, and Nintendo Switch as a freelancer, as well as self-published the games DWVR and rRootage Reloaded. He is the author of the Vulkan learning website VkGuide.

Table of Contents

Preface

Part 1: Foundations of a Modern Rendering Engine

1

Introducing the Raptor Engine and Hydra

Technical requirements

Windows

Linux

macOS

How to read this book

Understanding the code structure

Layers of code

Understanding the glTF scene format

PBR in a nutshell

A word on GPU debugging

Summary

Further reading

2

Improving Resources Management

Technical requirements

Unlocking and implementing bindless rendering

Checking for support

Creating the descriptor pool

Updating the descriptor set

Update to shader code

Automating pipeline layout generation

Compiling GLSL to SPIR-V

Understanding the SPIR-V output

From SPIR-V to pipeline layout

Improving load times with a pipeline cache

Summary

Further reading

3

Unlocking Multi-Threading

Technical requirements

Task-based multi-threading using enkiTS

Why task-based parallelism?

Using the enkiTS (Task-Scheduler) library

Asynchronous loading

Creating the I/O thread and tasks

Vulkan queues and the first parallel command generation

The AsynchronousLoader class

Recording commands on multiple threads

The allocation strategy

Command buffer recycling

Primary versus secondary command buffers

Drawing using primary command buffers

Drawing using secondary command buffers

Spawning multiple tasks to record command buffers

Summary

Further reading

4

Implementing a Frame Graph

Technical requirements

Understanding frame graphs

Building a graph

A data-driven approach

Implementing the frame graph

Implementing topological sort

Driving rendering with the frame graph

Summary

Further reading

5

Unlocking Async Compute

Technical requirements

Replacing multiple fences with a single timeline semaphore

Enabling the timeline semaphore extension

Creating a timeline semaphore

Waiting for a timeline semaphore on the CPU

Using a timeline semaphore on the GPU

Adding a separate queue for async compute

Submitting work on separate queues

Implementing cloth simulation using async compute

Benefits of using compute shaders

Compute shaders overview

Writing compute shaders

Summary

Further reading

Part 2: GPU-Driven Rendering

6

GPU-Driven Rendering

Technical requirements

Breaking down large meshes into meshlets

Generating meshlets

Understanding task and mesh shaders

Implementing task shaders

Implementing mesh shaders

GPU culling using compute

Depth pyramid generation

Occlusion culling

Summary

Further reading

7

Rendering Many Lights with Clustered Deferred Rendering

Technical requirements

A brief history of clustered lighting

Differences between forward and deferred techniques

Implementing a G-buffer

Implementing light clusters

CPU lights assignment

GPU light processing

Summary

Further reading

8

Adding Shadows Using Mesh Shaders

Technical requirements

A brief history of shadow techniques

Shadow volumes

Shadow mapping

Raytraced shadows

Implementing shadow mapping using mesh shaders

Overview

Cubemap shadows

A note about multiview rendering

Per-light mesh instance culling

Indirect draw commands generation

Shadow cubemap face culling

Meshlet shadow rendering – task shader

Meshlet shadow rendering – mesh shader

Shadow map sampling

Improving shadow memory with Vulkan’s sparse resources

Creating and allocating sparse textures

Choosing per-light shadow memory usage

Rendering into a sparse shadow map

Summary

Further reading

9

Implementing Variable Rate Shading

Technical requirements

Introducing variable rate shading

Determining the shading rate

Integrating variable rate shading using Vulkan

Taking advantage of specialization constants

Summary

Further reading

10

Adding Volumetric Fog

Technical requirements

Introducing Volumetric Fog Rendering

Volumetric Rendering

Volumetric Fog

Implementing Volumetric Fog Rendering

Data injection

Calculating the lighting contribution

Integrating scattering and extinction

Applying Volumetric Fog to the scene

Adding filters

Volumetric noise generation

Blue noise

Summary

Further reading

Part 3: Advanced Rendering Techniques

11

Temporal Anti-Aliasing

Technical requirements

Overview

The simplest TAA implementation

Jittering the camera

Choosing jittering sequences

Adding motion vectors

First implementation code

Improving TAA

Reprojection

History sampling

Scene sampling

The history constraint

Resolve

Sharpening the image

Sharpness post-processing

Negative mip bias

Unjitter texture UVs

Improving banding

Summary

Further reading

12

Getting Started with Ray Tracing

Technical requirements

Introduction to ray tracing in Vulkan

Building the BLAS and TLAS

Defining and creating a ray tracing pipeline

Summary

Further reading

13

Revisiting Shadows with Ray Tracing

Technical requirements

Implementing simple ray-traced shadows

Improving ray-traced shadows

Motion vectors

Computing visibility variance

Computing visibility

Computing filtered visibility

Using the filtered visibility

Summary

Further reading

14

Adding Dynamic Diffuse Global Illumination with Ray Tracing

Technical requirements

Introduction to indirect lighting

Introduction to Dynamic Diffuse Global Illumination (DDGI)

Ray tracing for each probe

Probes offsetting

Probes irradiance and visibility updates

Probes sampling

Implementing DDGI

Ray-generation shader

Ray-hit shader

Ray-miss shader

Updating probes irradiance and visibility shaders

Indirect lighting sampling

Modifications to the calculate_lighting method

Probe offsets shader

Summary

Further reading

15

Adding Reflections with Ray Tracing

Technical requirements

How screen-space reflections work

Implementing ray-traced reflections

Implementing a denoiser

Summary

Further reading

Index

Other Books You May Enjoy

Part 1: Foundations of a Modern Rendering Engine

In this part, we will build a solid foundation for our rendering engine. We will cover the following chapters in this section:

Chapter 1, Introducing the Raptor Engine and HydraChapter 2, Improving Resources ManagementChapter 3, Unlocking Multi-ThreadingChapter 4, Implementing a Frame GraphChapter 5, Unlocking Async Compute