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_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

View File

@@ -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.

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 "../../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
};

View File

@@ -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;

View File

@@ -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_

View File

@@ -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()