В моей программе Vulkan GLFW открывает окно, но сбои на vkcreateswapchainkhr, что не так?C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 В моей программе Vulkan GLFW открывает окно, но сбои на vkcreateswapchainkhr, что не так?

Сообщение Anonymous »

На Popos 22 я могу успешно построить демоверсии Vulkan и компиляция. Таким образом, библиотеки работают.
Я написал компактную демонстрацию, которая сбивается с VkcreatesWapchainkhr. /> в коде GDB сбоятся в строке 142 vulkan_core.cpp < /p>
/*
Vulkan core utilities

Author:
Date: 2025-03-11
*/

#include
#include
#include "vulkan_core.hh"
#include
using namespace std;

language current_lang = language::en;

class vulkan_core {
private:
VkInstance instance;
VkPhysicalDevice physical_device;
VkDevice device;
VkSurfaceKHR surface;
int32_t graphics_queue_family;
VkQueue graphics_queue;
VkSwapchainKHR swapchain;
VkFormat swapchain_format;
VkExtent2D swapchain_extent;
GLFWwindow* window;

void create_instance() {
VkApplicationInfo app_info = {};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app_info.pApplicationName = settings.title.c_str();
app_info.engineVersion = 1;
app_info.apiVersion = VK_API_VERSION_1_0;

VkInstanceCreateInfo inst_info = {};
inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
inst_info.pApplicationInfo = &app_info;

VkResult res = vkCreateInstance(&inst_info, nullptr, &instance);
vkcheck_msg(res, error_type::initialization, "vkCreateInstance");
}

void physical_device_init() {
uint32_t gpu_count = 0;
vkcheck_msg(vkEnumeratePhysicalDevices(instance, &gpu_count, nullptr),
error_type::initialization, "vkEnumeratePhysicalDevices");

std::vector physical_devices(gpu_count);
vkcheck_msg(vkEnumeratePhysicalDevices(instance, &gpu_count, physical_devices.data()),
error_type::initialization, "vkEnumeratePhysicalDevices");

if (gpu_count > 0) {
physical_device = physical_devices[0];

uint32_t queue_family_count = 0;
vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_family_count, nullptr);
std::vector queue_families(queue_family_count);
vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_family_count, queue_families.data());

graphics_queue_family = -1;
for (uint32_t i = 0; i < queue_family_count; i++) {
if (queue_families.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
graphics_queue_family = i;
break;
}
}
if (graphics_queue_family == -1) {
throw ex(__FILE__, __LINE__, error_type::initialization, "No graphics queue found");
}
} else {
throw ex(__FILE__, __LINE__, error_type::initialization, "No physical devices found");
}
}

void create_logical_device() {
float queue_priority = 1.0f;
VkDeviceQueueCreateInfo queue_create_info = {};
queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queue_create_info.queueFamilyIndex = graphics_queue_family;
queue_create_info.queueCount = 1;
queue_create_info.pQueuePriorities = &queue_priority;

// Add required device extensions before device_create_info
const std::vector device_extensions = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME
};

VkDeviceCreateInfo device_create_info = {};
device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
device_create_info.queueCreateInfoCount = 1;
device_create_info.pQueueCreateInfos = &queue_create_info;
device_create_info.enabledExtensionCount = static_cast(device_extensions.size());
device_create_info.ppEnabledExtensionNames = device_extensions.data();

vkcheck_msg(vkCreateDevice(physical_device, &device_create_info, nullptr, &device),
error_type::initialization, "vkCreateDevice");

vkGetDeviceQueue(device, graphics_queue_family, 0, &graphics_queue);
}

void create_swapchain() {
VkSurfaceCapabilitiesKHR capabilities;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &capabilities);

uint32_t format_count;
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &format_count, nullptr);
std::vector formats(format_count);
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &format_count, formats.data());

VkSurfaceFormatKHR surface_format = formats[0];
for (const auto& format : formats) {
if (format.format == VK_FORMAT_B8G8R8A8_SRGB &&
format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
surface_format = format;
break;
}
}

swapchain_format = surface_format.format;
swapchain_extent = capabilities.currentExtent;

VkSwapchainCreateInfoKHR create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
create_info.surface = surface;
create_info.minImageCount = capabilities.minImageCount + 1;
create_info.imageFormat = surface_format.format;
create_info.imageColorSpace = surface_format.colorSpace;
create_info.imageExtent = capabilities.currentExtent;
create_info.imageArrayLayers = 1;
create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
create_info.preTransform = capabilities.currentTransform;
create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
create_info.presentMode = VK_PRESENT_MODE_FIFO_KHR;
create_info.clipped = VK_TRUE;

if (surface == VK_NULL_HANDLE) {
throw ex(__FILE__, __LINE__, error_type::initialization, "Device handle is null before swapchain creation");
}
vkcheck_msg(vkCreateSwapchainKHR(device, &create_info, nullptr, &swapchain),
error_type::initialization, "vkCreateSwapchainKHR");
}

void create_render_pass() {
}

void create_framebuffers() {
}

void create_command_pool() {
}

void create_vertex_buffer() {
}

void create_command_buffers() {
}

void create_sync_objects() {
}

public:
vulkan_core(GLFWwindow* win) {
create_instance();
physical_device_init();
create_logical_device();
create_swapchain();
create_render_pass();
create_framebuffers();
create_command_pool();
create_vertex_buffer();
create_command_buffers();
create_sync_objects();
}

~vulkan_core() {
if (instance != VK_NULL_HANDLE) {
vkDestroyInstance(instance, nullptr);
}
// Will add other cleanup as we implement each component
}
};

void test_all_exceptions(ofstream& log) {
#if MULTI_LANGUAGE
// Cast to underlying type to allow iteration
for (int lang = static_cast(language::en);
lang

Подробнее здесь: https://stackoverflow.com/questions/795 ... ainkhr-wha
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»