Исправил неопределённое поведение и добавил агрессивные оптимизации для Release конфигурации
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user