Skip to content

Commit

Permalink
Fix wasm compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 24, 2025
1 parent 9e300f7 commit ef51df0
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backends/gpu/webgpu/includes/kore3/webgpu/device_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <kore3/util/indexallocator.h>
#include <kore3/util/offalloc/offalloc.h>

#include <webgpu/webgpu.h>
#include "webgpu.h"

#ifdef __cplusplus
extern "C" {
Expand Down
88 changes: 88 additions & 0 deletions backends/gpu/webgpu/includes/kore3/webgpu/webgpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifndef KORE_WEBGPU_HEADER
#define KORE_WEBGPU_HEADER

#ifdef KINC_EMSCRIPTEN

#include <webgpu/webgpu.h>

#else

typedef struct WGPUDevice {
int nothing;
} WGPUDevice;

typedef struct WGPUQueue {
int nothing;
} WGPUQueue;

typedef struct WGPUSwapChain {
int nothing;
} WGPUSwapChain;

typedef enum WGPUSType {
WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector
} WGPUSType;

typedef struct WGPUChainedStruct {
WGPUSType sType;
} WGPUChainedStruct;

typedef struct WGPUSurfaceDescriptorFromCanvasHTMLSelector {
WGPUChainedStruct chain;
const char *selector;
} WGPUSurfaceDescriptorFromCanvasHTMLSelector;

typedef struct WGPUSurfaceDescriptor {
WGPUChainedStruct *nextInChain;
} WGPUSurfaceDescriptor;

typedef void *WGPUInstance;

typedef struct WGPUSurface {
int nothing;
} WGPUSurface;

typedef enum WGPUTextureUsage {
WGPUTextureUsage_RenderAttachment
} WGPUTextureUsage;

typedef enum WGPUTextureFormat {
WGPUTextureFormat_BGRA8Unorm
} WGPUTextureFormat;

typedef enum WGPUPresentMode {
WGPUPresentMode_Fifo
} WGPUPresentMode;

typedef struct WGPUSwapChainDescriptor {
WGPUTextureUsage usage;
WGPUTextureFormat format;
int width;
int height;
WGPUPresentMode presentMode;
} WGPUSwapChainDescriptor;

static inline WGPUQueue wgpuDeviceGetQueue(WGPUDevice device) {
WGPUQueue queue = {
.nothing = 0,
};
return queue;
}

static inline WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, const WGPUSurfaceDescriptor *surfaceDescriptor) {
WGPUSurface surface = {
.nothing = 0,
};
return surface;
}

static inline WGPUSwapChain wgpuDeviceCreateSwapChain(WGPUDevice device, WGPUSurface surface, const WGPUSwapChainDescriptor* swapChainDescriptor) {
WGPUSwapChain swapChain = {
.nothing = 0,
};
return swapChain;
}

#endif

#endif
4 changes: 4 additions & 0 deletions backends/gpu/webgpu/sources/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
#include <kore3/log.h>
#include <kore3/window.h>

#ifdef KINC_EMSCRIPTEN
#include <emscripten.h>
#include <emscripten/html5.h>
#include <emscripten/html5_webgpu.h>
#endif

#include <assert.h>

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

WGPUSurfaceDescriptorFromCanvasHTMLSelector canvas_selector = {
Expand Down

0 comments on commit ef51df0

Please sign in to comment.