Learning Vulkan Copyright © 2016 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.
Credits Author Copy Editor Parminder Singh Gladson Monteiro Reviewer Project Coordinator Chris Forbes Ritika Manoj Commissioning Editor Proofreader Ashwin Nair Safis Editing Acquisition Editors Indexer Smeet Thakkar Rekha Nair Aaron Lazar Content Development Editor Production Coordinator Sachin Karnani Aparna Bhagat Technical Editor Graphics Murtaza Tinwala Abhinash Sahu.
Acknowledgments I dedicate this to my sweet baby girl, Raskeerat, who was born at the same time as we started this project. With a little baby onboard, it's challenging to write a book; I am grateful to my beloved wife Gurpreet Kaur and my family for helping me deliver this project to the community.
About the Reviewer Chris Forbes works as a software developer for Google, working on Vulkan validation support and other ecosystem components. Previously he has been involved in implementing OpenGL 3 and 4 support in open source graphics drivers for Linux ( ), as well as rebuilding classic strategy games to run on modern systems www.mesa3d.org ( ).
Table of Contents Preface 1 Chapter 1: Getting Started with the NextGen 3D Graphics API 8 Vulkan and its evolution 8 Vulkan versus OpenGL 10 Important jargons before we get started 12 Learning the fundamentals of Vulkan 13 Vulkan's execution model 13 Vulkan's queues 15 The object model 16 Object lifetime and command syntax 16 Error checking and validation 17 Understanding the Vulkan application 17 Driver 18 Application 18 WSI 18 SPIR-V 18 LunarG SDK 19 Getting started with the Vulkan programming model 19 Hardware initialization 20 Window presentation surfaces 21 Resource setup 22 Pipeline setup 25 Descriptor sets and descriptor pools 25 Shaders with SPIR-V 26 Pipeline management 26 Recording commands 27 Queue submission 29 Summary 30 Chapter 2: Your First Vulkan Pseudo Program 31 Installing Vulkan 31 The Hello World!!! pseudocode 32 Initialization – a handshake with the device 33 Swapchain initialization – querying the WSI extension 37 Command buffer initialization – allocating command buffers 40 Resource objects – managing images and buffers 40.
Preface This book is all about learning Vulkan from scratch. Vulkan is a next-generation cross- platform graphics and compute API. Despite being a successor of OpenGL API, it is a completely fresh approach to redesigning an API from the base that meets the competitive demand of consumers and works very close with the underlying GPU hardware. Vulkan is a software interface that is capable of controlling GPU hardware settings to harness the power of paralleling computing. The driver layer in Vulkan is really thin and puts more responsibilities on the shoulders of an application programmer to manage the application, its resources, memory management, synchronization, and more; this explicit nature of Vulkan makes it verbose. This book allows the beginner to learn such topics in baby steps, covering each chapter with an easy-to-follow companion example. The chapters are laid out in an incremental fashion; each chapter is built on top of the previous one, exposing the modular difference to our readers.
1 Getting Started with the NextGen 3D Graphics API Vulkan is a revolutionary high-performance 3D graphics and computing API for modern GPU pipeline architectures to meet the demanding requirements of the community. This API provides a brand-new approach to overcome the complexities and gaps in existing traditional APIs. Vulkan is an explicit API that promises predictable behavior and allows you to have smooth rendering frame rates without causing lags or hitches. This chapter will present an overview of the Vulkan API and its distinct features compared to its predecessor: the OpenGL API. We will take a look at Vulkan's ecosystem and understand its graphics system.