Table Of ContentVulkan Cookbook
Work through recipes to unlock the full potential of the next
generation graphics API—Vulkan
Pawel Lapinski
BIRMINGHAM - MUMBAI
Vulkan Cookbook
Copyright © 2017 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, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be 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.
First published: April 2017
Production reference: 1260417
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78646-815-4
www.packtpub.com
Credits
Author Copy Editor
Pawel Lapinski Safis Editing
Reviewer Project Coordinator
Chris Forbes Ritika Manoj
Commissioning Editor Proofreader
Ashwin Nair Safis Editing
Acquisition Editor Indexer
Nitin Dasan Tejal Daruwale Soni
Content Development Editor Production Coordinator
Aditi Gour Arvindkumar Gupta
Technical Editor Graphics
Murtaza Tinwala Jason Monteiro
About the Author
Pawel Lapinski is a graphics software engineer at Intel Corporation. His professional career
started 10 years ago when he and his friends were hired to develop a 3D training/simulation
application using C++, OpenGL, and Cg, which was later improved with added head-
mounted display support and stereoscopic image generation.
Since his studies, Pawel has been interested in 3D graphics and especially in the open
multiplatform OpenGL library. He wrote a diploma about the “Effective usage of vertex
and fragment shaders.” Since then, he has continued to pursue opportunities to work with
3D graphics and expand his knowledge in the field. He had the opportunity to join a team
that was developing one of the biggest CAVE‑like installations at the Polish Gdansk
University of Technology. His responsibility was to prepare 3D visualizations using
Unity3D engine and add stereoscopic image generation and support for motion tracking.
Pawel's whole career has involved working with computer graphics, the OpenGL library,
and shaders. However, some time ago, already as a programmer at Intel, he had the
opportunity to start working with the Vulkan API when he prepared validation tests for the
Vulkan graphics driver. He also prepared a series of tutorials teaching people how to use
Vulkan and now he wants to share more of his knowledge in the form of a Vulkan
Cookbook.
Acknowledgments
This is my first published book and it is a very important moment of my life. That’s why I’d
like to include quite many people in this “special thanks” list.
First and foremost, I want to thank my wife, Agata, my children, and the whole family for
all their love, patience, and continuous support.
I wouldn’t have written this book if Mr. Jacek Kuffel hadn't been my language teacher in
my primary school. He taught me how important our language is and he also taught me
how to express myself with written words. I learned all my love of writing from him.
My affection for 3D graphics programming started during my studies. It started growing
thanks to my thesis supervisor Mariusz Szwoch, Ph.D., and my 3D graphics teacher Jacek
Lebiedz, Ph.D. I’d like to thank them for their support and help. Without them I would not
have started learning OpenGL and, as the next step, the Vulkan API.
Kind regards and a huge thank you to my team here at Intel Poland. I couldn’t have joined
a better team or started working with better people. They are not only specialists at what
they do, but they are all kind, sincere and warmhearted friends. I’d like to thank them for
patiently answering my many questions, for sharing their knowledge. And for the great
atmosphere that they create every day. Special thanks are required to Slawek, Boguslaw,
Adam, Jacek, and to my manager Jan.
And last but not least – the Packt team. I’ve always dreamt about writing a book and they
not only allowed me to do it, but they helped me realize my dreams, showing their support
at every step from the very beginning. Aditi, Murtaza, Nitin, Sachin – You are great. It was
much easier to write this book with you on my side.
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
[www.mesa3d.org], as well as rebuilding classic strategy games to run on modern systems
[www.openra.net]. He also served as a technical reviewer on Packt's previous Vulkan title,
Learning Vulkan.
www.PacktPub.com
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and
eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt
books and video courses, as well as industry-leading tools to help you plan your personal
development and advance your career.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial
process. To help us improve, please leave us an honest review on this book's Amazon page
at https://www.amazon.com/Vulkan-Cookbook-Pawel-Lapinski/dp/1786468158.
If you'd like to join our team of regular reviewers, you can e-mail us at
customerreviews@packtpub.com. We award our regular reviewers with free eBooks and
videos in exchange for their valuable feedback. Help us be relentless in improving our
products!
Table of Contents
Preface
1
Chapter 1: Instance and Devices
8
Introduction 9
Downloading Vulkan's SDK 9
Getting ready 9
How to do it... 9
How it works... 11
See also 11
Enabling validation layers 12
How to do it... 13
How it works... 14
See also 15
Connecting with a Vulkan Loader library 15
How to do it... 16
How it works... 16
See also 17
Preparing for loading Vulkan API functions 17
How to do it... 18
How it works... 20
See also 20
Loading functions exported from a Vulkan Loader library 21
How to do it... 21
How it works... 22
See also 23
Loading global-level functions 23
How to do it... 24
How it works... 24
See also 25
Checking available Instance extensions 26
How to do it... 26
How it works... 27
See also 28
Creating a Vulkan Instance 28
How to do it... 28