fix surface creation on linux

This commit is contained in:
2026-05-23 23:29:57 -05:00
parent 65d21cd3c4
commit 8b798fcaa7
3 changed files with 17 additions and 9 deletions

View File

@@ -129,13 +129,14 @@ bool Device::createLogicalDevice() {
break; break;
} }
} }
if(queueIndex == -1) { if(queueIndex <= -1) {
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error: could not locate valid graphics queues." << std::endl; std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error: could not locate valid graphics queues." << std::endl;
return false;
} }
float queuePriority = 0.5f; float queuePriority = 0.5f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo { vk::DeviceQueueCreateInfo deviceQueueCreateInfo {
.queueFamilyIndex = queueIndex, .queueFamilyIndex = static_cast<uint32_t>(queueIndex),
.queueCount = 1, .queueCount = 1,
.pQueuePriorities = &queuePriority .pQueuePriorities = &queuePriority
}; };
@@ -173,6 +174,6 @@ bool Device::createLogicalDevice() {
void Device::createSurface() { void Device::createSurface() {
(void)window_->createSurface(&surface_); (void)window_->createSurface(instance_, &surface_);
} }

View File

@@ -45,18 +45,25 @@ void Window::handleEvent(SDL_Event& event) {
} }
} }
bool Window::createSurface(vk::raii::SurfaceKHR* surface) { bool Window::createSurface(vk::raii::Instance* instance, vk::raii::SurfaceKHR* surface) {
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] createSurface()" << std::endl; if(instance == nullptr) {
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error: cannot create surface with a null Vulkan instance." << std::endl;
return false;
}
#ifdef __WIN32 #ifdef __WIN32
vk::Win32SurfaceCreateInfoKHR createInfo { vk::Win32SurfaceCreateInfoKHR createInfo {
.hinstance = GetModuleHandle(nullptr), .hinstance = GetModuleHandle(nullptr),
.hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(sdlWindow_), "SDL.window.win32.hwnd", nullptr); .hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(sdlWindow_), "SDL.window.win32.hwnd", nullptr);
} }
surface = &instance_.createWin32SurfaceKHR(createInfo); surface = instance->createWin32SurfaceKHR(createInfo);
#else // __WIN32 #else
// this is so unbelievably ugly im so sorry
// its just sdl3 uses the c vulkan api and the app uses the c++ api
VkSurfaceKHR cSurface;
(void)SDL_Vulkan_CreateSurface(sdlWindow_, static_cast<VkInstance>(**instance), nullptr, &cSurface);
*surface = vk::raii::SurfaceKHR(*instance, cSurface);
#endif // __WIN32 #endif // __WIN32
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] attempted to createSurface" << std::endl; std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] attempted to createSurface" << std::endl;

View File

@@ -18,7 +18,7 @@ public:
bool rendering() { return rendering_; } bool rendering() { return rendering_; }
bool open() { return open_; } bool open() { return open_; }
bool createSurface(vk::raii::SurfaceKHR* surface); bool createSurface(vk::raii::Instance* instance, vk::raii::SurfaceKHR* surface);
private: private: