Исправил неопределённое поведение и добавил агрессивные оптимизации для Release конфигурации
This commit is contained in:
@@ -14,6 +14,22 @@ if(NOT MSVC)
|
|||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
|
||||||
endif()
|
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)
|
#if(MSVC)
|
||||||
# add_compile_options(/GR-)
|
# add_compile_options(/GR-)
|
||||||
#else()
|
#else()
|
||||||
|
|||||||
@@ -49,25 +49,6 @@ CoreInstance::CoreInstance()
|
|||||||
SaveMap load_main_config(payload);
|
SaveMap load_main_config(payload);
|
||||||
|
|
||||||
main_config_.load(std::make_shared<SaveMap>(load_main_config));
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,26 +10,27 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
int System::getCountCPU() {
|
int System::getCountCPU() {
|
||||||
DWORD len = 0;
|
DWORD len = 0; // In bytes
|
||||||
GetLogicalProcessorInformation(nullptr, &len);
|
GetLogicalProcessorInformation(nullptr, &len);
|
||||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||||
throw std::runtime_error(std::to_string(GetLastError()).c_str());
|
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)) {
|
if (!GetLogicalProcessorInformation(buffer.data(), &len)) {
|
||||||
throw std::runtime_error(std::to_string(GetLastError()).c_str());
|
throw std::runtime_error(std::to_string(GetLastError()).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD count = len / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
|
|
||||||
int physicalCoreCount = 0;
|
int physicalCoreCount = 0;
|
||||||
|
for (auto& i : buffer)
|
||||||
for (DWORD i = 0; i < count; ++i) {
|
{
|
||||||
if (buffer[i].Relationship == RelationProcessorCore) {
|
if (i.Relationship == RelationProcessorCore)
|
||||||
physicalCoreCount++;
|
{
|
||||||
|
++physicalCoreCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return physicalCoreCount;
|
return physicalCoreCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.hpp" "*.h")
|
|||||||
|
|
||||||
add_library(RenderEngineSDK ${SRC})
|
add_library(RenderEngineSDK ${SRC})
|
||||||
|
|
||||||
|
target_compile_features(RenderEngineSDK PRIVATE cxx_std_17)
|
||||||
|
|
||||||
target_include_directories(RenderEngineSDK PUBLIC
|
target_include_directories(RenderEngineSDK PUBLIC
|
||||||
${PROJECT_SOURCE_DIR}/glfw/Include
|
${PROJECT_SOURCE_DIR}/glfw/Include
|
||||||
${PROJECT_SOURCE_DIR}/Delegate
|
${PROJECT_SOURCE_DIR}/Delegate
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
VkExtent2D DeviceFunctions::choose_extent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window)
|
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{};
|
VkPhysicalDeviceMemoryProperties memory_properties{};
|
||||||
vkGetPhysicalDeviceMemoryProperties(physical_device, &memory_properties);
|
vkGetPhysicalDeviceMemoryProperties(physical_device, &memory_properties);
|
||||||
|
|
||||||
|
std::optional<uint32_t> mem_type = 0;
|
||||||
for (uint32_t i = 0; i < memory_properties.memoryTypeCount; ++i)
|
for (uint32_t i = 0; i < memory_properties.memoryTypeCount; ++i)
|
||||||
{
|
{
|
||||||
if (typeFilter & (1 << i) && (memory_properties.memoryTypes[i].propertyFlags & properties) == properties)
|
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)
|
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.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||||
copy_pool_info.queueFamilyIndex = transfer_queue_family;
|
copy_pool_info.queueFamilyIndex = transfer_queue_family;
|
||||||
copy_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
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{};
|
VkCommandBufferAllocateInfo command_buffer_allocate_info{};
|
||||||
command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_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;
|
command_buffer_allocate_info.commandBufferCount = 1;
|
||||||
|
|
||||||
VkCommandBuffer copy_buffer;
|
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{};
|
VkCommandBufferBeginInfo command_buffer_begin_info{};
|
||||||
command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_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;
|
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.srcOffset = 0;
|
||||||
buffer_copy.dstOffset = 0;
|
buffer_copy.dstOffset = 0;
|
||||||
buffer_copy.size = size;
|
buffer_copy.size = size;
|
||||||
@@ -105,7 +109,7 @@ VkBuffer DeviceFunctions::create_buffer(VkDevice device, VkDeviceSize size, VkBu
|
|||||||
}
|
}
|
||||||
|
|
||||||
VkBuffer buffer;
|
VkBuffer buffer;
|
||||||
VK_CHECK(vkCreateBuffer(device, &buffer_info, nullptr, &buffer));
|
VK_CHECK(vkCreateBuffer(device, &buffer_info, nullptr, &buffer))
|
||||||
return 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);
|
allocate_info.memoryTypeIndex = find_memory_type(physical_device, requirements.memoryTypeBits, property);
|
||||||
|
|
||||||
VkDeviceMemory device_memory;
|
VkDeviceMemory device_memory;
|
||||||
VK_CHECK(vkAllocateMemory(device, &allocate_info, nullptr, &device_memory));
|
VK_CHECK(vkAllocateMemory(device, &allocate_info, nullptr, &device_memory))
|
||||||
return device_memory;
|
return device_memory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "Game/World/World.hpp"
|
#include "Game/World/World.hpp"
|
||||||
#include "../Game/Actors/Mesh/Mesh.hpp"
|
#include "../Game/Actors/Mesh/Mesh.hpp"
|
||||||
#include "DeviceFunctions/DeviceFunctions.hpp"
|
#include "DeviceFunctions/DeviceFunctions.hpp"
|
||||||
|
#include "Log/Log.hpp"
|
||||||
|
|
||||||
RENDER_ENGINE_FACTORY_GENERATE(UwURenderEngine)
|
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_[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);
|
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);
|
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]);
|
vkMapMemory(device_.get_native(), uniform_buffers_memory_[i], 0, size, 0, &uniform_buffers_mapped_[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user