Add choose GPU.
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include "Log/Log.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include "Log/Log.h"
|
||||
#include <assert.h>
|
||||
#define VK_CHECK(res) assert(res == VK_SUCCESS)
|
||||
|
||||
@@ -42,9 +42,19 @@ std::vector<const char*> RenderEngine::get_required_extensions()
|
||||
return extensions;
|
||||
}
|
||||
|
||||
bool RenderEngine::is_device_suitable(VkPhysicalDevice device)
|
||||
{
|
||||
VkPhysicalDeviceProperties device_properties;
|
||||
VkPhysicalDeviceFeatures device_features;
|
||||
vkGetPhysicalDeviceProperties(device, &device_properties);
|
||||
vkGetPhysicalDeviceFeatures(device, &device_features);
|
||||
|
||||
return device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && device_features.geometryShader;
|
||||
}
|
||||
|
||||
RenderEngine::RenderEngine(GLFWwindow* window) : window_(window)
|
||||
#ifdef _DEBUG
|
||||
, debug_messenger_(nullptr)
|
||||
, debug_messenger_(nullptr)
|
||||
#endif
|
||||
{
|
||||
{
|
||||
@@ -89,13 +99,23 @@ RenderEngine::RenderEngine(GLFWwindow* window) : window_(window)
|
||||
uint32_t device_count = 0;
|
||||
std::vector<VkPhysicalDevice> devices;
|
||||
VK_CHECK(vkEnumeratePhysicalDevices(instance_, &device_count, nullptr));
|
||||
devices.resize(device_count);
|
||||
VK_CHECK(vkEnumeratePhysicalDevices(instance_, &device_count, devices.data()));
|
||||
|
||||
for (const auto& device : devices)
|
||||
{
|
||||
VkPhysicalDeviceProperties device_properties;
|
||||
vkGetPhysicalDeviceProperties(device, &device_properties);
|
||||
if (is_device_suitable(device))
|
||||
{
|
||||
physical_device_ = device;
|
||||
VkPhysicalDeviceProperties device_properties;
|
||||
vkGetPhysicalDeviceProperties(physical_device_, &device_properties);
|
||||
Log("Using device: " + std::string(device_properties.deviceName));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (VK_NULL_HANDLE == physical_device_)
|
||||
throw std::runtime_error("No suitable device found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user