Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions atlas/drivers/vulkan/device.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ namespace atlas::vulkan {

float queue_priority[1] = { 0.0f };

std::vector<const char*> device_extension = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME
};
#if defined(__APPLE__)
std::vector<const char*> device_extension = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, "VK_KHR_portability_subset" };
#else
std::vector<const char*> device_extension = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
#endif

uint32_t graphics_index =
m_physical.read_queue_family_indices().graphics;
Expand Down Expand Up @@ -203,4 +205,4 @@ namespace atlas::vulkan {
device_queue_family m_device_queues{};
VkFormat m_depth_format_selected;
};
};
};
61 changes: 28 additions & 33 deletions atlas/drivers/vulkan/instance_context.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,31 @@ import atlas.drivers.vulkan.physical_device;
import atlas.drivers.vulkan.device;

namespace atlas::vulkan {

static std::vector<const char*> initialize_instance_extensions() {
std::vector<const char*> 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<const char*> validation_layers = {
"VK_LAYER_KHRONOS_validation",
"VK_LAYER_KHRONOS_synchronization2"
Expand Down Expand Up @@ -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<const char*> 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<uint32_t>(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<uint32_t>(validation_layers.size());
Expand Down Expand Up @@ -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<VkDebugUtilsMessengerCreateInfoEXT*>(&debug_create_info);
#else
create_info.enabledLayerCount = 0;
create_info.ppEnabledLayerNames = nullptr;
Expand All @@ -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
Expand Down Expand Up @@ -244,4 +239,4 @@ namespace atlas::vulkan {
};

instance_context* instance_context::s_instance = nullptr;
};
};
13 changes: 12 additions & 1 deletion atlas/drivers/vulkan/physical_device.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -213,4 +224,4 @@ export namespace atlas::vulkan {
std::vector<VkQueueFamilyProperties> m_queue_family_properties{};
surface_properties m_surface_properties{};
};
};
};
19 changes: 16 additions & 3 deletions atlas/drivers/vulkan/render_system.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,27 @@ export namespace atlas::vulkan {
});

std::vector<vk::shader_handle> modules = m_shader_group.handles();

std::array<vk::color_blend_attachment_state, 1> color_blend_attachments = {
vk::color_blend_attachment_state{},
};

std::array<vk::dynamic_state, 2> 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);

Expand Down Expand Up @@ -672,4 +685,4 @@ export namespace atlas::vulkan {

ref<scene> m_current_scene;
};
};
};
4 changes: 2 additions & 2 deletions atlas/drivers/vulkan/swapchain.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -335,4 +335,4 @@ export namespace atlas::vulkan {

vk::device_present_queue m_present_to_queue;
};
};
};
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Loading