From 6bb808bbce46c460714e965caecb2307c21aa306 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 2 Feb 2026 01:23:45 -0800 Subject: [PATCH 1/2] Vulkan implementations are updated to handle Apple M-series configurations --- atlas/drivers/vulkan/device.cppm | 10 ++-- atlas/drivers/vulkan/instance_context.cppm | 61 ++++++++++------------ atlas/drivers/vulkan/physical_device.cppm | 13 ++++- atlas/drivers/vulkan/render_system.cppm | 19 +++++-- atlas/drivers/vulkan/swapchain.cppm | 4 +- 5 files changed, 64 insertions(+), 43 deletions(-) diff --git a/atlas/drivers/vulkan/device.cppm b/atlas/drivers/vulkan/device.cppm index c05f3202..efae541b 100644 --- a/atlas/drivers/vulkan/device.cppm +++ b/atlas/drivers/vulkan/device.cppm @@ -98,9 +98,11 @@ namespace atlas::vulkan { float queue_priority[1] = { 0.0f }; - std::vector device_extension = { - VK_KHR_SWAPCHAIN_EXTENSION_NAME - }; + #if defined(__APPLE__) + std::vector device_extension = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, "VK_KHR_portability_subset" }; + #else + std::vector device_extension = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; + #endif uint32_t graphics_index = m_physical.read_queue_family_indices().graphics; @@ -203,4 +205,4 @@ namespace atlas::vulkan { device_queue_family m_device_queues{}; VkFormat m_depth_format_selected; }; -}; \ No newline at end of file +}; diff --git a/atlas/drivers/vulkan/instance_context.cppm b/atlas/drivers/vulkan/instance_context.cppm index 80b828fd..cff67b81 100644 --- a/atlas/drivers/vulkan/instance_context.cppm +++ b/atlas/drivers/vulkan/instance_context.cppm @@ -27,42 +27,31 @@ import atlas.drivers.vulkan.physical_device; import atlas.drivers.vulkan.device; namespace atlas::vulkan { + static std::vector initialize_instance_extensions() { std::vector extension_names; - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + uint32_t extension_count = 0; + const char** require_extensions = glfwGetRequiredInstanceExtensions(&extension_count); + + for(uint32_t i = 0; i < extension_count; i++) { + // std::println("Required Extension = {}", require_extensions[i]); + extension_names.emplace_back(require_extensions[i]); + } + + #if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG) extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + #endif - // An additional surface extension needs to be loaded. This extension is - // platform-specific so needs to be selected based on the platform the - // example is going to be deployed to. Preprocessor directives are used - // here to select the correct platform. -#ifdef VK_USE_PLATFORM_WIN32_KHR - extension_names.emplace_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); -#endif -#ifdef VK_USE_PLATFORM_XLIB_KHR - extensionNames.emplace_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); -#endif -#ifdef VK_USE_PLATFORM_XCB_KHR - extensionNames.emplace_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); -#endif -#ifdef VK_USE_PLATFORM_ANDROID_KHR - extensionNames.emplace_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); -#endif -#ifdef VK_USE_PLATFORM_WAYLAND_KHR - extensionNames.emplace_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); -#endif -#ifdef VK_USE_PLATFORM_MACOS_MVK - extensionNames.emplace_back(VK_MVK_MACOS_SURFACE_EXTENSION_NAME); -#endif -#ifdef USE_PLATFORM_NULLWS - extensionNames.emplace_back(VK_KHR_DISPLAY_EXTENSION_NAME); -#endif + #if defined(__APPLE__) + extension_names.emplace_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); + extension_names.emplace_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); + #endif return extension_names; } -#ifdef _DEBUG +#if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG) const std::vector validation_layers = { "VK_LAYER_KHRONOS_validation", "VK_LAYER_KHRONOS_synchronization2" @@ -98,15 +87,20 @@ namespace atlas::vulkan { .pApplicationInfo = &app_info }; + + #if defined(__APPLE__) + create_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; + #endif + //! @note Setting up the required extensions for vulkan std::vector extensions = initialize_instance_extensions(); - #if _DEBUG + #if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG) extensions.push_back("VK_EXT_debug_utils"); #endif create_info.enabledExtensionCount = static_cast(extensions.size()); create_info.ppEnabledExtensionNames = extensions.data(); - #ifdef _DEBUG + #if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG) // by default we enable validation layers used for debugging! create_info.enabledLayerCount = static_cast(validation_layers.size()); @@ -144,8 +138,9 @@ namespace atlas::vulkan { .pfnUserCallback = debug_callback, }; - create_info.pNext = - (VkDebugUtilsMessengerCreateInfoEXT*)&debug_create_info; + + // create_info.pNext = (VkDebugUtilsMessengerCreateInfoEXT*)&debug_create_info; + create_info.pNext = static_cast(&debug_create_info); #else create_info.enabledLayerCount = 0; create_info.ppEnabledLayerNames = nullptr; @@ -154,7 +149,7 @@ namespace atlas::vulkan { vk_check(vkCreateInstance(&create_info, nullptr, &m_instance_handler), "vkCreateInstance"); - #if _DEBUG + #if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG) // This needs to be created after the VkInstance is or else it wont be // applied the debug information during validation layer error message // execution @@ -244,4 +239,4 @@ namespace atlas::vulkan { }; instance_context* instance_context::s_instance = nullptr; -}; \ No newline at end of file +}; diff --git a/atlas/drivers/vulkan/physical_device.cppm b/atlas/drivers/vulkan/physical_device.cppm index 03956e7d..0ca18c76 100644 --- a/atlas/drivers/vulkan/physical_device.cppm +++ b/atlas/drivers/vulkan/physical_device.cppm @@ -72,11 +72,22 @@ export namespace atlas::vulkan { VkPhysicalDeviceFeatures device_features; vkGetPhysicalDeviceProperties(device, &device_properties); vkGetPhysicalDeviceFeatures(device, &device_features); + #if defined(__APPLE__) + // Apple silicon chips are integrated GPUs + // Prefer integrated GPU over discrete GPU on macOS + if (device_properties.deviceType == + VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) { + m_physical_driver = device; + break; + } + #else + // Prefer discrete GPU over integrated GPU on other platforms (Linux, Windows) if (device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) { m_physical_driver = device; break; } + #endif } uint32_t queue_family_count = 0; @@ -213,4 +224,4 @@ export namespace atlas::vulkan { std::vector m_queue_family_properties{}; surface_properties m_surface_properties{}; }; -}; \ No newline at end of file +}; diff --git a/atlas/drivers/vulkan/render_system.cppm b/atlas/drivers/vulkan/render_system.cppm index 678c7192..2f625db1 100644 --- a/atlas/drivers/vulkan/render_system.cppm +++ b/atlas/drivers/vulkan/render_system.cppm @@ -457,14 +457,27 @@ export namespace atlas::vulkan { }); std::vector modules = m_shader_group.handles(); + + std::array color_blend_attachments = { + vk::color_blend_attachment_state{}, + }; + + std::array dynamic_states = { + vk::dynamic_state::viewport, vk::dynamic_state::scissor + }; - vk::pipeline_settings pipeline_configuration = { + vk::pipeline_params pipeline_configuration = { .renderpass = m_final_renderpass, .shader_modules = modules, .vertex_attributes = m_shader_group.vertex_attributes(), .vertex_bind_attributes = m_shader_group.vertex_bind_attributes(), - .descriptor_layouts = m_sets_layouts + .descriptor_layouts = m_sets_layouts, + .color_blend = { + .attachments = color_blend_attachments, + }, + .depth_stencil_enabled = true, + .dynamic_states = dynamic_states, }; m_main_pipeline = vk::pipeline(m_device, pipeline_configuration); @@ -672,4 +685,4 @@ export namespace atlas::vulkan { ref m_current_scene; }; -}; \ No newline at end of file +}; diff --git a/atlas/drivers/vulkan/swapchain.cppm b/atlas/drivers/vulkan/swapchain.cppm index 21733e36..5ee2b31c 100644 --- a/atlas/drivers/vulkan/swapchain.cppm +++ b/atlas/drivers/vulkan/swapchain.cppm @@ -170,7 +170,7 @@ export namespace atlas::vulkan { .preTransform = m_surface_properties.surface_capabilities.currentTransform, .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, - .presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR, + .presentMode = VK_PRESENT_MODE_FIFO_KHR, .clipped = true }; @@ -335,4 +335,4 @@ export namespace atlas::vulkan { vk::device_present_queue m_present_to_queue; }; -}; \ No newline at end of file +}; From 7a13871cf035252ed93aa66620d56a1cc2a6e15c Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 2 Feb 2026 19:10:14 -0800 Subject: [PATCH 2/2] Update: conanfile.py vulkan-cpp version 4.0 to 5.0 --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index 6cf03b46..ee5fcc80 100644 --- a/conanfile.py +++ b/conanfile.py @@ -40,7 +40,7 @@ def requirements(self): self.requires("yaml-cpp/0.8.0") # Vulkan-related headers and includes packages - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") self.requires("tinyobjloader/2.0.0-rc10") self.requires("stb/cci.20230920")