From 0a0a659eabbe28765aa8ee58bce7445979e821d4 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Wed, 9 Oct 2024 19:38:16 +0200 Subject: [PATCH] fix drawcallperf-sapp, but needs further fixes because of sokol_imgui.h --- wgpu/drawcallperf-wgpu.c | 94 +++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/wgpu/drawcallperf-wgpu.c b/wgpu/drawcallperf-wgpu.c index feab784c..2f61ee62 100644 --- a/wgpu/drawcallperf-wgpu.c +++ b/wgpu/drawcallperf-wgpu.c @@ -171,50 +171,64 @@ static void init(void) { .data.subimage[0][0] = SG_RANGE(pixels), }); } - state.bind.fs.samplers[0] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[0] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_NEAREST, .mag_filter = SG_FILTER_NEAREST, }); // a shader object sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks = { - [0].size = sizeof(vs_per_frame_t), - [1].size = sizeof(vs_per_instance_t), + .vertex_func.source = + "struct vs_per_frame {\n" + " viewproj: mat4x4f,\n" + "}\n" + "struct vs_per_instance {\n" + " world_pos: vec4f,\n" + "}\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) uv: vec2f,\n" + " @location(1) bright: f32,\n" + "}\n" + "@group(0) @binding(0) var per_frame: vs_per_frame;\n" + "@group(0) @binding(1) var per_instance: vs_per_instance;\n" + "@vertex fn main(@location(0) pos: vec3f, @location(1) uv: vec2f, @location(2) bright: f32) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = per_frame.viewproj * (per_instance.world_pos + vec4f(pos * 0.05, 1.0));\n" + " out.uv = uv;\n" + " out.bright = bright;\n" + " return out;\n" + "}\n", + .fragment_func.source = + "@group(1) @binding(0) var tex: texture_2d;\n" + "@group(1) @binding(1) var smp: sampler;\n" + "@fragment fn main(@location(0) uv: vec2f, @location(1) bright: f32) -> @location(0) vec4f {\n" + " return vec4f(textureSample(tex, smp, uv).xyz * bright, 1.0);\n" + "}\n", + .uniform_blocks = { + [0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_per_frame_t), + .wgsl_group0_binding_n = 0, }, - .source = - "struct vs_per_frame {\n" - " viewproj: mat4x4f,\n" - "}\n" - "struct vs_per_instance {\n" - " world_pos: vec4f,\n" - "}\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) uv: vec2f,\n" - " @location(1) bright: f32,\n" - "}\n" - "@group(0) @binding(0) var per_frame: vs_per_frame;\n" - "@group(0) @binding(1) var per_instance: vs_per_instance;\n" - "@vertex fn main(@location(0) pos: vec3f, @location(1) uv: vec2f, @location(2) bright: f32) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = per_frame.viewproj * (per_instance.world_pos + vec4f(pos * 0.05, 1.0));\n" - " out.uv = uv;\n" - " out.bright = bright;\n" - " return out;\n" - "}\n", + [1] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_per_instance_t), + .wgsl_group0_binding_n = 1, + } + }, + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 1, }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "@group(1) @binding(48) var tex: texture_2d;\n" - "@group(1) @binding(64) var smp: sampler;\n" - "@fragment fn main(@location(0) uv: vec2f, @location(1) bright: f32) -> @location(0) vec4f {\n" - " return vec4f(textureSample(tex, smp, uv).xyz * bright, 1.0);\n" - "}\n", + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0 }, }); @@ -295,10 +309,10 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = wgpu_swapchain() }); sg_apply_pipeline(state.pip); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_per_frame)); + sg_apply_uniforms(0, &SG_RANGE(vs_per_frame)); state.stats.num_uniform_updates++; - state.bind.fs.images[0] = state.img[0]; + state.bind.images[0] = state.img[0]; sg_apply_bindings(&state.bind); state.stats.num_binding_updates++; int cur_bind_count = 0; @@ -309,11 +323,11 @@ static void frame(void) { if (cur_img == NUM_IMAGES) { cur_img = 0; } - state.bind.fs.images[0] = state.img[cur_img++]; + state.bind.images[0] = state.img[cur_img++]; sg_apply_bindings(&state.bind); state.stats.num_binding_updates++; } - sg_apply_uniforms(SG_SHADERSTAGE_VS, 1, &SG_RANGE(positions[i])); + sg_apply_uniforms(1, &SG_RANGE(positions[i])); state.stats.num_uniform_updates++; sg_draw(0, 36, 1); state.stats.num_draw_calls++;