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