Исправил неопределённое поведение и добавил агрессивные оптимизации для Release конфигурации
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -50,25 +50,6 @@ CoreInstance::CoreInstance()
|
||||
|
||||
main_config_.load(std::make_shared<SaveMap>(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
|
||||
{
|
||||
render_engine_ = RenderEngineFactory(*this);
|
||||
|
||||
@@ -10,23 +10,24 @@
|
||||
#include <stdexcept>
|
||||
|
||||
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<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> buffer(len);
|
||||
std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
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<uint32_t> 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user