1 Vulkan 2 ====== 3 4 Skia has a Vulkan implementation of its GPU backend. The Vulkan backend can be 5 built alongside the OpenGL backend. The client can select between the OpenGL 6 and Vulkan implementation at runtime. The Vulkan backend has reached feature 7 parity with the OpenGL backend. At this time we find that many Vulkan drivers 8 have bugs that Skia triggers for which we have no workaround. We are reporting 9 bugs to vendors as we find them. 10 11 Windows and Linux 12 ----------------- 13 To build the Vulkan backend, set `skia_use_vulkan=true` in `args.gn`. 14 15 Android 16 ------- 17 The Vulkan backend can run on any device with Vulkan drivers, including all Android N+ devices. 18 To build the Vulkan backend, set `ndk_api = 24` in `args.gn` to target Android N. 19 20 Using the Vulkan Backend 21 ------------------------ 22 23 To create a GrContext that is backed by Vulkan the client creates a Vulkan device and queue, initializes a GrVkBackendContext to describe the context, and then calls GrContext::MakeVulkan: 24 25 <!--?prettify lang=c++?--> 26 sk_sp<GrVkBackendContext> vkContext = new GrVkBackendContext; 27 vkBackendContext.fInstance = vkInstance; 28 vkBackendContext.fPhysicalDevice = vkPhysDevice; 29 ... 30 vkBackendContext.fInterface.reset(GrVkCreateInterface(instance, vkPhysDevice, extensionFlags); 31 ... 32 33 sk_sp<GrContext> context = GrContext::MakeVulkan(vkBackendContext); 34 35 When using the Vulkan backend, GrVkImageInfo is used to construct GrBackendTexture 36 and GrBackendRenderTarget objects that in turn are used to create SkSurface and SkImage 37 objects that refer to VkImages created by the Skia client. 38 39 The GrBackendObject returned by SkImage::getTextureHandle(), 40 SkSurface::getTextureHandle(), and SkSurface::getRenderTargetHandle() should be 41 interpreted as a GrVkImageInfo*. This allows a client to get the backing VkImage 42 of a SkImage or SkSurface. 43 44 GrVkImageInfo specifies a VkImage and associated state (tiling, layout, format, etc). 45 After getting a GrVkImageInfo* via getTextureHandle() or 46 getRenderTargetHandle(), the client should check the fImageLayout field to know 47 what layout Skia left the VkImage in before using the VkImage. If the client 48 changes the layout of the VkImage, 49 GrVkImageInfo::updateImageLayout(VkImageLayout layout) should be called before 50 resuming Skia rendering. 51 52 The client is responsible for any synchronization or barriers needed before 53 Skia performs I/O on a VkImage imported into Skia via GrVkImageInfo. Skia will 54 assume it can start issuing commands referencing the VkImage without the need 55 for additional synchronization. 56