diff options
| author | hachem <im@hachem.wtf> | 2026-09-22 06:40:02 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-22 06:40:02 +0200 |
| commit | e321beb543311dcb591942ec42464e38cbeae0f0 (patch) | |
| tree | 1b0c1a9747d19a2cb74ad09a0365c139ef36b5d4 /src/platform/vulkan/vulkan_device.cpp | |
| parent | 53fa01afb052fd64c99e87fd53c22654e796b64f (diff) | |
fix: Vulkan backend on Windows
Diffstat (limited to 'src/platform/vulkan/vulkan_device.cpp')
| -rw-r--r-- | src/platform/vulkan/vulkan_device.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/platform/vulkan/vulkan_device.cpp b/src/platform/vulkan/vulkan_device.cpp index b4c2630..f5d7662 100644 --- a/src/platform/vulkan/vulkan_device.cpp +++ b/src/platform/vulkan/vulkan_device.cpp @@ -1,5 +1,15 @@ #include "vulkan_common.h" +#include <algorithm> +#include <filesystem> + +#if defined(_WIN32) + #ifndef NOMINMAX + #define NOMINMAX + #endif + #include <windows.h> +#endif + #include <imgui.h> #include <imgui_impl_glfw.h> #include <imgui_impl_vulkan.h> @@ -44,7 +54,14 @@ namespace Donut::RHI auto VulkanDevice::create_shader_module(const std::string& path, VkShaderModule& out) const -> bool { auto spv = load_spirv(path); - if (spv.empty()) { DONUT_ERROR("Vulkan RHI: failed to load SPIR-V {}", path); return false; } + if (spv.empty()) + { + std::error_code ec; + const auto cwd = std::filesystem::current_path(ec).u8string(); + DONUT_ERROR("Vulkan RHI: failed to load SPIR-V {} (cwd {}; shaders live in assets/shaders/generated, see tools/compile-shaders.sh)", + path, std::string(cwd.begin(), cwd.end())); + return false; + } VkShaderModuleCreateInfo ci{ VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO }; ci.codeSize = spv.size() * 4; ci.pCode = spv.data(); return vkCreateShaderModule(m_device, &ci, nullptr, &out) == VK_SUCCESS; @@ -184,6 +201,10 @@ namespace Donut::RHI void* mp = nullptr; vkMapMemory(m_device, mem, 0, sz, 0, &mp); std::memcpy(out.data(), mp, sz); vkUnmapMemory(m_device, mem); + const size_t row = (size_t)w * 4; + for (uint32_t y = 0; y < h / 2; ++y) + std::swap_ranges(out.begin() + (std::ptrdiff_t)(y * row), out.begin() + (std::ptrdiff_t)((y + 1) * row), + out.begin() + (std::ptrdiff_t)((h - 1 - y) * row)); vkFreeCommandBuffers(m_device, m_command_pool, 1, &cmd); vkDestroyBuffer(m_device, buf, nullptr); vkFreeMemory(m_device, mem, nullptr); } @@ -221,6 +242,10 @@ namespace Donut::RHI void* mp = nullptr; vkMapMemory(m_device, mem, 0, sz, 0, &mp); std::memcpy(out.data(), mp, sz); vkUnmapMemory(m_device, mem); + const size_t row = (size_t)w * 4; + for (uint32_t y = 0; y < h / 2; ++y) + std::swap_ranges(out.begin() + (std::ptrdiff_t)(y * row), out.begin() + (std::ptrdiff_t)((y + 1) * row), + out.begin() + (std::ptrdiff_t)((h - 1 - y) * row)); vkFreeCommandBuffers(m_device, m_command_pool, 1, &cmd); vkDestroyBuffer(m_device, buf, nullptr); vkFreeMemory(m_device, mem, nullptr); } @@ -291,6 +316,15 @@ namespace Donut::RHI auto create_vulkan_device() -> Scope<Device> { return create_scope<VulkanDevice>(); } + auto vulkan_runtime_available() -> bool + { +#if defined(_WIN32) + return LoadLibraryExW(L"vulkan-1.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32) != nullptr; +#else + return true; +#endif + } + auto vulkan_prepare_glfw() -> void { #ifdef __APPLE__ |
