@@ -20,6 +20,8 @@ import vk;
2020#define GLM_FORCE_RADIANS
2121#include < glm/glm.hpp>
2222#include < glm/gtc/matrix_transform.hpp>
23+ #include < algorithm>
24+ #include < cmath>
2325
2426static VKAPI_ATTR VkBool32 VKAPI_CALL
2527debug_callback (
@@ -32,38 +34,25 @@ debug_callback(
3234}
3335
3436std::vector<const char *>
35- initialize_instance_extensions () {
37+ get_instance_extensions () {
3638 std::vector<const char *> extension_names;
39+ uint32_t extension_count = 0 ;
40+ const char ** required_extensions =
41+ glfwGetRequiredInstanceExtensions (&extension_count);
3742
38- extension_names.emplace_back (VK_KHR_SURFACE_EXTENSION_NAME);
43+ for (uint32_t i = 0 ; i < extension_count; i++) {
44+ std::println (" Required Extension = {}" , required_extensions[i]);
45+ extension_names.emplace_back (required_extensions[i]);
46+ }
3947
4048 extension_names.emplace_back (VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
4149
42- // An additional surface extension needs to be loaded. This extension is
43- // platform-specific so needs to be selected based on the platform the
44- // example is going to be deployed to. Preprocessor directives are used
45- // here to select the correct platform.
46- #ifdef VK_USE_PLATFORM_WIN32_KHR
47- extension_names.emplace_back (VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
48- #endif
49- #ifdef VK_USE_PLATFORM_XLIB_KHR
50- extensionNames.emplace_back (VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
51- #endif
52- #ifdef VK_USE_PLATFORM_XCB_KHR
53- extensionNames.emplace_back (VK_KHR_XCB_SURFACE_EXTENSION_NAME);
54- #endif
55- #ifdef VK_USE_PLATFORM_ANDROID_KHR
56- extensionNames.emplace_back (VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
57- #endif
58- #ifdef VK_USE_PLATFORM_WAYLAND_KHR
59- extensionNames.emplace_back (VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
60- #endif
61- #ifdef VK_USE_PLATFORM_MACOS_MVK
62- extensionNames.emplace_back (VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
63- #endif
64- #ifdef USE_PLATFORM_NULLWS
65- extensionNames.emplace_back (VK_KHR_DISPLAY_EXTENSION_NAME);
50+ #if defined(__APPLE__)
51+ extension_names.emplace_back (VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
52+ extension_names.emplace_back (
53+ VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6654#endif
55+
6756 return extension_names;
6857}
6958
@@ -106,16 +95,11 @@ main() {
10695 };
10796
10897 // setting up extensions
109- std::vector<const char *> global_extensions =
110- initialize_instance_extensions ();
98+ std::vector<const char *> global_extensions = get_instance_extensions ();
11199
112100 vk::debug_message_utility debug_callback_info = {
113- // .severity essentially takes in vk::message::verbose,
114- // vk::message::warning, vk::message::error
115101 .severity =
116102 vk::message::verbose | vk::message::warning | vk::message::error,
117- // .message_type essentially takes in vk::debug. Like:
118- // vk::debug::general, vk::debug::validation, vk::debug::performance
119103 .message_type =
120104 vk::debug::general | vk::debug::validation | vk::debug::performance,
121105 .callback = debug_callback
@@ -137,24 +121,18 @@ main() {
137121 std::println (" \n api_instance alive and initiated!!!" );
138122 }
139123
140- // TODO: Implement this as a way to setup physical devices
141- // vk::enumerate_physical_devices(vk::instance) -> returns
142- // std::span<vk::physical_device>
143-
144- // setting up physical device
145- // TODO: Probably enforce the use of
146- // vk::enumerate_physical_device({.device_type =
147- // vk::physical_gpu::discrete})
148124 vk::physical_enumeration enumerate_devices{
149125 .device_type = vk::physical_gpu::discrete,
150126 };
127+
128+ #if defined(__APPLE__)
129+ enumerate_devices.device_type = vk::physical_gpu::integrated;
130+ #endif
131+
151132 vk::physical_device physical_device (api_instance, enumerate_devices);
152133
153134 // selecting depth format
154135 std::array<vk::format, 3 > format_support = {
155- // VK_FORMAT_D32_SFLOAT,
156- // VK_FORMAT_D32_SFLOAT_S8_UINT,
157- // VK_FORMAT_D24_UNORM_S8_UINT,
158136 vk::format::d32_sfloat,
159137 vk::format::d32_sfloat_s8_uint,
160138 vk::format::d24_unorm_s8_uint
@@ -172,7 +150,14 @@ main() {
172150
173151 // setting up logical device
174152 std::array<float , 1 > priorities = { 0 .f };
153+
154+ #if defined(__APPLE__)
155+ std::array<const char *, 2 > extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME,
156+ " VK_KHR_portability_subset" };
157+ #else
175158 std::array<const char *, 1 > extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
159+ #endif
160+
176161 vk::device_params logical_device_params = {
177162 .queue_priorities = priorities,
178163 .extensions = extensions,
@@ -204,19 +189,8 @@ main() {
204189 surface_properties);
205190
206191 // querying swapchain images
207- // TODO: Make the images and framebuffers contained within the vk::swapchain
208- // Considering if you have two display they will prob have their own set of
209- // images to display to the two separate screens
210- uint32_t image_count = 0 ;
211- vkGetSwapchainImagesKHR (logical_device,
212- main_swapchain,
213- &image_count,
214- nullptr ); // used to get the amount of images
215- std::vector<VkImage> images (image_count);
216- vkGetSwapchainImagesKHR (logical_device,
217- main_swapchain,
218- &image_count,
219- images.data ()); // used to store in the images
192+ std::span<const VkImage> images = main_swapchain.get_images ();
193+ uint32_t image_count = static_cast <uint32_t >(images.size ());
220194
221195 // Creating Images
222196 std::vector<vk::sample_image> swapchain_images (image_count);
@@ -279,7 +253,7 @@ main() {
279253 .layout = vk::image_layout::color_optimal,
280254 .samples = vk::sample_bit::count_1,
281255 .load = vk::attachment_load::clear,
282- .store = vk::attachment_store::dont_care ,
256+ .store = vk::attachment_store::store ,
283257 .stencil_load = vk::attachment_load::clear,
284258 .stencil_store = vk::attachment_store::dont_care,
285259 .initial_layout = vk::image_layout::undefined,
@@ -294,7 +268,7 @@ main() {
294268 .stencil_load = vk::attachment_load::clear,
295269 .stencil_store = vk::attachment_store::dont_care,
296270 .initial_layout = vk::image_layout::undefined,
297- .final_layout = vk::image_layout::present_src_khr ,
271+ .final_layout = vk::image_layout::depth_stencil_read_only_optimal ,
298272 },
299273 };
300274
@@ -506,7 +480,7 @@ main() {
506480 vk::texture_info config_texture = {
507481 .phsyical_memory_properties = physical_device.memory_properties (),
508482 .filepath =
509- std::filesystem::path (" asset_samples/container_diffuse.png" )
483+ std::filesystem::path (" asset_samples/container_diffuse.png" ),
510484 };
511485 vk::texture texture1 (logical_device, config_texture);
512486
0 commit comments