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