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