adding backend bootstrapper

This commit is contained in:
2025-08-27 23:36:32 +02:00
parent 08d25cd631
commit 84bb6854c1
33 changed files with 925 additions and 7 deletions

38
Scripts/BackendTemplate/Template.c git.filemode.normal_file
View File

@@ -0,0 +1,38 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "Template.h"
#include "TemplateDevice.h"
PulseBackendFlags TemplateNameCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used)
{
if(candidates != PULSE_BACKEND_ANY && (candidates & PULSE_BACKEND_TEMPLATE) == 0)
return PULSE_BACKEND_INVALID;
//if((shader_formats_used & PULSE_SHADER_FORMAT_SPIRV_BIT) == 0)
// return PULSE_BACKEND_INVALID;
return PULSE_BACKEND_TEMPLATE;
}
bool TemplateNameLoadBackend(PulseBackend backend, PulseDebugLevel debug_level)
{
PULSE_UNUSED(backend);
PULSE_UNUSED(debug_level);
return true;
}
void TemplateNameUnloadBackend(PulseBackend backend)
{
}
PulseBackendHandler TemplateNameDriver = {
.PFN_LoadBackend = TemplateNameLoadBackend,
.PFN_UnloadBackend = TemplateNameUnloadBackend,
.PFN_CreateDevice = TemplateNameCreateDevice,
.backend = PULSE_BACKEND_TEMPLATE,
.supported_shader_formats = PULSE_SHADER_FORMAT_SPIRV_BIT,
.driver_data = PULSE_NULLPTR
};

18
Scripts/BackendTemplate/Template.h git.filemode.normal_file
View File

@@ -0,0 +1,18 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#ifdef PULSE_ENABLE_TEMPLATE_BACKEND
#ifndef PULSE_TEMPLATE_H_
#define PULSE_TEMPLATE_H_
#define TEMPLATE_RETRIEVE_DRIVER_DATA_AS(handle, cast) ((cast)handle->driver_data)
PulseBackendFlags TemplateNameCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used); // Returns corresponding PULSE_BACKEND enum in case of success and PULSE_BACKEND_INVALID otherwise
#endif // PULSE_TEMPLATE_H_
#endif // PULSE_ENABLE_TEMPLATE_BACKEND

41
Scripts/BackendTemplate/TemplateBuffer.c git.filemode.normal_file
View File

@@ -0,0 +1,41 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <string.h>
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "Template.h"
#include "TemplateBuffer.h"
#include "TemplateCommandList.h"
PulseBuffer TemplateNameCreateBuffer(PulseDevice device, const PulseBufferCreateInfo* create_infos)
{
PulseBuffer buffer = (PulseBuffer)calloc(1, sizeof(PulseBufferHandler));
PULSE_CHECK_ALLOCATION_RETVAL(buffer, PULSE_NULL_HANDLE);
return buffer;
}
bool TemplateNameMapBuffer(PulseBuffer buffer, PulseMapMode mode, void** data)
{
return true;
}
void TemplateNameUnmapBuffer(PulseBuffer buffer)
{
}
bool TemplateNameCopyBufferToBuffer(PulseCommandList cmd, const PulseBufferRegion* src, const PulseBufferRegion* dst)
{
return true;
}
bool TemplateNameCopyBufferToImage(PulseCommandList cmd, const PulseBufferRegion* src, const PulseImageRegion* dst)
{
return true;
}
void TemplateNameDestroyBuffer(PulseDevice device, PulseBuffer buffer)
{
}

28
Scripts/BackendTemplate/TemplateBuffer.h git.filemode.normal_file
View File

@@ -0,0 +1,28 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#ifdef PULSE_ENABLE_TEMPLATE_BACKEND
#ifndef PULSE_TEMPLATE_BUFFER_H_
#define PULSE_TEMPLATE_BUFFER_H_
#include "Template.h"
typedef struct TemplateNameBuffer
{
int dummy;
} TemplateNameBuffer;
PulseBuffer TemplateNameCreateBuffer(PulseDevice device, const PulseBufferCreateInfo* create_infos);
bool TemplateNameMapBuffer(PulseBuffer buffer, PulseMapMode mode, void** data);
void TemplateNameUnmapBuffer(PulseBuffer buffer);
bool TemplateNameCopyBufferToBuffer(PulseCommandList cmd, const PulseBufferRegion* src, const PulseBufferRegion* dst);
bool TemplateNameCopyBufferToImage(PulseCommandList cmd, const PulseBufferRegion* src, const PulseImageRegion* dst);
void TemplateNameDestroyBuffer(PulseDevice device, PulseBuffer buffer);
#endif // PULSE_TEMPLATE_BUFFER_H_
#endif // PULSE_ENABLE_TEMPLATE_BACKEND

29
Scripts/BackendTemplate/TemplateCommandList.c git.filemode.normal_file
View File

@@ -0,0 +1,29 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "Template.h"
#include "TemplateFence.h"
#include "TemplateDevice.h"
#include "TemplateCommandList.h"
#include "TemplateComputePass.h"
#include "TemplateComputePipeline.h"
#include "TemplateBuffer.h"
PulseCommandList TemplateNameRequestCommandList(PulseDevice device, PulseCommandListUsage usage)
{
PULSE_CHECK_HANDLE_RETVAL(device, PULSE_NULL_HANDLE);
PulseCommandList cmd = (PulseCommandList)calloc(1, sizeof(PulseCommandListHandler));
PULSE_CHECK_ALLOCATION_RETVAL(cmd, PULSE_NULL_HANDLE);
return cmd;
}
bool TemplateNameSubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFence fence)
{
}
void TemplateNameReleaseCommandList(PulseDevice device, PulseCommandList cmd)
{
}

29
Scripts/BackendTemplate/TemplateCommandList.h git.filemode.normal_file
View File

@@ -0,0 +1,29 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#ifdef PULSE_ENABLE_TEMPLATE_BACKEND
#ifndef PULSE_TEMPLATE_COMMAND_LIST_H_
#define PULSE_TEMPLATE_COMMAND_LIST_H_
#include <stdatomic.h>
#include <tinycthread.h>
#include "Template.h"
#include "TemplateFence.h"
typedef struct TemplateNameCommandList
{
int dummy;
} TemplateNameCommandList;
PulseCommandList TemplateNameRequestCommandList(PulseDevice device, PulseCommandListUsage usage);
bool TemplateNameSubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFence fence);
void TemplateNameReleaseCommandList(PulseDevice device, PulseCommandList cmd);
#endif // PULSE_TEMPLATE_COMMAND_LIST_H_
#endif // PULSE_ENABLE_TEMPLATE_BACKEND

49
Scripts/BackendTemplate/TemplateComputePass.c git.filemode.normal_file
View File

@@ -0,0 +1,49 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "Template.h"
#include "TemplateComputePass.h"
#include "TemplateCommandList.h"
PulseComputePass TemplateNameCreateComputePass(PulseDevice device, PulseCommandList cmd)
{
PULSE_UNUSED(device);
PulseComputePass pass = (PulseComputePass)calloc(1, sizeof(PulseComputePassHandler));
PULSE_CHECK_ALLOCATION_RETVAL(pass, PULSE_NULL_HANDLE);
return pass;
}
void TemplateNameDestroyComputePass(PulseDevice device, PulseComputePass pass)
{
}
PulseComputePass TemplateNameBeginComputePass(PulseCommandList cmd)
{
}
void TemplateNameEndComputePass(PulseComputePass pass)
{
}
void TemplateNameBindStorageBuffers(PulseComputePass pass, const PulseBuffer* buffers, uint32_t num_buffers)
{
}
void TemplateNameBindUniformData(PulseComputePass pass, uint32_t slot, const void* data, uint32_t data_size)
{
}
void TemplateNameBindStorageImages(PulseComputePass pass, const PulseImage* images, uint32_t num_images)
{
}
void TemplateNameBindComputePipeline(PulseComputePass pass, PulseComputePipeline pipeline)
{
}
void TemplateNameDispatchComputations(PulseComputePass pass, uint32_t groupcount_x, uint32_t groupcount_y, uint32_t groupcount_z)
{
}

27
Scripts/BackendTemplate/TemplateComputePass.h git.filemode.normal_file
View File

@@ -0,0 +1,27 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#ifdef PULSE_ENABLE_TEMPLATE_BACKEND
#ifndef PULSE_TEMPLATE_COMPUTE_PASS_H_
#define PULSE_TEMPLATE_COMPUTE_PASS_H_
#include "Template.h"
PulseComputePass TemplateNameCreateComputePass(PulseDevice device, PulseCommandList cmd);
void TemplateNameDestroyComputePass(PulseDevice device, PulseComputePass pass);
PulseComputePass TemplateNameBeginComputePass(PulseCommandList cmd);
void TemplateNameEndComputePass(PulseComputePass pass);
void TemplateNameBindStorageBuffers(PulseComputePass pass, const PulseBuffer* buffers, uint32_t num_buffers);
void TemplateNameBindUniformData(PulseComputePass pass, uint32_t slot, const void* data, uint32_t data_size);
void TemplateNameBindStorageImages(PulseComputePass pass, const PulseImage* images, uint32_t num_images);
void TemplateNameBindComputePipeline(PulseComputePass pass, PulseComputePipeline pipeline);
void TemplateNameDispatchComputations(PulseComputePass pass, uint32_t groupcount_x, uint32_t groupcount_y, uint32_t groupcount_z);
#endif // PULSE_TEMPLATE_COMPUTE_PASS_H_
#endif // PULSE_ENABLE_TEMPLATE_BACKEND

View File

@@ -0,0 +1,22 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "Template.h"
#include "TemplateDevice.h"
#include "TemplateComputePipeline.h"
PulseComputePipeline TemplateNameCreateComputePipeline(PulseDevice device, const PulseComputePipelineCreateInfo* info)
{
PulseComputePipelineHandler* pipeline = (PulseComputePipelineHandler*)calloc(1, sizeof(PulseComputePipelineHandler));
PULSE_CHECK_ALLOCATION_RETVAL(pipeline, PULSE_NULL_HANDLE);
if(PULSE_IS_BACKEND_HIGH_LEVEL_DEBUG(device->backend))
PulseLogInfoFmt(device->backend, "(Template) created new compute pipeline %p", pipeline);
return pipeline;
}
void TemplateNameDestroyComputePipeline(PulseDevice device, PulseComputePipeline pipeline)
{
}

View File

@@ -0,0 +1,24 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#ifdef PULSE_ENABLE_TEMPLATE_BACKEND
#ifndef PULSE_TEMPLATE_COMPUTE_PIPELINE_H_
#define PULSE_TEMPLATE_COMPUTE_PIPELINE_H_
#include "Template.h"
typedef struct TemplateNameComputePipeline
{
int dummy;
} TemplateNameComputePipeline;
PulseComputePipeline TemplateNameCreateComputePipeline(PulseDevice device, const PulseComputePipelineCreateInfo* info);
void TemplateNameDestroyComputePipeline(PulseDevice device, PulseComputePipeline pipeline);
#endif // PULSE_TEMPLATE_COMPUTE_PIPELINE_H_
#endif // PULSE_ENABLE_TEMPLATE_BACKEND

36
Scripts/BackendTemplate/TemplateDevice.c git.filemode.normal_file
View File

@@ -0,0 +1,36 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "Template.h"
#include "TemplateComputePipeline.h"
#include "TemplateCommandList.h"
#include "TemplateDevice.h"
#include "TemplateFence.h"
#include "TemplateBuffer.h"
#include "TemplateImage.h"
#include "TemplateComputePass.h"
PulseDevice TemplateNameCreateDevice(PulseBackend backend, PulseDevice* forbiden_devices, uint32_t forbiden_devices_count)
{
PULSE_UNUSED(forbiden_devices);
PULSE_UNUSED(forbiden_devices_count);
PULSE_CHECK_HANDLE_RETVAL(backend, PULSE_NULLPTR);
PulseDevice pulse_device = (PulseDeviceHandler*)calloc(1, sizeof(PulseDeviceHandler));
PULSE_CHECK_ALLOCATION_RETVAL(pulse_device, PULSE_NULL_HANDLE);
pulse_device->backend = backend;
PULSE_LOAD_DRIVER_DEVICE(TemplateName);
if(PULSE_IS_BACKEND_HIGH_LEVEL_DEBUG(backend))
PulseLogInfoFmt(backend, "(Template) created device from %s", "yes");
return pulse_device;
}
void TemplateNameDestroyDevice(PulseDevice device)
{
}

24
Scripts/BackendTemplate/TemplateDevice.h git.filemode.normal_file
View File

@@ -0,0 +1,24 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#ifdef PULSE_ENABLE_TEMPLATE_BACKEND
#ifndef PULSE_TEMPLATE_DEVICE_H_
#define PULSE_TEMPLATE_DEVICE_H_
#include "Template.h"
typedef struct TemplateNameDevice
{
int dummy;
} TemplateNameDevice;
PulseDevice TemplateNameCreateDevice(PulseBackend backend, PulseDevice* forbiden_devices, uint32_t forbiden_devices_count);
void TemplateNameDestroyDevice(PulseDevice device);
#endif // PULSE_TEMPLATE_DEVICE_H_
#endif // PULSE_ENABLE_TEMPLATE_BACKEND

31
Scripts/BackendTemplate/TemplateFence.c git.filemode.normal_file
View File

@@ -0,0 +1,31 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "Template.h"
#include "TemplateFence.h"
#include "TemplateCommandList.h"
PulseFence TemplateNameCreateFence(PulseDevice device)
{
PulseFence fence = (PulseFence)calloc(1, sizeof(PulseFence));
PULSE_CHECK_ALLOCATION_RETVAL(fence, PULSE_NULL_HANDLE);
return fence;
}
void TemplateNameDestroyFence(PulseDevice device, PulseFence fence)
{
free(fence);
}
bool TemplateNameIsFenceReady(PulseDevice device, PulseFence fence)
{
return true;
}
bool TemplateNameWaitForFences(PulseDevice device, const PulseFence* fences, uint32_t fences_count, bool wait_for_all)
{
return true;
}

27
Scripts/BackendTemplate/TemplateFence.h git.filemode.normal_file
View File

@@ -0,0 +1,27 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#ifdef PULSE_ENABLE_TEMPLATE_BACKEND
#ifndef PULSE_TEMPLATE_FENCE_H_
#define PULSE_TEMPLATE_FENCE_H_
#include <Pulse.h>
#include "Template.h"
typedef struct TemplateNameFence
{
int dummy;
} TemplateNameFence;
PulseFence TemplateNameCreateFence(PulseDevice device);
void TemplateNameDestroyFence(PulseDevice device, PulseFence fence);
bool TemplateNameIsFenceReady(PulseDevice device, PulseFence fence);
bool TemplateNameWaitForFences(PulseDevice device, const PulseFence* fences, uint32_t fences_count, bool wait_for_all);
#endif // PULSE_TEMPLATE_FENCE_H_
#endif // PULSE_ENABLE_TEMPLATE_BACKEND

28
Scripts/BackendTemplate/TemplateImage.c git.filemode.normal_file
View File

@@ -0,0 +1,28 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "Template.h"
#include "TemplateImage.h"
PulseImage TemplateNameCreateImage(PulseDevice device, const PulseImageCreateInfo* create_infos)
{
}
bool TemplateNameIsImageFormatValid(PulseDevice device, PulseImageFormat format, PulseImageType type, PulseImageUsageFlags usage)
{
}
bool TemplateNameCopyImageToBuffer(PulseCommandList cmd, const PulseImageRegion* src, const PulseBufferRegion* dst)
{
}
bool TemplateNameBlitImage(PulseCommandList cmd, const PulseImageRegion* src, const PulseImageRegion* dst)
{
}
void TemplateNameDestroyImage(PulseDevice device, PulseImage image)
{
}

27
Scripts/BackendTemplate/TemplateImage.h git.filemode.normal_file
View File

@@ -0,0 +1,27 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#ifdef PULSE_ENABLE_TEMPLATE_BACKEND
#ifndef PULSE_TEMPLATE_IMAGE_H_
#define PULSE_TEMPLATE_IMAGE_H_
#include "Template.h"
typedef struct TemplateNameImage
{
int dummy;
} TemplateNameImage;
PulseImage TemplateNameCreateImage(PulseDevice device, const PulseImageCreateInfo* create_infos);
bool TemplateNameIsImageFormatValid(PulseDevice device, PulseImageFormat format, PulseImageType type, PulseImageUsageFlags usage);
bool TemplateNameCopyImageToBuffer(PulseCommandList cmd, const PulseImageRegion* src, const PulseBufferRegion* dst);
bool TemplateNameBlitImage(PulseCommandList cmd, const PulseImageRegion* src, const PulseImageRegion* dst);
void TemplateNameDestroyImage(PulseDevice device, PulseImage image);
#endif // PULSE_TEMPLATE_IMAGE_H_
#endif // PULSE_ENABLE_TEMPLATE_BACKEND