Closed FaultyPine closed 4 months ago
Must be something about the swapchain setup. Does the same problem happen with the samples here: https://floooh.github.io/sokol-html5/?
A couple of questions:
Nvm, I can reproduce the problem, but only with your repro.zip, not from the code in sokol-samples. I'll check how the code differs.
Hmm, no differences at first glance except for a couple of minor C vs C++ changes.
I'll need to dive a bit deeper later today.
Can you check if the original code in sokol-samples works?
Basically:
./fips emsdk install latest
./fips set config wgpu-wasm-ninja-release
./fips build
./fips run clear-wgpu
...this works here, but your example doesn't.
Erm, wait a second... the code somehow combines sokol_app.h with the bare wgpu-init code, that definitely won't work...
The idea is that you either use sokolapp.h (which has its own webgpu setup code) or the wgpu setup code, but not both (since both sokolapp.h and wgpu will do the WebGPU device and swapchain setup.
Let me check something...
...ok, the easiest way to make it work is to ignore all the stuff under wgpu/
, and change main.cpp like this (ignoring the C++20 warnings):
//------------------------------------------------------------------------------
// clear-wgpu.c
// Simple draw loop, clear default framebuffer.
//------------------------------------------------------------------------------
#ifdef TARGET_WEB
#elif defined(TARGET_DESKTOP)
#define SOKOL_GLCORE
#else
#error "Unsupported target right now..."
#endif
#define SOKOL_IMPL
#define SOKOL_WGPU
#include "sokol/sokol_gfx.h"
#include "sokol/sokol_log.h"
#include "sokol/sokol_app.h"
#include "sokol/sokol_glue.h"
// emcc src/main.cpp -o app.html -I. -s USE_WEBGPU=1 -DTARGET_WEB -Iexternal -g -s USE_WEBGPU=1 --shell-file=configs/index.html
static sg_pass_action pass_action;
static void init(void) {
sg_desc desc =
{
.logger.func = slog_func,
.environment = sglue_environment(),
};
sg_setup(&desc);
pass_action = (sg_pass_action) {
.colors[0] = {
.load_action = SG_LOADACTION_CLEAR,
.clear_value = { 1.0f, 0.0f, 0.0f, 1.0f }
}
};
}
static void frame(void) {
float g = pass_action.colors[0].clear_value.g + 0.01f;
pass_action.colors[0].clear_value.g = (g > 1.0f) ? 0.0f : g;
sg_pass pass = { .action = pass_action, .swapchain = sglue_swapchain() };
sg_begin_pass(&pass);
sg_end_pass();
sg_commit();
}
static void shutdown(void) {
sg_shutdown();
}
sapp_desc sokol_main(int argc, char* argv[])
{
return {
.width = 640,
.height = 480,
.init_cb = init,
.frame_cb = frame,
.cleanup_cb = shutdown,
.window_title = "clear-wgpu",
};
}
...otherwise if you don't want to to use sokolapp.h, use the wgpu* files from there, but in that case do not use sokol_app.h: https://github.com/floooh/sokol-samples/tree/master/wgpu
Just be aware that the current version of libdawn isn't supported, so that code won't help you getting a native WebGPU executable.
Ahhh that makes sense. Fixed! Thank you for the quick response! It's really appreciated <3
I'm getting this error message loads of times in the chrome console (and a black canvas) when trying to run a webgpu sokol app. Reduced the code down to the bare minimum example code from sokol-samples.
Chrome version: 126.0.6478.127
Code
```cpp //------------------------------------------------------------------------------ // clear-wgpu.c // Simple draw loop, clear default framebuffer. //------------------------------------------------------------------------------ #ifdef TARGET_WEB #define SOKOL_WGPU #elif defined(TARGET_DESKTOP) #define SOKOL_GLCORE #else #error "Unsupported target right now..." #endif #define SOKOL_IMPL #include "sokol/sokol_gfx.h" #include "sokol/sokol_log.h" #include "sokol/sokol_app.h" #ifdef TARGET_WEB #include "wgpu/wgpu_entry.h" #includecompiled with
where index.html looks like
index.html
```html {{{ SCRIPT }}} ```repro.zip
Running the compilation command in this repro folder and then doing
emrun app.html
reproduced the issue for me.