Book description
Work through recipes to unlock the full potential of the next generation graphics API—Vulkan
About This Book
This book explores a wide range of modern graphics programming techniques and GPU compute methods to make the best use of the Vulkan API
Learn techniques that can be applied to a wide range of platforms desktop, smartphones, and embedded devices
Get an idea on the graphics engine with multi-platform support and learn exciting imaging processing and post-processing techniques
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 of 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.
What You Will Learn
Work with Swapchain to present images on screen
Create, submit, and synchronize operations processed by the hardware
Create buffers and images, manage their memory, and upload data to them from CPU
Explore descriptor sets and set up an interface between application and shaders
Organize drawing operations into a set of render passes and subpasses
Prepare graphics pipelines to draw 3D scenes and compute pipelines to perform mathematical calculations
Implement geometry projection and tessellation, texturing, lighting, and post-processing techniques
Write shaders in GLSL and convert them into SPIR-V assemblies
Find out about and implement a collection of popular, advanced rendering techniques found in games and benchmarks
In Detail
Vulkan is the next generation graphics API released by the Khronos group. It is expected to be the successor to OpenGL and OpenGL ES, which it shares some similarities with such as its cross-platform capabilities, programmed pipeline stages, or nomenclature. Vulkan is a low-level API that gives developers much more control over the hardware, but also adds new responsibilities such as explicit memory and resources management. With it, though, Vulkan is expected to be much faster.
This book is your guide to understanding Vulkan through a series of recipes. We start off by teaching you how to create instances in Vulkan and choose the device on which operations will be performed. You will then explore more complex topics such as command buffers, resources and memory management, pipelines, GLSL shaders, render passes, and more. Gradually, the book moves on to teach you advanced rendering techniques, how to draw 3D scenes, and how to improve the performance of your applications.
By the end of the book, you will be familiar with the latest advanced techniques implemented with the Vulkan API, which can be used on a wide range of platforms.
Style and approach
This recipe-based guide will empower you to implement modern graphic programming techniques and help gain a solid understanding of the new Vulkan API.
Table of contents
- Preface
-
Instance and Devices
- Introduction
- Downloading Vulkan's SDK
- Enabling validation layers
- Connecting with a Vulkan Loader library
- Preparing for loading Vulkan API functions
- Loading functions exported from a Vulkan Loader library
- Loading global-level functions
- Checking available Instance extensions
- Creating a Vulkan Instance
- Loading instance-level functions
- Enumerating available physical devices
- Checking available device extensions
- Getting features and properties of a physical device
- Checking available queue families and their properties
- Selecting the index of a queue family with the desired capabilities
- Creating a logical device
- Loading device-level functions
- Getting a device queue
- Creating a logical device with geometry shaders, graphics, and compute queues
- Destroying a logical device
- Destroying a Vulkan Instance
- Releasing a Vulkan Loader library
-
Image Presentation
- Introduction
- Creating a Vulkan Instance with WSI extensions enabled
- Creating a presentation surface
- Selecting a queue family that supports presentation to a given surface
- Creating a logical device with WSI extensions enabled
- Selecting a desired presentation mode
- Getting the capabilities of a presentation surface
- Selecting a number of swapchain images
- Choosing a size of swapchain images
- Selecting desired usage scenarios of swapchain images
- Selecting a transformation of swapchain images
- Selecting a format of swapchain images
- Creating a swapchain
- Getting handles of swapchain images
- Creating a swapchain with R8G8B8A8 format and a mailbox present mode
- Acquiring a swapchain image
- Presenting an image
- Destroying a swapchain
- Destroying a presentation surface
-
Command Buffers and Synchronization
- Introduction
- Creating a command pool
- Allocating command buffers
- Beginning a command buffer recording operation
- Ending a command buffer recording operation
- Resetting a command buffer
- Resetting a command pool
- Creating a semaphore
- Creating a fence
- Waiting for fences
- Resetting fences
- Submitting command buffers to a queue
- Synchronizing two command buffers
- Checking if processing of a submitted command buffer has finished
- Waiting until all commands submitted to a queue are finished
- Waiting for all submitted commands to be finished
- Destroying a fence
- Destroying a semaphore
- Freeing command buffers
- Destroying a command pool
-
Resources and Memory
- Introduction
- Creating a buffer
- Allocating and binding a memory object for a buffer
- Setting a buffer memory barrier
- Creating a buffer view
- Creating an image
- Allocating and binding a memory object to an image
- Setting an image memory barrier
- Creating an image view
- Creating a 2D image and view
- Creating a layered 2D image with a CUBEMAP view
- Mapping, updating and unmapping host-visible memory
- Copying data between buffers
- Copying data from a buffer to an image
- Copying data from an image to a buffer
- Using a staging buffer to update a buffer with a device-local memory bound
- Using a staging buffer to update an image with a device-local memory bound
- Destroying an image view
- Destroying an image
- Destroying a buffer view
- Freeing a memory object
- Destroying a buffer
-
Descriptor Sets
- Introduction
- Creating a sampler
- Creating a sampled image
- Creating a combined image sampler
- Creating a storage image
- Creating a uniform texel buffer
- Creating a storage texel buffer
- Creating a uniform buffer
- Creating a storage buffer
- Creating an input attachment
- Creating a descriptor set layout
- Creating a descriptor pool
- Allocating descriptor sets
- Updating descriptor sets
- Binding descriptor sets
- Creating descriptors with a texture and a uniform buffer
- Freeing descriptor sets
- Resetting a descriptor pool
- Destroying a descriptor pool
- Destroying a descriptor set layout
- Destroying a sampler
-
Render Passes and Framebuffers
- Introduction
- Specifying attachments descriptions
- Specifying subpass descriptions
- Specifying dependencies between subpasses
- Creating a render pass
- Creating a framebuffer
- Preparing a render pass for geometry rendering and postprocess subpasses
- Preparing a render pass and a framebuffer with color and depth attachments
- Beginning a render pass
- Progressing to the next subpass
- Ending a render pass
- Destroying a framebuffer
- Destroying a render pass
-
Shaders
- Introduction
- Converting GLSL shaders to SPIR-V assemblies
- Writing vertex shaders
- Writing tessellation control shaders
- Writing tessellation evaluation shaders
- Writing geometry shaders
- Writing fragment shaders
- Writing compute shaders
- Writing a vertex shader that multiplies vertex position by a projection matrix
- Using push constants in shaders
- Writing texturing vertex and fragment shaders
- Displaying polygon normals with a geometry shader
-
Graphics and Compute Pipelines
- Introduction
- Creating a shader module
- Specifying pipeline shader stages
- Specifying a pipeline vertex binding description, attribute description, and input state
- Specifying a pipeline input assembly state
- Specifying a pipeline tessellation state
- Specifying a pipeline viewport and scissor test state
- Specifying a pipeline rasterization state
- Specifying a pipeline multisample state
- Specifying a pipeline depth and stencil state
- Specifying a pipeline blend state
- Specifying pipeline dynamic states
- Creating a pipeline layout
- Specifying graphics pipeline creation parameters
- Creating a pipeline cache object
- Retrieving data from a pipeline cache
- Merging multiple pipeline cache objects
- Creating a graphics pipeline
- Creating a compute pipeline
- Binding a pipeline object
- Creating a pipeline layout with a combined image sampler, a buffer, and push constant ranges
- Creating a graphics pipeline with vertex and fragment shaders, depth test enabled, and with dynamic viewport and scissor tests
- Creating multiple graphics pipelines on multiple threads
- Destroying a pipeline
- Destroying a pipeline cache
- Destroying a pipeline layout
- Destroying a shader module
-
Command Recording and Drawing
- Introduction
- Clearing a color image
- Clearing a depth-stencil image
- Clearing render pass attachments
- Binding vertex buffers
- Binding an index buffer
- Providing data to shaders through push constants
- Setting viewport states dynamically
- Setting scissor states dynamically
- Setting line width states dynamically
- Setting depth bias states dynamically
- Setting blend constants states dynamically
- Drawing a geometry
- Drawing an indexed geometry
- Dispatching compute work
- Executing a secondary command buffer inside a primary command buffer
- Recording a command buffer that draws a geometry with dynamic viewport and scissor states
- Recording command buffers on multiple threads
- Preparing a single frame of animation
- Increasing the performance through increasing the number of separately rendered frames
- Helper Recipes
- Lighting
- Advanced Rendering Techniques
Product information
- Title: Vulkan Cookbook
- Author(s):
- Release date: April 2017
- Publisher(s): Packt Publishing
- ISBN: 9781786468154
You might also like
book
The Modern Vulkan Cookbook
Discover essential real-time rendering techniques, curated by industry-leading computer graphics professionals, with over 60 recipes for …
book
Hands-On High Performance Programming with Qt 5
Build efficient and fast Qt applications, target performance problems, and discover solutions to refine your code …
book
OpenCV 3 Computer Vision with Python Cookbook
Recipe-based approach to tackle the most common problems in Computer Vision by leveraging the functionality of …
book
C++ Quick Syntax Reference
The C++ Quick Syntax Reference is a condensed code and syntax reference to the C++ programming …