1Vulkan 2====== 3 4Skis 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_vulkan_sdk` to the path to your Vulkan SDK in `args.gn`. 14This defaults to the environment variable `VULKAN_SDK`. 15 16Android 17------- 18The Vulkan backend can run on any device with Vulkan drivers, including all Android N+ devices. 19To build the Vulkan backend, set `ndk_api = 24` in `args.gn` to target Android N. 20 21Using the Vulkan Backend 22------------------------ 23 24To 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::Create: 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::Create(kVulkan_GrBackend, (GrBackendContext) vkBackendContext); 35 36When using the Vulkan backend the GrBackendObject field in 37GrBackendRenderTargetDesc and GrBackendTextureDesc is interpeted as a pointer 38to a GrVkImageInfo object. GrVkImageInfo specifies a VkImage and associated 39state (tiling, layout, format, etc). This allows the client to import 40externally created Vulkan images as destinations for Skia rendering via 41SkSurface factory functions or for to composite Skia rendered content using 42SkImage::getTextureHandle(). 43 44After getting a GrVkImageInfo* via getTextureHandle() or 45getRenderTargetHandle(), the client should check the fImageLayout field to know 46what layout Skia left the VkImage in before using the VkImage. If the client 47changes the layout of the VkImage, 48GrVkImageInfo::updateImageLayout(VkImageLayout layout) should be called before 49resuming Skia rendering. 50 51The client is responsible for any synchronization or barriers needed before 52Skia performs I/O on a VkImage imported into Skia via GrVkImageInfo. Skia will 53assume it can start issuing commands referencing the VkImage without the need 54for additional synchronization. 55