Skip to content

Commit

Permalink
Initialize WebGPU
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 24, 2025
1 parent 193019e commit 9e300f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 5 additions & 1 deletion backends/gpu/webgpu/includes/kore3/webgpu/device_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
#include <kore3/util/indexallocator.h>
#include <kore3/util/offalloc/offalloc.h>

#include <webgpu/webgpu.h>

#ifdef __cplusplus
extern "C" {
#endif

#define KORE_WEBGPU_FRAME_COUNT 2

typedef struct kore_webgpu_device {
int nothing;
WGPUDevice device;
WGPUQueue queue;
WGPUSwapChain swap_chain;
} kore_webgpu_device;

typedef struct kore_webgpu_query_set {
Expand Down
32 changes: 31 additions & 1 deletion backends/gpu/webgpu/sources/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,39 @@
#include <kore3/log.h>
#include <kore3/window.h>

#include <emscripten.h>
#include <emscripten/html5.h>
#include <emscripten/html5_webgpu.h>

#include <assert.h>

void kore_webgpu_device_create(kore_gpu_device *device, const kore_gpu_device_wishlist *wishlist) {}
void kore_webgpu_device_create(kore_gpu_device *device, const kore_gpu_device_wishlist *wishlist) {
device->webgpu.device = emscripten_webgpu_get_device();
device->webgpu.queue = wgpuDeviceGetQueue(device->webgpu.device);

WGPUSurfaceDescriptorFromCanvasHTMLSelector canvas_selector = {
.chain = {
.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector,
},
.selector = "canvas",
};

WGPUSurfaceDescriptor surface_descriptor = {
.nextInChain = (WGPUChainedStruct *)&canvas_selector,
};

WGPUInstance instance = 0;
WGPUSurface surface = wgpuInstanceCreateSurface(instance, &surface_descriptor);

WGPUSwapChainDescriptor swap_chain_descriptor = {
.usage = WGPUTextureUsage_RenderAttachment,
.format = WGPUTextureFormat_BGRA8Unorm,
.width = kore_window_width(0),
.height = kore_window_height(0),
.presentMode = WGPUPresentMode_Fifo,
};
device->webgpu.swap_chain = wgpuDeviceCreateSwapChain(device->webgpu.device, surface, &swap_chain_descriptor);
}

void kore_webgpu_device_destroy(kore_gpu_device *device) {}

Expand Down

0 comments on commit 9e300f7

Please sign in to comment.