Remove linux support. Add create logical device
This commit is contained in:
@@ -63,7 +63,7 @@ CoreInstance::CoreInstance()
|
|||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
throw std::runtime_error("Fail create window");
|
throw std::runtime_error("Fail create window");
|
||||||
}
|
}
|
||||||
render_engine_ = new RenderEngine(window_);
|
render_engine_ = new RenderEngine(*this, window_);
|
||||||
|
|
||||||
game_ = GameFactory(*this);
|
game_ = GameFactory(*this);
|
||||||
if (game_ == nullptr)
|
if (game_ == nullptr)
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ public:
|
|||||||
|
|
||||||
int getCountCPU() const { return countCPU_; }
|
int getCountCPU() const { return countCPU_; }
|
||||||
double getMemorySize() const { return memorySize_; }
|
double getMemorySize() const { return memorySize_; }
|
||||||
|
const std::string& getBaseWorldName() const { return main_config_.base_world; }
|
||||||
|
const std::string& getGameName() const { return main_config_.game_name; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws std::runtime_error if module isn't enabled
|
* @throws std::runtime_error if module isn't enabled
|
||||||
@@ -78,7 +80,4 @@ public:
|
|||||||
* @throws std::runtime_error module isn't contain QuitModule function
|
* @throws std::runtime_error module isn't contain QuitModule function
|
||||||
*/
|
*/
|
||||||
void disableModule(const char* name) noexcept(false);
|
void disableModule(const char* name) noexcept(false);
|
||||||
|
|
||||||
const std::string& getBaseWorldName() const { return main_config_.base_world; }
|
|
||||||
const std::string& getGameName() const { return main_config_.game_name; }
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
#ifdef __linux__
|
|
||||||
|
|
||||||
#include "SystemCalls.h"
|
|
||||||
|
|
||||||
#include <sys/sysinfo.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
int System::getCountCPU()
|
|
||||||
{
|
|
||||||
int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
|
|
||||||
if(num_cores <= 0)
|
|
||||||
throw std::runtime_error("Fail get number of cores");
|
|
||||||
|
|
||||||
return num_cores;
|
|
||||||
}
|
|
||||||
|
|
||||||
double System::getMemorySize()
|
|
||||||
{
|
|
||||||
struct sysinfo info{};
|
|
||||||
if(sysinfo(&info) == -1)
|
|
||||||
std::runtime_error("Fail get system info");
|
|
||||||
return info.totalram / 1024 / 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* System::InitModule(const char* ModuleName, CoreInstance& core)
|
|
||||||
{
|
|
||||||
std::string fileName = "./lib";
|
|
||||||
fileName += ModuleName;
|
|
||||||
fileName += ".so";
|
|
||||||
|
|
||||||
void* handler = dlopen(fileName.c_str(), RTLD_NOW);
|
|
||||||
if(handler == nullptr)
|
|
||||||
throw std::runtime_error("Module not found");
|
|
||||||
|
|
||||||
void(*init)(CoreInstance&) = reinterpret_cast<void(*)(CoreInstance&)>(dlsym(handler, "InitModule"));
|
|
||||||
if(init == nullptr)
|
|
||||||
throw std::runtime_error("Module not contains InitModule");
|
|
||||||
init(core);
|
|
||||||
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::StartModule(void* handler)
|
|
||||||
{
|
|
||||||
void(*start)() = reinterpret_cast<void(*)()>(dlsym(handler, "StartModule"));
|
|
||||||
if(start == nullptr)
|
|
||||||
throw std::runtime_error("Module not contins StartModule");
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::QuitModule(void* handler)
|
|
||||||
{
|
|
||||||
void(*quit)() = reinterpret_cast<void(*)()>(dlsym(handler, "QuitModule"));
|
|
||||||
if(quit == nullptr)
|
|
||||||
throw std::runtime_error("Module not contains QuitModule");
|
|
||||||
quit();
|
|
||||||
dlclose(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+93
-17
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "CoreInstance.h"
|
||||||
#include "Log/Log.h"
|
#include "Log/Log.h"
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@@ -21,6 +23,11 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
|||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RenderEngine::QueueFamilyIndices::is_complete()
|
||||||
|
{
|
||||||
|
return graphycs_family.has_value();
|
||||||
|
}
|
||||||
|
|
||||||
VkResult RenderEngine::enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info)
|
VkResult RenderEngine::enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info)
|
||||||
{
|
{
|
||||||
PFN_vkCreateDebugUtilsMessengerEXT debug_creator = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance_, "vkCreateDebugUtilsMessengerEXT"));
|
PFN_vkCreateDebugUtilsMessengerEXT debug_creator = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance_, "vkCreateDebugUtilsMessengerEXT"));
|
||||||
@@ -49,27 +56,42 @@ bool RenderEngine::is_device_suitable(VkPhysicalDevice device)
|
|||||||
vkGetPhysicalDeviceProperties(device, &device_properties);
|
vkGetPhysicalDeviceProperties(device, &device_properties);
|
||||||
vkGetPhysicalDeviceFeatures(device, &device_features);
|
vkGetPhysicalDeviceFeatures(device, &device_features);
|
||||||
|
|
||||||
return device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && device_features.geometryShader;
|
QueueFamilyIndices indices = find_queue_family_indices(device);
|
||||||
|
|
||||||
|
return device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
|
||||||
|
&& device_features.geometryShader
|
||||||
|
&& indices.is_complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderEngine::RenderEngine(GLFWwindow* window) : window_(window)
|
RenderEngine::QueueFamilyIndices RenderEngine::find_queue_family_indices(VkPhysicalDevice device)
|
||||||
#ifdef _DEBUG
|
|
||||||
, debug_messenger_(nullptr)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
|
QueueFamilyIndices queue_family_indices;
|
||||||
|
|
||||||
|
uint32_t queueFamilyCount = 0;
|
||||||
|
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr);
|
||||||
|
std::vector<VkQueueFamilyProperties> family_propertieses(queueFamilyCount);
|
||||||
|
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, family_propertieses.data());
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < family_propertieses.size(); ++i)
|
||||||
{
|
{
|
||||||
|
if (family_propertieses[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
||||||
|
queue_family_indices.graphycs_family = i;
|
||||||
|
if(queue_family_indices.is_complete())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return queue_family_indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderEngine::create_instance()
|
||||||
|
{
|
||||||
std::vector<const char*> extensions = get_required_extensions();
|
std::vector<const char*> extensions = get_required_extensions();
|
||||||
std::vector<const char*> layers = {
|
|
||||||
#ifdef _DEBUG
|
|
||||||
"VK_LAYER_KHRONOS_validation"
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
VkApplicationInfo app_info{};
|
VkApplicationInfo app_info{};
|
||||||
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||||
app_info.apiVersion = VK_API_VERSION_1_0;
|
app_info.apiVersion = VK_API_VERSION_1_0;
|
||||||
app_info.applicationVersion = VK_MAKE_VERSION(0, 0, 0);
|
app_info.applicationVersion = VK_MAKE_VERSION(0, 0, 0);
|
||||||
app_info.pApplicationName = "UwU Engine";
|
app_info.pApplicationName = core_.getGameName().c_str();
|
||||||
app_info.pEngineName = "UwU Engine";
|
app_info.pEngineName = "UwU Engine";
|
||||||
app_info.engineVersion = VK_MAKE_VERSION(0, 0, 0);
|
app_info.engineVersion = VK_MAKE_VERSION(0, 0, 0);
|
||||||
|
|
||||||
@@ -77,11 +99,14 @@ RenderEngine::RenderEngine(GLFWwindow* window) : window_(window)
|
|||||||
VkInstanceCreateInfo instance_create_info{};
|
VkInstanceCreateInfo instance_create_info{};
|
||||||
instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||||
instance_create_info.pApplicationInfo = &app_info;
|
instance_create_info.pApplicationInfo = &app_info;
|
||||||
instance_create_info.enabledExtensionCount = extensions.size();
|
instance_create_info.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
|
||||||
instance_create_info.ppEnabledExtensionNames = extensions.data();
|
instance_create_info.ppEnabledExtensionNames = extensions.data();
|
||||||
instance_create_info.enabledLayerCount = layers.size();
|
|
||||||
instance_create_info.ppEnabledLayerNames = layers.data();
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
std::vector<const char*> layers_validation = {
|
||||||
|
"VK_LAYER_KHRONOS_validation"
|
||||||
|
};
|
||||||
|
instance_create_info.enabledLayerCount = static_cast<uint32_t>(layers_validation.size());
|
||||||
|
instance_create_info.ppEnabledLayerNames = layers_validation.data();
|
||||||
VkDebugUtilsMessengerCreateInfoEXT debug_messenger_create_info{};
|
VkDebugUtilsMessengerCreateInfoEXT debug_messenger_create_info{};
|
||||||
debug_messenger_create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
debug_messenger_create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
||||||
debug_messenger_create_info.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
|
debug_messenger_create_info.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
|
||||||
@@ -93,9 +118,10 @@ RenderEngine::RenderEngine(GLFWwindow* window) : window_(window)
|
|||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
VK_CHECK(enable_layer_validation(&debug_messenger_create_info));
|
VK_CHECK(enable_layer_validation(&debug_messenger_create_info));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
void RenderEngine::pick_physical_device()
|
||||||
|
{
|
||||||
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));
|
||||||
@@ -117,10 +143,60 @@ RenderEngine::RenderEngine(GLFWwindow* window) : window_(window)
|
|||||||
if (VK_NULL_HANDLE == physical_device_)
|
if (VK_NULL_HANDLE == physical_device_)
|
||||||
throw std::runtime_error("No suitable device found");
|
throw std::runtime_error("No suitable device found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderEngine::create_logical_device()
|
||||||
|
{
|
||||||
|
QueueFamilyIndices indices = find_queue_family_indices(physical_device_);
|
||||||
|
|
||||||
|
VkPhysicalDeviceFeatures device_features{};
|
||||||
|
|
||||||
|
float queue_priority = 1.0f;
|
||||||
|
VkDeviceQueueCreateInfo device_queue_create_info{};
|
||||||
|
device_queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
||||||
|
device_queue_create_info.queueFamilyIndex = indices.graphycs_family.value();
|
||||||
|
device_queue_create_info.queueCount = 1;
|
||||||
|
device_queue_create_info.pQueuePriorities = &queue_priority;
|
||||||
|
|
||||||
|
VkDeviceCreateInfo device_create_info{};
|
||||||
|
device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||||
|
device_create_info.queueCreateInfoCount = 1;
|
||||||
|
device_create_info.pQueueCreateInfos = &device_queue_create_info;
|
||||||
|
device_create_info.pEnabledFeatures = &device_features;
|
||||||
|
device_create_info.enabledExtensionCount = 0;
|
||||||
|
device_create_info.ppEnabledExtensionNames = nullptr;
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
std::vector<const char*> layers_validation = {
|
||||||
|
"VK_LAYER_KHRONOS_validation"
|
||||||
|
};
|
||||||
|
device_create_info.enabledLayerCount = static_cast<uint32_t>(layers_validation.size());
|
||||||
|
device_create_info.ppEnabledLayerNames = layers_validation.data();
|
||||||
|
#else
|
||||||
|
device_create_info.enabledLayerCount = 0;
|
||||||
|
device_create_info.ppEnabledLayerNames = nullptr;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
VK_CHECK(vkCreateDevice(physical_device_, &device_create_info, nullptr, &device_));
|
||||||
|
vkGetDeviceQueue(device_, indices.graphycs_family.value(), 0, &graphics_queue_);
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderEngine::RenderEngine(CoreInstance& core, GLFWwindow* window):
|
||||||
|
core_(core),
|
||||||
|
window_(window)
|
||||||
|
#ifdef _DEBUG
|
||||||
|
,debug_messenger_(nullptr)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
create_instance();
|
||||||
|
pick_physical_device();
|
||||||
|
create_logical_device();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderEngine::~RenderEngine()
|
RenderEngine::~RenderEngine()
|
||||||
{
|
{
|
||||||
|
if (device_ != VK_NULL_HANDLE)
|
||||||
|
vkDestroyDevice(device_, nullptr);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if (debug_messenger_ != nullptr && instance_ != nullptr) {
|
if (debug_messenger_ != nullptr && instance_ != nullptr) {
|
||||||
PFN_vkDestroyDebugUtilsMessengerEXT destroyer_messenger = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance_, "vkDestroyDebugUtilsMessengerEXT"));
|
PFN_vkDestroyDebugUtilsMessengerEXT destroyer_messenger = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance_, "vkDestroyDebugUtilsMessengerEXT"));
|
||||||
@@ -128,7 +204,7 @@ RenderEngine::~RenderEngine()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (instance_ != nullptr)
|
if (instance_ != VK_NULL_HANDLE)
|
||||||
vkDestroyInstance(instance_, nullptr);
|
vkDestroyInstance(instance_, nullptr);
|
||||||
|
|
||||||
if (window_ != nullptr)
|
if (window_ != nullptr)
|
||||||
|
|||||||
@@ -5,12 +5,24 @@
|
|||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
class CoreInstance;
|
||||||
|
|
||||||
class RenderEngine
|
class RenderEngine
|
||||||
{
|
{
|
||||||
|
struct QueueFamilyIndices
|
||||||
|
{
|
||||||
|
std::optional<uint32_t> graphycs_family;
|
||||||
|
bool is_complete();
|
||||||
|
};
|
||||||
|
|
||||||
|
CoreInstance& core_;
|
||||||
GLFWwindow* window_;
|
GLFWwindow* window_;
|
||||||
VkInstance instance_ = VK_NULL_HANDLE;
|
VkInstance instance_ = VK_NULL_HANDLE;
|
||||||
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
|
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
|
||||||
|
VkDevice device_ = VK_NULL_HANDLE;
|
||||||
|
VkQueue graphics_queue_ = VK_NULL_HANDLE;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
VkResult enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info);
|
VkResult enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info);
|
||||||
@@ -18,9 +30,15 @@ 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);
|
static bool is_device_suitable(VkPhysicalDevice device);
|
||||||
|
static QueueFamilyIndices find_queue_family_indices(VkPhysicalDevice device);
|
||||||
|
|
||||||
|
void create_instance();
|
||||||
|
void pick_physical_device();
|
||||||
|
void create_logical_device();
|
||||||
public:
|
public:
|
||||||
RenderEngine(GLFWwindow* window);
|
// Can throw the exception
|
||||||
|
RenderEngine(CoreInstance& core, GLFWwindow* window);
|
||||||
~RenderEngine();
|
~RenderEngine();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include "SystemCalls.h"
|
#include "../SystemCalls.h"
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ double System::getMemorySize() {
|
|||||||
memStatus.dwLength = sizeof(memStatus);
|
memStatus.dwLength = sizeof(memStatus);
|
||||||
|
|
||||||
GlobalMemoryStatusEx(&memStatus);
|
GlobalMemoryStatusEx(&memStatus);
|
||||||
return memStatus.ullTotalPhys / 1024 / 1024;
|
return static_cast<double>(memStatus.ullTotalPhys) / 1024. / 1024.;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* System::InitModule(const char* ModuleName, CoreCallBacks* callbacks) {
|
void* System::InitModule(const char* ModuleName, CoreCallBacks* callbacks) {
|
||||||
Reference in New Issue
Block a user