1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2016 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef GrVkBackendContext_DEFINED
9cb93a386Sopenharmony_ci#define GrVkBackendContext_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h"
12cb93a386Sopenharmony_ci#include "include/gpu/vk/GrVkMemoryAllocator.h"
13cb93a386Sopenharmony_ci#include "include/gpu/vk/GrVkTypes.h"
14cb93a386Sopenharmony_ci
15cb93a386Sopenharmony_ciclass GrVkExtensions;
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_cienum GrVkExtensionFlags {
18cb93a386Sopenharmony_ci    kEXT_debug_report_GrVkExtensionFlag    = 0x0001,
19cb93a386Sopenharmony_ci    kNV_glsl_shader_GrVkExtensionFlag      = 0x0002,
20cb93a386Sopenharmony_ci    kKHR_surface_GrVkExtensionFlag         = 0x0004,
21cb93a386Sopenharmony_ci    kKHR_swapchain_GrVkExtensionFlag       = 0x0008,
22cb93a386Sopenharmony_ci    kKHR_win32_surface_GrVkExtensionFlag   = 0x0010,
23cb93a386Sopenharmony_ci    kKHR_android_surface_GrVkExtensionFlag = 0x0020,
24cb93a386Sopenharmony_ci    kKHR_xcb_surface_GrVkExtensionFlag     = 0x0040,
25cb93a386Sopenharmony_ci    kKHR_ohos_surface_GrVkExtensionFlag    = 0x0080,
26cb93a386Sopenharmony_ci};
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_cienum GrVkFeatureFlags {
29cb93a386Sopenharmony_ci    kGeometryShader_GrVkFeatureFlag    = 0x0001,
30cb93a386Sopenharmony_ci    kDualSrcBlend_GrVkFeatureFlag      = 0x0002,
31cb93a386Sopenharmony_ci    kSampleRateShading_GrVkFeatureFlag = 0x0004,
32cb93a386Sopenharmony_ci};
33cb93a386Sopenharmony_ci
34cb93a386Sopenharmony_ci// It is not guarenteed VkPhysicalDeviceProperties2 will be in the client's header so we forward
35cb93a386Sopenharmony_ci// declare it here to be safe.
36cb93a386Sopenharmony_cistruct VkPhysicalDeviceFeatures2;
37cb93a386Sopenharmony_ci
38cb93a386Sopenharmony_ci// The BackendContext contains all of the base Vulkan objects needed by the GrVkGpu. The assumption
39cb93a386Sopenharmony_ci// is that the client will set these up and pass them to the GrVkGpu constructor. The VkDevice
40cb93a386Sopenharmony_ci// created must support at least one graphics queue, which is passed in as well.
41cb93a386Sopenharmony_ci// The QueueFamilyIndex must match the family of the given queue. It is needed for CommandPool
42cb93a386Sopenharmony_ci// creation, and any GrBackendObjects handed to us (e.g., for wrapped textures) needs to be created
43cb93a386Sopenharmony_ci// in or transitioned to that family. The refs held by members of this struct must be released
44cb93a386Sopenharmony_ci// (either by deleting the struct or manually releasing the refs) before the underlying vulkan
45cb93a386Sopenharmony_ci// device and instance are destroyed.
46cb93a386Sopenharmony_cistruct SK_API GrVkBackendContext {
47cb93a386Sopenharmony_ci    VkInstance                       fInstance;
48cb93a386Sopenharmony_ci    VkPhysicalDevice                 fPhysicalDevice;
49cb93a386Sopenharmony_ci    VkDevice                         fDevice;
50cb93a386Sopenharmony_ci    VkQueue                          fQueue;
51cb93a386Sopenharmony_ci    uint32_t                         fGraphicsQueueIndex;
52cb93a386Sopenharmony_ci    uint32_t                         fMinAPIVersion; // Deprecated. Set fInstanceVersion instead.
53cb93a386Sopenharmony_ci    uint32_t                         fInstanceVersion = 0; // Deprecated. Set fMaxApiVersion instead
54cb93a386Sopenharmony_ci    // The max api version set here should match the value set in VkApplicationInfo::apiVersion when
55cb93a386Sopenharmony_ci    // then VkInstance was created.
56cb93a386Sopenharmony_ci    uint32_t                         fMaxAPIVersion = 0;
57cb93a386Sopenharmony_ci    uint32_t                         fExtensions = 0; // Deprecated. Use fVkExtensions instead.
58cb93a386Sopenharmony_ci    const GrVkExtensions*            fVkExtensions = nullptr;
59cb93a386Sopenharmony_ci    uint32_t                         fFeatures; // Deprecated. Use fDeviceFeatures[2] instead.
60cb93a386Sopenharmony_ci    // The client can create their VkDevice with either a VkPhysicalDeviceFeatures or
61cb93a386Sopenharmony_ci    // VkPhysicalDeviceFeatures2 struct, thus we have to support taking both. The
62cb93a386Sopenharmony_ci    // VkPhysicalDeviceFeatures2 struct is needed so we know if the client enabled any extension
63cb93a386Sopenharmony_ci    // specific features. If fDeviceFeatures2 is not null then we ignore fDeviceFeatures. If both
64cb93a386Sopenharmony_ci    // fDeviceFeatures and fDeviceFeatures2 are null we will assume no features are enabled.
65cb93a386Sopenharmony_ci    const VkPhysicalDeviceFeatures*  fDeviceFeatures = nullptr;
66cb93a386Sopenharmony_ci    const VkPhysicalDeviceFeatures2* fDeviceFeatures2 = nullptr;
67cb93a386Sopenharmony_ci    sk_sp<GrVkMemoryAllocator>       fMemoryAllocator;
68cb93a386Sopenharmony_ci    GrVkGetProc                      fGetProc = nullptr;
69cb93a386Sopenharmony_ci    // This is deprecated and should be set to false. The client is responsible for managing the
70cb93a386Sopenharmony_ci    // lifetime of the VkInstance and VkDevice objects.
71cb93a386Sopenharmony_ci    bool                             fOwnsInstanceAndDevice = false;
72cb93a386Sopenharmony_ci    // Indicates that we are working with protected content and all CommandPool and Queue operations
73cb93a386Sopenharmony_ci    // should be done in a protected context.
74cb93a386Sopenharmony_ci    GrProtected                      fProtectedContext = GrProtected::kNo;
75cb93a386Sopenharmony_ci};
76cb93a386Sopenharmony_ci
77cb93a386Sopenharmony_ci#endif
78