28 {
33 SKGPU_LOG_E(
"Failed to create VulkanSharedContext because either fInstance,"
34 "fPhysicalDevice, fDevice, or fQueue in the VulkanBackendContext is"
35 "VK_NULL_HANDLE.");
36 return nullptr;
37 }
38 if (!context.fGetProc) {
39 SKGPU_LOG_E(
"Failed to create VulkanSharedContext because there is no valid VulkanGetProc"
40 "on the VulkanBackendContext");
41 return nullptr;
42 }
43
47 uint32_t instanceVersion = 0;
48 if (!localEnumerateInstanceVersion) {
50 } else {
51 VkResult err = localEnumerateInstanceVersion(&instanceVersion);
52 if (err) {
53 SKGPU_LOG_E(
"Failed to enumerate instance version. Err: %d\n", err);
54 return nullptr;
55 }
56 }
57
60 context.fGetProc("vkGetPhysicalDeviceProperties",
61 context.fInstance,
63
64 if (!localGetPhysicalDeviceProperties) {
65 SKGPU_LOG_E(
"Failed to get function pointer to vkGetPhysicalDeviceProperties.");
66 return nullptr;
67 }
69 localGetPhysicalDeviceProperties(context.fPhysicalDevice, &physDeviceProperties);
70 uint32_t physDevVersion = physDeviceProperties.
apiVersion;
71
72 uint32_t apiVersion = context.fMaxAPIVersion ? context.fMaxAPIVersion : instanceVersion;
73
74 instanceVersion =
std::min(instanceVersion, apiVersion);
75 physDevVersion =
std::min(physDevVersion, apiVersion);
76
79 context.fInstance,
80 context.fDevice,
81 instanceVersion,
82 physDevVersion,
83 context.fVkExtensions));
84 if (!
interface->
validate(instanceVersion, physDevVersion, context.fVkExtensions)) {
86 return nullptr;
87 }
88
91
92
93 if (!context.fDeviceFeatures2 && context.fDeviceFeatures) {
94 features.
pNext =
nullptr;
95 features.
features = *context.fDeviceFeatures;
96 featuresPtr = &features;
97 } else {
98 featuresPtr = context.fDeviceFeatures2;
99 }
100
101 std::unique_ptr<const VulkanCaps>
caps(
new VulkanCaps(
options,
103 context.fPhysicalDevice,
104 physDevVersion,
105 featuresPtr,
106 context.fVkExtensions,
107 context.fProtectedContext));
108
110#if defined(SK_USE_VMA)
112
117 context.fPhysicalDevice,
118 context.fDevice,
119 physDevVersion,
120 context.fVkExtensions,
122 threadSafe);
123 }
124#endif
126 SKGPU_LOG_E(
"No supplied vulkan memory allocator and unable to create one internally.");
127 return nullptr;
128 }
129
134}
#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, ThreadSafe)
const Caps * caps() const
skgpu::VulkanMemoryAllocator * memoryAllocator() const
static float min(float r, float g, float b)
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)