diff --git a/.github/workflows/linux_clang.yml b/.github/workflows/linux_clang.yml index 6bd0e30..e882a62 100644 --- a/.github/workflows/linux_clang.yml +++ b/.github/workflows/linux_clang.yml @@ -39,4 +39,4 @@ jobs: # Build the test - name: Build Test - run: cd test && clang main.c ../libmlx.so -lSDL2 + run: cd test && bash ./build.sh diff --git a/.github/workflows/linux_gcc.yml b/.github/workflows/linux_gcc.yml index 6030878..3ababd5 100644 --- a/.github/workflows/linux_gcc.yml +++ b/.github/workflows/linux_gcc.yml @@ -39,5 +39,5 @@ jobs: # Build the test - name: Build Test - run: cd test && gcc main.c ../libmlx.so -lSDL2 + run: cd test && bash ./build.sh diff --git a/.github/workflows/macos_x86.yml b/.github/workflows/macos_x86.yml index 217d31f..0d1312f 100644 --- a/.github/workflows/macos_x86.yml +++ b/.github/workflows/macos_x86.yml @@ -45,5 +45,5 @@ jobs: # Build the test - name: Build Test - run: cd test && clang main.c ../libmlx.so -lSDL2 + run: cd test && bash ./build.sh diff --git a/Makefile b/Makefile index 7c51147..7a97434 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: maldavid +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/10/04 16:43:41 by maldavid #+# #+# # -# Updated: 2023/12/10 23:15:03 by kbz_8 ### ########.fr # +# Updated: 2023/12/12 13:38:08 by kbz_8 ### ########.fr # # # # **************************************************************************** # @@ -44,7 +44,9 @@ else endif ifeq ($(OS), Darwin) - LDLIBS += -lSDL2 + LDLIBS += -L /opt/homebrew/lib -lSDL2 + CXXFLAGS += -I /opt/homebrew/include + NAME = libmlx.dylib endif ifeq ($(DEBUG), true) diff --git a/src/renderer/core/render_core.cpp b/src/renderer/core/render_core.cpp index 669e4c0..c708fd9 100644 --- a/src/renderer/core/render_core.cpp +++ b/src/renderer/core/render_core.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */ -/* Updated: 2023/12/10 23:14:18 by kbz_8 ### ########.fr */ +/* Updated: 2023/12/12 15:45:26 by kbz_8 ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,6 +49,39 @@ namespace mlx core::error::report(e_kind::fatal_error, "Vulkan : failed to find suitable memory type"); return std::nullopt; } + + const char* verbaliseResultVk(VkResult result) + { + switch(result) + { + case VK_SUCCESS: return "Success"; + case VK_NOT_READY: return "A fence or query has not yet completed"; + case VK_TIMEOUT: return "A wait operation has not completed in the specified time"; + case VK_EVENT_SET: return "An event is signaled"; + case VK_EVENT_RESET: return "An event is unsignaled"; + case VK_INCOMPLETE: return "A return array was too small for the result"; + case VK_ERROR_OUT_OF_HOST_MEMORY: return "A host memory allocation has failed"; + case VK_ERROR_OUT_OF_DEVICE_MEMORY: return "A device memory allocation has failed"; + case VK_ERROR_INITIALIZATION_FAILED: return "Initialization of an object could not be completed for implementation-specific reasons"; + case VK_ERROR_DEVICE_LOST: return "The logical or physical device has been lost"; + case VK_ERROR_MEMORY_MAP_FAILED: return "Mapping of a memory object has failed"; + case VK_ERROR_LAYER_NOT_PRESENT: return "A requested layer is not present or could not be loaded"; + case VK_ERROR_EXTENSION_NOT_PRESENT: return "A requested extension is not supported"; + case VK_ERROR_FEATURE_NOT_PRESENT: return "A requested feature is not supported"; + case VK_ERROR_INCOMPATIBLE_DRIVER: return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible"; + case VK_ERROR_TOO_MANY_OBJECTS: return "Too many objects of the type have already been created"; + case VK_ERROR_FORMAT_NOT_SUPPORTED: return "A requested format is not supported on this device"; + case VK_ERROR_SURFACE_LOST_KHR: return "A surface is no longer available"; + case VK_SUBOPTIMAL_KHR: return "A swapchain no longer matches the surface properties exactly, but can still be used"; + case VK_ERROR_OUT_OF_DATE_KHR: return "A surface has changed in such a way that it is no longer compatible with the swapchain"; + case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: return "The display used by a swapchain does not use the same presentable image layout"; + case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: return "The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API"; + case VK_ERROR_VALIDATION_FAILED_EXT: return "A validation layer found an error"; + + default: return "Unknown Vulkan error"; + } + return nullptr; + } } void Render_Core::init() diff --git a/src/renderer/core/render_core.h b/src/renderer/core/render_core.h index e3fde08..fe4efbc 100644 --- a/src/renderer/core/render_core.h +++ b/src/renderer/core/render_core.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */ -/* Updated: 2023/12/08 18:53:36 by kbz_8 ### ########.fr */ +/* Updated: 2023/12/12 15:45:39 by kbz_8 ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,7 @@ namespace mlx namespace RCore { std::optional findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties, bool error = true); + const char* verbaliseResultVk(VkResult result); } #ifdef DEBUG diff --git a/src/renderer/core/vk_device.cpp b/src/renderer/core/vk_device.cpp index 08ed842..0322030 100644 --- a/src/renderer/core/vk_device.cpp +++ b/src/renderer/core/vk_device.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:14:29 by maldavid #+# #+# */ -/* Updated: 2023/11/18 17:22:02 by maldavid ### ########.fr */ +/* Updated: 2023/12/12 15:50:02 by kbz_8 ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,8 +56,9 @@ namespace mlx createInfo.ppEnabledExtensionNames = deviceExtensions.data(); createInfo.enabledLayerCount = 0; - if(vkCreateDevice(_physicalDevice, &createInfo, nullptr, &_device) != VK_SUCCESS) - core::error::report(e_kind::fatal_error, "Vulkan : failed to create logcal device"); + VkResult res; + if((res = vkCreateDevice(_physicalDevice, &createInfo, nullptr, &_device)) != VK_SUCCESS) + core::error::report(e_kind::fatal_error, "Vulkan : failed to create logcal device, %s", RCore::verbaliseResultVk(res)); #ifdef DEBUG core::error::report(e_kind::message, "Vulkan : created new logical device"); #endif diff --git a/src/renderer/core/vk_fence.cpp b/src/renderer/core/vk_fence.cpp index 3c54d49..8061a6c 100644 --- a/src/renderer/core/vk_fence.cpp +++ b/src/renderer/core/vk_fence.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/02 17:53:06 by maldavid #+# #+# */ -/* Updated: 2023/12/10 22:45:21 by kbz_8 ### ########.fr */ +/* Updated: 2023/12/12 15:50:48 by kbz_8 ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,8 +20,9 @@ namespace mlx fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; - if(vkCreateFence(Render_Core::get().getDevice().get(), &fenceInfo, nullptr, &_fence) != VK_SUCCESS) - core::error::report(e_kind::fatal_error, "Vulkan : failed to create CPU synchronization object"); + VkResult res; + if((res = vkCreateFence(Render_Core::get().getDevice().get(), &fenceInfo, nullptr, &_fence)) != VK_SUCCESS) + core::error::report(e_kind::fatal_error, "Vulkan : failed to create CPU synchronization object, %s", RCore::verbaliseResultVk(res)); #ifdef DEBUG core::error::report(e_kind::message, "Vulkan : created new fence"); #endif diff --git a/src/renderer/core/vk_instance.cpp b/src/renderer/core/vk_instance.cpp index 226505c..9ee7914 100644 --- a/src/renderer/core/vk_instance.cpp +++ b/src/renderer/core/vk_instance.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:04:21 by maldavid #+# #+# */ -/* Updated: 2023/11/18 17:21:42 by maldavid ### ########.fr */ +/* Updated: 2023/12/12 15:46:06 by kbz_8 ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,7 +54,7 @@ namespace mlx VkResult res; if((res = vkCreateInstance(&createInfo, nullptr, &_instance)) != VK_SUCCESS) - core::error::report(e_kind::fatal_error, "Vulkan : failed to create Vulkan instance"); + core::error::report(e_kind::fatal_error, "Vulkan : failed to create Vulkan instance, %s", RCore::verbaliseResultVk(res)); volkLoadInstance(_instance); #ifdef DEBUG core::error::report(e_kind::message, "Vulkan : created new instance"); diff --git a/src/renderer/core/vk_semaphore.cpp b/src/renderer/core/vk_semaphore.cpp index 00f2b07..59234eb 100644 --- a/src/renderer/core/vk_semaphore.cpp +++ b/src/renderer/core/vk_semaphore.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:01:08 by maldavid #+# #+# */ -/* Updated: 2023/11/18 17:22:29 by maldavid ### ########.fr */ +/* Updated: 2023/12/12 15:51:37 by kbz_8 ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,9 +21,10 @@ namespace mlx VkSemaphoreCreateInfo semaphoreInfo{}; semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; - if( vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_imageAvailableSemaphores) != VK_SUCCESS || - vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_renderFinishedSemaphores) != VK_SUCCESS) - core::error::report(e_kind::fatal_error, "Vulkan : failed to create GPU synchronization object"); + VkResult res; + if( (res = vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_imageAvailableSemaphores)) != VK_SUCCESS || + (res = vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_renderFinishedSemaphores)) != VK_SUCCESS) + core::error::report(e_kind::fatal_error, "Vulkan : failed to create GPU synchronization object, %s", RCore::verbaliseResultVk(res)); #ifdef DEBUG core::error::report(e_kind::message, "Vulkan : created new semaphore"); #endif diff --git a/test/build.sh b/test/build.sh new file mode 100755 index 0000000..28c509c --- /dev/null +++ b/test/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ $(uname -s) = 'Darwin' ]; then + clang main.c ../libmlx.dylib -L /opt/homebrew/lib -lSDL2 -g; +else + clang main.c ../libmlx.so -lSDL2 -g; +fi + diff --git a/test/run.sh b/test/run.sh index f3c908d..993cb20 100755 --- a/test/run.sh +++ b/test/run.sh @@ -1 +1,4 @@ -clang main.c ../libmlx.so -lSDL2 -g && ./a.out +#!/bin/bash + +bash ./build.sh +./a.out