MCPcopy Create free account
hub / github.com/LibreVR/Revive / ovr_GetSessionPhysicalDeviceVk

Function ovr_GetSessionPhysicalDeviceVk

Revive/REV_CAPI_Vk.cpp:104–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102
103OVR_PUBLIC_FUNCTION(ovrResult)
104ovr_GetSessionPhysicalDeviceVk(
105 ovrSession session,
106 ovrGraphicsLuid luid,
107 VkInstance instance,
108 VkPhysicalDevice* out_physicalDevice)
109{
110 VulkanLibrary = LoadLibraryW(L"vulkan-1.dll");
111 if (!VulkanLibrary)
112 return ovrError_InitializeVulkan;
113
114 VK_LIBRARY_FUNCTION(VulkanLibrary, vkGetInstanceProcAddr)
115 VK_INSTANCE_FUNCTION(instance, vkGetDeviceProcAddr)
116 VK_INSTANCE_FUNCTION(instance, vkEnumeratePhysicalDevices)
117 VK_INSTANCE_FUNCTION(instance, vkGetPhysicalDeviceMemoryProperties)
118 VK_INSTANCE_FUNCTION(instance, vkGetPhysicalDeviceProperties2KHR)
119
120#ifdef DEBUG
121 VK_INSTANCE_FUNCTION(instance, vkCreateDebugUtilsMessengerEXT)
122 VK_INSTANCE_FUNCTION(instance, vkDestroyDebugUtilsMessengerEXT)
123
124 VkDebugUtilsMessengerCreateInfoEXT callback1 = {
125 VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT, // sType
126 NULL, // pNext
127 0, // flags
128 VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | // messageSeverity
129 VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
130 VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
131 VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT,
132 VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | // messageType
133 VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT,
134 DebugUtilsCallback, // pfnUserCallback
135 NULL // pUserData
136 };
137 vkCreateDebugUtilsMessengerEXT(instance, &callback1, nullptr, &g_Messenger);
138#endif
139
140 VkPhysicalDevice physicalDevice = 0;
141 vr::VRSystem()->GetOutputDevice((uint64_t*)&physicalDevice, vr::TextureType_Vulkan, instance);
142
143 // Fall-back in case GetOutputDevice fails.
144 if (!physicalDevice)
145 {
146 uint32_t gpu_count;
147 std::vector<VkPhysicalDevice> devices;
148
149 // Get the number of devices (GPUs) available.
150 VkResult res = vkEnumeratePhysicalDevices(instance, &gpu_count, NULL);
151 // Allocate space and get the list of devices.
152 devices.resize(gpu_count);
153 res = vkEnumeratePhysicalDevices(instance, &gpu_count, devices.data());
154
155 for (VkPhysicalDevice device : devices)
156 {
157 VkPhysicalDeviceIDPropertiesKHR uid = {};
158 uid.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR;
159 VkPhysicalDeviceProperties2KHR properties = {};
160 properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
161 properties.pNext = &uid;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected