Kajetan Johannes Hammerle 20 godzin temu
rodzic
commit
d3d2211c53

+ 3 - 0
.clangd

@@ -1,3 +1,6 @@
 CompileFlags:
   Add: [-ferror-limit=0]
   CompilationDatabase: ./build_debug/
+Diagnostics:
+  Suppress:
+    - module_decl_not_at_start

+ 18 - 11
CMakeLists.txt

@@ -70,20 +70,27 @@ add_modules(
     PREFIX ${CMAKE_INSTALL_PREFIX}/
     FILES ${core_modules}
 )
-target_link_directories(gamingcore
-    PUBLIC ${CMAKE_INSTALL_PREFIX}/lib
+add_modules(
+    TARGET gamingcore
+    NAME gamingcore_modules
+    FILES
+       modules/Image.cppm
+       modules/Network.cppm
+       modules/Vulkan.cppm
+       modules/VulkanBase.cppm
+       modules/VulkanWrapper.cppm
+       modules/VulkanUtility.cppm
+       modules/WindowManager.cppm
 )
-target_sources(gamingcore PUBLIC
-    FILE_SET HEADERS
-    BASE_DIRS include
+add_modules(
+    TARGET gamingcore
+    NAME gamingcore_private_modules
     FILES
-        ./include/core/Image.hpp
-        ./include/core/Network.hpp
-        ./include/core/VulkanBase.hpp
-        ./include/core/VulkanWrapper.hpp
-        ./include/core/WindowManager.hpp
+        src/GLFW.cppm
+)
+target_link_directories(gamingcore
+    PUBLIC ${CMAKE_INSTALL_PREFIX}/lib
 )
-install(TARGETS gamingcore FILE_SET HEADERS)
 
 include("cmake/add_shader.cmake")
 

+ 0 - 28
include/core/VulkanUtility.hpp

@@ -1,28 +0,0 @@
-#ifndef GAMINGCORE_VULKAN_UTILITY_HPP
-#define GAMINGCORE_VULKAN_UTILITY_HPP
-
-#include <vulkan/vulkan.h>
-
-import Core.Logger;
-
-namespace Core::Vulkan {
-    const char* getResultString(VkResult r);
-}
-
-#define VK_REPORT(level, format, ...)                                         \
-    Core::report(                                                             \
-        Core::LogLevel::level, "Vulkan | " format __VA_OPT__(, ) __VA_ARGS__)
-#define VK_REPORT_ERROR(...) VK_REPORT(ERROR, __VA_ARGS__)
-#define VK_REPORT_WARNING(...) VK_REPORT(WARNING, __VA_ARGS__)
-#define VK_CHECK(r, a)                                                     \
-    do {                                                                   \
-        VkResult vkResult = (a);                                           \
-        if(vkResult != VK_SUCCESS) {                                       \
-            VK_REPORT_ERROR("#", Core::Vulkan::getResultString(vkResult)); \
-            return r;                                                      \
-        }                                                                  \
-    } while(false)
-#define VK_CHECK_TRUE(a) VK_CHECK(true, a)
-#define VK_CHECK_VOID(a) VK_CHECK(, a)
-
-#endif

+ 4 - 7
include/core/Image.hpp → modules/Image.cppm

@@ -1,10 +1,9 @@
-#ifndef GAMINGCORE_IMAGE_HPP
-#define GAMINGCORE_IMAGE_HPP
+export module Core.Image;
 
-import Core.List;
-import Core.Types;
+export import Core.List;
+export import Core.Types;
 
-namespace Core {
+export namespace Core {
     struct Image8 {
         List<u8> data{};
         int width = 0;
@@ -23,5 +22,3 @@ namespace Core {
         bool read(const char* path);
     };
 }
-
-#endif

+ 5 - 8
include/core/Network.hpp → modules/Network.cppm

@@ -1,11 +1,11 @@
-#ifndef GAMINGCORE_NETWORK_HPP
-#define GAMINGCORE_NETWORK_HPP
+export module Core.Network;
+
+export import Core.Buffer;
+export import Core.Types;
 
-import Core.Buffer;
-import Core.Types;
 import Core.UniquePointer;
 
-namespace Core {
+export namespace Core {
     enum class PacketSendMode { RELIABLE, SEQUENCED, UNSEQUENCED };
 
     class InPacket {
@@ -101,7 +101,4 @@ namespace Core {
     private:
         UniquePointer<Data> data;
     };
-
 }
-
-#endif

+ 189 - 0
modules/Vulkan.cppm

@@ -0,0 +1,189 @@
+module;
+
+#define GLFW_INCLUDE_VULKAN
+#include <GLFW/glfw3.h>
+
+export module Core.Vulkan;
+
+export import Core.Types;
+
+// NOLINTBEGIN(misc-unused-using-decls)
+
+export using ::glfwCreateWindowSurface;
+export using ::glfwGetRequiredInstanceExtensions;
+export using ::GLFWwindow;
+export using ::PFN_vkVoidFunction;
+export using ::VkBuffer;
+export using ::VkCommandBuffer;
+export using ::VkCommandPool;
+export using ::VkDebugReportCallbackEXT;
+export using ::VkDebugUtilsMessengerEXT;
+export using ::VkDevice;
+export using ::VkDeviceMemory;
+export using ::VkExtent2D;
+export using ::VkFence;
+export using ::VkFormat;
+export using ::VkFramebuffer;
+export using ::VkImage;
+export using ::VkImageView;
+export using ::VkInstance;
+export using ::VkMemoryPropertyFlags;
+export using ::VkPhysicalDevice;
+export using ::VkPhysicalDeviceProperties;
+export using ::VkPipeline;
+export using ::VkPipelineLayout;
+export using ::VkPipelineStageFlags;
+export using ::VkPresentModeKHR;
+export using ::VkQueue;
+export using ::VkQueueFlags;
+export using ::VkRect2D;
+export using ::VkRenderPass;
+export using ::VkResult;
+export using ::VkSemaphore;
+export using ::VkShaderModule;
+export using ::VkSharingMode;
+export using ::VkSurfaceCapabilitiesKHR;
+export using ::VkSurfaceFormatKHR;
+export using ::VkSurfaceKHR;
+export using ::VkSwapchainKHR;
+export using ::VkVertexInputAttributeDescription;
+export using ::VkVertexInputBindingDescription;
+export using ::VkViewport;
+export using ::glfwGetFramebufferSize;
+export using ::vkEnumeratePhysicalDevices;
+export using ::VkFramebufferCreateInfo;
+export using ::vkCreateImageView;
+export using ::VkImageViewCreateInfo;
+export using ::VkStructureType;
+export using ::VkSemaphoreCreateInfo;
+export using ::VkFenceCreateFlagBits;
+export using ::vkCreateFence;
+export using ::VkFenceCreateInfo;
+export using ::vkCreateSemaphore;
+export using ::vkCreateFramebuffer;
+export using ::vkDestroyRenderPass;
+export using ::vkResetFences;
+export using ::vkWaitForFences;
+export using ::VkSwapchainCreateInfoKHR;
+export using ::VkImageUsageFlagBits;
+export using ::VkCompositeAlphaFlagBitsKHR;
+export using ::vkCreateSwapchainKHR;
+export using ::vkAcquireNextImageKHR;
+export using ::VkImageAspectFlagBits;
+export using ::VkImageViewType;
+export using ::vkDestroyCommandPool;
+export using ::vkDestroyPipeline;
+export using ::VkPipelineLayoutCreateInfo;
+export using ::vkCreatePipelineLayout;
+export using ::vkCreateShaderModule;
+export using ::vkDestroyImageView;
+export using ::vkDestroyFramebuffer;
+export using ::vkDestroySemaphore;
+export using ::vkDestroyFence;
+export using ::vkDestroySwapchainKHR;
+export using ::vkDestroyShaderModule;
+export using ::vkDestroyPipelineLayout;
+export using ::VkShaderModuleCreateInfo;
+export using ::VkAttachmentDescription;
+export using ::vkGetSwapchainImagesKHR;
+export using ::VkAccessFlagBits;
+export using ::VkRenderPassCreateInfo;
+export using ::vkCreateRenderPass;
+export using ::VkShaderStageFlagBits;
+export using ::VkPipelineVertexInputStateCreateInfo;
+export using ::VkPipelineInputAssemblyStateCreateInfo;
+export using ::VkPipelineViewportStateCreateInfo;
+export using ::VkPrimitiveTopology;
+export using ::VkPipelineShaderStageCreateInfo;
+export using ::VkPipelineRasterizationStateCreateInfo;
+export using ::VkPolygonMode;
+export using ::VkCullModeFlagBits;
+export using ::VkFrontFace;
+export using ::VkSampleCountFlagBits;
+export using ::VkBlendFactor;
+export using ::VkBlendOp;
+export using ::VkColorComponentFlagBits;
+export using ::VkPipelineColorBlendAttachmentState;
+export using ::VkPipelineColorBlendStateCreateInfo;
+export using ::VkLogicOp;
+export using ::VkDynamicState;
+export using ::VkSampleCountFlagBits;
+export using ::VkGraphicsPipelineCreateInfo;
+export using ::VkPipelineDynamicStateCreateInfo;
+export using ::VkPipelineMultisampleStateCreateInfo;
+export using ::VkCommandPoolCreateFlagBits;
+export using ::VkAttachmentLoadOp;
+export using ::VkAttachmentStoreOp;
+export using ::VkImageLayout;
+export using ::VkAttachmentReference;
+export using ::VkSubpassDescription;
+export using ::VkSubpassDependency;
+export using ::VkPipelineBindPoint;
+export using ::vkEndCommandBuffer;
+export using ::vkBeginCommandBuffer;
+export using ::VkCommandBufferBeginInfo;
+export using ::VkRenderPassBeginInfo;
+export using ::VkClearValue;
+export using ::vkCmdEndRenderPass;
+export using ::vkCmdSetViewport;
+export using ::vkCmdBindPipeline;
+export using ::vkCmdSetScissor;
+export using ::vkCmdDraw;
+export using ::vkGetDeviceQueue;
+export using ::VkSubmitInfo;
+export using ::VkSubpassContents;
+export using ::vkCmdBeginRenderPass;
+export using ::vkQueueSubmit;
+export using ::VkPipelineStageFlagBits;
+export using ::VkImageUsageFlagBits;
+export using ::vkCreateGraphicsPipelines;
+export using ::VkCommandPoolCreateInfo;
+export using ::vkCreateCommandPool;
+export using ::VkMemoryRequirements;
+export using ::VkBufferUsageFlagBits;
+export using ::VkBufferCreateInfo;
+export using ::vkDestroyBuffer;
+export using ::VkMemoryPropertyFlagBits;
+export using ::vkAllocateMemory;
+export using ::VkMemoryAllocateInfo;
+export using ::vkBindBufferMemory;
+export using ::vkMapMemory;
+export using ::vkGetBufferMemoryRequirements;
+export using ::vkCreateBuffer;
+export using ::vkFreeMemory;
+export using ::VkPresentInfoKHR;
+export using ::vkQueuePresentKHR;
+export using ::VkVertexInputRate;
+export using ::VkCommandBufferAllocateInfo;
+export using ::VkCommandBufferLevel;
+export using ::VkQueueFlagBits;
+export using ::VkPhysicalDeviceType;
+export using ::VkColorSpaceKHR;
+export using ::vkAllocateCommandBuffers;
+export using ::vkResetCommandBuffer;
+export using ::vkUnmapMemory;
+export using ::VkDeviceSize;
+export using ::vkCmdBindVertexBuffers;
+export using ::VkMemoryPropertyFlagBits;
+export using ::VkMemoryPropertyFlagBits;
+export using ::VkMemoryPropertyFlagBits;
+export using ::VkMemoryPropertyFlagBits;
+export using ::VkMemoryPropertyFlagBits;
+export using ::VkMemoryPropertyFlagBits;
+
+static_assert(VK_NULL_HANDLE == nullptr);
+#undef VK_NULL_HANDLE
+export inline auto VK_NULL_HANDLE = nullptr;
+
+static_assert(VK_TRUE == true);
+#undef VK_TRUE
+export inline bool VK_TRUE = true;
+
+static_assert(VK_SUBPASS_EXTERNAL == ~0u);
+#undef VK_SUBPASS_EXTERNAL
+export inline u32 VK_SUBPASS_EXTERNAL = ~0u;
+
+#undef VK_KHR_SWAPCHAIN_EXTENSION_NAME
+export inline const char* VK_KHR_SWAPCHAIN_EXTENSION_NAME = "VK_KHR_swapchain";
+
+// NOLINTEND(misc-unused-using-decls)

+ 13 - 16
include/core/VulkanBase.hpp → modules/VulkanBase.cppm

@@ -1,19 +1,17 @@
-#ifndef GAMINGCORE_VULKAN_BASE_HPP
-#define GAMINGCORE_VULKAN_BASE_HPP
+export module Core.VulkanBase;
+
+export import Core.Types;
+export import Core.List;
+export import Core.Types;
+export import Core.Vulkan;
 
 import Core.Array;
-import Core.List;
-import Core.Types;
 import Core.Utility;
+import Core.VulkanUtility;
 
-#define GLFW_INCLUDE_VULKAN
-#include <GLFW/glfw3.h>
-
-#include "core/VulkanUtility.hpp"
-
-namespace Core::Vulkan {
-    [[maybe_unused]] constexpr u32 INVALID_QUEUE_FAMILY = 0xFFFF'FFFF;
-    [[maybe_unused]] constexpr u32 INVALID_MEMORY_TYPE = 0xFFFF'FFFF;
+export namespace Core::Vulkan {
+    inline constexpr u32 INVALID_QUEUE_FAMILY = 0xFFFF'FFFF;
+    inline constexpr u32 INVALID_MEMORY_TYPE = 0xFFFF'FFFF;
 
     struct DeviceQueueData {
         u32 queueFamilyIndex = 0;
@@ -50,8 +48,9 @@ namespace Core::Vulkan {
         bool findPhysicalDevice(T& data, PhysicalDeviceSelector<T> s) {
             Core::Array<VkPhysicalDevice, 32> devices;
             u32 c = devices.getLength();
-            VK_CHECK_TRUE(
-                vkEnumeratePhysicalDevices(instance, &c, &devices[0]));
+            if(check(vkEnumeratePhysicalDevices(instance, &c, &devices[0]))) {
+                return true;
+            }
             int bestPoints = 0;
             VkPhysicalDevice best = VK_NULL_HANDLE;
             for(u32 i = 0; i < c; i++) {
@@ -109,5 +108,3 @@ namespace Core::Vulkan {
         bool initSurface();
     };
 }
-
-#endif

+ 8 - 0
modules/VulkanUtility.cppm

@@ -0,0 +1,8 @@
+export module Core.VulkanUtility;
+
+export import Core.Vulkan;
+
+export namespace Core::Vulkan {
+    const char* getResultString(VkResult r);
+    bool check(VkResult r);
+}

+ 8 - 12
include/core/VulkanWrapper.hpp → modules/VulkanWrapper.cppm

@@ -1,15 +1,13 @@
-#ifndef GAMINGCORE_VULKAN_WRAPPER_HPP
-#define GAMINGCORE_VULKAN_WRAPPER_HPP
+export module Core.VulkanWrapper;
 
-#include <vulkan/vulkan.h>
+export import Core.Vulkan;
+export import Core.List;
+export import Core.Types;
+export import Core.VulkanBase;
 
-#include "core/VulkanBase.hpp"
-
-import Core.List;
 import Core.Meta;
-import Core.Types;
 
-namespace Core::Vulkan {
+export namespace Core::Vulkan {
     bool init();
     void render();
     void destroy();
@@ -81,7 +79,7 @@ namespace Core::Vulkan {
         ~Fence();
         bool init(VkDevice d);
         void reset();
-        void waitFor(u64 timeout = UINT64_MAX);
+        void waitFor(u64 timeout = 0xFFFF'FFFF'FFFF'FFFF);
     };
 
     enum class SwapchainResult { SUCCESS, RECREATE, ERROR_RECREATE, ERROR };
@@ -102,7 +100,7 @@ namespace Core::Vulkan {
 
         bool init(Data& d);
         SwapchainResult nextImage(
-            u32& imageIndex, Semaphore& s, u64 timeout = UINT64_MAX);
+            u32& imageIndex, Semaphore& s, u64 timeout = 0xFFFF'FFFF'FFFF'FFFF);
     };
 
     struct ShaderModule : public BaseWrapper<VkShaderModule> {
@@ -190,5 +188,3 @@ namespace Core::Vulkan {
         bool init(Base& base, size_t size, const void* data);
     };
 }
-
-#endif

+ 7 - 7
include/core/WindowManager.hpp → modules/WindowManager.cppm

@@ -1,10 +1,10 @@
-#ifndef GAMINGCORE_WINDOW_MANAGER_HPP
-#define GAMINGCORE_WINDOW_MANAGER_HPP
+export module Core.WindowManager;
 
-import Core.Types;
-import Core.Vector;
+export import Core.Types;
+export import Core.Vector;
+export import Core.Vulkan;
 
-namespace Core::Window {
+export namespace Core::Window {
     using RunHandler = bool (*)(void* data);
     using TickHandler = void (*)(void* data);
     using RenderHandler = void (*)(void* data, float lag);
@@ -61,6 +61,6 @@ namespace Core::Window {
     int getButtonDownTime(Button b);
     bool wasButtonReleased(Button b);
     const char* getButtonName(Button b);
-}
 
-#endif
+    GLFWwindow* get();
+}

+ 3 - 0
src/GLFW.cppm

@@ -0,0 +1,3 @@
+module;
+
+export module Core.WindowManager:Id;

+ 0 - 11
src/GLFW.hpp

@@ -1,11 +0,0 @@
-#ifndef GAMINGCORE_GLFW_HPP
-#define GAMINGCORE_GLFW_HPP
-
-#define GLFW_INCLUDE_VULKAN
-#include <GLFW/glfw3.h>
-
-namespace Core::Window {
-    GLFWwindow* get();
-}
-
-#endif

+ 8 - 5
src/Image.cpp

@@ -1,11 +1,9 @@
-#include "core/Image.hpp"
+module;
 
-#include <cerrno>
-#include <cstring>
-
-import Core.Logger;
 import Core.Utility;
 
+#include <cerrno>
+
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpragmas"
 #pragma GCC diagnostic ignored "-Wunknown-warning-option"
@@ -19,6 +17,11 @@ import Core.Utility;
 #include <stb_image.h>
 #pragma GCC diagnostic pop
 
+module Core.Image;
+
+import Core.Logger;
+import Core.Utility;
+
 static void reportError(const char* path) {
     Core::report(
         Core::LogLevel::ERROR, "Cannot read image '{}': {}", path,

+ 8 - 6
src/Network.cpp

@@ -1,19 +1,21 @@
-#include "core/Network.hpp"
+module;
 
 #define ENET_IMPLEMENTATION
-#include <cassert>
-#include <cstring>
-
 #include <enet.h>
 
 #include "ErrorSimulator.hpp"
 
+module Core.Network;
+
 import Core.HashMap;
 import Core.Logger;
 import Core.Utility;
 import Core.Types;
 import Core.Math;
 import Core.Buffer;
+import Core.Assert;
+
+#undef assert
 
 using Core::Client;
 using Core::InPacket;
@@ -432,7 +434,7 @@ static void writeId(ENetPeer* peer, Core::ClientHandle id) {
 }
 
 static Core::ClientHandle getId(ENetPeer* peer) {
-    assert(peer->data != nullptr);
+    Core::assert(peer->data != nullptr);
     Core::ClientHandle id = -1;
     memcpy(&id, &(peer->data), sizeof(id));
     return id;
@@ -440,7 +442,7 @@ static Core::ClientHandle getId(ENetPeer* peer) {
 
 static void handleConnect(Server& s, Server::Data& d, ENetEvent* e) {
     Core::ClientHandle id = d.idCounter++;
-    assert(!d.clients.contains(id));
+    Core::assert(!d.clients.contains(id));
     d.clients.add(id, e->peer);
     writeId(e->peer, id);
     d.onConnect(s, id);

+ 43 - 31
src/VulkanBase.cpp

@@ -1,13 +1,15 @@
-#include "core/VulkanBase.hpp"
+module;
 
-#include <cstring>
+#include <vulkan/vulkan.h>
 
-#include "GLFW.hpp"
+module Core.VulkanBase;
 
 import Core.List;
 import Core.Logger;
 import Core.Types;
 import Core.Array;
+import Core.WindowManager;
+import Core.Std;
 
 using Core::Vulkan::Base;
 
@@ -30,7 +32,8 @@ bool Base::initInstance() {
     u32 baseCount = 0;
     const char** baseExtensions = glfwGetRequiredInstanceExtensions(&baseCount);
     if(baseExtensions == nullptr) {
-        VK_REPORT_ERROR("Could not get required extensions from GLFW");
+        Core::report(
+            LogLevel::ERROR, "Could not get required extensions from GLFW");
         return true;
     }
     Core::List<const char*> extensions;
@@ -57,15 +60,16 @@ bool Base::initInstance() {
         .ppEnabledLayerNames = &layers[0],
         .enabledExtensionCount = static_cast<u32>(extensions.getLength()),
         .ppEnabledExtensionNames = &extensions[0]};
-    VK_CHECK_TRUE(vkCreateInstance(&info, nullptr, &instance));
-    return false;
+    return check(vkCreateInstance(&info, nullptr, &instance));
 }
 
 #ifdef DEBUG_VULKAN
 static VKAPI_ATTR VkBool32 onVulkanDebugMessenger VKAPI_CALL(
     VkDebugUtilsMessageSeverityFlagBitsEXT, VkDebugUtilsMessageTypeFlagsEXT,
     const VkDebugUtilsMessengerCallbackDataEXT* data, void*) {
-    VK_REPORT_WARNING("Vulkan validation layer message: {}", data->pMessage);
+    Core::report(
+        Core::LogLevel::WARNING, "Vulkan validation layer message: {}",
+        data->pMessage);
     return false;
 }
 
@@ -80,17 +84,19 @@ bool Base::initDebugMessenger() {
         .pfnUserCallback = onVulkanDebugMessenger};
     auto f = GET_FUNCTION(vkCreateDebugUtilsMessengerEXT);
     if(f == nullptr) {
-        VK_REPORT_WARNING("Could not find debug util messenger function");
+        report(
+            LogLevel::WARNING, "Could not find debug util messenger function");
         return false;
     }
-    VK_CHECK_TRUE(f(instance, &info, nullptr, &debugMessenger));
-    return false;
+    return check(f(instance, &info, nullptr, &debugMessenger));
 }
 
 static VKAPI_ATTR VkBool32 onVulkanDebugReport VKAPI_CALL(
     VkDebugReportFlagsEXT, VkDebugReportObjectTypeEXT, uint64_t, size_t,
     int32_t, const char* pLayerPrefix, const char* pMessage, void*) {
-    VK_REPORT_WARNING("Vulkan debug message '{}': {}", pLayerPrefix, pMessage);
+    Core::report(
+        Core::LogLevel::WARNING, "Vulkan debug message '{}': {}", pLayerPrefix,
+        pMessage);
     return false;
 }
 
@@ -103,11 +109,10 @@ bool Base::initDebugReportCallback() {
         .pfnCallback = onVulkanDebugReport};
     auto f = GET_FUNCTION(vkCreateDebugReportCallbackEXT);
     if(f == nullptr) {
-        VK_REPORT_WARNING("Could not find debug report function");
+        report(LogLevel::WARNING, "Could not find debug report function");
         return false;
     }
-    VK_CHECK_TRUE(f(instance, &info, nullptr, &debugReportCallback));
-    return false;
+    return check(f(instance, &info, nullptr, &debugReportCallback));
 }
 
 void Base::destroyDebugMessenger() {
@@ -116,7 +121,8 @@ void Base::destroyDebugMessenger() {
     }
     auto f = GET_FUNCTION(vkDestroyDebugUtilsMessengerEXT);
     if(f == nullptr) {
-        VK_REPORT_WARNING(
+        report(
+            LogLevel::WARNING,
             "Could not find debug util messenger destroy function");
         return;
     }
@@ -130,7 +136,8 @@ void Base::destroyDebugReportCallback() {
     }
     auto f = GET_FUNCTION(vkDestroyDebugReportCallbackEXT);
     if(f == nullptr) {
-        VK_REPORT_WARNING("Could not find debug report destroy function");
+        report(
+            LogLevel::WARNING, "Could not find debug report destroy function");
         return;
     }
     f(instance, debugReportCallback, nullptr);
@@ -141,11 +148,10 @@ void Base::destroyDebugReportCallback() {
 bool Base::initSurface() {
     GLFWwindow* w = Window::get();
     if(w == nullptr) {
-        VK_REPORT_ERROR("Init a window before Vulkan");
+        report(LogLevel::ERROR, "Init a window before Vulkan");
         return true;
     }
-    VK_CHECK_TRUE(glfwCreateWindowSurface(instance, w, nullptr, &surface));
-    return false;
+    return check(glfwCreateWindowSurface(instance, w, nullptr, &surface));
 }
 
 bool Base::init() {
@@ -198,7 +204,10 @@ u32 Base::findQueueFamily(VkQueueFlags flags) {
 static bool hasPresentationSupport(
     VkPhysicalDevice pd, VkSurfaceKHR s, u32 index) {
     VkBool32 b = false;
-    VK_CHECK(false, vkGetPhysicalDeviceSurfaceSupportKHR(pd, index, s, &b));
+    if(Core::Vulkan::check(
+           vkGetPhysicalDeviceSurfaceSupportKHR(pd, index, s, &b))) {
+        return false;
+    }
     return b;
 }
 
@@ -216,9 +225,10 @@ u32 Base::findSurfaceQueueFamily() {
 bool Base::hasExtension(const char* extension) {
     Core::Array<VkExtensionProperties, 1024> e;
     u32 c = e.getLength();
-    VK_CHECK(
-        false, vkEnumerateDeviceExtensionProperties(
-                   physicalDevice, nullptr, &c, &e[0]));
+    if(check(vkEnumerateDeviceExtensionProperties(
+           physicalDevice, nullptr, &c, &e[0]))) {
+        return false;
+    }
     for(u32 i = 0; i < c; i++) {
         if(strcmp(e[i].extensionName, extension) == 0) {
             return true;
@@ -228,17 +238,18 @@ bool Base::hasExtension(const char* extension) {
 }
 
 bool Base::getSurfaceCapabilities(VkSurfaceCapabilitiesKHR& c) {
-    VK_CHECK_TRUE(
+    return check(
         vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &c));
-    return false;
 }
 
 bool Base::findSurfaceFormat(
     VkSurfaceFormatKHR& sf, SurfaceFormatSelector sfs) {
     Core::Array<VkSurfaceFormatKHR, 128> formats;
     u32 c = formats.getLength();
-    VK_CHECK_TRUE(vkGetPhysicalDeviceSurfaceFormatsKHR(
-        physicalDevice, surface, &c, formats.begin()));
+    if(check(vkGetPhysicalDeviceSurfaceFormatsKHR(
+           physicalDevice, surface, &c, formats.begin()))) {
+        return true;
+    }
     int bestPoints = 0;
     for(u32 i = 0; i < c; i++) {
         int points = sfs(formats[i]);
@@ -254,8 +265,10 @@ bool Base::findSurfacePresentMode(
     VkPresentModeKHR& m, SurfacePresentModeSelector spms) {
     Core::Array<VkPresentModeKHR, 64> modes;
     u32 c = modes.getLength();
-    VK_CHECK_TRUE(vkGetPhysicalDeviceSurfacePresentModesKHR(
-        physicalDevice, surface, &c, modes.begin()));
+    if(check(vkGetPhysicalDeviceSurfacePresentModesKHR(
+           physicalDevice, surface, &c, modes.begin()))) {
+        return true;
+    }
     int bestPoints = 0;
     for(u32 i = 0; i < c; i++) {
         int points = spms(modes[i]);
@@ -286,8 +299,7 @@ bool Base::initDevice(
         .enabledExtensionCount = static_cast<u32>(extensions.getLength()),
         .ppEnabledExtensionNames = &extensions[0],
         .pEnabledFeatures = &deviceFeatures};
-    VK_CHECK_TRUE(vkCreateDevice(physicalDevice, &info, nullptr, &device));
-    return false;
+    return check(vkCreateDevice(physicalDevice, &info, nullptr, &device));
 }
 
 void Base::waitForIdle() {

+ 11 - 3
src/VulkanUtility.cpp

@@ -1,11 +1,11 @@
-#include "core/VulkanUtility.hpp"
+module Core.VulkanUtility;
 
-namespace Vulkan = Core::Vulkan;
+import Core.Logger;
 
 #define VK_ERROR_CASE(error)  \
     case error: return #error
 
-const char* Vulkan::getResultString(VkResult r) {
+const char* Core::Vulkan::getResultString(VkResult r) {
     switch(r) {
         VK_ERROR_CASE(VK_SUCCESS);
         VK_ERROR_CASE(VK_NOT_READY);
@@ -60,3 +60,11 @@ const char* Vulkan::getResultString(VkResult r) {
     }
     return "unknown";
 }
+
+bool Core::Vulkan::check(VkResult r) {
+    if(r != VK_SUCCESS) {
+        Core::report(LogLevel::ERROR, "Vulkan | {}", getResultString(r));
+        return true;
+    }
+    return false;
+}

+ 67 - 35
src/VulkanWrapper.cpp

@@ -1,19 +1,18 @@
-#include "core/VulkanWrapper.hpp"
+module;
 
-#include <cstring>
+#include <cstddef>
 
-#include "GLFW.hpp"
-#include "core/VulkanBase.hpp"
-#include "core/WindowManager.hpp"
+module Core.VulkanWrapper;
 
 import Core.File;
 import Core.UniquePointer;
-import Core.List;
 import Core.Logger;
-import Core.Types;
 import Core.Math;
 import Core.Array;
 import Core.Vector;
+import Core.VulkanUtility;
+import Core.WindowManager;
+import Core.Std;
 
 namespace Vulkan = Core::Vulkan;
 using Core::List;
@@ -57,7 +56,9 @@ bool ImageView::init(VkDevice d, VkImage image, VkFormat format) {
             .levelCount = 1,
             .baseArrayLayer = 0,
             .layerCount = 1}};
-    VK_CHECK_TRUE(vkCreateImageView(d, &info, nullptr, &handle));
+    if(check(vkCreateImageView(d, &info, nullptr, &handle))) {
+        return true;
+    }
     device = d;
     return false;
 }
@@ -73,7 +74,9 @@ bool Framebuffer::init(
         .width = width,
         .height = height,
         .layers = 1};
-    VK_CHECK_TRUE(vkCreateFramebuffer(iv.device, &info, nullptr, &handle));
+    if(check(vkCreateFramebuffer(iv.device, &info, nullptr, &handle))) {
+        return true;
+    }
     device = iv.device;
     return false;
 }
@@ -82,7 +85,9 @@ bool Semaphore::init(VkDevice d) {
     Semaphore::~Semaphore();
     VkSemaphoreCreateInfo info = {
         .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
-    VK_CHECK_TRUE(vkCreateSemaphore(d, &info, nullptr, &handle));
+    if(check(vkCreateSemaphore(d, &info, nullptr, &handle))) {
+        return true;
+    }
     device = d;
     return false;
 }
@@ -92,17 +97,19 @@ bool Fence::init(VkDevice d) {
     VkFenceCreateInfo info = {
         .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
         .flags = VK_FENCE_CREATE_SIGNALED_BIT};
-    VK_CHECK_TRUE(vkCreateFence(d, &info, nullptr, &handle));
+    if(check(vkCreateFence(d, &info, nullptr, &handle))) {
+        return true;
+    }
     device = d;
     return false;
 }
 
 void Fence::reset() {
-    VK_CHECK_VOID(vkResetFences(device, 1, &handle));
+    check(vkResetFences(device, 1, &handle));
 }
 
 void Fence::waitFor(u64 timeout) {
-    VK_CHECK_VOID(vkWaitForFences(device, 1, &handle, true, timeout));
+    check(vkWaitForFences(device, 1, &handle, true, timeout));
 }
 
 static u32 getSwapImageCount(const VkSurfaceCapabilitiesKHR* caps) {
@@ -138,7 +145,9 @@ bool Swapchain::init(Data& d) {
         .presentMode = d.presentMode,
         .clipped = VK_TRUE,
         .oldSwapchain = VK_NULL_HANDLE};
-    VK_CHECK_TRUE(vkCreateSwapchainKHR(d.base, &ci, nullptr, &handle));
+    if(check(vkCreateSwapchainKHR(d.base, &ci, nullptr, &handle))) {
+        return true;
+    }
     device = d.base;
     return false;
 }
@@ -151,8 +160,9 @@ SwapchainResult Swapchain::nextImage(
         return SwapchainResult::RECREATE;
     } else if(r == VK_ERROR_OUT_OF_DATE_KHR) {
         return SwapchainResult::ERROR_RECREATE;
+    } else if(r != VK_SUCCESS) {
+        return SwapchainResult::ERROR;
     }
-    VK_CHECK(SwapchainResult::ERROR, r);
     return SwapchainResult::SUCCESS;
 }
 
@@ -164,14 +174,16 @@ bool ShaderModule::init(VkDevice d, const char* path) {
     }
     size_t l = f.getLength() - 1;
     if((l % 4) != 0) {
-        VK_REPORT_ERROR("Shader size is not a multiple of 4");
+        Core::report(LogLevel::ERROR, "Shader size is not a multiple of 4");
         return true;
     }
     VkShaderModuleCreateInfo info = {
         .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
         .codeSize = l,
         .pCode = reinterpret_cast<u32*>(static_cast<void*>(&f[0]))};
-    VK_CHECK_TRUE(vkCreateShaderModule(d, &info, nullptr, &handle));
+    if(check(vkCreateShaderModule(d, &info, nullptr, &handle))) {
+        return true;
+    }
     device = d;
     return false;
 }
@@ -180,18 +192,24 @@ bool PipelineLayout::init(VkDevice d) {
     PipelineLayout::~PipelineLayout();
     VkPipelineLayoutCreateInfo info = {
         .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
-    VK_CHECK_TRUE(vkCreatePipelineLayout(d, &info, nullptr, &handle));
+    if(check(vkCreatePipelineLayout(d, &info, nullptr, &handle))) {
+        return true;
+    }
     device = d;
     return false;
 }
 
 bool SwapchainImages::init(const Swapchain& s, VkFormat format) {
     u32 c = 0;
-    VK_CHECK_TRUE(vkGetSwapchainImagesKHR(s.device, s.handle, &c, nullptr));
+    if(check(vkGetSwapchainImagesKHR(s.device, s.handle, &c, nullptr))) {
+        return true;
+    }
     images.resize(c);
     imageViews.resize(c);
     renderFinishedSemaphore.resize(c);
-    VK_CHECK_TRUE(vkGetSwapchainImagesKHR(s.device, s.handle, &c, &images[0]));
+    if(check(vkGetSwapchainImagesKHR(s.device, s.handle, &c, &images[0]))) {
+        return true;
+    }
     for(u32 x = 0; x < c; x++) {
         if(imageViews[x].init(s.device, images[x], format)) {
             return true;
@@ -235,7 +253,9 @@ bool RenderPass::init(VkDevice d, VkFormat format) {
         .pSubpasses = &subpass,
         .dependencyCount = 1,
         .pDependencies = &dependency};
-    VK_CHECK_TRUE(vkCreateRenderPass(d, &info, nullptr, &handle));
+    if(check(vkCreateRenderPass(d, &info, nullptr, &handle))) {
+        return true;
+    }
     device = d;
     return false;
 }
@@ -358,8 +378,10 @@ bool Pipeline::init(
         .basePipelineHandle = VK_NULL_HANDLE,
         .basePipelineIndex = -1};
 
-    VK_CHECK_TRUE(vkCreateGraphicsPipelines(
-        pl.device, VK_NULL_HANDLE, 1, &info, nullptr, &handle));
+    if(check(vkCreateGraphicsPipelines(
+           pl.device, VK_NULL_HANDLE, 1, &info, nullptr, &handle))) {
+        return true;
+    }
     device = pl.device;
     return false;
 }
@@ -370,7 +392,9 @@ bool CommandPool::init(VkDevice d, u32 queueFamily) {
         .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
         .flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
         .queueFamilyIndex = queueFamily};
-    VK_CHECK_TRUE(vkCreateCommandPool(d, &info, nullptr, &handle));
+    if(check(vkCreateCommandPool(d, &info, nullptr, &handle))) {
+        return true;
+    }
     device = d;
     return false;
 }
@@ -382,23 +406,25 @@ bool CommandBuffer::init(CommandPool& cp) {
         .commandPool = cp,
         .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
         .commandBufferCount = 1};
-    VK_CHECK_TRUE(vkAllocateCommandBuffers(cp.device, &info, &handle));
+    if(check(vkAllocateCommandBuffers(cp.device, &info, &handle))) {
+        return true;
+    }
     device = cp.device;
     return false;
 }
 
 void CommandBuffer::reset() {
-    VK_CHECK_VOID(vkResetCommandBuffer(handle, 0));
+    check(vkResetCommandBuffer(handle, 0));
 }
 
 void CommandBuffer::begin() {
     VkCommandBufferBeginInfo info = {
         .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
-    VK_CHECK_VOID(vkBeginCommandBuffer(handle, &info));
+    check(vkBeginCommandBuffer(handle, &info));
 }
 
 void CommandBuffer::end() {
-    VK_CHECK_VOID(vkEndCommandBuffer(handle));
+    check(vkEndCommandBuffer(handle));
 }
 
 void CommandBuffer::beginRenderPass(
@@ -445,7 +471,7 @@ void Queue::submit(
         .pCommandBuffers = cb,
         .signalSemaphoreCount = 1,
         .pSignalSemaphores = signal};
-    VK_CHECK_VOID(vkQueueSubmit(handle, 1, &info, f));
+    check(vkQueueSubmit(handle, 1, &info, f));
 }
 
 SwapchainResult Queue::present(Semaphore& signal, Swapchain& s, u32 index) {
@@ -461,8 +487,9 @@ SwapchainResult Queue::present(Semaphore& signal, Swapchain& s, u32 index) {
         return SwapchainResult::RECREATE;
     } else if(r == VK_ERROR_OUT_OF_DATE_KHR) {
         return SwapchainResult::ERROR_RECREATE;
+    } else if(r != VK_SUCCESS) {
+        return SwapchainResult::ERROR;
     }
-    VK_CHECK(SwapchainResult::ERROR, r);
     return SwapchainResult::SUCCESS;
 }
 
@@ -484,7 +511,9 @@ bool VertexBuffer::init(Base& b, size_t size, const void* data) {
         .size = size,
         .usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
         .sharingMode = VK_SHARING_MODE_EXCLUSIVE};
-    VK_CHECK_TRUE(vkCreateBuffer(b, &info, nullptr, &handle));
+    if(check(vkCreateBuffer(b, &info, nullptr, &handle))) {
+        return true;
+    }
     device = b;
 
     VkMemoryRequirements m;
@@ -495,11 +524,14 @@ bool VertexBuffer::init(Base& b, size_t size, const void* data) {
         .memoryTypeIndex = b.findMemoryType(
             m.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
                                   VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)};
-    VK_CHECK_TRUE(vkAllocateMemory(device, &aInfo, nullptr, &memory));
-    VK_CHECK_TRUE(vkBindBufferMemory(device, handle, memory, 0));
-
+    if(check(vkAllocateMemory(device, &aInfo, nullptr, &memory)) ||
+       check(vkBindBufferMemory(device, handle, memory, 0))) {
+        return true;
+    }
     void* destination = nullptr;
-    VK_CHECK_TRUE(vkMapMemory(device, memory, 0, size, 0, &destination));
+    if(check(vkMapMemory(device, memory, 0, size, 0, &destination))) {
+        return true;
+    }
     memcpy(destination, data, size);
     vkUnmapMemory(device, memory);
     return false;

+ 6 - 6
src/WindowManager.cpp

@@ -1,11 +1,10 @@
-#include "core/WindowManager.hpp"
-
-#include <cstdio>
+module;
 
+#define GLFW_INCLUDE_VULKAN
+#include <GLFW/glfw3.h>
 #include <limits.h>
 
-#include "GLFW.hpp"
-#include "core/VulkanWrapper.hpp"
+module Core.WindowManager;
 
 import Core.ArrayList;
 import Core.Clock;
@@ -17,6 +16,7 @@ import Core.Array;
 import Core.Vector;
 import Core.Types;
 import Core.Math;
+import Core.VulkanWrapper;
 
 namespace Window = Core::Window;
 using Core::Array;
@@ -396,7 +396,7 @@ Window::Button Window::addButton(const char* name) {
         return 0;
     }
     Button b = buttonIndex++;
-    snprintf(buttons[b].name, sizeof(buttons[b].name), "%s", name);
+    StringBase(buttons[b].name, sizeof(buttons[b].name)).add(name);
     return b;
 }
 

+ 1 - 1
test/modules/ImageTests.cpp

@@ -1,8 +1,8 @@
 import Core.Logger;
 import Core.ToString;
+import Core.Image;
 
 #include "../Tests.hpp"
-#include "core/Image.hpp"
 
 static void testReadPNG8(
     const char* path, const char* name, int width, int height, int channels) {

+ 1 - 1
test/modules/NetworkTests.cpp

@@ -2,13 +2,13 @@
 
 #include "../Tests.hpp"
 #include "../src/ErrorSimulator.hpp"
-#include "core/Network.hpp"
 
 import Core.Clock;
 import Core.Logger;
 import Core.Utility;
 import Core.Test;
 import Core.Types;
+import Core.Network;
 
 using Core::Client;
 using Core::InPacket;

+ 7 - 7
test/modules/WindowManagerTests.cpp

@@ -4,12 +4,12 @@
 #include <GLFW/glfw3.h>
 
 #include "../Tests.hpp"
-#include "core/WindowManager.hpp"
 
 import Core.Logger;
 import Core.Terminal;
 import Core.TerminalConstants;
 import Core.Vector;
+import Core.WindowManager;
 
 namespace W = Core::Window;
 
@@ -26,13 +26,13 @@ static void tick(void*) {
         Core::logInfo(
             "TPS: {}\nFPS: {}\n", W::getTicksPerSecond(),
             W::getFramesPerSecond());
-        printf(
-            "%12s | Down: %d | DownTime: %3d | Released: %d\n",
+        Core::print(
+            "{12} | Down: {} | DownTime: {3} | Released: {}\n",
             W::getButtonName(closeButton), W::isButtonDown(closeButton),
             W::getButtonDownTime(closeButton),
             W::wasButtonReleased(closeButton));
-        printf(
-            "%12s | Down: %d | DownTime: %3d | Released: %d\n",
+        Core::print(
+            "{12} | Down: {} | DownTime: {3} | Released: {}\n",
             W::getButtonName(testButton), W::isButtonDown(testButton),
             W::getButtonDownTime(testButton), W::wasButtonReleased(testButton));
         Core::Vector2 mouse = W::getLastMousePosition();
@@ -46,8 +46,8 @@ static void tick(void*) {
         }
     }
     if(W::isInputEnabled()) {
-        printf("Input: '%s'\n", W::getInputString());
-        printf("Cursor: %zu\n", W::getInputCursor());
+        Core::print("Input: '{}'\n", W::getInputString());
+        Core::print("Cursor: {}\n", W::getInputCursor());
     }
 }