mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-11 15:33:34 +00:00
adding base webgpu compute pass and compute pipeline
This commit is contained in:
@@ -9,18 +9,13 @@
|
|||||||
|
|
||||||
PulseComputePass VulkanCreateComputePass(PulseDevice device, PulseCommandList cmd)
|
PulseComputePass VulkanCreateComputePass(PulseDevice device, PulseCommandList cmd)
|
||||||
{
|
{
|
||||||
|
PULSE_UNUSED(device);
|
||||||
PulseComputePass pass = (PulseComputePass)calloc(1, sizeof(PulseComputePassHandler));
|
PulseComputePass pass = (PulseComputePass)calloc(1, sizeof(PulseComputePassHandler));
|
||||||
PULSE_CHECK_ALLOCATION_RETVAL(pass, PULSE_NULL_HANDLE);
|
PULSE_CHECK_ALLOCATION_RETVAL(pass, PULSE_NULL_HANDLE);
|
||||||
|
|
||||||
VulkanComputePass* vulkan_pass = (VulkanComputePass*)calloc(1, sizeof(VulkanComputePass));
|
VulkanComputePass* vulkan_pass = (VulkanComputePass*)calloc(1, sizeof(VulkanComputePass));
|
||||||
PULSE_CHECK_ALLOCATION_RETVAL(vulkan_pass, PULSE_NULL_HANDLE);
|
PULSE_CHECK_ALLOCATION_RETVAL(vulkan_pass, PULSE_NULL_HANDLE);
|
||||||
|
|
||||||
VulkanDevice* vulkan_device = VULKAN_RETRIEVE_DRIVER_DATA_AS(device, VulkanDevice*);
|
|
||||||
|
|
||||||
// vulkan_pass->read_only_descriptor_set = VulkanRequestDescriptorSetFromPool(
|
|
||||||
// VulkanGetAvailableDescriptorSetPool(&vulkan_device->descriptor_set_pool_manager),
|
|
||||||
// VulkanGetDescriptorSetLayout(&vulkan_device->descriptor_set_layout_manager, ));
|
|
||||||
|
|
||||||
pass->cmd = cmd;
|
pass->cmd = cmd;
|
||||||
pass->driver_data = vulkan_pass;
|
pass->driver_data = vulkan_pass;
|
||||||
|
|
||||||
@@ -29,7 +24,7 @@ PulseComputePass VulkanCreateComputePass(PulseDevice device, PulseCommandList cm
|
|||||||
|
|
||||||
void VulkanDestroyComputePass(PulseDevice device, PulseComputePass pass)
|
void VulkanDestroyComputePass(PulseDevice device, PulseComputePass pass)
|
||||||
{
|
{
|
||||||
(void)device; // Maybe reserved for future use
|
PULSE_UNUSED(device);
|
||||||
free(pass->driver_data);
|
free(pass->driver_data);
|
||||||
free(pass);
|
free(pass);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,21 +4,44 @@
|
|||||||
|
|
||||||
#include <Pulse.h>
|
#include <Pulse.h>
|
||||||
#include "WebGPU.h"
|
#include "WebGPU.h"
|
||||||
|
#include "WebGPUDevice.h"
|
||||||
|
#include "WebGPUComputePass.h"
|
||||||
|
|
||||||
PulseComputePass WebGPUCreateComputePass(PulseDevice device, PulseCommandList cmd)
|
PulseComputePass WebGPUCreateComputePass(PulseDevice device, PulseCommandList cmd)
|
||||||
{
|
{
|
||||||
|
PULSE_UNUSED(device);
|
||||||
|
PulseComputePass pass = (PulseComputePass)calloc(1, sizeof(PulseComputePassHandler));
|
||||||
|
PULSE_CHECK_ALLOCATION_RETVAL(pass, PULSE_NULL_HANDLE);
|
||||||
|
|
||||||
|
WebGPUComputePass* webgpu_pass = (WebGPUComputePass*)calloc(1, sizeof(WebGPUComputePass));
|
||||||
|
PULSE_CHECK_ALLOCATION_RETVAL(webgpu_pass, PULSE_NULL_HANDLE);
|
||||||
|
|
||||||
|
pass->cmd = cmd;
|
||||||
|
pass->driver_data = webgpu_pass;
|
||||||
|
|
||||||
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDestroyComputePass(PulseDevice device, PulseComputePass pass)
|
void WebGPUDestroyComputePass(PulseDevice device, PulseComputePass pass)
|
||||||
{
|
{
|
||||||
|
PULSE_UNUSED(device);
|
||||||
|
free(pass->driver_data);
|
||||||
|
free(pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
PulseComputePass WebGPUBeginComputePass(PulseCommandList cmd)
|
PulseComputePass WebGPUBeginComputePass(PulseCommandList cmd)
|
||||||
{
|
{
|
||||||
|
WebGPUCommandList* webgpu_cmd = WEBGPU_RETRIEVE_DRIVER_DATA_AS(cmd, WebGPUCommandList*);
|
||||||
|
WebGPUComputePass* webgpu_pass = WEBGPU_RETRIEVE_DRIVER_DATA_AS(cmd->pass, WebGPUComputePass*);
|
||||||
|
WGPUComputePassDescriptor descriptor = { 0 };
|
||||||
|
webgpu_pass->encoder = wgpuCommandEncoderBeginComputePass(webgpu_cmd->encoder, &descriptor);
|
||||||
|
return cmd->pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUEndComputePass(PulseComputePass pass)
|
void WebGPUEndComputePass(PulseComputePass pass)
|
||||||
{
|
{
|
||||||
|
WebGPUComputePass* webgpu_pass = WEBGPU_RETRIEVE_DRIVER_DATA_AS(pass, WebGPUComputePass*);
|
||||||
|
wgpuComputePassEncoderEnd(webgpu_pass->encoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUBindStorageBuffers(PulseComputePass pass, const PulseBuffer* buffers, uint32_t num_buffers)
|
void WebGPUBindStorageBuffers(PulseComputePass pass, const PulseBuffer* buffers, uint32_t num_buffers)
|
||||||
@@ -39,4 +62,6 @@ void WebGPUBindComputePipeline(PulseComputePass pass, PulseComputePipeline pipel
|
|||||||
|
|
||||||
void WebGPUDispatchComputations(PulseComputePass pass, uint32_t groupcount_x, uint32_t groupcount_y, uint32_t groupcount_z)
|
void WebGPUDispatchComputations(PulseComputePass pass, uint32_t groupcount_x, uint32_t groupcount_y, uint32_t groupcount_z)
|
||||||
{
|
{
|
||||||
|
WebGPUComputePass* webgpu_pass = WEBGPU_RETRIEVE_DRIVER_DATA_AS(pass, WebGPUComputePass*);
|
||||||
|
wgpuComputePassEncoderDispatchWorkgroups(webgpu_pass->encoder, groupcount_x, groupcount_y, groupcount_z);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
typedef struct WebGPUComputePass
|
typedef struct WebGPUComputePass
|
||||||
{
|
{
|
||||||
|
WGPUComputePassEncoder encoder;
|
||||||
} WebGPUComputePass;
|
} WebGPUComputePass;
|
||||||
|
|
||||||
PulseComputePass WebGPUCreateComputePass(PulseDevice device, PulseCommandList cmd);
|
PulseComputePass WebGPUCreateComputePass(PulseDevice device, PulseCommandList cmd);
|
||||||
|
|||||||
@@ -3,10 +3,57 @@
|
|||||||
// For conditions of distribution and use, see copyright notice in LICENSE
|
// For conditions of distribution and use, see copyright notice in LICENSE
|
||||||
|
|
||||||
#include <Pulse.h>
|
#include <Pulse.h>
|
||||||
|
#include "../../PulseInternal.h"
|
||||||
#include "WebGPU.h"
|
#include "WebGPU.h"
|
||||||
|
#include "WebGPUDevice.h"
|
||||||
|
#include "WebGPUComputePipeline.h"
|
||||||
|
|
||||||
PulseComputePipeline WebGPUCreateComputePipeline(PulseDevice device, const PulseComputePipelineCreateInfo* info)
|
PulseComputePipeline WebGPUCreateComputePipeline(PulseDevice device, const PulseComputePipelineCreateInfo* info)
|
||||||
{
|
{
|
||||||
|
WebGPUDevice* webgpu_device = WEBGPU_RETRIEVE_DRIVER_DATA_AS(device, WebGPUDevice*);
|
||||||
|
|
||||||
|
PulseComputePipelineHandler* pipeline = (PulseComputePipelineHandler*)calloc(1, sizeof(PulseComputePipelineHandler));
|
||||||
|
PULSE_CHECK_ALLOCATION_RETVAL(pipeline, PULSE_NULL_HANDLE);
|
||||||
|
|
||||||
|
WebGPUComputePipeline* webgpu_pipeline = (WebGPUComputePipeline*)calloc(1, sizeof(WebGPUComputePipeline));
|
||||||
|
PULSE_CHECK_ALLOCATION_RETVAL(webgpu_pipeline, PULSE_NULL_HANDLE);
|
||||||
|
|
||||||
|
pipeline->driver_data = webgpu_pipeline;
|
||||||
|
|
||||||
|
if(PULSE_IS_BACKEND_LOW_LEVEL_DEBUG(device->backend))
|
||||||
|
{
|
||||||
|
if(info->code == PULSE_NULLPTR)
|
||||||
|
PulseLogError(device->backend, "invalid code pointer passed to PulseComputePipelineCreateInfo");
|
||||||
|
if(info->entrypoint == PULSE_NULLPTR)
|
||||||
|
PulseLogError(device->backend, "invalid entrypoint pointer passed to PulseComputePipelineCreateInfo");
|
||||||
|
if(info->format == PULSE_SHADER_FORMAT_WGSL_BIT && (device->backend->supported_shader_formats & PULSE_SHADER_FORMAT_WGSL_BIT) == 0)
|
||||||
|
PulseLogError(device->backend, "invalid shader format passed to PulseComputePipelineCreateInfo");
|
||||||
|
}
|
||||||
|
|
||||||
|
WGPUStringView code = { 0 };
|
||||||
|
code.length = info->code_size;
|
||||||
|
code.data = (const char*)info->code;
|
||||||
|
WGPUChainedStruct chain = { 0 };
|
||||||
|
chain.next = PULSE_NULLPTR;
|
||||||
|
chain.sType = WGPUSType_ShaderSourceWGSL;
|
||||||
|
WGPUShaderSourceWGSL source = { 0 };
|
||||||
|
source.chain = chain;
|
||||||
|
source.code = code;
|
||||||
|
WGPUShaderModuleDescriptor shader_descriptor = { 0 };
|
||||||
|
shader_descriptor.nextInChain = (const WGPUChainedStruct*)&source;
|
||||||
|
webgpu_pipeline->shader = wgpuDeviceCreateShaderModule(webgpu_device->device, &shader_descriptor);
|
||||||
|
|
||||||
|
WGPUStringView entrypoint = { 0 };
|
||||||
|
code.length = WGPU_STRLEN;
|
||||||
|
code.data = info->entrypoint;
|
||||||
|
WGPUProgrammableStageDescriptor state = { 0 };
|
||||||
|
state.module = webgpu_pipeline->shader;
|
||||||
|
state.entryPoint = entrypoint;
|
||||||
|
WGPUComputePipelineDescriptor pipeline_descriptor = { 0 };
|
||||||
|
pipeline_descriptor.compute = state;
|
||||||
|
webgpu_pipeline->pipeline = wgpuDeviceCreateComputePipeline(webgpu_device->device, &pipeline_descriptor);
|
||||||
|
|
||||||
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDestroyComputePipeline(PulseDevice device, PulseComputePipeline pipeline)
|
void WebGPUDestroyComputePipeline(PulseDevice device, PulseComputePipeline pipeline)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
typedef struct WebGPUComputePipeline
|
typedef struct WebGPUComputePipeline
|
||||||
{
|
{
|
||||||
|
WGPUComputePipeline pipeline;
|
||||||
|
WGPUShaderModule shader;
|
||||||
} WebGPUComputePipeline;
|
} WebGPUComputePipeline;
|
||||||
|
|
||||||
PulseComputePipeline WebGPUCreateComputePipeline(PulseDevice device, const PulseComputePipelineCreateInfo* info);
|
PulseComputePipeline WebGPUCreateComputePipeline(PulseDevice device, const PulseComputePipelineCreateInfo* info);
|
||||||
|
|||||||
Reference in New Issue
Block a user