No more WebGPU errors

This commit is contained in:
Clément Pons 2025-05-01 16:13:27 +02:00
parent ceaa78ea1a
commit 0059d8fc3b
4 changed files with 24 additions and 17 deletions

View File

@ -20,6 +20,7 @@
"ratio": "cpp",
"sokol_log.h": "c",
"syslog.h": "c",
"base.h": "c"
"base.h": "c",
"stdarg.h": "c"
}
}

View File

@ -311,7 +311,7 @@ static const uint8_t vs_source_wgsl[1944] = {
struct main_out {
@builtin(frag_depth)
gl_FragDepth_1 : f32,
@location(4)
@location(0)
frag_color_1 : vec4f,
}
@ -371,7 +371,7 @@ static const uint8_t fs_source_wgsl[1047] = {
0x69,0x6c,0x74,0x69,0x6e,0x28,0x66,0x72,0x61,0x67,0x5f,0x64,0x65,0x70,0x74,0x68,
0x29,0x0a,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,
0x5f,0x31,0x20,0x3a,0x20,0x66,0x33,0x32,0x2c,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63,
0x61,0x74,0x69,0x6f,0x6e,0x28,0x34,0x29,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,
0x61,0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,
0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,
0x0a,0x7d,0x0a,0x0a,0x40,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x0a,0x66,0x6e,
0x20,0x6d,0x61,0x69,0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,

View File

@ -13,7 +13,9 @@
#include "generated/base.h"
#include <stdio.h>
#ifndef _STDIO_H
#include <stdio.h>
#endif
#include <stdlib.h>
#include <math.h>
#include <stdarg.h>
@ -44,8 +46,9 @@ typedef struct position_t
typedef struct renderer_t {
sg_pipeline pipeline;
sg_pipeline compute;
sg_bindings* binding;
sg_bindings binding;
sg_range uniform;
sg_pass_action pass;
} renderer_t;
typedef struct userdata_t
@ -60,17 +63,14 @@ static void frame(void* _userdata)
{
userdata_t* userdata = (userdata_t*) _userdata;
sg_begin_pass(&(sg_pass) {
.action = {
.colors[0] = {
.load_action = SG_LOADACTION_CLEAR,
.clear_value = { 0.0f, 0.0f, 0.0f, 1.0f},
},
},
sg_begin_pass(&(sg_pass){
.action = userdata->renderer.pass,
.swapchain = sglue_swapchain(),
});
sg_apply_pipeline(userdata->renderer.pipeline);
sg_apply_bindings(userdata->renderer.binding);
sg_apply_bindings(&userdata->renderer.binding);
sg_apply_uniforms(UB_vs_uniform, &userdata->renderer.uniform);
sg_apply_uniforms(UB_fs_uniform, &userdata->renderer.uniform);
@ -88,6 +88,7 @@ static void init(void* _userdata)
// Initialize Sokol GFX.
sg_desc sgdesc = {
.environment = sglue_environment(),
.logger.func = slog_func,
};
sg_setup(&sgdesc);
if (!sg_isvalid()) {
@ -112,9 +113,13 @@ static void init(void* _userdata)
void* tmp_buffer = malloc(sizeof(position_t) * SAMPLE_COUNT);
userdata->renderer = (renderer_t) {
.pass = (sg_pass_action) {
.colors[0] = { .clear_value = { 0.0f, 0.0f, 0.0f, 1.0f }, .load_action = SG_LOADACTION_CLEAR }
},
.pipeline = sg_make_pipeline(&(sg_pipeline_desc) {
.shader = sg_make_shader(base_shader_desc(sg_query_backend())),
.depth.write_enabled = true,
.index_type = SG_INDEXTYPE_UINT16,
.layout.attrs = {
[ATTR_base_in_quad].format = SG_VERTEXFORMAT_FLOAT2,
},
@ -123,9 +128,9 @@ static void init(void* _userdata)
.compute = true,
.shader = sg_make_shader(compute_shader_desc(sg_query_backend())),
}),*/
.binding = &(sg_bindings) {
.binding = (sg_bindings) {
.vertex_buffers = {
[0] = sg_make_buffer(&(sg_buffer_desc) {
[ATTR_base_in_quad] = sg_make_buffer(&(sg_buffer_desc) {
.type = SG_BUFFERTYPE_VERTEXBUFFER,
.data = SG_RANGE(quad),
}),
@ -144,7 +149,7 @@ static void init(void* _userdata)
}),
},
},
.uniform = &SG_RANGE(uniform),
.uniform = SG_RANGE(uniform),
};
userdata->pan = (position_t) { .x = 0, .y = 0 };
@ -213,6 +218,7 @@ sapp_desc sokol_main(int argc, char* argv[])
.cleanup_userdata_cb = cleanup,
.event_userdata_cb = event,
.window_title = "Sokol",
.logger.func = slog_func,
.allocator = {
.alloc_fn = smemtrack_alloc,
.free_fn = smemtrack_free,

View File

@ -44,10 +44,10 @@ layout(binding = 1) uniform fs_uniform {
float radius;
};
layout(location = 0) out vec4 frag_color;
layout(location = 1) in vec2 _quad;
layout(location = 2) in vec2 _centroid;
layout(location = 3) flat in vec3 _color;
layout(location = 4) out vec4 frag_color;
void main()
{