Clear code

This commit is contained in:
Jiga228
2025-10-07 21:18:11 +07:00
parent d5261561ed
commit 2b2ed1f050
2 changed files with 15 additions and 0 deletions
+10
View File
@@ -78,10 +78,13 @@ VkVertexInputBindingDescription RenderEngine::Vertex::get_binding_description()
std::array<VkVertexInputAttributeDescription, 2> RenderEngine::Vertex::get_vertex_attribute_descriptions() std::array<VkVertexInputAttributeDescription, 2> RenderEngine::Vertex::get_vertex_attribute_descriptions()
{ {
std::array<VkVertexInputAttributeDescription, 2> descriptions; std::array<VkVertexInputAttributeDescription, 2> descriptions;
// Bind vertex loc
descriptions[0].binding = 0; descriptions[0].binding = 0;
descriptions[0].location = 0; descriptions[0].location = 0;
descriptions[0].format = VK_FORMAT_R32G32_SFLOAT; descriptions[0].format = VK_FORMAT_R32G32_SFLOAT;
descriptions[0].offset = offsetof(Vertex, pos); descriptions[0].offset = offsetof(Vertex, pos);
// Bind color
descriptions[1].binding = 0; descriptions[1].binding = 0;
descriptions[1].location = 1; descriptions[1].location = 1;
descriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT; descriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
@@ -98,6 +101,7 @@ bool RenderEngine::is_device_suitable(VkPhysicalDevice device, VkSurfaceKHR surf
vkGetPhysicalDeviceFeatures(device, &device_features); vkGetPhysicalDeviceFeatures(device, &device_features);
try { try {
// Ловить исключения имеет смысыл только здесь
QueueFamilyIndices indices = find_queue_family_indices(device, surface); QueueFamilyIndices indices = find_queue_family_indices(device, surface);
} catch (...) { } catch (...) {
return false; return false;
@@ -155,8 +159,10 @@ RenderEngine::QueueFamilyIndices RenderEngine::find_queue_family_indices(VkPhysi
// Find present // Find present
VkBool32 present_support = false; VkBool32 present_support = false;
VK_CHECK(vkGetPhysicalDeviceSurfaceSupportKHR(physical_device, queue_family_indices.graphics_family.value(), surface, &present_support)); VK_CHECK(vkGetPhysicalDeviceSurfaceSupportKHR(physical_device, queue_family_indices.graphics_family.value(), surface, &present_support));
// Если графическая очередь поддерживет презентацию кадров, то используем её
if (present_support == VK_TRUE) if (present_support == VK_TRUE)
queue_family_indices.present_family = queue_family_indices.graphics_family; queue_family_indices.present_family = queue_family_indices.graphics_family;
// иначе ищем другую подходящую очередь
else else
{ {
for(uint32_t i = 0; i < family_properties.size(); ++i) for(uint32_t i = 0; i < family_properties.size(); ++i)
@@ -174,6 +180,8 @@ RenderEngine::QueueFamilyIndices RenderEngine::find_queue_family_indices(VkPhysi
if (queue_family_indices.present_family.has_value() == false) if (queue_family_indices.present_family.has_value() == false)
throw std::runtime_error("Failed to find a present queue family"); throw std::runtime_error("Failed to find a present queue family");
// С начала пытаемся найти очередь специалезированную
// для копирования отличную от графической
for(uint32_t i = 0; i < family_properties.size(); ++i) for(uint32_t i = 0; i < family_properties.size(); ++i)
{ {
if (i == queue_family_indices.graphics_family.value()) if (i == queue_family_indices.graphics_family.value())
@@ -181,6 +189,7 @@ RenderEngine::QueueFamilyIndices RenderEngine::find_queue_family_indices(VkPhysi
if (family_properties[i].queueFlags & VK_QUEUE_TRANSFER_BIT) if (family_properties[i].queueFlags & VK_QUEUE_TRANSFER_BIT)
queue_family_indices.transfer_family = i; queue_family_indices.transfer_family = i;
} }
// Если не находим, то используем графическую
if (queue_family_indices.transfer_family.has_value() == false) if (queue_family_indices.transfer_family.has_value() == false)
queue_family_indices.transfer_family = queue_family_indices.graphics_family; queue_family_indices.transfer_family = queue_family_indices.graphics_family;
return queue_family_indices; return queue_family_indices;
@@ -208,6 +217,7 @@ VkPresentModeKHR RenderEngine::choose_present_mode(const std::vector<VkPresentMo
VkExtent2D RenderEngine::choose_extent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window) VkExtent2D RenderEngine::choose_extent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window)
{ {
// Здесь вычисляется допустимое разрешение рендера
if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max()) if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max())
return capabilities.currentExtent; return capabilities.currentExtent;
else else
+5
View File
@@ -60,7 +60,9 @@ class RenderEngine
int current_frame_ = 0; int current_frame_ = 0;
CoreInstance& core_; CoreInstance& core_;
GLFWwindow* window_; GLFWwindow* window_;
VkInstance instance_ = VK_NULL_HANDLE; VkInstance instance_ = VK_NULL_HANDLE;
VkSurfaceKHR surface_ = VK_NULL_HANDLE; VkSurfaceKHR surface_ = VK_NULL_HANDLE;
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE; VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
@@ -80,6 +82,7 @@ class RenderEngine
VkCommandPool command_pool_ = VK_NULL_HANDLE; VkCommandPool command_pool_ = VK_NULL_HANDLE;
std::vector<VkCommandBuffer> command_buffers_; std::vector<VkCommandBuffer> command_buffers_;
// Sync objects
std::vector<VkSemaphore> image_available_semaphores_, render_finished_semaphores_; std::vector<VkSemaphore> image_available_semaphores_, render_finished_semaphores_;
std::vector<VkFence> in_flight_fences_; std::vector<VkFence> in_flight_fences_;
@@ -123,4 +126,6 @@ public:
void start(); void start();
void stop_render() const; void stop_render() const;
GLFWwindow* get_window() const { return window_; }
}; };