Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Vulkan Cookbook

You're reading from   Vulkan Cookbook Work through recipes to unlock the full potential of the next generation graphics API—Vulkan

Arrow left icon
Product type Paperback
Published in Apr 2017
Publisher Packt
ISBN-13 9781786468154
Length 700 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Pawel Lapinski Pawel Lapinski
Author Profile Icon Pawel Lapinski
Pawel Lapinski
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Title Page
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Instance and Devices 2. Image Presentation FREE CHAPTER 3. Command Buffers and Synchronization 4. Resources and Memory 5. Descriptor Sets 6. Render Passes and Framebuffers 7. Shaders 8. Graphics and Compute Pipelines 9. Command Recording and Drawing 10. Helper Recipes 11. Lighting 12. Advanced Rendering Techniques

Preface

Computer graphics have a very long and interesting history. Many APIs or custom approaches to the generation of 2D or 3D images have come and gone. A landmark in this history was the invention of OpenGL, one of the first graphics libraries, which allowed us to create real‑time, high-performance 3D graphics, and which was available for everyone on multiple operating systems. It is still developed and widely used even today. And this year we can celebrate its 25th birthday!

But many things have changed since OpenGL was created. The graphics hardware industry is evolving very quickly. And recently, to accommodate these changes, a new approach to 3D graphics rendering was presented. It took the form of a low‑level access to the graphics hardware. OpenGL was designed as a high-level API, which allows users to easily render images on screen. But this high‑level approach, convenient for users, is difficult for graphics drivers to handle. This is one of the main reasons for restricting the hardware to show its full potential. The new approach tries to overcome these struggles–it gives users much more control over the hardware, but also many more responsibilities. This way application developers can release the full potential of the graphics hardware, because the drivers no longer block them. Low‑level access allows drivers to be much smaller, much thinner. But these benefits come at the expense of much more work that needs to done by the developers.

The first evangelist of the new approach to graphics rendering was a Mantle API designed by AMD. When it proved that low‑level access can give considerable performance benefits, other companies started working on their own graphics libraries. One of the most notable representatives of the new trend were Metal API, designed by Apple, and DirectX 12, developed by Microsoft.

But all of the above libraries were developed with specific operating systems and/or hardware in mind. There was no open and multiplatform standard such as OpenGL. Until last year. Year 2016 saw the release of the Vulkan API, developed by Khronos consortium, which maintains the OpenGL library. Vulkan also represents the new approach, a low‑level access to the graphics hardware, but unlike the other libraries it is available for everyone on multiple operating systems and hardware platforms–from high‑performance desktop computers with Windows or Linux operating systems, to mobile devices with Android OS. And as it is still being very new, there are few resources teaching developers how to use it. This book tries to fill this gap.

What this book covers

Chapter 1, Instance and Devices, shows how to get started with the Vulkan API. This chapter explains where to download the Vulkan SDK from, how to connect with the Vulkan Loader library, how to select the physical device on which operations will be performed, and how to prepare and create a logical device.

Chapter 2, Image Presentation, describes how to display Vulkan‑generated images on screen. It explains what a swapchain is and what parameters are required to create it, so we can use it for rendering and see the results of our work.

Chapter 3, Command Buffers and Synchronization, is about recording various operations into command buffers and submitting them to queues, where they are processed by the hardware. Also, various synchronization mechanisms are presented in this chapter.

Chapter 4, Resources and Memory, presents two basic and most important resource types, images and buffers, which allow us to store data. We explain how to create them, how to prepare memory for these resources, and, also, how to upload data to them from our application (CPU).

Chapter 5, Descriptor Sets, explains how to provide created resource to shaders. We explain how to prepare resources so they can be used inside shaders and how to set up descriptor sets, which form the interface between the application and the shaders.

Chapter 6, Render Passes and Framebuffers, shows how to organize drawing operations into sets of separate steps called subpasses, which are organized into render passes. In this chapter we also show how to prepare descriptions of attachments (render targets) used during drawing and how to create framebuffers, which bind specific resources according to these descriptions.

Chapter 7, Shaders, describes the specifics of programming all available graphics and compute shader stages. This chapter presents how to implement shader programs using GLSL programming language and how to convert them into SPIR‑V assemblies – the only form core Vulkan API accepts.

Chapter 8, Graphics and Compute Pipelines, presents the process of creating two available pipeline types. They are used to set up all the parameters graphics hardware needs to properly process drawing commands or computational work.

Chapter 9, Command Recording and Drawing, is about recording all the operations needed to successfully draw 3D models or dispatch computational work. Also, various optimization techniques are presented in this chapter, which can help increase the performance of the application.

Chapter 10, Helper Recipes, shows convenient set of tools no 3D rendering application can do without. It is shown how to load textures and 3D models from files and how to manipulate the geometry inside shaders.

Chapter 11, Lighting, presents commonly used lighting techniques from simple diffuse and specular lighting calculations to normal mapping and shadow mapping techniques.

Chapter 12, Advanced Rendering Techniques, explains how to implement impressive graphics techniques, which can be found in many popular 3D applications such as games and benchmarks.

What you need for this book

This book explains various aspects of the Vulkan graphics API, which is open and multiplatform. It is available on Microsoft Windows (version 7 and newer) or Linux (preferably Ubuntu 16.04 or newer) systems. (Vulkan is also supported on Android devices with the 7.0+ / Nougat version of the operating system, but the code samples available with this book weren’t designed to be executed on the Android OS.)

To execute sample programs or to develop our own applications, apart from Windows 7+ or Linux operating systems, graphics hardware and drivers that support Vulkan API are also required. Refer to 3D graphics vendors’ sites and/or support to check which hardware is capable of running Vulkan‑enabled software.

When using the Windows operating system, code samples can be compiled using the Visual Studio Community 2015 IDE (or newer), which is free and available for everyone. To generate a solution for the Visual Studio IDE the CMAKE 3.0 or newer is required.

On Linux systems, compilation is performed using a combination of the CMAKE 3.0 and the make tool. But the samples can also be compiled using other tools such as QtCreator.

Who this book is for

This book is ideal for developers who know C/C++ languages, have some basic familiarity with graphics programming, and now want to take advantage of the new Vulkan API in the process of building next generation computer graphics. Some basic familiarity with Vulkan would be useful to follow the recipes. OpenGL developers who want to take advantage of the Vulkan API will also find this book useful.

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, we 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 the reader more knowledgeable about the recipe.

See also

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

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Just assign the names of the layers you want to activate to the VK_INSTANCE_LAYERS environment variable"

A block of code is set as follows:

{
 if( (result != VK_SUCCESS) || 
    (extensions_count == 0) ) { 
  std::cout << "Could not enumerate device extensions." << std::endl; 
  return false;
} 

Any command-line input or output is written as follows:

setx VK_INSTANCE_LAYERS VK_LAYER_LUNARG_api_dump;VK_LAYER_LUNARG_core_validation

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Select System info from the Administration panel."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors .

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Vulkan-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book 

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/VulkanCookbook_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.

lock icon The rest of the chapter is locked
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.
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
Visually different images