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 "SkRefCnt.h" 12 13 #include "vk/GrVkDefines.h" 14 15 struct GrVkInterface; 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 }; 26 27 enum GrVkFeatureFlags { 28 kGeometryShader_GrVkFeatureFlag = 0x0001, 29 kDualSrcBlend_GrVkFeatureFlag = 0x0002, 30 kSampleRateShading_GrVkFeatureFlag = 0x0004, 31 }; 32 33 // The BackendContext contains all of the base Vulkan objects needed by the GrVkGpu. The assumption 34 // is that the client will set these up and pass them to the GrVkGpu constructor. The VkDevice 35 // created must support at least one graphics queue, which is passed in as well. 36 // The QueueFamilyIndex must match the family of the given queue. It is needed for CommandPool 37 // creation, and any GrBackendObjects handed to us (e.g., for wrapped textures) need to be created 38 // in or transitioned to that family. 39 struct GrVkBackendContext : public SkRefCnt { 40 VkInstance fInstance; 41 VkPhysicalDevice fPhysicalDevice; 42 VkDevice fDevice; 43 VkQueue fQueue; 44 uint32_t fGraphicsQueueIndex; 45 uint32_t fMinAPIVersion; 46 uint32_t fExtensions; 47 uint32_t fFeatures; 48 sk_sp<const GrVkInterface> fInterface; 49 50 using CanPresentFn = std::function<bool(VkInstance, VkPhysicalDevice, 51 uint32_t queueFamilyIndex)>; 52 53 // Helper function to create the default Vulkan objects needed by the GrVkGpu object 54 // If presentQueueIndex is non-NULL, will try to set up presentQueue as part of device 55 // creation using the platform-specific canPresent() function. 56 static const GrVkBackendContext* Create(uint32_t* presentQueueIndex = nullptr, 57 CanPresentFn = CanPresentFn()); 58 59 ~GrVkBackendContext() override; 60 }; 61 62 #endif 63