From e321beb543311dcb591942ec42464e38cbeae0f0 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 22 Sep 2026 06:40:02 +0200 Subject: fix: Vulkan backend on Windows --- src/platform/vulkan/vulkan_device.cpp | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/platform/vulkan/vulkan_device.cpp') 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 +#include + +#if defined(_WIN32) + #ifndef NOMINMAX + #define NOMINMAX + #endif + #include +#endif + #include #include #include @@ -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 { return create_scope(); } + 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__ -- cgit v1.3