diff --git a/demos/1-instance/application.cpp b/demos/1-instance/application.cpp index 164a766..3125687 100644 --- a/demos/1-instance/application.cpp +++ b/demos/1-instance/application.cpp @@ -26,38 +26,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -90,8 +77,7 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { .severity = diff --git a/demos/1-instance/conanfile.py b/demos/1-instance/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/1-instance/conanfile.py +++ b/demos/1-instance/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/10-textures/application.cpp b/demos/10-textures/application.cpp index cf950a3..83e6538 100644 --- a/demos/10-textures/application.cpp +++ b/demos/10-textures/application.cpp @@ -20,6 +20,8 @@ import vk; #define GLM_FORCE_RADIANS #include #include +#include +#include static VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback( @@ -32,38 +34,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -106,16 +95,11 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { - // .severity essentially takes in vk::message::verbose, - // vk::message::warning, vk::message::error .severity = vk::message::verbose | vk::message::warning | vk::message::error, - // .message_type essentially takes in vk::debug. Like: - // vk::debug::general, vk::debug::validation, vk::debug::performance .message_type = vk::debug::general | vk::debug::validation | vk::debug::performance, .callback = debug_callback @@ -137,24 +121,18 @@ main() { std::println("\napi_instance alive and initiated!!!"); } - // TODO: Implement this as a way to setup physical devices - // vk::enumerate_physical_devices(vk::instance) -> returns - // std::span - - // setting up physical device - // TODO: Probably enforce the use of - // vk::enumerate_physical_device({.device_type = - // vk::physical_gpu::discrete}) vk::physical_enumeration enumerate_devices{ .device_type = vk::physical_gpu::discrete, }; + +#if defined(__APPLE__) + enumerate_devices.device_type = vk::physical_gpu::integrated; +#endif + vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format std::array format_support = { - // VK_FORMAT_D32_SFLOAT, - // VK_FORMAT_D32_SFLOAT_S8_UINT, - // VK_FORMAT_D24_UNORM_S8_UINT, vk::format::d32_sfloat, vk::format::d32_sfloat_s8_uint, vk::format::d24_unorm_s8_uint @@ -172,7 +150,14 @@ main() { // setting up logical device std::array priorities = { 0.f }; + +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, @@ -204,19 +189,8 @@ main() { surface_properties); // querying swapchain images - // TODO: Make the images and framebuffers contained within the vk::swapchain - // Considering if you have two display they will prob have their own set of - // images to display to the two separate screens - uint32_t image_count = 0; - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - nullptr); // used to get the amount of images - std::vector images(image_count); - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - images.data()); // used to store in the images + std::span images = main_swapchain.get_images(); + uint32_t image_count = static_cast(images.size()); // Creating Images std::vector swapchain_images(image_count); @@ -279,7 +253,7 @@ main() { .layout = vk::image_layout::color_optimal, .samples = vk::sample_bit::count_1, .load = vk::attachment_load::clear, - .store = vk::attachment_store::dont_care, + .store = vk::attachment_store::store, .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, @@ -294,7 +268,7 @@ main() { .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, - .final_layout = vk::image_layout::present_src_khr, + .final_layout = vk::image_layout::depth_stencil_read_only_optimal, }, }; @@ -506,7 +480,7 @@ main() { vk::texture_info config_texture = { .phsyical_memory_properties = physical_device.memory_properties(), .filepath = - std::filesystem::path("asset_samples/container_diffuse.png") + std::filesystem::path("asset_samples/container_diffuse.png"), }; vk::texture texture1(logical_device, config_texture); diff --git a/demos/10-textures/conanfile.py b/demos/10-textures/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/10-textures/conanfile.py +++ b/demos/10-textures/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/11-depth-buffering/application.cpp b/demos/11-depth-buffering/application.cpp index a98986c..30887b8 100644 --- a/demos/11-depth-buffering/application.cpp +++ b/demos/11-depth-buffering/application.cpp @@ -32,37 +32,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); + + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -101,16 +89,11 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { - // .severity essentially takes in vk::message::verbose, - // vk::message::warning, vk::message::error .severity = vk::message::verbose | vk::message::warning | vk::message::error, - // .message_type essentially takes in vk::debug. Like: - // vk::debug::general, vk::debug::validation, vk::debug::performance .message_type = vk::debug::general | vk::debug::validation | vk::debug::performance, .callback = debug_callback @@ -132,24 +115,18 @@ main() { std::println("\napi_instance alive and initiated!!!"); } - // TODO: Implement this as a way to setup physical devices - // vk::enumerate_physical_devices(vk::instance) -> returns - // std::span - - // setting up physical device - // TODO: Probably enforce the use of - // vk::enumerate_physical_device({.device_type = - // vk::physical_gpu::discrete}) vk::physical_enumeration enumerate_devices{ .device_type = vk::physical_gpu::discrete, }; + +#if defined(__APPLE__) + enumerate_devices.device_type = vk::physical_gpu::integrated; +#endif + vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format std::array format_support = { - // VK_FORMAT_D32_SFLOAT, - // VK_FORMAT_D32_SFLOAT_S8_UINT, - // VK_FORMAT_D24_UNORM_S8_UINT, vk::format::d32_sfloat, vk::format::d32_sfloat_s8_uint, vk::format::d24_unorm_s8_uint @@ -167,7 +144,14 @@ main() { // setting up logical device std::array priorities = { 0.f }; + +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, @@ -199,19 +183,8 @@ main() { surface_properties); // querying swapchain images - // TODO: Make the images and framebuffers contained within the vk::swapchain - // Considering if you have two display they will prob have their own set of - // images to display to the two separate screens - uint32_t image_count = 0; - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - nullptr); // used to get the amount of images - std::vector images(image_count); - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - images.data()); // used to store in the images + std::span images = main_swapchain.get_images(); + uint32_t image_count = static_cast(images.size()); // Creating Images std::vector swapchain_images(image_count); @@ -273,7 +246,7 @@ main() { .layout = vk::image_layout::color_optimal, .samples = vk::sample_bit::count_1, .load = vk::attachment_load::clear, - .store = vk::attachment_store::dont_care, + .store = vk::attachment_store::store, .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, @@ -288,7 +261,7 @@ main() { .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, - .final_layout = vk::image_layout::present_src_khr, + .final_layout = vk::image_layout::depth_stencil_read_only_optimal, }, }; diff --git a/demos/11-depth-buffering/conanfile.py b/demos/11-depth-buffering/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/11-depth-buffering/conanfile.py +++ b/demos/11-depth-buffering/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/12-loading-models/application.cpp b/demos/12-loading-models/application.cpp index 11df6c0..e83eef5 100644 --- a/demos/12-loading-models/application.cpp +++ b/demos/12-loading-models/application.cpp @@ -23,7 +23,6 @@ import vk; #define GLM_ENABLE_EXPERIMENTAL #include -// loading tinyobjloader library here #include static VKAPI_ATTR VkBool32 VKAPI_CALL @@ -36,42 +35,6 @@ debug_callback( return false; } -std::vector -initialize_instance_extensions() { - std::vector extension_names; - - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); - - extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - - // 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 - return extension_names; -} - struct global_uniform { glm::mat4 model; glm::mat4 view; @@ -98,9 +61,7 @@ namespace std { }; } -// This is how we are going to load a .obj model for this demo -// Example of how you might want to have your own classes for loading -// geometry-meshes +// Part of this demo for loading a 3D .obj model class obj_model { public: obj_model() = default; @@ -229,12 +190,27 @@ class obj_model { vk::index_buffer m_index_buffer{}; }; -VkDeviceSize -get_alignment(VkDeviceSize p_original_size, VkDeviceSize p_min_ubo_alignment) { - // Round up originalSize to the nearest multiple of min_ubo_alignment - VkDeviceSize aligned_size = - (p_original_size + p_min_ubo_alignment - 1) & ~(p_min_ubo_alignment - 1); - return aligned_size; +std::vector +get_instance_extensions() { + std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); + + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } + + extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + +#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; } int @@ -266,16 +242,11 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { - // .severity essentially takes in vk::message::verbose, - // vk::message::warning, vk::message::error .severity = vk::message::verbose | vk::message::warning | vk::message::error, - // .message_type essentially takes in vk::debug. Like: - // vk::debug::general, vk::debug::validation, vk::debug::performance .message_type = vk::debug::general | vk::debug::validation | vk::debug::performance, .callback = debug_callback @@ -290,27 +261,26 @@ main() { global_extensions // .extensions also takes in std::span }; - // 1. Setting up vk instance + // Setting up vk instance vk::instance api_instance(config, debug_callback_info); if (api_instance.alive()) { std::println("\napi_instance alive and initiated!!!"); } - // setting up physical device - // TODO: Probably enforce the use of - // vk::enumerate_physical_device({.device_type = - // vk::physical_gpu::discrete}) vk::physical_enumeration enumerate_devices{ .device_type = vk::physical_gpu::discrete, }; + + // Specifically set for the mac m1 series platform +#if defined(__APPLE__) + enumerate_devices.device_type = vk::physical_gpu::integrated; +#endif + vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format std::array format_support = { - // VK_FORMAT_D32_SFLOAT, - // VK_FORMAT_D32_SFLOAT_S8_UINT, - // VK_FORMAT_D24_UNORM_S8_UINT, vk::format::d32_sfloat, vk::format::d32_sfloat_s8_uint, vk::format::d24_unorm_s8_uint @@ -328,7 +298,14 @@ main() { // setting up logical device std::array priorities = { 0.f }; + +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, @@ -360,19 +337,8 @@ main() { surface_properties); // querying swapchain images - // TODO: Make the images and framebuffers contained within the vk::swapchain - // Considering if you have two display they will prob have their own set of - // images to display to the two separate screens - uint32_t image_count = 0; - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - nullptr); // used to get the amount of images - std::vector images(image_count); - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - images.data()); // used to store in the images + std::span images = main_swapchain.get_images(); + uint32_t image_count = static_cast(images.size()); // Creating Images std::vector swapchain_images(image_count); @@ -426,10 +392,9 @@ main() { vk::command_buffer(logical_device, settings); } - // setting up renderpass - // setting up attachments for the renderpass std::array renderpass_attachments = { + // color attachment vk::attachment{ .format = surface_properties.format.format, .layout = vk::image_layout::color_optimal, @@ -441,6 +406,7 @@ main() { .initial_layout = vk::image_layout::undefined, .final_layout = vk::image_layout::present_src_khr, }, + // depth attachment vk::attachment{ .format = depth_format, .layout = vk::image_layout::depth_stencil_optimal, @@ -462,8 +428,6 @@ main() { std::vector swapchain_framebuffers(image_count); for (uint32_t i = 0; i < swapchain_framebuffers.size(); i++) { - // image_view_attachments.push_back(swapchain_images[i].view); - // image_view_attachments.push_back(swapchain_depth_images[i].view); // NOTE: This must match the amount of attachments the renderpass also // has to match the image_view attachment for per-framebuffers as well @@ -497,7 +461,7 @@ main() { // gets set with the renderpass std::array color = { 0.f, 0.5f, 0.5f, 1.f }; - std::println("Start implementing graphics pipeline!!!"); + // std::println("Start implementing graphics pipeline!!!"); // Now creating a vulkan graphics pipeline for the shader loading std::array shader_sources = { @@ -545,16 +509,11 @@ main() { vk::shader_resource_info shader_info = { .sources = shader_sources, .vertex_attributes = - attributes // this is to explicitly set to none, but also dont need to - // set this at all regardless + attributes // NOT NEEDED: Specifying vertex attributes }; vk::shader_resource geometry_resource(logical_device, shader_info); geometry_resource.vertex_attributes(attributes); - if (geometry_resource.is_valid()) { - std::println("geometry resource is valid!"); - } - // Setting up descriptor sets for graphics pipeline std::vector entries = { vk::descriptor_entry{ @@ -577,11 +536,9 @@ main() { } }; vk::descriptor_layout set0_layout = { - .slot = 0, // indicate that this is descriptor set 0 - // set layout able to be allocated - .max_sets = image_count, // max of descriptor sets able to allocate - // this descriptor sets - .entries = entries, // specifies pool sizes and descriptor layout + .slot = 0, // indicate specific descriptor slot 0 + .max_sets = image_count, // max descriptors to allocate + .entries = entries, // descriptor layout entries description }; vk::descriptor_resource set0_resource(logical_device, set0_layout); @@ -619,7 +576,7 @@ main() { .size_bytes = sizeof(global_uniform) }; vk::uniform_buffer test_ubo = vk::uniform_buffer(logical_device, test_ubo_info); - std::println("uniform_buffer.alive() = {}", test_ubo.alive()); + // std::println("uniform_buffer.alive() = {}", test_ubo.alive()); std::array uniforms0 = { vk::write_buffer{ .buffer = test_ubo, .offset = 0, .range = test_ubo.size_bytes() } }; @@ -627,7 +584,7 @@ main() { vk::write_buffer_descriptor{ .dst_binding = 0, .uniforms = uniforms0 } }; - // Loading a texture -- for testing + // Loading a texture vk::texture_info config_texture = { .phsyical_memory_properties = physical_device.memory_properties(), .filepath = std::filesystem::path("asset_samples/viking_room.png") @@ -642,7 +599,7 @@ main() { }, }; - // Moving update call here because now we add textures to set0 + // Specify image descriptor images/samplers to the descriptor std::array sample_images = { vk::write_image_descriptor{ .dst_binding = 1, @@ -723,9 +680,6 @@ main() { presentation_queue.present_frame(current_frame); } - // TODO: Make the cleanup much saner. For now we are cleaning it up like - // Potentially bring back submit_resource_free([this](){ .. free stuff .. - // }); (???) // this to ensure they are cleaned up in the proper order logical_device.wait(); main_swapchain.destroy(); diff --git a/demos/12-loading-models/conanfile.py b/demos/12-loading-models/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/12-loading-models/conanfile.py +++ b/demos/12-loading-models/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/13-skybox/conanfile.py b/demos/13-skybox/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/13-skybox/conanfile.py +++ b/demos/13-skybox/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/2-physical-device/application.cpp b/demos/2-physical-device/application.cpp index d8d9d52..64fb99f 100644 --- a/demos/2-physical-device/application.cpp +++ b/demos/2-physical-device/application.cpp @@ -26,38 +26,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -90,8 +77,7 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { .severity = @@ -118,8 +104,9 @@ main() { } // setting up physical device - vk::physical_enumeration enumerate_devices{ .device_type = - vk::physical_gpu::discrete }; + vk::physical_enumeration enumerate_devices{ + .device_type = vk::physical_gpu::integrated + }; vk::physical_device device(api_instance, enumerate_devices); diff --git a/demos/2-physical-device/conanfile.py b/demos/2-physical-device/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/2-physical-device/conanfile.py +++ b/demos/2-physical-device/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/3-logical-device/application.cpp b/demos/3-logical-device/application.cpp index 5239f15..1631dff 100644 --- a/demos/3-logical-device/application.cpp +++ b/demos/3-logical-device/application.cpp @@ -26,38 +26,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -90,8 +77,7 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { .severity = @@ -117,21 +103,14 @@ main() { std::println("\napi_instance alive and initiated!!!"); } - // TODO: Implement this as a way to setup physical devices - // vk::enumerate_physical_devices(vk::instance) -> returns - // std::span - // setting up physical device vk::physical_enumeration enumerate_devices{ - .device_type = vk::physical_gpu::discrete, + .device_type = vk::physical_gpu::integrated, }; vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format std::array format_support = { - // VK_FORMAT_D32_SFLOAT, - // VK_FORMAT_D32_SFLOAT_S8_UINT, - // VK_FORMAT_D24_UNORM_S8_UINT, vk::format::d32_sfloat, vk::format::d32_sfloat_s8_uint, vk::format::d24_unorm_s8_uint @@ -154,7 +133,13 @@ main() { // setting up logical device std::array priorities = { 0.f }; +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, diff --git a/demos/3-logical-device/conanfile.py b/demos/3-logical-device/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/3-logical-device/conanfile.py +++ b/demos/3-logical-device/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/4-surface/application.cpp b/demos/4-surface/application.cpp index faf81b0..3188b74 100644 --- a/demos/4-surface/application.cpp +++ b/demos/4-surface/application.cpp @@ -26,38 +26,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -90,8 +77,7 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { .severity = @@ -117,21 +103,14 @@ main() { std::println("\napi_instance alive and initiated!!!"); } - // TODO: Implement this as a way to setup physical devices - // vk::enumerate_physical_devices(vk::instance) -> returns - // std::span - // setting up physical device vk::physical_enumeration enumerate_devices{ - .device_type = vk::physical_gpu::discrete, + .device_type = vk::physical_gpu::integrated, }; vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format std::array format_support = { - // VK_FORMAT_D32_SFLOAT, - // VK_FORMAT_D32_SFLOAT_S8_UINT, - // VK_FORMAT_D24_UNORM_S8_UINT, vk::format::d32_sfloat, vk::format::d32_sfloat_s8_uint, vk::format::d24_unorm_s8_uint @@ -146,7 +125,14 @@ main() { // setting up logical device std::array priorities = { 0.f }; + +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, diff --git a/demos/4-surface/conanfile.py b/demos/4-surface/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/4-surface/conanfile.py +++ b/demos/4-surface/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/5-swapchain/README.md b/demos/5-swapchain/README.md index 1be3696..3ec4b76 100644 --- a/demos/5-swapchain/README.md +++ b/demos/5-swapchain/README.md @@ -81,7 +81,7 @@ By doing the following: ```C++ -std::span images = main_swapchain.presentable_images(); +std::span images = main_swapchain.get_images(); // image_count will be referenced throughout the demos uint32_t image_count = images.size(); @@ -93,7 +93,7 @@ As soon the images have been queried, you can now create the swapchain images. ```C++ // pasted from previous section to here -std::span images = main_swapchain.presentable_images(); +std::span images = main_swapchain.get_images(); uint32_t image_count = images.size(); std::vector swapchain_images(image_count); diff --git a/demos/5-swapchain/application.cpp b/demos/5-swapchain/application.cpp index b417026..be6d9a9 100644 --- a/demos/5-swapchain/application.cpp +++ b/demos/5-swapchain/application.cpp @@ -26,38 +26,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -90,8 +77,7 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { // .severity essentially takes in vk::message::verbose, @@ -121,36 +107,31 @@ main() { std::println("\napi_instance alive and initiated!!!"); } - // TODO: Implement this as a way to setup physical devices - // vk::enumerate_physical_devices(vk::instance) -> returns - // std::span - // setting up physical device vk::physical_enumeration enumerate_devices{ - .device_type = vk::physical_gpu::discrete, + .device_type = vk::physical_gpu::integrated, }; vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format std::array format_support = { - // VK_FORMAT_D32_SFLOAT, - // VK_FORMAT_D32_SFLOAT_S8_UINT, - // VK_FORMAT_D24_UNORM_S8_UINT, vk::format::d32_sfloat, vk::format::d32_sfloat_s8_uint, vk::format::d24_unorm_s8_uint }; - // We provide a selection of format support that we want to check is - // supported on current hardware device. - // VkFormat depth_format = - // vk::select_depth_format(physical_device, format_support); - vk::queue_indices queue_indices = physical_device.family_indices(); // setting up logical device std::array priorities = { 0.f }; + +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, @@ -164,13 +145,9 @@ main() { vk::surface_params surface_properties = vk::enumerate_surface(physical_device, window_surface); - // if (surface_properties.format.format != VK_FORMAT_UNDEFINED) { - // std::println("Surface Format.format is not undefined!!!"); - // } - vk::swapchain_params enumerate_swapchain_settings = { - .width = (uint32_t)width, - .height = (uint32_t)height, + .width = static_cast(width), + .height = static_cast(height), .present_index = physical_device.family_indices() .graphics, // presentation index just uses the graphics index @@ -181,12 +158,11 @@ main() { surface_properties); // querying presentable images - std::span images = main_swapchain.presentable_images(); - uint32_t image_count = images.size(); + std::span images = main_swapchain.get_images(); + uint32_t image_count = static_cast(images.size()); // Creating Images std::vector swapchain_images(image_count); - // std::vector swapchain_depth_images(image_count); VkExtent2D swapchain_extent = surface_properties.capabilities.currentExtent; @@ -199,7 +175,7 @@ main() { .height = swapchain_extent.height }, .format = surface_properties.format.format, .aspect = vk::image_aspect_flags::color_bit, - .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + .usage = vk::image_usage::color_attachment_bit, .mip_levels = 1, .layer_count = 1, .phsyical_memory_properties = physical_device.memory_properties(), @@ -207,20 +183,6 @@ main() { swapchain_images[i] = vk::sample_image(logical_device, images[i], swapchain_image_config); - - // Creating Depth Images for depth buffering - // vk::image_params depth_image_config = { - // .extent = { .width=swapchain_extent.width, - // .height=swapchain_extent.height }, .format = depth_format, - // .aspect = vk::image_aspect_flags::depth_bit, - // .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, - // .mip_levels = 1, - // .layer_count = 1, - // .phsyical_memory_properties = - // physical_device.memory_properties(), - // }; - // swapchain_depth_images[i] = - // vk::sample_image(logical_device, depth_image_config); } // setting up command buffers @@ -243,23 +205,12 @@ main() { .layout = vk::image_layout::color_optimal, .samples = vk::sample_bit::count_1, .load = vk::attachment_load::clear, - .store = vk::attachment_store::dont_care, + .store = vk::attachment_store::store, .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, .final_layout = vk::image_layout::present_src_khr, }, - // vk::attachment{ - // .format = depth_format, - // .layout = vk::image_layout::depth_stencil_optimal, - // .samples = vk::sample_bit::count_1, - // .load = vk::attachment_load::clear, - // .store = vk::attachment_store::dont_care, - // .stencil_load = vk::attachment_load::clear, - // .stencil_store = vk::attachment_store::dont_care, - // .initial_layout = vk::image_layout::undefined, - // .final_layout = vk::image_layout::present_src_khr, - // }, }; vk::renderpass main_renderpass(logical_device, renderpass_attachments); @@ -268,7 +219,6 @@ main() { std::array image_view_attachments = { swapchain_images[i].image_view(), - // swapchain_depth_images[i].image_view() }; vk::framebuffer_params framebuffer_info = { diff --git a/demos/5-swapchain/conanfile.py b/demos/5-swapchain/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/5-swapchain/conanfile.py +++ b/demos/5-swapchain/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/6-graphics-pipeline/application.cpp b/demos/6-graphics-pipeline/application.cpp index 8fd6016..7ee21e1 100644 --- a/demos/6-graphics-pipeline/application.cpp +++ b/demos/6-graphics-pipeline/application.cpp @@ -26,38 +26,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -90,16 +77,11 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { - // .severity essentially takes in vk::message::verbose, - // vk::message::warning, vk::message::error .severity = vk::message::verbose | vk::message::warning | vk::message::error, - // .message_type essentially takes in vk::debug. Like: - // vk::debug::general, vk::debug::validation, vk::debug::performance .message_type = vk::debug::general | vk::debug::validation | vk::debug::performance, .callback = debug_callback @@ -121,21 +103,19 @@ main() { std::println("\napi_instance alive and initiated!!!"); } - // TODO: Implement this as a way to setup physical devices - // vk::enumerate_physical_devices(vk::instance) -> returns - // std::span - // setting up physical device vk::physical_enumeration enumerate_devices{ .device_type = vk::physical_gpu::discrete, }; + +#if defined(__APPLE__) + enumerate_devices.device_type = vk::physical_gpu::integrated; +#endif + vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format std::array format_support = { - // VK_FORMAT_D32_SFLOAT, - // VK_FORMAT_D32_SFLOAT_S8_UINT, - // VK_FORMAT_D24_UNORM_S8_UINT, vk::format::d32_sfloat, vk::format::d32_sfloat_s8_uint, vk::format::d24_unorm_s8_uint @@ -153,7 +133,14 @@ main() { // setting up logical device std::array priorities = { 0.f }; + +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, @@ -185,19 +172,8 @@ main() { surface_properties); // querying swapchain images - // TODO: Make the images and framebuffers contained within the vk::swapchain - // Considering if you have two display they will prob have their own set of - // images to display to the two separate screens - uint32_t image_count = 0; - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - nullptr); // used to get the amount of images - std::vector images(image_count); - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - images.data()); // used to store in the images + std::span images = main_swapchain.get_images(); + uint32_t image_count = static_cast(images.size()); // Creating Images std::vector swapchain_images(image_count); @@ -258,7 +234,7 @@ main() { .layout = vk::image_layout::color_optimal, .samples = vk::sample_bit::count_1, .load = vk::attachment_load::clear, - .store = vk::attachment_store::dont_care, + .store = vk::attachment_store::store, .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, @@ -273,7 +249,7 @@ main() { .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, - .final_layout = vk::image_layout::present_src_khr, + .final_layout = vk::image_layout::depth_stencil_read_only_optimal, }, }; @@ -339,13 +315,7 @@ main() { std::println("geometry resource is valid!"); } - /* - This get_pipeline_configuration can work as an easy way for specfying - the vulkan configurations as an ease of setting things up - // TODO: Probably provide a shorthand - which could work as this: - vk::pipeline_settings pipeline_configuration = - vk::get_pipeline_configuration(main_renderpass, geometry_resource); - */ + // Setting up descriptor sets for graphics pipeline std::array color_blend_attachments = { vk::color_blend_attachment_state{}, }; @@ -406,9 +376,6 @@ main() { presentation_queue.present_frame(current_frame); } - // TODO: Make the cleanup much saner. For now we are cleaning it up like - // Potentially bring back submit_resource_free([this](){ .. free stuff .. - // }); (???) // this to ensure they are cleaned up in the proper order logical_device.wait(); main_swapchain.destroy(); @@ -439,14 +406,4 @@ main() { glfwDestroyWindow(window); api_instance.destroy(); return 0; -} - -// template -// static size_t destroy_function(const void* p_child_object) { -// if(p_child_object != nullptr) { -// const auto* obj = static_cast(p_child_object); -// obj->~T(); -// } - -// return sizeof(T); -// } +} \ No newline at end of file diff --git a/demos/6-graphics-pipeline/conanfile.py b/demos/6-graphics-pipeline/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/6-graphics-pipeline/conanfile.py +++ b/demos/6-graphics-pipeline/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/7-vertex-buffer/application.cpp b/demos/7-vertex-buffer/application.cpp index 32f8fd9..7fccc00 100644 --- a/demos/7-vertex-buffer/application.cpp +++ b/demos/7-vertex-buffer/application.cpp @@ -26,38 +26,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -90,8 +77,7 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { // .severity essentially takes in vk::message::verbose, @@ -132,6 +118,11 @@ main() { vk::physical_enumeration enumerate_devices{ .device_type = vk::physical_gpu::discrete, }; + +#if defined(__APPLE__) + enumerate_devices.device_type = vk::physical_gpu::integrated; +#endif + vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format @@ -156,7 +147,14 @@ main() { // setting up logical device std::array priorities = { 0.f }; + +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, @@ -188,19 +186,8 @@ main() { surface_properties); // querying swapchain images - // TODO: Make the images and framebuffers contained within the vk::swapchain - // Considering if you have two display they will prob have their own set of - // images to display to the two separate screens - uint32_t image_count = 0; - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - nullptr); // used to get the amount of images - std::vector images(image_count); - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - images.data()); // used to store in the images + std::span images = main_swapchain.get_images(); + uint32_t image_count = static_cast(images.size()); // Creating Images std::vector swapchain_images(image_count); @@ -262,7 +249,7 @@ main() { .layout = vk::image_layout::color_optimal, .samples = vk::sample_bit::count_1, .load = vk::attachment_load::clear, - .store = vk::attachment_store::dont_care, + .store = vk::attachment_store::store, .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, @@ -277,7 +264,7 @@ main() { .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, - .final_layout = vk::image_layout::present_src_khr, + .final_layout = vk::image_layout::depth_stencil_read_only_optimal, }, }; diff --git a/demos/7-vertex-buffer/conanfile.py b/demos/7-vertex-buffer/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/7-vertex-buffer/conanfile.py +++ b/demos/7-vertex-buffer/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/8-index-uniform-buffers/application.cpp b/demos/8-index-uniform-buffers/application.cpp index 86fa534..a73f189 100644 --- a/demos/8-index-uniform-buffers/application.cpp +++ b/demos/8-index-uniform-buffers/application.cpp @@ -26,38 +26,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -90,8 +77,7 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { // .severity essentially takes in vk::message::verbose, @@ -132,13 +118,15 @@ main() { vk::physical_enumeration enumerate_devices{ .device_type = vk::physical_gpu::discrete, }; + +#if defined(__APPLE__) + enumerate_devices.device_type = vk::physical_gpu::integrated; +#endif + vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format std::array format_support = { - // VK_FORMAT_D32_SFLOAT, - // VK_FORMAT_D32_SFLOAT_S8_UINT, - // VK_FORMAT_D24_UNORM_S8_UINT, vk::format::d32_sfloat, vk::format::d32_sfloat_s8_uint, vk::format::d24_unorm_s8_uint @@ -156,7 +144,14 @@ main() { // setting up logical device std::array priorities = { 0.f }; + +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, @@ -187,16 +182,9 @@ main() { enumerate_swapchain_settings, surface_properties); - uint32_t image_count = 0; - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - nullptr); // used to get the amount of images - std::vector images(image_count); - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - images.data()); // used to store in the images + // querying swapchain images + std::span images = main_swapchain.get_images(); + uint32_t image_count = static_cast(images.size()); // Creating Images std::vector swapchain_images(image_count); @@ -260,7 +248,7 @@ main() { .layout = vk::image_layout::color_optimal, .samples = vk::sample_bit::count_1, .load = vk::attachment_load::clear, - .store = vk::attachment_store::dont_care, + .store = vk::attachment_store::store, .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, @@ -275,7 +263,7 @@ main() { .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, - .final_layout = vk::image_layout::present_src_khr, + .final_layout = vk::image_layout::depth_stencil_read_only_optimal, }, }; diff --git a/demos/8-index-uniform-buffers/conanfile.py b/demos/8-index-uniform-buffers/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/8-index-uniform-buffers/conanfile.py +++ b/demos/8-index-uniform-buffers/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/demos/9-uniforms/application.cpp b/demos/9-uniforms/application.cpp index 2ab3b82..cb8de36 100644 --- a/demos/9-uniforms/application.cpp +++ b/demos/9-uniforms/application.cpp @@ -31,37 +31,25 @@ debug_callback( } std::vector -initialize_instance_extensions() { +get_instance_extensions() { std::vector extension_names; + uint32_t extension_count = 0; + const char** required_extensions = + glfwGetRequiredInstanceExtensions(&extension_count); + + for (uint32_t i = 0; i < extension_count; i++) { + std::println("Required Extension = {}", required_extensions[i]); + extension_names.emplace_back(required_extensions[i]); + } - extension_names.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); extension_names.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - // 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); +#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; } @@ -100,16 +88,11 @@ main() { }; // setting up extensions - std::vector global_extensions = - initialize_instance_extensions(); + std::vector global_extensions = get_instance_extensions(); vk::debug_message_utility debug_callback_info = { - // .severity essentially takes in vk::message::verbose, - // vk::message::warning, vk::message::error .severity = vk::message::verbose | vk::message::warning | vk::message::error, - // .message_type essentially takes in vk::debug. Like: - // vk::debug::general, vk::debug::validation, vk::debug::performance .message_type = vk::debug::general | vk::debug::validation | vk::debug::performance, .callback = debug_callback @@ -131,24 +114,18 @@ main() { std::println("\napi_instance alive and initiated!!!"); } - // TODO: Implement this as a way to setup physical devices - // vk::enumerate_physical_devices(vk::instance) -> returns - // std::span - - // setting up physical device - // TODO: Probably enforce the use of - // vk::enumerate_physical_device({.device_type = - // vk::physical_gpu::discrete}) vk::physical_enumeration enumerate_devices{ .device_type = vk::physical_gpu::discrete, }; + +#if defined(__APPLE__) + enumerate_devices.device_type = vk::physical_gpu::integrated; +#endif + vk::physical_device physical_device(api_instance, enumerate_devices); // selecting depth format std::array format_support = { - // VK_FORMAT_D32_SFLOAT, - // VK_FORMAT_D32_SFLOAT_S8_UINT, - // VK_FORMAT_D24_UNORM_S8_UINT, vk::format::d32_sfloat, vk::format::d32_sfloat_s8_uint, vk::format::d24_unorm_s8_uint @@ -166,7 +143,14 @@ main() { // setting up logical device std::array priorities = { 0.f }; + +#if defined(__APPLE__) + std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, + "VK_KHR_portability_subset" }; +#else std::array extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; +#endif + vk::device_params logical_device_params = { .queue_priorities = priorities, .extensions = extensions, @@ -198,19 +182,8 @@ main() { surface_properties); // querying swapchain images - // TODO: Make the images and framebuffers contained within the vk::swapchain - // Considering if you have two display they will prob have their own set of - // images to display to the two separate screens - uint32_t image_count = 0; - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - nullptr); // used to get the amount of images - std::vector images(image_count); - vkGetSwapchainImagesKHR(logical_device, - main_swapchain, - &image_count, - images.data()); // used to store in the images + std::span images = main_swapchain.get_images(); + uint32_t image_count = static_cast(images.size()); // Creating Images std::vector swapchain_images(image_count); @@ -222,16 +195,6 @@ main() { uint32_t layer_count = 1; uint32_t mip_levels = 1; for (uint32_t i = 0; i < swapchain_images.size(); i++) { - // vk::swapchain_image_enumeration enumerate_image_properties = { - // .image = images[i], - // .format = surface_properties.format.format, - // // .aspect = VK_IMAGE_ASPECT_COLOR_BIT, - // .aspect = vk::image_aspect_flags::color_bit, - // .layer_count = 1, - // .mip_levels = mip_levels - // }; - // swapchain_images[i] = - // create_image2d_view(logical_device, enumerate_image_properties); vk::image_params swapchain_image_config = { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, @@ -247,25 +210,6 @@ main() { swapchain_images[i] = vk::sample_image(logical_device, images[i], swapchain_image_config); - // Creating Depth Images for depth buffering - // vk::image_enumeration depth_image_enumeration = { - // .width = swapchain_extent.width, - // .height = swapchain_extent.height, - // .format = depth_format, - // // .aspect = VK_IMAGE_ASPECT_DEPTH_BIT - // .aspect = vk::image_aspect_flags::depth_bit - // }; - - // // Retrieving the image resource memory requirements for specific - // memory - // // allocation Parameter is default to using - // // vk::memory_property::device_local_bit - // // TODO: think about how to minimize the requirement of - // vk::physical_device for requesting vk::image_memory_requirements - // uint32_t memory_type_index = vk::image_memory_requirements( - // physical_device, logical_device, swapchain_images[i]); - // swapchain_depth_images[i] = create_depth_image2d( - // logical_device, depth_image_enumeration, memory_type_index); vk::image_params image_config = { .extent = { .width = swapchain_extent.width, .height = swapchain_extent.height }, @@ -274,7 +218,6 @@ main() { .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, .mip_levels = 1, .layer_count = 1, - // .physical_device = physical_device .phsyical_memory_properties = physical_device.memory_properties() }; swapchain_depth_images[i] = @@ -303,7 +246,7 @@ main() { .layout = vk::image_layout::color_optimal, .samples = vk::sample_bit::count_1, .load = vk::attachment_load::clear, - .store = vk::attachment_store::dont_care, + .store = vk::attachment_store::store, .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, @@ -318,7 +261,7 @@ main() { .stencil_load = vk::attachment_load::clear, .stencil_store = vk::attachment_store::dont_care, .initial_layout = vk::image_layout::undefined, - .final_layout = vk::image_layout::present_src_khr, + .final_layout = vk::image_layout::depth_stencil_read_only_optimal, }, }; @@ -330,8 +273,6 @@ main() { std::vector swapchain_framebuffers(image_count); for (uint32_t i = 0; i < swapchain_framebuffers.size(); i++) { - // image_view_attachments.push_back(swapchain_images[i].view); - // image_view_attachments.push_back(swapchain_depth_images[i].view); // NOTE: This must match the amount of attachments the renderpass also // has to match the image_view attachment for per-framebuffers as well diff --git a/demos/9-uniforms/conanfile.py b/demos/9-uniforms/conanfile.py index 6528e4b..708fb66 100644 --- a/demos/9-uniforms/conanfile.py +++ b/demos/9-uniforms/conanfile.py @@ -22,7 +22,7 @@ def requirements(self): self.requires("glm/1.0.1") self.requires("stb/cci.20230920") self.requires("tinyobjloader/2.0.0-rc10") - self.requires("vulkan-cpp/4.0") + self.requires("vulkan-cpp/5.0") def build(self): cmake = CMake(self) diff --git a/vulkan-cpp/instance.cppm b/vulkan-cpp/instance.cppm index 94085e4..4375c90 100644 --- a/vulkan-cpp/instance.cppm +++ b/vulkan-cpp/instance.cppm @@ -64,8 +64,12 @@ export namespace vk { static_cast(p_config.extensions.size()); instance_ci.ppEnabledExtensionNames = p_config.extensions.data(); - // Only run validation layers if we are running vulkan-cpp in debug mode - #if _DEBUG + #if defined(__APPLE__) + instance_ci.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; + #endif + + // Only execute this if we are in the debug build + #if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG) // Setting up validation layers instance_ci.enabledLayerCount = static_cast(p_config.validations.size()); @@ -81,8 +85,8 @@ export namespace vk { // This is to invoke the vulkan debug utils if it is a valid callback // To ensure that we are not using an invalid debug callback if (p_debug_message_utils.callback != nullptr) { - instance_ci.pNext = - (VkDebugUtilsMessengerCreateInfoEXT*)&debug_create_info; + // instance_ci.pNext = (VkDebugUtilsMessengerCreateInfoEXT*)&debug_create_info; + instance_ci.pNext = reinterpret_cast(&debug_create_info); } else { instance_ci.pNext = nullptr; @@ -94,8 +98,9 @@ export namespace vk { #endif vk_check(vkCreateInstance(&instance_ci, nullptr, &m_instance), "vkCreateInstance"); - - #if _DEBUG + + // Set the debug utility function pointer if we are in the debug build. + #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 m_vk_set_debug_utils_object_name_ext = reinterpret_cast(vkGetInstanceProcAddr(m_instance, "vkSetDebugUtilsObjectNameEXT")); #endif diff --git a/vulkan-cpp/physical_device.cppm b/vulkan-cpp/physical_device.cppm index cc28e20..c9aeeb5 100644 --- a/vulkan-cpp/physical_device.cppm +++ b/vulkan-cpp/physical_device.cppm @@ -20,7 +20,7 @@ export namespace vk { m_physical_device = enumerate_physical_devices(p_instance, p_physical_enumeration.device_type); if (m_physical_device == nullptr) { - throw std::runtime_error("m_physical_device was nullptr!!!"); + return; } m_queue_family_properties = @@ -104,7 +104,7 @@ export namespace vk { vkEnumeratePhysicalDevices(p_instance, &device_count, nullptr); if (device_count == 0) { - throw std::runtime_error("device_count is zero!"); + return nullptr; } diff --git a/vulkan-cpp/swapchain.cppm b/vulkan-cpp/swapchain.cppm index c919944..0401ad0 100644 --- a/vulkan-cpp/swapchain.cppm +++ b/vulkan-cpp/swapchain.cppm @@ -43,8 +43,8 @@ export namespace vk { .pQueueFamilyIndices = &p_settings.present_index, .preTransform = m_surface_params.capabilities.currentTransform, .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, - .presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR, - .clipped = true + .presentMode = static_cast(p_settings.present_mode), + .clipped = p_settings.clipped, }; vk_check(vkCreateSwapchainKHR( @@ -62,12 +62,12 @@ export namespace vk { * * vk::swapchain main_swapchain(logical_device, ...); * - * std::span images = main_swapchain.enumerate_images(); + * std::span images = main_swapchain.get_images(); * * ``` * */ - std::span presentable_images() { + std::span get_images() { uint32_t image_count=0; vkGetSwapchainImagesKHR(m_device, m_swapchain_handler, &image_count, nullptr); diff --git a/vulkan-cpp/texture.cppm b/vulkan-cpp/texture.cppm index 5bf2b1c..a5f2fa5 100644 --- a/vulkan-cpp/texture.cppm +++ b/vulkan-cpp/texture.cppm @@ -134,6 +134,8 @@ export namespace vk { // for getting image memory requirements for the texture VkPhysicalDeviceMemoryProperties phsyical_memory_properties; std::filesystem::path filepath; + uint32_t mip_levels = 1; + uint32_t layer_count = 1; }; struct texture_extent { @@ -214,12 +216,10 @@ export namespace vk { .format = VK_FORMAT_R8G8B8A8_UNORM, .property = (memory_property)property_flag, .aspect = image_aspect_flags::color_bit, - // .usage = (VkImageUsageFlags)(VK_IMAGE_USAGE_TRANSFER_DST_BIT | - // VK_IMAGE_USAGE_SAMPLED_BIT), .usage = image_usage::transfer_dst_bit | image_usage::sampled_bit, - // .physical_device = p_texture_info.physical - .phsyical_memory_properties = - p_texture_info.phsyical_memory_properties + .mip_levels = p_texture_info.mip_levels, + .layer_count = p_texture_info.layer_count, + .phsyical_memory_properties = p_texture_info.phsyical_memory_properties, }; m_image = create_texture_with_data(p_device, config_image, image_pixel_data); diff --git a/vulkan-cpp/types.cppm b/vulkan-cpp/types.cppm index c48439b..12d5486 100644 --- a/vulkan-cpp/types.cppm +++ b/vulkan-cpp/types.cppm @@ -451,9 +451,9 @@ export namespace vk { }; enum class api_version : uint32_t { - vk_1_2 = VK_API_VERSION_1_2, - vk_1_3 = VK_API_VERSION_1_3, // vulkan version 1.3 - // vk_1_2, // vulkan version 1.4 + vk_1_2 = VK_MAKE_API_VERSION(0, 1, 2, 0), // vulkan version 1.2 + vk_1_3 = VK_MAKE_API_VERSION(0, 1, 3, 0), // vulkan version 1.3 + vk_1_4 = VK_MAKE_API_VERSION(0, 1, 4, 0), // vulkan version 1.4 }; struct debug_message_utility { @@ -472,14 +472,6 @@ export namespace vk { std::span extensions; }; - struct swapchain_params { - uint32_t width; - uint32_t height; - uint32_t present_index = -1; - - VkFormat depth; // depth format - }; - struct filter_range { VkFilter min; VkFilter max; @@ -661,6 +653,25 @@ export namespace vk { // VK_COMMAND_POOL_CREATE_FLAG_BITS_MAX_ENUM }; + enum present_mode : uint32_t { + immediate = VK_PRESENT_MODE_IMMEDIATE_KHR, + mailbox_khr = VK_PRESENT_MODE_MAILBOX_KHR, + fifo_khr = VK_PRESENT_MODE_FIFO_KHR, + fifo_relaxed_khr = VK_PRESENT_MODE_FIFO_RELAXED_KHR, + shared_demand_refresh_khr = VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR, + shared_continuous_refresh_khr = VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR + }; + + struct swapchain_params { + uint32_t width; + uint32_t height; + uint32_t present_index = -1; + + uint64_t depth; // depth format + uint32_t present_mode = present_mode::fifo_khr; + bool clipped = true; + }; + /** * @brief settings for specifying command buffers to construct * @@ -686,7 +697,6 @@ export namespace vk { * restricted to authorized operations */ struct command_params { - command_levels levels; uint32_t queue_index = -1; // VkCommandPoolCreateFlagBits pool_flag; @@ -745,14 +755,14 @@ export namespace vk { patch_list = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST }; - enum polygon_mode : uint64_t { + enum polygon_mode : uint32_t { fill = VK_POLYGON_MODE_FILL, line = VK_POLYGON_MODE_LINE, point = VK_POLYGON_MODE_POINT, fill_rectangle_nv = VK_POLYGON_MODE_FILL_RECTANGLE_NV, }; - enum class cull_mode : uint32_t { + enum class cull_mode : uint8_t { none = VK_CULL_MODE_NONE, front_bit = VK_CULL_MODE_FRONT_BIT, back_bit = VK_CULL_MODE_BACK_BIT, @@ -785,7 +795,7 @@ export namespace vk { one_minus_src1_alpha = VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA }; - enum class blend_op : uint64_t { + enum class blend_op : uint32_t { add = VK_BLEND_OP_ADD, subtract = VK_BLEND_OP_SUBTRACT, reverse_subtract = VK_BLEND_OP_REVERSE_SUBTRACT, @@ -840,7 +850,7 @@ export namespace vk { }; // VkColorComponentFlags - enum color_component : uint32_t { + enum color_component : uint8_t { red = VK_COLOR_COMPONENT_R_BIT, green = VK_COLOR_COMPONENT_G_BIT, blue = VK_COLOR_COMPONENT_B_BIT, @@ -1118,7 +1128,7 @@ export namespace vk { }; //! @brief Equivalent to VkPipelineBindPoint - enum class pipeline_bind_point : uint64_t { + enum class pipeline_bind_point : uint32_t { graphics = VK_PIPELINE_BIND_POINT_GRAPHICS, // VK_PIPELINE_BIND_POINT_GRAPHICS compute = diff --git a/vulkan-cpp/utilities.cppm b/vulkan-cpp/utilities.cppm index d1716df..b9005a5 100644 --- a/vulkan-cpp/utilities.cppm +++ b/vulkan-cpp/utilities.cppm @@ -28,71 +28,6 @@ export namespace vk { } } - // VkDebugUtilsMessageSeverityFlagsEXT to_debug_message_severity( - // uint32_t p_flag) { - // VkDebugUtilsMessageSeverityFlagsEXT flag; - - // if (p_flag & vk::message::verbose) { - // flag |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT; - // } - // else if (p_flag & vk::message::warning) { - // flag |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT; - // } - // else if (p_flag & vk::message::error) { - // flag |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; - // } - - // return flag; - // } - - // VkDebugUtilsMessageTypeFlagsEXT to_message_type(uint32_t p_flag) { - // VkDebugUtilsMessageTypeFlagsEXT flag; - - // if (p_flag & vk::debug::general) { - // flag |= VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT; - // } - // else if (p_flag & vk::debug::validation) { - // flag |= VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT; - // } - // else if (p_flag & vk::debug::performance) { - // flag |= VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; - // } - - // return flag; - // } - - // uint32_t vk_api_version(const api_version& p_version) { - // switch (p_version) { - // case api_version::vk_1_2: - // return VK_API_VERSION_1_2; - // case api_version::vk_1_3: - // return VK_API_VERSION_1_3; - // } - // } - - // VkPhysicalDeviceType vk_physical_device_type(physical p_physical_type) { - // switch (p_physical_type) { - // case physical::integrated: - // return VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU; - // case physical::discrete: - // return VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU; - // case physical::virtualized: - // return VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU; - // case physical::cpu: - // return VK_PHYSICAL_DEVICE_TYPE_CPU; - // case physical::max_enum: - // return VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM; - // case physical::other: - // return VK_PHYSICAL_DEVICE_TYPE_OTHER; - // } - - // throw std::runtime_error("Invalid physical device!"); - // } - - // struct physical_device_handler { - // VkPhysicalDevice handler = nullptr; - // }; - std::vector enumerate_queue_family_properties( const VkPhysicalDevice& p_physical) { uint32_t queue_family_count = 0; @@ -222,7 +157,9 @@ export namespace vk { } } - enumerate_surface_properties.format = formats[0]; + if(enumerate_surface_properties.format.format == VK_FORMAT_UNDEFINED) { + enumerate_surface_properties.format = formats[0]; + } return enumerate_surface_properties; } @@ -244,66 +181,6 @@ export namespace vk { return final_image_count; } - // VkCommandBufferUsageFlags to_command_usage_flag_bits( - // command_usage p_command_usage_flag) { - // VkCommandBufferUsageFlags command_usage_flags; - // if (command_usage_flags & command_usage::one_time_submit) { - // command_usage_flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - // } - - // if (command_usage_flags & command_usage::renderpass_continue_bit) { - // command_usage_flags |= - // VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; - // } - - // if (command_usage_flags & command_usage::simulatneous_use_bit) { - // command_usage_flags |= VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; - // } - - // if (command_usage_flags & command_usage::max_bit) { - // command_usage_flags |= VK_COMMAND_BUFFER_USAGE_FLAG_BITS_MAX_ENUM; - // } - - // return command_usage_flags; - // } - - // VkImageAspectFlags to_image_aspect_flags(image_aspect_flags p_flag) { - // switch (p_flag) { - // case image_aspect_flags::color_bit: - // return VK_IMAGE_ASPECT_COLOR_BIT; - // case image_aspect_flags::depth_bit: - // return VK_IMAGE_ASPECT_DEPTH_BIT; - // case image_aspect_flags::stencil_bit: - // return VK_IMAGE_ASPECT_STENCIL_BIT; - // case image_aspect_flags::metadata_bit: - // return VK_IMAGE_ASPECT_METADATA_BIT; - // case image_aspect_flags::plane0_bit: - // return VK_IMAGE_ASPECT_PLANE_0_BIT; - // case image_aspect_flags::plane1_bit: - // return VK_IMAGE_ASPECT_PLANE_1_BIT; - // case image_aspect_flags::plane2_bit: - // return VK_IMAGE_ASPECT_PLANE_2_BIT; - // case image_aspect_flags::none: - // return VK_IMAGE_ASPECT_NONE; - // case image_aspect_flags::memory_plane0_bit_ext: - // return VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT; - // case image_aspect_flags::memory_plane1_bit_ext: - // return VK_IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT; - // case image_aspect_flags::memory_plane2_bit_ext: - // return VK_IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT; - // case image_aspect_flags::plane1_bit_khr: - // return VK_IMAGE_ASPECT_PLANE_1_BIT_KHR; - // case image_aspect_flags::plane2_bit_khr: - // return VK_IMAGE_ASPECT_PLANE_2_BIT_KHR; - // case image_aspect_flags::none_khr: - // return VK_IMAGE_ASPECT_NONE_KHR; - // case image_aspect_flags::bits_max_enum: - // return VK_IMAGE_ASPECT_FLAG_BITS_MAX_ENUM; - // } - - // throw std::runtime_error("Invalid image aspect flags specified!!!"); - // } - VkSampler create_sampler(const VkDevice& p_device, const filter_range& p_range, VkSamplerAddressMode p_address_mode) { @@ -374,112 +251,6 @@ export namespace vk { return -1; } - // VkCommandBufferLevel to_vk_command_buffer_level( - // const command_levels& p_level) { - // switch (p_level) { - // case command_levels::primary: - // return VK_COMMAND_BUFFER_LEVEL_PRIMARY; - // case command_levels::secondary: - // return VK_COMMAND_BUFFER_LEVEL_SECONDARY; - // case command_levels::max_enum: - // return VK_COMMAND_BUFFER_LEVEL_MAX_ENUM; - // } - - // throw std::runtime_error("Invalid command buffer levels"); - // } - - // VkCommandPoolCreateFlagBits to_command_buffer_pool_flags( - // command_pool_flags p_command_pool_flag) { - // switch (p_command_pool_flag) { - // case command_pool_flags::protected_bit: - // return VK_COMMAND_POOL_CREATE_PROTECTED_BIT; - // case command_pool_flags::reset: - // return VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - // case command_pool_flags::transient: - // return VK_COMMAND_POOL_CREATE_TRANSIENT_BIT; - // case command_pool_flags::max_enum_bit: - // return VK_COMMAND_POOL_CREATE_FLAG_BITS_MAX_ENUM; - // } - - // return (VkCommandPoolCreateFlagBits)0; - // } - - // VkSubpassContents to_subpass_contents(subpass_contents p_content) { - // switch (p_content) { - // case subpass_contents::inline_bit: - // return VK_SUBPASS_CONTENTS_INLINE; - // case subpass_contents::secondary_command: - // return VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS; - // case subpass_contents::inline_and_secondary_command_khr: - // return VK_SUBPASS_CONTENTS_INLINE_AND_SECONDARY_COMMAND_BUFFERS_KHR; - // case subpass_contents::max_enum_content: - // return VK_SUBPASS_CONTENTS_MAX_ENUM; - // default: - // break; - // } - // } - - // VkPipelineBindPoint to_pipeline_bind_point( - // pipeline_bind_point p_bind_point) { - // switch (p_bind_point) { - // case pipeline_bind_point::graphics: - // return VK_PIPELINE_BIND_POINT_GRAPHICS; - // case pipeline_bind_point::compute: - // return VK_PIPELINE_BIND_POINT_COMPUTE; - // case pipeline_bind_point::ray_tracing_khr: - // return VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR; - // case pipeline_bind_point::subpass_shading_hauwei: - // return VK_PIPELINE_BIND_POINT_SUBPASS_SHADING_HUAWEI; - // // case pipeline_bind_point::ray_tracing_nv: - // // return VK_PIPELINE_BIND_POINT_RAY_TRACING_NV; - // case pipeline_bind_point::max_enum: - // return VK_PIPELINE_BIND_POINT_MAX_ENUM; - // default: - // break; - // } - // } - - - // VkSampleCountFlagBits to_sample_count_bits(sample_bit p_sample_count_bit) { - // switch (p_sample_count_bit) { - // case sample_bit::count_1: - // return VK_SAMPLE_COUNT_1_BIT; - // case sample_bit::count_2: - // return VK_SAMPLE_COUNT_2_BIT; - // case sample_bit::count_4: - // return VK_SAMPLE_COUNT_4_BIT; - // case sample_bit::count_8: - // return VK_SAMPLE_COUNT_8_BIT; - // case sample_bit::count_16: - // return VK_SAMPLE_COUNT_16_BIT; - // case sample_bit::count_32: - // return VK_SAMPLE_COUNT_32_BIT; - // case sample_bit::count_64: - // return VK_SAMPLE_COUNT_64_BIT; - // case sample_bit::max_enum: - // return VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM; - // } - // } - - // VkImageLayout to_image_layout(image_layout p_layout) { - // switch (p_layout) { - // case image_layout::undefined: - // return VK_IMAGE_LAYOUT_UNDEFINED; - // case image_layout::general: - // return VK_IMAGE_LAYOUT_GENERAL; - // case image_layout::color_optimal: - // return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - // case image_layout::depth_stencil_optimal: - // return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - // case image_layout::depth_stencil_read_only_optimal: - // return VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL; - // case image_layout::present_src_khr: - // return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; - // case image_layout::shader_read_only_optimal: - // return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - // } - // } - VkVertexInputRate to_input_rate(input_rate p_input_rate) { switch (p_input_rate) { case input_rate::vertex: @@ -502,99 +273,6 @@ export namespace vk { return false; } - // VkShaderStageFlags to_shader_stage(const shader_stage& p_stage) { - // switch (p_stage) { - // case shader_stage::vertex: - // return VK_SHADER_STAGE_VERTEX_BIT; - // case shader_stage::fragment: - // return VK_SHADER_STAGE_FRAGMENT_BIT; - // default: - // return (VkShaderStageFlagBits)0; - // } - // } - - // VkFormat to_format(const format& p_format) { - // switch (p_format) { - // case format::rg32_sfloat: - // return VK_FORMAT_R32G32_SFLOAT; - // case format::rgb32_sfloat: - // return VK_FORMAT_R32G32B32A32_SFLOAT; - // default: - // return VK_FORMAT_UNDEFINED; - // } - // } - - // VkCommandPool create_single_command_pool(const VkDevice& p_device, - // uint32_t p_queue_family_index) { - // // uint32_t graphics_queue_index = - // // physical.read_queue_family_indices().graphics; - // VkCommandPoolCreateInfo pool_ci = { - // .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, - // .pNext = nullptr, - // .flags = 0, - // .queueFamilyIndex = p_queue_family_index - // }; - - // VkCommandPool command_pool = nullptr; - // vk_check( - // vkCreateCommandPool(p_device, &pool_ci, nullptr, &command_pool), - // "vkCreateCommandPool"); - - // return command_pool; - // } - - // void copy(const VkDevice& p_device, - // const buffer_copy_info& p_info, - // size_t p_size_of_bytes) { - - // // 1. Retrieve the first queue - // // TODO: Use vk::device_queue for this - // VkQueue temp_graphics_queue = nullptr; - // uint32_t queue_family_index = 0; - // uint32_t queue_index = 0; - // vkGetDeviceQueue( - // p_device, queue_family_index, queue_index, &temp_graphics_queue); - - // // command_buffer_info - // command_params enumerate_command_info = { - // .levels = command_levels::primary, - // .queue_index = 0, - // }; - // command_buffer copy_command_buffer(p_device, enumerate_command_info); - - // copy_command_buffer.begin(command_usage::one_time_submit); - // VkBufferCopy copy_region{}; - // copy_region.size = (VkDeviceSize)p_size_of_bytes; - // vkCmdCopyBuffer( - // copy_command_buffer, p_info.src, p_info.dst, 1, ©_region); - // copy_command_buffer.end(); - // VkCommandBuffer temp = copy_command_buffer; - // VkSubmitInfo submit_info{}; - // submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - // submit_info.commandBufferCount = 1; - // submit_info.pCommandBuffers = &temp; - - // vkQueueSubmit(temp_graphics_queue, 1, &submit_info, nullptr); - // vkQueueWaitIdle(temp_graphics_queue); - - // // vkFreeCommandBuffers(, command_pool, 1, ©_cmd_buffer); - // // vkDestroyCommandPool(driver, command_pool, nullptr); - // copy_command_buffer.destroy(); - // } - - // VkDescriptorType to_descriptor_type(const buffer& p_type) { - // switch (p_type) { - // case buffer::storage: - // return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; - // case buffer::uniform: - // return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - // case buffer::combined_image_sampler: - // return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - // case buffer::sampled_only_image: - // return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; - // } - // } - int bytes_per_texture_format(VkFormat p_format) { switch (p_format) { case VK_FORMAT_R8_SINT: @@ -624,36 +302,6 @@ export namespace vk { (p_format == VK_FORMAT_D24_UNORM_S8_UINT)); } - // VkImageView create_image2d_view( - // const VkDevice& p_device, - // const VkImage& p_image, - // const image_params& p_config) { - // VkImageViewCreateInfo view_info = { - // .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, - // .pNext = nullptr, - // .flags = 0, - // .image = p_image, - // .viewType = VK_IMAGE_VIEW_TYPE_2D, - // .format = p_config.format, - // .components = { .r = VK_COMPONENT_SWIZZLE_IDENTITY, - // .g = VK_COMPONENT_SWIZZLE_IDENTITY, - // .b = VK_COMPONENT_SWIZZLE_IDENTITY, - // .a = VK_COMPONENT_SWIZZLE_IDENTITY }, - // .subresourceRange = { .aspectMask = - // to_image_aspect_flags(p_config.aspect), - // .baseMipLevel = 0, - // .levelCount = 1, - // .baseArrayLayer = 0, - // .layerCount = 1 } - // }; - - // VkImageView image_view = nullptr; - // vk_check(vkCreateImageView(p_device, &view_info, nullptr, &image_view), - // "vkCreateImageView"); - - // return image_view; - // } - uint32_t select_memory_requirements( VkPhysicalDeviceMemoryProperties p_physical_memory_props, VkMemoryRequirements p_memory_requirements,