working on WebGPU command lists

This commit is contained in:
2025-02-23 20:50:49 +01:00
parent 443eb6b810
commit 311545feb2
12 changed files with 134 additions and 146 deletions

View File

@@ -4,15 +4,62 @@
#include <Pulse.h>
#include "WebGPU.h"
#include "WebGPUDevice.h"
#include "WebGPUCommandList.h"
#include "WebGPUComputePass.h"
#include "../../PulseInternal.h"
PulseCommandList WebGPURequestCommandList(PulseDevice device, PulseCommandListUsage usage)
{
PULSE_CHECK_HANDLE_RETVAL(device, PULSE_NULL_HANDLE);
PULSE_UNUSED(usage);
WebGPUDevice* webgpu_device = WEBGPU_RETRIEVE_DRIVER_DATA_AS(device, WebGPUDevice*);
PulseCommandList cmd = (PulseCommandList)calloc(1, sizeof(PulseCommandListHandler));
PULSE_CHECK_ALLOCATION_RETVAL(cmd, PULSE_NULL_HANDLE);
WebGPUCommandList* webgpu_cmd = (WebGPUCommandList*)calloc(1, sizeof(WebGPUCommandList));
PULSE_CHECK_ALLOCATION_RETVAL(webgpu_cmd, PULSE_NULL_HANDLE);
WGPUCommandEncoderDescriptor encoder_descriptor = { 0 };
webgpu_cmd->encoder = wgpuDeviceCreateCommandEncoder(webgpu_device->device, &encoder_descriptor);
cmd->usage = usage;
cmd->device = device;
cmd->driver_data = webgpu_cmd;
cmd->thread_id = PulseGetThreadID();
cmd->pass = WebGPUCreateComputePass(device, cmd);
cmd->state = PULSE_COMMAND_LIST_STATE_RECORDING;
cmd->is_available = false;
return cmd;
}
bool WebGPUSubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFence fence)
{
WebGPUDevice* webgpu_device = WEBGPU_RETRIEVE_DRIVER_DATA_AS(device, WebGPUDevice*);
WebGPUCommandList* webgpu_cmd = WEBGPU_RETRIEVE_DRIVER_DATA_AS(cmd, WebGPUCommandList*);
WGPUCommandBufferDescriptor command_buffer_descriptor = { 0 };
WGPUCommandBuffer command_buffer = wgpuCommandEncoderFinish(webgpu_cmd->encoder, &command_buffer_descriptor);
wgpuQueueSubmit(webgpu_device->queue, 1, &command_buffer);
wgpuCommandBufferRelease(command_buffer);
return true;
}
void WebGPUReleaseCommandList(PulseDevice device, PulseCommandList cmd)
{
PULSE_CHECK_HANDLE(device);
WebGPUCommandList* webgpu_cmd = WEBGPU_RETRIEVE_DRIVER_DATA_AS(cmd, WebGPUCommandList*);
wgpuCommandEncoderRelease(webgpu_cmd->encoder);
free(webgpu_cmd);
free(cmd);
}