mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-11 15:33:34 +00:00
fences
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
// This file is part of "Pulse"
|
||||
// For conditions of distribution and use, see copyright notice in LICENSE
|
||||
|
||||
#include <stdatomic.h>
|
||||
|
||||
#include <Pulse.h>
|
||||
#include "WebGPU.h"
|
||||
#include "WebGPUDevice.h"
|
||||
#include "WebGPUFence.h"
|
||||
#include "WebGPUCommandList.h"
|
||||
#include "WebGPUComputePass.h"
|
||||
#include "../../PulseInternal.h"
|
||||
@@ -38,6 +41,17 @@ PulseCommandList WebGPURequestCommandList(PulseDevice device, PulseCommandListUs
|
||||
return cmd;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static void WebGPUFenceCallback(WGPUQueueWorkDoneStatus status, void* userdata1, void* userdata2)
|
||||
{
|
||||
PULSE_UNUSED(userdata2);
|
||||
WebGPUFence* webgpu_fence = (WebGPUFence*)userdata1;
|
||||
if(status == WGPUQueueWorkDoneStatus_Success)
|
||||
atomic_store(&webgpu_fence->signal, true);
|
||||
puts("test");
|
||||
}
|
||||
|
||||
bool WebGPUSubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFence fence)
|
||||
{
|
||||
WebGPUDevice* webgpu_device = WEBGPU_RETRIEVE_DRIVER_DATA_AS(device, WebGPUDevice*);
|
||||
@@ -48,6 +62,15 @@ bool WebGPUSubmitCommandList(PulseDevice device, PulseCommandList cmd, PulseFenc
|
||||
|
||||
wgpuQueueSubmit(webgpu_device->queue, 1, &command_buffer);
|
||||
|
||||
WebGPUFence* webgpu_fence = WEBGPU_RETRIEVE_DRIVER_DATA_AS(fence, WebGPUFence*);
|
||||
atomic_store(&webgpu_fence->signal, false);
|
||||
|
||||
WGPUQueueWorkDoneCallbackInfo callback = { 0 };
|
||||
callback.mode = WGPUCallbackMode_AllowSpontaneous;
|
||||
callback.callback = WebGPUFenceCallback;
|
||||
callback.userdata1 = webgpu_fence;
|
||||
wgpuQueueOnSubmittedWorkDone(webgpu_device->queue, callback);
|
||||
|
||||
wgpuCommandBufferRelease(command_buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "WebGPUBuffer.h"
|
||||
#include "WebGPUImage.h"
|
||||
#include "WebGPUComputePass.h"
|
||||
#include "webgpu.h"
|
||||
|
||||
#ifndef PULSE_PLAT_WASM
|
||||
#include <wgpu.h>
|
||||
|
||||
@@ -3,20 +3,59 @@
|
||||
// For conditions of distribution and use, see copyright notice in LICENSE
|
||||
|
||||
#include <Pulse.h>
|
||||
#include "../../PulseInternal.h"
|
||||
#include "WebGPU.h"
|
||||
#include "WebGPUFence.h"
|
||||
|
||||
PulseFence WebGPUCreateFence(PulseDevice device)
|
||||
{
|
||||
PULSE_UNUSED(device);
|
||||
|
||||
PulseFence fence = (PulseFence)calloc(1, sizeof(PulseFence));
|
||||
PULSE_CHECK_ALLOCATION_RETVAL(fence, PULSE_NULL_HANDLE);
|
||||
|
||||
WebGPUFence* webgpu_fence = (WebGPUFence*)calloc(1, sizeof(WebGPUFence));
|
||||
PULSE_CHECK_ALLOCATION_RETVAL(webgpu_fence, PULSE_NULL_HANDLE);
|
||||
|
||||
atomic_store(&webgpu_fence->signal, true);
|
||||
|
||||
fence->driver_data = webgpu_fence;
|
||||
|
||||
return fence;
|
||||
}
|
||||
|
||||
void WebGPUDestroyFence(PulseDevice device, PulseFence fence)
|
||||
{
|
||||
PULSE_UNUSED(device);
|
||||
free(fence->driver_data);
|
||||
free(fence);
|
||||
}
|
||||
|
||||
bool WebGPUIsFenceReady(PulseDevice device, PulseFence fence)
|
||||
{
|
||||
PULSE_UNUSED(device);
|
||||
WebGPUFence* webgpu_fence = WEBGPU_RETRIEVE_DRIVER_DATA_AS(fence, WebGPUFence*);
|
||||
return atomic_load(&webgpu_fence->signal) == true;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
bool WebGPUWaitForFences(PulseDevice device, const PulseFence* fences, uint32_t fences_count, bool wait_for_all)
|
||||
{
|
||||
PULSE_UNUSED(device);
|
||||
if(fences_count == 0)
|
||||
return true;
|
||||
uint32_t fences_to_wait = fences_count;
|
||||
while(fences_to_wait != 0)
|
||||
{
|
||||
for(uint32_t i = 0; i < fences_count; i++)
|
||||
{
|
||||
if(WebGPUIsFenceReady(device, fences[i]))
|
||||
fences_to_wait--;
|
||||
}
|
||||
if(!wait_for_all && fences_to_wait != fences_count)
|
||||
return true;
|
||||
PulseSleep(1); // 1ms
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,15 @@
|
||||
#define PULSE_WEBGPU_FENCE_H_
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
#include <Pulse.h>
|
||||
|
||||
typedef struct WebGPUFence
|
||||
{
|
||||
atomic_bool signal;
|
||||
} WebGPUFence;
|
||||
|
||||
PulseFence WebGPUCreateFence(PulseDevice device);
|
||||
void WebGPUDestroyFence(PulseDevice device, PulseFence fence);
|
||||
bool WebGPUIsFenceReady(PulseDevice device, PulseFence fence);
|
||||
|
||||
Reference in New Issue
Block a user