logo资料库

Vulkan Cookbook.pdf

第1页 / 共692页
第2页 / 共692页
第3页 / 共692页
第4页 / 共692页
第5页 / 共692页
第6页 / 共692页
第7页 / 共692页
第8页 / 共692页
资料共692页,剩余部分请下载后查看
Cover
Copyright
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Customer Feedback
Table of Contents
Preface
Chapter 1: Instance and Devices
Introduction
Downloading Vulkan's SDK
Getting ready
How to do it...
How it works...
See also
Enabling validation layers
How to do it...
How it works...
See also
Connecting with a Vulkan Loader library
How to do it...
How it works...
See also
Preparing for loading Vulkan API functions
How to do it...
How it works...
See also
Loading functions exported from a Vulkan Loader library
How to do it...
How it works...
See also
Loading global-level functions
How to do it...
How it works...
See also
Checking available Instance extensions
How to do it...
How it works...
See also
Creating a Vulkan Instance
How to do it...
How it works...
See also
Loading instance-level functions
How to do it...
How it works...
See also
Enumerating available physical devices
How to do it...
How it works...
See also
Checking available device extensions
How to do it...
How it works...
See also
Getting features and properties of a physical device
How to do it...
How it works...
See also
Checking available queue families and their properties
How to do it...
How it works...
See also
Selecting the index of a queue family with the desired capabilities
How to do it...
How it works...
See also
Creating a logical device
Getting ready
How to do it...
How it works...
See also
Loading device-level functions
How to do it...
How it works...
See also
Getting a device queue
How to do it...
How it works...
See also
Creating a logical device with geometry shaders, graphics, and compute queues
How to do it...
How it works...
See also
Destroying a logical device
How to do it...
How it works...
See also
Destroying a Vulkan Instance
How to do it...
How it works...
See also
Releasing a Vulkan Loader library
How to do it...
How it works...
See also
Chapter 2: Image Presentation
Introduction
Creating a Vulkan Instance with WSI extensions enabled
How to do it...
How it works...
See also
Creating a presentation surface
Getting ready
How to do it...
How it works...
See also
Selecting a queue family that supports presentation to a given surface
How to do it...
How it works...
See also
Creating a logical device with WSI extensions enabled
How to do it...
How it works...
See also
Selecting a desired presentation mode
How to do it...
How it works...
See also
Getting the capabilities of a presentation surface
How to do it...
How it works...
See also
Selecting a number of swapchain images
How to do it...
How it works...
See also
Choosing a size of swapchain images
How to do it...
How it works...
See also
Selecting desired usage scenarios of swapchain images
How to do it...
How it works...
See also
Selecting a transformation of swapchain images
How to do it...
How it works...
See also
Selecting a format of swapchain images
Getting ready
How to do it...
How it works...
See also
Creating a swapchain
How to do it...
How it works...
See also
Getting handles of swapchain images
How to do it...
How it works...
See also
Creating a swapchain with R8G8B8A8 format and a mailbox present mode
How to do it...
How it works...
See also
Acquiring a swapchain image
Getting ready
How to do it...
How it works...
See also
Presenting an image
Getting ready
How to do it...
How it works...
See also
Destroying a swapchain
How to do it...
How it works...
See also
Destroying a presentation surface
How to do it...
How it works...
See also
Chapter 3: Command Buffers and Synchronization
Introduction
Creating a command pool
How to do it...
How it works...
See also
Allocating command buffers
How to do it...
How it works...
See also
Beginning a command buffer recording operation
How to do it...
How it works...
See also
Ending a command buffer recording operation
How to do it...
How it works...
See also
Resetting a command buffer
How to do it...
How it works...
See also
Resetting a command pool
How to do it...
How it works...
See also
Creating a semaphore
How to do it...
How it works...
See also
Creating a fence
How to do it...
How it works...
See also
Waiting for fences
How to do it...
How it works...
See also
Resetting fences
How to do it...
How it works...
See also
Submitting command buffers to a queue
Getting ready
How to do it...
How it works...
See also
Synchronizing two command buffers
Getting ready
How to do it...
How it works...
See also
Checking if processing of a submitted command buffer has finished
How to do it...
How it works...
See also
Waiting until all commands submitted to a queue are finished
How to do it...
How it works...
See also
Waiting for all submitted commands to be finished
How to do it...
How it works...
See also
Destroying a fence
How to do it...
How it works...
See also
Destroying a semaphore
How to do it...
How it works...
See also
Freeing command buffers
How to do it...
How it works...
See also
Destroying a command pool
How to do it...
How it works...
See also
Chapter 4: Resources and Memory
Introduction
Creating a buffer
How to do it...
How it works...
See also
Allocating and binding a memory object for a buffer
How to do it...
How it works...
There's more...
See also
Setting a buffer memory barrier
Getting ready
How to do it...
How it works...
There's more...
See also
Creating a buffer view
How to do it...
How it works...
See also
Creating an image
How to do it...
How it works...
See also
Allocating and binding a memory object to an image
How to do it...
How it works...
There's more...
See also
Setting an image memory barrier
Getting ready
How to do it...
How it works...
See also
Creating an image view
How to do it...
How it works...
See also
Creating a 2D image and view
How to do it...
How it works...
See also
Creating a layered 2D image with a CUBEMAP view
How to do it...
How it works...
See also
Mapping, updating and unmapping host-visible memory
How to do it...
How it works...
See also
Copying data between buffers
How to do it...
How it works...
See also
Copying data from a buffer to an image
How to do it...
How it works...
See also
Copying data from an image to a buffer
How to do it...
How it works...
See also
Using a staging buffer to update a buffer with a device-local memory bound
How to do it...
How it works...
See also
Using a staging buffer to update an image with a device-local memory bound
How to do it...
How it works...
See also
Destroying an image view
How to do it...
How it works...
See also
Destroying an image
How to do it...
How it works...
See also
Destroying a buffer view
How to do it...
How it works...
See also
Freeing a memory object
How to do it...
How it works...
See also
Destroying a buffer
How to do it...
How it works...
See also
Chapter 5: Descriptor Sets
Introduction
Creating a sampler
How to do it...
How it works...
See also
Creating a sampled image
How to do it...
How it works...
See also
Creating a combined image sampler
How to do it...
How it works...
See also
Creating a storage image
How to do it...
How it works...
See also
Creating a uniform texel buffer
How to do it...
How it works...
See also
Creating a storage texel buffer
How to do it...
How it works...
See also
Creating a uniform buffer
How to do it...
How it works...
See also
Creating a storage buffer
How to do it...
How it works...
See also
Creating an input attachment
How to do it...
How it works...
See also
Creating a descriptor set layout
How to do it...
How it works...
See also
Creating a descriptor pool
How to do it...
How it works...
See also
Allocating descriptor sets
How to do it...
How it works...
See also
Updating descriptor sets
Getting ready
How to do it...
How it works...
See also
Binding descriptor sets
How to do it...
How it works...
See also
Creating descriptors with a texture and a uniform buffer
How to do it...
How it works...
See also
Freeing descriptor sets
How to do it...
How it works...
See also
Resetting a descriptor pool
How to do it...
How it works...
See also
Destroying a descriptor pool
How to do it...
How it works...
See also
Destroying a descriptor set layout
How to do it...
How it works...
See also
Destroying a sampler
How to do it...
How it works...
See also
Chapter 6: Render Passes and Framebuffers
Introduction
Specifying attachments descriptions
How to do it...
How it works...
See also
Specifying subpass descriptions
Getting ready
How to do it...
How it works...
See also
Specifying dependencies between subpasses
How to do it...
How it works...
See also
Creating a render pass
Getting ready
How to do it...
How it works...
See also
Creating a framebuffer
How to do it...
How it works...
See also
Preparing a render pass for geometry rendering and postprocess subpasses
Getting ready
How to do it...
How it works...
See also
Preparing a render pass and a framebuffer with color and depth attachments
Getting ready
How to do it...
How it works...
See also
Beginning a render pass
How to do it...
How it works...
See also
Progressing to the next subpass
How to do it...
How it works...
See also
Ending a render pass
How to do it...
How it works...
See also
Destroying a framebuffer
How to do it...
How it works...
See also
Destroying a render pass
How to do it...
How it works...
See also
Chapter 7: Shaders
Introduction
Converting GLSL shaders to SPIR-V assemblies
How to do it...
How it works...
See also
Writing vertex shaders
How to do it...
How it works...
See also
Writing tessellation control shaders
How to do it...
How it works...
See also
Writing tessellation evaluation shaders
How to do it...
How it works...
See also
Writing geometry shaders
How to do it...
How it works...
See also
Writing fragment shaders
How to do it...
How it works...
See also
Writing compute shaders
How to do it...
How it works...
See also
Writing a vertex shader that multiplies vertex position by a projection matrix
How to do it...
How it works...
See also
Using push constants in shaders
How to do it...
How it works...
See also
Writing texturing vertex and fragment shaders
How to do it...
How it works...
See also
Displaying polygon normals with a geometry shader
How to do it...
How it works...
See also
Chapter 8: Graphics and Compute Pipelines
Introduction
Creating a shader module
How to do it...
How it works...
See also
Specifying pipeline shader stages
Getting ready
How to do it...
How it works...
See also
Specifying a pipeline vertex binding description, attribute description, and input state
How to do it...
How it works...
See also
Specifying a pipeline input assembly state
How to do it...
How it works...
See also
Specifying a pipeline tessellation state
How to do it...
How it works...
See also
Specifying a pipeline viewport and scissor test state
Getting ready
How to do it...
How it works...
See also
Specifying a pipeline rasterization state
How to do it...
How it works...
See also
Specifying a pipeline multisample state
How to do it...
How it works...
See also
Specifying a pipeline depth and stencil state
How to do it...
How it works...
See also
Specifying a pipeline blend state
How to do it...
How it works...
See also
Specifying pipeline dynamic states
How to do it...
How it works...
See also
Creating a pipeline layout
How to do it...
How it works...
See also
Specifying graphics pipeline creation parameters
How to do it...
How it works...
See also
Creating a pipeline cache object
How to do it...
How it works...
See also
Retrieving data from a pipeline cache
How to do it...
How it works...
See also
Merging multiple pipeline cache objects
How to do it...
How it works...
See also
Creating a graphics pipeline
How to do it...
How it works...
See also
Creating a compute pipeline
How to do it...
How it works...
See also
Binding a pipeline object
How to do it...
How it works...
See also
Creating a pipeline layout with a combined image sampler, a buffer, and push constant ranges
How to do it...
How it works...
See also
Creating a graphics pipeline with vertex and fragment shaders, depth test enabled, and with dynamic viewport and scissor tests
How to do it...
How it works...
See also
Creating multiple graphics pipelines on multiple threads
Getting ready
How to do it...
How it works...
See also
Destroying a pipeline
How to do it...
How it works...
See also
Destroying a pipeline cache
How to do it...
How it works...
See also
Destroying a pipeline layout
How to do it...
How it works...
See also
Destroying a shader module
How to do it...
How it works...
See also
Chapter 9: Command Recording and Drawing
Introduction
Clearing a color image
How to do it...
How it works...
See also
Clearing a depth-stencil image
How to do it...
How it works...
See also
Clearing render pass attachments
How to do it...
How it works...
See also
Binding vertex buffers
Getting ready
How to do it...
How it works...
See also
Binding an index buffer
How to do it...
How it works...
See also
Providing data to shaders through push constants
How to do it...
How it works...
See also
Setting viewport states dynamically
How to do it...
How it works...
See also
Setting scissor states dynamically
How to do it...
How it works...
See also
Setting line width states dynamically
How to do it...
How it works...
See also
Setting depth bias states dynamically
How to do it...
How it works...
See also
Setting blend constants states dynamically
How to do it...
How it works...
See also
Drawing a geometry
How to do it...
How it works...
See also
Drawing an indexed geometry
How to do it...
How it works...
See also
Dispatching compute work
How to do it...
How it works...
See also
Executing a secondary command buffer inside a primary command buffer
How to do it...
How it works...
See also
Recording a command buffer that draws a geometry with dynamic viewport and scissor states
Getting ready
How to do it...
How it works...
See also
Recording command buffers on multiple threads
Getting ready
How to do it...
How it works...
See also
Preparing a single frame of animation
How to do it...
How it works...
See also
Increasing the performance through increasing the number of separately rendered frames
Getting ready
How to do it...
How it works...
See also
Chapter 10: Helper Recipes
Introduction
Preparing a translation matrix
How to do it...
How it works...
See also
Preparing a rotation matrix
How to do it...
How it works...
See also
Preparing a scaling matrix
How to do it...
How it works...
See also
Preparing a perspective projection matrix
How to do it...
How it works...
See also
Preparing an orthographic projection matrix
How to do it...
How it works...
See also
Loading texture data from a file
Getting ready
How to do it...
How it works...
See also
Loading a 3D model from an OBJ file
Getting ready
How to do it...
How it works...
See also
Chapter 11: Lighting
Introduction
Rendering a geometry with a vertex diffuse lighting
Getting ready
How to do it...
How it works...
See also
Rendering a geometry with a fragment specular lighting
Getting ready
How to do it...
How it works...
See also
Rendering a normal mapped geometry
Getting ready
How to do it...
How it works...
See also
Drawing a reflective and refractive geometry using cubemaps
Getting ready
How to do it...
How it works...
See also
Adding shadows to the scene
Getting ready
How to do it...
How it works...
See also
Chapter 12: Advanced Rendering Techniques
Introduction
Drawing a skybox
Getting ready
How to do it...
How it works...
See also
Drawing billboards using geometry shaders
How to do it...
How it works...
See also
Drawing particles using compute and graphics pipelines
How to do it...
How it works...
See also
Rendering a tessellated terrain
Getting ready
How to do it...
How it works...
See also
Rendering a full-screen quad for post-processing
How to do it...
How it works...
See also
Using input attachments for a color correction post-process effect
How to do it...
How it works...
See also
Index
Vulkan 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 Pawel Lapinski Reviewer Chris Forbes Commissioning Editor Ashwin Nair Copy Editor Safis Editing Project Coordinator Ritika Manoj Proofreader Safis Editing Acquisition Editor Indexer Nitin Dasan Tejal Daruwale Soni Content Development Editor Production Coordinator Aditi Gour Arvindkumar Gupta Technical Editor Murtaza Tinwala Graphics 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. h t t p s ://w w w . p a c k t p u b . c o m /m a p t 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
分享到:
收藏