removing D3D11, adding metal base

This commit is contained in:
2025-01-12 19:07:35 +01:00
parent f9476986c2
commit 4bd57a2a51
8 changed files with 46 additions and 46 deletions

View File

@@ -36,7 +36,7 @@ typedef enum PulseBackendBits
PULSE_BACKEND_INVALID = PULSE_BIT(1), PULSE_BACKEND_INVALID = PULSE_BIT(1),
PULSE_BACKEND_ANY = PULSE_BIT(2), PULSE_BACKEND_ANY = PULSE_BIT(2),
PULSE_BACKEND_VULKAN = PULSE_BIT(3), PULSE_BACKEND_VULKAN = PULSE_BIT(3),
PULSE_BACKEND_D3D11 = PULSE_BIT(4), PULSE_BACKEND_METAL = PULSE_BIT(4),
// More to come // More to come
} PulseBackendBits; } PulseBackendBits;
typedef PulseFlags PulseBackendFlags; typedef PulseFlags PulseBackendFlags;
@@ -67,8 +67,9 @@ typedef PulseFlags PulseImageUsageFlags;
typedef enum PulseShaderFormatsBits typedef enum PulseShaderFormatsBits
{ {
PULSE_SHADER_FORMAT_SPIRV_BIT = PULSE_BIT(1), // Can be used by Vulkan | D3D11 backends PULSE_SHADER_FORMAT_SPIRV_BIT = PULSE_BIT(1), // Can be used by Vulkan
PULSE_SHADER_FORMAT_DXBC_BIT = PULSE_BIT(2), // Can be used by D3D11 backend only 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 // More to come
} PulseShaderFormatsBits; } PulseShaderFormatsBits;
typedef PulseFlags PulseShaderFormatsFlags; 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 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 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); PULSE_API const char* PulseVerbaliseErrorType(PulseErrorType error);
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -1,3 +1,3 @@
# PulseGPU # 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.

View File

@@ -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 <Pulse.h>
#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

16
Sources/Backends/Metal/Metal.h git.filemode.normal_file
View File

@@ -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 <Pulse.h>
#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

View File

@@ -5,22 +5,22 @@
#include <Pulse.h> #include <Pulse.h>
#include "../../PulseInternal.h" #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; 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;
return PULSE_BACKEND_INVALID; // Not supported return PULSE_BACKEND_INVALID; // Not supported yet
} }
PulseBackendHandler D3D11Driver = { PulseBackendHandler MetalDriver = {
.PFN_LoadBackend = PULSE_NULLPTR, .PFN_LoadBackend = PULSE_NULLPTR,
.PFN_UnloadBackend = PULSE_NULLPTR, .PFN_UnloadBackend = PULSE_NULLPTR,
.PFN_CreateDevice = PULSE_NULLPTR, .PFN_CreateDevice = PULSE_NULLPTR,
.backend = PULSE_BACKEND_D3D11, .backend = PULSE_BACKEND_METAL,
.supported_shader_formats = PULSE_SHADER_FORMAT_DXBC_BIT, .supported_shader_formats = PULSE_SHADER_FORMAT_MSL_BIT | PULSE_SHADER_FORMAT_METALLIB_BIT,
.driver_data = PULSE_NULLPTR .driver_data = PULSE_NULLPTR
}; };

View File

@@ -11,8 +11,8 @@
#ifdef PULSE_ENABLE_VULKAN_BACKEND #ifdef PULSE_ENABLE_VULKAN_BACKEND
#include "Backends/Vulkan/Vulkan.h" #include "Backends/Vulkan/Vulkan.h"
#endif #endif
#ifdef PULSE_ENABLE_D3D11_BACKEND #ifdef PULSE_ENABLE_METAL_BACKEND
#include "Backends/D3D11/D3D11.h" #include "Backends/Metal/Metal.h"
#endif #endif
// Ordered by default preference // Ordered by default preference
@@ -20,8 +20,8 @@ static const PulseCheckBackendSupportPFN backends_supports[] = {
#ifdef PULSE_ENABLE_VULKAN_BACKEND #ifdef PULSE_ENABLE_VULKAN_BACKEND
VulkanCheckSupport, VulkanCheckSupport,
#endif #endif
#ifdef PULSE_ENABLE_D3D11_BACKEND #ifdef PULSE_ENABLE_METAL_BACKEND
D3D11CheckSupport, MetalCheckSupport,
#endif #endif
PULSE_NULLPTR PULSE_NULLPTR
}; };
@@ -87,8 +87,8 @@ static PulseBackend PulseGetBackendFromFlag(PulseBackendBits flag)
#ifdef PULSE_ENABLE_VULKAN_BACKEND #ifdef PULSE_ENABLE_VULKAN_BACKEND
case PULSE_BACKEND_VULKAN: return &VulkanDriver; case PULSE_BACKEND_VULKAN: return &VulkanDriver;
#endif #endif
#ifdef PULSE_ENABLE_D3D11_BACKEND #ifdef PULSE_ENABLE_METAL_BACKEND
case PULSE_BACKEND_D3D11: return &D3D11Driver; case PULSE_BACKEND_METAL: return &MetalDriver;
#endif #endif
default: break; default: break;

View File

@@ -131,8 +131,8 @@ void PulseLogBackend(PulseBackend backend, PulseDebugMessageSeverity type, const
#ifdef PULSE_ENABLE_VULKAN_BACKEND #ifdef PULSE_ENABLE_VULKAN_BACKEND
extern PulseBackendHandler VulkanDriver; extern PulseBackendHandler VulkanDriver;
#endif // PULSE_ENABLE_VULKAN_BACKEND #endif // PULSE_ENABLE_VULKAN_BACKEND
#ifdef PULSE_ENABLE_D3D11_BACKEND #ifdef PULSE_ENABLE_METAL_BACKEND
extern PulseBackendHandler D3D11Driver; extern PulseBackendHandler MetalDriver;
#endif // PULSE_ENABLE_D3D11_BACKEND #endif // PULSE_ENABLE_METAL_BACKEND
#endif // PULSE_INTERNAL_H_ #endif // PULSE_INTERNAL_H_

View File

@@ -6,16 +6,18 @@ local backends = {
Vulkan = { Vulkan = {
option = "vulkan", option = "vulkan",
default = true, default = true,
has_cpp_files = true,
packages = { "vulkan-headers", "vulkan-memory-allocator" }, packages = { "vulkan-headers", "vulkan-memory-allocator" },
custom = function() custom = function()
add_defines("VK_NO_PROTOTYPES") add_defines("VK_NO_PROTOTYPES")
add_files("Sources/Backends/Vulkan/**.cpp")
end end
}, },
D3D11 = { Metal = {
option = "d3d11", option = "metal",
default = is_plat("windows", "mingw"), default = is_plat("macosx", "iphoneos"),
has_cpp_files = false, 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_headerfiles("Sources/Backends/" .. name .. "/**.inl", { prefixdir = "private", install = false })
add_files("Sources/Backends/" .. name .. "/**.c") add_files("Sources/Backends/" .. name .. "/**.c")
if module.has_cpp_files then
add_files("Sources/Backends/" .. name .. "/**.cpp")
end
if module.custom then if module.custom then
module.custom() module.custom()