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_vulkan_sdk` to the path to your Vulkan SDK in `args.gn`. 14 This defaults to the environment variable `VULKAN_SDK`. 15 16 Android 17 ------- 18 The Vulkan backend can run on any device with Vulkan drivers, including all Android N+ devices. 19 To build the Vulkan backend, set `ndk_api = 24` in `args.gn` to target Android N. 20 21 Using the Vulkan Backend 22 ------------------------ 23 24 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: 25 26 <!--?prettify lang=c++?--> 27 sk_sp<GrVkBackendContext> vkContext = new GrVkBackendContext; 28 vkBackendContext.fInstance = vkInstance; 29 vkBackendContext.fPhysicalDevice = vkPhysDevice; 30 ... 31 vkBackendContext.fInterface.reset(GrVkCreateInterface(instance, vkPhysDevice, extensionFlags); 32 ... 33 34 sk_sp<GrContext> context = GrContext::MakeVulkan(vkBackendContext); 35 36 When using the Vulkan backend, GrVkImageInfo is used to construct GrBackendTexture 37 and GrBackendRenderTarget objects that in turn are used to create SkSurface and SkImage 38 objects that refer to VkImages created by the Skia client. 39 40 The GrBackendObject returned by SkImage::getTextureHandle(), 41 SkSurface::getTextureHandle(), and SkSurface::getRenderTargetHandle() should be 42 interpreted as a GrVkImageInfo*. This allows a client to get the backing VkImage 43 of a SkImage or SkSurface. 44 45 GrVkImageInfo specifies a VkImage and associated state (tiling, layout, format, etc). 46 After getting a GrVkImageInfo* via getTextureHandle() or 47 getRenderTargetHandle(), the client should check the fImageLayout field to know 48 what layout Skia left the VkImage in before using the VkImage. If the client 49 changes the layout of the VkImage, 50 GrVkImageInfo::updateImageLayout(VkImageLayout layout) should be called before 51 resuming Skia rendering. 52 53 The client is responsible for any synchronization or barriers needed before 54 Skia performs I/O on a VkImage imported into Skia via GrVkImageInfo. Skia will 55 assume it can start issuing commands referencing the VkImage without the need 56 for additional synchronization. 57