Skip to content

Commit

Permalink
Merge pull request #12 from 420verfl0w/macos-debug
Browse files Browse the repository at this point in the history
Macos debug
  • Loading branch information
Kbz-8 authored Dec 12, 2023
2 parents c2c2dec + c5752f7 commit cfd1aab
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/linux_gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion .github/workflows/macos_x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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 #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -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)
Expand Down
35 changes: 34 additions & 1 deletion src/renderer/core/render_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/core/render_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -31,6 +31,7 @@ namespace mlx
namespace RCore
{
std::optional<uint32_t> findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties, bool error = true);
const char* verbaliseResultVk(VkResult result);
}

#ifdef DEBUG
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/core/vk_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/core/vk_fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/core/vk_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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");
Expand Down
9 changes: 5 additions & 4 deletions src/renderer/core/vk_semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/build.sh
Original file line number Diff line number Diff line change
@@ -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

5 changes: 4 additions & 1 deletion test/run.sh
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
clang main.c ../libmlx.so -lSDL2 -g && ./a.out
#!/bin/bash

bash ./build.sh
./a.out

0 comments on commit cfd1aab

Please sign in to comment.