25 {
30 SKGPU_LOG_E(
"Failed to create VulkanSharedContext because either fInstance,"
31 "fPhysicalDevice, fDevice, or fQueue in the VulkanBackendContext is"
32 "VK_NULL_HANDLE.");
33 return nullptr;
34 }
35 if (!context.fGetProc) {
36 SKGPU_LOG_E(
"Failed to create VulkanSharedContext because there is no valid VulkanGetProc"
37 "on the VulkanBackendContext");
38 return nullptr;
39 }
40
44 uint32_t instanceVersion = 0;
45 if (!localEnumerateInstanceVersion) {
47 } else {
48 VkResult err = localEnumerateInstanceVersion(&instanceVersion);
49 if (err) {
50 SKGPU_LOG_E(
"Failed to enumerate instance version. Err: %d\n", err);
51 return nullptr;
52 }
53 }
54
57 context.fGetProc("vkGetPhysicalDeviceProperties",
58 context.fInstance,
60
61 if (!localGetPhysicalDeviceProperties) {
62 SKGPU_LOG_E(
"Failed to get function pointer to vkGetPhysicalDeviceProperties.");
63 return nullptr;
64 }
66 localGetPhysicalDeviceProperties(context.fPhysicalDevice, &physDeviceProperties);
67 uint32_t physDevVersion = physDeviceProperties.
apiVersion;
68
69 uint32_t apiVersion = context.fMaxAPIVersion ? context.fMaxAPIVersion : instanceVersion;
70
71 instanceVersion = std::min(instanceVersion, apiVersion);
72 physDevVersion = std::min(physDevVersion, apiVersion);
73
76 context.fInstance,
77 context.fDevice,
78 instanceVersion,
79 physDevVersion,
80 context.fVkExtensions));
81 if (!
interface->
validate(instanceVersion, physDevVersion, context.fVkExtensions)) {
83 return nullptr;
84 }
85
88
89
90 if (!context.fDeviceFeatures2 && context.fDeviceFeatures) {
91 features.
pNext =
nullptr;
92 features.
features = *context.fDeviceFeatures;
93 featuresPtr = &features;
94 } else {
95 featuresPtr = context.fDeviceFeatures2;
96 }
97
98 std::unique_ptr<const VulkanCaps>
caps(
new VulkanCaps(
options,
100 context.fPhysicalDevice,
101 physDevVersion,
102 featuresPtr,
103 context.fVkExtensions,
104 context.fProtectedContext));
105
108
109 bool threadSafe = !
options.fClientWillExternallySynchronizeAllThreads;
111 context.fPhysicalDevice,
112 context.fDevice,
113 physDevVersion,
114 context.fVkExtensions,
116 threadSafe);
117 }
119 SKGPU_LOG_E(
"No supplied vulkan memory allocator and unable to create one internally.");
120 return nullptr;
121 }
122
127}
#define SKGPU_LOG_E(fmt,...)
static sk_sp< VulkanMemoryAllocator > Make(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, uint32_t physicalDeviceVersion, const VulkanExtensions *extensions, const VulkanInterface *interface, bool threadSafe)
const Caps * caps() const
skgpu::VulkanMemoryAllocator * memoryAllocator() const
VkPhysicalDeviceFeatures features
bool validate(uint32_t instanceVersion, uint32_t physicalDeviceVersion, const VulkanExtensions *) const
void(VKAPI_PTR * PFN_vkGetPhysicalDeviceProperties)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties)
#define VK_MAKE_VERSION(major, minor, patch)
VkResult(VKAPI_PTR * PFN_vkEnumerateInstanceVersion)(uint32_t *pApiVersion)