Add choose GPU.

This commit is contained in:
Jiga228
2025-09-18 20:19:24 +07:00
parent e151663de5
commit 6ce11daa24
4 changed files with 29 additions and 7 deletions
+1
View File
@@ -8,6 +8,7 @@
#include <iostream>
#include <thread>
#include "RenderEngine.h"
#include "Game/GameInstance.h"
#include "Log/Log.h"
#include "Game/SaveMap/SaveMap.h"
+1 -1
View File
@@ -5,13 +5,13 @@
#include <memory>
#include <vector>
#include "RenderEngine.h"
#include "Game/SaveMap/ISave.h"
#include "Core/CoreCallBacks.h"
class SaveMap;
class RenderEngine;
class GameInstance;
struct GLFWwindow;
class CoreInstance {
struct Module {
+23 -3
View File
@@ -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,14 +99,24 @@ 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)
{
if (is_device_suitable(device))
{
physical_device_ = device;
VkPhysicalDeviceProperties device_properties;
vkGetPhysicalDeviceProperties(device, &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");
}
}
RenderEngine::~RenderEngine()
+3 -2
View File
@@ -9,7 +9,8 @@
class RenderEngine
{
GLFWwindow* window_;
VkInstance instance_;
VkInstance instance_ = VK_NULL_HANDLE;
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
#ifdef _DEBUG
VkResult enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info);
@@ -17,7 +18,7 @@ class RenderEngine
#endif
static std::vector<const char*> get_required_extensions();
bool is_device_suitable(VkPhysicalDevice device);
public:
RenderEngine(GLFWwindow* window);
~RenderEngine();