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