diff --git a/Scripts/BackendBootstraper.py b/Scripts/BackendBootstraper.py new file mode 100644 index 0000000..efaf7ba --- /dev/null +++ b/Scripts/BackendBootstraper.py @@ -0,0 +1,70 @@ +import os +import shutil +import argparse + +def main(): + parser = argparse.ArgumentParser( + description="Bootstraps a new backend." + ) + parser.add_argument("name", help="Backend's name") + parser.add_argument("fn_name", help="Backend's function names") + args = parser.parse_args() + + base_name = "Template" + src_dir = os.path.abspath("Backend" + base_name) + dest_dir = os.path.abspath("../Sources/Backends/" + args.name) + + if not os.path.isdir(src_dir): + raise SystemExit(f"Source directory '{base_name}' not found in current path.") + + if os.path.exists(dest_dir): + raise SystemExit(f"Destination already exists: {dest_dir}") + + fn_name = args.fn_name + name = args.name + name_upper = name.upper() + + # Copy template directory + shutil.copytree(src_dir, dest_dir) + + # Walk through destination and replace names/contents + for root, dirs, files in os.walk(dest_dir, topdown=False): + # Process files + for fname in files: + fpath = os.path.join(root, fname) + + # Replace contents in text files + try: + with open(fpath, "rb") as fb: + head = fb.read(2048) + is_binary = b"\x00" in head + except Exception: + is_binary = True + + if not is_binary: + try: + with open(fpath, "r", encoding="utf-8") as f: + text = f.read() + new_text = text.replace("TemplateName", fn_name).replace("TEMPLATE", name_upper).replace("Template", name) + if new_text != text: + with open(fpath, "w", encoding="utf-8") as f: + f.write(new_text) + except UnicodeDecodeError: + pass + + # Rename file if needed + new_fname = fname.replace("TEMPLATE", name_upper).replace("Template", name) + if new_fname != fname: + os.replace(fpath, os.path.join(root, new_fname)) + + # Process directories + for dname in dirs: + old_dpath = os.path.join(root, dname) + new_dname = dname.replace("TEMPLATE", name_upper).replace("Template", name) + if new_dname != dname: + os.replace(old_dpath, os.path.join(root, new_dname)) + + print(f"✅ Project created at: {dest_dir}") + +if __name__ == '__main__': + main() diff --git a/Scripts/BackendTemplate/Template.c b/Scripts/BackendTemplate/Template.c new file mode 100644 index 0000000..2a70575 --- /dev/null +++ b/Scripts/BackendTemplate/Template.c @@ -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 +#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 +}; diff --git a/Scripts/BackendTemplate/Template.h b/Scripts/BackendTemplate/Template.h new file mode 100644 index 0000000..b3beaad --- /dev/null +++ b/Scripts/BackendTemplate/Template.h @@ -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 + +#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 diff --git a/Scripts/BackendTemplate/TemplateBuffer.c b/Scripts/BackendTemplate/TemplateBuffer.c new file mode 100644 index 0000000..c40ef40 --- /dev/null +++ b/Scripts/BackendTemplate/TemplateBuffer.c @@ -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 + +#include +#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) +{ +} diff --git a/Scripts/BackendTemplate/TemplateBuffer.h b/Scripts/BackendTemplate/TemplateBuffer.h new file mode 100644 index 0000000..c751517 --- /dev/null +++ b/Scripts/BackendTemplate/TemplateBuffer.h @@ -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 + +#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 diff --git a/Scripts/BackendTemplate/TemplateCommandList.c b/Scripts/BackendTemplate/TemplateCommandList.c new file mode 100644 index 0000000..a1ac1f2 --- /dev/null +++ b/Scripts/BackendTemplate/TemplateCommandList.c @@ -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 +#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) +{ +} diff --git a/Scripts/BackendTemplate/TemplateCommandList.h b/Scripts/BackendTemplate/TemplateCommandList.h new file mode 100644 index 0000000..59edcf5 --- /dev/null +++ b/Scripts/BackendTemplate/TemplateCommandList.h @@ -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 + +#ifdef PULSE_ENABLE_TEMPLATE_BACKEND + +#ifndef PULSE_TEMPLATE_COMMAND_LIST_H_ +#define PULSE_TEMPLATE_COMMAND_LIST_H_ + +#include +#include + +#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 diff --git a/Scripts/BackendTemplate/TemplateComputePass.c b/Scripts/BackendTemplate/TemplateComputePass.c new file mode 100644 index 0000000..6b62655 --- /dev/null +++ b/Scripts/BackendTemplate/TemplateComputePass.c @@ -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 +#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) +{ +} diff --git a/Scripts/BackendTemplate/TemplateComputePass.h b/Scripts/BackendTemplate/TemplateComputePass.h new file mode 100644 index 0000000..10badf8 --- /dev/null +++ b/Scripts/BackendTemplate/TemplateComputePass.h @@ -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 + +#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 diff --git a/Scripts/BackendTemplate/TemplateComputePipeline.c b/Scripts/BackendTemplate/TemplateComputePipeline.c new file mode 100644 index 0000000..cb480ff --- /dev/null +++ b/Scripts/BackendTemplate/TemplateComputePipeline.c @@ -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 +#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) +{ +} diff --git a/Scripts/BackendTemplate/TemplateComputePipeline.h b/Scripts/BackendTemplate/TemplateComputePipeline.h new file mode 100644 index 0000000..a203d5f --- /dev/null +++ b/Scripts/BackendTemplate/TemplateComputePipeline.h @@ -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 + +#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 diff --git a/Scripts/BackendTemplate/TemplateDevice.c b/Scripts/BackendTemplate/TemplateDevice.c new file mode 100644 index 0000000..ff56503 --- /dev/null +++ b/Scripts/BackendTemplate/TemplateDevice.c @@ -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 +#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) +{ +} diff --git a/Scripts/BackendTemplate/TemplateDevice.h b/Scripts/BackendTemplate/TemplateDevice.h new file mode 100644 index 0000000..1717a3a --- /dev/null +++ b/Scripts/BackendTemplate/TemplateDevice.h @@ -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 + +#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 diff --git a/Scripts/BackendTemplate/TemplateFence.c b/Scripts/BackendTemplate/TemplateFence.c new file mode 100644 index 0000000..7dcee73 --- /dev/null +++ b/Scripts/BackendTemplate/TemplateFence.c @@ -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 +#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; +} diff --git a/Scripts/BackendTemplate/TemplateFence.h b/Scripts/BackendTemplate/TemplateFence.h new file mode 100644 index 0000000..8270d4e --- /dev/null +++ b/Scripts/BackendTemplate/TemplateFence.h @@ -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 + +#ifdef PULSE_ENABLE_TEMPLATE_BACKEND + +#ifndef PULSE_TEMPLATE_FENCE_H_ +#define PULSE_TEMPLATE_FENCE_H_ + +#include +#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 diff --git a/Scripts/BackendTemplate/TemplateImage.c b/Scripts/BackendTemplate/TemplateImage.c new file mode 100644 index 0000000..4eda548 --- /dev/null +++ b/Scripts/BackendTemplate/TemplateImage.c @@ -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 +#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) +{ +} diff --git a/Scripts/BackendTemplate/TemplateImage.h b/Scripts/BackendTemplate/TemplateImage.h new file mode 100644 index 0000000..64bf60a --- /dev/null +++ b/Scripts/BackendTemplate/TemplateImage.h @@ -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 + +#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 diff --git a/Sources/Backends/D3D11/D3D11.c b/Sources/Backends/D3D11/D3D11.c index 1105053..e491c46 100644 --- a/Sources/Backends/D3D11/D3D11.c +++ b/Sources/Backends/D3D11/D3D11.c @@ -19,6 +19,8 @@ PulseBackendFlags Direct3D11CheckSupport(PulseBackendFlags candidates, PulseShad bool Direct3D11LoadBackend(PulseBackend backend, PulseDebugLevel debug_level) { + PULSE_UNUSED(backend); + PULSE_UNUSED(debug_level); return true; } @@ -34,4 +36,3 @@ PulseBackendHandler D3D11Driver = { .supported_shader_formats = PULSE_SHADER_FORMAT_DXBC_BIT, .driver_data = PULSE_NULLPTR }; - diff --git a/Sources/Backends/D3D11/D3D11.h b/Sources/Backends/D3D11/D3D11.h index 1a9929e..7022e9a 100644 --- a/Sources/Backends/D3D11/D3D11.h +++ b/Sources/Backends/D3D11/D3D11.h @@ -2,6 +2,8 @@ // 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_ @@ -18,7 +20,7 @@ #define D3D11_RETRIEVE_DRIVER_DATA_AS(handle, cast) ((cast)handle->driver_data) -PulseBackendFlags Direct3D11CheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used); // Return PULSE_BACKEND_D3D11 in case of success and PULSE_BACKEND_INVALID otherwise +PulseBackendFlags Direct3D11CheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used); // Returns corresponding PULSE_BACKEND enum in case of success and PULSE_BACKEND_INVALID otherwise #endif // PULSE_D3D11_H_ diff --git a/Sources/Backends/D3D11/D3D11Buffer.c b/Sources/Backends/D3D11/D3D11Buffer.c new file mode 100644 index 0000000..9f45ffb --- /dev/null +++ b/Sources/Backends/D3D11/D3D11Buffer.c @@ -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 + +#include +#include "../../PulseInternal.h" +#include "D3D11.h" +#include "D3D11Buffer.h" +#include "D3D11CommandList.h" + +PulseBuffer Direct3D11CreateBuffer(PulseDevice device, const PulseBufferCreateInfo* create_infos) +{ + PulseBuffer buffer = (PulseBuffer)calloc(1, sizeof(PulseBufferHandler)); + PULSE_CHECK_ALLOCATION_RETVAL(buffer, PULSE_NULL_HANDLE); + return buffer; +} + +bool Direct3D11MapBuffer(PulseBuffer buffer, PulseMapMode mode, void** data) +{ + return true; +} + +void Direct3D11UnmapBuffer(PulseBuffer buffer) +{ +} + +bool Direct3D11CopyBufferToBuffer(PulseCommandList cmd, const PulseBufferRegion* src, const PulseBufferRegion* dst) +{ + return true; +} + +bool Direct3D11CopyBufferToImage(PulseCommandList cmd, const PulseBufferRegion* src, const PulseImageRegion* dst) +{ + return true; +} + +void Direct3D11DestroyBuffer(PulseDevice device, PulseBuffer buffer) +{ +} diff --git a/Sources/Backends/D3D11/D3D11Buffer.h b/Sources/Backends/D3D11/D3D11Buffer.h new file mode 100644 index 0000000..eb13ce5 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11Buffer.h @@ -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 + +#ifdef PULSE_ENABLE_D3D11_BACKEND + +#ifndef PULSE_D3D11_BUFFER_H_ +#define PULSE_D3D11_BUFFER_H_ + +#include "D3D11.h" + +typedef struct Direct3D11Buffer +{ + int dummy; +} Direct3D11Buffer; + +PulseBuffer Direct3D11CreateBuffer(PulseDevice device, const PulseBufferCreateInfo* create_infos); +bool Direct3D11MapBuffer(PulseBuffer buffer, PulseMapMode mode, void** data); +void Direct3D11UnmapBuffer(PulseBuffer buffer); +bool Direct3D11CopyBufferToBuffer(PulseCommandList cmd, const PulseBufferRegion* src, const PulseBufferRegion* dst); +bool Direct3D11CopyBufferToImage(PulseCommandList cmd, const PulseBufferRegion* src, const PulseImageRegion* dst); +void Direct3D11DestroyBuffer(PulseDevice device, PulseBuffer buffer); + +#endif // PULSE_D3D11_BUFFER_H_ + +#endif // PULSE_ENABLE_D3D11_BACKEND diff --git a/Sources/Backends/D3D11/D3D11CommandList.c b/Sources/Backends/D3D11/D3D11CommandList.c new file mode 100644 index 0000000..20dc593 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11CommandList.c @@ -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 +#include "../../PulseInternal.h" +#include "D3D11.h" +#include "D3D11Fence.h" +#include "D3D11Device.h" +#include "D3D11CommandList.h" +#include "D3D11ComputePass.h" +#include "D3D11ComputePipeline.h" +#include "D3D11Buffer.h" + +PulseCommandList Direct3D11RequestCommandList(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 Direct3D11SubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFence fence) +{ +} + +void Direct3D11ReleaseCommandList(PulseDevice device, PulseCommandList cmd) +{ +} diff --git a/Sources/Backends/D3D11/D3D11CommandList.h b/Sources/Backends/D3D11/D3D11CommandList.h new file mode 100644 index 0000000..c20c0a7 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11CommandList.h @@ -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 + +#ifdef PULSE_ENABLE_D3D11_BACKEND + +#ifndef PULSE_D3D11_COMMAND_LIST_H_ +#define PULSE_D3D11_COMMAND_LIST_H_ + +#include +#include + +#include "D3D11.h" +#include "D3D11Fence.h" + +typedef struct Direct3D11CommandList +{ + int dummy; +} Direct3D11CommandList; + +PulseCommandList Direct3D11RequestCommandList(PulseDevice device, PulseCommandListUsage usage); +bool Direct3D11SubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFence fence); +void Direct3D11ReleaseCommandList(PulseDevice device, PulseCommandList cmd); + +#endif // PULSE_D3D11_COMMAND_LIST_H_ + +#endif // PULSE_ENABLE_D3D11_BACKEND diff --git a/Sources/Backends/D3D11/D3D11ComputePass.c b/Sources/Backends/D3D11/D3D11ComputePass.c new file mode 100644 index 0000000..eec8e9f --- /dev/null +++ b/Sources/Backends/D3D11/D3D11ComputePass.c @@ -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 +#include "../../PulseInternal.h" +#include "D3D11.h" +#include "D3D11ComputePass.h" +#include "D3D11CommandList.h" + +PulseComputePass Direct3D11CreateComputePass(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 Direct3D11DestroyComputePass(PulseDevice device, PulseComputePass pass) +{ +} + +PulseComputePass Direct3D11BeginComputePass(PulseCommandList cmd) +{ +} + +void Direct3D11EndComputePass(PulseComputePass pass) +{ +} + +void Direct3D11BindStorageBuffers(PulseComputePass pass, const PulseBuffer* buffers, uint32_t num_buffers) +{ +} + +void Direct3D11BindUniformData(PulseComputePass pass, uint32_t slot, const void* data, uint32_t data_size) +{ +} + +void Direct3D11BindStorageImages(PulseComputePass pass, const PulseImage* images, uint32_t num_images) +{ +} + +void Direct3D11BindComputePipeline(PulseComputePass pass, PulseComputePipeline pipeline) +{ +} + +void Direct3D11DispatchComputations(PulseComputePass pass, uint32_t groupcount_x, uint32_t groupcount_y, uint32_t groupcount_z) +{ +} diff --git a/Sources/Backends/D3D11/D3D11ComputePass.h b/Sources/Backends/D3D11/D3D11ComputePass.h new file mode 100644 index 0000000..40079e6 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11ComputePass.h @@ -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 + +#ifdef PULSE_ENABLE_D3D11_BACKEND + +#ifndef PULSE_D3D11_COMPUTE_PASS_H_ +#define PULSE_D3D11_COMPUTE_PASS_H_ + +#include "D3D11.h" + +PulseComputePass Direct3D11CreateComputePass(PulseDevice device, PulseCommandList cmd); +void Direct3D11DestroyComputePass(PulseDevice device, PulseComputePass pass); + +PulseComputePass Direct3D11BeginComputePass(PulseCommandList cmd); +void Direct3D11EndComputePass(PulseComputePass pass); +void Direct3D11BindStorageBuffers(PulseComputePass pass, const PulseBuffer* buffers, uint32_t num_buffers); +void Direct3D11BindUniformData(PulseComputePass pass, uint32_t slot, const void* data, uint32_t data_size); +void Direct3D11BindStorageImages(PulseComputePass pass, const PulseImage* images, uint32_t num_images); +void Direct3D11BindComputePipeline(PulseComputePass pass, PulseComputePipeline pipeline); +void Direct3D11DispatchComputations(PulseComputePass pass, uint32_t groupcount_x, uint32_t groupcount_y, uint32_t groupcount_z); + +#endif // PULSE_D3D11_COMPUTE_PASS_H_ + +#endif // PULSE_ENABLE_D3D11_BACKEND diff --git a/Sources/Backends/D3D11/D3D11ComputePipeline.c b/Sources/Backends/D3D11/D3D11ComputePipeline.c new file mode 100644 index 0000000..6238288 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11ComputePipeline.c @@ -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 +#include "../../PulseInternal.h" +#include "D3D11.h" +#include "D3D11Device.h" +#include "D3D11ComputePipeline.h" + +PulseComputePipeline Direct3D11CreateComputePipeline(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, "(D3D11) created new compute pipeline %p", pipeline); + return pipeline; +} + +void Direct3D11DestroyComputePipeline(PulseDevice device, PulseComputePipeline pipeline) +{ +} diff --git a/Sources/Backends/D3D11/D3D11ComputePipeline.h b/Sources/Backends/D3D11/D3D11ComputePipeline.h new file mode 100644 index 0000000..42a5870 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11ComputePipeline.h @@ -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 + +#ifdef PULSE_ENABLE_D3D11_BACKEND + +#ifndef PULSE_D3D11_COMPUTE_PIPELINE_H_ +#define PULSE_D3D11_COMPUTE_PIPELINE_H_ + +#include "D3D11.h" + +typedef struct Direct3D11ComputePipeline +{ + int dummy; +} Direct3D11ComputePipeline; + +PulseComputePipeline Direct3D11CreateComputePipeline(PulseDevice device, const PulseComputePipelineCreateInfo* info); +void Direct3D11DestroyComputePipeline(PulseDevice device, PulseComputePipeline pipeline); + +#endif // PULSE_D3D11_COMPUTE_PIPELINE_H_ + +#endif // PULSE_ENABLE_D3D11_BACKEND diff --git a/Sources/Backends/D3D11/D3D11Device.c b/Sources/Backends/D3D11/D3D11Device.c index a1bb6c6..277d2eb 100644 --- a/Sources/Backends/D3D11/D3D11Device.c +++ b/Sources/Backends/D3D11/D3D11Device.c @@ -2,13 +2,18 @@ // This file is part of "Pulse" // For conditions of distribution and use, see copyright notice in LICENSE -#include - #include +#include #include "../../PulseInternal.h" #include "D3D11.h" +#include "D3D11ComputePipeline.h" +#include "D3D11CommandList.h" #include "D3D11Device.h" +#include "D3D11Fence.h" +#include "D3D11Buffer.h" +#include "D3D11Image.h" +#include "D3D11ComputePass.h" bool Direct3D11IsDedicatedAdapter(IDXGIAdapter1* adapter) { @@ -146,8 +151,7 @@ PulseDevice Direct3D11CreateDevice(PulseBackend backend, PulseDevice* forbiden_d }; D3D11CreateDevice((IDXGIAdapter*)device->adapter, D3D_DRIVER_TYPE_UNKNOWN, PULSE_NULLPTR, 0, feature_levels, PULSE_SIZEOF_ARRAY(feature_levels), D3D11_SDK_VERSION, &device->device, PULSE_NULLPTR, &device->context); - - pulse_device->PFN_DestroyDevice = Direct3D11DestroyDevice; + PULSE_LOAD_DRIVER_DEVICE(Direct3D11); if(PULSE_IS_BACKEND_HIGH_LEVEL_DEBUG(backend)) PulseLogInfoFmt(backend, "(D3D11) created device from %ls", device->description.Description); diff --git a/Sources/Backends/D3D11/D3D11Device.h b/Sources/Backends/D3D11/D3D11Device.h index 9fe22bb..d71fcf7 100644 --- a/Sources/Backends/D3D11/D3D11Device.h +++ b/Sources/Backends/D3D11/D3D11Device.h @@ -2,12 +2,13 @@ // 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_DEVICE_H_ #define PULSE_D3D11_DEVICE_H_ -#include #include "D3D11.h" typedef struct Direct3D11Device diff --git a/Sources/Backends/D3D11/D3D11Fence.c b/Sources/Backends/D3D11/D3D11Fence.c new file mode 100644 index 0000000..615da64 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11Fence.c @@ -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 +#include "../../PulseInternal.h" +#include "D3D11.h" +#include "D3D11Fence.h" +#include "D3D11CommandList.h" + +PulseFence Direct3D11CreateFence(PulseDevice device) +{ + PulseFence fence = (PulseFence)calloc(1, sizeof(PulseFence)); + PULSE_CHECK_ALLOCATION_RETVAL(fence, PULSE_NULL_HANDLE); + return fence; +} + +void Direct3D11DestroyFence(PulseDevice device, PulseFence fence) +{ + free(fence); +} + +bool Direct3D11IsFenceReady(PulseDevice device, PulseFence fence) +{ + return true; +} + +bool Direct3D11WaitForFences(PulseDevice device, const PulseFence* fences, uint32_t fences_count, bool wait_for_all) +{ + return true; +} diff --git a/Sources/Backends/D3D11/D3D11Fence.h b/Sources/Backends/D3D11/D3D11Fence.h new file mode 100644 index 0000000..384dba7 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11Fence.h @@ -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 + +#ifdef PULSE_ENABLE_D3D11_BACKEND + +#ifndef PULSE_D3D11_FENCE_H_ +#define PULSE_D3D11_FENCE_H_ + +#include +#include "D3D11.h" + +typedef struct Direct3D11Fence +{ + int dummy; +} Direct3D11Fence; + +PulseFence Direct3D11CreateFence(PulseDevice device); +void Direct3D11DestroyFence(PulseDevice device, PulseFence fence); +bool Direct3D11IsFenceReady(PulseDevice device, PulseFence fence); +bool Direct3D11WaitForFences(PulseDevice device, const PulseFence* fences, uint32_t fences_count, bool wait_for_all); + +#endif // PULSE_D3D11_FENCE_H_ + +#endif // PULSE_ENABLE_D3D11_BACKEND diff --git a/Sources/Backends/D3D11/D3D11Image.c b/Sources/Backends/D3D11/D3D11Image.c new file mode 100644 index 0000000..b8b25e1 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11Image.c @@ -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 +#include "../../PulseInternal.h" +#include "D3D11.h" +#include "D3D11Image.h" + +PulseImage Direct3D11CreateImage(PulseDevice device, const PulseImageCreateInfo* create_infos) +{ +} + +bool Direct3D11IsImageFormatValid(PulseDevice device, PulseImageFormat format, PulseImageType type, PulseImageUsageFlags usage) +{ +} + +bool Direct3D11CopyImageToBuffer(PulseCommandList cmd, const PulseImageRegion* src, const PulseBufferRegion* dst) +{ +} + +bool Direct3D11BlitImage(PulseCommandList cmd, const PulseImageRegion* src, const PulseImageRegion* dst) +{ +} + +void Direct3D11DestroyImage(PulseDevice device, PulseImage image) +{ +} diff --git a/Sources/Backends/D3D11/D3D11Image.h b/Sources/Backends/D3D11/D3D11Image.h new file mode 100644 index 0000000..4aa5150 --- /dev/null +++ b/Sources/Backends/D3D11/D3D11Image.h @@ -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 + +#ifdef PULSE_ENABLE_D3D11_BACKEND + +#ifndef PULSE_D3D11_IMAGE_H_ +#define PULSE_D3D11_IMAGE_H_ + +#include "D3D11.h" + +typedef struct Direct3D11Image +{ + int dummy; +} Direct3D11Image; + +PulseImage Direct3D11CreateImage(PulseDevice device, const PulseImageCreateInfo* create_infos); +bool Direct3D11IsImageFormatValid(PulseDevice device, PulseImageFormat format, PulseImageType type, PulseImageUsageFlags usage); +bool Direct3D11CopyImageToBuffer(PulseCommandList cmd, const PulseImageRegion* src, const PulseBufferRegion* dst); +bool Direct3D11BlitImage(PulseCommandList cmd, const PulseImageRegion* src, const PulseImageRegion* dst); +void Direct3D11DestroyImage(PulseDevice device, PulseImage image); + +#endif // PULSE_D3D11_IMAGE_H_ + +#endif // PULSE_ENABLE_D3D11_BACKEND