10#if defined(SK_GANESH) && defined(SK_VULKAN)
23#include <initializer_list>
28#define ACQUIRE_VK_PROC_NOCHECK(name, instance) \
29 PFN_vk##name grVk##name = \
30 reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, VK_NULL_HANDLE))
32#define ACQUIRE_VK_PROC(name, instance) \
33 PFN_vk##name grVk##name = \
34 reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, VK_NULL_HANDLE)); \
36 if (grVk##name == nullptr) { \
37 if (instance != VK_NULL_HANDLE) { \
38 destroy_instance(getProc, instance); \
44#define ACQUIRE_VK_PROC_LOCAL(name, instance) \
45 PFN_vk##name grVk##name = \
46 reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, VK_NULL_HANDLE)); \
48 if (grVk##name == nullptr) { \
53#define GET_PROC_LOCAL(F, inst) PFN_vk ## F F = (PFN_vk ## F) getProc("vk" #F, inst, VK_NULL_HANDLE)
57 grVkDestroyInstance(
inst,
nullptr);
68 if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
72 auto getProc = [instProc](
const char* proc_name, VkInstance
instance, VkDevice) {
73 return instProc(
instance, proc_name);
79 uint32_t instanceVersion = 0;
80 if (!grVkEnumerateInstanceVersion) {
83 err = grVkEnumerateInstanceVersion(&instanceVersion);
85 ERRORF(
reporter,
"failed ot enumerate instance version. Err: %d", err);
99 instanceVersion =
std::min(instanceVersion, apiVersion);
101 VkPhysicalDevice physDev;
127 err = grVkCreateInstance(&instance_create,
nullptr, &
inst);
133 ACQUIRE_VK_PROC(EnumeratePhysicalDevices,
inst);
134 ACQUIRE_VK_PROC(GetPhysicalDeviceProperties,
inst);
135 ACQUIRE_VK_PROC(GetPhysicalDeviceQueueFamilyProperties,
inst);
136 ACQUIRE_VK_PROC(GetPhysicalDeviceFeatures,
inst);
137 ACQUIRE_VK_PROC(CreateDevice,
inst);
138 ACQUIRE_VK_PROC(GetDeviceQueue,
inst);
139 ACQUIRE_VK_PROC(DeviceWaitIdle,
inst);
140 ACQUIRE_VK_PROC(DestroyDevice,
inst);
143 err = grVkEnumeratePhysicalDevices(
inst, &gpuCount,
nullptr);
146 destroy_instance(getProc,
inst);
152 destroy_instance(getProc,
inst);
158 err = grVkEnumeratePhysicalDevices(
inst, &gpuCount, &physDev);
162 destroy_instance(getProc,
inst);
168 grVkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount,
nullptr);
170 ERRORF(
reporter,
"vkGetPhysicalDeviceQueueFamilyProperties returned no queues.");
171 destroy_instance(getProc,
inst);
179 grVkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueProps);
182 uint32_t graphicsQueueIndex = queueCount;
183 for (uint32_t
i = 0;
i < queueCount;
i++) {
185 graphicsQueueIndex =
i;
189 if (graphicsQueueIndex == queueCount) {
190 ERRORF(
reporter,
"Could not find any supported graphics queues.");
191 destroy_instance(getProc,
inst);
198 if (!EnumerateDeviceExtensionProperties ||
199 !EnumerateDeviceLayerProperties) {
200 destroy_instance(getProc,
inst);
206 uint32_t extensionCount = 0;
207 err = EnumerateDeviceExtensionProperties(physDev,
nullptr, &extensionCount,
nullptr);
209 ERRORF(
reporter,
"Could not enumerate device extension properties.");
210 destroy_instance(getProc,
inst);
214 err = EnumerateDeviceExtensionProperties(physDev,
nullptr, &extensionCount,
extensions);
217 ERRORF(
reporter,
"Could not enumerate device extension properties.");
218 destroy_instance(getProc,
inst);
221 bool hasPriorityExt =
false;
222 for (uint32_t
i = 0;
i < extensionCount; ++
i) {
224 hasPriorityExt =
true;
229 if (!hasPriorityExt) {
230 destroy_instance(getProc,
inst);
237 grVkGetPhysicalDeviceFeatures(physDev, &deviceFeatures);
243 float queuePriorities[1] = { 0.0 };
246 queuePriorityCreateInfo.
sType =
248 queuePriorityCreateInfo.
pNext =
nullptr;
252 &queuePriorityCreateInfo,
278 err = grVkCreateDevice(physDev, &deviceInfo,
nullptr, &
device);
281 ERRORF(
reporter,
"CreateDevice failed: %d, priority %d", err, globalPriority);
282 destroy_instance(getProc,
inst);
286 grVkDestroyDevice(
device,
nullptr);
289 destroy_instance(getProc,
inst);
#define GET_PROC_LOCAL(F)
#define ACQUIRE_VK_PROC_LOCAL(name, inst)
#define DEF_GANESH_TEST_FOR_VULKAN_CONTEXT(name, reporter, context_info, ctsEnforcement)
static float min(float r, float g, float b)
std::function< PFN_vkVoidFunction(const char *, VkInstance, VkDevice)> VulkanGetProc
VkQueueGlobalPriorityKHR globalPriority
VkBool32 robustBufferAccess
#define VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME
@ VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
@ VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
@ VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
@ VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
#define VK_MAKE_VERSION(major, minor, patch)
@ VK_ERROR_NOT_PERMITTED_EXT
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
@ VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO
@ VK_STRUCTURE_TYPE_APPLICATION_INFO
@ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
@ VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
@ VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO