xref: /aosp_15_r20/external/skia/include/gpu/vk/VulkanBackendContext.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2022 Google LLC
3*c8dee2aaSAndroid Build Coastguard Worker  *
4*c8dee2aaSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker  * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker  */
7*c8dee2aaSAndroid Build Coastguard Worker 
8*c8dee2aaSAndroid Build Coastguard Worker #ifndef skgpu_VulkanBackendContext_DEFINED
9*c8dee2aaSAndroid Build Coastguard Worker #define skgpu_VulkanBackendContext_DEFINED
10*c8dee2aaSAndroid Build Coastguard Worker 
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkRefCnt.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/GpuTypes.h"
13*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/vk/VulkanMemoryAllocator.h"
14*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/vk/VulkanTypes.h"
15*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/base/SkAPI.h"
16*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/gpu/vk/SkiaVulkan.h"
17*c8dee2aaSAndroid Build Coastguard Worker 
18*c8dee2aaSAndroid Build Coastguard Worker #include <cstdint>
19*c8dee2aaSAndroid Build Coastguard Worker 
20*c8dee2aaSAndroid Build Coastguard Worker namespace skgpu {
21*c8dee2aaSAndroid Build Coastguard Worker 
22*c8dee2aaSAndroid Build Coastguard Worker class VulkanExtensions;
23*c8dee2aaSAndroid Build Coastguard Worker 
24*c8dee2aaSAndroid Build Coastguard Worker // The VkBackendContext contains all of the base Vk objects needed by the skia Vulkan context.
25*c8dee2aaSAndroid Build Coastguard Worker struct SK_API VulkanBackendContext {
26*c8dee2aaSAndroid Build Coastguard Worker     VkInstance                       fInstance = VK_NULL_HANDLE;
27*c8dee2aaSAndroid Build Coastguard Worker     VkPhysicalDevice                 fPhysicalDevice = VK_NULL_HANDLE;
28*c8dee2aaSAndroid Build Coastguard Worker     VkDevice                         fDevice = VK_NULL_HANDLE;
29*c8dee2aaSAndroid Build Coastguard Worker     VkQueue                          fQueue = VK_NULL_HANDLE;
30*c8dee2aaSAndroid Build Coastguard Worker     uint32_t                         fGraphicsQueueIndex = 0;
31*c8dee2aaSAndroid Build Coastguard Worker     // The max api version set here should match the value set in VkApplicationInfo::apiVersion when
32*c8dee2aaSAndroid Build Coastguard Worker     // then VkInstance was created.
33*c8dee2aaSAndroid Build Coastguard Worker     uint32_t                         fMaxAPIVersion = 0;
34*c8dee2aaSAndroid Build Coastguard Worker     const skgpu::VulkanExtensions*   fVkExtensions = nullptr;
35*c8dee2aaSAndroid Build Coastguard Worker     // The client can create their VkDevice with either a VkPhysicalDeviceFeatures or
36*c8dee2aaSAndroid Build Coastguard Worker     // VkPhysicalDeviceFeatures2 struct, thus we have to support taking both. The
37*c8dee2aaSAndroid Build Coastguard Worker     // VkPhysicalDeviceFeatures2 struct is needed so we know if the client enabled any extension
38*c8dee2aaSAndroid Build Coastguard Worker     // specific features. If fDeviceFeatures2 is not null then we ignore fDeviceFeatures. If both
39*c8dee2aaSAndroid Build Coastguard Worker     // fDeviceFeatures and fDeviceFeatures2 are null we will assume no features are enabled.
40*c8dee2aaSAndroid Build Coastguard Worker     const VkPhysicalDeviceFeatures*  fDeviceFeatures = nullptr;
41*c8dee2aaSAndroid Build Coastguard Worker     const VkPhysicalDeviceFeatures2* fDeviceFeatures2 = nullptr;
42*c8dee2aaSAndroid Build Coastguard Worker     // Optional. The client may provide an inplementation of a VulkanMemoryAllocator for Skia to use
43*c8dee2aaSAndroid Build Coastguard Worker     // for allocating Vulkan resources that use VkDeviceMemory.
44*c8dee2aaSAndroid Build Coastguard Worker     sk_sp<VulkanMemoryAllocator>     fMemoryAllocator;
45*c8dee2aaSAndroid Build Coastguard Worker     skgpu::VulkanGetProc             fGetProc;
46*c8dee2aaSAndroid Build Coastguard Worker     Protected                        fProtectedContext = Protected::kNo;
47*c8dee2aaSAndroid Build Coastguard Worker     // Optional callback which will be invoked if a VK_ERROR_DEVICE_LOST error code is received from
48*c8dee2aaSAndroid Build Coastguard Worker     // the driver. Debug information from the driver will be provided to the callback if the
49*c8dee2aaSAndroid Build Coastguard Worker     // VK_EXT_device_fault extension is supported and enabled (VkPhysicalDeviceFaultFeaturesEXT must
50*c8dee2aaSAndroid Build Coastguard Worker     // be in the pNext chain of VkDeviceCreateInfo).
51*c8dee2aaSAndroid Build Coastguard Worker     skgpu::VulkanDeviceLostContext   fDeviceLostContext = nullptr;
52*c8dee2aaSAndroid Build Coastguard Worker     skgpu::VulkanDeviceLostProc      fDeviceLostProc = nullptr;
53*c8dee2aaSAndroid Build Coastguard Worker };
54*c8dee2aaSAndroid Build Coastguard Worker 
55*c8dee2aaSAndroid Build Coastguard Worker }  // namespace skgpu
56*c8dee2aaSAndroid Build Coastguard Worker 
57*c8dee2aaSAndroid Build Coastguard Worker #endif // skgpu_VulkanBackendContext_DEFINED
58