blob: 6e84530a058861bf4b3d36af46fbf84a310a14ea [file] [log] [blame]
Po-Hsien Wang00777b22019-04-24 16:37:09 -07001// Copyright 2019 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <limits>
6#include <vulkan/vulkan.hpp>
7#include "testUtil.h"
8#include "utils.h"
9
10bool vkbench::IsLayersSupported(const std::vector<const char*>& kLayers) {
11 std::vector<vk::LayerProperties>
12 availLayers = vk::enumerateInstanceLayerProperties();
13 for (const auto& layer : kLayers) {
14 bool found = false;
15 for (const auto availLayer : availLayers) {
16 if (!strcmp(availLayer.layerName, layer)) {
17 DEBUG("%s Layer is support.", layer)
18 found = true;
19 break;
20 }
21 }
22 if (!found) {
23 DEBUG("Layer %s is not support.", layer)
24 return false;
25 }
26 }
27 return true;
28}
29
30bool vkbench::IsExtensionSupported(
31 const std::vector<const char*>& kExtensions) {
32 std::vector<vk::ExtensionProperties>
33 availExtensions = vk::enumerateInstanceExtensionProperties();
34 for (const auto extension : kExtensions) {
35 bool found = false;
36 for (const auto availExtension : availExtensions) {
37 if (!strcmp(availExtension.extensionName, extension)) {
38 found = true;
39 break;
40 }
41 }
42 if (!found) {
43 DEBUG("Extension %s is not supported.", extension)
44 return false;
45 }
46 }
47 return true;
48}
49
50vk::Result vkbench::CreateDebugUtilsMessengerEXT(
51 vk::Instance instance,
52 const vk::DebugUtilsMessengerCreateInfoEXT* kPcreateInfo,
53 const vk::AllocationCallbacks* kPallocator,
54 vk::DebugUtilsMessengerEXT* pdebug_messengeer) {
55 auto func = (PFN_vkCreateDebugUtilsMessengerEXT) instance.getProcAddr(
56 "vkCreateDebugUtilsMessengerEXT");
57 if (func != nullptr) {
58 return static_cast<vk::Result>(func(
59 instance,
60 reinterpret_cast<const VkDebugUtilsMessengerCreateInfoEXT*>(
61 kPcreateInfo),
62 reinterpret_cast<const VkAllocationCallbacks*>(kPallocator),
63 reinterpret_cast<VkDebugUtilsMessengerEXT*>(pdebug_messengeer)));
64 } else {
65 return vk::Result::eErrorExtensionNotPresent;
66 }
67}
68
69void vkbench::DestroyDebugUtilsMessengerEXT(
70 vk::Instance instance,
71 vk::DebugUtilsMessengerEXT debug_messengeer,
72 const vk::AllocationCallbacks* kPAllocator) {
73 auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) instance.getProcAddr(
74 "vkDestroyDebugUtilsMessengerEXT");
75 if (func != nullptr) {
76 func(instance,
77 static_cast<VkDebugUtilsMessengerEXT>(debug_messengeer),
78 reinterpret_cast<const VkAllocationCallbacks*>(
79 static_cast<const vk::AllocationCallbacks*>(kPAllocator)));
80 }
81}
82
83uint32_t vkbench::ChooseGFXQueueFamilies(
84 const vk::PhysicalDevice& kPhysical_device) {
85 uint32_t gfxQueueIdx = UINT32_MAX;
86 std::vector<vk::QueueFamilyProperties>
87 props = kPhysical_device.getQueueFamilyProperties();
88 for (uint32_t i = 0; i < props.size(); i++) {
89 if (props[i].queueCount <= 0)
90 continue;
91 if (props[i].queueFlags & vk::QueueFlagBits::eGraphics) {
92 gfxQueueIdx = i;
93 break;
94 }
95 }
96 return gfxQueueIdx;
97}