diff --git a/CMakeLists.txt b/CMakeLists.txt index 6785b9f..921e8be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,22 @@ if(NOT MSVC) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") endif() +if(CMAKE_BUILD_TYPE STREQUAL "Release" OR NOT CMAKE_BUILD_TYPE) + if(MSVC) + # Оптимизации для Microsoft Visual C++ + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Oi /Ot /GL /Gw /arch:AVX2") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") + set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG") + + elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + # Оптимизации для GCC и Clang (у них одинаковый синтаксический синтаксис флагов) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -flto -fomit-frame-pointer") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -flto") + endif() +endif() + #if(MSVC) # add_compile_options(/GR-) #else() diff --git a/Core/Core/CoreInstance.cpp b/Core/Core/CoreInstance.cpp index 46726dd..0f1039b 100644 --- a/Core/Core/CoreInstance.cpp +++ b/Core/Core/CoreInstance.cpp @@ -49,25 +49,6 @@ CoreInstance::CoreInstance() SaveMap load_main_config(payload); main_config_.load(std::make_shared(load_main_config)); - - // if (glfwInit() == GLFW_FALSE) - // throw std::runtime_error("Fail init glfw"); - // - // glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); - // glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - // window_ = glfwCreateWindow(800, 600, main_config_.game_name.c_str(), nullptr, nullptr); - // if (window_ == nullptr) - // { - // std::cout << "[!] Init render engine: Fail create window\n"; - // return; - // } - // try { - // render_engine_ = new RenderEngine(*this, window_); - // } catch (const std::exception& e) - // { - // std::cout << "[!] Init render engine: " << e.what() << '\n'; - // return; - // } try { diff --git a/Core/Core/Windows/WindowsCalls.cpp b/Core/Core/Windows/WindowsCalls.cpp index 81824f4..55c7cdd 100644 --- a/Core/Core/Windows/WindowsCalls.cpp +++ b/Core/Core/Windows/WindowsCalls.cpp @@ -10,26 +10,27 @@ #include int System::getCountCPU() { - DWORD len = 0; + DWORD len = 0; // In bytes GetLogicalProcessorInformation(nullptr, &len); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { throw std::runtime_error(std::to_string(GetLastError()).c_str()); } + DWORD count = len / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); - std::vector buffer(len); + std::vector buffer(count); if (!GetLogicalProcessorInformation(buffer.data(), &len)) { throw std::runtime_error(std::to_string(GetLastError()).c_str()); } - DWORD count = len / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); int physicalCoreCount = 0; - - for (DWORD i = 0; i < count; ++i) { - if (buffer[i].Relationship == RelationProcessorCore) { - physicalCoreCount++; + for (auto& i : buffer) + { + if (i.Relationship == RelationProcessorCore) + { + ++physicalCoreCount; } } - + return physicalCoreCount; } diff --git a/RenderEngineSDK/CMakeLists.txt b/RenderEngineSDK/CMakeLists.txt index 7d53a0c..e7b6bb9 100644 --- a/RenderEngineSDK/CMakeLists.txt +++ b/RenderEngineSDK/CMakeLists.txt @@ -4,6 +4,8 @@ file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.hpp" "*.h") add_library(RenderEngineSDK ${SRC}) +target_compile_features(RenderEngineSDK PRIVATE cxx_std_17) + target_include_directories(RenderEngineSDK PUBLIC ${PROJECT_SOURCE_DIR}/glfw/Include ${PROJECT_SOURCE_DIR}/Delegate diff --git a/RenderEngineSDK/DeviceFunctions/DeviceFunctions.cpp b/RenderEngineSDK/DeviceFunctions/DeviceFunctions.cpp index 44b6d87..e1e3a58 100644 --- a/RenderEngineSDK/DeviceFunctions/DeviceFunctions.cpp +++ b/RenderEngineSDK/DeviceFunctions/DeviceFunctions.cpp @@ -2,6 +2,7 @@ #include #include +#include VkExtent2D DeviceFunctions::choose_extent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window) { @@ -27,13 +28,16 @@ uint32_t DeviceFunctions::find_memory_type(VkPhysicalDevice physical_device, uin VkPhysicalDeviceMemoryProperties memory_properties{}; vkGetPhysicalDeviceMemoryProperties(physical_device, &memory_properties); + std::optional mem_type = 0; for (uint32_t i = 0; i < memory_properties.memoryTypeCount; ++i) { if (typeFilter & (1 << i) && (memory_properties.memoryTypes[i].propertyFlags & properties) == properties) - return i; + mem_type = i; } - throw std::runtime_error("failed to find suitable memory type!"); + if (mem_type.has_value() == false) + throw std::runtime_error("failed to find suitable memory type!"); + return mem_type.value(); } void DeviceFunctions::device_memcpy(VkDevice device, uint32_t transfer_queue_family, VkBuffer src, VkBuffer dst, size_t size) @@ -43,7 +47,7 @@ void DeviceFunctions::device_memcpy(VkDevice device, uint32_t transfer_queue_fam copy_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; copy_pool_info.queueFamilyIndex = transfer_queue_family; copy_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - VK_CHECK(vkCreateCommandPool(device, ©_pool_info, nullptr, ©_pool)); + VK_CHECK(vkCreateCommandPool(device, ©_pool_info, nullptr, ©_pool)) VkCommandBufferAllocateInfo command_buffer_allocate_info{}; command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; @@ -52,15 +56,15 @@ void DeviceFunctions::device_memcpy(VkDevice device, uint32_t transfer_queue_fam command_buffer_allocate_info.commandBufferCount = 1; VkCommandBuffer copy_buffer; - VK_CHECK(vkAllocateCommandBuffers(device, &command_buffer_allocate_info, ©_buffer)); + VK_CHECK(vkAllocateCommandBuffers(device, &command_buffer_allocate_info, ©_buffer)) VkCommandBufferBeginInfo command_buffer_begin_info{}; command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - VK_CHECK(vkBeginCommandBuffer(copy_buffer, &command_buffer_begin_info)); + VK_CHECK(vkBeginCommandBuffer(copy_buffer, &command_buffer_begin_info)) - VkBufferCopy buffer_copy{}; + VkBufferCopy buffer_copy; buffer_copy.srcOffset = 0; buffer_copy.dstOffset = 0; buffer_copy.size = size; @@ -105,7 +109,7 @@ VkBuffer DeviceFunctions::create_buffer(VkDevice device, VkDeviceSize size, VkBu } VkBuffer buffer; - VK_CHECK(vkCreateBuffer(device, &buffer_info, nullptr, &buffer)); + VK_CHECK(vkCreateBuffer(device, &buffer_info, nullptr, &buffer)) return buffer; } @@ -120,6 +124,6 @@ VkDeviceMemory DeviceFunctions::allocate_device_memory(VkPhysicalDevice physical allocate_info.memoryTypeIndex = find_memory_type(physical_device, requirements.memoryTypeBits, property); VkDeviceMemory device_memory; - VK_CHECK(vkAllocateMemory(device, &allocate_info, nullptr, &device_memory)); + VK_CHECK(vkAllocateMemory(device, &allocate_info, nullptr, &device_memory)) return device_memory; } diff --git a/UwURenderEngine/RenderEngine/UwURenderEngine.cpp b/UwURenderEngine/RenderEngine/UwURenderEngine.cpp index 0b2ae6b..9ab2fdd 100644 --- a/UwURenderEngine/RenderEngine/UwURenderEngine.cpp +++ b/UwURenderEngine/RenderEngine/UwURenderEngine.cpp @@ -15,6 +15,7 @@ #include "Game/World/World.hpp" #include "../Game/Actors/Mesh/Mesh.hpp" #include "DeviceFunctions/DeviceFunctions.hpp" +#include "Log/Log.hpp" RENDER_ENGINE_FACTORY_GENERATE(UwURenderEngine) @@ -31,7 +32,7 @@ void UwURenderEngine::create_uniform_buffers() uniform_buffers_[i] = DeviceFunctions::create_buffer(device_.get_native(), size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, arr_indices); uniform_buffers_memory_[i] = DeviceFunctions::allocate_device_memory(physical_device_.get_native(), device_.get_native(), uniform_buffers_[i], VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); vkBindBufferMemory(device_.get_native(), uniform_buffers_[i], uniform_buffers_memory_[i], 0); - + vkMapMemory(device_.get_native(), uniform_buffers_memory_[i], 0, size, 0, &uniform_buffers_mapped_[i]); } }