diff --git a/Includes/Pulse.h b/Includes/Pulse.h index d0c1ef3..bd2bf91 100644 --- a/Includes/Pulse.h +++ b/Includes/Pulse.h @@ -36,7 +36,7 @@ typedef enum PulseBackendBits PULSE_BACKEND_INVALID = PULSE_BIT(1), PULSE_BACKEND_ANY = PULSE_BIT(2), PULSE_BACKEND_VULKAN = PULSE_BIT(3), - PULSE_BACKEND_D3D11 = PULSE_BIT(4), + PULSE_BACKEND_METAL = PULSE_BIT(4), // More to come } PulseBackendBits; typedef PulseFlags PulseBackendFlags; @@ -67,8 +67,9 @@ typedef PulseFlags PulseImageUsageFlags; typedef enum PulseShaderFormatsBits { - PULSE_SHADER_FORMAT_SPIRV_BIT = PULSE_BIT(1), // Can be used by Vulkan | D3D11 backends - PULSE_SHADER_FORMAT_DXBC_BIT = PULSE_BIT(2), // Can be used by D3D11 backend only + PULSE_SHADER_FORMAT_SPIRV_BIT = PULSE_BIT(1), // Can be used by Vulkan + PULSE_SHADER_FORMAT_MSL_BIT = PULSE_BIT(2), // Can be used by Metal + PULSE_SHADER_FORMAT_METALLIB_BIT = PULSE_BIT(3), // Can be used by Metal // More to come } PulseShaderFormatsBits; typedef PulseFlags PulseShaderFormatsFlags; @@ -284,7 +285,7 @@ PULSE_API PulseComputePipeline PulseCreateComputePipeline(PulseDevice device, co PULSE_API void PulseDispatchComputePipeline(PulseComputePipeline pipeline, PulseCommandList cmd, uint32_t groupcount_x, uint32_t groupcount_y, uint32_t groupcount_z); PULSE_API void PulseDestroyComputePipeline(PulseDevice device, PulseComputePipeline pipeline); -PULSE_API PulseErrorType PulseGetLastErrorType(); // /!\ Warning /!\ Call to this function resets the internal last error variable +PULSE_API PulseErrorType PulseGetLastErrorType(); // Call to this function resets the internal last error variable PULSE_API const char* PulseVerbaliseErrorType(PulseErrorType error); #ifdef __cplusplus diff --git a/README.md b/README.md index 3866d35..69e2649 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # PulseGPU -Pulse is a low level GPGPU library designed for highly intensive general GPU computations with high control over the hardware. It is built on top of Vulkan, D3D11 and a Metal support is in discussion. +Pulse is a low level GPGPU library designed for highly intensive general GPU computations with high control over the hardware. It is built on top of Vulkan and a Metal support is in discussion. diff --git a/Sources/Backends/D3D11/D3D11.h b/Sources/Backends/D3D11/D3D11.h deleted file mode 100644 index 3c5c7dd..0000000 --- a/Sources/Backends/D3D11/D3D11.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2024 kanel -// This file is part of "Pulse" -// For conditions of distribution and use, see copyright notice in LICENSE - -#include - -#ifdef PULSE_ENABLE_D3D11_BACKEND - -#ifndef PULSE_D3D11_H_ -#define PULSE_D3D11_H_ - -PulseBackendFlags D3D11CheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used); // Return PULSE_BACKEND_VULKAN in case of success and PULSE_BACKEND_INVALID otherwise - -#endif // PULSE_D3D11_H_ - -#endif // PULSE_ENABLE_D3D11_BACKEND diff --git a/Sources/Backends/Metal/Metal.h b/Sources/Backends/Metal/Metal.h new file mode 100644 index 0000000..17f86f8 --- /dev/null +++ b/Sources/Backends/Metal/Metal.h @@ -0,0 +1,16 @@ +// Copyright (C) 2024 kanel +// This file is part of "Pulse" +// For conditions of distribution and use, see copyright notice in LICENSE + +#include + +#ifdef PULSE_ENABLE_METAL_BACKEND + +#ifndef PULSE_METAL_H_ +#define PULSE_METAL_H_ + +PulseBackendFlags MetalCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used); // Return PULSE_BACKEND_METAL in case of success and PULSE_BACKEND_INVALID otherwise + +#endif // PULSE_METAL_H_ + +#endif // PULSE_ENABLE_METAL_BACKEND diff --git a/Sources/Backends/D3D11/D3D11.c b/Sources/Backends/Metal/Metal.m similarity index 53% rename from Sources/Backends/D3D11/D3D11.c rename to Sources/Backends/Metal/Metal.m index a9b8c55..0b201f9 100644 --- a/Sources/Backends/D3D11/D3D11.c +++ b/Sources/Backends/Metal/Metal.m @@ -5,22 +5,22 @@ #include #include "../../PulseInternal.h" -#include "D3D11.h" +#include "Metal.h" -PulseBackendFlags D3D11CheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used) +PulseBackendFlags MetalCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used) { - if(candidates != PULSE_BACKEND_ANY && (candidates & PULSE_BACKEND_D3D11) == 0) + if(candidates != PULSE_BACKEND_ANY && (candidates & PULSE_BACKEND_METAL) == 0) return PULSE_BACKEND_INVALID; - if((shader_formats_used & PULSE_SHADER_FORMAT_DXBC_BIT) == 0) + if((shader_formats_used & PULSE_SHADER_FORMAT_MSL_BIT) == 0 && (shader_formats_used & PULSE_SHADER_FORMAT_METALLIB_BIT) == 0) return PULSE_BACKEND_INVALID; - return PULSE_BACKEND_INVALID; // Not supported + return PULSE_BACKEND_INVALID; // Not supported yet } -PulseBackendHandler D3D11Driver = { +PulseBackendHandler MetalDriver = { .PFN_LoadBackend = PULSE_NULLPTR, .PFN_UnloadBackend = PULSE_NULLPTR, .PFN_CreateDevice = PULSE_NULLPTR, - .backend = PULSE_BACKEND_D3D11, - .supported_shader_formats = PULSE_SHADER_FORMAT_DXBC_BIT, + .backend = PULSE_BACKEND_METAL, + .supported_shader_formats = PULSE_SHADER_FORMAT_MSL_BIT | PULSE_SHADER_FORMAT_METALLIB_BIT, .driver_data = PULSE_NULLPTR }; diff --git a/Sources/PulseBackend.c b/Sources/PulseBackend.c index 1b16caf..17ad3eb 100644 --- a/Sources/PulseBackend.c +++ b/Sources/PulseBackend.c @@ -11,8 +11,8 @@ #ifdef PULSE_ENABLE_VULKAN_BACKEND #include "Backends/Vulkan/Vulkan.h" #endif -#ifdef PULSE_ENABLE_D3D11_BACKEND - #include "Backends/D3D11/D3D11.h" +#ifdef PULSE_ENABLE_METAL_BACKEND + #include "Backends/Metal/Metal.h" #endif // Ordered by default preference @@ -20,8 +20,8 @@ static const PulseCheckBackendSupportPFN backends_supports[] = { #ifdef PULSE_ENABLE_VULKAN_BACKEND VulkanCheckSupport, #endif - #ifdef PULSE_ENABLE_D3D11_BACKEND - D3D11CheckSupport, + #ifdef PULSE_ENABLE_METAL_BACKEND + MetalCheckSupport, #endif PULSE_NULLPTR }; @@ -87,8 +87,8 @@ static PulseBackend PulseGetBackendFromFlag(PulseBackendBits flag) #ifdef PULSE_ENABLE_VULKAN_BACKEND case PULSE_BACKEND_VULKAN: return &VulkanDriver; #endif - #ifdef PULSE_ENABLE_D3D11_BACKEND - case PULSE_BACKEND_D3D11: return &D3D11Driver; + #ifdef PULSE_ENABLE_METAL_BACKEND + case PULSE_BACKEND_METAL: return &MetalDriver; #endif default: break; diff --git a/Sources/PulseInternal.h b/Sources/PulseInternal.h index 962c199..caaca2e 100644 --- a/Sources/PulseInternal.h +++ b/Sources/PulseInternal.h @@ -131,8 +131,8 @@ void PulseLogBackend(PulseBackend backend, PulseDebugMessageSeverity type, const #ifdef PULSE_ENABLE_VULKAN_BACKEND extern PulseBackendHandler VulkanDriver; #endif // PULSE_ENABLE_VULKAN_BACKEND -#ifdef PULSE_ENABLE_D3D11_BACKEND - extern PulseBackendHandler D3D11Driver; -#endif // PULSE_ENABLE_D3D11_BACKEND +#ifdef PULSE_ENABLE_METAL_BACKEND + extern PulseBackendHandler MetalDriver; +#endif // PULSE_ENABLE_METAL_BACKEND #endif // PULSE_INTERNAL_H_ diff --git a/xmake.lua b/xmake.lua index 2028185..5e66cc9 100644 --- a/xmake.lua +++ b/xmake.lua @@ -6,16 +6,18 @@ local backends = { Vulkan = { option = "vulkan", default = true, - has_cpp_files = true, packages = { "vulkan-headers", "vulkan-memory-allocator" }, custom = function() add_defines("VK_NO_PROTOTYPES") + add_files("Sources/Backends/Vulkan/**.cpp") end }, - D3D11 = { - option = "d3d11", - default = is_plat("windows", "mingw"), - has_cpp_files = false, + Metal = { + option = "metal", + default = is_plat("macosx", "iphoneos"), + custom = function() + add_files("Sources/Backends/Metal/**.m") + end } } @@ -80,9 +82,6 @@ target("pulse_gpu") add_headerfiles("Sources/Backends/" .. name .. "/**.inl", { prefixdir = "private", install = false }) add_files("Sources/Backends/" .. name .. "/**.c") - if module.has_cpp_files then - add_files("Sources/Backends/" .. name .. "/**.cpp") - end if module.custom then module.custom()