• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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::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
36When using the Vulkan backend, GrVkImageInfo is used to construct GrBackendTexture
37and GrBackendRenderTarget objects that in turn are used to create SkSurface and SkImage
38objects that refer to VkImages created by the Skia client.
39
40The GrBackendObject returned by SkImage::getTextureHandle(),
41SkSurface::getTextureHandle(), and SkSurface::getRenderTargetHandle() should be
42interpreted as a GrVkImageInfo*. This allows a client to get the backing VkImage
43of a SkImage or SkSurface.
44
45GrVkImageInfo specifies a VkImage and associated state (tiling, layout, format, etc).
46After getting a GrVkImageInfo* via getTextureHandle() or
47getRenderTargetHandle(), the client should check the fImageLayout field to know
48what layout Skia left the VkImage in before using the VkImage. If the client
49changes the layout of the VkImage,
50GrVkImageInfo::updateImageLayout(VkImageLayout layout) should be called before
51resuming Skia rendering.
52
53The client is responsible for any synchronization or barriers needed before
54Skia performs I/O on a VkImage imported into Skia via GrVkImageInfo.  Skia will
55assume it can start issuing commands referencing the VkImage without the need
56for additional synchronization.
57