Add choose GPU.
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#include "RenderEngine.h"
|
||||||
#include "Game/GameInstance.h"
|
#include "Game/GameInstance.h"
|
||||||
#include "Log/Log.h"
|
#include "Log/Log.h"
|
||||||
#include "Game/SaveMap/SaveMap.h"
|
#include "Game/SaveMap/SaveMap.h"
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "RenderEngine.h"
|
|
||||||
#include "Game/SaveMap/ISave.h"
|
#include "Game/SaveMap/ISave.h"
|
||||||
#include "Core/CoreCallBacks.h"
|
#include "Core/CoreCallBacks.h"
|
||||||
|
|
||||||
class SaveMap;
|
class SaveMap;
|
||||||
class RenderEngine;
|
class RenderEngine;
|
||||||
class GameInstance;
|
class GameInstance;
|
||||||
|
struct GLFWwindow;
|
||||||
|
|
||||||
class CoreInstance {
|
class CoreInstance {
|
||||||
struct Module {
|
struct Module {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "Log/Log.h"
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#include "Log/Log.h"
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#define VK_CHECK(res) assert(res == VK_SUCCESS)
|
#define VK_CHECK(res) assert(res == VK_SUCCESS)
|
||||||
|
|
||||||
@@ -42,9 +42,19 @@ std::vector<const char*> RenderEngine::get_required_extensions()
|
|||||||
return 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)
|
RenderEngine::RenderEngine(GLFWwindow* window) : window_(window)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
, debug_messenger_(nullptr)
|
, debug_messenger_(nullptr)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -89,13 +99,23 @@ RenderEngine::RenderEngine(GLFWwindow* window) : window_(window)
|
|||||||
uint32_t device_count = 0;
|
uint32_t device_count = 0;
|
||||||
std::vector<VkPhysicalDevice> devices;
|
std::vector<VkPhysicalDevice> devices;
|
||||||
VK_CHECK(vkEnumeratePhysicalDevices(instance_, &device_count, nullptr));
|
VK_CHECK(vkEnumeratePhysicalDevices(instance_, &device_count, nullptr));
|
||||||
|
devices.resize(device_count);
|
||||||
VK_CHECK(vkEnumeratePhysicalDevices(instance_, &device_count, devices.data()));
|
VK_CHECK(vkEnumeratePhysicalDevices(instance_, &device_count, devices.data()));
|
||||||
|
|
||||||
for (const auto& device : devices)
|
for (const auto& device : devices)
|
||||||
{
|
{
|
||||||
VkPhysicalDeviceProperties device_properties;
|
if (is_device_suitable(device))
|
||||||
vkGetPhysicalDeviceProperties(device, &device_properties);
|
{
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
class RenderEngine
|
class RenderEngine
|
||||||
{
|
{
|
||||||
GLFWwindow* window_;
|
GLFWwindow* window_;
|
||||||
VkInstance instance_;
|
VkInstance instance_ = VK_NULL_HANDLE;
|
||||||
|
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
VkResult enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info);
|
VkResult enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info);
|
||||||
@@ -17,7 +18,7 @@ class RenderEngine
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static std::vector<const char*> get_required_extensions();
|
static std::vector<const char*> get_required_extensions();
|
||||||
|
bool is_device_suitable(VkPhysicalDevice device);
|
||||||
public:
|
public:
|
||||||
RenderEngine(GLFWwindow* window);
|
RenderEngine(GLFWwindow* window);
|
||||||
~RenderEngine();
|
~RenderEngine();
|
||||||
|
|||||||
Reference in New Issue
Block a user