1page.title=Vulkan Design Guidelines 2@jd:body 3 4<div id="qv-wrapper"> 5 <div id="qv"> 6 <h2>On this page</h2> 7 8 <ol> 9 <li><a href="#apply">Apply Display Rotation During Rendering</a></li> 10 <li><a href="#minimize">Minimize Render Passes Per Frame</a></li> 11 <li><a href="#choose">Choose Appropriate Memory Types</a></li> 12 <li><a href="#group">Group Descriptor Sets by Frequency</a></li> 13 </ol> 14 </div> 15 </div> 16 17<p> 18Vulkan is unlike earlier graphics APIs in that drivers do not perform certain 19optimizations, such as pipeline reuse, for apps. Instead, apps using Vulkan must 20implement such optimizations themselves. If they do not, they may exhibit worse 21performance than apps running OpenGL ES. 22</p> 23 24<p> 25When apps implement these optimizations themselves, they have the potential 26to do so more successfully than the driver can, because they have access to 27more specific information for a given use case. As a result, skillfully 28optimizing an app that uses Vulkan can yield better performance than if the 29app were using OpenGL ES. 30</p> 31 32<p> 33This page introduces several optimizations that your Android app can implement 34to gain performance boosts from Vulkan. 35</p> 36 37<h2 id="apply">Apply Display Rotation During Rendering</h2> 38 39<p> 40When the upward-facing direction of an app doesn’t match the orientation of the device’s 41display, the compositor rotates the application’s swapchain images so that it 42does match. It performs this rotation as it displays the images, which results 43in more power consumption—sometimes significantly more—than if it were not 44rotating them. 45</p> 46 47<p> 48By contrast, rotating swapchain images while generating them results in 49little, if any, additional power consumption. The 50{@code VkSurfaceCapabilitiesKHR::currentTransform} field indicates the rotation 51that the compositor applies to the window. After an app applies that rotation 52during rendering, the app uses the {@code VkSwapchainCreateInfoKHR::preTransform} 53field to report that the rotation is complete. 54</p> 55 56<h2 id="minimize">Minimize Render Passes Per Frame</h2> 57 58<p> 59On most mobile GPU architectures, beginning and ending a render pass is an 60expensive operation. Your app can improve performance by organizing rendering operations into 61as few render passes as possible. 62</p> 63 64<p> 65Different attachment-load and attachment-store ops offer different levels of 66performance. For example, if you do not need to preserve the contents of an attachment, you 67can use the much faster {@code VK_ATTACHMENT_LOAD_OP_CLEAR} or 68{@code VK_ATTACHMENT_LOAD_OP_DONT_CARE} instead of {@code VK_ATTACHMENT_LOAD_OP_LOAD}. Similarly, if 69you don't need to write the attachment's final values to memory for later use, you can use 70{@code VK_ATTACHMENT_STORE_OP_DONT_CARE} to attain much better performance than 71{@code VK_ATTACHMENT_STORE_OP_STORE}. 72</p> 73 74<p> 75Also, in most render passes, your app doesn’t need to load or store the 76depth/stencil attachment. In such cases, you can avoid having to allocate physical memory for 77the attachment by using the {@code VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT} 78flag when creating the attachment image. This bit provides the same benefits as does 79{@code glFramebufferDiscard} in OpenGL ES. 80</p> 81 82<h2 id="choose">Choose Appropriate Memory Types</h2> 83 84<p> 85When allocating device memory, apps must choose a memory type. Memory type 86determines how an app can use the memory, and also describes caching and 87coherence properties of the memory. Different devices have different memory 88types available; different memory types exhibit different performance 89characteristics. 90</p> 91 92<p> 93An app can use a simple algorithm to pick the best memory type for a given 94use. This algorithm picks the first memory type in the 95{@code VkPhysicalDeviceMemoryProperties::memoryTypes} array that meets two criteria: 96The memory type must be allowed for the buffer 97or image, and must have the minimum properties that the app requires. 98</p> 99 100<p> 101Mobile systems generally don’t have separate physical memory heaps for the 102CPU and GPU. On such systems, {@code VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT} is not as 103significant as it is on systems that have discrete GPUs with their own, dedicated 104memory. An app should not assume this property is required. 105</p> 106 107<h2 id="group">Group Descriptor Sets by Frequency</h2> 108 109<p> 110If you have resource bindings that change at different frequencies, use 111multiple descriptor sets per pipeline rather than rebinding all resources for 112each draw. For example, you can have one set of descriptors for per-scene 113bindings, another set for per-material bindings, and a third set for 114per-mesh-instance bindings. 115</p> 116 117<p> 118Use immediate constants for the highest-frequency changes, such as changes 119executed with each draw call. 120</p> 121 122