Vulkan Cookbook

Work through recipes to unlock the full potential of the next generation graphics API—Vulkan

Vulkan Cookbook

This ebook is included in a Mapt subscription
Pawel Lapinski

Work through recipes to unlock the full potential of the next generation graphics API—Vulkan
$0.00
$39.99
$49.99
$1,200.00p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781786468154
Paperback700 pages

Book Description

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.

Table of Contents

Chapter 1: 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
Chapter 2: 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
Chapter 3: 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
Chapter 4: 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
Chapter 5: 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
Chapter 6: 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
Chapter 7: 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
Chapter 8: 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
Chapter 9: 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
Chapter 10: Helper Recipes
Introduction
Preparing a translation matrix
Preparing a rotation matrix
Preparing a scaling matrix
Preparing a perspective projection matrix
Preparing an orthographic projection matrix
Loading texture data from a file
Loading a 3D model from an OBJ file
Chapter 11: Lighting
Introduction
Rendering a geometry with a vertex diffuse lighting
Rendering a geometry with a fragment specular lighting
Rendering a normal mapped geometry
Drawing a reflective and refractive geometry using cubemaps
Adding shadows to the scene
Chapter 12: Advanced Rendering Techniques
Introduction
Drawing a skybox
Drawing billboards using geometry shaders
Drawing particles using compute and graphics pipelines
Rendering a tessellated terrain
Rendering a full-screen quad for post-processing
Using input attachments for a color correction post-process effect

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

Authors

Table of Contents

Chapter 1: 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
Chapter 2: 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
Chapter 3: 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
Chapter 4: 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
Chapter 5: 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
Chapter 6: 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
Chapter 7: 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
Chapter 8: 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
Chapter 9: 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
Chapter 10: Helper Recipes
Introduction
Preparing a translation matrix
Preparing a rotation matrix
Preparing a scaling matrix
Preparing a perspective projection matrix
Preparing an orthographic projection matrix
Loading texture data from a file
Loading a 3D model from an OBJ file
Chapter 11: Lighting
Introduction
Rendering a geometry with a vertex diffuse lighting
Rendering a geometry with a fragment specular lighting
Rendering a normal mapped geometry
Drawing a reflective and refractive geometry using cubemaps
Adding shadows to the scene
Chapter 12: Advanced Rendering Techniques
Introduction
Drawing a skybox
Drawing billboards using geometry shaders
Drawing particles using compute and graphics pipelines
Rendering a tessellated terrain
Rendering a full-screen quad for post-processing
Using input attachments for a color correction post-process effect

Book Details

ISBN 139781786468154
Paperback700 pages
Read More

Read More Reviews