| 301 | } |
| 302 | |
| 303 | bool PlVulkan::ChooseVulkanDevice(uintptr_t game_view_ptr, PDECODER_PARAMETERS params, bool hdrOutputRequired) |
| 304 | { |
| 305 | /* |
| 306 | * 暂时不用支持HDR输出 |
| 307 | * HDR(High Dynamic Range,高动态范围)输出是音视频领域的一项重要技术,它通过扩展亮度和色彩范围,带来更加逼真和沉浸式的视觉体验。 |
| 308 | */ |
| 309 | hdrOutputRequired = false; |
| 310 | |
| 311 | uint32_t physicalDeviceCount = 0; |
| 312 | fn_vkEnumeratePhysicalDevices(m_PlVkInstance->instance, &physicalDeviceCount, nullptr); |
| 313 | std::vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount); |
| 314 | fn_vkEnumeratePhysicalDevices(m_PlVkInstance->instance, &physicalDeviceCount, physicalDevices.data()); |
| 315 | |
| 316 | std::set<uint32_t> devicesTried; |
| 317 | VkPhysicalDeviceProperties deviceProps; |
| 318 | |
| 319 | if (physicalDeviceCount == 0) { |
| 320 | LOGE("No Vulkan devices found!"); |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | // First, try the first device in the list to support device selection layers |
| 325 | // that put the user's preferred GPU in the first slot. |
| 326 | fn_vkGetPhysicalDeviceProperties(physicalDevices[0], &deviceProps); |
| 327 | if (tryInitializeDevice(game_view_ptr, physicalDevices[0], &deviceProps, params, hdrOutputRequired)) { |
| 328 | return true; |
| 329 | } |
| 330 | devicesTried.emplace(0); |
| 331 | |
| 332 | // Next, we'll try to match an integrated GPU, since we want to minimize |
| 333 | // power consumption and inter-GPU copies. |
| 334 | for (uint32_t i = 0; i < physicalDeviceCount; i++) { |
| 335 | // Skip devices we've already tried |
| 336 | if (devicesTried.find(i) != devicesTried.end()) { |
| 337 | continue; |
| 338 | } |
| 339 | |
| 340 | VkPhysicalDeviceProperties deviceProps; |
| 341 | fn_vkGetPhysicalDeviceProperties(physicalDevices[i], &deviceProps); |
| 342 | if (deviceProps.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) { |
| 343 | if (tryInitializeDevice(game_view_ptr, physicalDevices[i], &deviceProps, params, hdrOutputRequired)) { |
| 344 | return true; |
| 345 | } |
| 346 | devicesTried.emplace(i); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | // Next, we'll try to match a discrete GPU. |
| 351 | for (uint32_t i = 0; i < physicalDeviceCount; i++) { |
| 352 | // Skip devices we've already tried |
| 353 | if (devicesTried.find(i) != devicesTried.end()) { |
| 354 | continue; |
| 355 | } |
| 356 | |
| 357 | VkPhysicalDeviceProperties deviceProps; |
| 358 | fn_vkGetPhysicalDeviceProperties(physicalDevices[i], &deviceProps); |
| 359 | if (deviceProps.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) { |
| 360 | if (tryInitializeDevice(game_view_ptr, physicalDevices[i], &deviceProps, params, hdrOutputRequired)) { |
nothing calls this directly
no outgoing calls
no test coverage detected