From 7a86b5de66fb509dd671fd6436ab2fdab61b2fa3 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 8 Sep 2024 10:35:50 +0200 Subject: [PATCH 01/36] start fixing cube-metal.c for bindings rework --- metal/cube-metal.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/metal/cube-metal.c b/metal/cube-metal.c index dba87d5d..9afa443c 100644 --- a/metal/cube-metal.c +++ b/metal/cube-metal.c @@ -84,8 +84,16 @@ static void init(void) { // a shader, note that Metal only needs to know uniform block sizes, but // not their internal layout sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.source = + .vertex_attrs = { + [0] = { .used = true, .msl_attribute_n = 0 }, + [1] = { .used = true, .msl_attribute_n = 1 }, + }, + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, + .vertex_function.source = "#include \n" "using namespace metal;\n" "struct params_t {\n" @@ -105,7 +113,7 @@ static void init(void) { " out.color = in.color;\n" " return out;\n" "}\n", - .fs.source = + .fragment_function.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" @@ -150,7 +158,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From 948c4f600fa9591b5d13a504fbc1c28a166cff8e Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Tue, 10 Sep 2024 14:26:41 +0200 Subject: [PATCH 02/36] fix metal/cube-metal.c --- metal/cube-metal.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/metal/cube-metal.c b/metal/cube-metal.c index 9afa443c..bbef535d 100644 --- a/metal/cube-metal.c +++ b/metal/cube-metal.c @@ -84,16 +84,12 @@ static void init(void) { // a shader, note that Metal only needs to know uniform block sizes, but // not their internal layout sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vertex_attrs = { - [0] = { .used = true, .msl_attribute_n = 0 }, - [1] = { .used = true, .msl_attribute_n = 1 }, - }, .uniform_blocks[0] = { .stage = SG_SHADERBINDSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, - .vertex_function.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct params_t {\n" @@ -113,7 +109,7 @@ static void init(void) { " out.color = in.color;\n" " return out;\n" "}\n", - .fragment_function.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" From 596d5af3e1a79a5856bf53f90a2c098d2d269bf0 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 14 Sep 2024 14:33:28 +0200 Subject: [PATCH 03/36] fix metal/texcube-metal.c --- metal/texcube-metal.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/metal/texcube-metal.c b/metal/texcube-metal.c index 4108bf8c..b439b776 100644 --- a/metal/texcube-metal.c +++ b/metal/texcube-metal.c @@ -89,22 +89,21 @@ static void init(void) { 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, }; - state.bind.fs.images[0] = sg_make_image(&(sg_image_desc){ + state.bind.images[0] = sg_make_image(&(sg_image_desc){ .width = 4, .height = 4, .data.subimage[0][0] = SG_RANGE(pixels) }); // ...and a sampler - 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 sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), + .vertex_func = { .entry = "vs_main", .source = "#include \n" @@ -130,10 +129,7 @@ static void init(void) { " return out;\n" "}\n" }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, + .fragment_func = { .entry = "fs_main", .source = "#include \n" @@ -148,7 +144,25 @@ static void init(void) { "{\n" " return float4(tex.sample(smp, in.uv).xyz, 1.0) * in.color;\n" "};\n" - } + }, + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, + .images[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_texture_n = 0 + }, + .samplers[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_sampler_n = 0 + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0 + }, }); // a pipeline state object @@ -187,7 +201,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From 1b93b864269b8a8e7fbe320c186c8aa7f6d87e89 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 14 Sep 2024 15:44:21 +0200 Subject: [PATCH 04/36] fix all metal samples except imgui-metal --- metal/arraytex-metal.c | 113 +++++++++++--------- metal/binshader-metal.c | 14 +-- metal/blend-metal.c | 28 +++-- metal/bufferoffsets-metal.c | 4 +- metal/dyntex-metal.c | 36 +++++-- metal/inject-metal.m | 50 +++++---- metal/instancing-metal.c | 14 ++- metal/mipmap-metal.c | 34 ++++-- metal/mrt-metal.c | 200 +++++++++++++++++------------------ metal/noninterleaved-metal.c | 14 ++- metal/offscreen-metal.c | 112 +++++++++++--------- metal/quad-metal.c | 4 +- metal/releasetest-metal.c | 4 +- metal/triangle-metal.c | 4 +- metal/vertexpulling-metal.c | 24 +++-- 15 files changed, 372 insertions(+), 283 deletions(-) diff --git a/metal/arraytex-metal.c b/metal/arraytex-metal.c index bdab755e..2a122baa 100644 --- a/metal/arraytex-metal.c +++ b/metal/arraytex-metal.c @@ -56,7 +56,7 @@ static void init(void) { } } } - state.bind.fs.images[0] = sg_make_image(&(sg_image_desc) { + state.bind.images[0] = sg_make_image(&(sg_image_desc) { .type = SG_IMAGETYPE_ARRAY, .width = IMG_WIDTH, .height = IMG_HEIGHT, @@ -64,7 +64,7 @@ static void init(void) { .pixel_format = SG_PIXELFORMAT_RGBA8, .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_LINEAR, .mag_filter = SG_FILTER_LINEAR, }); @@ -122,55 +122,66 @@ static void init(void) { // shader to sample from array texture sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "#include \n" - "using namespace metal;\n" - "struct params_t {\n" - " float4x4 mvp;\n" - " float2 offset0;\n" - " float2 offset1;\n" - " float2 offset2;\n" - "};\n" - "struct vs_in {\n" - " float4 pos [[attribute(0)]];\n" - " float2 uv [[attribute(1)]];\n" - "};\n" - "struct vs_out {\n" - " float4 pos [[position]];\n" - " float3 uv0;\n" - " float3 uv1;\n" - " float3 uv2;\n" - "};\n" - "vertex vs_out _main(vs_in in [[stage_in]], constant params_t& params [[buffer(0)]]) {\n" - " vs_out out;\n" - " out.pos = params.mvp * in.pos;\n" - " out.uv0 = float3(in.uv + params.offset0, 0.0);\n" - " out.uv1 = float3(in.uv + params.offset1, 1.0);\n" - " out.uv2 = float3(in.uv + params.offset2, 2.0);\n" - " return out;\n" - "}\n", + .vertex_func.source = + "#include \n" + "using namespace metal;\n" + "struct params_t {\n" + " float4x4 mvp;\n" + " float2 offset0;\n" + " float2 offset1;\n" + " float2 offset2;\n" + "};\n" + "struct vs_in {\n" + " float4 pos [[attribute(0)]];\n" + " float2 uv [[attribute(1)]];\n" + "};\n" + "struct vs_out {\n" + " float4 pos [[position]];\n" + " float3 uv0;\n" + " float3 uv1;\n" + " float3 uv2;\n" + "};\n" + "vertex vs_out _main(vs_in in [[stage_in]], constant params_t& params [[buffer(0)]]) {\n" + " vs_out out;\n" + " out.pos = params.mvp * in.pos;\n" + " out.uv0 = float3(in.uv + params.offset0, 0.0);\n" + " out.uv1 = float3(in.uv + params.offset1, 1.0);\n" + " out.uv2 = float3(in.uv + params.offset2, 2.0);\n" + " return out;\n" + "}\n", + .fragment_func.source = + "#include \n" + "using namespace metal;\n" + "struct fs_in {\n" + " float3 uv0;\n" + " float3 uv1;\n" + " float3 uv2;\n" + "};\n" + "fragment float4 _main(fs_in in [[stage_in]], texture2d_array tex [[texture(0)]], sampler smp [[sampler(0)]]) {\n" + " float4 c0 = tex.sample(smp, in.uv0.xy, int(in.uv0.z));\n" + " float4 c1 = tex.sample(smp, in.uv1.xy, int(in.uv1.z));\n" + " float4 c2 = tex.sample(smp, in.uv2.xy, int(in.uv2.z));\n" + " return float4(c0.xyz + c1.xyz + c2.xyz, 1.0);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, + .images[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .image_type = SG_IMAGETYPE_ARRAY, + .msl_texture_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_sampler_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, - .fs = { - .images[0] = { .used = true, .image_type = SG_IMAGETYPE_ARRAY }, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "#include \n" - "using namespace metal;\n" - "struct fs_in {\n" - " float3 uv0;\n" - " float3 uv1;\n" - " float3 uv2;\n" - "};\n" - "fragment float4 _main(fs_in in [[stage_in]], texture2d_array tex [[texture(0)]], sampler smp [[sampler(0)]]) {\n" - " float4 c0 = tex.sample(smp, in.uv0.xy, int(in.uv0.z));\n" - " float4 c1 = tex.sample(smp, in.uv1.xy, int(in.uv1.z));\n" - " float4 c2 = tex.sample(smp, in.uv2.xy, int(in.uv2.z));\n" - " return float4(c0.xyz + c1.xyz + c2.xyz, 1.0);\n" - "}\n" - } }); // a pipeline object @@ -222,7 +233,7 @@ static void frame() { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/metal/binshader-metal.c b/metal/binshader-metal.c index d8374c5b..f81aa272 100644 --- a/metal/binshader-metal.c +++ b/metal/binshader-metal.c @@ -88,13 +88,13 @@ static void init(void) { /* shader as precompiled metal lib */ sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .bytecode = SG_RANGE(vs_bytecode) + .vertex_func.bytecode = SG_RANGE(vs_bytecode), + .fragment_func.bytecode = SG_RANGE(fs_bytecode), + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, }, - .fs = { - .bytecode = SG_RANGE(fs_bytecode) - } }); /* pipeline object for rendering the cube */ @@ -132,7 +132,7 @@ static void frame() { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/metal/blend-metal.c b/metal/blend-metal.c index 1d2f15c0..13929a8f 100644 --- a/metal/blend-metal.c +++ b/metal/blend-metal.c @@ -62,7 +62,7 @@ static void init(void) { // a shader for the fullscreen background quad sg_shader bg_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { + .vertex_func = { .entry = "vs_main", .source = "#include \n" @@ -79,8 +79,7 @@ static void init(void) { " return out;\n" "};\n" }, - .fs = { - .uniform_blocks[0].size = sizeof(fs_params_t), + .fragment_func = { .entry = "fs_main", .source = "#include \n" @@ -92,7 +91,12 @@ static void init(void) { " float2 xy = fract((frag_coord.xy-float2(params.tick)) / 50.0);\n" " return float4(float3(xy.x*xy.y), 1.0);\n" "}\n" - } + }, + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .size = sizeof(fs_params_t), + .msl_buffer_n = 0, + }, }); // a pipeline state object for rendering the background quad @@ -112,8 +116,7 @@ static void init(void) { // a shader for the blended quads sg_shader quad_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), + .vertex_func = { .entry = "vs_main", .source = "#include \n" @@ -136,7 +139,7 @@ static void init(void) { " return out;\n" "}\n" }, - .fs = { + .fragment_func = { .entry = "fs_main", .source = "#include \n" @@ -147,7 +150,12 @@ static void init(void) { "fragment float4 fs_main(fs_in in [[stage_in]]) {\n" " return in.color;\n" "};\n" - } + }, + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, }); // one pipeline object per blend-factor combination @@ -188,7 +196,7 @@ static void frame(void) { /* draw a background quad */ sg_apply_pipeline(state.bg_pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, &SG_RANGE(state.fs_params)); + sg_apply_uniforms(0, &SG_RANGE(state.fs_params)); sg_draw(0, 4, 1); // draw the blended quads @@ -204,7 +212,7 @@ static void frame(void) { sg_apply_pipeline(state.pips[src][dst]); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(state.vs_params)); + sg_apply_uniforms(0, &SG_RANGE(state.vs_params)); sg_draw(0, 4, 1); } } diff --git a/metal/bufferoffsets-metal.c b/metal/bufferoffsets-metal.c index 752fe949..a3f40401 100644 --- a/metal/bufferoffsets-metal.c +++ b/metal/bufferoffsets-metal.c @@ -56,7 +56,7 @@ static void init(void) { // a shader and pipeline to render 2D shapes sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct vs_in {\n" @@ -73,7 +73,7 @@ static void init(void) { " out.color = float4(in.color, 1.0);\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" diff --git a/metal/dyntex-metal.c b/metal/dyntex-metal.c index 3f822452..d85f42f0 100644 --- a/metal/dyntex-metal.c +++ b/metal/dyntex-metal.c @@ -42,13 +42,13 @@ static void init(void) { }); // a 128x128 image with streaming update strategy - state.bind.fs.images[0] = sg_make_image(&(sg_image_desc){ + state.bind.images[0] = sg_make_image(&(sg_image_desc){ .width = IMAGE_WIDTH, .height = IMAGE_HEIGHT, .pixel_format = SG_PIXELFORMAT_RGBA8, .usage = SG_USAGE_STREAM, }); - 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_LINEAR, .mag_filter = SG_FILTER_LINEAR, .wrap_u = SG_WRAP_CLAMP_TO_EDGE, @@ -106,8 +106,7 @@ static void init(void) { // a shader to render a textured cube sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct params_t {\n" @@ -130,10 +129,7 @@ static void init(void) { " out.uv = in.uv;\n" " return out;\n" "}\n", - .fs.images[0].used = true, - .fs.samplers[0].used = true, - .fs.image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "struct fs_in {\n" @@ -142,7 +138,25 @@ static void init(void) { "};\n" "fragment float4 _main(fs_in in [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) {\n" " return float4(tex.sample(smp, in.uv).xyz, 1.0) * in.color;\n" - "};\n" + "};\n", + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, + .images[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_texture_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_sampler_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, + }, }); // a pipeline state object @@ -185,7 +199,7 @@ static void frame(void) { game_of_life_update(); // update the texture - sg_update_image(state.bind.fs.images[0], &(sg_image_data){ + sg_update_image(state.bind.images[0], &(sg_image_data){ .subimage[0][0] = SG_RANGE(state.pixels) }); @@ -193,7 +207,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/metal/inject-metal.m b/metal/inject-metal.m index ec97a5fa..53145515 100644 --- a/metal/inject-metal.m +++ b/metal/inject-metal.m @@ -133,9 +133,9 @@ static void init(void) { } sg_reset_state_cache(); - state.bind.fs.images[0] = sg_make_image(&img_desc); - assert(((__bridge id) sg_mtl_query_image_info(state.bind.fs.images[0]).tex[0]) == mtl_tex[0]); - assert(((__bridge id) sg_mtl_query_image_info(state.bind.fs.images[0]).tex[1]) == mtl_tex[1]); + state.bind.images[0] = sg_make_image(&img_desc); + assert(((__bridge id) sg_mtl_query_image_info(state.bind.images[0]).tex[0]) == mtl_tex[0]); + assert(((__bridge id) sg_mtl_query_image_info(state.bind.images[0]).tex[1]) == mtl_tex[1]); // create a Metal sampler object and inject into a sokol-gfx sampler object MTLSamplerDescriptor* mtl_smp_desc = [[MTLSamplerDescriptor alloc] init]; @@ -153,13 +153,12 @@ static void init(void) { .mtl_sampler = mtl_smp, }; sg_reset_state_cache(); - state.bind.fs.samplers[0] = sg_make_sampler(&smp_desc); - assert(((__bridge id) sg_mtl_query_sampler_info(state.bind.fs.samplers[0]).smp) == mtl_smp); + state.bind.samplers[0] = sg_make_sampler(&smp_desc); + assert(((__bridge id) sg_mtl_query_sampler_info(state.bind.samplers[0]).smp) == mtl_smp); // a shader const sg_shader_desc shader_desc = { - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), + .vertex_func = { .entry = "vs_main", .source = "#include \n" @@ -182,10 +181,7 @@ static void init(void) { " return out;\n" "}\n" }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, + .fragment_func = { .entry = "fs_main", .source = "#include \n" @@ -199,13 +195,31 @@ static void init(void) { "{\n" " return float4(tex.sample(smp, in.uv).xyz, 1.0);\n" "};\n" - } + }, + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, + .images[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_texture_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_sampler_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, + }, }; sg_shader shd = sg_make_shader(&shader_desc); - assert(((__bridge id) sg_mtl_query_shader_info(shd).vs_lib) != nil); - assert(((__bridge id) sg_mtl_query_shader_info(shd).fs_lib) != nil); - assert(((__bridge id) sg_mtl_query_shader_info(shd).vs_func) != nil); - assert(((__bridge id) sg_mtl_query_shader_info(shd).fs_func) != nil); + assert(((__bridge id) sg_mtl_query_shader_info(shd).vertex_lib) != nil); + assert(((__bridge id) sg_mtl_query_shader_info(shd).fragment_lib) != nil); + assert(((__bridge id) sg_mtl_query_shader_info(shd).vertex_func) != nil); + assert(((__bridge id) sg_mtl_query_shader_info(shd).fragment_func) != nil); // a pipeline state object const sg_pipeline_desc pip_desc = { @@ -253,12 +267,12 @@ static void frame(void) { } } state.counter++; - sg_update_image(state.bind.fs.images[0], &(sg_image_data){ .subimage[0][0] = SG_RANGE(state.pixels) }); + sg_update_image(state.bind.images[0], &(sg_image_data){ .subimage[0][0] = SG_RANGE(state.pixels) }); sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/metal/instancing-metal.c b/metal/instancing-metal.c index 8c3761c7..ac7d9700 100644 --- a/metal/instancing-metal.c +++ b/metal/instancing-metal.c @@ -79,8 +79,7 @@ static void init(void) { // a shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct params_t {\n" @@ -102,12 +101,17 @@ static void init(void) { " out.color = in.color;\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" " return color;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, }); // a pipeline object @@ -182,7 +186,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 24, state.cur_num_particles); sg_end_pass(); sg_commit(); diff --git a/metal/mipmap-metal.c b/metal/mipmap-metal.c index 91f041e3..d7d76690 100644 --- a/metal/mipmap-metal.c +++ b/metal/mipmap-metal.c @@ -142,8 +142,7 @@ static void init(void) { // shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), + .vertex_func = { .entry = "vs_main", .source = "#include \n" @@ -166,10 +165,7 @@ static void init(void) { " return out;\n" "}\n" }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, + .fragment_func = { .entry = "fs_main", .source = "#include \n" @@ -183,7 +179,25 @@ static void init(void) { "{\n" " return float4(tex.sample(smp, in.uv).xyz, 1.0);\n" "};\n" - } + }, + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, + .images[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_texture_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_sampler_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, + }, }); // pipeline state @@ -211,7 +225,7 @@ static void frame(void) { sg_bindings bind = { .vertex_buffers[0] = state.vbuf, - .fs.images[0] = state.img, + .images[0] = state.img, }; sg_begin_pass(&(sg_pass){ .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); @@ -220,9 +234,9 @@ static void frame(void) { const float y = ((float)(i / 4) - 1.0f) * -2.0f; hmm_mat4 model = HMM_MultiplyMat4(HMM_Translate(HMM_Vec3(x, y, 0.0f)), rm); vs_params.mvp = HMM_MultiplyMat4(state.view_proj, model); - bind.fs.samplers[0] = state.smp[i]; + bind.samplers[0] = state.smp[i]; sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } sg_end_pass(); diff --git a/metal/mrt-metal.c b/metal/mrt-metal.c index fd4de7e4..6bddb159 100644 --- a/metal/mrt-metal.c +++ b/metal/mrt-metal.c @@ -148,8 +148,7 @@ static void init(void) { // a shader to render the cube into offscreen MRT render targest sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0].size = sizeof(offscreen_params_t), - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct params_t {\n" @@ -169,7 +168,7 @@ static void init(void) { " out.bright = in.bright;\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "struct fs_out {\n" @@ -183,7 +182,12 @@ static void init(void) { " out.color1 = float4(0.0, bright, 0.0, 1.0);\n" " out.color2 = float4(0.0, 0.0, bright, 1.0);\n" " return out;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(offscreen_params_t), + .msl_buffer_n = 0, + }, }); // pipeline object for the offscreen-rendered cube @@ -223,75 +227,75 @@ static void init(void) { // a shader to render a fullscreen rectangle by adding the 3 offscreen-rendered images sg_shader fsq_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(params_t), - .source = - "#include \n" - "using namespace metal;\n" - "struct params_t {\n" - " float2 offset;\n" - "};\n" - "struct vs_in {\n" - " float2 pos [[attribute(0)]];\n" - "};\n" - "struct vs_out {\n" - " float4 pos [[position]];\n" - " float2 uv0;\n" - " float2 uv1;\n" - " float2 uv2;\n" - "};\n" - "vertex vs_out _main(vs_in in [[stage_in]], constant params_t& params [[buffer(0)]]) {\n" - " vs_out out;\n" - " out.pos = float4(in.pos*2.0-1.0, 0.5, 1.0);\n" - " out.uv0 = in.pos + float2(params.offset.x, 0.0);\n" - " out.uv1 = in.pos + float2(0.0, params.offset.y);\n" - " out.uv2 = in.pos;\n" - " return out;\n" - "}\n" + .vertex_func.source = + "#include \n" + "using namespace metal;\n" + "struct params_t {\n" + " float2 offset;\n" + "};\n" + "struct vs_in {\n" + " float2 pos [[attribute(0)]];\n" + "};\n" + "struct vs_out {\n" + " float4 pos [[position]];\n" + " float2 uv0;\n" + " float2 uv1;\n" + " float2 uv2;\n" + "};\n" + "vertex vs_out _main(vs_in in [[stage_in]], constant params_t& params [[buffer(0)]]) {\n" + " vs_out out;\n" + " out.pos = float4(in.pos*2.0-1.0, 0.5, 1.0);\n" + " out.uv0 = in.pos + float2(params.offset.x, 0.0);\n" + " out.uv1 = in.pos + float2(0.0, params.offset.y);\n" + " out.uv2 = in.pos;\n" + " return out;\n" + "}\n", + .fragment_func.source = + "#include \n" + "using namespace metal;\n" + "struct fs_in {\n" + " float2 uv0;\n" + " float2 uv1;\n" + " float2 uv2;\n" + "};\n" + "fragment float4 _main(fs_in in [[stage_in]],\n" + " texture2d tex0 [[texture(0)]],\n" + " texture2d tex1 [[texture(1)]],\n" + " texture2d tex2 [[texture(2)]],\n" + " sampler smp [[sampler(0)]])\n" + "{\n" + " float3 c0 = tex0.sample(smp, in.uv0).xyz;\n" + " float3 c1 = tex1.sample(smp, in.uv1).xyz;\n" + " float3 c2 = tex2.sample(smp, in.uv2).xyz;\n" + " return float4(c0 + c1 + c2, 1.0);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(params_t), + .msl_buffer_n = 0, + }, + .images = { + [0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_texture_n = 0 }, + [1] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_texture_n = 1 }, + [2] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_texture_n = 2 }, + }, + .samplers = { + [0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_sampler_n = 0 }, + }, + .image_sampler_pairs = { + [0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, + [1] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .image_slot = 1, .sampler_slot = 0 }, + [2] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .image_slot = 2, .sampler_slot = 0 }, }, - .fs = { - .images = { - [0].used = true, - [1].used = true, - [2].used = true, - }, - .samplers[0].used = true, - .image_sampler_pairs = { - [0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - [1] = { .used = true, .image_slot = 1, .sampler_slot = 0 }, - [2] = { .used = true, .image_slot = 2, .sampler_slot = 0 }, - }, - .source = - "#include \n" - "using namespace metal;\n" - "struct fs_in {\n" - " float2 uv0;\n" - " float2 uv1;\n" - " float2 uv2;\n" - "};\n" - "fragment float4 _main(fs_in in [[stage_in]],\n" - " texture2d tex0 [[texture(0)]],\n" - " texture2d tex1 [[texture(1)]],\n" - " texture2d tex2 [[texture(2)]],\n" - " sampler smp [[sampler(0)]])\n" - "{\n" - " float3 c0 = tex0.sample(smp, in.uv0).xyz;\n" - " float3 c1 = tex1.sample(smp, in.uv1).xyz;\n" - " float3 c2 = tex2.sample(smp, in.uv2).xyz;\n" - " return float4(c0 + c1 + c2, 1.0);\n" - "}\n" - } }); // setup resource binding struct for rendering fullscreen quad state.fsq_bind = (sg_bindings) { .vertex_buffers[0] = quad_vbuf, - .fs = { - .images[0] = state.offscreen_attachments_desc.resolves[0].image, - .images[1] = state.offscreen_attachments_desc.resolves[1].image, - .images[2] = state.offscreen_attachments_desc.resolves[2].image, - .samplers[0] = smp - } + .images[0] = state.offscreen_attachments_desc.resolves[0].image, + .images[1] = state.offscreen_attachments_desc.resolves[1].image, + .images[2] = state.offscreen_attachments_desc.resolves[2].image, + .samplers[0] = smp, }; // the pipeline object to render the fullscreen quad @@ -311,41 +315,37 @@ static void init(void) { }, .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, .shader = sg_make_shader(&(sg_shader_desc){ - .vs = { - .source = - "#include \n" - "using namespace metal;\n" - "struct vs_in {\n" - " float2 pos [[attribute(0)]];\n" - "};\n" - "struct vs_out {\n" - " float4 pos [[position]];\n" - " float2 uv;\n" - "};\n" - "vertex vs_out _main(vs_in in [[stage_in]]) {\n" - " vs_out out;\n" - " out.pos = float4(in.pos*2.0-1.0, 0.5, 1.0);\n" - " out.uv = in.pos;\n" - " return out;\n" - "}\n", - }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "#include \n" - "using namespace metal;\n" - "fragment float4 _main(float2 uv [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) {\n" - " return float4(tex.sample(smp, uv).xyz, 1.0);\n" - "}\n" - } + .vertex_func.source = + "#include \n" + "using namespace metal;\n" + "struct vs_in {\n" + " float2 pos [[attribute(0)]];\n" + "};\n" + "struct vs_out {\n" + " float4 pos [[position]];\n" + " float2 uv;\n" + "};\n" + "vertex vs_out _main(vs_in in [[stage_in]]) {\n" + " vs_out out;\n" + " out.pos = float4(in.pos*2.0-1.0, 0.5, 1.0);\n" + " out.uv = in.pos;\n" + " return out;\n" + "}\n", + .fragment_func.source = + "#include \n" + "using namespace metal;\n" + "fragment float4 _main(float2 uv [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) {\n" + " return float4(tex.sample(smp, uv).xyz, 1.0);\n" + "}\n", + .images[0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_texture_n = 0 }, + .samplers[0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_sampler_n = 0 }, + .image_sampler_pairs[0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, }), }); // images will be filled right before rendering state.dbg_bind = (sg_bindings){ .vertex_buffers[0] = quad_vbuf, - .fs.samplers[0] = smp, + .samplers[0] = smp, }; // default pass action, no clear needed, since whole screen is overwritten @@ -378,7 +378,7 @@ static void frame(void) { }); sg_apply_pipeline(state.offscreen_pip); sg_apply_bindings(&state.offscreen_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(offscreen_params)); + sg_apply_uniforms(0, &SG_RANGE(offscreen_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -389,14 +389,14 @@ static void frame(void) { }); sg_apply_pipeline(state.fsq_pip); sg_apply_bindings(&state.fsq_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(params)); + sg_apply_uniforms(0, &SG_RANGE(params)); sg_draw(0, 4, 1); // render the small debug quads sg_apply_pipeline(state.dbg_pip); for (int i = 0; i < 3; i++) { sg_apply_viewport(i*100, 0, 100, 100, false); - state.dbg_bind.fs.images[0] = state.offscreen_attachments_desc.resolves[i].image; + state.dbg_bind.images[0] = state.offscreen_attachments_desc.resolves[i].image; sg_apply_bindings(&state.dbg_bind); sg_draw(0, 4, 1); } diff --git a/metal/noninterleaved-metal.c b/metal/noninterleaved-metal.c index 064d55d5..ddbfde06 100644 --- a/metal/noninterleaved-metal.c +++ b/metal/noninterleaved-metal.c @@ -75,8 +75,7 @@ static void init(void) { // a shader, note that Metal only needs to know uniform block sizes, but // not their internal layout sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct params_t {\n" @@ -96,12 +95,17 @@ static void init(void) { " out.color = in.color;\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" " return color;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, }); // a pipeline object @@ -158,7 +162,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/metal/offscreen-metal.c b/metal/offscreen-metal.c index f3976321..bf38edae 100644 --- a/metal/offscreen-metal.c +++ b/metal/offscreen-metal.c @@ -144,16 +144,13 @@ static void init(void) { state.default_bind = (sg_bindings){ .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs= { - .images[0] = resolve_img, - .samplers[0] = resolve_smp, - } + .images[0] = resolve_img, + .samplers[0] = resolve_smp, }; // a shader for a non-textured cube, rendered in the offscreen pass sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct params_t {\n" @@ -173,58 +170,73 @@ static void init(void) { " out.color = in.color;\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" " return color;\n" - "};\n" + "};\n", + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, }); // ...and another shader for the display-pass, rendering a textured cube // using the offscreen render target as texture */ sg_shader default_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "#include \n" - "using namespace metal;\n" - "struct params_t {\n" - " float4x4 mvp;\n" - "};\n" - "struct vs_in {\n" - " float4 position [[attribute(0)]];\n" - " float4 color [[attribute(1)]];\n" - " float2 uv [[attribute(2)]];\n" - "};\n" - "struct vs_out {\n" - " float4 pos [[position]];\n" - " float4 color;\n" - " float2 uv;\n" - "};\n" - "vertex vs_out _main(vs_in in [[stage_in]], constant params_t& params [[buffer(0)]]) {\n" - " vs_out out;\n" - " out.pos = params.mvp * in.position;\n" - " out.color = in.color;\n" - " out.uv = in.uv;\n" - " return out;\n" - "}\n", + .vertex_func.source = + "#include \n" + "using namespace metal;\n" + "struct params_t {\n" + " float4x4 mvp;\n" + "};\n" + "struct vs_in {\n" + " float4 position [[attribute(0)]];\n" + " float4 color [[attribute(1)]];\n" + " float2 uv [[attribute(2)]];\n" + "};\n" + "struct vs_out {\n" + " float4 pos [[position]];\n" + " float4 color;\n" + " float2 uv;\n" + "};\n" + "vertex vs_out _main(vs_in in [[stage_in]], constant params_t& params [[buffer(0)]]) {\n" + " vs_out out;\n" + " out.pos = params.mvp * in.position;\n" + " out.color = in.color;\n" + " out.uv = in.uv;\n" + " return out;\n" + "}\n", + .fragment_func.source = + "#include \n" + "using namespace metal;\n" + "struct fs_in {\n" + " float4 color;\n" + " float2 uv;\n" + "};\n" + "fragment float4 _main(fs_in in [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) {\n" + " return float4(tex.sample(smp, in.uv).xyz + in.color.xyz * 0.5, 1.0);\n" + "};\n", + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, + .images[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_texture_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .msl_sampler_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "#include \n" - "using namespace metal;\n" - "struct fs_in {\n" - " float4 color;\n" - " float2 uv;\n" - "};\n" - "fragment float4 _main(fs_in in [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) {\n" - " return float4(tex.sample(smp, in.uv).xyz + in.color.xyz * 0.5, 1.0);\n" - "};\n" - } }); // pipeline-state-object for offscreen-rendered cube, don't need texture coord here @@ -291,7 +303,7 @@ static void frame(void) { }); sg_apply_pipeline(state.offscreen_pip); sg_apply_bindings(&state.offscreen_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -303,7 +315,7 @@ static void frame(void) { }); sg_apply_pipeline(state.default_pip); sg_apply_bindings(&state.default_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); diff --git a/metal/quad-metal.c b/metal/quad-metal.c index 741c00dd..f7b90ad2 100644 --- a/metal/quad-metal.c +++ b/metal/quad-metal.c @@ -39,7 +39,7 @@ static void init(void) { // a shader (use separate shader sources here sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct vs_in {\n" @@ -56,7 +56,7 @@ static void init(void) { " out.color = in.color;\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "#include \n" "using namespace metal;\n" diff --git a/metal/releasetest-metal.c b/metal/releasetest-metal.c index 39f67f40..d97e5641 100644 --- a/metal/releasetest-metal.c +++ b/metal/releasetest-metal.c @@ -50,7 +50,7 @@ static void frame(void) { default function. This can be override with the sg_shader_desc.vs.entry and sg_shader_desc.fs.entry fields. */ - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct vs_in {\n" @@ -67,7 +67,7 @@ static void frame(void) { " outp.color = inp.color;\n" " return outp;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" diff --git a/metal/triangle-metal.c b/metal/triangle-metal.c index d1bc96b2..d0bdd4b3 100644 --- a/metal/triangle-metal.c +++ b/metal/triangle-metal.c @@ -37,7 +37,7 @@ static void init(void) { default function. This can be override with the sg_shader_desc.vs.entry and sg_shader_desc.fs.entry fields. */ - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct vs_in {\n" @@ -54,7 +54,7 @@ static void init(void) { " outp.color = inp.color;\n" " return outp;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" diff --git a/metal/vertexpulling-metal.c b/metal/vertexpulling-metal.c index 58ffb010..f6befd5b 100644 --- a/metal/vertexpulling-metal.c +++ b/metal/vertexpulling-metal.c @@ -67,7 +67,7 @@ static void init(void) { { .pos = { 1.0, 1.0, 1.0, 1.0 }, .color = { 1.0, 0.0, 0.5, 1.0 } }, { .pos = { 1.0, 1.0, -1.0, 1.0 }, .color = { 1.0, 0.0, 0.5, 1.0 } } }; - state.bind.vs.storage_buffers[0] = sg_make_buffer(&(sg_buffer_desc){ + state.bind.storage_buffers[0] = sg_make_buffer(&(sg_buffer_desc){ .type = SG_BUFFERTYPE_STORAGEBUFFER, .data = SG_RANGE(vertices), }); @@ -86,9 +86,7 @@ static void init(void) { }); sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.storage_buffers[0] = { .used = true, .readonly = true }, - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct params_t {\n" @@ -105,18 +103,28 @@ static void init(void) { " float4 pos [[position]];\n" " float4 color;\n" "};\n" - "vertex vs_out _main(constant params_t& params [[buffer(0)]], const device ssbo_t& ssbo [[buffer(12)]], uint vidx [[vertex_id]]) {\n" + "vertex vs_out _main(constant params_t& params [[buffer(0)]], const device ssbo_t& ssbo [[buffer(1)]], uint vidx [[vertex_id]]) {\n" " vs_out out;\n" " out.pos = params.mvp * ssbo.vtx[vidx].pos;\n" " out.color = ssbo.vtx[vidx].color;\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" " return color;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .msl_buffer_n = 0, + }, + .storage_buffers[0] = { + .stage = SG_SHADERBINDSTAGE_VERTEX, + .readonly = true, + .msl_buffer_n = 1, + }, }); state.pip = sg_make_pipeline(&(sg_pipeline_desc){ @@ -145,7 +153,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = osx_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From cb6681c0f05854a4e89f5f279bee0cb3c62a299c Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 14 Sep 2024 17:09:06 +0200 Subject: [PATCH 05/36] sg_shader_bind_stage => sg_shader_stage --- metal/arraytex-metal.c | 8 ++++---- metal/binshader-metal.c | 2 +- metal/blend-metal.c | 4 ++-- metal/cube-metal.c | 2 +- metal/dyntex-metal.c | 8 ++++---- metal/inject-metal.m | 8 ++++---- metal/instancing-metal.c | 2 +- metal/mipmap-metal.c | 8 ++++---- metal/mrt-metal.c | 24 ++++++++++++------------ metal/noninterleaved-metal.c | 2 +- metal/offscreen-metal.c | 10 +++++----- metal/texcube-metal.c | 8 ++++---- metal/vertexpulling-metal.c | 4 ++-- 13 files changed, 45 insertions(+), 45 deletions(-) diff --git a/metal/arraytex-metal.c b/metal/arraytex-metal.c index 2a122baa..0510425b 100644 --- a/metal/arraytex-metal.c +++ b/metal/arraytex-metal.c @@ -164,21 +164,21 @@ static void init(void) { " return float4(c0.xyz + c1.xyz + c2.xyz, 1.0);\n" "}\n", .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, .images[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .image_type = SG_IMAGETYPE_ARRAY, .msl_texture_n = 0, }, .samplers[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_sampler_n = 0, }, .image_sampler_pairs[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0, }, diff --git a/metal/binshader-metal.c b/metal/binshader-metal.c index f81aa272..67bd48ff 100644 --- a/metal/binshader-metal.c +++ b/metal/binshader-metal.c @@ -91,7 +91,7 @@ static void init(void) { .vertex_func.bytecode = SG_RANGE(vs_bytecode), .fragment_func.bytecode = SG_RANGE(fs_bytecode), .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, diff --git a/metal/blend-metal.c b/metal/blend-metal.c index 13929a8f..5dc33ae4 100644 --- a/metal/blend-metal.c +++ b/metal/blend-metal.c @@ -93,7 +93,7 @@ static void init(void) { "}\n" }, .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .size = sizeof(fs_params_t), .msl_buffer_n = 0, }, @@ -152,7 +152,7 @@ static void init(void) { "};\n" }, .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, diff --git a/metal/cube-metal.c b/metal/cube-metal.c index bbef535d..4b318f94 100644 --- a/metal/cube-metal.c +++ b/metal/cube-metal.c @@ -85,7 +85,7 @@ static void init(void) { // not their internal layout sg_shader shd = sg_make_shader(&(sg_shader_desc){ .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, diff --git a/metal/dyntex-metal.c b/metal/dyntex-metal.c index d85f42f0..43fbff75 100644 --- a/metal/dyntex-metal.c +++ b/metal/dyntex-metal.c @@ -140,20 +140,20 @@ static void init(void) { " return float4(tex.sample(smp, in.uv).xyz, 1.0) * in.color;\n" "};\n", .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, .images[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_texture_n = 0, }, .samplers[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_sampler_n = 0, }, .image_sampler_pairs[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0, }, diff --git a/metal/inject-metal.m b/metal/inject-metal.m index 53145515..8882ee57 100644 --- a/metal/inject-metal.m +++ b/metal/inject-metal.m @@ -197,20 +197,20 @@ static void init(void) { "};\n" }, .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, .images[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_texture_n = 0, }, .samplers[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_sampler_n = 0, }, .image_sampler_pairs[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0, }, diff --git a/metal/instancing-metal.c b/metal/instancing-metal.c index ac7d9700..4d92b6d2 100644 --- a/metal/instancing-metal.c +++ b/metal/instancing-metal.c @@ -108,7 +108,7 @@ static void init(void) { " return color;\n" "}\n", .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, diff --git a/metal/mipmap-metal.c b/metal/mipmap-metal.c index d7d76690..2bb2f388 100644 --- a/metal/mipmap-metal.c +++ b/metal/mipmap-metal.c @@ -181,20 +181,20 @@ static void init(void) { "};\n" }, .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, .images[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_texture_n = 0, }, .samplers[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_sampler_n = 0, }, .image_sampler_pairs[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0, }, diff --git a/metal/mrt-metal.c b/metal/mrt-metal.c index 6bddb159..12af407b 100644 --- a/metal/mrt-metal.c +++ b/metal/mrt-metal.c @@ -184,7 +184,7 @@ static void init(void) { " return out;\n" "}\n", .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(offscreen_params_t), .msl_buffer_n = 0, }, @@ -270,22 +270,22 @@ static void init(void) { " return float4(c0 + c1 + c2, 1.0);\n" "}\n", .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(params_t), .msl_buffer_n = 0, }, .images = { - [0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_texture_n = 0 }, - [1] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_texture_n = 1 }, - [2] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_texture_n = 2 }, + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .msl_texture_n = 0 }, + [1] = { .stage = SG_SHADERSTAGE_FRAGMENT, .msl_texture_n = 1 }, + [2] = { .stage = SG_SHADERSTAGE_FRAGMENT, .msl_texture_n = 2 }, }, .samplers = { - [0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_sampler_n = 0 }, + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .msl_sampler_n = 0 }, }, .image_sampler_pairs = { - [0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, - [1] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .image_slot = 1, .sampler_slot = 0 }, - [2] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .image_slot = 2, .sampler_slot = 0 }, + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, + [1] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 1, .sampler_slot = 0 }, + [2] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 2, .sampler_slot = 0 }, }, }); @@ -337,9 +337,9 @@ static void init(void) { "fragment float4 _main(float2 uv [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) {\n" " return float4(tex.sample(smp, uv).xyz, 1.0);\n" "}\n", - .images[0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_texture_n = 0 }, - .samplers[0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .msl_sampler_n = 0 }, - .image_sampler_pairs[0] = { .stage = SG_SHADERBINDSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, + .images[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .msl_texture_n = 0 }, + .samplers[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .msl_sampler_n = 0 }, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, }), }); // images will be filled right before rendering diff --git a/metal/noninterleaved-metal.c b/metal/noninterleaved-metal.c index ddbfde06..1cf0cc5b 100644 --- a/metal/noninterleaved-metal.c +++ b/metal/noninterleaved-metal.c @@ -102,7 +102,7 @@ static void init(void) { " return color;\n" "}\n", .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, diff --git a/metal/offscreen-metal.c b/metal/offscreen-metal.c index bf38edae..3fdc0650 100644 --- a/metal/offscreen-metal.c +++ b/metal/offscreen-metal.c @@ -177,7 +177,7 @@ static void init(void) { " return color;\n" "};\n", .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, @@ -220,20 +220,20 @@ static void init(void) { " return float4(tex.sample(smp, in.uv).xyz + in.color.xyz * 0.5, 1.0);\n" "};\n", .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, .images[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_texture_n = 0, }, .samplers[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_sampler_n = 0, }, .image_sampler_pairs[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0, }, diff --git a/metal/texcube-metal.c b/metal/texcube-metal.c index b439b776..4c386854 100644 --- a/metal/texcube-metal.c +++ b/metal/texcube-metal.c @@ -146,20 +146,20 @@ static void init(void) { "};\n" }, .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, .images[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_texture_n = 0 }, .samplers[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .msl_sampler_n = 0 }, .image_sampler_pairs[0] = { - .stage = SG_SHADERBINDSTAGE_FRAGMENT, + .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, diff --git a/metal/vertexpulling-metal.c b/metal/vertexpulling-metal.c index f6befd5b..81dbb471 100644 --- a/metal/vertexpulling-metal.c +++ b/metal/vertexpulling-metal.c @@ -116,12 +116,12 @@ static void init(void) { " return color;\n" "}\n", .uniform_blocks[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(vs_params_t), .msl_buffer_n = 0, }, .storage_buffers[0] = { - .stage = SG_SHADERBINDSTAGE_VERTEX, + .stage = SG_SHADERSTAGE_VERTEX, .readonly = true, .msl_buffer_n = 1, }, From a7aa05fc0174d52271ab4e1d8d2a501a96cb308a Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 15 Sep 2024 17:52:14 +0200 Subject: [PATCH 06/36] fix cube-d3d11 for bindings cleanup --- d3d11/cube-d3d11.c | 58 ++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/d3d11/cube-d3d11.c b/d3d11/cube-d3d11.c index ad144825..d305ae11 100644 --- a/d3d11/cube-d3d11.c +++ b/d3d11/cube-d3d11.c @@ -86,35 +86,37 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0] = { .sem_name = "POSITION" }, - [1] = { .sem_name = "COLOR", .sem_index=1 } - }, - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "cbuffer params: register(b0) {\n" - " float4x4 mvp;\n" - "};\n" - "struct vs_in {\n" - " float4 pos: POSITION;\n" - " float4 color: COLOR1;\n" - "};\n" - "struct vs_out {\n" - " float4 color: COLOR0;\n" - " float4 pos: SV_Position;\n" - "};\n" - "vs_out main(vs_in inp) {\n" - " vs_out outp;\n" - " outp.pos = mul(mvp, inp.pos);\n" - " outp.color = inp.color;\n" - " return outp;\n" - "};\n", - }, - .fs.source = + .vertex_func.source = + "cbuffer params: register(b0) {\n" + " float4x4 mvp;\n" + "};\n" + "struct vs_in {\n" + " float4 pos: POSITION;\n" + " float4 color: COLOR1;\n" + "};\n" + "struct vs_out {\n" + " float4 color: COLOR0;\n" + " float4 pos: SV_Position;\n" + "};\n" + "vs_out main(vs_in inp) {\n" + " vs_out outp;\n" + " outp.pos = mul(mvp, inp.pos);\n" + " outp.color = inp.color;\n" + " return outp;\n" + "};\n", + .fragment_func.source = "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" - "}\n" + "}\n", + .vertex_attrs = { + [0] = { .hlsl_sem_name = "POSITION" }, + [1] = { .hlsl_sem_name = "COLOR", .hlsl_sem_index = 1 }, + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, + }, }); // a pipeline object @@ -157,7 +159,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From 2a2fe55f7afa8f2745906599c67bc21edc94bab1 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 16 Sep 2024 13:21:18 +0200 Subject: [PATCH 07/36] update texcube-d3d11.c for bindings cleanup --- d3d11/texcube-d3d11.c | 94 +++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/d3d11/texcube-d3d11.c b/d3d11/texcube-d3d11.c index 3327857a..346c60c3 100644 --- a/d3d11/texcube-d3d11.c +++ b/d3d11/texcube-d3d11.c @@ -100,46 +100,56 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0] = { .sem_name="POSITION" }, - [1] = { .sem_name="COLOR", .sem_index=1 }, - [2] = { .sem_name="TEXCOORD", .sem_index=1 } + .vertex_func.source = + "cbuffer params: register(b0) {\n" + " float4x4 mvp;\n" + "};\n" + "struct vs_in {\n" + " float4 pos: POSITION;\n" + " float4 color: COLOR1;\n" + " float2 uv: TEXCOORD1;\n" + "};\n" + "struct vs_out {\n" + " float4 color: COLOR0;\n" + " float2 uv: TEXCOORD0;\n" + " float4 pos: SV_Position;\n" + "};\n" + "vs_out main(vs_in inp) {\n" + " vs_out outp;\n" + " outp.pos = mul(mvp, inp.pos);\n" + " outp.color = inp.color;\n" + " outp.uv = inp.uv * 5.0;\n" + " return outp;\n" + "};\n", + .fragment_func.source = + "Texture2D tex: register(t0);\n" + "sampler smp: register(s0);\n" + "float4 main(float4 color: COLOR0, float2 uv: TEXCOORD0): SV_Target0 {\n" + " return tex.Sample(smp, uv) * color;\n" + "}\n", + .vertex_attrs = { + [0] = { .hlsl_sem_name="POSITION" }, + [1] = { .hlsl_sem_name="COLOR", .hlsl_sem_index=1 }, + [2] = { .hlsl_sem_name="TEXCOORD", .hlsl_sem_index=1 } }, - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "cbuffer params: register(b0) {\n" - " float4x4 mvp;\n" - "};\n" - "struct vs_in {\n" - " float4 pos: POSITION;\n" - " float4 color: COLOR1;\n" - " float2 uv: TEXCOORD1;\n" - "};\n" - "struct vs_out {\n" - " float4 color: COLOR0;\n" - " float2 uv: TEXCOORD0;\n" - " float4 pos: SV_Position;\n" - "};\n" - "vs_out main(vs_in inp) {\n" - " vs_out outp;\n" - " outp.pos = mul(mvp, inp.pos);\n" - " outp.color = inp.color;\n" - " outp.uv = inp.uv * 5.0;\n" - " return outp;\n" - "};\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, + }, + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_t_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_s_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "Texture2D tex: register(t0);\n" - "sampler smp: register(s0);\n" - "float4 main(float4 color: COLOR0, float2 uv: TEXCOORD0): SV_Target0 {\n" - " return tex.Sample(smp, uv) * color;\n" - "}\n" - } }); // pipeline object @@ -167,10 +177,8 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_bindings bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - }, + .images[0] = img, + .samplers[0] = smp, }; // view-projection matrix @@ -192,7 +200,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From 1ec7e41ef8422e4213601b715aeb8247969b2645 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 16 Sep 2024 14:19:46 +0200 Subject: [PATCH 08/36] update all d3d11 sampler for bindings cleanup --- d3d11/arraytex-d3d11.c | 117 ++++++++++++++------------ d3d11/binshader-d3d11.c | 20 ++--- d3d11/blend-d3d11.c | 54 ++++++------ d3d11/bufferoffsets-d3d11.c | 14 ++-- d3d11/dyntex-d3d11.c | 95 +++++++++++---------- d3d11/imgui-d3d11.cc | 41 ++++----- d3d11/inject-d3d11.c | 89 +++++++++++--------- d3d11/instancing-d3d11.c | 24 +++--- d3d11/mipmap-d3d11.c | 82 ++++++++++-------- d3d11/mrt-d3d11.c | 162 ++++++++++++++++++------------------ d3d11/offscreen-d3d11.c | 116 ++++++++++++++------------ d3d11/quad-d3d11.c | 14 ++-- d3d11/triangle-d3d11.c | 14 ++-- d3d11/vertexpulling-d3d11.c | 24 ++++-- 14 files changed, 468 insertions(+), 398 deletions(-) diff --git a/d3d11/arraytex-d3d11.c b/d3d11/arraytex-d3d11.c index af0422e4..bbb659e5 100644 --- a/d3d11/arraytex-d3d11.c +++ b/d3d11/arraytex-d3d11.c @@ -115,65 +115,74 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_bindings bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - } + .images[0] = img, + .samplers[0] = smp, }; // shader to sample from array texture sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "TEXCOORD" + .vertex_func.source = + "cbuffer params: register(b0) {\n" + " float4x4 mvp;\n" + " float2 offset0;\n" + " float2 offset1;\n" + " float2 offset2;\n" + "};\n" + "struct vs_in {\n" + " float4 pos: POSITION;\n" + " float2 uv: TEXCOORD0;\n" + "};\n" + "struct vs_out {\n" + " float3 uv0: TEXCOORD0;\n" + " float3 uv1: TEXCOORD1;\n" + " float3 uv2: TEXCOORD2;\n" + " float4 pos: SV_Position;\n" + "};\n" + "vs_out main(vs_in inp) {\n" + " vs_out outp;\n" + " outp.pos = mul(mvp, inp.pos);\n" + " outp.uv0 = float3(inp.uv + offset0, 0.0);\n" + " outp.uv1 = float3(inp.uv + offset1, 1.0);\n" + " outp.uv2 = float3(inp.uv + offset2, 2.0);\n" + " return outp;\n" + "}\n", + .fragment_func.source = + "Texture2DArray tex: register(t0);\n" + "sampler smp: register(s0);\n" + "struct fs_in {\n" + " float3 uv0: TEXCOORD0;\n" + " float3 uv1: TEXCOORD1;\n" + " float3 uv2: TEXCOORD2;\n" + "};\n" + "float4 main(fs_in inp): SV_Target0 {\n" + " float3 c0 = tex.Sample(smp, inp.uv0).xyz;\n" + " float3 c1 = tex.Sample(smp, inp.uv1).xyz;\n" + " float3 c2 = tex.Sample(smp, inp.uv2).xyz;\n" + " return float4(c0+c1+c2, 1.0);\n" + "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "TEXCOORD" }, - .vs = { - .uniform_blocks[0].size = sizeof(params_t), - .source = - "cbuffer params {\n" - " float4x4 mvp;\n" - " float2 offset0;\n" - " float2 offset1;\n" - " float2 offset2;\n" - "};\n" - "struct vs_in {\n" - " float4 pos: POSITION;\n" - " float2 uv: TEXCOORD0;\n" - "};\n" - "struct vs_out {\n" - " float3 uv0: TEXCOORD0;\n" - " float3 uv1: TEXCOORD1;\n" - " float3 uv2: TEXCOORD2;\n" - " float4 pos: SV_Position;\n" - "};\n" - "vs_out main(vs_in inp) {\n" - " vs_out outp;\n" - " outp.pos = mul(mvp, inp.pos);\n" - " outp.uv0 = float3(inp.uv + offset0, 0.0);\n" - " outp.uv1 = float3(inp.uv + offset1, 1.0);\n" - " outp.uv2 = float3(inp.uv + offset2, 2.0);\n" - " return outp;\n" - "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .hlsl_register_b_n = 0, + }, + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_type = SG_IMAGETYPE_ARRAY, + .hlsl_register_t_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_s_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, - .fs = { - .images[0] = { .used = true, .image_type = SG_IMAGETYPE_ARRAY }, - .samplers[0] = { .used = true }, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "Texture2DArray tex: register(t0);\n" - "sampler smp: register(s0);\n" - "struct fs_in {\n" - " float3 uv0: TEXCOORD0;\n" - " float3 uv1: TEXCOORD1;\n" - " float3 uv2: TEXCOORD2;\n" - "};\n" - "float4 main(fs_in inp): SV_Target0 {\n" - " float3 c0 = tex.Sample(smp, inp.uv0).xyz;\n" - " float3 c1 = tex.Sample(smp, inp.uv1).xyz;\n" - " float3 c2 = tex.Sample(smp, inp.uv2).xyz;\n" - " return float4(c0+c1+c2, 1.0);\n" - "}\n" - } }); // create pipeline object @@ -225,7 +234,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/d3d11/binshader-d3d11.c b/d3d11/binshader-d3d11.c index 7fbc8b77..713641e2 100644 --- a/d3d11/binshader-d3d11.c +++ b/d3d11/binshader-d3d11.c @@ -88,17 +88,17 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "COLOR" + .vertex_func.bytecode = SG_RANGE(vs_bin), + .fragment_func.bytecode = SG_RANGE(fs_bin), + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "COLOR" }, - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .bytecode = SG_RANGE(vs_bin) + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, }, - .fs = { - .bytecode = SG_RANGE(fs_bin) - } }); // a pipeline object @@ -139,7 +139,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/d3d11/blend-d3d11.c b/d3d11/blend-d3d11.c index 70eb015b..9f292b0d 100644 --- a/d3d11/blend-d3d11.c +++ b/d3d11/blend-d3d11.c @@ -48,8 +48,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // a shader for the fullscreen background quad sg_shader bg_shd = sg_make_shader(&(sg_shader_desc){ - .attrs[0].sem_name = "POS", - .vs.source = + .vertex_func.source = "struct vs_in {\n" " float2 pos: POS;\n" "};\n" @@ -61,18 +60,21 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.pos = float4(inp.pos, 0.5, 1.0);\n" " return outp;\n" "};\n", - .fs = { - .uniform_blocks[0].size = sizeof(fs_params_t), - .source = - "cbuffer params: register(b0) {\n" - " float tick;\n" - "};\n" - "float4 main(float4 frag_coord: SV_Position): SV_Target0 {\n" - " float2 xy = frac((frag_coord.xy-float2(tick,tick)) / 50.0);\n" - " float c = xy.x * xy.y;\n" - " return float4(c, c, c, 1.0);\n" - "};\n" - } + .fragment_func.source = + "cbuffer params: register(b0) {\n" + " float tick;\n" + "};\n" + "float4 main(float4 frag_coord: SV_Position): SV_Target0 {\n" + " float2 xy = frac((frag_coord.xy-float2(tick,tick)) / 50.0);\n" + " float c = xy.x * xy.y;\n" + " return float4(c, c, c, 1.0);\n" + "};\n", + .vertex_attrs[0].hlsl_sem_name = "POS", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .size = sizeof(fs_params_t), + .hlsl_register_b_n = 0, + }, }); // a pipeline state object for rendering the background quad @@ -87,12 +89,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // a shader for the blended quads sg_shader quad_shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POS", - [1].sem_name = "COLOR" - }, - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.source = + .vertex_func.source = "cbuffer params: register(b0) {\n" " float4x4 mvp;\n" "};\n" @@ -110,10 +107,19 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.color = inp.color;\n" " return outp;\n" "}\n", - .fs.source = + .fragment_func.source = "float4 main(float4 color: COLOR): SV_Target0 {\n" " return color;\n" - "}\n" + "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POS", + [1].hlsl_sem_name = "COLOR" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, + }, }); // one pipeline object per blend-factor combination @@ -169,7 +175,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // draw a background quad sg_apply_pipeline(bg_pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, &SG_RANGE(fs_params)); + sg_apply_uniforms(0, &SG_RANGE(fs_params)); sg_draw(0, 4, 1); // draw the blended quads @@ -185,7 +191,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_apply_pipeline(pips[src][dst]); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } } diff --git a/d3d11/bufferoffsets-d3d11.c b/d3d11/bufferoffsets-d3d11.c index a3cbec45..ccb89b1c 100644 --- a/d3d11/bufferoffsets-d3d11.c +++ b/d3d11/bufferoffsets-d3d11.c @@ -51,11 +51,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // a shader to render the 2D shapes sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "COLOR" - }, - .vs.source = + .vertex_func.source = "struct vs_in {\n" " float2 pos: POSITION;\n" " float3 color: COLOR0;\n" @@ -70,10 +66,14 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.color = float4(inp.color, 1.0);\n" " return outp;\n" "}\n", - .fs.source = + .fragment_func.source = "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" - "}\n" + "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "COLOR" + }, }); // a pipeline state object, default states are fine diff --git a/d3d11/dyntex-d3d11.c b/d3d11/dyntex-d3d11.c index 10b709d2..8a37ae39 100644 --- a/d3d11/dyntex-d3d11.c +++ b/d3d11/dyntex-d3d11.c @@ -104,54 +104,63 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_bindings bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - } + .images[0] = img, + .samplers[0] = smp, }; // a shader to render textured cube sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "COLOR", - [2].sem_name = "TEXCOORD" + .vertex_func.source = + "cbuffer params: register(b0) {\n" + " float4x4 mvp;\n" + "};\n" + "struct vs_in {\n" + " float4 pos: POSITION;\n" + " float4 color: COLOR0;\n" + " float2 uv: TEXCOORD0;\n" + "};\n" + "struct vs_out {\n" + " float4 color: COLOR0;\n" + " float2 uv: TEXCOORD0;\n" + " float4 pos: SV_Position;\n" + "};\n" + "vs_out main(vs_in inp) {\n" + " vs_out outp;\n" + " outp.pos = mul(mvp, inp.pos);\n" + " outp.color = inp.color;\n" + " outp.uv = inp.uv;\n" + " return outp;\n" + "}\n", + .fragment_func.source ={ + "Texture2D tex: register(t0);\n" + "sampler smp: register(s0);\n" + "float4 main(float4 color: COLOR0, float2 uv: TEXCOORD0): SV_Target0 {\n" + " return tex.Sample(smp, uv) * color;\n" + "}\n" }, - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "cbuffer params {\n" - " float4x4 mvp;\n" - "};\n" - "struct vs_in {\n" - " float4 pos: POSITION;\n" - " float4 color: COLOR0;\n" - " float2 uv: TEXCOORD0;\n" - "};\n" - "struct vs_out {\n" - " float4 color: COLOR0;\n" - " float2 uv: TEXCOORD0;\n" - " float4 pos: SV_Position;\n" - "};\n" - "vs_out main(vs_in inp) {\n" - " vs_out outp;\n" - " outp.pos = mul(mvp, inp.pos);\n" - " outp.color = inp.color;\n" - " outp.uv = inp.uv;\n" - " return outp;\n" - "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "COLOR", + [2].hlsl_sem_name = "TEXCOORD" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, + }, + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_t_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_s_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "Texture2D tex: register(t0);\n" - "sampler smp: register(s0);\n" - "float4 main(float4 color: COLOR0, float2 uv: TEXCOORD0): SV_Target0 {\n" - " return tex.Sample(smp, uv) * color;\n" - "}\n" - } }); // a pipeline-state-object for the textured cube @@ -207,7 +216,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/d3d11/imgui-d3d11.cc b/d3d11/imgui-d3d11.cc index 3747db54..5d0102ae 100644 --- a/d3d11/imgui-d3d11.cc +++ b/d3d11/imgui-d3d11.cc @@ -98,21 +98,16 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; img_desc.data.subimage[0][0].ptr = font_pixels; img_desc.data.subimage[0][0].size = font_width * font_height * 4; - bind.fs.images[0] = sg_make_image(&img_desc); + bind.images[0] = sg_make_image(&img_desc); sg_sampler_desc smp_desc = { }; smp_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; smp_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; - bind.fs.samplers[0] = sg_make_sampler(&smp_desc); + bind.samplers[0] = sg_make_sampler(&smp_desc); // shader object for imgui rendering sg_shader_desc shd_desc = { }; - auto& ub = shd_desc.vs.uniform_blocks[0]; - ub.size = sizeof(vs_params_t); - shd_desc.attrs[0].sem_name = "POSITION"; - shd_desc.attrs[1].sem_name = "TEXCOORD"; - shd_desc.attrs[2].sem_name = "COLOR"; - shd_desc.vs.source = - "cbuffer params {\n" + shd_desc.vertex_func.source = + "cbuffer params: register(b0) {\n" " float2 disp_size;\n" "};\n" "struct vs_in {\n" @@ -132,26 +127,34 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.color = inp.color;\n" " return outp;\n" "}\n"; - shd_desc.fs.images[0].used = true; - shd_desc.fs.samplers[0].used = true; - shd_desc.fs.image_sampler_pairs[0].used = true; - shd_desc.fs.image_sampler_pairs[0].image_slot = 0; - shd_desc.fs.image_sampler_pairs[0].sampler_slot = 0; - shd_desc.fs.source = + shd_desc.fragment_func.source = "Texture2D tex: register(t0);\n" "sampler smp: register(s0);\n" "float4 main(float2 uv: TEXCOORD0, float4 color: COLOR0): SV_Target0 {\n" " return tex.Sample(smp, uv) * color;\n" "}\n"; + shd_desc.vertex_attrs[0].hlsl_sem_name = "POSITION"; + shd_desc.vertex_attrs[1].hlsl_sem_name = "TEXCOORD"; + shd_desc.vertex_attrs[2].hlsl_sem_name = "COLOR"; + shd_desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + shd_desc.uniform_blocks[0].size = sizeof(vs_params_t); + shd_desc.uniform_blocks[0].hlsl_register_b_n = 0; + shd_desc.images[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.images[0].hlsl_register_t_n = 0, + shd_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.samplers[0].hlsl_register_s_n = 0; + shd_desc.image_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.image_sampler_pairs[0].image_slot = 0; + shd_desc.image_sampler_pairs[0].sampler_slot = 0; sg_shader shd = sg_make_shader(&shd_desc); // pipeline object for imgui rendering sg_pipeline_desc pip_desc = { }; pip_desc.layout.buffers[0].stride = sizeof(ImDrawVert); auto& attrs = pip_desc.layout.attrs; - attrs[0].offset=offsetof(ImDrawVert, pos); attrs[0].format=SG_VERTEXFORMAT_FLOAT2; - attrs[1].offset=offsetof(ImDrawVert, uv); attrs[1].format=SG_VERTEXFORMAT_FLOAT2; - attrs[2].offset=offsetof(ImDrawVert, col); attrs[2].format=SG_VERTEXFORMAT_UBYTE4N; + attrs[0].offset = offsetof(ImDrawVert, pos); attrs[0].format = SG_VERTEXFORMAT_FLOAT2; + attrs[1].offset = offsetof(ImDrawVert, uv); attrs[1].format = SG_VERTEXFORMAT_FLOAT2; + attrs[2].offset = offsetof(ImDrawVert, col); attrs[2].format = SG_VERTEXFORMAT_UBYTE4N; pip_desc.shader = shd; pip_desc.index_type = SG_INDEXTYPE_UINT16; pip_desc.colors[0].blend.enabled = true; @@ -227,7 +230,7 @@ void draw_imgui(ImDrawData* draw_data) { vs_params.disp_size.x = ImGui::GetIO().DisplaySize.x; vs_params.disp_size.y = ImGui::GetIO().DisplaySize.y; sg_apply_pipeline(pip); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE(vs_params)); + sg_apply_uniforms(0, SG_RANGE(vs_params)); for (int cl_index = 0; cl_index < draw_data->CmdListsCount; cl_index++) { const ImDrawList* cl = draw_data->CmdLists[cl_index]; diff --git a/d3d11/inject-d3d11.c b/d3d11/inject-d3d11.c index 237b08b4..b7fb443d 100644 --- a/d3d11/inject-d3d11.c +++ b/d3d11/inject-d3d11.c @@ -201,48 +201,57 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "TEXCOORD" + .vertex_func.source = + "cbuffer params: register(b0) {\n" + " float4x4 mvp;\n" + "};\n" + "struct vs_in {\n" + " float4 pos: POSITION;\n" + " float2 uv: TEXCOORD0;\n" + "};\n" + "struct vs_out {\n" + " float2 uv: TEXCOORD0;\n" + " float4 pos: SV_Position;\n" + "};\n" + "vs_out main(vs_in inp) {\n" + " vs_out outp;\n" + " outp.pos = mul(mvp, inp.pos);\n" + " outp.uv = inp.uv;\n" + " return outp;\n" + "};\n", + .fragment_func.source = + "Texture2D tex: register(t0);\n" + "sampler smp: register(s0);\n" + "float4 main(float2 uv: TEXCOORD0): SV_Target0 {\n" + " return tex.Sample(smp, uv);\n" + "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "TEXCOORD" }, - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "cbuffer params: register(b0) {\n" - " float4x4 mvp;\n" - "};\n" - "struct vs_in {\n" - " float4 pos: POSITION;\n" - " float2 uv: TEXCOORD0;\n" - "};\n" - "struct vs_out {\n" - " float2 uv: TEXCOORD0;\n" - " float4 pos: SV_Position;\n" - "};\n" - "vs_out main(vs_in inp) {\n" - " vs_out outp;\n" - " outp.pos = mul(mvp, inp.pos);\n" - " outp.uv = inp.uv;\n" - " return outp;\n" - "};\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "Texture2D tex: register(t0);\n" - "sampler smp: register(s0);\n" - "float4 main(float2 uv: TEXCOORD0): SV_Target0 {\n" - " return tex.Sample(smp, uv);\n" - "}\n" + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_t_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_s_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, }); assert(sg_d3d11_query_shader_info(shd).vs != 0); assert(sg_d3d11_query_shader_info(shd).fs != 0); - assert(sg_d3d11_query_shader_info(shd).vs_cbufs[0] != 0); - assert(sg_d3d11_query_shader_info(shd).vs_cbufs[1] == 0); - assert(sg_d3d11_query_shader_info(shd).fs_cbufs[0] == 0); + assert(sg_d3d11_query_shader_info(shd).cbufs[0] != 0); + assert(sg_d3d11_query_shader_info(shd).cbufs[1] == 0); // pipeline object sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){ @@ -272,10 +281,8 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_bindings bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - }, + .images[0] = img, + .samplers[0] = smp, }; // view-projection matrix @@ -311,7 +318,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/d3d11/instancing-d3d11.c b/d3d11/instancing-d3d11.c index bcfee519..a639bae5 100644 --- a/d3d11/instancing-d3d11.c +++ b/d3d11/instancing-d3d11.c @@ -70,13 +70,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "COLOR", - [2].sem_name = "INSTPOS" - }, - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.source = + .vertex_func.source = "cbuffer params: register(b0) {\n" " float4x4 mvp;\n" "};\n" @@ -95,10 +89,20 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.color = inp.color;\n" " return outp;\n" "};\n", - .fs.source = + .fragment_func.source = "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" - "};\n" + "};\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "COLOR", + [2].hlsl_sem_name = "INSTPOS" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, + } }); // pipeline object, note the vertex layout description @@ -189,7 +193,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 24, cur_num_particles); sg_end_pass(); sg_commit(); diff --git a/d3d11/mipmap-d3d11.c b/d3d11/mipmap-d3d11.c index 91cbea96..ef1a865b 100644 --- a/d3d11/mipmap-d3d11.c +++ b/d3d11/mipmap-d3d11.c @@ -130,41 +130,51 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "TEXCOORD" + .vertex_func.source = + "cbuffer params: register(b0) {\n" + " float4x4 mvp;\n" + "};\n" + "struct vs_in {\n" + " float4 pos: POSITION;\n" + " float2 uv: TEXCOORD0;\n" + "};\n" + "struct vs_out {\n" + " float2 uv: TEXCOORD0;\n" + " float4 pos: SV_Position;\n" + "};\n" + "vs_out main(vs_in inp) {\n" + " vs_out outp;\n" + " outp.pos = mul(mvp, inp.pos);\n" + " outp.uv = inp.uv;\n" + " return outp;\n" + "};\n", + .fragment_func.source = + "Texture2D tex: register(t0);\n" + "sampler smp: register(s0);\n" + "float4 main(float2 uv: TEXCOORD0): SV_Target0 {\n" + " return tex.Sample(smp, uv);\n" + "};\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "TEXCOORD" }, - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "cbuffer params: register(b0) {\n" - " float4x4 mvp;\n" - "};\n" - "struct vs_in {\n" - " float4 pos: POSITION;\n" - " float2 uv: TEXCOORD0;\n" - "};\n" - "struct vs_out {\n" - " float2 uv: TEXCOORD0;\n" - " float4 pos: SV_Position;\n" - "};\n" - "vs_out main(vs_in inp) {\n" - " vs_out outp;\n" - " outp.pos = mul(mvp, inp.pos);\n" - " outp.uv = inp.uv;\n" - " return outp;\n" - "};\n" + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "Texture2D tex: register(t0);\n" - "sampler smp: register(s0);\n" - "float4 main(float2 uv: TEXCOORD0): SV_Target0 {\n" - " return tex.Sample(smp, uv);\n" - "};\n" + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_t_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_s_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, } }); @@ -195,7 +205,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_apply_pipeline(pip); sg_bindings bind = { .vertex_buffers[0] = vbuf, - .fs.images[0] = img, + .images[0] = img, }; for (int i = 0; i < 12; i++) { const float x = ((float)(i & 3) - 1.5f) * 2.0f; @@ -203,9 +213,9 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ hmm_mat4 model = HMM_MultiplyMat4(HMM_Translate(HMM_Vec3(x, y, 0.0f)), rm); vs_params.mvp = HMM_MultiplyMat4(view_proj, model); - bind.fs.samplers[0] = smp[i]; + bind.samplers[0] = smp[i]; sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } sg_end_pass(); diff --git a/d3d11/mrt-d3d11.c b/d3d11/mrt-d3d11.c index f8acd020..4239c0e6 100644 --- a/d3d11/mrt-d3d11.c +++ b/d3d11/mrt-d3d11.c @@ -144,12 +144,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // a shader to render a cube into MRT offscreen render targets sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "BRIGHT" - }, - .vs.uniform_blocks[0].size = sizeof(offscreen_params_t), - .vs.source = + .vertex_func.source = "cbuffer params: register(b0) {\n" " float4x4 mvp;\n" "};\n" @@ -167,7 +162,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.bright = inp.bright;\n" " return outp;\n" "}\n", - .fs.source = + .fragment_func.source = "struct fs_out {\n" " float4 c0: SV_Target0;\n" " float4 c1: SV_Target1;\n" @@ -179,7 +174,16 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.c1 = float4(0.0, b, 0.0, 1.0);\n" " outp.c2 = float4(0.0, 0.0, b, 1.0);\n" " return outp;\n" - "}\n" + "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "BRIGHT" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(offscreen_params_t), + .hlsl_register_b_n = 0, + }, }); // pipeline object for the offscreen-rendered cube @@ -226,60 +230,60 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // a shader to render a fullscreen rectangle, which 'composes' // the 3 offscreen render target images onto the screen sg_shader fsq_shd = sg_make_shader(&(sg_shader_desc){ - .attrs[0].sem_name = "POSITION", - .vs = { - .uniform_blocks[0].size = sizeof(params_t), - .source = - "cbuffer params {\n" - " float2 offset;\n" - "};\n" - "struct vs_in {\n" - " float2 pos: POSITION;\n" - "};\n" - "struct vs_out {\n" - " float2 uv0: TEXCOORD0;\n" - " float2 uv1: TEXCOORD1;\n" - " float2 uv2: TEXCOORD2;\n" - " float4 pos: SV_Position;\n" - "};\n" - "vs_out main(vs_in inp) {\n" - " vs_out outp;\n" - " outp.pos = float4(inp.pos*2.0-1.0, 0.5, 1.0);\n" - " outp.uv0 = inp.pos + float2(offset.x, 0.0);\n" - " outp.uv1 = inp.pos + float2(0.0, offset.y);\n" - " outp.uv2 = inp.pos;\n" - " return outp;\n" - "}\n", + .vertex_func.source = + "cbuffer params: register(b0) {\n" + " float2 offset;\n" + "};\n" + "struct vs_in {\n" + " float2 pos: POSITION;\n" + "};\n" + "struct vs_out {\n" + " float2 uv0: TEXCOORD0;\n" + " float2 uv1: TEXCOORD1;\n" + " float2 uv2: TEXCOORD2;\n" + " float4 pos: SV_Position;\n" + "};\n" + "vs_out main(vs_in inp) {\n" + " vs_out outp;\n" + " outp.pos = float4(inp.pos*2.0-1.0, 0.5, 1.0);\n" + " outp.uv0 = inp.pos + float2(offset.x, 0.0);\n" + " outp.uv1 = inp.pos + float2(0.0, offset.y);\n" + " outp.uv2 = inp.pos;\n" + " return outp;\n" + "}\n", + .fragment_func.source = + "Texture2D tex0: register(t0);\n" + "Texture2D tex1: register(t1);\n" + "Texture2D tex2: register(t2);\n" + "sampler smp0: register(s0);\n" + "struct fs_in {\n" + " float2 uv0: TEXCOORD0;\n" + " float2 uv1: TEXCOORD1;\n" + " float2 uv2: TEXCOORD2;\n" + "};\n" + "float4 main(fs_in inp): SV_Target0 {\n" + " float3 c0 = tex0.Sample(smp0, inp.uv0).xyz;\n" + " float3 c1 = tex1.Sample(smp0, inp.uv1).xyz;\n" + " float3 c2 = tex2.Sample(smp0, inp.uv2).xyz;\n" + " float4 c = float4(c0 + c1 + c2, 1.0);\n" + " return c;\n" + "}\n", + .vertex_attrs[0].hlsl_sem_name = "POSITION", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .hlsl_register_b_n = 0, }, - .fs = { - .images = { - [0].used = true, - [1].used = true, - [2].used = true, - }, - .samplers[0].used = true, - .image_sampler_pairs = { - [0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - [1] = { .used = true, .image_slot = 1, .sampler_slot = 0 }, - [2] = { .used = true, .image_slot = 2, .sampler_slot = 0 }, - }, - .source = - "Texture2D tex0: register(t0);\n" - "Texture2D tex1: register(t1);\n" - "Texture2D tex2: register(t2);\n" - "sampler smp0: register(s0);\n" - "struct fs_in {\n" - " float2 uv0: TEXCOORD0;\n" - " float2 uv1: TEXCOORD1;\n" - " float2 uv2: TEXCOORD2;\n" - "};\n" - "float4 main(fs_in inp): SV_Target0 {\n" - " float3 c0 = tex0.Sample(smp0, inp.uv0).xyz;\n" - " float3 c1 = tex1.Sample(smp0, inp.uv1).xyz;\n" - " float3 c2 = tex2.Sample(smp0, inp.uv2).xyz;\n" - " float4 c = float4(c0 + c1 + c2, 1.0);\n" - " return c;\n" - "}\n", + .images = { + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .hlsl_register_t_n = 0 }, + [1] = { .stage = SG_SHADERSTAGE_FRAGMENT, .hlsl_register_t_n = 1 }, + [2] = { .stage = SG_SHADERSTAGE_FRAGMENT, .hlsl_register_t_n = 2 }, + }, + .samplers[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .hlsl_register_s_n = 0 }, + .image_sampler_pairs = { + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, + [1] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 1, .sampler_slot = 0 }, + [2] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 2, .sampler_slot = 0 }, } }); @@ -293,14 +297,12 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // resource bindings for the fullscreen quad sg_bindings fsq_bind = { .vertex_buffers[0] = quad_buf, - .fs = { - .images = { - [0] = offscreen_attachments_desc.resolves[0].image, - [1] = offscreen_attachments_desc.resolves[1].image, - [2] = offscreen_attachments_desc.resolves[2].image, - }, - .samplers[0] = smp, - } + .images = { + [0] = offscreen_attachments_desc.resolves[0].image, + [1] = offscreen_attachments_desc.resolves[1].image, + [2] = offscreen_attachments_desc.resolves[2].image, + }, + .samplers[0] = smp, }; // pipeline and resource bindings to render a debug visualizations @@ -309,8 +311,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ .layout.attrs[0].format = SG_VERTEXFORMAT_FLOAT2, .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, .shader = sg_make_shader(&(sg_shader_desc){ - .attrs[0].sem_name = "POSITION", - .vs.source = + .vertex_func.source = "struct vs_in {\n" " float2 pos: POSITION;\n" "};\n" @@ -324,21 +325,22 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.uv = inp.pos;\n" " return outp;\n" "}\n", - .fs.images[0].used = true, - .fs.samplers[0].used = true, - .fs.image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .fs.source = + .fragment_func.source = "Texture2D tex: register(t0);\n" "sampler smp: register(s0);\n" "float4 main(float2 uv: TEXCOORD0): SV_Target0 {\n" " return float4(tex.Sample(smp, uv).xyz, 1.0);\n" - "}\n" + "}\n", + .vertex_attrs[0].hlsl_sem_name = "POSITION", + .images[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .hlsl_register_t_n = 0 }, + .samplers[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .hlsl_register_s_n = 0 }, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, }) }); // images will be filled right before rendering sg_bindings dbg_bind = { .vertex_buffers[0] = quad_buf, - .fs.samplers[0] = smp, + .samplers[0] = smp, }; // default pass action, no clear needed, since whole screen is overwritten @@ -371,7 +373,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ }); sg_apply_pipeline(offscreen_pip); sg_apply_bindings(&offscreen_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(offscreen_params)); + sg_apply_uniforms(0, &SG_RANGE(offscreen_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -383,12 +385,12 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ }); sg_apply_pipeline(fsq_pip); sg_apply_bindings(&fsq_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(params)); + sg_apply_uniforms(0, &SG_RANGE(params)); sg_draw(0, 4, 1); sg_apply_pipeline(dbg_pip); for (int i = 0; i < 3; i++) { sg_apply_viewport(i*100, 0, 100, 100, false); - dbg_bind.fs.images[0] = offscreen_attachments_desc.resolves[i].image; + dbg_bind.images[0] = offscreen_attachments_desc.resolves[i].image; sg_apply_bindings(&dbg_bind); sg_draw(0, 4, 1); } diff --git a/d3d11/offscreen-d3d11.c b/d3d11/offscreen-d3d11.c index 739aa365..13702413 100644 --- a/d3d11/offscreen-d3d11.c +++ b/d3d11/offscreen-d3d11.c @@ -124,12 +124,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // shader for non-textured cube, rendered in offscreen pass sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "COLOR" - }, - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.source = + .vertex_func.source = "cbuffer params: register(b0) {\n" " float4x4 mvp;\n" "};\n" @@ -147,54 +142,73 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.color = inp.color;\n" " return outp;\n" "}\n", - .fs.source = + .fragment_func.source = "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" - "}\n" + "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "COLOR" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, + } }); // ...and a second shader for rendering a textured cube in the default pass sg_shader default_shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POSITION", - [1].sem_name = "COLOR", - [2].sem_name = "TEXCOORD" + .vertex_func.source = + "cbuffer params: register(b0) {\n" + " float4x4 mvp;\n" + "};\n" + "struct vs_in {\n" + " float4 pos: POSITION;\n" + " float4 color: COLOR0;\n" + " float2 uv: TEXCOORD0;\n" + "};\n" + "struct vs_out {\n" + " float4 color: COLOR0;\n" + " float2 uv: TEXCOORD0;\n" + " float4 pos: SV_Position;\n" + "};\n" + "vs_out main(vs_in inp) {\n" + " vs_out outp;\n" + " outp.pos = mul(mvp, inp.pos);\n" + " outp.color = inp.color;\n" + " outp.uv = inp.uv;\n" + " return outp;\n" + "}\n", + .fragment_func.source = + "Texture2D tex: register(t0);\n" + "sampler smp: register(s0);\n" + "float4 main(float4 color: COLOR0, float2 uv: TEXCOORD0): SV_Target0 {\n" + " return tex.Sample(smp, uv) + color * 0.5;\n" + "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POSITION", + [1].hlsl_sem_name = "COLOR", + [2].hlsl_sem_name = "TEXCOORD" }, - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "cbuffer params: register(b0) {\n" - " float4x4 mvp;\n" - "};\n" - "struct vs_in {\n" - " float4 pos: POSITION;\n" - " float4 color: COLOR0;\n" - " float2 uv: TEXCOORD0;\n" - "};\n" - "struct vs_out {\n" - " float4 color: COLOR0;\n" - " float2 uv: TEXCOORD0;\n" - " float4 pos: SV_Position;\n" - "};\n" - "vs_out main(vs_in inp) {\n" - " vs_out outp;\n" - " outp.pos = mul(mvp, inp.pos);\n" - " outp.color = inp.color;\n" - " outp.uv = inp.uv;\n" - " return outp;\n" - "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, + }, + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_t_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .hlsl_register_s_n = 0, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - .source = - "Texture2D tex: register(t0);\n" - "sampler smp: register(s0);\n" - "float4 main(float4 color: COLOR0, float2 uv: TEXCOORD0): SV_Target0 {\n" - " return tex.Sample(smp, uv) + color * 0.5;\n" - "}\n" - } }); // pipeline object for offscreen rendering @@ -246,10 +260,8 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_bindings default_bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = color_img, - .samplers[0] = smp, - } + .images[0] = color_img, + .samplers[0] = smp, }; // view-projection matrix @@ -273,7 +285,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = offscreen_pass_action, .attachments = offscreen_attachments }); sg_apply_pipeline(offscreen_pip); sg_apply_bindings(&offscreen_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -281,7 +293,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = default_pass_action, .swapchain = d3d11_swapchain() }); sg_apply_pipeline(default_pip); sg_apply_bindings(&default_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); diff --git a/d3d11/quad-d3d11.c b/d3d11/quad-d3d11.c index 3fc377c6..e5a1c5f3 100644 --- a/d3d11/quad-d3d11.c +++ b/d3d11/quad-d3d11.c @@ -39,11 +39,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // a shader to render the quad sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POS", - [1].sem_name = "COLOR" - }, - .vs.source = + .vertex_func.source = "struct vs_in {\n" " float4 pos: POS;\n" " float4 color: COLOR;\n" @@ -58,10 +54,14 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.color = inp.color;\n" " return outp;\n" "}\n", - .fs.source = + .fragment_func.source = "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" - "}\n" + "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POS", + [1].hlsl_sem_name = "COLOR" + }, }); // pipeline state object diff --git a/d3d11/triangle-d3d11.c b/d3d11/triangle-d3d11.c index 68b0f21e..bf6eb1ec 100644 --- a/d3d11/triangle-d3d11.c +++ b/d3d11/triangle-d3d11.c @@ -45,11 +45,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ // a shader to render the triangle sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].sem_name = "POS", - [1].sem_name = "COLOR" - }, - .vs.source = + .vertex_func.source = "struct vs_in {\n" " float4 pos: POS;\n" " float4 color: COLOR;\n" @@ -64,10 +60,14 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.color = inp.color;\n" " return outp;\n" "}\n", - .fs.source = + .fragment_func.source = "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" - "}\n" + "}\n", + .vertex_attrs = { + [0].hlsl_sem_name = "POS", + [1].hlsl_sem_name = "COLOR" + }, }); // a pipeline object diff --git a/d3d11/vertexpulling-d3d11.c b/d3d11/vertexpulling-d3d11.c index 379d7a00..a01abe16 100644 --- a/d3d11/vertexpulling-d3d11.c +++ b/d3d11/vertexpulling-d3d11.c @@ -84,13 +84,11 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ }); sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.storage_buffers[0] = { .used = true, .readonly = true }, - .vs.source = + .vertex_func.source = "cbuffer params: register(b0) {\n" " float4x4 mvp;\n" "};\n" - "ByteAddressBuffer vertices: register(t16);\n" + "ByteAddressBuffer vertices: register(t0);\n" "struct vs_out {\n" " float4 color: COLOR0;\n" " float4 pos: SV_Position;\n" @@ -103,10 +101,20 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.color = color;\n" " return outp;\n" "};\n", - .fs.source = + .fragment_func.source = "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .hlsl_register_b_n = 0, + }, + .storage_buffers[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .readonly = true, + .hlsl_register_t_n = 0, + }, }); sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){ @@ -121,7 +129,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_bindings bind = { .index_buffer = ibuf, - .vs.storage_buffers[0] = sbuf, + .storage_buffers[0] = sbuf, }; float rx = 0.0f, ry = 0.0f; @@ -141,7 +149,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From 6b0295871e95be21f889b8b1d4c4bd0bc5b85169 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Wed, 18 Sep 2024 18:11:10 +0200 Subject: [PATCH 09/36] fix d3d11 samples (vertex_attrs => attrs) --- d3d11/arraytex-d3d11.c | 2 +- d3d11/binshader-d3d11.c | 2 +- d3d11/blend-d3d11.c | 2 +- d3d11/bufferoffsets-d3d11.c | 2 +- d3d11/cube-d3d11.c | 2 +- d3d11/dyntex-d3d11.c | 2 +- d3d11/inject-d3d11.c | 2 +- d3d11/instancing-d3d11.c | 2 +- d3d11/mipmap-d3d11.c | 2 +- d3d11/mrt-d3d11.c | 2 +- d3d11/offscreen-d3d11.c | 4 ++-- d3d11/quad-d3d11.c | 2 +- d3d11/texcube-d3d11.c | 2 +- d3d11/triangle-d3d11.c | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/d3d11/arraytex-d3d11.c b/d3d11/arraytex-d3d11.c index bbb659e5..868f5f7c 100644 --- a/d3d11/arraytex-d3d11.c +++ b/d3d11/arraytex-d3d11.c @@ -160,7 +160,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " float3 c2 = tex.Sample(smp, inp.uv2).xyz;\n" " return float4(c0+c1+c2, 1.0);\n" "}\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "TEXCOORD" }, diff --git a/d3d11/binshader-d3d11.c b/d3d11/binshader-d3d11.c index 713641e2..5cc06d24 100644 --- a/d3d11/binshader-d3d11.c +++ b/d3d11/binshader-d3d11.c @@ -90,7 +90,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ sg_shader shd = sg_make_shader(&(sg_shader_desc){ .vertex_func.bytecode = SG_RANGE(vs_bin), .fragment_func.bytecode = SG_RANGE(fs_bin), - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "COLOR" }, diff --git a/d3d11/blend-d3d11.c b/d3d11/blend-d3d11.c index 9f292b0d..b005c79f 100644 --- a/d3d11/blend-d3d11.c +++ b/d3d11/blend-d3d11.c @@ -111,7 +111,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float4 color: COLOR): SV_Target0 {\n" " return color;\n" "}\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POS", [1].hlsl_sem_name = "COLOR" }, diff --git a/d3d11/bufferoffsets-d3d11.c b/d3d11/bufferoffsets-d3d11.c index ccb89b1c..50c99139 100644 --- a/d3d11/bufferoffsets-d3d11.c +++ b/d3d11/bufferoffsets-d3d11.c @@ -70,7 +70,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" "}\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "COLOR" }, diff --git a/d3d11/cube-d3d11.c b/d3d11/cube-d3d11.c index d305ae11..ae1b1ca8 100644 --- a/d3d11/cube-d3d11.c +++ b/d3d11/cube-d3d11.c @@ -108,7 +108,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" "}\n", - .vertex_attrs = { + .attrs = { [0] = { .hlsl_sem_name = "POSITION" }, [1] = { .hlsl_sem_name = "COLOR", .hlsl_sem_index = 1 }, }, diff --git a/d3d11/dyntex-d3d11.c b/d3d11/dyntex-d3d11.c index 8a37ae39..1eeccdf2 100644 --- a/d3d11/dyntex-d3d11.c +++ b/d3d11/dyntex-d3d11.c @@ -138,7 +138,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " return tex.Sample(smp, uv) * color;\n" "}\n" }, - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "COLOR", [2].hlsl_sem_name = "TEXCOORD" diff --git a/d3d11/inject-d3d11.c b/d3d11/inject-d3d11.c index b7fb443d..a6911cd8 100644 --- a/d3d11/inject-d3d11.c +++ b/d3d11/inject-d3d11.c @@ -225,7 +225,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float2 uv: TEXCOORD0): SV_Target0 {\n" " return tex.Sample(smp, uv);\n" "}\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "TEXCOORD" }, diff --git a/d3d11/instancing-d3d11.c b/d3d11/instancing-d3d11.c index a639bae5..91a381df 100644 --- a/d3d11/instancing-d3d11.c +++ b/d3d11/instancing-d3d11.c @@ -93,7 +93,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" "};\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "COLOR", [2].hlsl_sem_name = "INSTPOS" diff --git a/d3d11/mipmap-d3d11.c b/d3d11/mipmap-d3d11.c index ef1a865b..1de4d2a8 100644 --- a/d3d11/mipmap-d3d11.c +++ b/d3d11/mipmap-d3d11.c @@ -154,7 +154,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float2 uv: TEXCOORD0): SV_Target0 {\n" " return tex.Sample(smp, uv);\n" "};\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "TEXCOORD" }, diff --git a/d3d11/mrt-d3d11.c b/d3d11/mrt-d3d11.c index 4239c0e6..11110ac8 100644 --- a/d3d11/mrt-d3d11.c +++ b/d3d11/mrt-d3d11.c @@ -175,7 +175,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " outp.c2 = float4(0.0, 0.0, b, 1.0);\n" " return outp;\n" "}\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "BRIGHT" }, diff --git a/d3d11/offscreen-d3d11.c b/d3d11/offscreen-d3d11.c index 13702413..f0e7f980 100644 --- a/d3d11/offscreen-d3d11.c +++ b/d3d11/offscreen-d3d11.c @@ -146,7 +146,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" "}\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "COLOR" }, @@ -186,7 +186,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float4 color: COLOR0, float2 uv: TEXCOORD0): SV_Target0 {\n" " return tex.Sample(smp, uv) + color * 0.5;\n" "}\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POSITION", [1].hlsl_sem_name = "COLOR", [2].hlsl_sem_name = "TEXCOORD" diff --git a/d3d11/quad-d3d11.c b/d3d11/quad-d3d11.c index e5a1c5f3..df256392 100644 --- a/d3d11/quad-d3d11.c +++ b/d3d11/quad-d3d11.c @@ -58,7 +58,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" "}\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POS", [1].hlsl_sem_name = "COLOR" }, diff --git a/d3d11/texcube-d3d11.c b/d3d11/texcube-d3d11.c index 346c60c3..fb1dafd9 100644 --- a/d3d11/texcube-d3d11.c +++ b/d3d11/texcube-d3d11.c @@ -127,7 +127,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float4 color: COLOR0, float2 uv: TEXCOORD0): SV_Target0 {\n" " return tex.Sample(smp, uv) * color;\n" "}\n", - .vertex_attrs = { + .attrs = { [0] = { .hlsl_sem_name="POSITION" }, [1] = { .hlsl_sem_name="COLOR", .hlsl_sem_index=1 }, [2] = { .hlsl_sem_name="TEXCOORD", .hlsl_sem_index=1 } diff --git a/d3d11/triangle-d3d11.c b/d3d11/triangle-d3d11.c index bf6eb1ec..d0a555e9 100644 --- a/d3d11/triangle-d3d11.c +++ b/d3d11/triangle-d3d11.c @@ -64,7 +64,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float4 color: COLOR0): SV_Target0 {\n" " return color;\n" "}\n", - .vertex_attrs = { + .attrs = { [0].hlsl_sem_name = "POS", [1].hlsl_sem_name = "COLOR" }, From 6311b3d960e5d74bd7665ce5ff71bb4f430ce70a Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 21 Sep 2024 16:47:35 +0200 Subject: [PATCH 10/36] fix most glfw samples for new binding model --- glfw/arraytex-glfw.c | 100 +++++++++++----------- glfw/blend-glfw.c | 60 ++++++------- glfw/bufferoffsets-glfw.c | 10 +-- glfw/cube-glfw.c | 25 +++--- glfw/dyntex-glfw.c | 80 ++++++++--------- glfw/imgui-glfw.cc | 33 +++---- glfw/inject-glfw.c | 62 +++++++------- glfw/instancing-glfw.c | 23 ++--- glfw/metal-glfw.m | 4 +- glfw/mipmap-glfw.c | 68 ++++++++------- glfw/mrt-glfw.c | 170 ++++++++++++++++++------------------- glfw/multiwindow-glfw.c | 25 +++--- glfw/noninterleaved-glfw.c | 25 +++--- glfw/offscreen-glfw.c | 98 ++++++++++----------- glfw/quad-glfw.c | 8 +- glfw/texcube-glfw.c | 76 ++++++++--------- glfw/triangle-glfw.c | 8 +- 17 files changed, 435 insertions(+), 440 deletions(-) diff --git a/glfw/arraytex-glfw.c b/glfw/arraytex-glfw.c index 8d73f305..e947f3c2 100644 --- a/glfw/arraytex-glfw.c +++ b/glfw/arraytex-glfw.c @@ -120,60 +120,60 @@ int main() { sg_bindings bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - } + .images[0] = img, + .samplers[0] = smp, }; /* shader to sample from array texture */ sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 }, - [1] = { .name="offset0", .type=SG_UNIFORMTYPE_FLOAT2 }, - [2] = { .name="offset1", .type=SG_UNIFORMTYPE_FLOAT2 }, - [3] = { .name="offset2", .type=SG_UNIFORMTYPE_FLOAT2 } - } - }, - .source = - "#version 330\n" - "uniform mat4 mvp;\n" - "uniform vec2 offset0;\n" - "uniform vec2 offset1;\n" - "uniform vec2 offset2;\n" - "layout(location=0) in vec4 position;\n" - "layout(location=1) in vec2 texcoord0;\n" - "out vec3 uv0;\n" - "out vec3 uv1;\n" - "out vec3 uv2;\n" - "void main() {\n" - " gl_Position = mvp * position;\n" - " uv0 = vec3(texcoord0 + offset0, 0.0);\n" - " uv1 = vec3(texcoord0 + offset1, 1.0);\n" - " uv2 = vec3(texcoord0 + offset2, 2.0);\n" - "}\n", + .vertex_func.source = + "#version 410\n" + "uniform mat4 mvp;\n" + "uniform vec2 offset0;\n" + "uniform vec2 offset1;\n" + "uniform vec2 offset2;\n" + "layout(location=0) in vec4 position;\n" + "layout(location=1) in vec2 texcoord0;\n" + "out vec3 uv0;\n" + "out vec3 uv1;\n" + "out vec3 uv2;\n" + "void main() {\n" + " gl_Position = mvp * position;\n" + " uv0 = vec3(texcoord0 + offset0, 0.0);\n" + " uv1 = vec3(texcoord0 + offset1, 1.0);\n" + " uv2 = vec3(texcoord0 + offset2, 2.0);\n" + "}\n", + .fragment_func.source = + "#version 410\n" + "uniform sampler2DArray tex;\n" + "in vec3 uv0;\n" + "in vec3 uv1;\n" + "in vec3 uv2;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " vec4 c0 = texture(tex, uv0);\n" + " vec4 c1 = texture(tex, uv1);\n" + " vec4 c2 = texture(tex, uv2);\n" + " frag_color = vec4(c0.xyz + c1.xyz + c2.xyz, 1.0);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name="mvp", .type=SG_UNIFORMTYPE_MAT4 }, + [1] = { .glsl_name="offset0", .type=SG_UNIFORMTYPE_FLOAT2 }, + [2] = { .glsl_name="offset1", .type=SG_UNIFORMTYPE_FLOAT2 }, + [3] = { .glsl_name="offset2", .type=SG_UNIFORMTYPE_FLOAT2 } + } + }, + .images[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_type = SG_IMAGETYPE_ARRAY }, + .samplers[0] = { .stage = SG_SHADERSTAGE_FRAGMENT }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, + .glsl_name = "tex", }, - .fs = { - .images[0] = { .used = true, .image_type = SG_IMAGETYPE_ARRAY }, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "#version 330\n" - "uniform sampler2DArray tex;\n" - "in vec3 uv0;\n" - "in vec3 uv1;\n" - "in vec3 uv2;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " vec4 c0 = texture(tex, uv0);\n" - " vec4 c1 = texture(tex, uv1);\n" - " vec4 c2 = texture(tex, uv2);\n" - " frag_color = vec4(c0.xyz + c1.xyz + c2.xyz, 1.0);\n" - "}\n", - } }); // create pipeline object @@ -224,7 +224,7 @@ int main() { sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = glfw_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/glfw/blend-glfw.c b/glfw/blend-glfw.c index 5ae182b9..183d10d8 100644 --- a/glfw/blend-glfw.c +++ b/glfw/blend-glfw.c @@ -47,27 +47,26 @@ int main() { // a shader for the fullscreen background quad sg_shader bg_shd = sg_make_shader(&(sg_shader_desc){ - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "layout(location=0) in vec2 position;\n" "void main() {\n" " gl_Position = vec4(position, 0.5, 1.0);\n" "}\n", - .fs = { - .uniform_blocks[0] = { - .size = sizeof(fs_params_t), - .uniforms = { - [0] = { .name="tick", .type=SG_UNIFORMTYPE_FLOAT } - } - }, - .source = - "#version 330\n" - "uniform float tick;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " vec2 xy = fract((gl_FragCoord.xy-vec2(tick)) / 50.0);\n" - " frag_color = vec4(vec3(xy.x*xy.y), 1.0);\n" - "}\n" + .fragment_func.source = + "#version 410\n" + "uniform float tick;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " vec2 xy = fract((gl_FragCoord.xy-vec2(tick)) / 50.0);\n" + " frag_color = vec4(vec3(xy.x*xy.y), 1.0);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .size = sizeof(fs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "tick", .type = SG_UNIFORMTYPE_FLOAT }, + } } }); @@ -85,14 +84,8 @@ int main() { // a shader for the blended quads sg_shader quad_shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "uniform mat4 mvp;\n" "layout(location=0) in vec4 position;\n" "layout(location=1) in vec4 color0;\n" @@ -101,13 +94,20 @@ int main() { " gl_Position = mvp * position;\n" " color = color0;\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" " frag_color = color;\n" - "}" + "}", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + }, }); // one pipeline object per blend-factor combination @@ -161,7 +161,7 @@ int main() { // draw a background quad sg_apply_pipeline(bg_pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, &SG_RANGE(fs_params)); + sg_apply_uniforms(0, &SG_RANGE(fs_params)); sg_draw(0, 4, 1); // draw the blended quads @@ -177,7 +177,7 @@ int main() { sg_apply_pipeline(pips[src][dst]); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } } diff --git a/glfw/bufferoffsets-glfw.c b/glfw/bufferoffsets-glfw.c index 4d0f13d0..53e2b053 100644 --- a/glfw/bufferoffsets-glfw.c +++ b/glfw/bufferoffsets-glfw.c @@ -57,8 +57,8 @@ int main() { // create a shader to render 2D colored shapes sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "layout(location=0) in vec2 pos;" "layout(location=1) in vec3 color0;" "out vec4 color;" @@ -66,13 +66,13 @@ int main() { " gl_Position = vec4(pos, 0.5, 1.0);\n" " color = vec4(color0, 1.0);\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" " frag_color = color;\n" - "}\n" + "}\n", }); // a pipeline state object, default states are fine diff --git a/glfw/cube-glfw.c b/glfw/cube-glfw.c index 99c1a8e2..d6e41692 100644 --- a/glfw/cube-glfw.c +++ b/glfw/cube-glfw.c @@ -85,17 +85,11 @@ int main() { // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc) { - .vs.uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, /* NOTE: since the shader defines explicit attribute locations, we don't need to provide an attribute name lookup table in the shader */ - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "uniform mat4 mvp;\n" "layout(location=0) in vec4 position;\n" "layout(location=1) in vec4 color0;\n" @@ -104,13 +98,20 @@ int main() { " gl_Position = mvp * position;\n" " color = color0;\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" " frag_color = color;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .type = SG_UNIFORMTYPE_MAT4, .glsl_name = "mvp" }, + } + }, }); // create pipeline object @@ -155,7 +156,7 @@ int main() { sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = glfw_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/glfw/dyntex-glfw.c b/glfw/dyntex-glfw.c index 12b7ee28..13aa684c 100644 --- a/glfw/dyntex-glfw.c +++ b/glfw/dyntex-glfw.c @@ -104,49 +104,50 @@ int main() { sg_bindings bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - } + .images[0] = img, + .samplers[0] = smp, }; // a shader to render textured cube sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .source = - "#version 330\n" - "uniform mat4 mvp;\n" - "layout(location=0) in vec4 position;\n" - "layout(location=1) in vec4 color0;\n" - "layout(location=2) in vec2 texcoord0;\n" - "out vec2 uv;" - "out vec4 color;" - "void main() {\n" - " gl_Position = mvp * position;\n" - " uv = texcoord0;\n" - " color = color0;\n" - "}\n", + .vertex_func.source = + "#version 410\n" + "uniform mat4 mvp;\n" + "layout(location=0) in vec4 position;\n" + "layout(location=1) in vec4 color0;\n" + "layout(location=2) in vec2 texcoord0;\n" + "out vec2 uv;" + "out vec4 color;" + "void main() {\n" + " gl_Position = mvp * position;\n" + " uv = texcoord0;\n" + " color = color0;\n" + "}\n", + .fragment_func.source = + "#version 410\n" + "uniform sampler2D tex;\n" + "in vec4 color;\n" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv) * color;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + }, + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, + .glsl_name = "tex", + }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "#version 330\n" - "uniform sampler2D tex;\n" - "in vec4 color;\n" - "in vec2 uv;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " frag_color = texture(tex, uv) * color;\n" - "}\n" - } }); // a pipeline-state-object for the textured cube @@ -202,14 +203,13 @@ int main() { sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = glfw_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); glfwSwapBuffers(glfw_window()); glfwPollEvents(); } - sg_shutdown(); glfwTerminate(); } diff --git a/glfw/imgui-glfw.cc b/glfw/imgui-glfw.cc index 6a0c5af8..2d7d724a 100644 --- a/glfw/imgui-glfw.cc +++ b/glfw/imgui-glfw.cc @@ -120,21 +120,22 @@ int main() { img_desc.height = font_height; img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; img_desc.data.subimage[0][0] = sg_range{ font_pixels, size_t(font_width * font_height * 4) }; - bind.fs.images[0] = sg_make_image(&img_desc); + bind.images[0] = sg_make_image(&img_desc); sg_sampler_desc smp_desc = { }; smp_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; smp_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; - bind.fs.samplers[0] = sg_make_sampler(&smp_desc); + bind.samplers[0] = sg_make_sampler(&smp_desc); // shader object for imgui rendering sg_shader_desc shd_desc = { }; - auto& ub = shd_desc.vs.uniform_blocks[0]; + auto& ub = shd_desc.uniform_blocks[0]; + ub.stage = SG_SHADERSTAGE_VERTEX; ub.size = sizeof(vs_params_t); - ub.uniforms[0].name = "disp_size"; - ub.uniforms[0].type = SG_UNIFORMTYPE_FLOAT2; - shd_desc.vs.source = - "#version 330\n" + ub.glsl_uniforms[0].glsl_name = "disp_size"; + ub.glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT2; + shd_desc.vertex_func.source = + "#version 410\n" "uniform vec2 disp_size;\n" "layout(location=0) in vec2 position;\n" "layout(location=1) in vec2 texcoord0;\n" @@ -146,14 +147,8 @@ int main() { " uv = texcoord0;\n" " color = color0;\n" "}\n"; - shd_desc.fs.images[0].used = true; - shd_desc.fs.samplers[0].used = true; - shd_desc.fs.image_sampler_pairs[0].used = true; - shd_desc.fs.image_sampler_pairs[0].glsl_name = "tex"; - shd_desc.fs.image_sampler_pairs[0].image_slot = 0; - shd_desc.fs.image_sampler_pairs[0].sampler_slot = 0; - shd_desc.fs.source = - "#version 330\n" + shd_desc.fragment_func.source = + "#version 410\n" "uniform sampler2D tex;\n" "in vec2 uv;\n" "in vec4 color;\n" @@ -161,6 +156,12 @@ int main() { "void main() {\n" " frag_color = texture(tex, uv) * color;\n" "}\n"; + shd_desc.images[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.image_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.image_sampler_pairs[0].glsl_name = "tex"; + shd_desc.image_sampler_pairs[0].image_slot = 0; + shd_desc.image_sampler_pairs[0].sampler_slot = 0; sg_shader shd = sg_make_shader(&shd_desc); // pipeline object for imgui rendering @@ -246,7 +247,7 @@ void draw_imgui(ImDrawData* draw_data) { vs_params_t vs_params; vs_params.disp_size.x = ImGui::GetIO().DisplaySize.x; vs_params.disp_size.y = ImGui::GetIO().DisplaySize.y; - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE(vs_params)); + sg_apply_uniforms(0, SG_RANGE(vs_params)); for (int cl_index = 0; cl_index < draw_data->CmdListsCount; cl_index++) { const ImDrawList* cl = draw_data->CmdLists[cl_index]; diff --git a/glfw/inject-glfw.c b/glfw/inject-glfw.c index fdb48a13..5580324b 100644 --- a/glfw/inject-glfw.c +++ b/glfw/inject-glfw.c @@ -153,42 +153,40 @@ int main() { sg_bindings bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { .images[0] = img, .samplers[0] = smp }, + .images[0] = img, + .samplers[0] = smp, }; // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - }, - }, - .source = - "#version 330\n" - "uniform mat4 mvp;\n" - "layout(location=0) in vec4 position;\n" - "layout(location=1) in vec2 texcoord0;\n" - "out vec2 uv;" - "void main() {\n" - " gl_Position = mvp * position;\n" - " uv = texcoord0;\n" - "}\n", + .vertex_func.source = + "#version 410\n" + "uniform mat4 mvp;\n" + "layout(location=0) in vec4 position;\n" + "layout(location=1) in vec2 texcoord0;\n" + "out vec2 uv;" + "void main() {\n" + " gl_Position = mvp * position;\n" + " uv = texcoord0;\n" + "}\n", + .fragment_func.source = + "#version 410\n" + "uniform sampler2D tex;" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 }, + } }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "#version 330\n" - "uniform sampler2D tex;" - "in vec2 uv;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " frag_color = texture(tex, uv);\n" - "}\n" - } + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, }); assert(sg_gl_query_shader_info(shd).prog != 0); @@ -246,7 +244,7 @@ int main() { sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = glfw_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/glfw/instancing-glfw.c b/glfw/instancing-glfw.c index 04476e20..e11cea7a 100644 --- a/glfw/instancing-glfw.c +++ b/glfw/instancing-glfw.c @@ -71,14 +71,8 @@ int main() { // create a shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "uniform mat4 mvp;\n" "layout(location=0) in vec3 position;\n" "layout(location=1) in vec4 color0;\n" @@ -89,13 +83,20 @@ int main() { " gl_Position = mvp * pos;\n" " color = color0;\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" " frag_color = color;\n" "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 }, + } + }, }); // pipeline state object, note the vertex layout definition @@ -180,7 +181,7 @@ int main() { sg_begin_pass(&(sg_pass){ .swapchain = glfw_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 24, cur_num_particles); sg_end_pass(); sg_commit(); diff --git a/glfw/metal-glfw.m b/glfw/metal-glfw.m index cfbafc9f..5fd205ae 100644 --- a/glfw/metal-glfw.m +++ b/glfw/metal-glfw.m @@ -88,7 +88,7 @@ The shader main() function cannot be called 'main' in default function. This can be override with the sg_shader_desc.vs.entry and sg_shader_desc.fs.entry fields. */ - .vs.source = + .vertex_func.source = "#include \n" "using namespace metal;\n" "struct vs_in {\n" @@ -105,7 +105,7 @@ The shader main() function cannot be called 'main' in " outp.color = inp.color;\n" " return outp;\n" "}\n", - .fs.source = + .fragment_func.source = "#include \n" "using namespace metal;\n" "fragment float4 _main(float4 color [[stage_in]]) {\n" diff --git a/glfw/mipmap-glfw.c b/glfw/mipmap-glfw.c index 36edb523..07e8271a 100644 --- a/glfw/mipmap-glfw.c +++ b/glfw/mipmap-glfw.c @@ -133,37 +133,39 @@ int main() { // shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .source = - "#version 330\n" - "uniform mat4 mvp;\n" - "layout(location=0) in vec4 position;\n" - "layout(location=1) in vec2 texcoord0;\n" - "out vec2 uv;\n" - "void main() {\n" - " gl_Position = mvp * position;\n" - " uv = texcoord0;\n" - "}\n" + .vertex_func.source = + "#version 410\n" + "uniform mat4 mvp;\n" + "layout(location=0) in vec4 position;\n" + "layout(location=1) in vec2 texcoord0;\n" + "out vec2 uv;\n" + "void main() {\n" + " gl_Position = mvp * position;\n" + " uv = texcoord0;\n" + "}\n", + .fragment_func.source = + "#version 330\n" + "uniform sampler2D tex;" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + }, + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, + .glsl_name = "tex", }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "#version 330\n" - "uniform sampler2D tex;" - "in vec2 uv;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " frag_color = texture(tex, uv);\n" - "}\n" - } }); // pipeline state @@ -180,7 +182,7 @@ int main() { sg_bindings bind = { .vertex_buffers[0] = vbuf, - .fs.images[0] = img, + .images[0] = img, }; vs_params_t vs_params; float r = 0.0f; @@ -200,9 +202,9 @@ int main() { const float y = ((float)(i / 4) - 1.0f) * -2.0f; hmm_mat4 model = HMM_MultiplyMat4(HMM_Translate(HMM_Vec3(x, y, 0.0f)), rm); vs_params.mvp = HMM_MultiplyMat4(view_proj, model); - bind.fs.samplers[0] = smp[i]; + bind.samplers[0] = smp[i]; sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } sg_end_pass(); diff --git a/glfw/mrt-glfw.c b/glfw/mrt-glfw.c index 6b469280..8aa4d95f 100644 --- a/glfw/mrt-glfw.c +++ b/glfw/mrt-glfw.c @@ -145,14 +145,8 @@ int main() { // a shader to render the cube into offscreen MRT render targets sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0] = { - .size = sizeof(offscreen_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "uniform mat4 mvp;\n" "layout(location=0) in vec4 position;\n" "layout(location=1) in float bright0;\n" @@ -161,8 +155,8 @@ int main() { " gl_Position = mvp * position;\n" " bright = bright0;\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in float bright;\n" "layout(location=0) out vec4 frag_color_0;\n" "layout(location=1) out vec4 frag_color_1;\n" @@ -171,7 +165,14 @@ int main() { " frag_color_0 = vec4(bright, 0.0, 0.0, 1.0);\n" " frag_color_1 = vec4(0.0, bright, 0.0, 1.0);\n" " frag_color_2 = vec4(0.0, 0.0, bright, 1.0);\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(offscreen_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + } }); // resource bindings for offscreen rendering @@ -220,66 +221,63 @@ int main() { // resource bindings to render the fullscreen quad sg_bindings fsq_bind = { .vertex_buffers[0] = quad_vbuf, - .fs.images = { + .images = { [0] = offscreen_attachments_desc.resolves[0].image, [1] = offscreen_attachments_desc.resolves[1].image, [2] = offscreen_attachments_desc.resolves[2].image, }, - .fs.samplers[0] = smp, + .samplers[0] = smp, }; /* a shader to render a fullscreen rectangle, which 'composes' the 3 offscreen render target images onto the screen */ sg_shader fsq_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="offset", .type=SG_UNIFORMTYPE_FLOAT2} - } - }, - .source = - "#version 330\n" - "uniform vec2 offset;" - "layout(location=0) in vec2 pos;\n" - "out vec2 uv0;\n" - "out vec2 uv1;\n" - "out vec2 uv2;\n" - "void main() {\n" - " gl_Position = vec4(pos*2.0-1.0, 0.5, 1.0);\n" - " uv0 = pos + vec2(offset.x, 0.0);\n" - " uv1 = pos + vec2(0.0, offset.y);\n" - " uv2 = pos;\n" - "}\n", + .vertex_func.source = + "#version 410\n" + "uniform vec2 offset;" + "layout(location=0) in vec2 pos;\n" + "out vec2 uv0;\n" + "out vec2 uv1;\n" + "out vec2 uv2;\n" + "void main() {\n" + " gl_Position = vec4(pos*2.0-1.0, 0.5, 1.0);\n" + " uv0 = pos + vec2(offset.x, 0.0);\n" + " uv1 = pos + vec2(0.0, offset.y);\n" + " uv2 = pos;\n" + "}\n", + .fragment_func.source = + "#version 410\n" + "uniform sampler2D tex0;\n" + "uniform sampler2D tex1;\n" + "uniform sampler2D tex2;\n" + "in vec2 uv0;\n" + "in vec2 uv1;\n" + "in vec2 uv2;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " vec3 c0 = texture(tex0, uv0).xyz;\n" + " vec3 c1 = texture(tex1, uv1).xyz;\n" + " vec3 c2 = texture(tex2, uv2).xyz;\n" + " frag_color = vec4(c0 + c1 + c2, 1.0);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "offset", .type = SG_UNIFORMTYPE_FLOAT2 } + } + }, + .images = { + [0].stage = SG_SHADERSTAGE_FRAGMENT, + [1].stage = SG_SHADERSTAGE_FRAGMENT, + [2].stage = SG_SHADERSTAGE_FRAGMENT, + }, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs = { + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex0", .image_slot = 0, .sampler_slot = 0 }, + [1] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex1", .image_slot = 1, .sampler_slot = 0 }, + [2] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex2", .image_slot = 2, .sampler_slot = 0 }, }, - .fs = { - .images = { - [0].used = true, - [1].used = true, - [2].used = true, - }, - .samplers[0].used = true, - .image_sampler_pairs = { - [0] = { .used = true, .glsl_name = "tex0", .image_slot = 0, .sampler_slot = 0 }, - [1] = { .used = true, .glsl_name = "tex1", .image_slot = 1, .sampler_slot = 0 }, - [2] = { .used = true, .glsl_name = "tex2", .image_slot = 2, .sampler_slot = 0 }, - }, - .source = - "#version 330\n" - "uniform sampler2D tex0;\n" - "uniform sampler2D tex1;\n" - "uniform sampler2D tex2;\n" - "in vec2 uv0;\n" - "in vec2 uv1;\n" - "in vec2 uv2;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " vec3 c0 = texture(tex0, uv0).xyz;\n" - " vec3 c1 = texture(tex1, uv1).xyz;\n" - " vec3 c2 = texture(tex2, uv2).xyz;\n" - " frag_color = vec4(c0 + c1 + c2, 1.0);\n" - "}\n" - } }); // the pipeline object for the fullscreen rectangle @@ -299,34 +297,30 @@ int main() { }, .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, .shader = sg_make_shader(&(sg_shader_desc){ - .vs = { - .source = - "#version 330\n" - "layout(location=0) in vec2 pos;\n" - "out vec2 uv;\n" - "void main() {\n" - " gl_Position = vec4(pos*2.0-1.0, 0.5, 1.0);\n" - " uv = pos;\n" - "}\n", - }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "#version 330\n" - "uniform sampler2D tex;\n" - "in vec2 uv;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " frag_color = vec4(texture(tex,uv).xyz, 1.0);\n" - "}\n" - } + .vertex_func.source = + "#version 410\n" + "layout(location=0) in vec2 pos;\n" + "out vec2 uv;\n" + "void main() {\n" + " gl_Position = vec4(pos*2.0-1.0, 0.5, 1.0);\n" + " uv = pos;\n" + "}\n", + .fragment_func.source = + "#version 330\n" + "uniform sampler2D tex;\n" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = vec4(texture(tex,uv).xyz, 1.0);\n" + "}\n", + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, }) }); sg_bindings dbg_bind = { .vertex_buffers[0] = quad_vbuf, - .fs.samplers[0] = smp, + .samplers[0] = smp, // images will be filled right before rendering }; @@ -360,7 +354,7 @@ int main() { }); sg_apply_pipeline(offscreen_pip); sg_apply_bindings(&offscreen_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(offscreen_params)); + sg_apply_uniforms(0, &SG_RANGE(offscreen_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -372,12 +366,12 @@ int main() { }); sg_apply_pipeline(fsq_pip); sg_apply_bindings(&fsq_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(params)); + sg_apply_uniforms(0, &SG_RANGE(params)); sg_draw(0, 4, 1); sg_apply_pipeline(dbg_pip); for (int i = 0; i < 3; i++) { sg_apply_viewport(i*100, 0, 100, 100, false); - dbg_bind.fs.images[0] = offscreen_attachments_desc.resolves[i].image; + dbg_bind.images[0] = offscreen_attachments_desc.resolves[i].image; sg_apply_bindings(&dbg_bind); sg_draw(0, 4, 1); } diff --git a/glfw/multiwindow-glfw.c b/glfw/multiwindow-glfw.c index d0bf8188..799d3ac0 100644 --- a/glfw/multiwindow-glfw.c +++ b/glfw/multiwindow-glfw.c @@ -233,14 +233,8 @@ int main() { }), }; sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 }, - } - }, - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "uniform mat4 mvp;\n" "layout(location=0) in vec4 position;\n" "layout(location=1) in vec4 color0;\n" @@ -249,13 +243,20 @@ int main() { " gl_Position = mvp * position;\n" " color = color0;\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" " frag_color = color;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 }, + } + } }); sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { @@ -300,7 +301,7 @@ int main() { sg_begin_pass(&(sg_pass){ .action = win[i].pass_action, .swapchain = get_swapchain(&win[i])}); sg_apply_pipeline(pip); sg_apply_bindings(&bindings); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); } diff --git a/glfw/noninterleaved-glfw.c b/glfw/noninterleaved-glfw.c index d0fc20cb..9d40db2c 100644 --- a/glfw/noninterleaved-glfw.c +++ b/glfw/noninterleaved-glfw.c @@ -69,14 +69,8 @@ int main() { /* create shader */ sg_shader shd = sg_make_shader(&(sg_shader_desc) { - .vs.uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "uniform mat4 mvp;\n" "layout(location=0) in vec4 position;\n" "layout(location=1) in vec4 color0;\n" @@ -85,13 +79,20 @@ int main() { " gl_Position = mvp * position;\n" " color = color0;\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" " frag_color = color;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + }, }); /* create pipeline object */ @@ -155,7 +156,7 @@ int main() { sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = glfw_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/glfw/offscreen-glfw.c b/glfw/offscreen-glfw.c index 933e8884..e20cf527 100644 --- a/glfw/offscreen-glfw.c +++ b/glfw/offscreen-glfw.c @@ -118,14 +118,8 @@ int main() { // shader for the non-textured cube, rendered in the offscreen pass sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "uniform mat4 mvp;\n" "layout(location=0) in vec4 position;\n" "layout(location=1) in vec4 color0;\n" @@ -134,52 +128,56 @@ int main() { " gl_Position = mvp * position;\n" " color = color0;\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" " frag_color = color;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + } }); // ...and a second shader for rendering a textured cube in the default pass sg_shader default_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .source = - "#version 330\n" - "uniform mat4 mvp;\n" - "layout(location=0) in vec4 position;\n" - "layout(location=1) in vec4 color0;\n" - "layout(location=2) in vec2 texcoord0;\n" - "out vec4 color;\n" - "out vec2 uv;\n" - "void main() {\n" - " gl_Position = mvp * position;\n" - " color = color0;\n" - " uv = texcoord0;\n" - "}\n", + .vertex_func.source = + "#version 330\n" + "uniform mat4 mvp;\n" + "layout(location=0) in vec4 position;\n" + "layout(location=1) in vec4 color0;\n" + "layout(location=2) in vec2 texcoord0;\n" + "out vec4 color;\n" + "out vec2 uv;\n" + "void main() {\n" + " gl_Position = mvp * position;\n" + " color = color0;\n" + " uv = texcoord0;\n" + "}\n", + .fragment_func.source = + "#version 410\n" + "uniform sampler2D tex;\n" + "in vec4 color;\n" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv) + color * 0.5;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "#version 330\n" - "uniform sampler2D tex;\n" - "in vec4 color;\n" - "in vec2 uv;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " frag_color = texture(tex, uv) + color * 0.5;\n" - "}\n" - } + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, }); // pipeline object for offscreen rendering, don't need texcoords here @@ -234,10 +232,8 @@ int main() { sg_bindings default_bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = color_img, - .samplers[0] = smp, - }, + .images[0] = color_img, + .samplers[0] = smp, }; // everything ready, on to the draw loop! @@ -266,7 +262,7 @@ int main() { }); sg_apply_pipeline(offscreen_pip); sg_apply_bindings(&offscreen_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -278,7 +274,7 @@ int main() { }); sg_apply_pipeline(default_pip); sg_apply_bindings(&default_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/glfw/quad-glfw.c b/glfw/quad-glfw.c index 9cb99efb..018bdeb2 100644 --- a/glfw/quad-glfw.c +++ b/glfw/quad-glfw.c @@ -52,8 +52,8 @@ int main() { // create a shader (use vertex attribute locations) sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "layout(location=0) in vec4 position;\n" "layout(location=1) in vec4 color0;\n" "out vec4 color;\n" @@ -61,8 +61,8 @@ int main() { " gl_Position = position;\n" " color = color0;\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" diff --git a/glfw/texcube-glfw.c b/glfw/texcube-glfw.c index 32fae657..440a96fc 100644 --- a/glfw/texcube-glfw.c +++ b/glfw/texcube-glfw.c @@ -101,49 +101,49 @@ int main() { sg_bindings bind = { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - } + .images[0] = img, + .samplers[0] = smp, }; // create shader, note the combined-image-sampler description sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - }, + .vertex_func.source = + "#version 410\n" + "uniform mat4 mvp;\n" + "layout(location = 0) in vec4 position;\n" + "layout(location = 1) in vec4 color0;\n" + "layout(location = 2) in vec2 texcoord0;\n" + "out vec4 color;\n" + "out vec2 uv;" + "void main() {\n" + " gl_Position = mvp * position;\n" + " color = color0;\n" + " uv = texcoord0 * 5.0;\n" + "}\n", + .fragment_func.source = + "#version 410\n" + "uniform sampler2D tex;" + "in vec4 color;\n" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv) * color;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .type=SG_UNIFORMTYPE_MAT4, .glsl_name="mvp" } }, - .source = - "#version 330\n" - "uniform mat4 mvp;\n" - "layout(location = 0) in vec4 position;\n" - "layout(location = 1) in vec4 color0;\n" - "layout(location = 2) in vec2 texcoord0;\n" - "out vec4 color;\n" - "out vec2 uv;" - "void main() {\n" - " gl_Position = mvp * position;\n" - " color = color0;\n" - " uv = texcoord0 * 5.0;\n" - "}\n", }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "#version 330\n" - "uniform sampler2D tex;" - "in vec4 color;\n" - "in vec2 uv;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " frag_color = texture(tex, uv) * color;\n" - "}\n" - } + .images[0] = { .stage = SG_SHADERSTAGE_FRAGMENT }, + .samplers[0] = { .stage = SG_SHADERSTAGE_FRAGMENT }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, + .glsl_name = "tex" + }, }); // create pipeline object @@ -193,7 +193,7 @@ int main() { sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = glfw_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/glfw/triangle-glfw.c b/glfw/triangle-glfw.c index 24a717fc..3859565b 100644 --- a/glfw/triangle-glfw.c +++ b/glfw/triangle-glfw.c @@ -31,8 +31,8 @@ int main() { // a shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "layout(location=0) in vec4 position;\n" "layout(location=1) in vec4 color0;\n" "out vec4 color;\n" @@ -40,8 +40,8 @@ int main() { " gl_Position = position;\n" " color = color0;\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" From 0c653510599e5cd7e8e74acf88b37bbe70c106dc Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 21 Sep 2024 17:29:32 +0200 Subject: [PATCH 11/36] fix vertexpulling-glfw for new binding model --- glfw/vertexpulling-glfw.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/glfw/vertexpulling-glfw.c b/glfw/vertexpulling-glfw.c index dd06cbbc..6ff94ef1 100644 --- a/glfw/vertexpulling-glfw.c +++ b/glfw/vertexpulling-glfw.c @@ -93,14 +93,7 @@ int main() { // a shader where the vertex shader pulls the vertex data from an SSBO sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name = "mvp", .type = SG_UNIFORMTYPE_MAT4 }, - }, - }, - .vs.storage_buffers[0] = { .used = true, .readonly = true }, - .vs.source = + .vertex_func.source = "#version 430\n" "uniform mat4 mvp;\n" "struct vertex_t {\n" @@ -115,13 +108,25 @@ int main() { " gl_Position = mvp * vtx[gl_VertexID].pos;\n" " color = vtx[gl_VertexID].color;\n" "}\n", - .fs.source = + .fragment_func.source = "#version 430\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" " frag_color = color;\n" - "}\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = {.glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 }, + }, + }, + .storage_buffers[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .readonly = true, + .glsl_binding_n = 0, + }, }); // a pipeline object, note that there is no vertex layout specification @@ -139,7 +144,7 @@ int main() { // the storage buffer is bound to the vertex stage sg_bindings bind = { .index_buffer = ibuf, - .vs.storage_buffers[0] = sbuf, + .storage_buffers[0] = sbuf, }; vs_params_t vs_params; @@ -162,7 +167,7 @@ int main() { sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = glfw_swapchain() }); sg_apply_pipeline(pip); sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From e4ddca697e0ddea6c45b34dd4dcfe4b8abb2d4f5 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 21 Sep 2024 17:43:52 +0200 Subject: [PATCH 12/36] start porting webgl2 samples to new binding model --- html5/cube-emsc.c | 42 ++++++++++++----------- html5/quad-emsc.c | 27 ++++++++------- html5/texcube-emsc.c | 78 +++++++++++++++++++++---------------------- html5/triangle-emsc.c | 21 +++++++----- 4 files changed, 89 insertions(+), 79 deletions(-) diff --git a/html5/cube-emsc.c b/html5/cube-emsc.c index cfd04ec3..3476e3b4 100644 --- a/html5/cube-emsc.c +++ b/html5/cube-emsc.c @@ -89,31 +89,35 @@ int main() { // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].name = "position", - [1].name = "color0" - }, - .vs.uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = + .vertex_func.source = + "#version 300 es\n" "uniform mat4 mvp;\n" - "attribute vec4 position;\n" - "attribute vec4 color0;\n" - "varying vec4 color;\n" + "in vec4 position;\n" + "in vec4 color0;\n" + "out vec4 color;\n" "void main() {\n" " gl_Position = mvp * position;\n" " color = color0;\n" "}\n", - .fs.source = + .fragment_func.source = + "#version 300 es\n" "precision mediump float;\n" - "varying vec4 color;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" "void main() {\n" - " gl_FragColor = color;\n" - "}\n" + " frag_color = color;\n" + "}\n", + .attrs = { + [0].glsl_name = "position", + [1].glsl_name = "color0" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + }, }); // create pipeline object @@ -160,7 +164,7 @@ static EM_BOOL draw(double time, void* userdata) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = emsc_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/html5/quad-emsc.c b/html5/quad-emsc.c index 6b3392eb..de99c002 100644 --- a/html5/quad-emsc.c +++ b/html5/quad-emsc.c @@ -54,24 +54,27 @@ int main() { // create a shader sg_shader shd = sg_make_shader(&(sg_shader_desc) { - .attrs = { - [0].name = "position", - [1].name = "color0" - }, - .vs.source = - "attribute vec4 position;\n" - "attribute vec4 color0;\n" - "varying vec4 color;\n" + .vertex_func.source = + "#version 300 es\n" + "in vec4 position;\n" + "in vec4 color0;\n" + "out vec4 color;\n" "void main() {\n" " gl_Position = position;\n" " color = color0;\n" "}\n", - .fs.source = + .fragment_func.source = + "#version 300 es\n" "precision mediump float;\n" - "varying vec4 color;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" "void main() {\n" - " gl_FragColor = color;\n" - "}\n" + " frag_color = color;\n" + "}\n", + .attrs = { + [0].glsl_name = "position", + [1].glsl_name = "color0" + }, }); // a pipeline object (default render state is fine) diff --git a/html5/texcube-emsc.c b/html5/texcube-emsc.c index 43fc3cf3..debb1eeb 100644 --- a/html5/texcube-emsc.c +++ b/html5/texcube-emsc.c @@ -93,58 +93,58 @@ int main() { 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, }; - state.bind.fs.images[0] = sg_make_image(&(sg_image_desc){ + state.bind.images[0] = sg_make_image(&(sg_image_desc){ .width = 4, .height = 4, .data.subimage[0][0] = SG_RANGE(pixels) }); // create a sampler - 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, }); // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].name = "position", - [1].name = "color0", - [2].name = "texcoord0" + .vertex_func.source = + "#version 300 es\n" + "uniform mat4 mvp;\n" + "layout(location = 0) in vec4 position;\n" + "layout(location = 1) in vec4 color0;\n" + "layout(location = 2) in vec2 texcoord0;\n" + "out vec4 color;\n" + "out vec2 uv;" + "void main() {\n" + " gl_Position = mvp * position;\n" + " color = color0;\n" + " uv = texcoord0 * 5.0;\n" + "}\n", + .fragment_func.source = + "#version 300 es\n" + "precision mediump float;\n" + "uniform sampler2D tex;\n" + "in vec4 color;\n" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv) * color;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } }, - .vs = { - .uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .source = - "uniform mat4 mvp;\n" - "attribute vec4 position;\n" - "attribute vec4 color0;\n" - "attribute vec2 texcoord0;\n" - "varying vec4 color;\n" - "varying vec2 uv;" - "void main() {\n" - " gl_Position = mvp * position;\n" - " color = color0;\n" - " uv = texcoord0 * 5.0;\n" - "}\n", + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, + .glsl_name = "tex", }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "precision mediump float;\n" - "uniform sampler2D tex;\n" - "varying vec4 color;\n" - "varying vec2 uv;\n" - "void main() {\n" - " gl_FragColor = texture2D(tex, uv) * color;\n" - "}\n" - } }); // create pipeline object @@ -194,7 +194,7 @@ static EM_BOOL draw(double time, void* userdata) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = emsc_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/html5/triangle-emsc.c b/html5/triangle-emsc.c index 82148d5e..338cecfe 100644 --- a/html5/triangle-emsc.c +++ b/html5/triangle-emsc.c @@ -42,22 +42,25 @@ int main() { // create a shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ .attrs = { - [0].name = "position", - [1].name = "color0" + [0].glsl_name = "position", + [1].glsl_name = "color0" }, - .vs.source = - "attribute vec4 position;\n" - "attribute vec4 color0;\n" - "varying vec4 color;\n" + .vertex_func.source = + "#version 300 es\n" + "in vec4 position;\n" + "in vec4 color0;\n" + "out vec4 color;\n" "void main() {\n" " gl_Position = position;\n" " color = color0;\n" "}\n", - .fs.source = + .fragment_func.source = + "#version 300 es\n" "precision mediump float;\n" - "varying vec4 color;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" "void main() {\n" - " gl_FragColor = color;\n" + " frag_color = color;\n" "}\n" }); From 7282bec19eb099a8240f7efd55fc6f15d7141652 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 22 Sep 2024 11:58:17 +0200 Subject: [PATCH 13/36] webgl2 sample update wip --- html5/arraytex-emsc.c | 108 ++++++++++++++++++------------------- html5/blend-emsc.c | 77 +++++++++++++------------- html5/bufferoffsets-emsc.c | 21 ++++---- 3 files changed, 102 insertions(+), 104 deletions(-) diff --git a/html5/arraytex-emsc.c b/html5/arraytex-emsc.c index 80b8fc3d..fd6dd966 100644 --- a/html5/arraytex-emsc.c +++ b/html5/arraytex-emsc.c @@ -129,66 +129,66 @@ int main() { state.bind = (sg_bindings){ .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - } + .images[0] = img, + .samplers[0] = smp, }; // shader to sample from array texture sg_shader shd = sg_make_shader(&(sg_shader_desc){ + .vertex_func.source = + "#version 300 es\n" + "uniform mat4 mvp;\n" + "uniform vec2 offset0;\n" + "uniform vec2 offset1;\n" + "uniform vec2 offset2;\n" + "in vec4 position;\n" + "in vec2 texcoord0;\n" + "out vec3 uv0;\n" + "out vec3 uv1;\n" + "out vec3 uv2;\n" + "void main() {\n" + " gl_Position = mvp * position;\n" + " uv0 = vec3(texcoord0 + offset0, 0.0);\n" + " uv1 = vec3(texcoord0 + offset1, 1.0);\n" + " uv2 = vec3(texcoord0 + offset2, 2.0);\n" + "}\n", + .fragment_func.source = + "#version 300 es\n" + "precision mediump float;\n" + "precision lowp sampler2DArray;\n" + "uniform sampler2DArray tex;\n" + "in vec3 uv0;\n" + "in vec3 uv1;\n" + "in vec3 uv2;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " vec4 c0 = texture(tex, uv0);\n" + " vec4 c1 = texture(tex, uv1);\n" + " vec4 c2 = texture(tex, uv2);\n" + " frag_color = vec4(c0.xyz + c1.xyz + c2.xyz, 1.0);\n" + "}\n", .attrs = { - [0].name = "position", - [1].name = "texcoord0" + [0].glsl_name = "position", + [1].glsl_name = "texcoord0" }, - .vs = { - .uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 }, - [1] = { .name="offset0", .type=SG_UNIFORMTYPE_FLOAT2 }, - [2] = { .name="offset1", .type=SG_UNIFORMTYPE_FLOAT2 }, - [3] = { .name="offset2", .type=SG_UNIFORMTYPE_FLOAT2 } - } - }, - .source = - "#version 300 es\n" - "uniform mat4 mvp;\n" - "uniform vec2 offset0;\n" - "uniform vec2 offset1;\n" - "uniform vec2 offset2;\n" - "in vec4 position;\n" - "in vec2 texcoord0;\n" - "out vec3 uv0;\n" - "out vec3 uv1;\n" - "out vec3 uv2;\n" - "void main() {\n" - " gl_Position = mvp * position;\n" - " uv0 = vec3(texcoord0 + offset0, 0.0);\n" - " uv1 = vec3(texcoord0 + offset1, 1.0);\n" - " uv2 = vec3(texcoord0 + offset2, 2.0);\n" - "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 }, + [1] = { .glsl_name = "offset0", .type = SG_UNIFORMTYPE_FLOAT2 }, + [2] = { .glsl_name = "offset1", .type = SG_UNIFORMTYPE_FLOAT2 }, + [3] = { .glsl_name = "offset2", .type = SG_UNIFORMTYPE_FLOAT2 } + } + }, + .images[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_type = SG_IMAGETYPE_ARRAY }, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .glsl_name = "tex", + .image_slot = 0, + .sampler_slot = 0 }, - .fs = { - .images[0] = { .used = true, .image_type = SG_IMAGETYPE_ARRAY }, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "#version 300 es\n" - "precision mediump float;\n" - "precision lowp sampler2DArray;\n" - "uniform sampler2DArray tex;\n" - "in vec3 uv0;\n" - "in vec3 uv1;\n" - "in vec3 uv2;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " vec4 c0 = texture(tex, uv0);\n" - " vec4 c1 = texture(tex, uv1);\n" - " vec4 c2 = texture(tex, uv2);\n" - " frag_color = vec4(c0.xyz + c1.xyz + c2.xyz, 1.0);\n" - "}\n" - } }); // create pipeline object @@ -241,7 +241,7 @@ static EM_BOOL draw(double time, void* userdata) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = emsc_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/html5/blend-emsc.c b/html5/blend-emsc.c index 3138ee74..eb7fcece 100644 --- a/html5/blend-emsc.c +++ b/html5/blend-emsc.c @@ -64,29 +64,28 @@ int main() { // a shader for the fullscreen background quad sg_shader bg_shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].name = "position" - }, - .vs.source = - "attribute vec2 position;\n" + .vertex_func.source = + "#version 300 es\n" + "layout(location=0) in vec2 position;\n" "void main() {\n" " gl_Position = vec4(position, 0.5, 1.0);\n" "}\n", - .fs = { - .uniform_blocks[0] = { - .size = sizeof(fs_params_t), - .uniforms = { - [0] = { .name="tick", .type=SG_UNIFORMTYPE_FLOAT } - } + .fragment_func.source = + "#version 300 es\n" + "precision mediump float;\n" + "uniform float tick;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " vec2 xy = fract((gl_FragCoord.xy-vec2(tick)) / 50.0);\n" + " frag_color = vec4(vec3(xy.x*xy.y), 1.0);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .size = sizeof(fs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "tick", .type = SG_UNIFORMTYPE_FLOAT } }, - .source = - "precision mediump float;\n" - "uniform float tick;\n" - "void main() {\n" - " vec2 xy = fract((gl_FragCoord.xy-vec2(tick)) / 50.0);\n" - " gl_FragColor = vec4(vec3(xy.x*xy.y), 1.0);\n" - "}\n" - } + }, }); // a pipeline state object for rendering the background quad @@ -103,31 +102,31 @@ int main() { // a shader for the blended quads sg_shader quad_shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].name = "position", - [1].name = "color0" - }, - .vs.uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = + .vertex_func.source = + "#version 300 es\n" "uniform mat4 mvp;\n" - "attribute vec4 position;\n" - "attribute vec4 color0;\n" - "varying vec4 color;\n" + "layout(location=0) in vec4 position;\n" + "layout(location=1) in vec4 color0;\n" + "out vec4 color;\n" "void main() {\n" " gl_Position = mvp * position;" " color = color0;\n" "}\n", - .fs.source = + .fragment_func.source = + "#version 300 es\n" "precision mediump float;\n" - "varying vec4 color;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" "void main() {\n" - " gl_FragColor = color;\n" - "}" + " frag_color = color;\n" + "}", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + }, }); // one pipeline object per blend-factor combination @@ -200,7 +199,7 @@ static EM_BOOL draw(double time, void* userdata) { // draw a background quad sg_apply_pipeline(state.bg_pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, &SG_RANGE(state.fs_params)); + sg_apply_uniforms(0, &SG_RANGE(state.fs_params)); sg_draw(0, 4, 1); // draw the blended quads @@ -216,7 +215,7 @@ static EM_BOOL draw(double time, void* userdata) { if (state.pips[src][dst].id != SG_INVALID_ID) { sg_apply_pipeline(state.pips[src][dst]); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(state.vs_params)); + sg_apply_uniforms(0, &SG_RANGE(state.vs_params)); sg_draw(0, 4, 1); } } diff --git a/html5/bufferoffsets-emsc.c b/html5/bufferoffsets-emsc.c index e75b3142..0a952d77 100644 --- a/html5/bufferoffsets-emsc.c +++ b/html5/bufferoffsets-emsc.c @@ -63,23 +63,22 @@ int main() { // create a shader to render 2D colored shapes sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].name = "pos", - [1].name = "color0" - }, - .vs.source = - "attribute vec2 pos;" - "attribute vec3 color0;" - "varying vec4 color;" + .vertex_func.source = + "#version 300 es\n" + "layout(location=0) in vec2 pos;" + "layout(location=1) in vec3 color0;" + "out vec4 color;" "void main() {" " gl_Position = vec4(pos, 0.5, 1.0);\n" " color = vec4(color0, 1.0);\n" "}\n", - .fs.source = + .fragment_func.source = + "#version 300 es\n", "precision mediump float;\n" - "varying vec4 color;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" "void main() {\n" - " gl_FragColor = color;\n" + " frag_color = color;\n" "}\n" }); From 53ffb78a18e1fc2345ab8e53299ba576d40a5bd7 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 22 Sep 2024 14:02:48 +0200 Subject: [PATCH 14/36] emscripten samples bindings cleanup wip --- html5/bufferoffsets-emsc.c | 36 +++++-- html5/dyntex-emsc.c | 80 ++++++++------- html5/imgui-emsc.cc | 76 +++++++------- html5/inject-emsc.c | 66 ++++++------ html5/instancing-emsc.c | 46 +++++---- html5/mipmap-emsc.c | 66 ++++++------ html5/mrt-emsc.c | 193 +++++++++++++++++------------------- html5/noninterleaved-emsc.c | 42 ++++---- html5/offscreen-emsc.c | 142 ++++++++++++++++---------- 9 files changed, 398 insertions(+), 349 deletions(-) diff --git a/html5/bufferoffsets-emsc.c b/html5/bufferoffsets-emsc.c index 0a952d77..dd277d46 100644 --- a/html5/bufferoffsets-emsc.c +++ b/html5/bufferoffsets-emsc.c @@ -63,23 +63,41 @@ int main() { // create a shader to render 2D colored shapes sg_shader shd = sg_make_shader(&(sg_shader_desc){ + .attrs = { + [0].glsl_name = "pos", + [1].glsl_name = "color0", + }, .vertex_func.source = - "#version 300 es\n" - "layout(location=0) in vec2 pos;" - "layout(location=1) in vec3 color0;" - "out vec4 color;" + "attribute vec2 pos;" + "attribute vec3 color0;" + "varying vec4 color;" "void main() {" " gl_Position = vec4(pos, 0.5, 1.0);\n" " color = vec4(color0, 1.0);\n" "}\n", + // FIXME: for some reason using WebGL2 shaders causes corruption + //"#version 300 es\n" + //"in vec2 pos;" + //"in vec3 color0;" + //"out vec4 color;" + //"void main() {" + //" gl_Position = vec4(pos, 0.5, 1.0);\n" + //" color = vec4(color0, 1.0);\n" + //"}\n", .fragment_func.source = - "#version 300 es\n", "precision mediump float;\n" - "in vec4 color;\n" - "out vec4 frag_color;\n" + "varying vec4 color;\n" "void main() {\n" - " frag_color = color;\n" - "}\n" + " gl_FragColor = color;\n" + "}\n", + // FIXME! + //"#version 300 es\n", + //"precision mediump float;\n" + //"in vec4 color;\n" + //"out vec4 frag_color;\n" + //"void main() {\n" + //" frag_color = color;\n" + //"}\n" }); // a pipeline state object, default states are fine diff --git a/html5/dyntex-emsc.c b/html5/dyntex-emsc.c index b67e65df..71265bea 100644 --- a/html5/dyntex-emsc.c +++ b/html5/dyntex-emsc.c @@ -117,52 +117,50 @@ int main() { state.bind = (sg_bindings){ .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - } + .images[0] = img, + .samplers[0] = smp, }; // a shader to render textured cube sg_shader shd = sg_make_shader(&(sg_shader_desc){ + .vertex_func.source = + "#version 300 es\n" + "uniform mat4 mvp;\n" + "in vec4 position;\n" + "in vec4 color0;\n" + "in vec2 texcoord0;\n" + "out vec2 uv;" + "out vec4 color;" + "void main() {\n" + " gl_Position = mvp * position;\n" + " uv = texcoord0;\n" + " color = color0;\n" + "}\n", + .fragment_func.source = + "#version 300 es\n" + "precision mediump float;\n" + "uniform sampler2D tex;\n" + "in vec4 color;\n" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv) * color;\n" + "}\n", .attrs = { - [0].name = "position", - [1].name = "color0", - [2].name = "texcoord0" + [0].glsl_name = "position", + [1].glsl_name = "color0", + [2].glsl_name = "texcoord0" }, - .vs = { - .uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .source = - "uniform mat4 mvp;\n" - "attribute vec4 position;\n" - "attribute vec4 color0;\n" - "attribute vec2 texcoord0;\n" - "varying vec2 uv;" - "varying vec4 color;" - "void main() {\n" - " gl_Position = mvp * position;\n" - " uv = texcoord0;\n" - " color = color0;\n" - "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "precision mediump float;\n" - "uniform sampler2D tex;\n" - "varying vec4 color;\n" - "varying vec2 uv;\n" - "void main() {\n" - " gl_FragColor = texture2D(tex, uv) * color;\n" - "}\n" - } + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, }); // a pipeline-state-object for the textured cube @@ -209,13 +207,13 @@ static EM_BOOL draw(double time, void* userdata) { game_of_life_update(); // update the dynamic image - sg_update_image(state.bind.fs.images[0], &(sg_image_data){ .subimage[0][0] = SG_RANGE(pixels) }); + sg_update_image(state.bind.images[0], &(sg_image_data){ .subimage[0][0] = SG_RANGE(pixels) }); // draw pass sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = emsc_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/html5/imgui-emsc.cc b/html5/imgui-emsc.cc index 0dbadf12..344a5848 100644 --- a/html5/imgui-emsc.cc +++ b/html5/imgui-emsc.cc @@ -161,7 +161,7 @@ int main() { unsigned char* font_pixels; int font_width, font_height; io.Fonts->GetTexDataAsRGBA32(&font_pixels, &font_width, &font_height); - bind.fs.images[0] = sg_make_image({ + bind.images[0] = sg_make_image({ .width = font_width, .height = font_height, .pixel_format = SG_PIXELFORMAT_RGBA8, @@ -170,51 +170,51 @@ int main() { .size = size_t(font_width * font_height * 4) } }); - bind.fs.samplers[0] = sg_make_sampler({ + bind.samplers[0] = sg_make_sampler({ .wrap_u = SG_WRAP_CLAMP_TO_EDGE, .wrap_v = SG_WRAP_CLAMP_TO_EDGE, }); // shader object for imgui rendering sg_shader shd = sg_make_shader({ + .vertex_func.source = + "#version 300 es\n" + "uniform vec2 disp_size;\n" + "in vec2 position;\n" + "in vec2 texcoord0;\n" + "in vec4 color0;\n" + "out vec2 uv;\n" + "out vec4 color;\n" + "void main() {\n" + " gl_Position = vec4(((position/disp_size)-0.5)*vec2(2.0,-2.0), 0.5, 1.0);\n" + " uv = texcoord0;\n" + " color = color0;\n" + "}\n", + .fragment_func.source = + "#version 300 es\n" + "precision mediump float;" + "uniform sampler2D tex;\n" + "in vec2 uv;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv) * color;\n" + "}\n", .attrs = { - [0].name = "position", - [1].name = "texcoord0", - [2].name = "color0" + [0].glsl_name = "position", + [1].glsl_name = "texcoord0", + [2].glsl_name = "color0" }, - .vs = { - .uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="disp_size", .type=SG_UNIFORMTYPE_FLOAT2} - } - }, - .source = - "uniform vec2 disp_size;\n" - "attribute vec2 position;\n" - "attribute vec2 texcoord0;\n" - "attribute vec4 color0;\n" - "varying vec2 uv;\n" - "varying vec4 color;\n" - "void main() {\n" - " gl_Position = vec4(((position/disp_size)-0.5)*vec2(2.0,-2.0), 0.5, 1.0);\n" - " uv = texcoord0;\n" - " color = color0;\n" - "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "disp_size", .type = SG_UNIFORMTYPE_FLOAT2} + } }, - .fs = { - .images[0] = { .used = true }, - .samplers[0] = { .used = true }, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "precision mediump float;" - "uniform sampler2D tex;\n" - "varying vec2 uv;\n" - "varying vec4 color;\n" - "void main() {\n" - " gl_FragColor = texture2D(tex, uv) * color;\n" - "}\n" - } + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, }); // pipeline object for imgui rendering @@ -316,7 +316,7 @@ void draw_imgui(ImDrawData* draw_data) { vs_params.disp_size.x = ImGui::GetIO().DisplaySize.x; vs_params.disp_size.y = ImGui::GetIO().DisplaySize.y; sg_apply_pipeline(pip); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE(vs_params)); + sg_apply_uniforms(0, SG_RANGE(vs_params)); for (int cl_index = 0; cl_index < draw_data->CmdListsCount; cl_index++) { const ImDrawList* cl = draw_data->CmdLists[cl_index]; diff --git a/html5/inject-emsc.c b/html5/inject-emsc.c index 7c385c2a..45ac5b48 100644 --- a/html5/inject-emsc.c +++ b/html5/inject-emsc.c @@ -129,7 +129,7 @@ int main() { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IMG_WIDTH, IMG_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); } sg_reset_state_cache(); - state.bind.fs.images[0] = sg_make_image(&img_desc); + state.bind.images[0] = sg_make_image(&img_desc); // create a GL sampler object sg_sampler_desc smp_desc = { @@ -144,43 +144,43 @@ int main() { glSamplerParameteri(smp_desc.gl_sampler, GL_TEXTURE_WRAP_S, GL_REPEAT); glSamplerParameteri(smp_desc.gl_sampler, GL_TEXTURE_WRAP_T, GL_REPEAT); sg_reset_state_cache(); - state.bind.fs.samplers[0] = sg_make_sampler(&smp_desc); + state.bind.samplers[0] = sg_make_sampler(&smp_desc); // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ + .vertex_func.source = + "#version 300 es\n" + "uniform mat4 mvp;\n" + "in vec4 position;\n" + "in vec2 texcoord0;\n" + "out vec2 uv;" + "void main() {\n" + " gl_Position = mvp * position;\n" + " uv = texcoord0;\n" + "}\n", + .fragment_func.source = + "#version 300 es\n" + "precision mediump float;\n" + "uniform sampler2D tex;\n" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv);\n" + "}\n", .attrs = { - [0].name = "position", - [1].name = "texcoord0" + [0].glsl_name = "position", + [1].glsl_name = "texcoord0" }, - .vs = { - .uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name="mvp", .type=SG_UNIFORMTYPE_MAT4 } }, - .source = - "uniform mat4 mvp;\n" - "attribute vec4 position;\n" - "attribute vec2 texcoord0;\n" - "varying vec2 uv;" - "void main() {\n" - " gl_Position = mvp * position;\n" - " uv = texcoord0;\n" - "}\n", - }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "precision mediump float;\n" - "uniform sampler2D tex;\n" - "varying vec2 uv;\n" - "void main() {\n" - " gl_FragColor = texture2D(tex, uv);\n" - "}\n" }, + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, }); // create pipeline object @@ -230,13 +230,13 @@ static EM_BOOL draw(double time, void* userdata) { } } state.counter++; - sg_update_image(state.bind.fs.images[0], &(sg_image_data){ .subimage[0][0] = SG_RANGE(pixels) }); + sg_update_image(state.bind.images[0], &(sg_image_data){ .subimage[0][0] = SG_RANGE(pixels) }); // ...and draw sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = emsc_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/html5/instancing-emsc.c b/html5/instancing-emsc.c index fb479499..84ae9b04 100644 --- a/html5/instancing-emsc.c +++ b/html5/instancing-emsc.c @@ -88,34 +88,38 @@ int main() { // create a shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].name = "position", - [1].name = "color0", - [2].name = "instance_pos" - }, - .vs.uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = + .vertex_func.source = + "#version 300 es\n" "uniform mat4 mvp;\n" - "attribute vec3 position;\n" - "attribute vec4 color0;\n" - "attribute vec3 instance_pos;\n" - "varying vec4 color;\n" + "in vec3 position;\n" + "in vec4 color0;\n" + "in vec3 instance_pos;\n" + "out vec4 color;\n" "void main() {\n" " vec4 pos = vec4(position + instance_pos, 1.0);" " gl_Position = mvp * pos;\n" " color = color0;\n" "}\n", - .fs.source = + .fragment_func.source = + "#version 300 es\n" "precision mediump float;\n" - "varying vec4 color;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" "void main() {\n" - " gl_FragColor = color;\n" - "}\n" + " frag_color = color;\n" + "}\n", + .attrs = { + [0].glsl_name = "position", + [1].glsl_name = "color0", + [2].glsl_name = "instance_pos" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name="mvp", .type=SG_UNIFORMTYPE_MAT4 } + } + }, }); // pipeline state object, note the vertex attribute definition @@ -192,7 +196,7 @@ static EM_BOOL draw(double time, void* userdata) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = emsc_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 24, state.cur_num_particles); sg_end_pass(); sg_commit(); diff --git a/html5/mipmap-emsc.c b/html5/mipmap-emsc.c index be05d1e4..f10ce486 100644 --- a/html5/mipmap-emsc.c +++ b/html5/mipmap-emsc.c @@ -90,7 +90,7 @@ int main() { } // create a single image and 12 samplers - state.bind.fs.images[0] = sg_make_image(&(sg_image_desc){ + state.bind.images[0] = sg_make_image(&(sg_image_desc){ .width = 256, .height = 256, .num_mipmaps = 9, @@ -142,39 +142,39 @@ int main() { // shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ + .vertex_func.source = + "#version 300 es\n" + "uniform mat4 mvp;\n" + "in vec4 position;\n" + "in vec2 texcoord0;\n" + "out vec2 uv;\n" + "void main() {\n" + " gl_Position = mvp * position;\n" + " uv = texcoord0;\n" + "}\n", + .fragment_func.source = + "#version 300 es\n" + "precision mediump float;" + "uniform sampler2D tex;" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv);\n" + "}\n", .attrs = { - [0].name = "position", - [1].name = "texcoord0" + [0].glsl_name = "position", + [1].glsl_name = "texcoord0" }, - .vs = { - .uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .source = - "uniform mat4 mvp;\n" - "attribute vec4 position;\n" - "attribute vec2 texcoord0;\n" - "varying vec2 uv;\n" - "void main() {\n" - " gl_Position = mvp * position;\n" - " uv = texcoord0;\n" - "}\n" + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "precision mediump float;" - "uniform sampler2D tex;" - "varying vec2 uv;\n" - "void main() {\n" - " gl_FragColor = texture2D(tex, uv);\n" - "}\n" - } + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, }); // pipeline state @@ -214,9 +214,9 @@ static EM_BOOL draw(double time, void* userdata) { hmm_mat4 model = HMM_MultiplyMat4(HMM_Translate(HMM_Vec3(x, y, 0.0f)), rm); vs_params.mvp = HMM_MultiplyMat4(view_proj, model); - state.bind.fs.samplers[0] = state.smp[i]; + state.bind.samplers[0] = state.smp[i]; sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } sg_end_pass(); diff --git a/html5/mrt-emsc.c b/html5/mrt-emsc.c index 74102c3d..1c9b4dc0 100644 --- a/html5/mrt-emsc.c +++ b/html5/mrt-emsc.c @@ -175,17 +175,7 @@ int main() { // a shader to render the cube into offscreen MRT render targets sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].name = "position", - [1].name = "bright0" - }, - .vs.uniform_blocks[0] = { - .size = sizeof(offscreen_params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = + .vertex_func.source = "#version 300 es\n" "uniform mat4 mvp;\n" "in vec4 position;\n" @@ -195,7 +185,7 @@ int main() { " gl_Position = mvp * position;\n" " bright = bright0;\n" "}\n", - .fs.source = + .fragment_func.source = "#version 300 es\n" "precision mediump float;\n" "in float bright;\n" @@ -206,7 +196,18 @@ int main() { " frag_color_0 = vec4(bright, 0.0, 0.0, 1.0);\n" " frag_color_1 = vec4(0.0, bright, 0.0, 1.0);\n" " frag_color_2 = vec4(0.0, 0.0, bright, 1.0);\n" - "}\n" + "}\n", + .attrs = { + [0].glsl_name = "position", + [1].glsl_name = "bright0" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(offscreen_params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + }, }); // pipeline object for the offscreen-rendered cube @@ -247,70 +248,65 @@ int main() { // resource bindings to render the fullscreen quad state.display.fsq_bind = (sg_bindings){ .vertex_buffers[0] = quad_buf, - .fs = { - .images = { - [0] = state.offscreen.attachments_desc.resolves[0].image, - [1] = state.offscreen.attachments_desc.resolves[1].image, - [2] = state.offscreen.attachments_desc.resolves[2].image, - }, - .samplers[0] = smp, - } + .images = { + [0] = state.offscreen.attachments_desc.resolves[0].image, + [1] = state.offscreen.attachments_desc.resolves[1].image, + [2] = state.offscreen.attachments_desc.resolves[2].image, + }, + .samplers[0] = smp, }; // a shader to render a fullscreen rectangle, which 'composes' // the 3 offscreen render target images onto the screen sg_shader fsq_shd = sg_make_shader(&(sg_shader_desc){ - .attrs[0].name = "pos", - .vs = { - .uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="offset", .type=SG_UNIFORMTYPE_FLOAT2} - } - }, - .source = - "#version 300 es\n" - "uniform vec2 offset;" - "in vec2 pos;\n" - "out vec2 uv0;\n" - "out vec2 uv1;\n" - "out vec2 uv2;\n" - "void main() {\n" - " gl_Position = vec4(pos*2.0-1.0, 0.5, 1.0);\n" - " uv0 = pos + vec2(offset.x, 0.0);\n" - " uv1 = pos + vec2(0.0, offset.y);\n" - " uv2 = pos;\n" - "}\n", + .vertex_func.source = + "#version 300 es\n" + "uniform vec2 offset;" + "in vec2 pos;\n" + "out vec2 uv0;\n" + "out vec2 uv1;\n" + "out vec2 uv2;\n" + "void main() {\n" + " gl_Position = vec4(pos*2.0-1.0, 0.5, 1.0);\n" + " uv0 = pos + vec2(offset.x, 0.0);\n" + " uv1 = pos + vec2(0.0, offset.y);\n" + " uv2 = pos;\n" + "}\n", + .fragment_func.source = + "#version 300 es\n" + "precision mediump float;\n" + "uniform sampler2D tex0;\n" + "uniform sampler2D tex1;\n" + "uniform sampler2D tex2;\n" + "in vec2 uv0;\n" + "in vec2 uv1;\n" + "in vec2 uv2;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " vec3 c0 = texture(tex0, uv0).xyz;\n" + " vec3 c1 = texture(tex1, uv1).xyz;\n" + " vec3 c2 = texture(tex2, uv2).xyz;\n" + " frag_color = vec4(c0 + c1 + c2, 1.0);\n" + "}\n", + .attrs[0].glsl_name = "pos", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "offset", .type = SG_UNIFORMTYPE_FLOAT2} + } + }, + .images = { + [0].stage = SG_SHADERSTAGE_FRAGMENT, + [1].stage = SG_SHADERSTAGE_FRAGMENT, + [2].stage = SG_SHADERSTAGE_FRAGMENT, + }, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs = { + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex0", .image_slot = 0, .sampler_slot = 0 }, + [1] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex1", .image_slot = 1, .sampler_slot = 0 }, + [2] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex2", .image_slot = 2, .sampler_slot = 0 }, }, - .fs = { - .images = { - [0].used = true, - [1].used = true, - [2].used = true, - }, - .samplers[0].used = true, - .image_sampler_pairs = { - [0] = { .used = true, .glsl_name = "tex0", .image_slot = 0, .sampler_slot = 0 }, - [1] = { .used = true, .glsl_name = "tex1", .image_slot = 1, .sampler_slot = 0 }, - [2] = { .used = true, .glsl_name = "tex2", .image_slot = 2, .sampler_slot = 0 }, - }, - .source = - "#version 300 es\n" - "precision mediump float;\n" - "uniform sampler2D tex0;\n" - "uniform sampler2D tex1;\n" - "uniform sampler2D tex2;\n" - "in vec2 uv0;\n" - "in vec2 uv1;\n" - "in vec2 uv2;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " vec3 c0 = texture(tex0, uv0).xyz;\n" - " vec3 c1 = texture(tex1, uv1).xyz;\n" - " vec3 c2 = texture(tex2, uv2).xyz;\n" - " frag_color = vec4(c0 + c1 + c2, 1.0);\n" - "}\n" - } }); // the pipeline object for the fullscreen rectangle @@ -328,37 +324,32 @@ int main() { }, .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, .shader = sg_make_shader(&(sg_shader_desc){ - .attrs[0].name = "pos", - .vs = { - .source = - "#version 300 es\n" - "uniform vec2 offset;" - "in vec2 pos;\n" - "out vec2 uv;\n" - "void main() {\n" - " gl_Position = vec4(pos*2.0-1.0, 0.5, 1.0);\n" - " uv = pos;\n" - "}\n", - }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "#version 300 es\n" - "precision mediump float;\n" - "uniform sampler2D tex;\n" - "in vec2 uv;\n" - "out vec4 frag_color;\n" - "void main() {\n" - " frag_color = vec4(texture(tex,uv).xyz, 1.0);\n" - "}\n" - }, + .vertex_func.source = + "#version 300 es\n" + "in vec2 pos;\n" + "out vec2 uv;\n" + "void main() {\n" + " gl_Position = vec4(pos*2.0-1.0, 0.5, 1.0);\n" + " uv = pos;\n" + "}\n", + .fragment_func.source = + "#version 300 es\n" + "precision mediump float;\n" + "uniform sampler2D tex;\n" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = vec4(texture(tex,uv).xyz, 1.0);\n" + "}\n", + .attrs[0].glsl_name = "pos", + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, }) }); state.display.dbg_bind = (sg_bindings) { .vertex_buffers[0] = quad_buf, - .fs.samplers[0] = smp, + .samplers[0] = smp, // images will be filled right before rendering }; @@ -398,7 +389,7 @@ static EM_BOOL draw(double time, void* userdata) { }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(offscreen_params)); + sg_apply_uniforms(0, &SG_RANGE(offscreen_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -410,12 +401,12 @@ static EM_BOOL draw(double time, void* userdata) { }); sg_apply_pipeline(state.display.fsq_pip); sg_apply_bindings(&state.display.fsq_bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(params)); + sg_apply_uniforms(0, &SG_RANGE(params)); sg_draw(0, 4, 1); sg_apply_pipeline(state.display.dbg_pip); for (int i = 0; i < 3; i++) { sg_apply_viewport(i*100, 0, 100, 100, false); - state.display.dbg_bind.fs.images[0] = state.offscreen.attachments_desc.resolves[i].image; + state.display.dbg_bind.images[0] = state.offscreen.attachments_desc.resolves[i].image; sg_apply_bindings(&state.display.dbg_bind); sg_draw(0, 4, 1); } diff --git a/html5/noninterleaved-emsc.c b/html5/noninterleaved-emsc.c index 125fbea4..d320a233 100644 --- a/html5/noninterleaved-emsc.c +++ b/html5/noninterleaved-emsc.c @@ -79,31 +79,35 @@ int main() { // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .attrs = { - [0].name = "position", - [1].name = "color0" - }, - .vs.uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = + .vertex_func.source = + "#version 300 es\n" "uniform mat4 mvp;\n" - "attribute vec4 position;\n" - "attribute vec4 color0;\n" - "varying vec4 color;\n" + "in vec4 position;\n" + "in vec4 color0;\n" + "out vec4 color;\n" "void main() {\n" " gl_Position = mvp * position;\n" " color = color0;\n" "}\n", - .fs.source = + .fragment_func.source = + "#version 300 es\n" "precision mediump float;\n" - "varying vec4 color;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" "void main() {\n" - " gl_FragColor = color;\n" - "}\n" + " frag_color = color;\n" + "}\n", + .attrs = { + [0].glsl_name = "position", + [1].glsl_name = "color0" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + }, }); // create pipeline object @@ -168,7 +172,7 @@ static EM_BOOL draw(double time, void* userdata) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = emsc_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/html5/offscreen-emsc.c b/html5/offscreen-emsc.c index 9394bdaf..0c3eb124 100644 --- a/html5/offscreen-emsc.c +++ b/html5/offscreen-emsc.c @@ -127,17 +127,7 @@ int main() { // shader for the non-textured cube, rendered in the offscreen pass sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc) { - .attrs = { - [0].name = "position", - [1].name = "color0" - }, - .vs.uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .vs.source = + .vertex_func.source = "uniform mat4 mvp;\n" "attribute vec4 position;\n" "attribute vec4 color0;\n" @@ -146,54 +136,100 @@ int main() { " gl_Position = mvp * position;\n" " color = color0;\n" "}\n", - .fs.source = + // FIXME: switching to WebGL2 shader causes all sorts of weird errors + //"#version 300 es\n", + //"uniform mat4 mvp;\n" + //"in vec4 position;\n" + //"in vec4 color0;\n" + //"out vec4 color;\n" + //"void main() {\n" + //" gl_Position = mvp * position;\n" + //" color = color0;\n" + //"}\n", + .fragment_func.source = "precision mediump float;\n" "varying vec4 color;\n" "void main() {\n" " gl_FragColor = color;\n" - "}\n" + "}\n", + //"#version 300 es\n" + //"precision mediump float;\n" + //"in vec4 color;\n" + //"out vec4 frag_color;\n" + //"void main() {\n" + //" frag_color = color;\n" + //"}\n", + .attrs = { + [0].glsl_name = "position", + [1].glsl_name = "color0" + }, + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } + }, }); // ...and a second shader for rendering a textured cube in the default pass sg_shader default_shd = sg_make_shader(&(sg_shader_desc){ + .vertex_func.source = + //"uniform mat4 mvp;\n" + //"attribute vec4 position;\n" + //"attribute vec4 color0;\n" + //"attribute vec2 texcoord0;\n" + //"varying vec4 color;\n" + //"varying vec2 uv;\n" + //"void main() {\n" + //" gl_Position = mvp * position;\n" + //" color = color0;\n" + //" uv = texcoord0;\n" + //"}\n", + "#version 300 es\n" + "uniform mat4 mvp;\n" + "in vec4 position;\n" + "in vec4 color0;\n" + "in vec2 texcoord0;\n" + "out vec4 color;\n" + "out vec2 uv;\n" + "void main() {\n" + " gl_Position = mvp * position;\n" + " color = color0;\n" + " uv = texcoord0;\n" + "}\n", + .fragment_func.source = + //"precision mediump float;" + //"uniform sampler2D tex;\n" + //"varying vec4 color;\n" + //"varying vec2 uv;\n" + //"void main() {\n" + //" gl_FragColor = texture2D(tex, uv) + color * 0.5;\n" + //"}\n", + "#version 300 es\n" + "precision mediump float;" + "uniform sampler2D tex;\n" + "in vec4 color;\n" + "in vec2 uv;\n" + "out vec4 frag_color;\n" + "void main() {\n" + " frag_color = texture(tex, uv) + color * 0.5;\n" + "}\n", .attrs = { - [0].name = "position", - [1].name = "color0", - [2].name = "texcoord0" + [0].glsl_name = "position", + [1].glsl_name = "color0", + [2].glsl_name = "texcoord0" }, - .vs = { - .uniform_blocks[0] = { - .size = sizeof(params_t), - .uniforms = { - [0] = { .name="mvp", .type=SG_UNIFORMTYPE_MAT4 } - } - }, - .source = - "uniform mat4 mvp;\n" - "attribute vec4 position;\n" - "attribute vec4 color0;\n" - "attribute vec2 texcoord0;\n" - "varying vec4 color;\n" - "varying vec2 uv;\n" - "void main() {\n" - " gl_Position = mvp * position;\n" - " color = color0;\n" - " uv = texcoord0;\n" - "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(params_t), + .glsl_uniforms = { + [0] = { .glsl_name = "mvp", .type = SG_UNIFORMTYPE_MAT4 } + } }, - .fs = { - .images[0].used = true, - .samplers[0].used = true, - .image_sampler_pairs[0] = { .used = true, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, - .source = - "precision mediump float;" - "uniform sampler2D tex;\n" - "varying vec4 color;\n" - "varying vec2 uv;\n" - "void main() {\n" - " gl_FragColor = texture2D(tex, uv) + color * 0.5;\n" - "}\n" - } + .images[0].stage = SG_SHADERSTAGE_FRAGMENT, + .samplers[0].stage = SG_SHADERSTAGE_FRAGMENT, + .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .glsl_name = "tex", .image_slot = 0, .sampler_slot = 0 }, }); // pipeline object for offscreen rendering, don't need texcoords here @@ -248,10 +284,8 @@ int main() { state.display.bind = (sg_bindings){ .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = color_img, - .samplers[0] = smp, - } + .images[0] = color_img, + .samplers[0] = smp, }; // hand off control to browser loop @@ -282,7 +316,7 @@ static EM_BOOL draw(double time, void* userdata) { }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -294,7 +328,7 @@ static EM_BOOL draw(double time, void* userdata) { }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From ab2ff2b60ac6318475b6bba7eeaf80ed13a03af2 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 22 Sep 2024 14:55:47 +0200 Subject: [PATCH 15/36] fix bufferoffsets-emsc and offscreen-emsc --- html5/bufferoffsets-emsc.c | 32 +++++++------------------ html5/offscreen-emsc.c | 48 +++++++------------------------------- 2 files changed, 17 insertions(+), 63 deletions(-) diff --git a/html5/bufferoffsets-emsc.c b/html5/bufferoffsets-emsc.c index dd277d46..1518d7fc 100644 --- a/html5/bufferoffsets-emsc.c +++ b/html5/bufferoffsets-emsc.c @@ -68,36 +68,22 @@ int main() { [1].glsl_name = "color0", }, .vertex_func.source = - "attribute vec2 pos;" - "attribute vec3 color0;" - "varying vec4 color;" + "#version 300 es\n" + "in vec2 pos;" + "in vec3 color0;" + "out vec4 color;" "void main() {" " gl_Position = vec4(pos, 0.5, 1.0);\n" " color = vec4(color0, 1.0);\n" "}\n", - // FIXME: for some reason using WebGL2 shaders causes corruption - //"#version 300 es\n" - //"in vec2 pos;" - //"in vec3 color0;" - //"out vec4 color;" - //"void main() {" - //" gl_Position = vec4(pos, 0.5, 1.0);\n" - //" color = vec4(color0, 1.0);\n" - //"}\n", .fragment_func.source = + "#version 300 es\n" "precision mediump float;\n" - "varying vec4 color;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" "void main() {\n" - " gl_FragColor = color;\n" - "}\n", - // FIXME! - //"#version 300 es\n", - //"precision mediump float;\n" - //"in vec4 color;\n" - //"out vec4 frag_color;\n" - //"void main() {\n" - //" frag_color = color;\n" - //"}\n" + " frag_color = color;\n" + "}\n" }); // a pipeline state object, default states are fine diff --git a/html5/offscreen-emsc.c b/html5/offscreen-emsc.c index 0c3eb124..e7a2bea8 100644 --- a/html5/offscreen-emsc.c +++ b/html5/offscreen-emsc.c @@ -128,37 +128,23 @@ int main() { // shader for the non-textured cube, rendered in the offscreen pass sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc) { .vertex_func.source = + "#version 300 es\n" "uniform mat4 mvp;\n" - "attribute vec4 position;\n" - "attribute vec4 color0;\n" - "varying vec4 color;\n" + "in vec4 position;\n" + "in vec4 color0;\n" + "out vec4 color;\n" "void main() {\n" " gl_Position = mvp * position;\n" " color = color0;\n" "}\n", - // FIXME: switching to WebGL2 shader causes all sorts of weird errors - //"#version 300 es\n", - //"uniform mat4 mvp;\n" - //"in vec4 position;\n" - //"in vec4 color0;\n" - //"out vec4 color;\n" - //"void main() {\n" - //" gl_Position = mvp * position;\n" - //" color = color0;\n" - //"}\n", .fragment_func.source = + "#version 300 es\n" "precision mediump float;\n" - "varying vec4 color;\n" + "in vec4 color;\n" + "out vec4 frag_color;\n" "void main() {\n" - " gl_FragColor = color;\n" + " frag_color = color;\n" "}\n", - //"#version 300 es\n" - //"precision mediump float;\n" - //"in vec4 color;\n" - //"out vec4 frag_color;\n" - //"void main() {\n" - //" frag_color = color;\n" - //"}\n", .attrs = { [0].glsl_name = "position", [1].glsl_name = "color0" @@ -175,17 +161,6 @@ int main() { // ...and a second shader for rendering a textured cube in the default pass sg_shader default_shd = sg_make_shader(&(sg_shader_desc){ .vertex_func.source = - //"uniform mat4 mvp;\n" - //"attribute vec4 position;\n" - //"attribute vec4 color0;\n" - //"attribute vec2 texcoord0;\n" - //"varying vec4 color;\n" - //"varying vec2 uv;\n" - //"void main() {\n" - //" gl_Position = mvp * position;\n" - //" color = color0;\n" - //" uv = texcoord0;\n" - //"}\n", "#version 300 es\n" "uniform mat4 mvp;\n" "in vec4 position;\n" @@ -199,13 +174,6 @@ int main() { " uv = texcoord0;\n" "}\n", .fragment_func.source = - //"precision mediump float;" - //"uniform sampler2D tex;\n" - //"varying vec4 color;\n" - //"varying vec2 uv;\n" - //"void main() {\n" - //" gl_FragColor = texture2D(tex, uv) + color * 0.5;\n" - //"}\n", "#version 300 es\n" "precision mediump float;" "uniform sampler2D tex;\n" From 114927190c77c45efd0be98aea4a91cf7f349482 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 29 Sep 2024 17:08:46 +0200 Subject: [PATCH 16/36] wgpu samples: Dawn native fixes --- wgpu/CMakeLists.txt | 2 +- wgpu/wgpu_entry_dawn.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wgpu/CMakeLists.txt b/wgpu/CMakeLists.txt index 479dfa15..adf76225 100644 --- a/wgpu/CMakeLists.txt +++ b/wgpu/CMakeLists.txt @@ -4,7 +4,7 @@ fips_begin_lib(wgpu_entry) fips_files(wgpu_entry_emsc.c) else() fips_files(wgpu_entry_dawn.cc) - fips_libs(webgpu_dawn webgpu_glfw webgpu_cpp) + fips_libs(webgpu_dawn webgpu_glfw) endif() fips_end_lib() diff --git a/wgpu/wgpu_entry_dawn.cc b/wgpu/wgpu_entry_dawn.cc index bd6363f9..9b952ec6 100644 --- a/wgpu/wgpu_entry_dawn.cc +++ b/wgpu/wgpu_entry_dawn.cc @@ -10,7 +10,7 @@ #include "stdio.h" static WGPUSurface glfw_create_surface_for_window(WGPUInstance instance, void* glfw_window) { - wgpuInstanceReference(instance); + wgpuInstanceAddRef(instance); const auto cppInstance = wgpu::Instance::Acquire(instance); WGPUSurface surface = wgpu::glfw::CreateSurfaceForWindow(instance, (GLFWwindow*)glfw_window).MoveToCHandle(); return surface; @@ -90,7 +90,7 @@ static void request_adapter_cb(WGPURequestAdapterStatus status, WGPUAdapter adap WGPUFeatureName_Depth32FloatStencil8 }; WGPUDeviceDescriptor dev_desc = { - .requiredFeaturesCount = 1, + .requiredFeatureCount = 1, .requiredFeatures = requiredFeatures, }; wgpuAdapterRequestDevice(adapter, &dev_desc, request_device_cb, userdata); From 05c09fc4cd41da8a6c6279569164ad2cea43afbb Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 30 Sep 2024 14:18:49 +0200 Subject: [PATCH 17/36] fix webgpu deprecations in 'raw' wgpu samples --- wgpu/wgpu_entry.h | 3 +- wgpu/wgpu_entry_dawn.cc | 56 ++++++++++++++++++++++--------------- wgpu/wgpu_entry_emsc.c | 21 ++++++++------ wgpu/wgpu_entry_swapchain.c | 46 +++++++++++++++++++++++++----- 4 files changed, 87 insertions(+), 39 deletions(-) diff --git a/wgpu/wgpu_entry.h b/wgpu/wgpu_entry.h index 56b144bf..75e52207 100644 --- a/wgpu/wgpu_entry.h +++ b/wgpu/wgpu_entry.h @@ -63,7 +63,6 @@ typedef struct { WGPUAdapter adapter; WGPUDevice device; WGPUSurface surface; - WGPUSwapChain swapchain; WGPUTextureFormat render_format; WGPUTexture msaa_tex; WGPUTexture depth_stencil_tex; @@ -88,6 +87,8 @@ void wgpu_mouse_wheel(wgpu_mouse_wheel_func fn); // internal functions, don't call void wgpu_swapchain_init(wgpu_state_t* state); void wgpu_swapchain_discard(wgpu_state_t* state); +void wgpu_swapchain_resized(wgpu_state_t* state); +WGPUTextureView wgpu_swapchain_next(wgpu_state_t* state); void wgpu_platform_start(wgpu_state_t* state); #ifdef __cplusplus diff --git a/wgpu/wgpu_entry_dawn.cc b/wgpu/wgpu_entry_dawn.cc index 9b952ec6..3ff4109c 100644 --- a/wgpu/wgpu_entry_dawn.cc +++ b/wgpu/wgpu_entry_dawn.cc @@ -1,7 +1,9 @@ //------------------------------------------------------------------------------ -// wgpu_entry_dawn.c +// wgpu_entry_dawn.cc // // Dawn-specific wgpu entry code. +// +// NOTE: we could use https://github.com/eliemichel/glfw3webgpu/ and avoid C++. //------------------------------------------------------------------------------ #include "GLFW/glfw3.h" #include "webgpu/webgpu_cpp.h" @@ -72,12 +74,31 @@ static void glfw_scroll_cb(GLFWwindow* window, double xoffset, double yoffset) { } } +static void glfw_resize_cb(GLFWwindow* window, int width, int height) { + wgpu_state_t* state = (wgpu_state_t*) glfwGetWindowUserPointer(window); + state->width = width; + state->height = height; + wgpu_swapchain_resized(state); +} + static void request_device_cb(WGPURequestDeviceStatus status, WGPUDevice device, const char* msg, void* userdata) { (void)status; (void)msg; (void)userdata; wgpu_state_t* state = (wgpu_state_t*) userdata; state->device = device; } +static void error_cb(WGPUErrorType type, const char* message, void* userdata) { + (void)type; (void)userdata; + if (type != WGPUErrorType_NoError) { + printf("ERROR: %s\n", message); + } +} + +static void logging_cb(WGPULoggingType type, const char* message, void* userdata) { + (void)type; (void)userdata; + printf("LOG: %s\n", message); +} + static void request_adapter_cb(WGPURequestAdapterStatus status, WGPUAdapter adapter, const char* msg, void* userdata) { (void)msg; wgpu_state_t* state = (wgpu_state_t*) userdata; @@ -92,23 +113,14 @@ static void request_adapter_cb(WGPURequestAdapterStatus status, WGPUAdapter adap WGPUDeviceDescriptor dev_desc = { .requiredFeatureCount = 1, .requiredFeatures = requiredFeatures, + .uncapturedErrorCallbackInfo = { + .callback = error_cb, + }, }; wgpuAdapterRequestDevice(adapter, &dev_desc, request_device_cb, userdata); assert(0 != state->device); } -static void error_cb(WGPUErrorType type, const char* message, void* userdata) { - (void)type; (void)userdata; - if (type != WGPUErrorType_NoError) { - printf("ERROR: %s\n", message); - } -} - -static void logging_cb(WGPULoggingType type, const char* message, void* userdata) { - (void)type; (void)userdata; - printf("LOG: %s\n", message); -} - void wgpu_platform_start(wgpu_state_t* state) { assert(state->instance == 0); @@ -117,9 +129,7 @@ void wgpu_platform_start(wgpu_state_t* state) { wgpuInstanceRequestAdapter(state->instance, 0, request_adapter_cb, state); assert(state->device); - wgpuDeviceSetUncapturedErrorCallback(state->device, error_cb, 0); wgpuDeviceSetLoggingCallback(state->device, logging_cb, 0); - wgpuDeviceSetDeviceLostCallback(state->device, 0, 0); wgpuDevicePushErrorScope(state->device, WGPUErrorFilter_Validation); glfwInit(); @@ -131,11 +141,11 @@ void wgpu_platform_start(wgpu_state_t* state) { glfwSetMouseButtonCallback(window, glfw_mousebutton_cb); glfwSetCursorPosCallback(window, glfw_cursorpos_cb); glfwSetScrollCallback(window, glfw_scroll_cb); + glfwSetWindowSizeCallback(window, glfw_resize_cb); state->surface = glfw_create_surface_for_window(state->instance, window); assert(state->surface); - // FIXME: Dawn doesn't support wgpuSurfaceGetPreferredFormat? - state->render_format = WGPUTextureFormat_BGRA8Unorm; + state->render_format = wgpuSurfaceGetPreferredFormat(state->surface, state->adapter); wgpu_swapchain_init(state); state->desc.init_cb(); @@ -145,11 +155,13 @@ void wgpu_platform_start(wgpu_state_t* state) { while (!glfwWindowShouldClose(window)) { glfwPollEvents(); wgpuDevicePushErrorScope(state->device, WGPUErrorFilter_Validation); - state->swapchain_view = wgpuSwapChainGetCurrentTextureView(state->swapchain); - state->desc.frame_cb(); - wgpuSwapChainPresent(state->swapchain); - wgpuTextureViewRelease(state->swapchain_view); - state->swapchain_view = 0; + state->swapchain_view = wgpu_swapchain_next(state); + if (state->swapchain_view) { + state->desc.frame_cb(); + wgpuTextureViewRelease(state->swapchain_view); + state->swapchain_view = 0; + wgpuSurfacePresent(state->surface); + } wgpuDevicePopErrorScope(state->device, error_cb, 0); wgpuInstanceProcessEvents(state->instance); } diff --git a/wgpu/wgpu_entry_emsc.c b/wgpu/wgpu_entry_emsc.c index 38e2b89d..f0f12dd3 100644 --- a/wgpu/wgpu_entry_emsc.c +++ b/wgpu/wgpu_entry_emsc.c @@ -23,6 +23,7 @@ static EM_BOOL emsc_size_changed(int event_type, const EmscriptenUiEvent* ui_eve (void)event_type; (void)ui_event; wgpu_state_t* state = userdata; emsc_update_canvas_size(state); + wgpu_swapchain_resized(state); return true; } @@ -191,10 +192,12 @@ static EM_BOOL emsc_frame(double time, void* userdata) { return EM_TRUE; } wgpuDevicePushErrorScope(state->device, WGPUErrorFilter_Validation); - state->swapchain_view = wgpuSwapChainGetCurrentTextureView(state->swapchain); - state->desc.frame_cb(); - wgpuTextureViewRelease(state->swapchain_view); - state->swapchain_view = 0; + state->swapchain_view = wgpu_swapchain_next(state); + if (state->swapchain_view) { + state->desc.frame_cb(); + wgpuTextureViewRelease(state->swapchain_view); + state->swapchain_view = 0; + } wgpuDevicePopErrorScope(state->device, error_cb, 0); return EM_TRUE; } @@ -202,8 +205,12 @@ static EM_BOOL emsc_frame(double time, void* userdata) { void wgpu_platform_start(wgpu_state_t* state) { assert(state->instance == 0); + state->instance = wgpuCreateInstance(0); + assert(state->instance); + wgpuInstanceRequestAdapter(state->instance, 0, request_adapter_cb, state); + emsc_update_canvas_size(state); - emscripten_set_resize_callback("#canvas", 0, false, emsc_size_changed); + emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, state, false, emsc_size_changed); emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, state, true, emsc_keydown_cb); emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, state, true, emsc_keyup_cb); emscripten_set_keypress_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, state, true, emsc_keypress_cb); @@ -212,9 +219,5 @@ void wgpu_platform_start(wgpu_state_t* state) { emscripten_set_mousemove_callback("#canvas", state, true, emsc_mousemove_cb); emscripten_set_wheel_callback("#canvas", state, true, emsc_wheel_cb); - state->instance = wgpuCreateInstance(0); - assert(state->instance); - wgpuInstanceRequestAdapter(state->instance, 0, request_adapter_cb, state); - emscripten_request_animation_frame_loop(emsc_frame, state); } diff --git a/wgpu/wgpu_entry_swapchain.c b/wgpu/wgpu_entry_swapchain.c index e1291784..74686f04 100644 --- a/wgpu/wgpu_entry_swapchain.c +++ b/wgpu/wgpu_entry_swapchain.c @@ -5,26 +5,28 @@ //------------------------------------------------------------------------------ #include "wgpu_entry.h" #include +#include +#include void wgpu_swapchain_init(wgpu_state_t* state) { assert(state->adapter); assert(state->device); assert(state->surface); assert(state->render_format != WGPUTextureFormat_Undefined); - assert(0 == state->swapchain); assert(0 == state->depth_stencil_tex); assert(0 == state->depth_stencil_view); assert(0 == state->msaa_tex); assert(0 == state->msaa_view); - state->swapchain = wgpuDeviceCreateSwapChain(state->device, state->surface, &(WGPUSwapChainDescriptor){ - .usage = WGPUTextureUsage_RenderAttachment, + wgpuSurfaceConfigure(state->surface, &(WGPUSurfaceConfiguration){ + .device = state->device, .format = state->render_format, + .usage = WGPUTextureUsage_RenderAttachment, + .alphaMode = WGPUCompositeAlphaMode_Auto, .width = (uint32_t)state->width, .height = (uint32_t)state->height, .presentMode = WGPUPresentMode_Fifo, }); - assert(state->swapchain); if (!state->desc.no_depth_buffer) { state->depth_stencil_tex = wgpuDeviceCreateTexture(state->device, &(WGPUTextureDescriptor){ @@ -80,8 +82,38 @@ void wgpu_swapchain_discard(wgpu_state_t* state) { wgpuTextureRelease(state->depth_stencil_tex); state->depth_stencil_tex = 0; } - if (state->swapchain) { - wgpuSwapChainRelease(state->swapchain); - state->swapchain = 0; +} + +void wgpu_swapchain_resized(wgpu_state_t* state) { + wgpu_swapchain_discard(state); + wgpu_swapchain_init(state); +} + +// may return 0, in that case: skip this frame +WGPUTextureView wgpu_swapchain_next(wgpu_state_t* state) { + WGPUSurfaceTexture surface_texture = {0}; + wgpuSurfaceGetCurrentTexture(state->surface, &surface_texture); + switch (surface_texture.status) { + case WGPUSurfaceGetCurrentTextureStatus_Success: + // all ok + break; + case WGPUSurfaceGetCurrentTextureStatus_Timeout: + case WGPUSurfaceGetCurrentTextureStatus_Outdated: + case WGPUSurfaceGetCurrentTextureStatus_Lost: + // skip this frame and reconfigure surface + if (surface_texture.texture) { + wgpuTextureRelease(surface_texture.texture); + } + wgpu_swapchain_discard(state); + wgpu_swapchain_init(state); + return 0; + case WGPUSurfaceGetCurrentTextureStatus_OutOfMemory: + case WGPUSurfaceGetCurrentTextureStatus_DeviceLost: + default: + printf("wgpuSurfaceGetCurrentTexture() failed with: %#.8x\n", surface_texture.status); + abort(); } + WGPUTextureView view = wgpuTextureCreateView(surface_texture.texture, 0); + wgpuTextureRelease(surface_texture.texture); + return view; } From 8a57457c3c82bb5e62c8cc0786ec6843be518017 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 30 Sep 2024 15:35:25 +0200 Subject: [PATCH 18/36] fix triangle-wgpu.c for bindings cleanup --- wgpu/triangle-wgpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu/triangle-wgpu.c b/wgpu/triangle-wgpu.c index 43648f1b..70505865 100644 --- a/wgpu/triangle-wgpu.c +++ b/wgpu/triangle-wgpu.c @@ -37,7 +37,7 @@ static void init(void) { // a shader object with wgsl shader code sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.source = + .vertex_func.source = "struct vs_out {\n" " @builtin(position) pos: vec4f,\n" " @location(0) color: vec4f,\n" @@ -48,7 +48,7 @@ static void init(void) { " out.color = color;\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" " return color;\n" "}\n", From d05406bef759ec2e397778dc866a3a2c4d990981 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Tue, 1 Oct 2024 14:17:26 +0200 Subject: [PATCH 19/36] fix cube-wgpu for bindings cleanup --- wgpu/cube-wgpu.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/wgpu/cube-wgpu.c b/wgpu/cube-wgpu.c index 48a64ddf..1597daa8 100644 --- a/wgpu/cube-wgpu.c +++ b/wgpu/cube-wgpu.c @@ -88,28 +88,30 @@ void init(void) { // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0] = { .size = 16 * 4 }, - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) color: vec4f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.color = color;\n" - " return out;\n" - "}\n", - }, - .fs.source = + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) color: vec4f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.color = color;\n" + " return out;\n" + "}\n", + .fragment_func.source = "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" " return color;\n" "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, + }, }); // create pipeline object @@ -155,7 +157,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = wgpu_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From a3bb2d02f487f366e9f32886b75029453441337d Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Tue, 1 Oct 2024 15:07:09 +0200 Subject: [PATCH 20/36] fix texcube-wgpu for bindings cleanup --- wgpu/texcube-wgpu.c | 76 +++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/wgpu/texcube-wgpu.c b/wgpu/texcube-wgpu.c index ece9e7e0..b264ba97 100644 --- a/wgpu/texcube-wgpu.c +++ b/wgpu/texcube-wgpu.c @@ -103,50 +103,60 @@ static void init(void) { 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, }; - state.bind.fs.images[0] = sg_make_image(&(sg_image_desc){ + state.bind.images[0] = sg_make_image(&(sg_image_desc){ .width = 4, .height = 4, .data.subimage[0][0] = SG_RANGE(pixels), .label = "cube-texture" }); - 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, }); // create shader with WGSL source code const sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) color: vec4f,\n" - " @location(1) uv: vec2f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f, @location(2) uv: vec2f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.color = color;\n" - " out.uv = uv * 5.0;\n" - " return out;\n" - "}\n", + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) color: vec4f,\n" + " @location(1) uv: vec2f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f, @location(2) uv: vec2f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.color = color;\n" + " out.uv = uv * 5.0;\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) color: vec4f, @location(1) uv: vec2f) -> @location(0) vec4f {\n" + " return textureSample(tex, smp, uv) * color;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, + }, + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 1, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, - .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) color: vec4f, @location(1) uv: vec2f) -> @location(0) vec4f {\n" - " return textureSample(tex, smp, uv) * color;\n" - "}\n", - } }); // a pipeline state object @@ -190,7 +200,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = wgpu_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From 2137f179d6f9705aab153bedd0050f4735c682bd Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Tue, 1 Oct 2024 15:51:03 +0200 Subject: [PATCH 21/36] fix more wgpu samples for bindings cleanup --- wgpu/arraytex-wgpu.c | 93 +++++++++++++++++++++------------------ wgpu/blend-wgpu.c | 84 +++++++++++++++++------------------ wgpu/bufferoffsets-wgpu.c | 4 +- wgpu/dyntex-wgpu.c | 78 +++++++++++++++++--------------- wgpu/instancing-wgpu.c | 48 ++++++++++---------- wgpu/quad-wgpu.c | 10 ++--- 6 files changed, 167 insertions(+), 150 deletions(-) diff --git a/wgpu/arraytex-wgpu.c b/wgpu/arraytex-wgpu.c index be31743e..c3b71a0e 100644 --- a/wgpu/arraytex-wgpu.c +++ b/wgpu/arraytex-wgpu.c @@ -130,44 +130,55 @@ static void init(void) { // shader to sample from array texture sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - " offset0: vec2f,\n" - " offset1: vec2f,\n" - " offset2: vec2f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) uv0: vec3f,\n" - " @location(1) uv1: vec3f,\n" - " @location(2) uv2: vec3f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) uv: vec2f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.uv0 = vec3f(uv + in.offset0, 0.0);\n" - " out.uv1 = vec3f(uv + in.offset1, 1.0);\n" - " out.uv2 = vec3f(uv + in.offset2, 2.0);\n" - " return out;\n" - "}\n", + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + " offset0: vec2f,\n" + " offset1: vec2f,\n" + " offset2: vec2f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) uv0: vec3f,\n" + " @location(1) uv1: vec3f,\n" + " @location(2) uv2: vec3f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) uv: vec2f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.uv0 = vec3f(uv + in.offset0, 0.0);\n" + " out.uv1 = vec3f(uv + in.offset1, 1.0);\n" + " out.uv2 = vec3f(uv + in.offset2, 2.0);\n" + " return out;\n" + "}\n", + .fragment_func.source = + "@group(1) @binding(0) var tex: texture_2d_array;\n" + "@group(1) @binding(1) var smp: sampler;\n" + "@fragment fn main(@location(0) uv0: vec3f, @location(1) uv1: vec3f, @location(2) uv2: vec3f) -> @location(0) vec4f {\n" + " var c0 = textureSample(tex, smp, uv0.xy, u32(uv0.z)).xyz;\n" + " var c1 = textureSample(tex, smp, uv1.xy, u32(uv1.z)).xyz;\n" + " var c2 = textureSample(tex, smp, uv2.xy, u32(uv2.z)).xyz;\n" + " return vec4f(c0 + c1 + c2, 1.0);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, }, - .fs = { - .images[0] = { .used = true, .image_type = SG_IMAGETYPE_ARRAY }, - .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_array;\n" - "@group(1) @binding(64) var smp: sampler;\n" - "@fragment fn main(@location(0) uv0: vec3f, @location(1) uv1: vec3f, @location(2) uv2: vec3f) -> @location(0) vec4f {\n" - " var c0 = textureSample(tex, smp, uv0.xy, u32(uv0.z)).xyz;\n" - " var c1 = textureSample(tex, smp, uv1.xy, u32(uv1.z)).xyz;\n" - " var c2 = textureSample(tex, smp, uv2.xy, u32(uv2.z)).xyz;\n" - " return vec4f(c0 + c1 + c2, 1.0);\n" - "}\n", + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_type = SG_IMAGETYPE_ARRAY, + .wgsl_group1_binding_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 1, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, .label = "cube-shader", }); @@ -194,10 +205,8 @@ static void init(void) { state.bind = (sg_bindings) { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - }, + .images[0] = img, + .samplers[0] = smp, }; } @@ -225,7 +234,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = wgpu_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/wgpu/blend-wgpu.c b/wgpu/blend-wgpu.c index ce582387..4f62799c 100644 --- a/wgpu/blend-wgpu.c +++ b/wgpu/blend-wgpu.c @@ -54,23 +54,23 @@ static void init(void) { // a shader for the fullscreen background quad sg_shader bg_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .source = - "@vertex fn main(@location(0) pos: vec2f) -> @builtin(position) vec4f {\n" - " return vec4f(pos, 0.5, 1.0);\n" - "}\n", - }, - .fs = { - .uniform_blocks[0].size = sizeof(fs_params_t), - .source = - "struct fs_params {\n" - " tick: f32,\n" - "}\n" - "@group(0) @binding(4) var in: fs_params;\n" - "@fragment fn main(@builtin(position) frag_coord: vec4f) -> @location(0) vec4f {\n" - " let xy: vec2f = fract((frag_coord.xy - vec2f(in.tick)) / 50.0);\n" - " return vec4f(vec3f(xy.x * xy.y), 1.0);\n" - "}\n" + .vertex_func.source = + "@vertex fn main(@location(0) pos: vec2f) -> @builtin(position) vec4f {\n" + " return vec4f(pos, 0.5, 1.0);\n" + "}\n", + .fragment_func.source = + "struct fs_params {\n" + " tick: f32,\n" + "}\n" + "@group(0) @binding(0) var in: fs_params;\n" + "@fragment fn main(@builtin(position) frag_coord: vec4f) -> @location(0) vec4f {\n" + " let xy: vec2f = fract((frag_coord.xy - vec2f(in.tick)) / 50.0);\n" + " return vec4f(vec3f(xy.x * xy.y), 1.0);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .size = sizeof(fs_params_t), + .wgsl_group0_binding_n = 0, }, .label = "bg-shader", }); @@ -92,29 +92,29 @@ static void init(void) { // a shader for the blended quads sg_shader quad_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) color: vec4f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.color = color;\n" - " return out;\n" - "}\n", - }, - .fs = { - .source = - "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" - " return color;\n" - "}\n", + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) color: vec4f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.color = color;\n" + " return out;\n" + "}\n", + .fragment_func.source = + "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" + " return color;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, }, }); @@ -182,7 +182,7 @@ static void frame(void) { // draw a background quad sg_apply_pipeline(state.bg_pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, &SG_RANGE(state.bg_fs_params)); + sg_apply_uniforms(0, &SG_RANGE(state.bg_fs_params)); sg_draw(0, 4, 1); // draw the blended quads @@ -198,7 +198,7 @@ static void frame(void) { state.quad_vs_params.mvp = HMM_MultiplyMat4(view_proj, model); sg_apply_pipeline(state.pips[src][dst]); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(state.quad_vs_params)); + sg_apply_uniforms(0, &SG_RANGE(state.quad_vs_params)); sg_draw(0, 4, 1); } } diff --git a/wgpu/bufferoffsets-wgpu.c b/wgpu/bufferoffsets-wgpu.c index fc200282..4560ec3e 100644 --- a/wgpu/bufferoffsets-wgpu.c +++ b/wgpu/bufferoffsets-wgpu.c @@ -58,7 +58,7 @@ static void init(void) { // a shader object with wgsl code sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.source = + .vertex_func.source = "struct vs_out {\n" " @builtin(position) pos: vec4f,\n" " @location(0) color: vec4f,\n" @@ -69,7 +69,7 @@ static void init(void) { " out.color = color;\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" " return color;\n" "}\n", diff --git a/wgpu/dyntex-wgpu.c b/wgpu/dyntex-wgpu.c index bde12da3..90415cac 100644 --- a/wgpu/dyntex-wgpu.c +++ b/wgpu/dyntex-wgpu.c @@ -121,36 +121,46 @@ static void init(void) { // a shader to render a textured cube sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) color: vec4f,\n" - " @location(1) uv: vec2f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f, @location(2) uv: vec2f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.color = color;\n" - " out.uv = uv;\n" - " return out;\n" - "}\n", + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) color: vec4f,\n" + " @location(1) uv: vec2f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f, @location(2) uv: vec2f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.color = color;\n" + " out.uv = uv;\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) color: vec4f, @location(1) uv: vec2f) -> @location(0) vec4f {\n" + " return textureSample(tex, smp, uv) * color;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, }, - .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) color: vec4f, @location(1) uv: vec2f) -> @location(0) vec4f {\n" - " return textureSample(tex, smp, uv) * color;\n" - "}\n", + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 1, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, .label = "cube-shader", }); @@ -178,10 +188,8 @@ static void init(void) { state.bind = (sg_bindings) { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = img, - .samplers[0] = smp, - } + .images[0] = img, + .samplers[0] = smp, }; // initialize the game-of-life state @@ -205,7 +213,7 @@ void frame(void) { game_of_life_update(); // update the texture - sg_update_image(state.bind.fs.images[0], &(sg_image_data){ + sg_update_image(state.bind.images[0], &(sg_image_data){ .subimage[0][0] = SG_RANGE(state.pixels) }); @@ -213,7 +221,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = wgpu_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/wgpu/instancing-wgpu.c b/wgpu/instancing-wgpu.c index 0de8f74d..d0e6f7a7 100644 --- a/wgpu/instancing-wgpu.c +++ b/wgpu/instancing-wgpu.c @@ -87,29 +87,29 @@ static void init(void) { // a shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) color: vec4f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec3f, @location(1) color: vec4f, @location(2) inst_pos: vec3f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * vec4f(pos + inst_pos, 1.0);\n" - " out.color = color;\n" - " return out;\n" - "}\n", - }, - .fs = { - .source = - "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" - " return color;\n" - "}\n", + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) color: vec4f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec3f, @location(1) color: vec4f, @location(2) inst_pos: vec3f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * vec4f(pos + inst_pos, 1.0);\n" + " out.color = color;\n" + " return out;\n" + "}\n", + .fragment_func.source = + "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" + " return color;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, } }); @@ -186,7 +186,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = wgpu_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 24, (int)state.cur_num_particles); sg_end_pass(); sg_commit(); diff --git a/wgpu/quad-wgpu.c b/wgpu/quad-wgpu.c index a109646a..4d993c1d 100644 --- a/wgpu/quad-wgpu.c +++ b/wgpu/quad-wgpu.c @@ -47,7 +47,7 @@ void init(void) { // a shader object with wgsl shader code sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.source = + .vertex_func.source = "struct vs_out {\n" " @builtin(position) pos: vec4f,\n" " @location(0) color: vec4f,\n" @@ -58,10 +58,10 @@ void init(void) { " out.color = color;\n" " return out;\n" "}\n", - .fs.source = - "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" - " return color;\n" - "}\n", + .fragment_func.source = + "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" + " return color;\n" + "}\n", }); // a pipeline state object From 5007ea3adf56fe19ad90d6bc8a4aaab4850498d5 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Wed, 2 Oct 2024 13:41:36 +0200 Subject: [PATCH 22/36] update standalone wgpu samples for bindings cleanup (all except drawcallperf-wgpu) --- wgpu/imgui-wgpu.cc | 34 +++--- wgpu/inject-wgpu.c | 97 +++++++++------- wgpu/mipmap-wgpu.c | 72 +++++++----- wgpu/mrt-wgpu.c | 224 ++++++++++++++++++------------------- wgpu/noninterleaved-wgpu.c | 44 ++++---- wgpu/offscreen-wgpu.c | 117 ++++++++++--------- wgpu/uvwrap-wgpu.c | 74 ++++++------ wgpu/vertexpulling-wgpu.c | 22 ++-- 8 files changed, 370 insertions(+), 314 deletions(-) diff --git a/wgpu/imgui-wgpu.cc b/wgpu/imgui-wgpu.cc index fc2ad05b..9b4c6f0b 100644 --- a/wgpu/imgui-wgpu.cc +++ b/wgpu/imgui-wgpu.cc @@ -11,10 +11,6 @@ #include "sokol_log.h" #include "imgui.h" -#if !defined(__EMSCRIPTEN__) -#include "GLFW/glfw3.h" -#endif - static const size_t MaxVertices = 64 * 1024; static const size_t MaxIndices = MaxVertices * 3; static const int Width = 1024; @@ -98,17 +94,16 @@ static void init(void) { img_desc.height = font_height; img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; img_desc.data.subimage[0][0] = sg_range{ font_pixels, size_t(font_width * font_height * 4) }; - state.bind.fs.images[0] = sg_make_image(&img_desc); + state.bind.images[0] = sg_make_image(&img_desc); sg_sampler_desc smp_desc = { }; smp_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; smp_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; - state.bind.fs.samplers[0] = sg_make_sampler(&smp_desc); + state.bind.samplers[0] = sg_make_sampler(&smp_desc); // shader object for imgui rendering sg_shader_desc shd_desc = { }; - shd_desc.vs.uniform_blocks[0].size = sizeof(vs_params_t); - shd_desc.vs.source = + shd_desc.vertex_func.source = "struct vs_params {\n" " disp_size: vec2f,\n" "}\n" @@ -125,17 +120,22 @@ static void init(void) { " out.color = color;\n" " return out;\n" "}\n"; - shd_desc.fs.images[0].used = true; - shd_desc.fs.samplers[0].used = true; - shd_desc.fs.image_sampler_pairs[0].used = true; - shd_desc.fs.image_sampler_pairs[0].image_slot = 0; - shd_desc.fs.image_sampler_pairs[0].sampler_slot = 0; - shd_desc.fs.source = - "@group(1) @binding(48) var tex: texture_2d;\n" - "@group(1) @binding(64) var smp: sampler;\n" + shd_desc.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) color: vec4f) -> @location(0) vec4f {\n" " return textureSample(tex, smp, uv) * color;\n" "}\n"; + shd_desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; + shd_desc.uniform_blocks[0].size = sizeof(vs_params_t); + shd_desc.uniform_blocks[0].wgsl_group0_binding_n = 0; + shd_desc.images[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.images[0].wgsl_group1_binding_n = 0; + shd_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.samplers[0].wgsl_group1_binding_n = 1; + shd_desc.image_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + shd_desc.image_sampler_pairs[0].image_slot = 0; + shd_desc.image_sampler_pairs[0].sampler_slot = 0; sg_shader shd = sg_make_shader(&shd_desc); // pipeline object for imgui rendering @@ -220,7 +220,7 @@ void draw_imgui(ImDrawData* draw_data) { vs_params.disp_size.x = ImGui::GetIO().DisplaySize.x; vs_params.disp_size.y = ImGui::GetIO().DisplaySize.y; sg_apply_pipeline(state.pip); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE(vs_params)); + sg_apply_uniforms(0, SG_RANGE(vs_params)); for (int cl_index = 0; cl_index < draw_data->CmdListsCount; cl_index++) { const ImDrawList* cl = draw_data->CmdLists[cl_index]; diff --git a/wgpu/inject-wgpu.c b/wgpu/inject-wgpu.c index b77e3d7f..9f591859 100644 --- a/wgpu/inject-wgpu.c +++ b/wgpu/inject-wgpu.c @@ -22,6 +22,17 @@ #define IMG_WIDTH (32) #define IMG_HEIGHT (32) +// FIXME: temp workaround until emsdk webgpu.h catches up +#if defined(__EMSCRIPTEN__) +static const char* strview(const char* str) { + return str; +} +#else +static WGPUStringView strview(const char* str) { + return (WGPUStringView){ .data = str, .length = strlen(str) }; +} +#endif + static struct { sg_pass_action pass_action; sg_pipeline pip; @@ -100,7 +111,7 @@ static void init(void) { }; state.wgpu_vbuf = wgpuDeviceCreateBuffer(wgpu_dev, &(WGPUBufferDescriptor){ - .label = "wgpu-vertex-buffer", + .label = strview("wgpu-vertex-buffer"), .size = sizeof(vertices), .usage = WGPUBufferUsage_Vertex | WGPUBufferUsage_CopyDst, .mappedAtCreation = true, @@ -111,7 +122,7 @@ static void init(void) { wgpuBufferUnmap(state.wgpu_vbuf); state.wgpu_ibuf = wgpuDeviceCreateBuffer(wgpu_dev, &(WGPUBufferDescriptor){ - .label = "wgpu-index-buffer", + .label = strview("wgpu-index-buffer"), .size = roundup(sizeof(indices), 4), .usage = WGPUBufferUsage_Index | WGPUBufferUsage_CopyDst, .mappedAtCreation = true, @@ -140,7 +151,7 @@ static void init(void) { // create dynamically updated WebGPU texture object state.wgpu_tex = wgpuDeviceCreateTexture(wgpu_dev, &(WGPUTextureDescriptor) { - .label = "wgpu-texture", + .label = strview("wgpu-texture"), .usage = WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopyDst, .dimension = WGPUTextureDimension_2D, .size = { @@ -159,7 +170,7 @@ static void init(void) { sg_reset_state_cache(); // ... and the sokol-gfx texture object with the injected WGPU texture - state.bind.fs.images[0] = sg_make_image(&(sg_image_desc){ + state.bind.images[0] = sg_make_image(&(sg_image_desc){ .usage = SG_USAGE_STREAM, .width = IMG_WIDTH, .height = IMG_HEIGHT, @@ -167,12 +178,12 @@ static void init(void) { .wgpu_texture = state.wgpu_tex, .wgpu_texture_view = state.wgpu_tex_view, }); - assert(sg_wgpu_query_image_info(state.bind.fs.images[0]).tex == state.wgpu_tex); - assert(sg_wgpu_query_image_info(state.bind.fs.images[0]).view == state.wgpu_tex_view); + assert(sg_wgpu_query_image_info(state.bind.images[0]).tex == state.wgpu_tex); + assert(sg_wgpu_query_image_info(state.bind.images[0]).view == state.wgpu_tex_view); // a WebGPU sampler object... state.wgpu_smp = wgpuDeviceCreateSampler(wgpu_dev, &(WGPUSamplerDescriptor){ - .label = "wgpu-sampler", + .label = strview("wgpu-sampler"), .addressModeU = WGPUAddressMode_Repeat, .addressModeV = WGPUAddressMode_Repeat, .magFilter = WGPUFilterMode_Linear, @@ -182,45 +193,55 @@ static void init(void) { sg_reset_state_cache(); // ...and a matching sokol-gfx sampler with injected WebGPU sampler - state.bind.fs.samplers[0] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[0] = sg_make_sampler(&(sg_sampler_desc){ .wrap_u = SG_WRAP_REPEAT, .wrap_v = SG_WRAP_REPEAT, .min_filter = SG_FILTER_LINEAR, .mag_filter = SG_FILTER_LINEAR, .wgpu_sampler = state.wgpu_smp, }); - assert(sg_wgpu_query_sampler_info(state.bind.fs.samplers[0]).smp == state.wgpu_smp); + assert(sg_wgpu_query_sampler_info(state.bind.samplers[0]).smp == state.wgpu_smp); // a sokol-gfx shader object sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) uv: vec2f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) uv: vec2f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.uv = uv;\n" - " return out;\n" - "}\n" + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) uv: vec2f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) uv: vec2f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.uv = uv;\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(0) vec4f {\n" + " return textureSample(tex, smp, uv);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, + }, + .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(0) vec4f {\n" - " return textureSample(tex, smp, uv);\n" - "}\n" + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, }); assert(sg_wgpu_query_shader_info(shd).vs_mod != 0); @@ -274,12 +295,12 @@ void frame() { } state.counter++; sg_image_data content = { .subimage[0][0] = SG_RANGE(state.pixels) }; - sg_update_image(state.bind.fs.images[0], &content); + sg_update_image(state.bind.images[0], &content); sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = wgpu_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/wgpu/mipmap-wgpu.c b/wgpu/mipmap-wgpu.c index 34b138ce..7cc02e0d 100644 --- a/wgpu/mipmap-wgpu.c +++ b/wgpu/mipmap-wgpu.c @@ -83,7 +83,7 @@ static void init(void) { } // create a single image and 12 samplers - state.bind.fs.images[0] = sg_make_image(&(sg_image_desc){ + state.bind.images[0] = sg_make_image(&(sg_image_desc){ .width = 256, .height = 256, .num_mipmaps = 9, @@ -135,35 +135,45 @@ static void init(void) { // a shader object sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) uv: vec2f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) uv: vec2f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.uv = uv;\n" - " return out;\n" - "}\n" + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) uv: vec2f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) uv: vec2f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.uv = uv;\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(0) vec4f {\n" + " return textureSample(tex, smp, uv);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, + }, + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 1, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, - .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(0) vec4f {\n" - " return textureSample(tex, smp, uv);\n" - "}\n" - } }); // pipeline state @@ -192,10 +202,10 @@ static void frame(void) { const float x = ((float)(i & 3) - 1.5f) * 2.0f; const float y = ((float)(i / 4) - 1.0f) * -2.0f; hmm_mat4 model = HMM_MultiplyMat4(HMM_Translate(HMM_Vec3(x, y, 0.0f)), rm); - state.bind.fs.samplers[0] = state.smp[i]; + state.bind.samplers[0] = state.smp[i]; sg_apply_bindings(&state.bind); const vs_params_t vs_params = { .mvp = HMM_MultiplyMat4(view_proj, model) }; - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } sg_end_pass(); diff --git a/wgpu/mrt-wgpu.c b/wgpu/mrt-wgpu.c index aa4a8129..ffcfe0b7 100644 --- a/wgpu/mrt-wgpu.c +++ b/wgpu/mrt-wgpu.c @@ -172,38 +172,38 @@ static void init(void) { // a shader to render a cube into MRT offscreen render targets sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(offscreen_params_t), - .source = - "struct params {\n" - " mvp: mat4x4f,\n" - "}\n" - "@group(0) @binding(0) var in: params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) bright: f32,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) bright: f32) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.bright = bright;\n" - " return out;\n" - "}\n", - }, - .fs = { - .source = - "struct fs_out {\n" - " @location(0) c0: vec4f,\n" - " @location(1) c1: vec4f,\n" - " @location(2) c2: vec4f,\n" - "};\n" - "@fragment fn main(@location(0) b: f32) -> fs_out {\n" - " var out: fs_out;\n" - " out.c0 = vec4f(b, 0, 0, 1);\n" - " out.c1 = vec4f(0, b, 0, 1);\n" - " out.c2 = vec4f(0, 0, b, 1);\n" - " return out;\n" - "}\n", + .vertex_func.source = + "struct params {\n" + " mvp: mat4x4f,\n" + "}\n" + "@group(0) @binding(0) var in: params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) bright: f32,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) bright: f32) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.bright = bright;\n" + " return out;\n" + "}\n", + .fragment_func.source = + "struct fs_out {\n" + " @location(0) c0: vec4f,\n" + " @location(1) c1: vec4f,\n" + " @location(2) c2: vec4f,\n" + "};\n" + "@fragment fn main(@location(0) b: f32) -> fs_out {\n" + " var out: fs_out;\n" + " out.c0 = vec4f(b, 0, 0, 1);\n" + " out.c1 = vec4f(0, b, 0, 1);\n" + " out.c2 = vec4f(0, 0, b, 1);\n" + " return out;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(offscreen_params_t), + .wgsl_group0_binding_n = 0, }, .label = "offscreen-shader", }); @@ -259,52 +259,54 @@ static void init(void) { // a shader to render a fullscreen rectangle, which 'composes' // the 3 offscreen render target images onto the screen sg_shader fsq_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(fsq_params_t), - .source = - "struct params {\n" - " offset: vec2f,\n" - "}\n" - "@group(0) @binding(0) var in: params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) uv0: vec2f,\n" - " @location(1) uv1: vec2f,\n" - " @location(2) uv2: vec2f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec2f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = vec4f((pos * 2 - 1), 0.5, 1);\n" - " out.uv0 = pos + vec2f(in.offset.x, 0);\n" - " out.uv1 = pos + vec2f(0, in.offset.y);\n" - " out.uv2 = pos;\n" - " return out;\n" - "}\n", + .vertex_func.source = + "struct params {\n" + " offset: vec2f,\n" + "}\n" + "@group(0) @binding(0) var in: params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) uv0: vec2f,\n" + " @location(1) uv1: vec2f,\n" + " @location(2) uv2: vec2f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec2f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = vec4f((pos * 2 - 1), 0.5, 1);\n" + " out.uv0 = pos + vec2f(in.offset.x, 0);\n" + " out.uv1 = pos + vec2f(0, in.offset.y);\n" + " out.uv2 = pos;\n" + " return out;\n" + "}\n", + .fragment_func.source = + "@group(1) @binding(0) var tex0: texture_2d;\n" + "@group(1) @binding(1) var tex1: texture_2d;\n" + "@group(1) @binding(2) var tex2: texture_2d;\n" + "@group(1) @binding(3) var smp: sampler;\n" + "@fragment fn main(@location(0) uv0: vec2f, @location(1) uv1: vec2f, @location(2) uv2: vec2f) -> @location(0) vec4f {\n" + " var c0 = textureSample(tex0, smp, uv0).xyz;\n" + " var c1 = textureSample(tex1, smp, uv1).xyz;\n" + " var c2 = textureSample(tex2, smp, uv2).xyz;\n" + " var c = vec4f(c0 + c1 + c2, 1);\n" + " return c;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(fsq_params_t), + .wgsl_group0_binding_n = 0, }, - .fs = { - .images = { - [0].used = true, - [1].used = true, - [2].used = true, - }, - .samplers[0].used = true, - .image_sampler_pairs = { - [0] = { .used = true, .image_slot = 0, .sampler_slot = 0 }, - [1] = { .used = true, .image_slot = 1, .sampler_slot = 0 }, - [2] = { .used = true, .image_slot = 2, .sampler_slot = 0 }, - }, - .source = - "@group(1) @binding(48) var tex0: texture_2d;\n" - "@group(1) @binding(49) var tex1: texture_2d;\n" - "@group(1) @binding(50) var tex2: texture_2d;\n" - "@group(1) @binding(64) var smp: sampler;\n" - "@fragment fn main(@location(0) uv0: vec2f, @location(1) uv1: vec2f, @location(2) uv2: vec2f) -> @location(0) vec4f {\n" - " var c0 = textureSample(tex0, smp, uv0).xyz;\n" - " var c1 = textureSample(tex1, smp, uv1).xyz;\n" - " var c2 = textureSample(tex2, smp, uv2).xyz;\n" - " var c = vec4f(c0 + c1 + c2, 1);\n" - " return c;\n" - "}\n" + .images = { + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .wgsl_group1_binding_n = 0 }, + [1] = { .stage = SG_SHADERSTAGE_FRAGMENT, .wgsl_group1_binding_n = 1 }, + [2] = { .stage = SG_SHADERSTAGE_FRAGMENT, .wgsl_group1_binding_n = 2 }, + }, + .samplers = { + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .wgsl_group1_binding_n = 3 }, + }, + .image_sampler_pairs = { + [0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 }, + [1] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 1, .sampler_slot = 0 }, + [2] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 2, .sampler_slot = 0 }, }, .label = "fsq-shader", }); @@ -322,41 +324,39 @@ static void init(void) { // resource bindings for the fullscreen quad state.fsq.bind = (sg_bindings){ .vertex_buffers[0] = quad_buf, - .fs = { - .images = { - [0] = state.offscreen.attachments_desc.resolves[0].image, - [1] = state.offscreen.attachments_desc.resolves[1].image, - [2] = state.offscreen.attachments_desc.resolves[2].image, - }, - .samplers[0] = smp, - } + .images = { + [0] = state.offscreen.attachments_desc.resolves[0].image, + [1] = state.offscreen.attachments_desc.resolves[1].image, + [2] = state.offscreen.attachments_desc.resolves[2].image, + }, + .samplers[0] = smp, }; // shader, pipeline and resource bindings for debug-visualization quads sg_shader dbg_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .source = - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) uv: vec2f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec2f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = vec4f(pos * 2 - 1, 0.5, 1);\n" - " out.uv = pos;\n" - " return out;\n" - "}\n", - }, - .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 tex0: texture_2d;\n" - "@group(1) @binding(64) var smp: sampler;\n" - "@fragment fn main(@location(0) uv: vec2f) -> @location(0) vec4f {\n" - " return vec4f(textureSample(tex0, smp, uv).xyz, 1);\n" - "}\n" + .vertex_func.source = + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) uv: vec2f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec2f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = vec4f(pos * 2 - 1, 0.5, 1);\n" + " out.uv = pos;\n" + " return out;\n" + "}\n", + .fragment_func.source = + "@group(1) @binding(0) var tex0: texture_2d;\n" + "@group(1) @binding(1) var smp: sampler;\n" + "@fragment fn main(@location(0) uv: vec2f) -> @location(0) vec4f {\n" + " return vec4f(textureSample(tex0, smp, uv).xyz, 1);\n" + "}\n", + .images[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .wgsl_group1_binding_n = 0 }, + .samplers[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .wgsl_group1_binding_n = 1 }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, .label = "dbg-shader", }); @@ -371,7 +371,7 @@ static void init(void) { // images will be filled right before rendering state.dbg.bind = (sg_bindings){ .vertex_buffers[0] = quad_buf, - .fs.samplers[0] = smp, + .samplers[0] = smp, }; } @@ -404,7 +404,7 @@ static void frame(void) { }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(offscreen_params)); + sg_apply_uniforms(0, &SG_RANGE(offscreen_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -415,12 +415,12 @@ static void frame(void) { }); sg_apply_pipeline(state.fsq.pip); sg_apply_bindings(&state.fsq.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(fsq_params)); + sg_apply_uniforms(0, &SG_RANGE(fsq_params)); sg_draw(0, 4, 1); sg_apply_pipeline(state.dbg.pip); for (int i = 0; i < 3; i++) { sg_apply_viewport(i*100, 0, 100, 100, false); - state.dbg.bind.fs.images[0] = state.offscreen.attachments_desc.resolves[i].image; + state.dbg.bind.images[0] = state.offscreen.attachments_desc.resolves[i].image; sg_apply_bindings(&state.dbg.bind); sg_draw(0, 4, 1); } diff --git a/wgpu/noninterleaved-wgpu.c b/wgpu/noninterleaved-wgpu.c index 6f096536..a05f9f54 100644 --- a/wgpu/noninterleaved-wgpu.c +++ b/wgpu/noninterleaved-wgpu.c @@ -72,30 +72,30 @@ static void init(void) { // create shader sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks = { - [0] = { .size = 16 * 4 }, - }, - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "};\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) color: vec4f,\n" - "};\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.color = color;\n" - " return out;\n" - "}\n", - }, - .fs.source = + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "};\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) color: vec4f,\n" + "};\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.color = color;\n" + " return out;\n" + "}\n", + .fragment_func.source = "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" " return color;\n" "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, + }, }); // a pipeline object, note that we don't need to provide the MSAA sample count of the default framebuffer @@ -151,7 +151,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = wgpu_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/wgpu/offscreen-wgpu.c b/wgpu/offscreen-wgpu.c index 04109cf6..9ef47045 100644 --- a/wgpu/offscreen-wgpu.c +++ b/wgpu/offscreen-wgpu.c @@ -138,63 +138,74 @@ static void init(void) { // shader for non-textured cube, rendered in offscreen pass sg_shader offscreen_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "};\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) color: vec4f,\n" - "};\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.color = color;\n" - " return out;\n" - "}\n", - }, - .fs = { + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "};\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) color: vec4f,\n" + "};\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.color = color;\n" + " return out;\n" + "}\n", + .fragment_func.source = "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" " return color;\n" "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, }, }); // and a second shader for rendering a textured cube in the default pass sg_shader display_shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " mvp: mat4x4f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) color: vec4f,\n" - " @location(1) uv: vec2f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f, @location(2) uv: vec2f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = in.mvp * pos;\n" - " out.color = color;\n" - " out.uv = uv;\n" - " return out;\n" - "}\n", + .vertex_func.source = + "struct vs_params {\n" + " mvp: mat4x4f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) color: vec4f,\n" + " @location(1) uv: vec2f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f, @location(2) uv: vec2f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = in.mvp * pos;\n" + " out.color = color;\n" + " out.uv = uv;\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) color: vec4f, @location(1) uv: vec2f) -> @location(0) vec4f {\n" + " return textureSample(tex, smp, uv) + color * 0.5;\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, }, - .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) color: vec4f, @location(1) uv: vec2f) -> @location(0) vec4f {\n" - " return textureSample(tex, smp, uv) + color * 0.5;\n" - "}\n", + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 1, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, }); @@ -252,10 +263,8 @@ static void init(void) { state.display.bind = (sg_bindings){ .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[0] = color_img, - .samplers[0] = smp, - } + .images[0] = color_img, + .samplers[0] = smp, }; } @@ -280,7 +289,7 @@ static void frame(void) { }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -292,7 +301,7 @@ static void frame(void) { }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); diff --git a/wgpu/uvwrap-wgpu.c b/wgpu/uvwrap-wgpu.c index 279359e7..826250e7 100644 --- a/wgpu/uvwrap-wgpu.c +++ b/wgpu/uvwrap-wgpu.c @@ -79,35 +79,45 @@ static void init(void) { // a shader object sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs = { - .uniform_blocks[0].size = sizeof(vs_params_t), - .source = - "struct vs_params {\n" - " offset: vec2f,\n" - " scale: vec2f,\n" - "}\n" - "@group(0) @binding(0) var in: vs_params;\n" - "struct vs_out {\n" - " @builtin(position) pos: vec4f,\n" - " @location(0) uv: vec2f,\n" - "}\n" - "@vertex fn main(@location(0) pos: vec2f) -> vs_out {\n" - " var out: vs_out;\n" - " out.pos = vec4(pos * in.scale + in.offset, 0.5, 1.0);\n" - " out.uv = (pos + 1.0) - 0.5;\n" - " return out;\n" - "}\n", + .vertex_func.source = + "struct vs_params {\n" + " offset: vec2f,\n" + " scale: vec2f,\n" + "}\n" + "@group(0) @binding(0) var in: vs_params;\n" + "struct vs_out {\n" + " @builtin(position) pos: vec4f,\n" + " @location(0) uv: vec2f,\n" + "}\n" + "@vertex fn main(@location(0) pos: vec2f) -> vs_out {\n" + " var out: vs_out;\n" + " out.pos = vec4(pos * in.scale + in.offset, 0.5, 1.0);\n" + " out.uv = (pos + 1.0) - 0.5;\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(0) vec4f {\n" + " return textureSample(tex, smp, uv);\n" + "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, }, - .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(0) vec4f {\n" - " return textureSample(tex, smp, uv);\n" - "}\n", + .images[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 0, + }, + .samplers[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .wgsl_group1_binding_n = 1, + }, + .image_sampler_pairs[0] = { + .stage = SG_SHADERSTAGE_FRAGMENT, + .image_slot = 0, + .sampler_slot = 0, }, .label = "uvwrap-shader", }); @@ -133,10 +143,8 @@ static void frame(void) { for (int i = SG_WRAP_REPEAT; i <= SG_WRAP_MIRRORED_REPEAT; i++) { sg_apply_bindings(&(sg_bindings){ .vertex_buffers[0] = state.vbuf, - .fs = { - .images[0] = state.img, - .samplers[0] = state.smp[i], - } + .images[0] = state.img, + .samplers[0] = state.smp[i], }); float x_offset = 0, y_offset = 0; switch (i) { @@ -149,7 +157,7 @@ static void frame(void) { .offset = { x_offset, y_offset }, .scale = { 0.4f, 0.4f } }; - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } sg_end_pass(); diff --git a/wgpu/vertexpulling-wgpu.c b/wgpu/vertexpulling-wgpu.c index f81f55ac..37281c78 100644 --- a/wgpu/vertexpulling-wgpu.c +++ b/wgpu/vertexpulling-wgpu.c @@ -69,7 +69,7 @@ static void init(void) { { .pos = { 1.0, 1.0, 1.0, 1.0 }, .color = { 1.0, 0.0, 0.5, 1.0 } }, { .pos = { 1.0, 1.0, -1.0, 1.0 }, .color = { 1.0, 0.0, 0.5, 1.0 } } }; - state.bind.vs.storage_buffers[0] = sg_make_buffer(&(sg_buffer_desc){ + state.bind.storage_buffers[0] = sg_make_buffer(&(sg_buffer_desc){ .type = SG_BUFFERTYPE_STORAGEBUFFER, .data = SG_RANGE(vertices), }); @@ -88,9 +88,7 @@ static void init(void) { }); sg_shader shd = sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0].size = sizeof(vs_params_t), - .vs.storage_buffers[0] = { .used = true, .readonly = true }, - .vs.source = + .vertex_func.source = "struct vs_params {\n" " mvp: mat4x4f,\n" "}\n" @@ -102,7 +100,7 @@ static void init(void) { " vtx: array,\n" "}\n" "@group(0) @binding(0) var in: vs_params;\n" - "@group(1) @binding(32) var in_sbuf: sbuf;\n" + "@group(1) @binding(0) var in_sbuf: sbuf;\n" "struct vs_out {\n" " @builtin(position) pos: vec4f,\n" " @location(0) color: vec4f,\n" @@ -113,10 +111,20 @@ static void init(void) { " out.color = in_sbuf.vtx[vidx].color;\n" " return out;\n" "}\n", - .fs.source = + .fragment_func.source = "@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n" " return color;\n" "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .wgsl_group0_binding_n = 0, + }, + .storage_buffers[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .readonly = true, + .wgsl_group1_binding_n = 0, + } }); state.pip = sg_make_pipeline(&(sg_pipeline_desc){ @@ -145,7 +153,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = wgpu_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); From c043eed10333a60c4acef60419ce03b30bcdb494 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 6 Oct 2024 18:39:33 +0200 Subject: [PATCH 23/36] fix sapp samples for bindings cleanup wip --- sapp/arraytex-sapp.c | 12 +++++------- sapp/blend-sapp.c | 10 +++++----- sapp/bufferoffsets-sapp.c | 4 ++-- sapp/cgltf-sapp.c | 6 +++--- sapp/cube-sapp.c | 6 +++--- sapp/cubemaprt-sapp.c | 25 ++++++++++++------------- sapp/dyntex-sapp.c | 13 +++++++------ sapp/instancing-sapp.c | 8 ++++---- sapp/layerrender-sapp.c | 18 ++++++++---------- sapp/loadpng-sapp.c | 12 ++++++------ sapp/mipmap-sapp.c | 10 +++++----- sapp/miprender-sapp.c | 20 +++++++++----------- sapp/mrt-sapp.c | 32 +++++++++++++++----------------- sapp/noentry-dll-sapp.c | 6 +++--- sapp/noninterleaved-sapp.c | 6 +++--- sapp/noninterleaved-sapp.glsl | 4 ++-- sapp/offscreen-msaa-sapp.c | 20 +++++++++----------- sapp/offscreen-sapp.c | 20 +++++++++----------- sapp/plmpeg-sapp.c | 24 ++++++++++++------------ sapp/quad-sapp.c | 4 ++-- sapp/sdf-sapp.c | 4 ++-- sapp/shadows-depthtex-sapp.c | 28 ++++++++++++---------------- sapp/texcube-sapp.c | 6 +++--- sapp/triangle-sapp.c | 4 ++-- 24 files changed, 143 insertions(+), 159 deletions(-) diff --git a/sapp/arraytex-sapp.c b/sapp/arraytex-sapp.c index 56d4812b..75c0150c 100644 --- a/sapp/arraytex-sapp.c +++ b/sapp/arraytex-sapp.c @@ -126,8 +126,8 @@ void init(void) { state.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_texcoord0].format = SG_VERTEXFORMAT_FLOAT2 + [ATTR_arraytex_position].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_arraytex_texcoord0].format = SG_VERTEXFORMAT_FLOAT2 } }, .shader = sg_make_shader(arraytex_shader_desc(sg_query_backend())), @@ -144,10 +144,8 @@ void init(void) { state.bind = (sg_bindings) { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[SLOT_tex] = img, - .samplers[SLOT_smp] = smp, - } + .images[IMG_arraytex_tex] = img, + .samplers[SMP_arraytex_smp] = smp, }; } @@ -175,7 +173,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_arraytex_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/blend-sapp.c b/sapp/blend-sapp.c index ba5f824d..769a00e2 100644 --- a/sapp/blend-sapp.c +++ b/sapp/blend-sapp.c @@ -63,7 +63,7 @@ void init(void) { .layout = { .buffers[0].stride = 28, .attrs = { - [ATTR_vs_bg_position].format=SG_VERTEXFORMAT_FLOAT2 + [ATTR_bg_position].format=SG_VERTEXFORMAT_FLOAT2 } }, .shader = bg_shd, @@ -77,8 +77,8 @@ void init(void) { sg_pipeline_desc pip_desc = { .layout = { .attrs = { - [ATTR_vs_quad_position].format=SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_quad_color0].format=SG_VERTEXFORMAT_FLOAT4 + [ATTR_quad_position].format=SG_VERTEXFORMAT_FLOAT3, + [ATTR_quad_color0].format=SG_VERTEXFORMAT_FLOAT4 } }, .shader = quad_shd, @@ -114,7 +114,7 @@ void frame(void) { /* draw a background quad */ sg_apply_pipeline(state.bg_pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_bg_fs_params, &SG_RANGE(state.bg_fs_params)); + sg_apply_uniforms(UB_bg_bg_fs_params, &SG_RANGE(state.bg_fs_params)); sg_draw(0, 4, 1); // draw the blended quads @@ -130,7 +130,7 @@ void frame(void) { sg_apply_pipeline(state.pips[src][dst]); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_quad_vs_params, &SG_RANGE(state.quad_vs_params)); + sg_apply_uniforms(UB_quad_quad_vs_params, &SG_RANGE(state.quad_vs_params)); sg_draw(0, 4, 1); } } diff --git a/sapp/bufferoffsets-sapp.c b/sapp/bufferoffsets-sapp.c index ff9f2d8f..5ef840cf 100644 --- a/sapp/bufferoffsets-sapp.c +++ b/sapp/bufferoffsets-sapp.c @@ -67,8 +67,8 @@ void init(void) { .index_type = SG_INDEXTYPE_UINT16, .layout = { .attrs = { - [0].format=SG_VERTEXFORMAT_FLOAT2, - [1].format=SG_VERTEXFORMAT_FLOAT3 + [ATTR_bufferoffsets_position].format=SG_VERTEXFORMAT_FLOAT2, + [ATTR_bufferoffsets_color0].format=SG_VERTEXFORMAT_FLOAT3 } }, .label = "pipeline", diff --git a/sapp/cgltf-sapp.c b/sapp/cgltf-sapp.c index 055e001a..9db03fd2 100644 --- a/sapp/cgltf-sapp.c +++ b/sapp/cgltf-sapp.c @@ -844,9 +844,9 @@ static sg_vertex_format gltf_to_vertex_format(cgltf_accessor* acc) { static int gltf_attr_type_to_vs_input_slot(cgltf_attribute_type attr_type) { switch (attr_type) { - case cgltf_attribute_type_position: return ATTR_vs_position; - case cgltf_attribute_type_normal: return ATTR_vs_normal; - case cgltf_attribute_type_texcoord: return ATTR_vs_texcoord; + case cgltf_attribute_type_position: return ATTR_cgltf_metallic_position; + case cgltf_attribute_type_normal: return ATTR_cgltf_metallic_normal; + case cgltf_attribute_type_texcoord: return ATTR_cgltf_metallic_texcoord; default: return SCENE_INVALID_INDEX; } } diff --git a/sapp/cube-sapp.c b/sapp/cube-sapp.c index c8349471..0ea7b5d4 100644 --- a/sapp/cube-sapp.c +++ b/sapp/cube-sapp.c @@ -85,8 +85,8 @@ void init(void) { /* test to provide buffer stride, but no attr offsets */ .buffers[0].stride = 28, .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4 + [ATTR_cube_position].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_cube_color0].format = SG_VERTEXFORMAT_FLOAT4 } }, .shader = shd, @@ -132,7 +132,7 @@ void frame(void) { }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_cube_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/cubemaprt-sapp.c b/sapp/cubemaprt-sapp.c index b59eebb2..24b1f23c 100644 --- a/sapp/cubemaprt-sapp.c +++ b/sapp/cubemaprt-sapp.c @@ -130,18 +130,13 @@ void init(void) { // vertex- and index-buffers for cube app.cube = make_cube_mesh(); - // same vertex layout for all shaders - sg_vertex_layout_state layout = { - .attrs = { - [ATTR_vs_pos] = { .offset=offsetof(vertex_t, pos), .format=SG_VERTEXFORMAT_FLOAT3 }, - [ATTR_vs_norm] = { .offset=offsetof(vertex_t, norm), .format=SG_VERTEXFORMAT_FLOAT3 } - } - }; - // shader and pipeline objects for offscreen-rendering sg_pipeline_desc pip_desc = { .shader = sg_make_shader(shapes_shader_desc(sg_query_backend())), - .layout = layout, + .layout.attrs = { + [ATTR_shapes_pos] = { .offset = offsetof(vertex_t, pos), .format = SG_VERTEXFORMAT_FLOAT3 }, + [ATTR_shapes_norm] = { .offset=offsetof(vertex_t, norm), .format=SG_VERTEXFORMAT_FLOAT3 }, + }, .index_type = SG_INDEXTYPE_UINT16, .cull_mode = SG_CULLMODE_BACK, .sample_count = OFFSCREEN_SAMPLE_COUNT, @@ -161,7 +156,10 @@ void init(void) { // shader and pipeline objects for display-rendering app.display_cube_pip = sg_make_pipeline(&(sg_pipeline_desc){ .shader = sg_make_shader(cube_shader_desc(sg_query_backend())), - .layout = layout, + .layout.attrs = { + [ATTR_cube_pos] = { .offset = offsetof(vertex_t, pos), .format = SG_VERTEXFORMAT_FLOAT3 }, + [ATTR_cube_norm] = { .offset=offsetof(vertex_t, norm), .format=SG_VERTEXFORMAT_FLOAT3 }, + }, .index_type = SG_INDEXTYPE_UINT16, .cull_mode = SG_CULLMODE_BACK, .sample_count = DISPLAY_SAMPLE_COUNT, @@ -258,7 +256,8 @@ void frame(void) { sg_apply_bindings(&(sg_bindings){ .vertex_buffers[0] = app.cube.vbuf, .index_buffer = app.cube.ibuf, - .fs = { .images[SLOT_tex] = app.cubemap, .samplers[SLOT_smp] = app.smp }, + .images[IMG_cube_tex] = app.cubemap, + .samplers[SMP_cube_smp] = app.smp, }); shape_uniforms_t uniforms = { .mvp = HMM_MultiplyMat4(view_proj, model), @@ -267,7 +266,7 @@ void frame(void) { .light_dir = app.light_dir, .eye_pos = HMM_Vec4v(eye_pos, 1.0f) }; - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_shape_uniforms, &SG_RANGE(uniforms)); + sg_apply_uniforms(UB_cube_shape_uniforms, &SG_RANGE(uniforms)); sg_draw(0, app.cube.num_elements, 1); __dbgui_draw(); @@ -312,7 +311,7 @@ static void draw_cubes(sg_pipeline pip, hmm_vec3 eye_pos, hmm_mat4 view_proj) { .light_dir = app.light_dir, .eye_pos = HMM_Vec4v(eye_pos, 1.0f) }; - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_shape_uniforms, &SG_RANGE(uniforms)); + sg_apply_uniforms(UB_cube_shape_uniforms, &SG_RANGE(uniforms)); sg_draw(0, app.cube.num_elements, 1); } } diff --git a/sapp/dyntex-sapp.c b/sapp/dyntex-sapp.c index 0d679de0..58f4a9e2 100644 --- a/sapp/dyntex-sapp.c +++ b/sapp/dyntex-sapp.c @@ -112,9 +112,9 @@ void init(void) { state.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4, - [ATTR_vs_texcoord0].format = SG_VERTEXFORMAT_FLOAT2 + [ATTR_dyntex_position].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_dyntex_color0].format = SG_VERTEXFORMAT_FLOAT4, + [ATTR_dyntex_texcoord0].format = SG_VERTEXFORMAT_FLOAT2 } }, .shader = shd, @@ -131,7 +131,8 @@ void init(void) { state.bind = (sg_bindings) { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { .images[SLOT_tex] = img, .samplers[SLOT_smp] = smp }, + .images[IMG_dyntex_tex] = img, + .samplers[SMP_dyntex_smp] = smp, }; // initialize the game-of-life state @@ -155,7 +156,7 @@ void frame(void) { game_of_life_update(); // update the texture - sg_update_image(state.bind.fs.images[0], &(sg_image_data){ + sg_update_image(state.bind.images[0], &(sg_image_data){ .subimage[0][0] = SG_RANGE(state.pixels) }); @@ -163,7 +164,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_dyntex_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/instancing-sapp.c b/sapp/instancing-sapp.c index 17618870..d4678120 100644 --- a/sapp/instancing-sapp.c +++ b/sapp/instancing-sapp.c @@ -85,9 +85,9 @@ void init(void) { // vertex buffer at slot 1 must step per instance .buffers[1].step_func = SG_VERTEXSTEP_PER_INSTANCE, .attrs = { - [ATTR_vs_pos] = { .format=SG_VERTEXFORMAT_FLOAT3, .buffer_index=0 }, - [ATTR_vs_color0] = { .format=SG_VERTEXFORMAT_FLOAT4, .buffer_index=0 }, - [ATTR_vs_inst_pos] = { .format=SG_VERTEXFORMAT_FLOAT3, .buffer_index=1 } + [ATTR_instancing_pos] = { .format=SG_VERTEXFORMAT_FLOAT3, .buffer_index=0 }, + [ATTR_instancing_color0] = { .format=SG_VERTEXFORMAT_FLOAT4, .buffer_index=0 }, + [ATTR_instancing_inst_pos] = { .format=SG_VERTEXFORMAT_FLOAT3, .buffer_index=1 } } }, .shader = shd, @@ -150,7 +150,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_instancing_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 24, state.cur_num_particles); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/layerrender-sapp.c b/sapp/layerrender-sapp.c index e340544e..460319ac 100644 --- a/sapp/layerrender-sapp.c +++ b/sapp/layerrender-sapp.c @@ -122,8 +122,8 @@ static void init(void) { .layout = { .buffers[0].stride = sizeof(sshape_vertex_t), .attrs = { - [ATTR_vs_offscreen_in_pos] = sshape_position_vertex_attr_state(), - [ATTR_vs_offscreen_in_nrm] = sshape_normal_vertex_attr_state(), + [ATTR_offscreen_in_pos] = sshape_position_vertex_attr_state(), + [ATTR_offscreen_in_nrm] = sshape_normal_vertex_attr_state(), }, }, .shader = sg_make_shader(offscreen_shader_desc(sg_query_backend())), @@ -143,8 +143,8 @@ static void init(void) { .layout = { .buffers[0].stride = sizeof(sshape_vertex_t), .attrs = { - [ATTR_vs_display_in_pos] = sshape_position_vertex_attr_state(), - [ATTR_vs_display_in_uv] = sshape_texcoord_vertex_attr_state(), + [ATTR_display_in_pos] = sshape_position_vertex_attr_state(), + [ATTR_display_in_uv] = sshape_texcoord_vertex_attr_state(), }, }, .shader = sg_make_shader(display_shader_desc(sg_query_backend())), @@ -165,10 +165,8 @@ static void init(void) { state.display.bindings = (sg_bindings){ .vertex_buffers[0] = state.vbuf, .index_buffer = state.ibuf, - .fs = { - .images[SLOT_tex] = state.img, - .samplers[SLOT_smp] = state.smp, - }, + .images[IMG_display_tex] = state.img, + .samplers[SMP_display_smp] = state.smp, }; // initialize pass actions @@ -204,7 +202,7 @@ static void frame(void) { default: ry = -ry; break; } const vs_params_t offscreen_vsparams = compute_offscreen_vsparams(rx, ry); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(offscreen_vsparams)); + sg_apply_uniforms(UB_offscreen_vs_params, &SG_RANGE(offscreen_vsparams)); const sshape_element_range_t shape = state.offscreen.shapes[i]; sg_draw(shape.base_element, shape.num_elements, 1); sg_end_pass(); @@ -214,7 +212,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bindings); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(display_vsparams)); + sg_apply_uniforms(UB_display_vs_params, &SG_RANGE(display_vsparams)); sg_draw(state.display.plane.base_element, state.display.plane.num_elements, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/loadpng-sapp.c b/sapp/loadpng-sapp.c index 2e93e966..7224cde5 100644 --- a/sapp/loadpng-sapp.c +++ b/sapp/loadpng-sapp.c @@ -63,10 +63,10 @@ static void init(void) { Any draw calls containing such an "incomplete" image handle will be silently dropped. */ - state.bind.fs.images[SLOT_tex] = sg_alloc_image(); + state.bind.images[IMG_loadpng_tex] = sg_alloc_image(); // a sampler object - state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_loadpng_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_LINEAR, .mag_filter = SG_FILTER_LINEAR, }); @@ -129,8 +129,8 @@ static void init(void) { .shader = sg_make_shader(loadpng_shader_desc(sg_query_backend())), .layout = { .attrs = { - [ATTR_vs_pos].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_texcoord0].format = SG_VERTEXFORMAT_SHORT2N + [ATTR_loadpng_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_loadpng_texcoord0].format = SG_VERTEXFORMAT_SHORT2N } }, .index_type = SG_INDEXTYPE_UINT16, @@ -173,7 +173,7 @@ static void fetch_callback(const sfetch_response_t* response) { &num_channels, desired_channels); if (pixels) { // ok, time to actually initialize the sokol-gfx texture - sg_init_image(state.bind.fs.images[SLOT_tex], &(sg_image_desc){ + sg_init_image(state.bind.images[IMG_loadpng_tex], &(sg_image_desc){ .width = png_width, .height = png_height, .pixel_format = SG_PIXELFORMAT_RGBA8, @@ -216,7 +216,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_loadpng_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/mipmap-sapp.c b/sapp/mipmap-sapp.c index 2c39d2d4..c1c3b059 100644 --- a/sapp/mipmap-sapp.c +++ b/sapp/mipmap-sapp.c @@ -132,8 +132,8 @@ void init(void) { state.pip = sg_make_pipeline(&(sg_pipeline_desc) { .layout = { .attrs = { - [ATTR_vs_pos].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_uv0].format = SG_VERTEXFORMAT_FLOAT2 + [ATTR_mipmap_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_mipmap_uv0].format = SG_VERTEXFORMAT_FLOAT2 } }, .shader = sg_make_shader(mipmap_shader_desc(sg_query_backend())), @@ -151,7 +151,7 @@ void frame(void) { sg_bindings bind = { .vertex_buffers[0] = state.vbuf, - .fs.images[SLOT_tex] = state.img, + .images[IMG_mipmap_tex] = state.img, }; sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); @@ -161,9 +161,9 @@ void frame(void) { hmm_mat4 model = HMM_MultiplyMat4(HMM_Translate(HMM_Vec3(x, y, 0.0f)), rm); vs_params.mvp = HMM_MultiplyMat4(view_proj, model); - bind.fs.samplers[SLOT_smp] = state.smp[i]; + bind.samplers[SMP_mipmap_smp] = state.smp[i]; sg_apply_bindings(&bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_mipmap_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } __dbgui_draw(); diff --git a/sapp/miprender-sapp.c b/sapp/miprender-sapp.c index 52388005..db1dbe95 100644 --- a/sapp/miprender-sapp.c +++ b/sapp/miprender-sapp.c @@ -127,8 +127,8 @@ static void init(void) { .layout = { .buffers[0].stride = sizeof(sshape_vertex_t), .attrs = { - [ATTR_vs_offscreen_in_pos] = sshape_position_vertex_attr_state(), - [ATTR_vs_offscreen_in_nrm] = sshape_normal_vertex_attr_state(), + [ATTR_offscreen_in_pos] = sshape_position_vertex_attr_state(), + [ATTR_offscreen_in_nrm] = sshape_normal_vertex_attr_state(), }, }, .shader = sg_make_shader(offscreen_shader_desc(sg_query_backend())), @@ -148,8 +148,8 @@ static void init(void) { .layout = { .buffers[0].stride = sizeof(sshape_vertex_t), .attrs = { - [ATTR_vs_display_in_pos] = sshape_position_vertex_attr_state(), - [ATTR_vs_display_in_uv] = sshape_texcoord_vertex_attr_state(), + [ATTR_display_in_pos] = sshape_position_vertex_attr_state(), + [ATTR_display_in_uv] = sshape_texcoord_vertex_attr_state(), }, }, .shader = sg_make_shader(display_shader_desc(sg_query_backend())), @@ -169,10 +169,8 @@ static void init(void) { state.display.bindings = (sg_bindings) { .vertex_buffers[0] = state.vbuf, .index_buffer = state.ibuf, - .fs = { - .images[SLOT_tex] = state.img, - .samplers[SLOT_smp] = state.smp, - } + .images[IMG_display_tex] = state.img, + .samplers[SMP_display_smp] = state.smp, }; // initialize pass actions @@ -201,7 +199,7 @@ static void frame(void) { }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bindings); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(offscreen_vsparams)); + sg_apply_uniforms(UB_offscreen_vs_params, &SG_RANGE(offscreen_vsparams)); const sshape_element_range_t shape = state.offscreen.shapes[i % NUM_SHAPES]; sg_draw(shape.base_element, shape.num_elements, 1); sg_end_pass(); @@ -211,7 +209,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bindings); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(display_vsparams)); + sg_apply_uniforms(UB_display_vs_params, &SG_RANGE(display_vsparams)); sg_draw(state.display.plane.base_element, state.display.plane.num_elements, 1); __dbgui_draw(); sg_end_pass(); @@ -261,4 +259,4 @@ sapp_desc sokol_main(int argc, char* argv[]) { .icon.sokol_default = true, .logger.func = slog_func, }; -} \ No newline at end of file +} diff --git a/sapp/mrt-sapp.c b/sapp/mrt-sapp.c index af3661b3..44635824 100644 --- a/sapp/mrt-sapp.c +++ b/sapp/mrt-sapp.c @@ -83,7 +83,7 @@ void create_offscreen_attachments(int width, int height) { // also need to update the fullscreen-quad texture bindings for (int i = 0; i < 3; i++) { - state.fsq.bind.fs.images[i] = state.offscreen.atts_desc.resolves[i].image; + state.fsq.bind.images[i] = state.offscreen.atts_desc.resolves[i].image; } } @@ -194,8 +194,8 @@ void init(void) { .layout = { .buffers[0].stride = sizeof(vertex_t), .attrs = { - [ATTR_vs_offscreen_pos] = { .offset=offsetof(vertex_t,x), .format=SG_VERTEXFORMAT_FLOAT3 }, - [ATTR_vs_offscreen_bright0] = { .offset=offsetof(vertex_t,b), .format=SG_VERTEXFORMAT_FLOAT } + [ATTR_offscreen_pos] = { .offset=offsetof(vertex_t,x), .format=SG_VERTEXFORMAT_FLOAT3 }, + [ATTR_offscreen_bright0] = { .offset=offsetof(vertex_t,b), .format=SG_VERTEXFORMAT_FLOAT } } }, .shader = offscreen_shd, @@ -230,7 +230,7 @@ void init(void) { // the pipeline object to render the fullscreen quad state.fsq.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { - .attrs[ATTR_vs_fsq_pos].format=SG_VERTEXFORMAT_FLOAT2 + .attrs[ATTR_fsq_pos].format=SG_VERTEXFORMAT_FLOAT2 }, .shader = fsq_shd, .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, @@ -248,20 +248,18 @@ void init(void) { // resource bindings to render a fullscreen quad state.fsq.bind = (sg_bindings){ .vertex_buffers[0] = quad_vbuf, - .fs = { - .images = { - [SLOT_tex0] = state.offscreen.atts_desc.resolves[0].image, - [SLOT_tex1] = state.offscreen.atts_desc.resolves[1].image, - [SLOT_tex2] = state.offscreen.atts_desc.resolves[2].image - }, - .samplers[SLOT_smp] = smp, - } + .images = { + [IMG_fsq_tex0] = state.offscreen.atts_desc.resolves[0].image, + [IMG_fsq_tex1] = state.offscreen.atts_desc.resolves[1].image, + [IMG_fsq_tex2] = state.offscreen.atts_desc.resolves[2].image + }, + .samplers[SMP_fsq_smp] = smp, }; // pipeline and resource bindings to render debug-visualization quads state.dbg.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { - .attrs[ATTR_vs_dbg_pos].format=SG_VERTEXFORMAT_FLOAT2 + .attrs[ATTR_dbg_pos].format=SG_VERTEXFORMAT_FLOAT2 }, .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, .shader = sg_make_shader(dbg_shader_desc(sg_query_backend())), @@ -269,7 +267,7 @@ void init(void) { }), state.dbg.bind = (sg_bindings){ .vertex_buffers[0] = quad_vbuf, - .fs.samplers[SLOT_smp] = smp, + .samplers[SMP_dbg_smp] = smp, // images will be filled right before rendering }; } @@ -295,7 +293,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.offscreen.pass_action, .attachments = state.offscreen.atts }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_offscreen_params, &SG_RANGE(offscreen_params)); + sg_apply_uniforms(UB_offscreen_offscreen_params, &SG_RANGE(offscreen_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -303,12 +301,12 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.fsq.pip); sg_apply_bindings(&state.fsq.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_fsq_params, &SG_RANGE(fsq_params)); + sg_apply_uniforms(UB_fsq_fsq_params, &SG_RANGE(fsq_params)); sg_draw(0, 4, 1); sg_apply_pipeline(state.dbg.pip); for (int i = 0; i < 3; i++) { sg_apply_viewport(i*100, 0, 100, 100, false); - state.dbg.bind.fs.images[SLOT_tex] = state.offscreen.atts_desc.resolves[i].image; + state.dbg.bind.images[IMG_dbg_tex] = state.offscreen.atts_desc.resolves[i].image; sg_apply_bindings(&state.dbg.bind); sg_draw(0, 4, 1); } diff --git a/sapp/noentry-dll-sapp.c b/sapp/noentry-dll-sapp.c index 7fe08ee4..c24262f1 100644 --- a/sapp/noentry-dll-sapp.c +++ b/sapp/noentry-dll-sapp.c @@ -123,8 +123,8 @@ void init(void* user_data) { // test to provide buffer stride, but no attr offsets .buffers[0].stride = 28, .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4 + [ATTR_noentry_position].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_noentry_color0].format = SG_VERTEXFORMAT_FLOAT4 } }, .shader = shd, @@ -166,7 +166,7 @@ void frame(void* user_data) { }); sg_apply_pipeline(state->pip); sg_apply_bindings(&state->bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_noentry_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/sapp/noninterleaved-sapp.c b/sapp/noninterleaved-sapp.c index 22885780..3124415f 100644 --- a/sapp/noninterleaved-sapp.c +++ b/sapp/noninterleaved-sapp.c @@ -73,9 +73,9 @@ void init(void) { // note how the vertex components are pulled from different buffer bind slots .attrs = { // positions come from vertex buffer slot 0 - [0] = { .format=SG_VERTEXFORMAT_FLOAT3, .buffer_index=0 }, + [ATTR_noninterleaved_position] = { .format=SG_VERTEXFORMAT_FLOAT3, .buffer_index=0 }, // colors come from vertex buffer slot 1 - [1] = { .format=SG_VERTEXFORMAT_FLOAT4, .buffer_index=1 } + [ATTR_noninterleaved_color0] = { .format=SG_VERTEXFORMAT_FLOAT4, .buffer_index=1 } } }, .index_type = SG_INDEXTYPE_UINT16, @@ -120,7 +120,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_noninterleaved_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/noninterleaved-sapp.glsl b/sapp/noninterleaved-sapp.glsl index e42acff8..d92fc428 100644 --- a/sapp/noninterleaved-sapp.glsl +++ b/sapp/noninterleaved-sapp.glsl @@ -8,8 +8,8 @@ uniform vs_params { mat4 mvp; }; -layout(location=0) in vec4 position; -layout(location=1) in vec4 color0; +in vec4 position; +in vec4 color0; out vec4 color; void main() { diff --git a/sapp/offscreen-msaa-sapp.c b/sapp/offscreen-msaa-sapp.c index a1b1e099..8cdf14de 100644 --- a/sapp/offscreen-msaa-sapp.c +++ b/sapp/offscreen-msaa-sapp.c @@ -146,8 +146,8 @@ static void init(void) { .layout = { .buffers[0] = sshape_vertex_buffer_layout_state(), .attrs = { - [ATTR_vs_offscreen_position] = sshape_position_vertex_attr_state(), - [ATTR_vs_offscreen_normal] = sshape_normal_vertex_attr_state(), + [ATTR_offscreen_position] = sshape_position_vertex_attr_state(), + [ATTR_offscreen_normal] = sshape_normal_vertex_attr_state(), } }, .shader = sg_make_shader(offscreen_shader_desc(sg_query_backend())), @@ -168,9 +168,9 @@ static void init(void) { .layout = { .buffers[0] = sshape_vertex_buffer_layout_state(), .attrs = { - [ATTR_vs_display_position] = sshape_position_vertex_attr_state(), - [ATTR_vs_display_normal] = sshape_normal_vertex_attr_state(), - [ATTR_vs_display_texcoord0] = sshape_texcoord_vertex_attr_state(), + [ATTR_display_position] = sshape_position_vertex_attr_state(), + [ATTR_display_normal] = sshape_normal_vertex_attr_state(), + [ATTR_display_texcoord0] = sshape_texcoord_vertex_attr_state(), }, }, .shader = sg_make_shader(display_shader_desc(sg_query_backend())), @@ -202,10 +202,8 @@ static void init(void) { state.display.bind = (sg_bindings) { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[SLOT_tex] = resolve_image, - .samplers[SLOT_smp] = smp, - } + .images[IMG_display_tex] = resolve_image, + .samplers[SMP_display_smp] = smp, }; } @@ -238,7 +236,7 @@ static void frame(void) { }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_offscreen_vs_params, &SG_RANGE(vs_params)); sg_draw(state.sphere.base_element, state.sphere.num_elements, 1); sg_end_pass(); @@ -252,7 +250,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_display_vs_params, &SG_RANGE(vs_params)); sg_draw(state.donut.base_element, state.donut.num_elements, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/offscreen-sapp.c b/sapp/offscreen-sapp.c index 69408719..2b207096 100644 --- a/sapp/offscreen-sapp.c +++ b/sapp/offscreen-sapp.c @@ -118,8 +118,8 @@ static void init(void) { .layout = { .buffers[0] = sshape_vertex_buffer_layout_state(), .attrs = { - [ATTR_vs_offscreen_position] = sshape_position_vertex_attr_state(), - [ATTR_vs_offscreen_normal] = sshape_normal_vertex_attr_state() + [ATTR_offscreen_position] = sshape_position_vertex_attr_state(), + [ATTR_offscreen_normal] = sshape_normal_vertex_attr_state() } }, .shader = sg_make_shader(offscreen_shader_desc(sg_query_backend())), @@ -140,9 +140,9 @@ static void init(void) { .layout = { .buffers[0] = sshape_vertex_buffer_layout_state(), .attrs = { - [ATTR_vs_default_position] = sshape_position_vertex_attr_state(), - [ATTR_vs_default_normal] = sshape_normal_vertex_attr_state(), - [ATTR_vs_default_texcoord0] = sshape_texcoord_vertex_attr_state() + [ATTR_default_position] = sshape_position_vertex_attr_state(), + [ATTR_default_normal] = sshape_normal_vertex_attr_state(), + [ATTR_default_texcoord0] = sshape_texcoord_vertex_attr_state() } }, .shader = sg_make_shader(default_shader_desc(sg_query_backend())), @@ -173,10 +173,8 @@ static void init(void) { state.display.bind = (sg_bindings){ .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .fs = { - .images[SLOT_tex] = color_img, - .samplers[SLOT_smp] = smp, - } + .images[IMG_default_tex] = color_img, + .samplers[SMP_default_smp] = smp, }; } @@ -205,7 +203,7 @@ static void frame(void) { sg_begin_pass(&state.offscreen.pass); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_offscreen_vs_params, &SG_RANGE(vs_params)); sg_draw(state.donut.base_element, state.donut.num_elements, 1); sg_end_pass(); @@ -223,7 +221,7 @@ static void frame(void) { }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_default_vs_params, &SG_RANGE(vs_params)); sg_draw(state.sphere.base_element, state.sphere.num_elements, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/plmpeg-sapp.c b/sapp/plmpeg-sapp.c index 2661822d..58c5c2a2 100644 --- a/sapp/plmpeg-sapp.c +++ b/sapp/plmpeg-sapp.c @@ -176,9 +176,9 @@ static void init(void) { state.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout.attrs = { - [ATTR_vs_pos].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_normal].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_texcoord].format = SG_VERTEXFORMAT_FLOAT2 + [ATTR_plmpeg_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_plmpeg_normal].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_plmpeg_texcoord].format = SG_VERTEXFORMAT_FLOAT2 }, .shader = sg_make_shader(plmpeg_shader_desc(sg_query_backend())), .index_type = SG_INDEXTYPE_UINT16, @@ -189,7 +189,7 @@ static void init(void) { }, }); - state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_plmpeg_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_LINEAR, .mag_filter = SG_FILTER_LINEAR, .wrap_u = SG_WRAP_CLAMP_TO_EDGE, @@ -250,10 +250,10 @@ static void frame(void) { // start rendering, but not before the first video frame has been decoded into textures sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); - if (state.bind.fs.images[0].id != SG_INVALID_ID) { + if (state.bind.images[0].id != SG_INVALID_ID) { sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_plmpeg_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 24, 1); } __dbgui_draw(); @@ -280,8 +280,8 @@ static void validate_texture(int slot, plm_plane_t* plane) { state.image_attrs[slot].height = (int)plane->height; // NOTE: it's ok to call sg_destroy_image() with SG_INVALID_ID - sg_destroy_image(state.bind.fs.images[slot]); - state.bind.fs.images[slot] = sg_make_image(&(sg_image_desc){ + sg_destroy_image(state.bind.images[slot]); + state.bind.images[slot] = sg_make_image(&(sg_image_desc){ .width = (int)plane->width, .height = (int)plane->height, .pixel_format = SG_PIXELFORMAT_R8, @@ -293,7 +293,7 @@ static void validate_texture(int slot, plm_plane_t* plane) { // sg_update_image() is called more than once per frame if (state.image_attrs[slot].last_upd_frame != state.cur_frame) { state.image_attrs[slot].last_upd_frame = state.cur_frame; - sg_update_image(state.bind.fs.images[slot], &(sg_image_data){ + sg_update_image(state.bind.images[slot], &(sg_image_data){ .subimage[0][0] = { .ptr = plane->data, .size = plane->width * plane->height * sizeof(uint8_t) @@ -305,9 +305,9 @@ static void validate_texture(int slot, plm_plane_t* plane) { // the pl_mpeg video callback, copies decoded video data into textures static void video_cb(plm_t* mpeg, plm_frame_t* frame, void* user) { (void)mpeg; (void)user; - validate_texture(SLOT_tex_y, &frame->y); - validate_texture(SLOT_tex_cb, &frame->cb); - validate_texture(SLOT_tex_cr, &frame->cr); + validate_texture(IMG_plmpeg_tex_y, &frame->y); + validate_texture(IMG_plmpeg_tex_cb, &frame->cb); + validate_texture(IMG_plmpeg_tex_cr, &frame->cr); } // the pl_mpeg audio callback, forwards decoded audio samples to sokol-audio diff --git a/sapp/quad-sapp.c b/sapp/quad-sapp.c index b7cd96fa..8cfa6a94 100644 --- a/sapp/quad-sapp.c +++ b/sapp/quad-sapp.c @@ -52,8 +52,8 @@ void init(void) { .index_type = SG_INDEXTYPE_UINT16, .layout = { .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4 + [ATTR_quad_position].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_quad_color0].format = SG_VERTEXFORMAT_FLOAT4 } }, .label = "quad-pipeline" diff --git a/sapp/sdf-sapp.c b/sapp/sdf-sapp.c index 67b6d543..db2ff98f 100644 --- a/sapp/sdf-sapp.c +++ b/sapp/sdf-sapp.c @@ -38,7 +38,7 @@ void init(void) { // shader and pipeline object for rendering a fullscreen quad state.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { - .attrs[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT2 + .attrs[ATTR_sdf_position].format = SG_VERTEXFORMAT_FLOAT2 }, .shader = sg_make_shader(sdf_shader_desc(sg_query_backend())), }); @@ -57,7 +57,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(state.vs_params)); + sg_apply_uniforms(UB_sdf_vs_params, &SG_RANGE(state.vs_params)); sg_draw(0, 3, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/shadows-depthtex-sapp.c b/sapp/shadows-depthtex-sapp.c index 72deb5a6..dbbf3835 100644 --- a/sapp/shadows-depthtex-sapp.c +++ b/sapp/shadows-depthtex-sapp.c @@ -156,7 +156,7 @@ static void init(void) { // need to provide vertex stride, because normal component is skipped in shadow pass .buffers[0].stride = 6 * sizeof(float), .attrs = { - [ATTR_vs_shadow_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_shadow_pos].format = SG_VERTEXFORMAT_FLOAT3, }, }, .shader = sg_make_shader(shadow_shader_desc(sg_query_backend())), @@ -184,8 +184,8 @@ static void init(void) { state.display.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { .attrs = { - [ATTR_vs_display_pos].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_display_norm].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_display_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_display_norm].format = SG_VERTEXFORMAT_FLOAT3, } }, .shader = sg_make_shader(display_shader_desc(sg_query_backend())), @@ -202,10 +202,8 @@ static void init(void) { state.display.bind = (sg_bindings) { .vertex_buffers[0] = state.vbuf, .index_buffer = state.ibuf, - .fs = { - .images[SLOT_shadow_map] = state.shadow_map, - .samplers[SLOT_shadow_sampler] = state.shadow_sampler, - }, + .images[IMG_display_shadow_map] = state.shadow_map, + .samplers[SMP_display_shadow_sampler] = state.shadow_sampler, }; // a vertex buffer, pipeline and sampler to render a debug visualization of the shadow map @@ -216,7 +214,7 @@ static void init(void) { }); state.dbg.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { - .attrs[ATTR_vs_dbg_pos].format = SG_VERTEXFORMAT_FLOAT2, + .attrs[ATTR_dbg_pos].format = SG_VERTEXFORMAT_FLOAT2, }, .shader = sg_make_shader(dbg_shader_desc(sg_query_backend())), .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, @@ -234,10 +232,8 @@ static void init(void) { }); state.dbg.bind = (sg_bindings){ .vertex_buffers[0] = dbg_vbuf, - .fs = { - .images[SLOT_dbg_tex] = state.shadow_map, - .samplers[SLOT_dbg_smp] = dbg_smp, - } + .images[IMG_dbg_dbg_tex] = state.shadow_map, + .samplers[SMP_dbg_dbg_smp] = dbg_smp, }; } @@ -290,7 +286,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.shadow.pass_action, .attachments = state.shadow.atts }); sg_apply_pipeline(state.shadow.pip); sg_apply_bindings(&state.shadow.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_shadow_params, &SG_RANGE(cube_vs_shadow_params)); + sg_apply_uniforms(UB_shadow_vs_shadow_params, &SG_RANGE(cube_vs_shadow_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -298,12 +294,12 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bind); - sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_fs_display_params, &SG_RANGE(fs_display_params)); + sg_apply_uniforms(UB_display_fs_display_params, &SG_RANGE(fs_display_params)); // render plane - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_display_params, &SG_RANGE(plane_vs_display_params)); + sg_apply_uniforms(UB_display_vs_display_params , &SG_RANGE(plane_vs_display_params)); sg_draw(36, 6, 1); // render cube - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_display_params, &SG_RANGE(cube_vs_display_params)); + sg_apply_uniforms(UB_display_vs_display_params, &SG_RANGE(cube_vs_display_params)); sg_draw(0, 36, 1); // render debug visualization of shadow-map sg_apply_pipeline(state.dbg.pip); diff --git a/sapp/texcube-sapp.c b/sapp/texcube-sapp.c index d1795db3..011c96f4 100644 --- a/sapp/texcube-sapp.c +++ b/sapp/texcube-sapp.c @@ -101,7 +101,7 @@ void init(void) { 0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, }; // NOTE: SLOT_tex is provided by shader code generation - state.bind.fs.images[SLOT_tex] = sg_make_image(&(sg_image_desc){ + state.bind.images[IMG_texcube_tex] = sg_make_image(&(sg_image_desc){ .width = 4, .height = 4, .data.subimage[0][0] = SG_RANGE(pixels), @@ -109,7 +109,7 @@ void init(void) { }); // create a sampler object with default attributes - state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_texcube_smp] = sg_make_sampler(&(sg_sampler_desc){ .label = "texcube-sampler" }); @@ -157,7 +157,7 @@ void frame(void) { sg_begin_pass(&(sg_pass) { .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_texcube_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/triangle-sapp.c b/sapp/triangle-sapp.c index f99582b6..6bc1cbd2 100644 --- a/sapp/triangle-sapp.c +++ b/sapp/triangle-sapp.c @@ -44,8 +44,8 @@ static void init(void) { // if the vertex layout doesn't have gaps, don't need to provide strides and offsets .layout = { .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4 + [ATTR_triangle_position].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_triangle_color0].format = SG_VERTEXFORMAT_FLOAT4 } }, .label = "triangle-pipeline" From cb88e1233d42bffafb752677dce2d516a24a190a Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 7 Oct 2024 17:25:04 +0200 Subject: [PATCH 24/36] fix some sapp samples for layout(binding) and bindings cleanup --- sapp/CMakeLists.txt | 1158 +++++++++++++++---------------- sapp/arraytex-sapp.c | 6 +- sapp/arraytex-sapp.glsl | 6 +- sapp/blend-sapp.c | 4 +- sapp/blend-sapp.glsl | 4 +- sapp/cube-sapp.c | 2 +- sapp/cube-sapp.glsl | 2 +- sapp/cubemaprt-sapp.c | 8 +- sapp/cubemaprt-sapp.glsl | 6 +- sapp/dyntex-sapp.c | 6 +- sapp/dyntex-sapp.glsl | 6 +- sapp/instancing-pull-sapp.glsl | 2 +- sapp/instancing-sapp.c | 2 +- sapp/instancing-sapp.glsl | 2 +- sapp/layerrender-sapp.c | 8 +- sapp/layerrender-sapp.glsl | 8 +- sapp/loadpng-sapp.c | 8 +- sapp/loadpng-sapp.glsl | 6 +- sapp/mipmap-sapp.c | 6 +- sapp/mipmap-sapp.glsl | 6 +- sapp/miprender-sapp.c | 8 +- sapp/miprender-sapp.glsl | 6 +- sapp/mrt-pixelformats-sapp.c | 20 +- sapp/mrt-pixelformats-sapp.glsl | 8 +- sapp/mrt-sapp.c | 16 +- sapp/mrt-sapp.glsl | 16 +- sapp/noentry-dll-sapp.c | 2 +- sapp/noentry-dll-sapp.glsl | 2 +- sapp/noentry-sapp.c | 6 +- sapp/noentry-sapp.glsl | 2 +- sapp/noninterleaved-sapp.c | 2 +- sapp/noninterleaved-sapp.glsl | 2 +- sapp/offscreen-msaa-sapp.c | 8 +- sapp/offscreen-msaa-sapp.glsl | 6 +- sapp/offscreen-sapp.c | 8 +- sapp/offscreen-sapp.glsl | 6 +- sapp/plmpeg-sapp.c | 10 +- sapp/plmpeg-sapp.glsl | 10 +- sapp/sbuftex-sapp.glsl | 10 +- sapp/sdf-sapp.c | 2 +- sapp/sdf-sapp.glsl | 2 +- sapp/shadows-depthtex-sapp.c | 16 +- sapp/shadows-depthtex-sapp.glsl | 14 +- sapp/shadows-sapp.c | 28 +- sapp/shadows-sapp.glsl | 14 +- sapp/tex3d-sapp.c | 8 +- sapp/tex3d-sapp.glsl | 6 +- sapp/texcube-sapp.c | 12 +- sapp/texcube-sapp.glsl | 6 +- sapp/uvwrap-sapp.c | 10 +- sapp/uvwrap-sapp.glsl | 6 +- sapp/vertexpull-sapp.glsl | 6 +- 52 files changed, 764 insertions(+), 770 deletions(-) diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index 3f6f893c..c8beebf3 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -98,20 +98,20 @@ fips_begin_app(noninterleaved-sapp-ui windowed) target_compile_definitions(noninterleaved-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(vertexpull-sapp windowed) - fips_files(vertexpull-sapp.c) - sokol_shader(vertexpull-sapp.glsl ${slang}) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(vertexpull-sapp-ui windowed) - fips_files(vertexpull-sapp.c) - sokol_shader(vertexpull-sapp.glsl ${slang}) - fips_deps(sokol dbgui) - target_compile_definitions(vertexpull-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(vertexpull-sapp windowed) +# fips_files(vertexpull-sapp.c) +# sokol_shader(vertexpull-sapp.glsl ${slang}) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(vertexpull-sapp-ui windowed) +# fips_files(vertexpull-sapp.c) +# sokol_shader(vertexpull-sapp.glsl ${slang}) +# fips_deps(sokol dbgui) +# target_compile_definitions(vertexpull-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(texcube-sapp windowed) fips_files(texcube-sapp.c) @@ -126,20 +126,20 @@ fips_begin_app(texcube-sapp-ui windowed) target_compile_definitions(texcube-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(sbuftex-sapp windowed) - fips_files(sbuftex-sapp.c) - sokol_shader(sbuftex-sapp.glsl ${slang}) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(sbuftex-sapp-ui windowed) - fips_files(sbuftex-sapp.c) - sokol_shader(sbuftex-sapp.glsl ${slang}) - fips_deps(sokol dbgui) - target_compile_definitions(sbuftex-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(sbuftex-sapp windowed) +# fips_files(sbuftex-sapp.c) +# sokol_shader(sbuftex-sapp.glsl ${slang}) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(sbuftex-sapp-ui windowed) +# fips_files(sbuftex-sapp.c) +# sokol_shader(sbuftex-sapp.glsl ${slang}) +# fips_deps(sokol dbgui) +# target_compile_definitions(sbuftex-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(offscreen-sapp windowed) fips_files(offscreen-sapp.c) @@ -210,20 +210,20 @@ fips_begin_app(instancing-sapp-ui windowed) target_compile_definitions(instancing-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(instancing-pull-sapp windowed) - fips_files(instancing-pull-sapp.c) - sokol_shader(instancing-pull-sapp.glsl ${slang}) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(instancing-pull-sapp-ui windowed) - fips_files(instancing-pull-sapp.c) - sokol_shader(instancing-pull-sapp.glsl ${slang}) - fips_deps(sokol dbgui) - target_compile_definitions(instancing-pull-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(instancing-pull-sapp windowed) +# fips_files(instancing-pull-sapp.c) +# sokol_shader(instancing-pull-sapp.glsl ${slang}) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(instancing-pull-sapp-ui windowed) +# fips_files(instancing-pull-sapp.c) +# sokol_shader(instancing-pull-sapp.glsl ${slang}) +# fips_deps(sokol dbgui) +# target_compile_definitions(instancing-pull-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(mrt-sapp windowed) fips_files(mrt-sapp.c) @@ -280,13 +280,13 @@ fips_begin_app(tex3d-sapp-ui windowed) target_compile_definitions(tex3d-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(dyntex3d-sapp windowed) - fips_files(dyntex3d-sapp.c) - sokol_shader(dyntex3d-sapp.glsl ${slang}) - fips_deps(sokol cimgui) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(dyntex3d-sapp windowed) +# fips_files(dyntex3d-sapp.c) +# sokol_shader(dyntex3d-sapp.glsl ${slang}) +# fips_deps(sokol cimgui) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(dyntex-sapp windowed) fips_files(dyntex-sapp.c) @@ -315,38 +315,38 @@ fips_begin_app(mipmap-sapp-ui windowed) target_compile_definitions(mipmap-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(cubemap-jpeg-sapp windowed) - fips_files(cubemap-jpeg-sapp.c) - sokol_shader(cubemap-jpeg-sapp.glsl ${slang}) - fips_dir(data) - fipsutil_copy(cubemap-jpeg-assets.yml) - fips_deps(sokol fileutil stb) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(cubemap-jpeg-sapp-ui windowed) - fips_files(cubemap-jpeg-sapp.c) - sokol_shader(cubemap-jpeg-sapp.glsl ${slang}) - fips_deps(sokol fileutil stb dbgui) - target_compile_definitions(cubemap-jpeg-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(basisu-sapp windowed) - fips_files(basisu-sapp.c) - fips_deps(sokol basisu) - fips_dir(data) - fipsutil_embed(basisu-assets.yml basisu-assets.h) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(basisu-sapp-ui windowed) - fips_files(basisu-sapp.c) - fips_deps(sokol basisu dbgui) - fips_dir(data) - fipsutil_embed(basisu-assets.yml basisu-assets.h) - target_compile_definitions(basisu-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(cubemap-jpeg-sapp windowed) +# fips_files(cubemap-jpeg-sapp.c) +# sokol_shader(cubemap-jpeg-sapp.glsl ${slang}) +# fips_dir(data) +# fipsutil_copy(cubemap-jpeg-assets.yml) +# fips_deps(sokol fileutil stb) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(cubemap-jpeg-sapp-ui windowed) +# fips_files(cubemap-jpeg-sapp.c) +# sokol_shader(cubemap-jpeg-sapp.glsl ${slang}) +# fips_deps(sokol fileutil stb dbgui) +# target_compile_definitions(cubemap-jpeg-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(basisu-sapp windowed) +# fips_files(basisu-sapp.c) +# fips_deps(sokol basisu) +# fips_dir(data) +# fipsutil_embed(basisu-assets.yml basisu-assets.h) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(basisu-sapp-ui windowed) +# fips_files(basisu-sapp.c) +# fips_deps(sokol basisu dbgui) +# fips_dir(data) +# fipsutil_embed(basisu-assets.yml basisu-assets.h) +# target_compile_definitions(basisu-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(blend-sapp windowed) fips_files(blend-sapp.c) @@ -375,190 +375,190 @@ fips_begin_app(uvwrap-sapp-ui windowed) target_compile_definitions(uvwrap-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(uniformtypes-sapp windowed) - fips_files(uniformtypes-sapp.c) - sokol_shader(uniformtypes-sapp.glsl ${slang}) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(uniformtypes-sapp-ui windowed) - fips_files(uniformtypes-sapp.c) - sokol_shader(uniformtypes-sapp.glsl ${slang}) - fips_deps(sokol dbgui) - target_compile_definitions(uniformtypes-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(imgui-sapp windowed) - fips_files(imgui-sapp.cc) - # use sokol-cpp for testing here, this isn't required though - fips_deps(sokol-cpp imgui) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(imgui-dock-sapp windowed) - fips_files(imgui-dock-sapp.cc) - # use sokol-cpp for testing here, this isn't required though - fips_deps(sokol-cpp imgui-dock) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(imgui-highdpi-sapp windowed) - fips_files(imgui-highdpi-sapp.cc) - fips_deps(sokol imgui) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(cimgui-sapp windowed) - fips_files(cimgui-sapp.c) - fips_deps(sokol cimgui) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(imgui-usercallback-sapp windowed) - fips_files(imgui-usercallback-sapp.c) - sokol_shader(imgui-usercallback-sapp.glsl ${slang}) - fips_deps(sokol cimgui) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(imgui-images-sapp windowed) - fips_files(imgui-images-sapp.c) - fips_deps(sokol cimgui) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(imgui-perf-sapp windowed) - fips_files(imgui-perf-sapp.c) - fips_deps(sokol cimgui) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(events-sapp windowed) - fips_files(events-sapp.cc) - fips_deps(sokol imgui) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(pixelformats-sapp windowed) - fips_files(pixelformats-sapp.c) - sokol_shader(pixelformats-sapp.glsl ${slang}) - fips_deps(sokol cimgui) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(sgl-sapp windowed) - fips_files(sgl-sapp.c) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(sgl-sapp-ui windowed) - fips_files(sgl-sapp.c) - fips_deps(sokol dbgui) - target_compile_definitions(sgl-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(sgl-lines-sapp windowed) - fips_files(sgl-lines-sapp.c) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(sgl-lines-sapp-ui windowed) - fips_files(sgl-lines-sapp.c) - fips_deps(sokol dbgui) - target_compile_definitions(sgl-lines-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(sgl-points-sapp windowed) - fips_files(sgl-points-sapp.c) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(sgl-points-sapp-ui windowed) - fips_files(sgl-points-sapp.c) - fips_deps(sokol dbgui) - target_compile_definitions(sgl-points-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(sgl-context-sapp windowed) - fips_files(sgl-context-sapp.c) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(sgl-context-sapp-ui windowed) - fips_files(sgl-context-sapp.c) - fips_deps(sokol dbgui) - target_compile_definitions(sgl-context-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(sgl-microui-sapp windowed) - fips_files(sgl-microui-sapp.c) - fips_deps(sokol microui) -fips_end_app() -# NOTE: this uses cimgui -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(sgl-microui-sapp-ui windowed) - fips_files(sgl-microui-sapp.c) - fips_deps(sokol cdbgui cimgui microui) - target_compile_definitions(sgl-microui-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(nuklear-sapp windowed) - fips_files(nuklear-sapp.c) - fips_deps(sokol nuklear) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(nuklear-sapp-ui windowed) - fips_files(nuklear-sapp.c) - fips_deps(sokol nuklear dbgui) - target_compile_definitions(nuklear-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(nuklear-images-sapp windowed) - fips_files(nuklear-images-sapp.c) - fips_deps(sokol nuklear) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(nuklear-images-sapp-ui windowed) - fips_files(nuklear-images-sapp.c) - fips_deps(sokol nuklear dbgui) - target_compile_definitions(nuklear-images-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(uniformtypes-sapp windowed) +# fips_files(uniformtypes-sapp.c) +# sokol_shader(uniformtypes-sapp.glsl ${slang}) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(uniformtypes-sapp-ui windowed) +# fips_files(uniformtypes-sapp.c) +# sokol_shader(uniformtypes-sapp.glsl ${slang}) +# fips_deps(sokol dbgui) +# target_compile_definitions(uniformtypes-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(imgui-sapp windowed) +# fips_files(imgui-sapp.cc) +# # use sokol-cpp for testing here, this isn't required though +# fips_deps(sokol-cpp imgui) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(imgui-dock-sapp windowed) +# fips_files(imgui-dock-sapp.cc) +# # use sokol-cpp for testing here, this isn't required though +# fips_deps(sokol-cpp imgui-dock) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(imgui-highdpi-sapp windowed) +# fips_files(imgui-highdpi-sapp.cc) +# fips_deps(sokol imgui) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(cimgui-sapp windowed) +# fips_files(cimgui-sapp.c) +# fips_deps(sokol cimgui) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(imgui-usercallback-sapp windowed) +# fips_files(imgui-usercallback-sapp.c) +# sokol_shader(imgui-usercallback-sapp.glsl ${slang}) +# fips_deps(sokol cimgui) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(imgui-images-sapp windowed) +# fips_files(imgui-images-sapp.c) +# fips_deps(sokol cimgui) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(imgui-perf-sapp windowed) +# fips_files(imgui-perf-sapp.c) +# fips_deps(sokol cimgui) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(events-sapp windowed) +# fips_files(events-sapp.cc) +# fips_deps(sokol imgui) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(pixelformats-sapp windowed) +# fips_files(pixelformats-sapp.c) +# sokol_shader(pixelformats-sapp.glsl ${slang}) +# fips_deps(sokol cimgui) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(sgl-sapp windowed) +# fips_files(sgl-sapp.c) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(sgl-sapp-ui windowed) +# fips_files(sgl-sapp.c) +# fips_deps(sokol dbgui) +# target_compile_definitions(sgl-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(sgl-lines-sapp windowed) +# fips_files(sgl-lines-sapp.c) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(sgl-lines-sapp-ui windowed) +# fips_files(sgl-lines-sapp.c) +# fips_deps(sokol dbgui) +# target_compile_definitions(sgl-lines-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(sgl-points-sapp windowed) +# fips_files(sgl-points-sapp.c) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(sgl-points-sapp-ui windowed) +# fips_files(sgl-points-sapp.c) +# fips_deps(sokol dbgui) +# target_compile_definitions(sgl-points-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(sgl-context-sapp windowed) +# fips_files(sgl-context-sapp.c) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(sgl-context-sapp-ui windowed) +# fips_files(sgl-context-sapp.c) +# fips_deps(sokol dbgui) +# target_compile_definitions(sgl-context-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(sgl-microui-sapp windowed) +# fips_files(sgl-microui-sapp.c) +# fips_deps(sokol microui) +#fips_end_app() +## NOTE: this uses cimgui +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(sgl-microui-sapp-ui windowed) +# fips_files(sgl-microui-sapp.c) +# fips_deps(sokol cdbgui cimgui microui) +# target_compile_definitions(sgl-microui-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(nuklear-sapp windowed) +# fips_files(nuklear-sapp.c) +# fips_deps(sokol nuklear) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(nuklear-sapp-ui windowed) +# fips_files(nuklear-sapp.c) +# fips_deps(sokol nuklear dbgui) +# target_compile_definitions(nuklear-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(nuklear-images-sapp windowed) +# fips_files(nuklear-images-sapp.c) +# fips_deps(sokol nuklear) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(nuklear-images-sapp-ui windowed) +# fips_files(nuklear-images-sapp.c) +# fips_deps(sokol nuklear dbgui) +# target_compile_definitions(nuklear-images-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(cubemaprt-sapp windowed) fips_files(cubemaprt-sapp.c) @@ -615,117 +615,117 @@ fips_begin_app(sdf-sapp-ui windowed) target_compile_definitions(sdf-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(shapes-sapp windowed) - fips_files(shapes-sapp.c) - sokol_shader(shapes-sapp.glsl ${slang}) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(shapes-sapp-ui windowed) - fips_files(shapes-sapp.c) - sokol_shader(shapes-sapp.glsl ${slang}) - fips_deps(sokol dbgui) - target_compile_definitions(shapes-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(shapes-transform-sapp windowed) - fips_files(shapes-transform-sapp.c) - sokol_shader(shapes-transform-sapp.glsl ${slang}) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(shapes-transform-sapp-ui windowed) - fips_files(shapes-transform-sapp.c) - sokol_shader(shapes-transform-sapp.glsl ${slang}) - fips_deps(sokol dbgui) - target_compile_definitions(shapes-transform-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(primtypes-sapp windowed) - fips_files(primtypes-sapp.c) - sokol_shader(primtypes-sapp.glsl ${slang}) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(primtypes-sapp-ui windowed) - fips_files(primtypes-sapp.c) - sokol_shader(primtypes-sapp.glsl ${slang}) - fips_deps(sokol dbgui) - target_compile_definitions(primtypes-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(drawcallperf-sapp windowed) - fips_files(drawcallperf-sapp.c) - sokol_shader(drawcallperf-sapp.glsl ${slang}) - fips_deps(sokol cimgui) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(debugtext-sapp windowed) - fips_files(debugtext-sapp.c) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(debugtext-sapp-ui windowed) - fips_files(debugtext-sapp.c) - fips_deps(sokol dbgui) - target_compile_definitions(debugtext-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(debugtext-printf-sapp windowed) - fips_files(debugtext-printf-sapp.c) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(debugtext-printf-sapp-ui windowed) - fips_files(debugtext-printf-sapp.c) - fips_deps(sokol dbgui) - target_compile_definitions(debugtext-printf-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(debugtext-userfont-sapp windowed) - fips_files(debugtext-userfont-sapp.c) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(debugtext-userfont-sapp-ui windowed) - fips_files(debugtext-userfont-sapp.c) - fips_deps(sokol dbgui) - target_compile_definitions(debugtext-userfont-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(debugtext-context-sapp windowed) - fips_files(debugtext-context-sapp.c) - sokol_shader(debugtext-context-sapp.glsl ${slang}) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(debugtext-context-sapp-ui windowed) - fips_files(debugtext-context-sapp.c) - sokol_shader(debugtext-context-sapp.glsl ${slang}) - fips_deps(sokol dbgui) - target_compile_definitions(debugtext-context-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(debugtext-layers-sapp windowed) - fips_files(debugtext-layers-sapp.c) - fips_deps(sokol) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(debugtext-layers-sapp-ui windowed) - fips_files(debugtext-layers-sapp.c) - fips_deps(sokol dbgui) - target_compile_definitions(debugtext-layers-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(shapes-sapp windowed) +# fips_files(shapes-sapp.c) +# sokol_shader(shapes-sapp.glsl ${slang}) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(shapes-sapp-ui windowed) +# fips_files(shapes-sapp.c) +# sokol_shader(shapes-sapp.glsl ${slang}) +# fips_deps(sokol dbgui) +# target_compile_definitions(shapes-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(shapes-transform-sapp windowed) +# fips_files(shapes-transform-sapp.c) +# sokol_shader(shapes-transform-sapp.glsl ${slang}) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(shapes-transform-sapp-ui windowed) +# fips_files(shapes-transform-sapp.c) +# sokol_shader(shapes-transform-sapp.glsl ${slang}) +# fips_deps(sokol dbgui) +# target_compile_definitions(shapes-transform-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(primtypes-sapp windowed) +# fips_files(primtypes-sapp.c) +# sokol_shader(primtypes-sapp.glsl ${slang}) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(primtypes-sapp-ui windowed) +# fips_files(primtypes-sapp.c) +# sokol_shader(primtypes-sapp.glsl ${slang}) +# fips_deps(sokol dbgui) +# target_compile_definitions(primtypes-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(drawcallperf-sapp windowed) +# fips_files(drawcallperf-sapp.c) +# sokol_shader(drawcallperf-sapp.glsl ${slang}) +# fips_deps(sokol cimgui) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(debugtext-sapp windowed) +# fips_files(debugtext-sapp.c) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(debugtext-sapp-ui windowed) +# fips_files(debugtext-sapp.c) +# fips_deps(sokol dbgui) +# target_compile_definitions(debugtext-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(debugtext-printf-sapp windowed) +# fips_files(debugtext-printf-sapp.c) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(debugtext-printf-sapp-ui windowed) +# fips_files(debugtext-printf-sapp.c) +# fips_deps(sokol dbgui) +# target_compile_definitions(debugtext-printf-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(debugtext-userfont-sapp windowed) +# fips_files(debugtext-userfont-sapp.c) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(debugtext-userfont-sapp-ui windowed) +# fips_files(debugtext-userfont-sapp.c) +# fips_deps(sokol dbgui) +# target_compile_definitions(debugtext-userfont-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(debugtext-context-sapp windowed) +# fips_files(debugtext-context-sapp.c) +# sokol_shader(debugtext-context-sapp.glsl ${slang}) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(debugtext-context-sapp-ui windowed) +# fips_files(debugtext-context-sapp.c) +# sokol_shader(debugtext-context-sapp.glsl ${slang}) +# fips_deps(sokol dbgui) +# target_compile_definitions(debugtext-context-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(debugtext-layers-sapp windowed) +# fips_files(debugtext-layers-sapp.c) +# fips_deps(sokol) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(debugtext-layers-sapp-ui windowed) +# fips_files(debugtext-layers-sapp.c) +# fips_deps(sokol dbgui) +# target_compile_definitions(debugtext-layers-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(saudio-sapp windowed) fips_files(saudio-sapp.c) @@ -735,55 +735,55 @@ fips_begin_app(saudio-sapp windowed) endif() fips_end_app() -fips_ide_group(Samples) -fips_begin_app(icon-sapp windowed) - fips_files(icon-sapp.c) - fips_deps(sokol) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(droptest-sapp windowed) - fips_files(droptest-sapp.c) - fips_deps(sokol cimgui) - if (FIPS_IOS) - fips_files(ios-info.plist) - endif() -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(fontstash-sapp windowed) - fips_files(fontstash-sapp.c) - fips_deps(sokol fileutil) - fips_dir(data) - fipsutil_copy(fontstash.yml) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(fontstash-sapp-ui windowed) - fips_files(fontstash-sapp.c) - fips_deps(sokol fileutil dbgui) - fips_dir(data) - fipsutil_copy(fontstash.yml) - target_compile_definitions(fontstash-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(fontstash-layers-sapp windowed) - fips_files(fontstash-layers-sapp.c) - fips_deps(sokol fileutil) - sokol_shader(fontstash-layers-sapp.glsl ${slang}) - fips_dir(data) - fipsutil_copy(fontstash.yml) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(fontstash-layers-sapp-ui windowed) - fips_files(fontstash-layers-sapp.c) - fips_deps(sokol fileutil dbgui) - sokol_shader(fontstash-layers-sapp.glsl ${slang}) - fips_dir(data) - fipsutil_copy(fontstash.yml) - target_compile_definitions(fontstash-layers-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(icon-sapp windowed) +# fips_files(icon-sapp.c) +# fips_deps(sokol) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(droptest-sapp windowed) +# fips_files(droptest-sapp.c) +# fips_deps(sokol cimgui) +# if (FIPS_IOS) +# fips_files(ios-info.plist) +# endif() +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(fontstash-sapp windowed) +# fips_files(fontstash-sapp.c) +# fips_deps(sokol fileutil) +# fips_dir(data) +# fipsutil_copy(fontstash.yml) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(fontstash-sapp-ui windowed) +# fips_files(fontstash-sapp.c) +# fips_deps(sokol fileutil dbgui) +# fips_dir(data) +# fipsutil_copy(fontstash.yml) +# target_compile_definitions(fontstash-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(fontstash-layers-sapp windowed) +# fips_files(fontstash-layers-sapp.c) +# fips_deps(sokol fileutil) +# sokol_shader(fontstash-layers-sapp.glsl ${slang}) +# fips_dir(data) +# fipsutil_copy(fontstash.yml) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(fontstash-layers-sapp-ui windowed) +# fips_files(fontstash-layers-sapp.c) +# fips_deps(sokol fileutil dbgui) +# sokol_shader(fontstash-layers-sapp.glsl ${slang}) +# fips_dir(data) +# fipsutil_copy(fontstash.yml) +# target_compile_definitions(fontstash-layers-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(modplay-sapp windowed) fips_files(modplay-sapp.c) @@ -795,15 +795,15 @@ fips_begin_app(modplay-sapp windowed) fips_deps(sokol libmodplug) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(restart-sapp windowed) - fips_files(restart-sapp.c) - sokol_shader(restart-sapp.glsl ${slang}) - fips_dir(data) - fipsutil_copy(restart-assets.yml) - fips_deps(sokol fileutil stb libmodplug) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(restart-sapp windowed) +# fips_files(restart-sapp.c) +# sokol_shader(restart-sapp.glsl ${slang}) +# fips_dir(data) +# fipsutil_copy(restart-assets.yml) +# fips_deps(sokol fileutil stb libmodplug) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(plmpeg-sapp windowed) fips_files(plmpeg-sapp.c) @@ -822,24 +822,24 @@ fips_begin_app(plmpeg-sapp-ui windowed) target_compile_definitions(plmpeg-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(cgltf-sapp windowed) - fips_files(cgltf-sapp.c) - sokol_shader(cgltf-sapp.glsl ${slang}) - fips_dir(data) - fipsutil_copy(cgltf-assets.yml) - fips_deps(sokol basisu fileutil) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(cgltf-sapp-ui windowed) - fips_files(cgltf-sapp.c) - sokol_shader(cgltf-sapp.glsl ${slang}) - fips_dir(data) - fipsutil_copy(cgltf-assets.yml) - fips_deps(sokol dbgui basisu fileutil) - target_compile_definitions(cgltf-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(cgltf-sapp windowed) +# fips_files(cgltf-sapp.c) +# sokol_shader(cgltf-sapp.glsl ${slang}) +# fips_dir(data) +# fipsutil_copy(cgltf-assets.yml) +# fips_deps(sokol basisu fileutil) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(cgltf-sapp-ui windowed) +# fips_files(cgltf-sapp.c) +# sokol_shader(cgltf-sapp.glsl ${slang}) +# fips_dir(data) +# fipsutil_copy(cgltf-assets.yml) +# fips_deps(sokol dbgui basisu fileutil) +# target_compile_definitions(cgltf-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# fips_ide_group(Samples) fips_begin_app(loadpng-sapp windowed) fips_files(loadpng-sapp.c) @@ -858,133 +858,133 @@ fips_begin_app(loadpng-sapp-ui windowed) target_compile_definitions(loadpng-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -fips_ide_group(Samples) -fips_begin_app(spine-simple-sapp windowed) - fips_files(spine-simple-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(spine-simple-sapp-ui windowed) - fips_files(spine-simple-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil dbgui) - target_compile_definitions(spine-simple-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(spine-inspector-sapp windowed) - fips_files(spine-inspector-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil cimgui) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(spine-skinsets-sapp windowed) - fips_files(spine-skinsets-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(spine-skinsets-sapp-ui windowed) - fips_files(spine-skinsets-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil dbgui) - target_compile_definitions(spine-skinsets-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(spine-layers-sapp windowed) - fips_files(spine-layers-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(spine-layers-sapp-ui windowed) - fips_files(spine-layers-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil dbgui) - target_compile_definitions(spine-layers-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(spine-contexts-sapp windowed) - fips_files(spine-contexts-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(spine-contexts-sapp-ui windowed) - fips_files(spine-contexts-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil dbgui) - target_compile_definitions(spine-contexts-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(spine-switch-skinsets-sapp windowed) - fips_files(spine-switch-skinsets-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil) -fips_end_app() -fips_ide_group(SamplesWithDebugUI) -fips_begin_app(spine-switch-skinsets-sapp-ui windowed) - fips_files(spine-switch-skinsets-sapp.c) - fips_dir(data) - fipsutil_copy(spine-assets.yml) - fips_deps(sokol spine-c stb fileutil dbgui) - target_compile_definitions(spine-switch-skinsets-sapp-ui PRIVATE USE_DBG_UI) -fips_end_app() - -fips_ide_group(Samples) -fips_begin_app(ozz-anim-sapp windowed) - fips_files(ozz-anim-sapp.cc) - fips_dir(data) - fipsutil_copy(ozz-anim-assets.yml) - fips_deps(sokol fileutil ozzanim imgui) -fips_end_app() - -fips_begin_app(ozz-skin-sapp windowed) - fips_files(ozz-skin-sapp.cc) - sokol_shader(ozz-skin-sapp.glsl ${slang}) - fips_dir(data) - fipsutil_copy(ozz-skin-assets.yml) - fips_deps(sokol fileutil ozzanim imgui) -fips_end_app() - -fips_begin_app(ozz-storagebuffer-sapp windowed) - fips_files(ozz-storagebuffer-sapp.cc) - sokol_shader(ozz-storagebuffer-sapp.glsl ${slang}) - fips_dir(data) - fipsutil_copy(ozz-skin-assets.yml) - fips_deps(sokol fileutil ozzanim imgui) -fips_end_app() - -fips_begin_app(shdfeatures-sapp windowed) - fips_files(shdfeatures-sapp.c) - sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "none" "NONE") - sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "slm" "SKINNING:LIGHTING:MATERIAL") - sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "sl" "SKINNING:LIGHTING") - sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "s" "SKINNING") - sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "sm" "SKINNING:MATERIAL") - sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "lm" "LIGHTING:MATERIAL") - sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "m" "MATERIAL") - sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "l" "LIGHTING") - fips_dir(data) - fipsutil_copy(ozz-skin-assets.yml) - fips_deps(sokol fileutil ozzutil cimgui) -fips_end_app() - +#fips_ide_group(Samples) +#fips_begin_app(spine-simple-sapp windowed) +# fips_files(spine-simple-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(spine-simple-sapp-ui windowed) +# fips_files(spine-simple-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil dbgui) +# target_compile_definitions(spine-simple-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(spine-inspector-sapp windowed) +# fips_files(spine-inspector-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil cimgui) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(spine-skinsets-sapp windowed) +# fips_files(spine-skinsets-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(spine-skinsets-sapp-ui windowed) +# fips_files(spine-skinsets-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil dbgui) +# target_compile_definitions(spine-skinsets-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(spine-layers-sapp windowed) +# fips_files(spine-layers-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(spine-layers-sapp-ui windowed) +# fips_files(spine-layers-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil dbgui) +# target_compile_definitions(spine-layers-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(spine-contexts-sapp windowed) +# fips_files(spine-contexts-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(spine-contexts-sapp-ui windowed) +# fips_files(spine-contexts-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil dbgui) +# target_compile_definitions(spine-contexts-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(spine-switch-skinsets-sapp windowed) +# fips_files(spine-switch-skinsets-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil) +#fips_end_app() +#fips_ide_group(SamplesWithDebugUI) +#fips_begin_app(spine-switch-skinsets-sapp-ui windowed) +# fips_files(spine-switch-skinsets-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil dbgui) +# target_compile_definitions(spine-switch-skinsets-sapp-ui PRIVATE USE_DBG_UI) +#fips_end_app() +# +#fips_ide_group(Samples) +#fips_begin_app(ozz-anim-sapp windowed) +# fips_files(ozz-anim-sapp.cc) +# fips_dir(data) +# fipsutil_copy(ozz-anim-assets.yml) +# fips_deps(sokol fileutil ozzanim imgui) +#fips_end_app() +# +#fips_begin_app(ozz-skin-sapp windowed) +# fips_files(ozz-skin-sapp.cc) +# sokol_shader(ozz-skin-sapp.glsl ${slang}) +# fips_dir(data) +# fipsutil_copy(ozz-skin-assets.yml) +# fips_deps(sokol fileutil ozzanim imgui) +#fips_end_app() +# +#fips_begin_app(ozz-storagebuffer-sapp windowed) +# fips_files(ozz-storagebuffer-sapp.cc) +# sokol_shader(ozz-storagebuffer-sapp.glsl ${slang}) +# fips_dir(data) +# fipsutil_copy(ozz-skin-assets.yml) +# fips_deps(sokol fileutil ozzanim imgui) +#fips_end_app() +# +#fips_begin_app(shdfeatures-sapp windowed) +# fips_files(shdfeatures-sapp.c) +# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "none" "NONE") +# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "slm" "SKINNING:LIGHTING:MATERIAL") +# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "sl" "SKINNING:LIGHTING") +# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "s" "SKINNING") +# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "sm" "SKINNING:MATERIAL") +# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "lm" "LIGHTING:MATERIAL") +# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "m" "MATERIAL") +# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "l" "LIGHTING") +# fips_dir(data) +# fipsutil_copy(ozz-skin-assets.yml) +# fips_deps(sokol fileutil ozzutil cimgui) +#fips_end_app() +# if (NOT FIPS_ANDROID) fips_ide_group(Samples) fips_begin_app(noentry-sapp windowed) diff --git a/sapp/arraytex-sapp.c b/sapp/arraytex-sapp.c index 75c0150c..40f8da1a 100644 --- a/sapp/arraytex-sapp.c +++ b/sapp/arraytex-sapp.c @@ -144,8 +144,8 @@ void init(void) { state.bind = (sg_bindings) { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .images[IMG_arraytex_tex] = img, - .samplers[SMP_arraytex_smp] = smp, + .images[IMG_tex] = img, + .samplers[SMP_smp] = smp, }; } @@ -173,7 +173,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_arraytex_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/arraytex-sapp.glsl b/sapp/arraytex-sapp.glsl index 675a2e8b..23056e9b 100644 --- a/sapp/arraytex-sapp.glsl +++ b/sapp/arraytex-sapp.glsl @@ -5,7 +5,7 @@ @ctype vec2 hmm_vec2 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; vec2 offset0; vec2 offset1; @@ -28,8 +28,8 @@ void main() { @end @fs fs -uniform texture2DArray tex; -uniform sampler smp; +layout(binding=0) uniform texture2DArray tex; +layout(binding=0) uniform sampler smp; in vec3 uv0; in vec3 uv1; diff --git a/sapp/blend-sapp.c b/sapp/blend-sapp.c index 769a00e2..e17149ef 100644 --- a/sapp/blend-sapp.c +++ b/sapp/blend-sapp.c @@ -114,7 +114,7 @@ void frame(void) { /* draw a background quad */ sg_apply_pipeline(state.bg_pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_bg_bg_fs_params, &SG_RANGE(state.bg_fs_params)); + sg_apply_uniforms(UB_bg_fs_params, &SG_RANGE(state.bg_fs_params)); sg_draw(0, 4, 1); // draw the blended quads @@ -130,7 +130,7 @@ void frame(void) { sg_apply_pipeline(state.pips[src][dst]); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_quad_quad_vs_params, &SG_RANGE(state.quad_vs_params)); + sg_apply_uniforms(UB_quad_vs_params, &SG_RANGE(state.quad_vs_params)); sg_draw(0, 4, 1); } } diff --git a/sapp/blend-sapp.glsl b/sapp/blend-sapp.glsl index 861a2945..be4d2ad8 100644 --- a/sapp/blend-sapp.glsl +++ b/sapp/blend-sapp.glsl @@ -11,7 +11,7 @@ void main() { @end @fs fs_bg -uniform bg_fs_params { +layout(binding=0) uniform bg_fs_params { float tick; }; @@ -26,7 +26,7 @@ void main() { @program bg vs_bg fs_bg @vs vs_quad -uniform quad_vs_params { +layout(binding=0) uniform quad_vs_params { mat4 mvp; }; diff --git a/sapp/cube-sapp.c b/sapp/cube-sapp.c index 0ea7b5d4..3e4978c0 100644 --- a/sapp/cube-sapp.c +++ b/sapp/cube-sapp.c @@ -132,7 +132,7 @@ void frame(void) { }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_cube_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/cube-sapp.glsl b/sapp/cube-sapp.glsl index 4dc4082c..7ff7bb6a 100644 --- a/sapp/cube-sapp.glsl +++ b/sapp/cube-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; diff --git a/sapp/cubemaprt-sapp.c b/sapp/cubemaprt-sapp.c index 24b1f23c..3a8f5d13 100644 --- a/sapp/cubemaprt-sapp.c +++ b/sapp/cubemaprt-sapp.c @@ -256,8 +256,8 @@ void frame(void) { sg_apply_bindings(&(sg_bindings){ .vertex_buffers[0] = app.cube.vbuf, .index_buffer = app.cube.ibuf, - .images[IMG_cube_tex] = app.cubemap, - .samplers[SMP_cube_smp] = app.smp, + .images[IMG_tex] = app.cubemap, + .samplers[SMP_smp] = app.smp, }); shape_uniforms_t uniforms = { .mvp = HMM_MultiplyMat4(view_proj, model), @@ -266,7 +266,7 @@ void frame(void) { .light_dir = app.light_dir, .eye_pos = HMM_Vec4v(eye_pos, 1.0f) }; - sg_apply_uniforms(UB_cube_shape_uniforms, &SG_RANGE(uniforms)); + sg_apply_uniforms(UB_shape_uniforms, &SG_RANGE(uniforms)); sg_draw(0, app.cube.num_elements, 1); __dbgui_draw(); @@ -311,7 +311,7 @@ static void draw_cubes(sg_pipeline pip, hmm_vec3 eye_pos, hmm_mat4 view_proj) { .light_dir = app.light_dir, .eye_pos = HMM_Vec4v(eye_pos, 1.0f) }; - sg_apply_uniforms(UB_cube_shape_uniforms, &SG_RANGE(uniforms)); + sg_apply_uniforms(UB_shape_uniforms, &SG_RANGE(uniforms)); sg_draw(0, app.cube.num_elements, 1); } } diff --git a/sapp/cubemaprt-sapp.glsl b/sapp/cubemaprt-sapp.glsl index 67491965..05b90e78 100644 --- a/sapp/cubemaprt-sapp.glsl +++ b/sapp/cubemaprt-sapp.glsl @@ -6,7 +6,7 @@ // same vertex shader for offscreen- and default-pass @vs vs -uniform shape_uniforms { +layout(binding=0) uniform shape_uniforms { mat4 mvp; // model-view-projection matrix mat4 model; // model matrix vec4 shape_color; @@ -75,8 +75,8 @@ void main() { @include_block lighting @include_block fs_inputs -uniform textureCube tex; -uniform sampler smp; +layout(binding=0) uniform textureCube tex; +layout(binding=0) uniform sampler smp; out vec4 frag_color; void main() { diff --git a/sapp/dyntex-sapp.c b/sapp/dyntex-sapp.c index 58f4a9e2..3b3082b8 100644 --- a/sapp/dyntex-sapp.c +++ b/sapp/dyntex-sapp.c @@ -131,8 +131,8 @@ void init(void) { state.bind = (sg_bindings) { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .images[IMG_dyntex_tex] = img, - .samplers[SMP_dyntex_smp] = smp, + .images[IMG_tex] = img, + .samplers[SMP_smp] = smp, }; // initialize the game-of-life state @@ -164,7 +164,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_dyntex_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/dyntex-sapp.glsl b/sapp/dyntex-sapp.glsl index 5bb8c3f3..86488609 100644 --- a/sapp/dyntex-sapp.glsl +++ b/sapp/dyntex-sapp.glsl @@ -4,7 +4,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -23,8 +23,8 @@ void main() { @end @fs fs -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; layout(location=0) in vec4 color; layout(location=1) in vec2 uv; out vec4 frag_color; diff --git a/sapp/instancing-pull-sapp.glsl b/sapp/instancing-pull-sapp.glsl index 945620fe..41688b63 100644 --- a/sapp/instancing-pull-sapp.glsl +++ b/sapp/instancing-pull-sapp.glsl @@ -3,7 +3,7 @@ @ctype vec4 hmm_vec4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; diff --git a/sapp/instancing-sapp.c b/sapp/instancing-sapp.c index d4678120..5fecb54e 100644 --- a/sapp/instancing-sapp.c +++ b/sapp/instancing-sapp.c @@ -150,7 +150,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_instancing_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 24, state.cur_num_particles); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/instancing-sapp.glsl b/sapp/instancing-sapp.glsl index eec40f0b..1a715804 100644 --- a/sapp/instancing-sapp.glsl +++ b/sapp/instancing-sapp.glsl @@ -4,7 +4,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; diff --git a/sapp/layerrender-sapp.c b/sapp/layerrender-sapp.c index 460319ac..a9fa5f6b 100644 --- a/sapp/layerrender-sapp.c +++ b/sapp/layerrender-sapp.c @@ -165,8 +165,8 @@ static void init(void) { state.display.bindings = (sg_bindings){ .vertex_buffers[0] = state.vbuf, .index_buffer = state.ibuf, - .images[IMG_display_tex] = state.img, - .samplers[SMP_display_smp] = state.smp, + .images[IMG_tex] = state.img, + .samplers[SMP_smp] = state.smp, }; // initialize pass actions @@ -202,7 +202,7 @@ static void frame(void) { default: ry = -ry; break; } const vs_params_t offscreen_vsparams = compute_offscreen_vsparams(rx, ry); - sg_apply_uniforms(UB_offscreen_vs_params, &SG_RANGE(offscreen_vsparams)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(offscreen_vsparams)); const sshape_element_range_t shape = state.offscreen.shapes[i]; sg_draw(shape.base_element, shape.num_elements, 1); sg_end_pass(); @@ -212,7 +212,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bindings); - sg_apply_uniforms(UB_display_vs_params, &SG_RANGE(display_vsparams)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(display_vsparams)); sg_draw(state.display.plane.base_element, state.display.plane.num_elements, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/layerrender-sapp.glsl b/sapp/layerrender-sapp.glsl index 4b8fa5a3..43e1cc1a 100644 --- a/sapp/layerrender-sapp.glsl +++ b/sapp/layerrender-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @block vs_uniforms -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @end @@ -44,8 +44,8 @@ void main() { @end @fs fs_display -uniform texture2DArray tex; -uniform sampler smp; +layout(binding=0) uniform texture2DArray tex; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; @@ -58,4 +58,4 @@ void main() { } @end -@program display vs_display fs_display \ No newline at end of file +@program display vs_display fs_display diff --git a/sapp/loadpng-sapp.c b/sapp/loadpng-sapp.c index 7224cde5..7bbc404f 100644 --- a/sapp/loadpng-sapp.c +++ b/sapp/loadpng-sapp.c @@ -63,10 +63,10 @@ static void init(void) { Any draw calls containing such an "incomplete" image handle will be silently dropped. */ - state.bind.images[IMG_loadpng_tex] = sg_alloc_image(); + state.bind.images[IMG_tex] = sg_alloc_image(); // a sampler object - state.bind.samplers[SMP_loadpng_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_LINEAR, .mag_filter = SG_FILTER_LINEAR, }); @@ -173,7 +173,7 @@ static void fetch_callback(const sfetch_response_t* response) { &num_channels, desired_channels); if (pixels) { // ok, time to actually initialize the sokol-gfx texture - sg_init_image(state.bind.images[IMG_loadpng_tex], &(sg_image_desc){ + sg_init_image(state.bind.images[IMG_tex], &(sg_image_desc){ .width = png_width, .height = png_height, .pixel_format = SG_PIXELFORMAT_RGBA8, @@ -216,7 +216,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_loadpng_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/loadpng-sapp.glsl b/sapp/loadpng-sapp.glsl index ec4e2888..13067ce1 100644 --- a/sapp/loadpng-sapp.glsl +++ b/sapp/loadpng-sapp.glsl @@ -4,7 +4,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -19,8 +19,8 @@ void main() { @end @fs fs -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/mipmap-sapp.c b/sapp/mipmap-sapp.c index c1c3b059..a3f763e8 100644 --- a/sapp/mipmap-sapp.c +++ b/sapp/mipmap-sapp.c @@ -151,7 +151,7 @@ void frame(void) { sg_bindings bind = { .vertex_buffers[0] = state.vbuf, - .images[IMG_mipmap_tex] = state.img, + .images[IMG_tex] = state.img, }; sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); @@ -161,9 +161,9 @@ void frame(void) { hmm_mat4 model = HMM_MultiplyMat4(HMM_Translate(HMM_Vec3(x, y, 0.0f)), rm); vs_params.mvp = HMM_MultiplyMat4(view_proj, model); - bind.samplers[SMP_mipmap_smp] = state.smp[i]; + bind.samplers[SMP_smp] = state.smp[i]; sg_apply_bindings(&bind); - sg_apply_uniforms(UB_mipmap_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } __dbgui_draw(); diff --git a/sapp/mipmap-sapp.glsl b/sapp/mipmap-sapp.glsl index 371e4904..7de66863 100644 --- a/sapp/mipmap-sapp.glsl +++ b/sapp/mipmap-sapp.glsl @@ -4,7 +4,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -20,8 +20,8 @@ void main() { @end @fs fs -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/miprender-sapp.c b/sapp/miprender-sapp.c index db1dbe95..d9ce9725 100644 --- a/sapp/miprender-sapp.c +++ b/sapp/miprender-sapp.c @@ -169,8 +169,8 @@ static void init(void) { state.display.bindings = (sg_bindings) { .vertex_buffers[0] = state.vbuf, .index_buffer = state.ibuf, - .images[IMG_display_tex] = state.img, - .samplers[SMP_display_smp] = state.smp, + .images[IMG_tex] = state.img, + .samplers[SMP_smp] = state.smp, }; // initialize pass actions @@ -199,7 +199,7 @@ static void frame(void) { }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bindings); - sg_apply_uniforms(UB_offscreen_vs_params, &SG_RANGE(offscreen_vsparams)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(offscreen_vsparams)); const sshape_element_range_t shape = state.offscreen.shapes[i % NUM_SHAPES]; sg_draw(shape.base_element, shape.num_elements, 1); sg_end_pass(); @@ -209,7 +209,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bindings); - sg_apply_uniforms(UB_display_vs_params, &SG_RANGE(display_vsparams)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(display_vsparams)); sg_draw(state.display.plane.base_element, state.display.plane.num_elements, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/miprender-sapp.glsl b/sapp/miprender-sapp.glsl index 036ca80c..5d5fafc6 100644 --- a/sapp/miprender-sapp.glsl +++ b/sapp/miprender-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @block uniforms -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @end @@ -44,8 +44,8 @@ void main() { @end @fs fs_display -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/mrt-pixelformats-sapp.c b/sapp/mrt-pixelformats-sapp.c index 7bc9fac9..53c1cd18 100644 --- a/sapp/mrt-pixelformats-sapp.c +++ b/sapp/mrt-pixelformats-sapp.c @@ -128,9 +128,9 @@ static void init(void) { .layout = { .buffers[0] = sshape_vertex_buffer_layout_state(), .attrs = { - [ATTR_vs_offscreen_in_pos] = sshape_position_vertex_attr_state(), - [ATTR_vs_offscreen_in_normal] = sshape_normal_vertex_attr_state(), - [ATTR_vs_offscreen_in_color] = sshape_color_vertex_attr_state() + [ATTR_offscreen_in_pos] = sshape_position_vertex_attr_state(), + [ATTR_offscreen_in_normal] = sshape_normal_vertex_attr_state(), + [ATTR_offscreen_in_color] = sshape_color_vertex_attr_state() } }, .depth = { @@ -174,7 +174,7 @@ static void init(void) { state.display.pip = sg_make_pipeline(&(sg_pipeline_desc){ .shader = sg_make_shader(quad_shader_desc(sg_query_backend())), .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, - .layout.attrs[ATTR_vs_quad_pos].format = SG_VERTEXFORMAT_FLOAT2, + .layout.attrs[ATTR_quad_pos].format = SG_VERTEXFORMAT_FLOAT2, }); // a sampler for sampling the offscreen render target as textures @@ -224,7 +224,7 @@ static void frame(void) { }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_offscreen_params, &SG_RANGE(offscreen_params)); + sg_apply_uniforms(UB_offscreen_params, &SG_RANGE(offscreen_params)); sg_draw(state.offscreen.donut.base_element, state.offscreen.donut.num_elements, 1); sg_end_pass(); @@ -238,7 +238,7 @@ static void frame(void) { const int y0 = (disp_height - quad_height) / 2; sg_bindings bindings = { .vertex_buffers[0] = state.display.vbuf, - .fs.samplers[SLOT_smp] = state.display.smp, + .samplers[SMP_smp] = state.display.smp, }; sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); @@ -248,22 +248,22 @@ static void frame(void) { sg_apply_viewport(x0 + i*(quad_width+quad_gap), y0, quad_width, quad_height, true); switch (i) { case 0: - bindings.fs.images[0] = state.offscreen.depth_img; + bindings.images[IMG_tex] = state.offscreen.depth_img; quad_params.color_bias = 0.0f; quad_params.color_scale = 0.5f; break; case 1: - bindings.fs.images[0] = state.offscreen.normal_img; + bindings.images[IMG_tex] = state.offscreen.normal_img; quad_params.color_bias = 1.0f; quad_params.color_scale = 0.5f; break; case 2: - bindings.fs.images[0] = state.offscreen.color_img; + bindings.images[IMG_tex] = state.offscreen.color_img; quad_params.color_bias = 0.0f; quad_params.color_scale = 1.0f; break; } - sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_quad_params, &SG_RANGE(quad_params)); + sg_apply_uniforms(UB_quad_params, &SG_RANGE(quad_params)); sg_apply_bindings(&bindings); sg_draw(0, 4, 1); } diff --git a/sapp/mrt-pixelformats-sapp.glsl b/sapp/mrt-pixelformats-sapp.glsl index 186c8ea6..43722666 100644 --- a/sapp/mrt-pixelformats-sapp.glsl +++ b/sapp/mrt-pixelformats-sapp.glsl @@ -7,7 +7,7 @@ //--- offscreen MRT shader @vs vs_offscreen -uniform offscreen_params { +layout(binding=0) uniform offscreen_params { mat4 mvp; }; @@ -62,13 +62,13 @@ void main() { @fs fs_quad @image_sample_type tex unfilterable_float @sampler_type smp nonfiltering -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; -uniform quad_params { +layout(binding=0) uniform quad_params { float color_bias; float color_scale; }; diff --git a/sapp/mrt-sapp.c b/sapp/mrt-sapp.c index 44635824..a96fa41d 100644 --- a/sapp/mrt-sapp.c +++ b/sapp/mrt-sapp.c @@ -249,11 +249,11 @@ void init(void) { state.fsq.bind = (sg_bindings){ .vertex_buffers[0] = quad_vbuf, .images = { - [IMG_fsq_tex0] = state.offscreen.atts_desc.resolves[0].image, - [IMG_fsq_tex1] = state.offscreen.atts_desc.resolves[1].image, - [IMG_fsq_tex2] = state.offscreen.atts_desc.resolves[2].image + [IMG_tex0] = state.offscreen.atts_desc.resolves[0].image, + [IMG_tex1] = state.offscreen.atts_desc.resolves[1].image, + [IMG_tex2] = state.offscreen.atts_desc.resolves[2].image }, - .samplers[SMP_fsq_smp] = smp, + .samplers[SMP_smp] = smp, }; // pipeline and resource bindings to render debug-visualization quads @@ -267,7 +267,7 @@ void init(void) { }), state.dbg.bind = (sg_bindings){ .vertex_buffers[0] = quad_vbuf, - .samplers[SMP_dbg_smp] = smp, + .samplers[SMP_smp] = smp, // images will be filled right before rendering }; } @@ -293,7 +293,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.offscreen.pass_action, .attachments = state.offscreen.atts }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(UB_offscreen_offscreen_params, &SG_RANGE(offscreen_params)); + sg_apply_uniforms(UB_offscreen_params, &SG_RANGE(offscreen_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -301,12 +301,12 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.fsq.pip); sg_apply_bindings(&state.fsq.bind); - sg_apply_uniforms(UB_fsq_fsq_params, &SG_RANGE(fsq_params)); + sg_apply_uniforms(UB_fsq_params, &SG_RANGE(fsq_params)); sg_draw(0, 4, 1); sg_apply_pipeline(state.dbg.pip); for (int i = 0; i < 3; i++) { sg_apply_viewport(i*100, 0, 100, 100, false); - state.dbg.bind.images[IMG_dbg_tex] = state.offscreen.atts_desc.resolves[i].image; + state.dbg.bind.images[IMG_tex] = state.offscreen.atts_desc.resolves[i].image; sg_apply_bindings(&state.dbg.bind); sg_draw(0, 4, 1); } diff --git a/sapp/mrt-sapp.glsl b/sapp/mrt-sapp.glsl index 736ff95e..57a0981d 100644 --- a/sapp/mrt-sapp.glsl +++ b/sapp/mrt-sapp.glsl @@ -7,7 +7,7 @@ // shaders for offscreen-pass rendering @vs vs_offscreen -uniform offscreen_params { +layout(binding=0) uniform offscreen_params { mat4 mvp; }; @@ -42,7 +42,7 @@ void main() { @vs vs_fsq @glsl_options flip_vert_y -uniform fsq_params { +layout(binding=0) uniform fsq_params { vec2 offset; }; @@ -61,10 +61,10 @@ void main() { @end @fs fs_fsq -uniform texture2D tex0; -uniform texture2D tex1; -uniform texture2D tex2; -uniform sampler smp; +layout(binding=0) uniform texture2D tex0; +layout(binding=1) uniform texture2D tex1; +layout(binding=2) uniform texture2D tex2; +layout(binding=0) uniform sampler smp; in vec2 uv0; in vec2 uv1; @@ -96,8 +96,8 @@ void main() { @end @fs fs_dbg -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/noentry-dll-sapp.c b/sapp/noentry-dll-sapp.c index c24262f1..5e477627 100644 --- a/sapp/noentry-dll-sapp.c +++ b/sapp/noentry-dll-sapp.c @@ -166,7 +166,7 @@ void frame(void* user_data) { }); sg_apply_pipeline(state->pip); sg_apply_bindings(&state->bind); - sg_apply_uniforms(UB_noentry_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/sapp/noentry-dll-sapp.glsl b/sapp/noentry-dll-sapp.glsl index d8a31214..9a23d4ea 100644 --- a/sapp/noentry-dll-sapp.glsl +++ b/sapp/noentry-dll-sapp.glsl @@ -4,7 +4,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; diff --git a/sapp/noentry-sapp.c b/sapp/noentry-sapp.c index ed399b08..59433bfc 100644 --- a/sapp/noentry-sapp.c +++ b/sapp/noentry-sapp.c @@ -124,8 +124,8 @@ void init(void* user_data) { // test to provide buffer stride, but no attr offsets .buffers[0].stride = 28, .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4 + [ATTR_noentry_position].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_noentry_color0].format = SG_VERTEXFORMAT_FLOAT4 } }, .shader = shd, @@ -167,7 +167,7 @@ void frame(void* user_data) { }); sg_apply_pipeline(state->pip); sg_apply_bindings(&state->bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sg_end_pass(); sg_commit(); diff --git a/sapp/noentry-sapp.glsl b/sapp/noentry-sapp.glsl index d8a31214..9a23d4ea 100644 --- a/sapp/noentry-sapp.glsl +++ b/sapp/noentry-sapp.glsl @@ -4,7 +4,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; diff --git a/sapp/noninterleaved-sapp.c b/sapp/noninterleaved-sapp.c index 3124415f..8a049778 100644 --- a/sapp/noninterleaved-sapp.c +++ b/sapp/noninterleaved-sapp.c @@ -120,7 +120,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_noninterleaved_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/noninterleaved-sapp.glsl b/sapp/noninterleaved-sapp.glsl index d92fc428..a4564c59 100644 --- a/sapp/noninterleaved-sapp.glsl +++ b/sapp/noninterleaved-sapp.glsl @@ -4,7 +4,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; diff --git a/sapp/offscreen-msaa-sapp.c b/sapp/offscreen-msaa-sapp.c index 8cdf14de..1d9e033f 100644 --- a/sapp/offscreen-msaa-sapp.c +++ b/sapp/offscreen-msaa-sapp.c @@ -202,8 +202,8 @@ static void init(void) { state.display.bind = (sg_bindings) { .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .images[IMG_display_tex] = resolve_image, - .samplers[SMP_display_smp] = smp, + .images[IMG_tex] = resolve_image, + .samplers[SMP_smp] = smp, }; } @@ -236,7 +236,7 @@ static void frame(void) { }); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(UB_offscreen_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(state.sphere.base_element, state.sphere.num_elements, 1); sg_end_pass(); @@ -250,7 +250,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bind); - sg_apply_uniforms(UB_display_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(state.donut.base_element, state.donut.num_elements, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/offscreen-msaa-sapp.glsl b/sapp/offscreen-msaa-sapp.glsl index f596465c..95180dd9 100644 --- a/sapp/offscreen-msaa-sapp.glsl +++ b/sapp/offscreen-msaa-sapp.glsl @@ -5,7 +5,7 @@ // shared code for all shaders @block uniforms -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @end @@ -53,8 +53,8 @@ void main() { @end @fs fs_display -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec4 nrm; in vec2 uv; diff --git a/sapp/offscreen-sapp.c b/sapp/offscreen-sapp.c index 2b207096..509cc3a7 100644 --- a/sapp/offscreen-sapp.c +++ b/sapp/offscreen-sapp.c @@ -173,8 +173,8 @@ static void init(void) { state.display.bind = (sg_bindings){ .vertex_buffers[0] = vbuf, .index_buffer = ibuf, - .images[IMG_default_tex] = color_img, - .samplers[SMP_default_smp] = smp, + .images[IMG_tex] = color_img, + .samplers[SMP_smp] = smp, }; } @@ -203,7 +203,7 @@ static void frame(void) { sg_begin_pass(&state.offscreen.pass); sg_apply_pipeline(state.offscreen.pip); sg_apply_bindings(&state.offscreen.bind); - sg_apply_uniforms(UB_offscreen_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(state.donut.base_element, state.donut.num_elements, 1); sg_end_pass(); @@ -221,7 +221,7 @@ static void frame(void) { }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bind); - sg_apply_uniforms(UB_default_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(state.sphere.base_element, state.sphere.num_elements, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/offscreen-sapp.glsl b/sapp/offscreen-sapp.glsl index 554d1f9e..4da8921c 100644 --- a/sapp/offscreen-sapp.glsl +++ b/sapp/offscreen-sapp.glsl @@ -5,7 +5,7 @@ // shared code for all shaders @block uniforms -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @end @@ -53,8 +53,8 @@ void main() { @end @fs fs_default -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec4 nrm; in vec2 uv; diff --git a/sapp/plmpeg-sapp.c b/sapp/plmpeg-sapp.c index 58c5c2a2..eccee024 100644 --- a/sapp/plmpeg-sapp.c +++ b/sapp/plmpeg-sapp.c @@ -189,7 +189,7 @@ static void init(void) { }, }); - state.bind.samplers[SMP_plmpeg_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_LINEAR, .mag_filter = SG_FILTER_LINEAR, .wrap_u = SG_WRAP_CLAMP_TO_EDGE, @@ -253,7 +253,7 @@ static void frame(void) { if (state.bind.images[0].id != SG_INVALID_ID) { sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_plmpeg_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 24, 1); } __dbgui_draw(); @@ -305,9 +305,9 @@ static void validate_texture(int slot, plm_plane_t* plane) { // the pl_mpeg video callback, copies decoded video data into textures static void video_cb(plm_t* mpeg, plm_frame_t* frame, void* user) { (void)mpeg; (void)user; - validate_texture(IMG_plmpeg_tex_y, &frame->y); - validate_texture(IMG_plmpeg_tex_cb, &frame->cb); - validate_texture(IMG_plmpeg_tex_cr, &frame->cr); + validate_texture(IMG_tex_y, &frame->y); + validate_texture(IMG_tex_cb, &frame->cb); + validate_texture(IMG_tex_cr, &frame->cr); } // the pl_mpeg audio callback, forwards decoded audio samples to sokol-audio diff --git a/sapp/plmpeg-sapp.glsl b/sapp/plmpeg-sapp.glsl index cee56ce9..4df3db4b 100644 --- a/sapp/plmpeg-sapp.glsl +++ b/sapp/plmpeg-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -18,10 +18,10 @@ void main() { @end @fs fs -uniform texture2D tex_y; -uniform texture2D tex_cb; -uniform texture2D tex_cr; -uniform sampler smp; +layout(binding=0) uniform texture2D tex_y; +layout(binding=1) uniform texture2D tex_cb; +layout(binding=2) uniform texture2D tex_cr; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/sbuftex-sapp.glsl b/sapp/sbuftex-sapp.glsl index 615c8721..4dcba60e 100644 --- a/sapp/sbuftex-sapp.glsl +++ b/sapp/sbuftex-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -11,7 +11,7 @@ struct sb_vertex { vec2 uv; }; -readonly buffer vertices { +layout(binding=0) readonly buffer vertices { sb_vertex vtx[]; }; @@ -26,14 +26,14 @@ void main() { @end @fs fs -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; struct sb_color { vec4 color; }; -readonly buffer colors { +layout(binding=1) readonly buffer colors { sb_color clr[]; }; diff --git a/sapp/sdf-sapp.c b/sapp/sdf-sapp.c index db2ff98f..51f0f374 100644 --- a/sapp/sdf-sapp.c +++ b/sapp/sdf-sapp.c @@ -57,7 +57,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_sdf_vs_params, &SG_RANGE(state.vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(state.vs_params)); sg_draw(0, 3, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/sdf-sapp.glsl b/sapp/sdf-sapp.glsl index c0bd6984..78cdc104 100644 --- a/sapp/sdf-sapp.glsl +++ b/sapp/sdf-sapp.glsl @@ -6,7 +6,7 @@ //--- vertex shader @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { float aspect; float time; }; diff --git a/sapp/shadows-depthtex-sapp.c b/sapp/shadows-depthtex-sapp.c index dbbf3835..aa26ff4b 100644 --- a/sapp/shadows-depthtex-sapp.c +++ b/sapp/shadows-depthtex-sapp.c @@ -202,8 +202,8 @@ static void init(void) { state.display.bind = (sg_bindings) { .vertex_buffers[0] = state.vbuf, .index_buffer = state.ibuf, - .images[IMG_display_shadow_map] = state.shadow_map, - .samplers[SMP_display_shadow_sampler] = state.shadow_sampler, + .images[IMG_shadow_map] = state.shadow_map, + .samplers[SMP_shadow_sampler] = state.shadow_sampler, }; // a vertex buffer, pipeline and sampler to render a debug visualization of the shadow map @@ -232,8 +232,8 @@ static void init(void) { }); state.dbg.bind = (sg_bindings){ .vertex_buffers[0] = dbg_vbuf, - .images[IMG_dbg_dbg_tex] = state.shadow_map, - .samplers[SMP_dbg_dbg_smp] = dbg_smp, + .images[IMG_dbg_tex] = state.shadow_map, + .samplers[SMP_dbg_smp] = dbg_smp, }; } @@ -286,7 +286,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.shadow.pass_action, .attachments = state.shadow.atts }); sg_apply_pipeline(state.shadow.pip); sg_apply_bindings(&state.shadow.bind); - sg_apply_uniforms(UB_shadow_vs_shadow_params, &SG_RANGE(cube_vs_shadow_params)); + sg_apply_uniforms(UB_vs_shadow_params, &SG_RANGE(cube_vs_shadow_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -294,12 +294,12 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bind); - sg_apply_uniforms(UB_display_fs_display_params, &SG_RANGE(fs_display_params)); + sg_apply_uniforms(UB_fs_display_params, &SG_RANGE(fs_display_params)); // render plane - sg_apply_uniforms(UB_display_vs_display_params , &SG_RANGE(plane_vs_display_params)); + sg_apply_uniforms(UB_vs_display_params , &SG_RANGE(plane_vs_display_params)); sg_draw(36, 6, 1); // render cube - sg_apply_uniforms(UB_display_vs_display_params, &SG_RANGE(cube_vs_display_params)); + sg_apply_uniforms(UB_vs_display_params, &SG_RANGE(cube_vs_display_params)); sg_draw(0, 36, 1); // render debug visualization of shadow-map sg_apply_pipeline(state.dbg.pip); diff --git a/sapp/shadows-depthtex-sapp.glsl b/sapp/shadows-depthtex-sapp.glsl index bf693c21..cfb01ff5 100644 --- a/sapp/shadows-depthtex-sapp.glsl +++ b/sapp/shadows-depthtex-sapp.glsl @@ -5,7 +5,7 @@ @vs vs_shadow @glsl_options fixup_clipspace // important: map clipspace z from -1..+1 to 0..+1 on GL -uniform vs_shadow_params { +layout(binding=0) uniform vs_shadow_params { mat4 mvp; }; @@ -25,7 +25,7 @@ void main() { } //=== display pass @vs vs_display -uniform vs_display_params { +layout(binding=0) uniform vs_display_params { mat4 mvp; mat4 model; mat4 light_mvp; @@ -53,13 +53,13 @@ void main() { @fs fs_display -uniform fs_display_params { +layout(binding=1) uniform fs_display_params { vec3 light_dir; vec3 eye_pos; }; -uniform texture2D shadow_map; -uniform sampler shadow_sampler; +layout(binding=0) uniform texture2D shadow_map; +layout(binding=0) uniform sampler shadow_sampler; in vec3 color; in vec4 light_proj_pos; @@ -117,8 +117,8 @@ void main() { @fs fs_dbg @image_sample_type dbg_tex unfilterable_float @sampler_type dbg_smp nonfiltering -uniform texture2D dbg_tex; -uniform sampler dbg_smp; +layout(binding=0) uniform texture2D dbg_tex; +layout(binding=0) uniform sampler dbg_smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/shadows-sapp.c b/sapp/shadows-sapp.c index 81d041e9..8e3c28c2 100644 --- a/sapp/shadows-sapp.c +++ b/sapp/shadows-sapp.c @@ -167,7 +167,7 @@ void init(void) { // need to provide vertex stride, because normal component is skipped in shadow pass .buffers[0].stride = 6 * sizeof(float), .attrs = { - [ATTR_vs_shadow_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_shadow_pos].format = SG_VERTEXFORMAT_FLOAT3, }, }, .shader = sg_make_shader(shadow_shader_desc(sg_query_backend())), @@ -194,8 +194,8 @@ void init(void) { state.display.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { .attrs = { - [ATTR_vs_display_pos].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_display_norm].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_display_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_display_norm].format = SG_VERTEXFORMAT_FLOAT3, } }, .shader = sg_make_shader(display_shader_desc(sg_query_backend())), @@ -212,10 +212,8 @@ void init(void) { state.display.bind = (sg_bindings) { .vertex_buffers[0] = state.vbuf, .index_buffer = state.ibuf, - .fs = { - .images[SLOT_shadow_map] = state.shadow_map, - .samplers[SLOT_shadow_sampler] = state.shadow_sampler, - }, + .images[IMG_shadow_map] = state.shadow_map, + .samplers[SMP_shadow_sampler] = state.shadow_sampler, }; // a vertex buffer, pipeline and sampler to render a debug visualization of the shadow map @@ -226,7 +224,7 @@ void init(void) { }); state.dbg.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { - .attrs[ATTR_vs_dbg_pos].format = SG_VERTEXFORMAT_FLOAT2, + .attrs[ATTR_dbg_pos].format = SG_VERTEXFORMAT_FLOAT2, }, .shader = sg_make_shader(dbg_shader_desc(sg_query_backend())), .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, @@ -241,10 +239,8 @@ void init(void) { }); state.dbg.bind = (sg_bindings){ .vertex_buffers[0] = dbg_vbuf, - .fs = { - .images[SLOT_dbg_tex] = state.shadow_map, - .samplers[SLOT_dbg_smp] = dbg_smp, - } + .images[IMG_dbg_tex] = state.shadow_map, + .samplers[SMP_dbg_smp] = dbg_smp, }; } @@ -297,7 +293,7 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.shadow.pass_action, .attachments = state.shadow.atts }); sg_apply_pipeline(state.shadow.pip); sg_apply_bindings(&state.shadow.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_shadow_params, &SG_RANGE(cube_vs_shadow_params)); + sg_apply_uniforms(UB_vs_shadow_params, &SG_RANGE(cube_vs_shadow_params)); sg_draw(0, 36, 1); sg_end_pass(); @@ -305,12 +301,12 @@ void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.display.pip); sg_apply_bindings(&state.display.bind); - sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_fs_display_params, &SG_RANGE(fs_display_params)); + sg_apply_uniforms(UB_fs_display_params, &SG_RANGE(fs_display_params)); // render plane - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_display_params, &SG_RANGE(plane_vs_display_params)); + sg_apply_uniforms(UB_vs_display_params, &SG_RANGE(plane_vs_display_params)); sg_draw(36, 6, 1); // render cube - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_display_params, &SG_RANGE(cube_vs_display_params)); + sg_apply_uniforms(UB_vs_display_params, &SG_RANGE(cube_vs_display_params)); sg_draw(0, 36, 1); // render debug visualization of shadow-map sg_apply_pipeline(state.dbg.pip); diff --git a/sapp/shadows-sapp.glsl b/sapp/shadows-sapp.glsl index 01eeafbe..8289df7d 100644 --- a/sapp/shadows-sapp.glsl +++ b/sapp/shadows-sapp.glsl @@ -43,7 +43,7 @@ float sample_shadow_pcf(texture2D tex, sampler smp, vec3 uv_depth, vec2 sm_size) //=== shadow pass @vs vs_shadow -uniform vs_shadow_params { +layout(binding=0) uniform vs_shadow_params { mat4 mvp; }; @@ -73,7 +73,7 @@ void main() { //=== display pass @vs vs_display -uniform vs_display_params { +layout(binding=0) uniform vs_display_params { mat4 mvp; mat4 model; mat4 light_mvp; @@ -102,13 +102,13 @@ void main() { @fs fs_display @include_block util -uniform fs_display_params { +layout(binding=1) uniform fs_display_params { vec3 light_dir; vec3 eye_pos; }; -uniform texture2D shadow_map; -uniform sampler shadow_sampler; +layout(binding=0) uniform texture2D shadow_map; +layout(binding=0) uniform sampler shadow_sampler; in vec3 color; in vec4 light_proj_pos; @@ -167,8 +167,8 @@ void main() { @fs fs_dbg @include_block util -uniform texture2D dbg_tex; -uniform sampler dbg_smp; +layout(binding=0) uniform texture2D dbg_tex; +layout(binding=0) uniform sampler dbg_smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/tex3d-sapp.c b/sapp/tex3d-sapp.c index 857c9d26..8c7c501d 100644 --- a/sapp/tex3d-sapp.c +++ b/sapp/tex3d-sapp.c @@ -72,7 +72,7 @@ static void init(void) { state.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3 + [ATTR_cube_position].format = SG_VERTEXFORMAT_FLOAT3 } }, .shader = sg_make_shader(cube_shader_desc(sg_query_backend())), @@ -94,7 +94,7 @@ static void init(void) { } } } - state.bind.fs.images[SLOT_tex] = sg_make_image(&(sg_image_desc){ + state.bind.images[IMG_tex] = sg_make_image(&(sg_image_desc){ .type = SG_IMAGETYPE_3D, .width = TEX3D_DIM, .height = TEX3D_DIM, @@ -106,7 +106,7 @@ static void init(void) { }); // ...and a sampler object - state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_LINEAR, .mag_filter = SG_FILTER_LINEAR, }); @@ -133,7 +133,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/tex3d-sapp.glsl b/sapp/tex3d-sapp.glsl index 40081c27..a2115444 100644 --- a/sapp/tex3d-sapp.glsl +++ b/sapp/tex3d-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; float scale; }; @@ -16,8 +16,8 @@ void main() { @end @fs fs -uniform texture3D tex; -uniform sampler smp; +layout(binding=0) uniform texture3D tex; +layout(binding=0) uniform sampler smp; in vec3 uvw; out vec4 frag_color; diff --git a/sapp/texcube-sapp.c b/sapp/texcube-sapp.c index 011c96f4..bb298092 100644 --- a/sapp/texcube-sapp.c +++ b/sapp/texcube-sapp.c @@ -101,7 +101,7 @@ void init(void) { 0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, }; // NOTE: SLOT_tex is provided by shader code generation - state.bind.images[IMG_texcube_tex] = sg_make_image(&(sg_image_desc){ + state.bind.images[IMG_tex] = sg_make_image(&(sg_image_desc){ .width = 4, .height = 4, .data.subimage[0][0] = SG_RANGE(pixels), @@ -109,7 +109,7 @@ void init(void) { }); // create a sampler object with default attributes - state.bind.samplers[SMP_texcube_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){ .label = "texcube-sampler" }); @@ -120,9 +120,9 @@ void init(void) { state.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { .attrs = { - [ATTR_vs_pos].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_color0].format = SG_VERTEXFORMAT_UBYTE4N, - [ATTR_vs_texcoord0].format = SG_VERTEXFORMAT_SHORT2N + [ATTR_texcube_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_texcube_color0].format = SG_VERTEXFORMAT_UBYTE4N, + [ATTR_texcube_texcoord0].format = SG_VERTEXFORMAT_SHORT2N } }, .shader = shd, @@ -157,7 +157,7 @@ void frame(void) { sg_begin_pass(&(sg_pass) { .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(UB_texcube_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/texcube-sapp.glsl b/sapp/texcube-sapp.glsl index 2aed854e..b771bcac 100644 --- a/sapp/texcube-sapp.glsl +++ b/sapp/texcube-sapp.glsl @@ -7,7 +7,7 @@ #pragma sokol @ctype mat4 hmm_mat4 #pragma sokol @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -26,8 +26,8 @@ void main() { #pragma sokol @end #pragma sokol @fs fs -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec4 color; in vec2 uv; diff --git a/sapp/uvwrap-sapp.c b/sapp/uvwrap-sapp.c index 04fab832..4fc3bcba 100644 --- a/sapp/uvwrap-sapp.c +++ b/sapp/uvwrap-sapp.c @@ -70,7 +70,7 @@ static void init(void) { state.pip = sg_make_pipeline(&(sg_pipeline_desc){ .shader = sg_make_shader(uvwrap_shader_desc(sg_query_backend())), .layout = { - .attrs[ATTR_vs_pos].format = SG_VERTEXFORMAT_FLOAT2 + .attrs[ATTR_uvwrap_pos].format = SG_VERTEXFORMAT_FLOAT2 }, .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, .depth = { @@ -91,10 +91,8 @@ static void frame(void) { for (int i = SG_WRAP_REPEAT; i <= SG_WRAP_MIRRORED_REPEAT; i++) { sg_apply_bindings(&(sg_bindings){ .vertex_buffers[0] = state.vbuf, - .fs = { - .images[SLOT_tex] = state.img, - .samplers[SLOT_smp] = state.smp[i], - } + .images[IMG_tex] = state.img, + .samplers[SMP_smp] = state.smp[i], }); float x_offset = 0, y_offset = 0; switch (i) { @@ -107,7 +105,7 @@ static void frame(void) { .offset = { x_offset, y_offset }, .scale = { 0.4f, 0.4f } }; - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 4, 1); } __dbgui_draw(); diff --git a/sapp/uvwrap-sapp.glsl b/sapp/uvwrap-sapp.glsl index f012e19d..12dd313b 100644 --- a/sapp/uvwrap-sapp.glsl +++ b/sapp/uvwrap-sapp.glsl @@ -3,7 +3,7 @@ // Shader code for uvwrap-sapp sample. //------------------------------------------------------------------------------ @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { vec2 offset; vec2 scale; }; @@ -18,8 +18,8 @@ void main() { @end @fs fs -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/vertexpull-sapp.glsl b/sapp/vertexpull-sapp.glsl index 30ae6745..1760195f 100644 --- a/sapp/vertexpull-sapp.glsl +++ b/sapp/vertexpull-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -11,7 +11,7 @@ struct sb_vertex { vec4 color; }; -readonly buffer ssbo { +layout(binding=0) readonly buffer ssbo { sb_vertex vtx[]; }; @@ -33,4 +33,4 @@ void main() { } @end -@program vertexpull vs fs \ No newline at end of file +@program vertexpull vs fs From 9cd7e20e4e549d3be4164227a683c1d1c6b8b38d Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Wed, 9 Oct 2024 19:28:57 +0200 Subject: [PATCH 25/36] fix more samples for bindings cleanup --- sapp/CMakeLists.txt | 178 ++++++++++++++++++++--------------------- sapp/vertexpull-sapp.c | 4 +- 2 files changed, 91 insertions(+), 91 deletions(-) diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index c8beebf3..4831e7db 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -98,20 +98,20 @@ fips_begin_app(noninterleaved-sapp-ui windowed) target_compile_definitions(noninterleaved-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(vertexpull-sapp windowed) -# fips_files(vertexpull-sapp.c) -# sokol_shader(vertexpull-sapp.glsl ${slang}) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(vertexpull-sapp-ui windowed) -# fips_files(vertexpull-sapp.c) -# sokol_shader(vertexpull-sapp.glsl ${slang}) -# fips_deps(sokol dbgui) -# target_compile_definitions(vertexpull-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(vertexpull-sapp windowed) + fips_files(vertexpull-sapp.c) + sokol_shader(vertexpull-sapp.glsl ${slang}) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(vertexpull-sapp-ui windowed) + fips_files(vertexpull-sapp.c) + sokol_shader(vertexpull-sapp.glsl ${slang}) + fips_deps(sokol dbgui) + target_compile_definitions(vertexpull-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(texcube-sapp windowed) fips_files(texcube-sapp.c) @@ -389,44 +389,44 @@ fips_end_app() # target_compile_definitions(uniformtypes-sapp-ui PRIVATE USE_DBG_UI) #fips_end_app() # -#fips_ide_group(Samples) -#fips_begin_app(imgui-sapp windowed) -# fips_files(imgui-sapp.cc) -# # use sokol-cpp for testing here, this isn't required though -# fips_deps(sokol-cpp imgui) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(imgui-dock-sapp windowed) -# fips_files(imgui-dock-sapp.cc) -# # use sokol-cpp for testing here, this isn't required though -# fips_deps(sokol-cpp imgui-dock) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(imgui-highdpi-sapp windowed) -# fips_files(imgui-highdpi-sapp.cc) -# fips_deps(sokol imgui) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(cimgui-sapp windowed) -# fips_files(cimgui-sapp.c) -# fips_deps(sokol cimgui) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(imgui-sapp windowed) + fips_files(imgui-sapp.cc) + # use sokol-cpp for testing here, this isn't required though + fips_deps(sokol-cpp imgui) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(imgui-dock-sapp windowed) + fips_files(imgui-dock-sapp.cc) + # use sokol-cpp for testing here, this isn't required though + fips_deps(sokol-cpp imgui-dock) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(imgui-highdpi-sapp windowed) + fips_files(imgui-highdpi-sapp.cc) + fips_deps(sokol imgui) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(cimgui-sapp windowed) + fips_files(cimgui-sapp.c) + fips_deps(sokol cimgui) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + #fips_ide_group(Samples) #fips_begin_app(imgui-usercallback-sapp windowed) # fips_files(imgui-usercallback-sapp.c) @@ -664,42 +664,42 @@ fips_end_app() # fips_deps(sokol cimgui) #fips_end_app() # -#fips_ide_group(Samples) -#fips_begin_app(debugtext-sapp windowed) -# fips_files(debugtext-sapp.c) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(debugtext-sapp-ui windowed) -# fips_files(debugtext-sapp.c) -# fips_deps(sokol dbgui) -# target_compile_definitions(debugtext-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(debugtext-printf-sapp windowed) -# fips_files(debugtext-printf-sapp.c) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(debugtext-printf-sapp-ui windowed) -# fips_files(debugtext-printf-sapp.c) -# fips_deps(sokol dbgui) -# target_compile_definitions(debugtext-printf-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(debugtext-userfont-sapp windowed) -# fips_files(debugtext-userfont-sapp.c) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(debugtext-userfont-sapp-ui windowed) -# fips_files(debugtext-userfont-sapp.c) -# fips_deps(sokol dbgui) -# target_compile_definitions(debugtext-userfont-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(debugtext-sapp windowed) + fips_files(debugtext-sapp.c) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(debugtext-sapp-ui windowed) + fips_files(debugtext-sapp.c) + fips_deps(sokol dbgui) + target_compile_definitions(debugtext-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(debugtext-printf-sapp windowed) + fips_files(debugtext-printf-sapp.c) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(debugtext-printf-sapp-ui windowed) + fips_files(debugtext-printf-sapp.c) + fips_deps(sokol dbgui) + target_compile_definitions(debugtext-printf-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(debugtext-userfont-sapp windowed) + fips_files(debugtext-userfont-sapp.c) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(debugtext-userfont-sapp-ui windowed) + fips_files(debugtext-userfont-sapp.c) + fips_deps(sokol dbgui) + target_compile_definitions(debugtext-userfont-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + #fips_ide_group(Samples) #fips_begin_app(debugtext-context-sapp windowed) # fips_files(debugtext-context-sapp.c) @@ -713,7 +713,7 @@ fips_end_app() # fips_deps(sokol dbgui) # target_compile_definitions(debugtext-context-sapp-ui PRIVATE USE_DBG_UI) #fips_end_app() -# + #fips_ide_group(Samples) #fips_begin_app(debugtext-layers-sapp windowed) # fips_files(debugtext-layers-sapp.c) diff --git a/sapp/vertexpull-sapp.c b/sapp/vertexpull-sapp.c index 0672ae69..898b58d6 100644 --- a/sapp/vertexpull-sapp.c +++ b/sapp/vertexpull-sapp.c @@ -101,7 +101,7 @@ static void init(void) { // resource bindings, note that there is no vertex buffer binding state.bind = (sg_bindings){ .index_buffer = ibuf, - .vs.storage_buffers[SLOT_ssbo] = sbuf, + .storage_buffers[SBUF_ssbo] = sbuf, }; // define a clear color @@ -131,7 +131,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); From 0a0a659eabbe28765aa8ee58bce7445979e821d4 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Wed, 9 Oct 2024 19:38:16 +0200 Subject: [PATCH 26/36] 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++; From 26a986df17cad29474f9642988ffffd941c2325b Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Thu, 10 Oct 2024 20:18:34 +0200 Subject: [PATCH 27/36] more samples fixed/tested for bindings cleanup --- sapp/CMakeLists.txt | 154 ++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index 4831e7db..0770c670 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -474,67 +474,67 @@ fips_end_app() # endif() #fips_end_app() # -#fips_ide_group(Samples) -#fips_begin_app(sgl-sapp windowed) -# fips_files(sgl-sapp.c) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(sgl-sapp-ui windowed) -# fips_files(sgl-sapp.c) -# fips_deps(sokol dbgui) -# target_compile_definitions(sgl-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(sgl-lines-sapp windowed) -# fips_files(sgl-lines-sapp.c) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(sgl-lines-sapp-ui windowed) -# fips_files(sgl-lines-sapp.c) -# fips_deps(sokol dbgui) -# target_compile_definitions(sgl-lines-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(sgl-points-sapp windowed) -# fips_files(sgl-points-sapp.c) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(sgl-points-sapp-ui windowed) -# fips_files(sgl-points-sapp.c) -# fips_deps(sokol dbgui) -# target_compile_definitions(sgl-points-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(sgl-context-sapp windowed) -# fips_files(sgl-context-sapp.c) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(sgl-context-sapp-ui windowed) -# fips_files(sgl-context-sapp.c) -# fips_deps(sokol dbgui) -# target_compile_definitions(sgl-context-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(sgl-microui-sapp windowed) -# fips_files(sgl-microui-sapp.c) -# fips_deps(sokol microui) -#fips_end_app() -## NOTE: this uses cimgui -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(sgl-microui-sapp-ui windowed) -# fips_files(sgl-microui-sapp.c) -# fips_deps(sokol cdbgui cimgui microui) -# target_compile_definitions(sgl-microui-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(sgl-sapp windowed) + fips_files(sgl-sapp.c) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(sgl-sapp-ui windowed) + fips_files(sgl-sapp.c) + fips_deps(sokol dbgui) + target_compile_definitions(sgl-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(sgl-lines-sapp windowed) + fips_files(sgl-lines-sapp.c) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(sgl-lines-sapp-ui windowed) + fips_files(sgl-lines-sapp.c) + fips_deps(sokol dbgui) + target_compile_definitions(sgl-lines-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(sgl-points-sapp windowed) + fips_files(sgl-points-sapp.c) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(sgl-points-sapp-ui windowed) + fips_files(sgl-points-sapp.c) + fips_deps(sokol dbgui) + target_compile_definitions(sgl-points-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(sgl-context-sapp windowed) + fips_files(sgl-context-sapp.c) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(sgl-context-sapp-ui windowed) + fips_files(sgl-context-sapp.c) + fips_deps(sokol dbgui) + target_compile_definitions(sgl-context-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(sgl-microui-sapp windowed) + fips_files(sgl-microui-sapp.c) + fips_deps(sokol microui) +fips_end_app() +# NOTE: this uses cimgui +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(sgl-microui-sapp-ui windowed) + fips_files(sgl-microui-sapp.c) + fips_deps(sokol cdbgui cimgui microui) + target_compile_definitions(sgl-microui-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + #fips_ide_group(Samples) #fips_begin_app(nuklear-sapp windowed) # fips_files(nuklear-sapp.c) @@ -750,22 +750,22 @@ fips_end_app() # endif() #fips_end_app() # -#fips_ide_group(Samples) -#fips_begin_app(fontstash-sapp windowed) -# fips_files(fontstash-sapp.c) -# fips_deps(sokol fileutil) -# fips_dir(data) -# fipsutil_copy(fontstash.yml) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(fontstash-sapp-ui windowed) -# fips_files(fontstash-sapp.c) -# fips_deps(sokol fileutil dbgui) -# fips_dir(data) -# fipsutil_copy(fontstash.yml) -# target_compile_definitions(fontstash-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(fontstash-sapp windowed) + fips_files(fontstash-sapp.c) + fips_deps(sokol fileutil) + fips_dir(data) + fipsutil_copy(fontstash.yml) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(fontstash-sapp-ui windowed) + fips_files(fontstash-sapp.c) + fips_deps(sokol fileutil dbgui) + fips_dir(data) + fipsutil_copy(fontstash.yml) + target_compile_definitions(fontstash-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + #fips_ide_group(Samples) #fips_begin_app(fontstash-layers-sapp windowed) # fips_files(fontstash-layers-sapp.c) From bb71bdcb0751b55e277385c3d275b073d6762d4a Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 12 Oct 2024 19:44:42 +0200 Subject: [PATCH 28/36] fix more samples for bindings cleanup --- sapp/CMakeLists.txt | 96 ++++++++++++++++++++++---------------------- sapp/cgltf-sapp.c | 34 ++++++++-------- sapp/cgltf-sapp.glsl | 27 ++++++------- sapp/sbuftex-sapp.c | 10 ++--- 4 files changed, 83 insertions(+), 84 deletions(-) diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index 0770c670..03f1cc61 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -126,20 +126,20 @@ fips_begin_app(texcube-sapp-ui windowed) target_compile_definitions(texcube-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(sbuftex-sapp windowed) -# fips_files(sbuftex-sapp.c) -# sokol_shader(sbuftex-sapp.glsl ${slang}) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(sbuftex-sapp-ui windowed) -# fips_files(sbuftex-sapp.c) -# sokol_shader(sbuftex-sapp.glsl ${slang}) -# fips_deps(sokol dbgui) -# target_compile_definitions(sbuftex-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(sbuftex-sapp windowed) + fips_files(sbuftex-sapp.c) + sokol_shader(sbuftex-sapp.glsl ${slang}) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(sbuftex-sapp-ui windowed) + fips_files(sbuftex-sapp.c) + sokol_shader(sbuftex-sapp.glsl ${slang}) + fips_deps(sokol dbgui) + target_compile_definitions(sbuftex-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(offscreen-sapp windowed) fips_files(offscreen-sapp.c) @@ -331,22 +331,22 @@ fips_end_app() # target_compile_definitions(cubemap-jpeg-sapp-ui PRIVATE USE_DBG_UI) #fips_end_app() # -#fips_ide_group(Samples) -#fips_begin_app(basisu-sapp windowed) -# fips_files(basisu-sapp.c) -# fips_deps(sokol basisu) -# fips_dir(data) -# fipsutil_embed(basisu-assets.yml basisu-assets.h) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(basisu-sapp-ui windowed) -# fips_files(basisu-sapp.c) -# fips_deps(sokol basisu dbgui) -# fips_dir(data) -# fipsutil_embed(basisu-assets.yml basisu-assets.h) -# target_compile_definitions(basisu-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(basisu-sapp windowed) + fips_files(basisu-sapp.c) + fips_deps(sokol basisu) + fips_dir(data) + fipsutil_embed(basisu-assets.yml basisu-assets.h) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(basisu-sapp-ui windowed) + fips_files(basisu-sapp.c) + fips_deps(sokol basisu dbgui) + fips_dir(data) + fipsutil_embed(basisu-assets.yml basisu-assets.h) + target_compile_definitions(basisu-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(blend-sapp windowed) fips_files(blend-sapp.c) @@ -822,24 +822,24 @@ fips_begin_app(plmpeg-sapp-ui windowed) target_compile_definitions(plmpeg-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(cgltf-sapp windowed) -# fips_files(cgltf-sapp.c) -# sokol_shader(cgltf-sapp.glsl ${slang}) -# fips_dir(data) -# fipsutil_copy(cgltf-assets.yml) -# fips_deps(sokol basisu fileutil) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(cgltf-sapp-ui windowed) -# fips_files(cgltf-sapp.c) -# sokol_shader(cgltf-sapp.glsl ${slang}) -# fips_dir(data) -# fipsutil_copy(cgltf-assets.yml) -# fips_deps(sokol dbgui basisu fileutil) -# target_compile_definitions(cgltf-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(cgltf-sapp windowed) + fips_files(cgltf-sapp.c) + sokol_shader(cgltf-sapp.glsl ${slang}) + fips_dir(data) + fipsutil_copy(cgltf-assets.yml) + fips_deps(sokol basisu fileutil) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(cgltf-sapp-ui windowed) + fips_files(cgltf-sapp.c) + sokol_shader(cgltf-sapp.glsl ${slang}) + fips_dir(data) + fipsutil_copy(cgltf-assets.yml) + fips_deps(sokol dbgui basisu fileutil) + target_compile_definitions(cgltf-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(loadpng-sapp windowed) fips_files(loadpng-sapp.c) diff --git a/sapp/cgltf-sapp.c b/sapp/cgltf-sapp.c index 9db03fd2..c017c645 100644 --- a/sapp/cgltf-sapp.c +++ b/sapp/cgltf-sapp.c @@ -94,7 +94,7 @@ typedef struct { // helper struct to map sokol-gfx buffer bindslots to scene.buffers indices typedef struct { int num; - int buffer[SG_MAX_VERTEX_BUFFERS]; + int buffer[SG_MAX_VERTEXBUFFER_BINDSLOTS]; } vertex_buffer_mapping_t; // a 'primitive' (aka submesh) contains everything needed to issue a draw call @@ -360,8 +360,8 @@ static void frame(void) { if (prim->index_buffer != SCENE_INVALID_INDEX) { bind.index_buffer = state.scene.buffers[prim->index_buffer]; } - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); - sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_light_params, &SG_RANGE(state.point_light)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_light_params, &SG_RANGE(state.point_light)); if (mat->is_metallic) { sg_image base_color_tex = state.scene.image_samplers[mat->metallic.images.base_color].img; sg_image metallic_roughness_tex = state.scene.image_samplers[mat->metallic.images.metallic_roughness].img; @@ -394,17 +394,17 @@ static void frame(void) { emissive_tex = state.placeholders.black; emissive_smp = state.placeholders.smp; } - bind.fs.images[SLOT_base_color_tex] = base_color_tex; - bind.fs.images[SLOT_metallic_roughness_tex] = metallic_roughness_tex; - bind.fs.images[SLOT_normal_tex] = normal_tex; - bind.fs.images[SLOT_occlusion_tex] = occlusion_tex; - bind.fs.images[SLOT_emissive_tex] = emissive_tex; - bind.fs.samplers[SLOT_base_color_smp] = base_color_smp; - bind.fs.samplers[SLOT_metallic_roughness_smp] = metallic_roughness_smp; - bind.fs.samplers[SLOT_normal_smp] = normal_smp; - bind.fs.samplers[SLOT_occlusion_smp] = occlusion_smp; - bind.fs.samplers[SLOT_emissive_tex] = emissive_smp; - sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_metallic_params, &SG_RANGE(mat->metallic.fs_params)); + bind.images[IMG_base_color_tex] = base_color_tex; + bind.images[IMG_metallic_roughness_tex] = metallic_roughness_tex; + bind.images[IMG_normal_tex] = normal_tex; + bind.images[IMG_occlusion_tex] = occlusion_tex; + bind.images[IMG_emissive_tex] = emissive_tex; + bind.samplers[SMP_base_color_smp] = base_color_smp; + bind.samplers[SMP_metallic_roughness_smp] = metallic_roughness_smp; + bind.samplers[SMP_normal_smp] = normal_smp; + bind.samplers[SMP_occlusion_smp] = occlusion_smp; + bind.samplers[SMP_emissive_smp] = emissive_smp; + sg_apply_uniforms(UB_metallic_params, &SG_RANGE(mat->metallic.fs_params)); } else { /* sg_apply_uniforms(SG_SHADERSTAGE_VS, @@ -877,7 +877,7 @@ static sg_index_type gltf_to_index_type(const cgltf_primitive* prim) { // creates a vertex buffer bind slot mapping for a specific GLTF primitive static vertex_buffer_mapping_t create_vertex_buffer_mapping_for_gltf_primitive(const cgltf_data* gltf, const cgltf_primitive* prim) { vertex_buffer_mapping_t map = { 0 }; - for (int i = 0; i < SG_MAX_VERTEX_BUFFERS; i++) { + for (int i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) { map.buffer[i] = SCENE_INVALID_INDEX; } for (cgltf_size attr_index = 0; attr_index < prim->attributes_count; attr_index++) { @@ -890,10 +890,10 @@ static vertex_buffer_mapping_t create_vertex_buffer_mapping_for_gltf_primitive(c break; } } - if ((i == map.num) && (map.num < SG_MAX_VERTEX_BUFFERS)) { + if ((i == map.num) && (map.num < SG_MAX_VERTEXBUFFER_BINDSLOTS)) { map.buffer[map.num++] = buffer_view_index; } - assert(map.num <= SG_MAX_VERTEX_BUFFERS); + assert(map.num <= SG_MAX_VERTEXBUFFER_BINDSLOTS); } return map; } diff --git a/sapp/cgltf-sapp.glsl b/sapp/cgltf-sapp.glsl index 5d0ef041..e4aaebf5 100644 --- a/sapp/cgltf-sapp.glsl +++ b/sapp/cgltf-sapp.glsl @@ -8,7 +8,7 @@ @ctype vec3 hmm_vec3 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 model; mat4 view_proj; vec3 eye_pos; @@ -51,31 +51,31 @@ struct material_info_t { vec3 specular_color; // color contribution from specular lighting }; -uniform metallic_params { +layout(binding=1) uniform metallic_params { vec4 base_color_factor; vec3 emissive_factor; float metallic_factor; float roughness_factor; }; -uniform light_params { +layout(binding=2) uniform light_params { vec3 light_pos; float light_range; vec3 light_color; float light_intensity; }; -uniform texture2D base_color_tex; -uniform texture2D metallic_roughness_tex; -uniform texture2D normal_tex; -uniform texture2D occlusion_tex; -uniform texture2D emissive_tex; +layout(binding=0) uniform texture2D base_color_tex; +layout(binding=1) uniform texture2D metallic_roughness_tex; +layout(binding=2) uniform texture2D normal_tex; +layout(binding=3) uniform texture2D occlusion_tex; +layout(binding=4) uniform texture2D emissive_tex; -uniform sampler base_color_smp; -uniform sampler metallic_roughness_smp; -uniform sampler normal_smp; -uniform sampler occlusion_smp; -uniform sampler emissive_smp; +layout(binding=0) uniform sampler base_color_smp; +layout(binding=1) uniform sampler metallic_roughness_smp; +layout(binding=2) uniform sampler normal_smp; +layout(binding=3) uniform sampler occlusion_smp; +layout(binding=4) uniform sampler emissive_smp; vec3 linear_to_srgb(vec3 linear) { return pow(linear, vec3(1.0/2.2)); @@ -275,4 +275,3 @@ void main() { @end @program cgltf_metallic vs metallic_fs - diff --git a/sapp/sbuftex-sapp.c b/sapp/sbuftex-sapp.c index c06cbd0f..c2c0163b 100644 --- a/sapp/sbuftex-sapp.c +++ b/sapp/sbuftex-sapp.c @@ -83,7 +83,7 @@ static void init(void) { { .pos = { 1.0f, 1.0f, 1.0f }, .idx = 5, .uv = { 1.0f, 1.0f } }, { .pos = { 1.0f, 1.0f, -1.0f }, .idx = 5, .uv = { 0.0f, 1.0f } }, }; - state.bind.vs.storage_buffers[SLOT_vertices] = sg_make_buffer(&(sg_buffer_desc){ + state.bind.storage_buffers[SBUF_vertices] = sg_make_buffer(&(sg_buffer_desc){ .type = SG_BUFFERTYPE_STORAGEBUFFER, .data = SG_RANGE(vertices), .label = "cube-vertices", @@ -113,7 +113,7 @@ static void init(void) { { .color = { 0.0f, 0.5f, 1.0f, 1.0f } }, { .color = { 1.0f, 0.5f, 0.0f, 1.0f } }, }; - state.bind.fs.storage_buffers[SLOT_colors] = sg_make_buffer(&(sg_buffer_desc){ + state.bind.storage_buffers[SBUF_colors] = sg_make_buffer(&(sg_buffer_desc){ .type = SG_BUFFERTYPE_STORAGEBUFFER, .data = SG_RANGE(colors), .label = "color-palette", @@ -126,7 +126,7 @@ static void init(void) { { 0x88, 0x44, 0xFF, 0xCC }, { 0x44, 0xFF, 0xCC, 0x88 }, }; - state.bind.fs.images[SLOT_tex] = sg_make_image(&(sg_image_desc){ + state.bind.images[IMG_tex] = sg_make_image(&(sg_image_desc){ .width = 4, .height = 4, .pixel_format = SG_PIXELFORMAT_R8, @@ -135,7 +135,7 @@ static void init(void) { }); // ...and a matching sampler - state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_NEAREST, .mag_filter = SG_FILTER_NEAREST, .label = "sampler", @@ -165,7 +165,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); __dbgui_draw(); sg_end_pass(); From 722ae74eb5daa97a7fe534326e2fd8fe23b267d9 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 14 Oct 2024 15:10:26 +0200 Subject: [PATCH 29/36] fix uniformarrays-glfw for bindings cleanup --- glfw/uniformarrays-glfw.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/glfw/uniformarrays-glfw.c b/glfw/uniformarrays-glfw.c index 86d6ca8d..460cbd9a 100644 --- a/glfw/uniformarrays-glfw.c +++ b/glfw/uniformarrays-glfw.c @@ -101,7 +101,7 @@ int main() { for (vs_params.sel = 0; vs_params.sel < NUM_ARRAYS; vs_params.sel++) { vs_params.offset[0] = -1.0f + (10.0f * glyph_w); for (vs_params.idx = 0; vs_params.idx < ARRAY_COUNT; vs_params.idx++) { - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(0, &SG_RANGE(vs_params)); sg_draw(0, 6, 1); vs_params.offset[0] += glyph_h * 4.0f; } @@ -123,21 +123,8 @@ int main() { // helper function to create shader object static sg_shader create_shader(void) { return sg_make_shader(&(sg_shader_desc){ - .vs.uniform_blocks[0] = { - .size = sizeof(vs_params_t), - .layout = SG_UNIFORMLAYOUT_NATIVE, // this is the default, so not really needed - .uniforms = { - { .name = "sel", .type = SG_UNIFORMTYPE_INT }, - { .name = "idx", .type = SG_UNIFORMTYPE_INT }, - { .name = "offset", .type = SG_UNIFORMTYPE_FLOAT2 }, - { .name = "scale", .type = SG_UNIFORMTYPE_FLOAT2 }, - { .name = "f1", .type = SG_UNIFORMTYPE_FLOAT, .array_count = ARRAY_COUNT }, - { .name = "f2", .type = SG_UNIFORMTYPE_FLOAT2, .array_count = ARRAY_COUNT }, - { .name = "f3", .type = SG_UNIFORMTYPE_FLOAT3, .array_count = ARRAY_COUNT }, - } - }, - .vs.source = - "#version 330\n" + .vertex_func.source = + "#version 410\n" "#define ARRAY_COUNT (8)\n" "uniform int sel;\n" "uniform int idx;\n" @@ -160,12 +147,26 @@ static sg_shader create_shader(void) { " color = vec4(f3[idx], 1.0);\n" " }\n" "}\n", - .fs.source = - "#version 330\n" + .fragment_func.source = + "#version 410\n" "in vec4 color;\n" "out vec4 frag_color;\n" "void main() {\n" " frag_color = color;\n" "}\n", + .uniform_blocks[0] = { + .stage = SG_SHADERSTAGE_VERTEX, + .size = sizeof(vs_params_t), + .layout = SG_UNIFORMLAYOUT_NATIVE, // this is the default, so not really needed + .glsl_uniforms = { + { .glsl_name = "sel", .type = SG_UNIFORMTYPE_INT }, + { .glsl_name = "idx", .type = SG_UNIFORMTYPE_INT }, + { .glsl_name = "offset", .type = SG_UNIFORMTYPE_FLOAT2 }, + { .glsl_name = "scale", .type = SG_UNIFORMTYPE_FLOAT2 }, + { .glsl_name = "f1", .type = SG_UNIFORMTYPE_FLOAT, .array_count = ARRAY_COUNT }, + { .glsl_name = "f2", .type = SG_UNIFORMTYPE_FLOAT2, .array_count = ARRAY_COUNT }, + { .glsl_name = "f3", .type = SG_UNIFORMTYPE_FLOAT3, .array_count = ARRAY_COUNT }, + } + } }); } From c17b13b86b9800463337dff80a16c6539bac5b6b Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 14 Oct 2024 17:49:59 +0200 Subject: [PATCH 30/36] fix more sapp samples for bindings cleanup --- sapp/CMakeLists.txt | 598 +++++++++++++++--------------- sapp/cubemap-jpeg-sapp.c | 10 +- sapp/cubemap-jpeg-sapp.glsl | 6 +- sapp/debugtext-context-sapp.c | 9 +- sapp/debugtext-context-sapp.glsl | 6 +- sapp/drawcallperf-sapp.glsl | 8 +- sapp/dyntex3d-sapp.glsl | 6 +- sapp/fontstash-layers-sapp.c | 4 +- sapp/imgui-usercallback-sapp.c | 6 +- sapp/imgui-usercallback-sapp.glsl | 2 +- sapp/instancing-pull-sapp.c | 8 +- sapp/instancing-pull-sapp.glsl | 4 +- sapp/pixelformats-sapp.c | 18 +- sapp/pixelformats-sapp.glsl | 4 +- sapp/primtypes-sapp.c | 6 +- sapp/primtypes-sapp.glsl | 2 +- sapp/restart-sapp.c | 12 +- sapp/restart-sapp.glsl | 6 +- sapp/shapes-sapp.c | 2 +- sapp/shapes-sapp.glsl | 2 +- sapp/shapes-transform-sapp.c | 2 +- sapp/shapes-transform-sapp.glsl | 2 +- sapp/uniformtypes-sapp.c | 2 +- sapp/uniformtypes-sapp.glsl | 3 +- 24 files changed, 364 insertions(+), 364 deletions(-) diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index 03f1cc61..6608e3ba 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -210,20 +210,20 @@ fips_begin_app(instancing-sapp-ui windowed) target_compile_definitions(instancing-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(instancing-pull-sapp windowed) -# fips_files(instancing-pull-sapp.c) -# sokol_shader(instancing-pull-sapp.glsl ${slang}) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(instancing-pull-sapp-ui windowed) -# fips_files(instancing-pull-sapp.c) -# sokol_shader(instancing-pull-sapp.glsl ${slang}) -# fips_deps(sokol dbgui) -# target_compile_definitions(instancing-pull-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(instancing-pull-sapp windowed) + fips_files(instancing-pull-sapp.c) + sokol_shader(instancing-pull-sapp.glsl ${slang}) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(instancing-pull-sapp-ui windowed) + fips_files(instancing-pull-sapp.c) + sokol_shader(instancing-pull-sapp.glsl ${slang}) + fips_deps(sokol dbgui) + target_compile_definitions(instancing-pull-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(mrt-sapp windowed) fips_files(mrt-sapp.c) @@ -280,12 +280,12 @@ fips_begin_app(tex3d-sapp-ui windowed) target_compile_definitions(tex3d-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(dyntex3d-sapp windowed) -# fips_files(dyntex3d-sapp.c) -# sokol_shader(dyntex3d-sapp.glsl ${slang}) -# fips_deps(sokol cimgui) -#fips_end_app() +# fips_ide_group(Samples) +# fips_begin_app(dyntex3d-sapp windowed) +# fips_files(dyntex3d-sapp.c) +# sokol_shader(dyntex3d-sapp.glsl ${slang}) +# fips_deps(sokol cimgui) +# fips_end_app() # fips_ide_group(Samples) fips_begin_app(dyntex-sapp windowed) @@ -315,22 +315,22 @@ fips_begin_app(mipmap-sapp-ui windowed) target_compile_definitions(mipmap-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(cubemap-jpeg-sapp windowed) -# fips_files(cubemap-jpeg-sapp.c) -# sokol_shader(cubemap-jpeg-sapp.glsl ${slang}) -# fips_dir(data) -# fipsutil_copy(cubemap-jpeg-assets.yml) -# fips_deps(sokol fileutil stb) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(cubemap-jpeg-sapp-ui windowed) -# fips_files(cubemap-jpeg-sapp.c) -# sokol_shader(cubemap-jpeg-sapp.glsl ${slang}) -# fips_deps(sokol fileutil stb dbgui) -# target_compile_definitions(cubemap-jpeg-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(cubemap-jpeg-sapp windowed) + fips_files(cubemap-jpeg-sapp.c) + sokol_shader(cubemap-jpeg-sapp.glsl ${slang}) + fips_dir(data) + fipsutil_copy(cubemap-jpeg-assets.yml) + fips_deps(sokol fileutil stb) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(cubemap-jpeg-sapp-ui windowed) + fips_files(cubemap-jpeg-sapp.c) + sokol_shader(cubemap-jpeg-sapp.glsl ${slang}) + fips_deps(sokol fileutil stb dbgui) + target_compile_definitions(cubemap-jpeg-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(basisu-sapp windowed) fips_files(basisu-sapp.c) @@ -375,20 +375,20 @@ fips_begin_app(uvwrap-sapp-ui windowed) target_compile_definitions(uvwrap-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(uniformtypes-sapp windowed) -# fips_files(uniformtypes-sapp.c) -# sokol_shader(uniformtypes-sapp.glsl ${slang}) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(uniformtypes-sapp-ui windowed) -# fips_files(uniformtypes-sapp.c) -# sokol_shader(uniformtypes-sapp.glsl ${slang}) -# fips_deps(sokol dbgui) -# target_compile_definitions(uniformtypes-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(uniformtypes-sapp windowed) + fips_files(uniformtypes-sapp.c) + sokol_shader(uniformtypes-sapp.glsl ${slang}) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(uniformtypes-sapp-ui windowed) + fips_files(uniformtypes-sapp.c) + sokol_shader(uniformtypes-sapp.glsl ${slang}) + fips_deps(sokol dbgui) + target_compile_definitions(uniformtypes-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(imgui-sapp windowed) fips_files(imgui-sapp.cc) @@ -427,53 +427,53 @@ fips_begin_app(cimgui-sapp windowed) endif() fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(imgui-usercallback-sapp windowed) -# fips_files(imgui-usercallback-sapp.c) -# sokol_shader(imgui-usercallback-sapp.glsl ${slang}) -# fips_deps(sokol cimgui) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(imgui-images-sapp windowed) -# fips_files(imgui-images-sapp.c) -# fips_deps(sokol cimgui) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(imgui-perf-sapp windowed) -# fips_files(imgui-perf-sapp.c) -# fips_deps(sokol cimgui) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(events-sapp windowed) -# fips_files(events-sapp.cc) -# fips_deps(sokol imgui) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(pixelformats-sapp windowed) -# fips_files(pixelformats-sapp.c) -# sokol_shader(pixelformats-sapp.glsl ${slang}) -# fips_deps(sokol cimgui) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(imgui-usercallback-sapp windowed) + fips_files(imgui-usercallback-sapp.c) + sokol_shader(imgui-usercallback-sapp.glsl ${slang}) + fips_deps(sokol cimgui) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(imgui-images-sapp windowed) + fips_files(imgui-images-sapp.c) + fips_deps(sokol cimgui) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(imgui-perf-sapp windowed) + fips_files(imgui-perf-sapp.c) + fips_deps(sokol cimgui) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(events-sapp windowed) + fips_files(events-sapp.cc) + fips_deps(sokol imgui) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(pixelformats-sapp windowed) + fips_files(pixelformats-sapp.c) + sokol_shader(pixelformats-sapp.glsl ${slang}) + fips_deps(sokol cimgui) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + fips_ide_group(Samples) fips_begin_app(sgl-sapp windowed) fips_files(sgl-sapp.c) @@ -615,54 +615,54 @@ fips_begin_app(sdf-sapp-ui windowed) target_compile_definitions(sdf-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(shapes-sapp windowed) -# fips_files(shapes-sapp.c) -# sokol_shader(shapes-sapp.glsl ${slang}) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(shapes-sapp-ui windowed) -# fips_files(shapes-sapp.c) -# sokol_shader(shapes-sapp.glsl ${slang}) -# fips_deps(sokol dbgui) -# target_compile_definitions(shapes-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(shapes-transform-sapp windowed) -# fips_files(shapes-transform-sapp.c) -# sokol_shader(shapes-transform-sapp.glsl ${slang}) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(shapes-transform-sapp-ui windowed) -# fips_files(shapes-transform-sapp.c) -# sokol_shader(shapes-transform-sapp.glsl ${slang}) -# fips_deps(sokol dbgui) -# target_compile_definitions(shapes-transform-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(primtypes-sapp windowed) -# fips_files(primtypes-sapp.c) -# sokol_shader(primtypes-sapp.glsl ${slang}) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(primtypes-sapp-ui windowed) -# fips_files(primtypes-sapp.c) -# sokol_shader(primtypes-sapp.glsl ${slang}) -# fips_deps(sokol dbgui) -# target_compile_definitions(primtypes-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(drawcallperf-sapp windowed) -# fips_files(drawcallperf-sapp.c) -# sokol_shader(drawcallperf-sapp.glsl ${slang}) -# fips_deps(sokol cimgui) -#fips_end_app() +fips_ide_group(Samples) +fips_begin_app(shapes-sapp windowed) + fips_files(shapes-sapp.c) + sokol_shader(shapes-sapp.glsl ${slang}) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(shapes-sapp-ui windowed) + fips_files(shapes-sapp.c) + sokol_shader(shapes-sapp.glsl ${slang}) + fips_deps(sokol dbgui) + target_compile_definitions(shapes-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(shapes-transform-sapp windowed) + fips_files(shapes-transform-sapp.c) + sokol_shader(shapes-transform-sapp.glsl ${slang}) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(shapes-transform-sapp-ui windowed) + fips_files(shapes-transform-sapp.c) + sokol_shader(shapes-transform-sapp.glsl ${slang}) + fips_deps(sokol dbgui) + target_compile_definitions(shapes-transform-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(primtypes-sapp windowed) + fips_files(primtypes-sapp.c) + sokol_shader(primtypes-sapp.glsl ${slang}) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(primtypes-sapp-ui windowed) + fips_files(primtypes-sapp.c) + sokol_shader(primtypes-sapp.glsl ${slang}) + fips_deps(sokol dbgui) + target_compile_definitions(primtypes-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +# fips_ide_group(Samples) +# fips_begin_app(drawcallperf-sapp windowed) +# fips_files(drawcallperf-sapp.c) +# sokol_shader(drawcallperf-sapp.glsl ${slang}) +# fips_deps(sokol cimgui) +# fips_end_app() # fips_ide_group(Samples) fips_begin_app(debugtext-sapp windowed) @@ -700,32 +700,32 @@ fips_begin_app(debugtext-userfont-sapp-ui windowed) target_compile_definitions(debugtext-userfont-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(debugtext-context-sapp windowed) -# fips_files(debugtext-context-sapp.c) -# sokol_shader(debugtext-context-sapp.glsl ${slang}) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(debugtext-context-sapp-ui windowed) -# fips_files(debugtext-context-sapp.c) -# sokol_shader(debugtext-context-sapp.glsl ${slang}) -# fips_deps(sokol dbgui) -# target_compile_definitions(debugtext-context-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() +fips_ide_group(Samples) +fips_begin_app(debugtext-context-sapp windowed) + fips_files(debugtext-context-sapp.c) + sokol_shader(debugtext-context-sapp.glsl ${slang}) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(debugtext-context-sapp-ui windowed) + fips_files(debugtext-context-sapp.c) + sokol_shader(debugtext-context-sapp.glsl ${slang}) + fips_deps(sokol dbgui) + target_compile_definitions(debugtext-context-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(debugtext-layers-sapp windowed) + fips_files(debugtext-layers-sapp.c) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(debugtext-layers-sapp-ui windowed) + fips_files(debugtext-layers-sapp.c) + fips_deps(sokol dbgui) + target_compile_definitions(debugtext-layers-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(debugtext-layers-sapp windowed) -# fips_files(debugtext-layers-sapp.c) -# fips_deps(sokol) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(debugtext-layers-sapp-ui windowed) -# fips_files(debugtext-layers-sapp.c) -# fips_deps(sokol dbgui) -# target_compile_definitions(debugtext-layers-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# fips_ide_group(Samples) fips_begin_app(saudio-sapp windowed) fips_files(saudio-sapp.c) @@ -735,21 +735,21 @@ fips_begin_app(saudio-sapp windowed) endif() fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(icon-sapp windowed) -# fips_files(icon-sapp.c) -# fips_deps(sokol) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(droptest-sapp windowed) -# fips_files(droptest-sapp.c) -# fips_deps(sokol cimgui) -# if (FIPS_IOS) -# fips_files(ios-info.plist) -# endif() -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(icon-sapp windowed) + fips_files(icon-sapp.c) + fips_deps(sokol) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(droptest-sapp windowed) + fips_files(droptest-sapp.c) + fips_deps(sokol cimgui) + if (FIPS_IOS) + fips_files(ios-info.plist) + endif() +fips_end_app() + fips_ide_group(Samples) fips_begin_app(fontstash-sapp windowed) fips_files(fontstash-sapp.c) @@ -766,24 +766,24 @@ fips_begin_app(fontstash-sapp-ui windowed) target_compile_definitions(fontstash-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(fontstash-layers-sapp windowed) -# fips_files(fontstash-layers-sapp.c) -# fips_deps(sokol fileutil) -# sokol_shader(fontstash-layers-sapp.glsl ${slang}) -# fips_dir(data) -# fipsutil_copy(fontstash.yml) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(fontstash-layers-sapp-ui windowed) -# fips_files(fontstash-layers-sapp.c) -# fips_deps(sokol fileutil dbgui) -# sokol_shader(fontstash-layers-sapp.glsl ${slang}) -# fips_dir(data) -# fipsutil_copy(fontstash.yml) -# target_compile_definitions(fontstash-layers-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(fontstash-layers-sapp windowed) + fips_files(fontstash-layers-sapp.c) + fips_deps(sokol fileutil) + sokol_shader(fontstash-layers-sapp.glsl ${slang}) + fips_dir(data) + fipsutil_copy(fontstash.yml) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(fontstash-layers-sapp-ui windowed) + fips_files(fontstash-layers-sapp.c) + fips_deps(sokol fileutil dbgui) + sokol_shader(fontstash-layers-sapp.glsl ${slang}) + fips_dir(data) + fipsutil_copy(fontstash.yml) + target_compile_definitions(fontstash-layers-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(modplay-sapp windowed) fips_files(modplay-sapp.c) @@ -795,15 +795,15 @@ fips_begin_app(modplay-sapp windowed) fips_deps(sokol libmodplug) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(restart-sapp windowed) -# fips_files(restart-sapp.c) -# sokol_shader(restart-sapp.glsl ${slang}) -# fips_dir(data) -# fipsutil_copy(restart-assets.yml) -# fips_deps(sokol fileutil stb libmodplug) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(restart-sapp windowed) + fips_files(restart-sapp.c) + sokol_shader(restart-sapp.glsl ${slang}) + fips_dir(data) + fipsutil_copy(restart-assets.yml) + fips_deps(sokol fileutil stb libmodplug) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(plmpeg-sapp windowed) fips_files(plmpeg-sapp.c) @@ -858,94 +858,94 @@ fips_begin_app(loadpng-sapp-ui windowed) target_compile_definitions(loadpng-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(spine-simple-sapp windowed) -# fips_files(spine-simple-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(spine-simple-sapp-ui windowed) -# fips_files(spine-simple-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil dbgui) -# target_compile_definitions(spine-simple-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(spine-inspector-sapp windowed) -# fips_files(spine-inspector-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil cimgui) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(spine-skinsets-sapp windowed) -# fips_files(spine-skinsets-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(spine-skinsets-sapp-ui windowed) -# fips_files(spine-skinsets-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil dbgui) -# target_compile_definitions(spine-skinsets-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(spine-layers-sapp windowed) -# fips_files(spine-layers-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(spine-layers-sapp-ui windowed) -# fips_files(spine-layers-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil dbgui) -# target_compile_definitions(spine-layers-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(spine-contexts-sapp windowed) -# fips_files(spine-contexts-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(spine-contexts-sapp-ui windowed) -# fips_files(spine-contexts-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil dbgui) -# target_compile_definitions(spine-contexts-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(spine-switch-skinsets-sapp windowed) -# fips_files(spine-switch-skinsets-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(spine-switch-skinsets-sapp-ui windowed) -# fips_files(spine-switch-skinsets-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil dbgui) -# target_compile_definitions(spine-switch-skinsets-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() +fips_ide_group(Samples) +fips_begin_app(spine-simple-sapp windowed) + fips_files(spine-simple-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(spine-simple-sapp-ui windowed) + fips_files(spine-simple-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil dbgui) + target_compile_definitions(spine-simple-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +# fips_ide_group(Samples) +# fips_begin_app(spine-inspector-sapp windowed) +# fips_files(spine-inspector-sapp.c) +# fips_dir(data) +# fipsutil_copy(spine-assets.yml) +# fips_deps(sokol spine-c stb fileutil cimgui) +# fips_end_app() # +fips_ide_group(Samples) +fips_begin_app(spine-skinsets-sapp windowed) + fips_files(spine-skinsets-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(spine-skinsets-sapp-ui windowed) + fips_files(spine-skinsets-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil dbgui) + target_compile_definitions(spine-skinsets-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(spine-layers-sapp windowed) + fips_files(spine-layers-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(spine-layers-sapp-ui windowed) + fips_files(spine-layers-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil dbgui) + target_compile_definitions(spine-layers-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(spine-contexts-sapp windowed) + fips_files(spine-contexts-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(spine-contexts-sapp-ui windowed) + fips_files(spine-contexts-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil dbgui) + target_compile_definitions(spine-contexts-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(spine-switch-skinsets-sapp windowed) + fips_files(spine-switch-skinsets-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(spine-switch-skinsets-sapp-ui windowed) + fips_files(spine-switch-skinsets-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil dbgui) + target_compile_definitions(spine-switch-skinsets-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + #fips_ide_group(Samples) #fips_begin_app(ozz-anim-sapp windowed) # fips_files(ozz-anim-sapp.cc) diff --git a/sapp/cubemap-jpeg-sapp.c b/sapp/cubemap-jpeg-sapp.c index 78609fea..daa6add6 100644 --- a/sapp/cubemap-jpeg-sapp.c +++ b/sapp/cubemap-jpeg-sapp.c @@ -138,10 +138,10 @@ static void init(void) { }); // allocate a texture handle, but initialize the texture later after data is loaded - state.bind.fs.images[SLOT_tex] = sg_alloc_image(); + state.bind.images[IMG_tex] = sg_alloc_image(); // a sampler object - state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_LINEAR, .mag_filter = SG_FILTER_LINEAR, .label = "cubemap-sampler" @@ -149,7 +149,7 @@ static void init(void) { // a pipeline object state.pip = sg_make_pipeline(&(sg_pipeline_desc){ - .layout.attrs[ATTR_vs_pos].format = SG_VERTEXFORMAT_FLOAT3, + .layout.attrs[ATTR_cubemap_pos].format = SG_VERTEXFORMAT_FLOAT3, .shader = sg_make_shader(cubemap_shader_desc(sg_query_backend())), .index_type = SG_INDEXTYPE_UINT16, .depth = { @@ -193,7 +193,7 @@ static void fetch_cb(const sfetch_response_t* response) { stbi_image_free(decoded_pixels); // all 6 faces loaded? if (++state.load_count == SG_CUBEFACE_NUM) { - sg_init_image(state.bind.fs.images[SLOT_tex], &(sg_image_desc){ + sg_init_image(state.bind.images[IMG_tex], &(sg_image_desc){ .type = SG_IMAGETYPE_CUBE, .width = width, .height = height, @@ -237,7 +237,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind), - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sdtx_draw(); __dbgui_draw(); diff --git a/sapp/cubemap-jpeg-sapp.glsl b/sapp/cubemap-jpeg-sapp.glsl index b71ebbf3..e71d6948 100644 --- a/sapp/cubemap-jpeg-sapp.glsl +++ b/sapp/cubemap-jpeg-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -15,8 +15,8 @@ void main() { @end @fs fs -uniform textureCube tex; -uniform sampler smp; +layout(binding=0) uniform textureCube tex; +layout(binding=0) uniform sampler smp; in vec3 uvw; out vec4 frag_color; diff --git a/sapp/debugtext-context-sapp.c b/sapp/debugtext-context-sapp.c index 60e84d63..b6f9a1ae 100644 --- a/sapp/debugtext-context-sapp.c +++ b/sapp/debugtext-context-sapp.c @@ -136,8 +136,8 @@ static void init(void) { state.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { .attrs = { - [ATTR_vs_pos].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_texcoord0].format = SG_VERTEXFORMAT_SHORT2N + [ATTR_debugtext_context_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_debugtext_context_texcoord0].format = SG_VERTEXFORMAT_SHORT2N } }, .shader = sg_make_shader(debugtext_context_shader_desc(sg_query_backend())), @@ -247,12 +247,13 @@ static void frame(void) { // draw the cube as 6 separate draw calls (because each has its own texture) sg_apply_pipeline(state.pip); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); for (int i = 0; i < NUM_FACES; i++) { sg_apply_bindings(&(sg_bindings){ .vertex_buffers[0] = state.vbuf, .index_buffer = state.ibuf, - .fs = { .images[0] = state.passes[i].img, .samplers[0] = state.smp } + .images[IMG_tex] = state.passes[i].img, + .samplers[SMP_smp] = state.smp }); sg_draw(i * 6, 6, 1); } diff --git a/sapp/debugtext-context-sapp.glsl b/sapp/debugtext-context-sapp.glsl index 30ed231e..d20ca3d3 100644 --- a/sapp/debugtext-context-sapp.glsl +++ b/sapp/debugtext-context-sapp.glsl @@ -4,7 +4,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -24,8 +24,8 @@ void main() { @end @fs fs -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/drawcallperf-sapp.glsl b/sapp/drawcallperf-sapp.glsl index 0fc7efa3..5285f89c 100644 --- a/sapp/drawcallperf-sapp.glsl +++ b/sapp/drawcallperf-sapp.glsl @@ -2,11 +2,11 @@ @ctype vec4 hmm_vec4 @vs vs -uniform vs_per_frame { +layout(binding=0) uniform vs_per_frame { mat4 viewproj; }; -uniform vs_per_instance { +layout(binding=1) uniform vs_per_instance { vec4 world_pos; }; @@ -24,8 +24,8 @@ void main() { @end @fs fs -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec2 uv; in float bright; diff --git a/sapp/dyntex3d-sapp.glsl b/sapp/dyntex3d-sapp.glsl index a8695d4b..ee583e39 100644 --- a/sapp/dyntex3d-sapp.glsl +++ b/sapp/dyntex3d-sapp.glsl @@ -4,7 +4,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { float w; }; @@ -21,8 +21,8 @@ void main() { @end @fs fs -uniform texture3D tex; -uniform sampler smp; +layout(binding=0) uniform texture3D tex; +layout(binding=0) uniform sampler smp; in vec3 uvw; out vec4 frag_color; diff --git a/sapp/fontstash-layers-sapp.c b/sapp/fontstash-layers-sapp.c index 4de7defd..bdea59e4 100644 --- a/sapp/fontstash-layers-sapp.c +++ b/sapp/fontstash-layers-sapp.c @@ -104,8 +104,8 @@ static void init(void) { .shader = sg_make_shader(triangle_shader_desc(sg_query_backend())), .layout = { .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4, + [ATTR_triangle_position].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_triangle_color0].format = SG_VERTEXFORMAT_FLOAT4, } }, .colors[0] = { diff --git a/sapp/imgui-usercallback-sapp.c b/sapp/imgui-usercallback-sapp.c index fcfd5790..1467d9db 100644 --- a/sapp/imgui-usercallback-sapp.c +++ b/sapp/imgui-usercallback-sapp.c @@ -116,8 +116,8 @@ void init(void) { state.scene1.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { .attrs = { - [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4 + [ATTR_scene_position].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_scene_color0].format = SG_VERTEXFORMAT_FLOAT4 } }, .shader = sg_make_shader(scene_shader_desc(sg_query_backend())), @@ -180,7 +180,7 @@ void draw_scene_1(const ImDrawList* dl, const ImDrawCmd* cmd) { */ sg_apply_pipeline(state.scene1.pip); sg_apply_bindings(&state.scene1.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); } diff --git a/sapp/imgui-usercallback-sapp.glsl b/sapp/imgui-usercallback-sapp.glsl index 3d9ccb3b..5f9ab0ec 100644 --- a/sapp/imgui-usercallback-sapp.glsl +++ b/sapp/imgui-usercallback-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; diff --git a/sapp/instancing-pull-sapp.c b/sapp/instancing-pull-sapp.c index 5ae5f3fb..21b27857 100644 --- a/sapp/instancing-pull-sapp.c +++ b/sapp/instancing-pull-sapp.c @@ -64,7 +64,7 @@ static void init(void) { { .pos = HMM_Vec3( -r, 0.0f, r ), .color = HMM_Vec4(0.0f, 1.0f, 1.0f, 1.0f) }, { .pos = HMM_Vec3(0.0f, r, 0.0f), .color = HMM_Vec4(1.0f, 0.0f, 1.0f, 1.0f) }, }; - state.bind.vs.storage_buffers[SLOT_vertices] = sg_make_buffer(&(sg_buffer_desc){ + state.bind.storage_buffers[SBUF_vertices] = sg_make_buffer(&(sg_buffer_desc){ .type = SG_BUFFERTYPE_STORAGEBUFFER, .data = SG_RANGE(vertices), .label = "geometry-vertices", @@ -82,7 +82,7 @@ static void init(void) { }); // a dynamic storage buffer for the per-instance data - state.bind.vs.storage_buffers[SLOT_instances] = sg_make_buffer(&(sg_buffer_desc) { + state.bind.storage_buffers[SBUF_instances] = sg_make_buffer(&(sg_buffer_desc) { .type = SG_BUFFERTYPE_STORAGEBUFFER, .usage = SG_USAGE_STREAM, .size = MAX_PARTICLES * sizeof(sb_instance_t), @@ -115,7 +115,7 @@ static void frame(void) { update_particles(frame_time); // update instance data storage buffer - sg_update_buffer(state.bind.vs.storage_buffers[SLOT_instances], &(sg_range){ + sg_update_buffer(state.bind.storage_buffers[SBUF_instances], &(sg_range){ .ptr = state.inst, .size = (size_t)state.cur_num_particles * sizeof(sb_instance_t), }); @@ -127,7 +127,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 24, state.cur_num_particles); __dbgui_draw(); sg_end_pass(); diff --git a/sapp/instancing-pull-sapp.glsl b/sapp/instancing-pull-sapp.glsl index 41688b63..b6954a82 100644 --- a/sapp/instancing-pull-sapp.glsl +++ b/sapp/instancing-pull-sapp.glsl @@ -16,11 +16,11 @@ struct sb_instance { vec3 pos; }; -readonly buffer vertices { +layout(binding=0) readonly buffer vertices { sb_vertex vtx[]; }; -readonly buffer instances { +layout(binding=1) readonly buffer instances { sb_instance inst[]; }; diff --git a/sapp/pixelformats-sapp.c b/sapp/pixelformats-sapp.c index 98d5f7b4..b50249e8 100644 --- a/sapp/pixelformats-sapp.c +++ b/sapp/pixelformats-sapp.c @@ -98,8 +98,8 @@ static void init(void) { sg_pipeline_desc cube_render_pip_desc = { .layout = { .attrs = { - [ATTR_vs_cube_pos].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_cube_color0].format = SG_VERTEXFORMAT_FLOAT4 + [ATTR_cube_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_cube_color0].format = SG_VERTEXFORMAT_FLOAT4 } }, .shader = sg_make_shader(cube_shader_desc(sg_query_backend())), @@ -113,7 +113,7 @@ static void init(void) { }, }; sg_pipeline_desc bg_render_pip_desc = { - .layout.attrs[ATTR_vs_bg_position].format = SG_VERTEXFORMAT_FLOAT2, + .layout.attrs[ATTR_bg_position].format = SG_VERTEXFORMAT_FLOAT2, .shader = sg_make_shader(bg_shader_desc(sg_query_backend())), .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP, .sample_count = 1, @@ -317,11 +317,11 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .attachments = state.fmt[i].render_atts }); sg_apply_pipeline(state.fmt[i].bg_render_pip); sg_apply_bindings(&state.bg_bindings); - sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_bg_fs_params, &SG_RANGE(state.bg_fs_params)); + sg_apply_uniforms(UB_bg_fs_params, &SG_RANGE(state.bg_fs_params)); sg_draw(0, 4, 1); sg_apply_pipeline(state.fmt[i].cube_render_pip); sg_apply_bindings(&state.cube_bindings); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_cube_vs_params, &SG_RANGE(state.cube_vs_params)); + sg_apply_uniforms(UB_cube_vs_params, &SG_RANGE(state.cube_vs_params)); sg_draw(0, 36, 1); sg_end_pass(); } @@ -329,11 +329,11 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .attachments = state.fmt[i].blend_atts }); sg_apply_pipeline(state.fmt[i].bg_render_pip); // not a bug sg_apply_bindings(&state.bg_bindings); // not a bug - sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_bg_fs_params, &SG_RANGE(state.bg_fs_params)); + sg_apply_uniforms(UB_bg_fs_params, &SG_RANGE(state.bg_fs_params)); sg_draw(0, 4, 1); sg_apply_pipeline(state.fmt[i].cube_blend_pip); sg_apply_bindings(&state.cube_bindings); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_cube_vs_params, &SG_RANGE(state.cube_vs_params)); + sg_apply_uniforms(UB_cube_vs_params, &SG_RANGE(state.cube_vs_params)); sg_draw(0, 36, 1); sg_end_pass(); } @@ -341,11 +341,11 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .attachments = state.fmt[i].msaa_atts, .action = { .colors[0].store_action = SG_STOREACTION_DONTCARE } }); sg_apply_pipeline(state.fmt[i].bg_msaa_pip); sg_apply_bindings(&state.bg_bindings); - sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_bg_fs_params, &SG_RANGE(state.bg_fs_params)); + sg_apply_uniforms(UB_bg_fs_params, &SG_RANGE(state.bg_fs_params)); sg_draw(0, 4, 1); sg_apply_pipeline(state.fmt[i].cube_msaa_pip); sg_apply_bindings(&state.cube_bindings); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_cube_vs_params, &SG_RANGE(state.cube_vs_params)); + sg_apply_uniforms(UB_cube_vs_params, &SG_RANGE(state.cube_vs_params)); sg_draw(0, 36, 1); sg_end_pass(); } diff --git a/sapp/pixelformats-sapp.glsl b/sapp/pixelformats-sapp.glsl index 0ef8f753..94d1e84d 100644 --- a/sapp/pixelformats-sapp.glsl +++ b/sapp/pixelformats-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs_cube -uniform cube_vs_params { +layout(binding=0) uniform cube_vs_params { mat4 mvp; }; in vec4 pos; @@ -34,7 +34,7 @@ void main() { @end @fs fs_bg -uniform bg_fs_params { +layout(binding=0) uniform bg_fs_params { float tick; }; diff --git a/sapp/primtypes-sapp.c b/sapp/primtypes-sapp.c index 5fe1ccf5..e3b29aac 100644 --- a/sapp/primtypes-sapp.c +++ b/sapp/primtypes-sapp.c @@ -105,8 +105,8 @@ static void init(void) { // create pipeline state objects for each primitive type sg_pipeline_desc pip_desc = { .layout = { - .attrs[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT2, - .attrs[ATTR_vs_color0].format = SG_VERTEXFORMAT_UBYTE4N, + .attrs[ATTR_primtypes_position].format = SG_VERTEXFORMAT_FLOAT2, + .attrs[ATTR_primtypes_color0].format = SG_VERTEXFORMAT_UBYTE4N, }, .shader = sg_make_shader(primtypes_shader_desc(sg_query_backend())), .depth = { @@ -157,7 +157,7 @@ static void frame(void) { .vertex_buffers[0] = state.vbuf, .index_buffer = state.prim[state.cur_prim_type].ibuf, }); - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, state.prim[state.cur_prim_type].num_elements, 1); sdtx_draw(); __dbgui_draw(); diff --git a/sapp/primtypes-sapp.glsl b/sapp/primtypes-sapp.glsl index 842d9100..1d3cb335 100644 --- a/sapp/primtypes-sapp.glsl +++ b/sapp/primtypes-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; float point_size; }; diff --git a/sapp/restart-sapp.c b/sapp/restart-sapp.c index 521630d5..367f8ccb 100644 --- a/sapp/restart-sapp.c +++ b/sapp/restart-sapp.c @@ -182,7 +182,7 @@ static void init(void) { }); // setup rendering resources - state.scene.bind.fs.images[0] = sg_alloc_image(); + state.scene.bind.images[IMG_tex] = sg_alloc_image(); state.scene.bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){ .data = SG_RANGE(cube_vertices), @@ -195,7 +195,7 @@ static void init(void) { .label = "cube-indices" }); - state.scene.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.scene.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_LINEAR, .mag_filter = SG_FILTER_LINEAR, }); @@ -204,8 +204,8 @@ static void init(void) { .shader = sg_make_shader(restart_shader_desc(sg_query_backend())), .layout = { .attrs = { - [ATTR_vs_pos].format = SG_VERTEXFORMAT_FLOAT3, - [ATTR_vs_texcoord0].format = SG_VERTEXFORMAT_SHORT2N + [ATTR_restart_pos].format = SG_VERTEXFORMAT_FLOAT3, + [ATTR_restart_texcoord0].format = SG_VERTEXFORMAT_SHORT2N } }, .index_type = SG_INDEXTYPE_UINT16, @@ -262,7 +262,7 @@ static void fetch_img_callback(const sfetch_response_t* response) { &png_width, &png_height, &num_channels, desired_channels); if (pixels) { - sg_init_image(state.scene.bind.fs.images[SLOT_tex], &(sg_image_desc){ + sg_init_image(state.scene.bind.images[IMG_tex], &(sg_image_desc){ .width = png_width, .height = png_height, .pixel_format = SG_PIXELFORMAT_RGBA8, @@ -393,7 +393,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.scene.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.scene.pip); sg_apply_bindings(&state.scene.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 36, 1); sgl_draw(); sdtx_draw(); diff --git a/sapp/restart-sapp.glsl b/sapp/restart-sapp.glsl index 06e26d07..3905f026 100644 --- a/sapp/restart-sapp.glsl +++ b/sapp/restart-sapp.glsl @@ -5,7 +5,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; }; @@ -20,8 +20,8 @@ void main() { @end @fs fs -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; in vec2 uv; out vec4 frag_color; diff --git a/sapp/shapes-sapp.c b/sapp/shapes-sapp.c index d6b6e8df..776aafcd 100644 --- a/sapp/shapes-sapp.c +++ b/sapp/shapes-sapp.c @@ -170,7 +170,7 @@ static void frame(void) { // per shape model-view-projection matrix hmm_mat4 model = HMM_MultiplyMat4(HMM_Translate(state.shapes[i].pos), rm); state.vs_params.mvp = HMM_MultiplyMat4(view_proj, model); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(state.vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(state.vs_params)); sg_draw(state.shapes[i].draw.base_element, state.shapes[i].draw.num_elements, 1); } sdtx_draw(); diff --git a/sapp/shapes-sapp.glsl b/sapp/shapes-sapp.glsl index 06799db0..a3033e59 100644 --- a/sapp/shapes-sapp.glsl +++ b/sapp/shapes-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; float draw_mode; }; diff --git a/sapp/shapes-transform-sapp.c b/sapp/shapes-transform-sapp.c index 15388648..f97699a0 100644 --- a/sapp/shapes-transform-sapp.c +++ b/sapp/shapes-transform-sapp.c @@ -149,7 +149,7 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(state.vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(state.vs_params)); sg_draw(state.elms.base_element, state.elms.num_elements, 1); // render help text and finish frame diff --git a/sapp/shapes-transform-sapp.glsl b/sapp/shapes-transform-sapp.glsl index 2247ecc0..2bea6a56 100644 --- a/sapp/shapes-transform-sapp.glsl +++ b/sapp/shapes-transform-sapp.glsl @@ -1,7 +1,7 @@ @ctype mat4 hmm_mat4 @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { float draw_mode; mat4 mvp; }; diff --git a/sapp/uniformtypes-sapp.c b/sapp/uniformtypes-sapp.c index 04f961ba..371ce911 100644 --- a/sapp/uniformtypes-sapp.c +++ b/sapp/uniformtypes-sapp.c @@ -118,7 +118,7 @@ static void frame(void) { state.vs_params.sel = i; state.vs_params.offset[0] = x0; state.vs_params.offset[1] = y0; - sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(state.vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(state.vs_params)); sg_draw(0, 6, 1); y0 -= 4.0f * glyph_h; } diff --git a/sapp/uniformtypes-sapp.glsl b/sapp/uniformtypes-sapp.glsl index a5786924..efca41cc 100644 --- a/sapp/uniformtypes-sapp.glsl +++ b/sapp/uniformtypes-sapp.glsl @@ -4,7 +4,7 @@ // inefficient in the sokol-gfx GL backend, because the uniform // block will not be flattened into a single float or int array! // -uniform vs_params { +layout(binding=0) uniform vs_params { vec2 offset; vec2 scale; // scramble the vector sizes to enforce 'weird' padding @@ -67,4 +67,3 @@ void main() { @end @program uniformtypes vs fs - From d35ddac88fbe4c990c02dfc61077968051234b49 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 14 Oct 2024 18:05:34 +0200 Subject: [PATCH 31/36] fix more sapp samples for bindings cleanup --- sapp/CMakeLists.txt | 78 ++++++++++++++++++++--------------------- sapp/ozz-skin-sapp.glsl | 6 ++-- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index 6608e3ba..564c2a8f 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -535,30 +535,30 @@ fips_begin_app(sgl-microui-sapp-ui windowed) target_compile_definitions(sgl-microui-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(nuklear-sapp windowed) -# fips_files(nuklear-sapp.c) -# fips_deps(sokol nuklear) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(nuklear-sapp-ui windowed) -# fips_files(nuklear-sapp.c) -# fips_deps(sokol nuklear dbgui) -# target_compile_definitions(nuklear-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# -#fips_ide_group(Samples) -#fips_begin_app(nuklear-images-sapp windowed) -# fips_files(nuklear-images-sapp.c) -# fips_deps(sokol nuklear) -#fips_end_app() -#fips_ide_group(SamplesWithDebugUI) -#fips_begin_app(nuklear-images-sapp-ui windowed) -# fips_files(nuklear-images-sapp.c) -# fips_deps(sokol nuklear dbgui) -# target_compile_definitions(nuklear-images-sapp-ui PRIVATE USE_DBG_UI) -#fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(nuklear-sapp windowed) + fips_files(nuklear-sapp.c) + fips_deps(sokol nuklear) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(nuklear-sapp-ui windowed) + fips_files(nuklear-sapp.c) + fips_deps(sokol nuklear dbgui) + target_compile_definitions(nuklear-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + +fips_ide_group(Samples) +fips_begin_app(nuklear-images-sapp windowed) + fips_files(nuklear-images-sapp.c) + fips_deps(sokol nuklear) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(nuklear-images-sapp-ui windowed) + fips_files(nuklear-images-sapp.c) + fips_deps(sokol nuklear dbgui) + target_compile_definitions(nuklear-images-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(cubemaprt-sapp windowed) fips_files(cubemaprt-sapp.c) @@ -946,21 +946,21 @@ fips_begin_app(spine-switch-skinsets-sapp-ui windowed) target_compile_definitions(spine-switch-skinsets-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -#fips_ide_group(Samples) -#fips_begin_app(ozz-anim-sapp windowed) -# fips_files(ozz-anim-sapp.cc) -# fips_dir(data) -# fipsutil_copy(ozz-anim-assets.yml) -# fips_deps(sokol fileutil ozzanim imgui) -#fips_end_app() -# -#fips_begin_app(ozz-skin-sapp windowed) -# fips_files(ozz-skin-sapp.cc) -# sokol_shader(ozz-skin-sapp.glsl ${slang}) -# fips_dir(data) -# fipsutil_copy(ozz-skin-assets.yml) -# fips_deps(sokol fileutil ozzanim imgui) -#fips_end_app() +fips_ide_group(Samples) +fips_begin_app(ozz-anim-sapp windowed) + fips_files(ozz-anim-sapp.cc) + fips_dir(data) + fipsutil_copy(ozz-anim-assets.yml) + fips_deps(sokol fileutil ozzanim imgui) +fips_end_app() + +# fips_begin_app(ozz-skin-sapp windowed) +# fips_files(ozz-skin-sapp.cc) +# sokol_shader(ozz-skin-sapp.glsl ${slang}) +# fips_dir(data) +# fipsutil_copy(ozz-skin-assets.yml) +# fips_deps(sokol fileutil ozzanim imgui) +# fips_end_app() # #fips_begin_app(ozz-storagebuffer-sapp windowed) # fips_files(ozz-storagebuffer-sapp.cc) diff --git a/sapp/ozz-skin-sapp.glsl b/sapp/ozz-skin-sapp.glsl index 013ea4bf..998aff7e 100644 --- a/sapp/ozz-skin-sapp.glsl +++ b/sapp/ozz-skin-sapp.glsl @@ -45,15 +45,15 @@ void skinned_pos_nrm(in vec4 pos, in vec4 nrm, in vec4 skin_weights, in vec4 ski @end @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 view_proj; float joint_pixel_width; }; @image_sample_type joint_tex unfilterable_float -uniform texture2D joint_tex; +layout(binding=0) uniform texture2D joint_tex; @sampler_type smp nonfiltering -uniform sampler smp; +layout(binding=0) uniform sampler smp; in vec4 position; in vec4 normal; From 54c1428df089b2158e0f4c0d869539ea99d4671f Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Wed, 16 Oct 2024 17:33:07 +0200 Subject: [PATCH 32/36] all sapp samples updated for bindings cleanup --- sapp/CMakeLists.txt | 107 +++++++++++++++---------------- sapp/drawcallperf-sapp.c | 16 ++--- sapp/dyntex3d-sapp.c | 6 +- sapp/ozz-skin-sapp.cc | 30 ++++----- sapp/ozz-storagebuffer-sapp.cc | 10 +-- sapp/ozz-storagebuffer-sapp.glsl | 8 +-- sapp/shdfeatures-sapp.c | 90 +++++++++++++------------- sapp/shdfeatures-sapp.glsl | 8 +-- 8 files changed, 135 insertions(+), 140 deletions(-) diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index 564c2a8f..51eb6862 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -41,7 +41,6 @@ fips_begin_app(triangle-bufferless-sapp-ui windowed) target_compile_definitions(triangle-bufferless-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() - fips_ide_group(Samples) fips_begin_app(quad-sapp windowed) fips_files(quad-sapp.c) @@ -280,13 +279,13 @@ fips_begin_app(tex3d-sapp-ui windowed) target_compile_definitions(tex3d-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -# fips_ide_group(Samples) -# fips_begin_app(dyntex3d-sapp windowed) -# fips_files(dyntex3d-sapp.c) -# sokol_shader(dyntex3d-sapp.glsl ${slang}) -# fips_deps(sokol cimgui) -# fips_end_app() -# + fips_ide_group(Samples) + fips_begin_app(dyntex3d-sapp windowed) + fips_files(dyntex3d-sapp.c) + sokol_shader(dyntex3d-sapp.glsl ${slang}) + fips_deps(sokol cimgui) + fips_end_app() + fips_ide_group(Samples) fips_begin_app(dyntex-sapp windowed) fips_files(dyntex-sapp.c) @@ -657,13 +656,13 @@ fips_begin_app(primtypes-sapp-ui windowed) target_compile_definitions(primtypes-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -# fips_ide_group(Samples) -# fips_begin_app(drawcallperf-sapp windowed) -# fips_files(drawcallperf-sapp.c) -# sokol_shader(drawcallperf-sapp.glsl ${slang}) -# fips_deps(sokol cimgui) -# fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(drawcallperf-sapp windowed) + fips_files(drawcallperf-sapp.c) + sokol_shader(drawcallperf-sapp.glsl ${slang}) + fips_deps(sokol cimgui) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(debugtext-sapp windowed) fips_files(debugtext-sapp.c) @@ -874,14 +873,14 @@ fips_begin_app(spine-simple-sapp-ui windowed) target_compile_definitions(spine-simple-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() -# fips_ide_group(Samples) -# fips_begin_app(spine-inspector-sapp windowed) -# fips_files(spine-inspector-sapp.c) -# fips_dir(data) -# fipsutil_copy(spine-assets.yml) -# fips_deps(sokol spine-c stb fileutil cimgui) -# fips_end_app() -# +fips_ide_group(Samples) +fips_begin_app(spine-inspector-sapp windowed) + fips_files(spine-inspector-sapp.c) + fips_dir(data) + fipsutil_copy(spine-assets.yml) + fips_deps(sokol spine-c stb fileutil cimgui) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(spine-skinsets-sapp windowed) fips_files(spine-skinsets-sapp.c) @@ -954,37 +953,37 @@ fips_begin_app(ozz-anim-sapp windowed) fips_deps(sokol fileutil ozzanim imgui) fips_end_app() -# fips_begin_app(ozz-skin-sapp windowed) -# fips_files(ozz-skin-sapp.cc) -# sokol_shader(ozz-skin-sapp.glsl ${slang}) -# fips_dir(data) -# fipsutil_copy(ozz-skin-assets.yml) -# fips_deps(sokol fileutil ozzanim imgui) -# fips_end_app() -# -#fips_begin_app(ozz-storagebuffer-sapp windowed) -# fips_files(ozz-storagebuffer-sapp.cc) -# sokol_shader(ozz-storagebuffer-sapp.glsl ${slang}) -# fips_dir(data) -# fipsutil_copy(ozz-skin-assets.yml) -# fips_deps(sokol fileutil ozzanim imgui) -#fips_end_app() -# -#fips_begin_app(shdfeatures-sapp windowed) -# fips_files(shdfeatures-sapp.c) -# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "none" "NONE") -# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "slm" "SKINNING:LIGHTING:MATERIAL") -# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "sl" "SKINNING:LIGHTING") -# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "s" "SKINNING") -# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "sm" "SKINNING:MATERIAL") -# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "lm" "LIGHTING:MATERIAL") -# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "m" "MATERIAL") -# sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "l" "LIGHTING") -# fips_dir(data) -# fipsutil_copy(ozz-skin-assets.yml) -# fips_deps(sokol fileutil ozzutil cimgui) -#fips_end_app() -# +fips_begin_app(ozz-skin-sapp windowed) + fips_files(ozz-skin-sapp.cc) + sokol_shader(ozz-skin-sapp.glsl ${slang}) + fips_dir(data) + fipsutil_copy(ozz-skin-assets.yml) + fips_deps(sokol fileutil ozzanim imgui) +fips_end_app() + +fips_begin_app(ozz-storagebuffer-sapp windowed) + fips_files(ozz-storagebuffer-sapp.cc) + sokol_shader(ozz-storagebuffer-sapp.glsl ${slang}) + fips_dir(data) + fipsutil_copy(ozz-skin-assets.yml) + fips_deps(sokol fileutil ozzanim imgui) +fips_end_app() + +fips_begin_app(shdfeatures-sapp windowed) + fips_files(shdfeatures-sapp.c) + sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "none" "NONE") + sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "slm" "SKINNING:LIGHTING:MATERIAL") + sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "sl" "SKINNING:LIGHTING") + sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "s" "SKINNING") + sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "sm" "SKINNING:MATERIAL") + sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "lm" "LIGHTING:MATERIAL") + sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "m" "MATERIAL") + sokol_shader_variant_with_reflection(shdfeatures-sapp.glsl ${slang} "l" "LIGHTING") + fips_dir(data) + fipsutil_copy(ozz-skin-assets.yml) + fips_deps(sokol fileutil ozzutil cimgui) +fips_end_app() + if (NOT FIPS_ANDROID) fips_ide_group(Samples) fips_begin_app(noentry-sapp windowed) diff --git a/sapp/drawcallperf-sapp.c b/sapp/drawcallperf-sapp.c index 8dee7871..2a6d0eeb 100644 --- a/sapp/drawcallperf-sapp.c +++ b/sapp/drawcallperf-sapp.c @@ -156,7 +156,7 @@ static void init(void) { .data.subimage[0][0] = SG_RANGE(pixels), }); } - state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_NEAREST, .mag_filter = SG_FILTER_NEAREST, }); @@ -165,9 +165,9 @@ static void init(void) { state.pip = sg_make_pipeline(&(sg_pipeline_desc){ .layout = { .attrs = { - [ATTR_vs_in_pos] = { .format = SG_VERTEXFORMAT_FLOAT3 }, - [ATTR_vs_in_uv] = { .format = SG_VERTEXFORMAT_FLOAT2 }, - [ATTR_vs_in_bright] = { .format = SG_VERTEXFORMAT_FLOAT }, + [ATTR_drawcallperf_in_pos] = { .format = SG_VERTEXFORMAT_FLOAT3 }, + [ATTR_drawcallperf_in_uv] = { .format = SG_VERTEXFORMAT_FLOAT2 }, + [ATTR_drawcallperf_in_bright] = { .format = SG_VERTEXFORMAT_FLOAT }, } }, .shader = sg_make_shader(drawcallperf_shader_desc(sg_query_backend())), @@ -246,10 +246,10 @@ static void frame(void) { sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); sg_apply_pipeline(state.pip); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_per_frame, &SG_RANGE(vs_per_frame)); + sg_apply_uniforms(UB_vs_per_frame, &SG_RANGE(vs_per_frame)); state.stats.num_uniform_updates++; - state.bind.fs.images[SLOT_tex] = state.img[0]; + state.bind.images[IMG_tex] = state.img[0]; sg_apply_bindings(&state.bind); state.stats.num_binding_updates++; int cur_bind_count = 0; @@ -260,11 +260,11 @@ static void frame(void) { if (cur_img == NUM_IMAGES) { cur_img = 0; } - state.bind.fs.images[SLOT_tex] = state.img[cur_img++]; + state.bind.images[IMG_tex] = state.img[cur_img++]; sg_apply_bindings(&state.bind); state.stats.num_binding_updates++; } - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_per_instance, &SG_RANGE(positions[i])); + sg_apply_uniforms(UB_vs_per_instance, &SG_RANGE(positions[i])); state.stats.num_uniform_updates++; sg_draw(0, 36, 1); state.stats.num_draw_calls++; diff --git a/sapp/dyntex3d-sapp.c b/sapp/dyntex3d-sapp.c index 1d2708f5..ec5fabab 100644 --- a/sapp/dyntex3d-sapp.c +++ b/sapp/dyntex3d-sapp.c @@ -70,10 +70,10 @@ static void init(void) { }); state.img = sg_alloc_image(); - state.bind.fs.images[SLOT_tex] = state.img; + state.bind.images[IMG_tex] = state.img; recreate_image(); - state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){ + state.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){ .min_filter = SG_FILTER_NEAREST, .mag_filter = SG_FILTER_NEAREST, .wrap_u = SG_WRAP_CLAMP_TO_EDGE, @@ -92,7 +92,7 @@ static void frame(void) { sg_apply_bindings(&state.bind); for (int slice = 0; slice < 3; slice++) { const vs_params_t vs_params = (vs_params_t){ .w = 0.1f + ((float)slice) / 3.0 }; - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params)); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); sg_draw(0, 6, 1); } draw_ui(); diff --git a/sapp/ozz-skin-sapp.cc b/sapp/ozz-skin-sapp.cc index 0eef7ecf..7bfe283a 100644 --- a/sapp/ozz-skin-sapp.cc +++ b/sapp/ozz-skin-sapp.cc @@ -199,18 +199,18 @@ static void init(void) { pip_desc.layout.buffers[0].stride = sizeof(vertex_t); pip_desc.layout.buffers[1].stride = sizeof(instance_t); pip_desc.layout.buffers[1].step_func = SG_VERTEXSTEP_PER_INSTANCE; - pip_desc.layout.attrs[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3; - pip_desc.layout.attrs[ATTR_vs_normal].format = SG_VERTEXFORMAT_BYTE4N; - pip_desc.layout.attrs[ATTR_vs_jindices].format = SG_VERTEXFORMAT_UBYTE4N; - pip_desc.layout.attrs[ATTR_vs_jweights].format = SG_VERTEXFORMAT_UBYTE4N; - pip_desc.layout.attrs[ATTR_vs_inst_xxxx].format = SG_VERTEXFORMAT_FLOAT4; - pip_desc.layout.attrs[ATTR_vs_inst_xxxx].buffer_index = 1; - pip_desc.layout.attrs[ATTR_vs_inst_yyyy].format = SG_VERTEXFORMAT_FLOAT4; - pip_desc.layout.attrs[ATTR_vs_inst_yyyy].buffer_index = 1; - pip_desc.layout.attrs[ATTR_vs_inst_zzzz].format = SG_VERTEXFORMAT_FLOAT4; - pip_desc.layout.attrs[ATTR_vs_inst_zzzz].buffer_index = 1; - pip_desc.layout.attrs[ATTR_vs_inst_joint_uv].format = SG_VERTEXFORMAT_FLOAT2; - pip_desc.layout.attrs[ATTR_vs_inst_joint_uv].buffer_index = 1; + pip_desc.layout.attrs[ATTR_skinned_position].format = SG_VERTEXFORMAT_FLOAT3; + pip_desc.layout.attrs[ATTR_skinned_normal].format = SG_VERTEXFORMAT_BYTE4N; + pip_desc.layout.attrs[ATTR_skinned_jindices].format = SG_VERTEXFORMAT_UBYTE4N; + pip_desc.layout.attrs[ATTR_skinned_jweights].format = SG_VERTEXFORMAT_UBYTE4N; + pip_desc.layout.attrs[ATTR_skinned_inst_xxxx].format = SG_VERTEXFORMAT_FLOAT4; + pip_desc.layout.attrs[ATTR_skinned_inst_xxxx].buffer_index = 1; + pip_desc.layout.attrs[ATTR_skinned_inst_yyyy].format = SG_VERTEXFORMAT_FLOAT4; + pip_desc.layout.attrs[ATTR_skinned_inst_yyyy].buffer_index = 1; + pip_desc.layout.attrs[ATTR_skinned_inst_zzzz].format = SG_VERTEXFORMAT_FLOAT4; + pip_desc.layout.attrs[ATTR_skinned_inst_zzzz].buffer_index = 1; + pip_desc.layout.attrs[ATTR_skinned_inst_joint_uv].format = SG_VERTEXFORMAT_FLOAT2; + pip_desc.layout.attrs[ATTR_skinned_inst_joint_uv].buffer_index = 1; pip_desc.index_type = SG_INDEXTYPE_UINT16; // ozz mesh data appears to have counter-clock-wise face winding pip_desc.face_winding = SG_FACEWINDING_CCW; @@ -230,7 +230,7 @@ static void init(void) { img_desc.pixel_format = SG_PIXELFORMAT_RGBA32F; img_desc.usage = SG_USAGE_STREAM; state.joint_texture = sg_make_image(&img_desc); - state.bind.vs.images[SLOT_joint_tex] = state.joint_texture; + state.bind.images[IMG_joint_tex] = state.joint_texture; sg_sampler_desc smp_desc = { }; smp_desc.min_filter = SG_FILTER_NEAREST; @@ -238,7 +238,7 @@ static void init(void) { smp_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; smp_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; state.smp = sg_make_sampler(&smp_desc); - state.bind.vs.samplers[SLOT_smp] = state.smp; + state.bind.samplers[SMP_smp] = state.smp; // create an sokol-imgui wrapper for the joint texture simgui_image_desc_t simgui_img_desc = { }; @@ -398,7 +398,7 @@ static void frame(void) { vs_params.joint_pixel_width = 1.0f / (float)state.joint_texture_width; sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, SG_RANGE_REF(vs_params)); + sg_apply_uniforms(UB_vs_params, SG_RANGE_REF(vs_params)); if (state.draw_enabled) { sg_draw(0, state.num_triangle_indices, state.num_instances); } diff --git a/sapp/ozz-storagebuffer-sapp.cc b/sapp/ozz-storagebuffer-sapp.cc index 4466f379..d8bf4a5b 100644 --- a/sapp/ozz-storagebuffer-sapp.cc +++ b/sapp/ozz-storagebuffer-sapp.cc @@ -178,7 +178,7 @@ static void init(void) { buf_desc.type = SG_BUFFERTYPE_STORAGEBUFFER; buf_desc.data = SG_RANGE(instance_data); buf_desc.label = "instances"; - state.bind.vs.storage_buffers[SLOT_instances] = sg_make_buffer(&buf_desc); + state.bind.storage_buffers[SBUF_instances] = sg_make_buffer(&buf_desc); } // create another dynamic storage buffer which receives the animated joint matrices @@ -188,7 +188,7 @@ static void init(void) { buf_desc.usage = SG_USAGE_STREAM; buf_desc.size = MAX_INSTANCES * MAX_JOINTS * sizeof(sb_joint_t); buf_desc.label = "joints"; - state.bind.vs.storage_buffers[SLOT_joints] = sg_make_buffer(&buf_desc); + state.bind.storage_buffers[SBUF_joints] = sg_make_buffer(&buf_desc); } // NOTE: the storage buffers for vertices and indices are created in the async fetch callbacks @@ -247,7 +247,7 @@ static void frame(void) { vs_params.view_proj = state.camera.view_proj; sg_apply_pipeline(state.pip); sg_apply_bindings(&state.bind); - sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, SG_RANGE_REF(vs_params)); + sg_apply_uniforms(UB_vs_params, SG_RANGE_REF(vs_params)); sg_draw(0, state.num_triangle_indices, state.num_instances); } simgui_render(); @@ -312,7 +312,7 @@ static void update_joints(void) { state.time.anim_eval_time = stm_since(start_time); // update the sokol-gfx joint storage buffer - sg_update_buffer(state.bind.vs.storage_buffers[SLOT_joints], SG_RANGE(joint_upload_buffer)); + sg_update_buffer(state.bind.storage_buffers[SBUF_joints], SG_RANGE(joint_upload_buffer)); } // arrange the character instances into a quad @@ -460,7 +460,7 @@ static void mesh_data_loaded(const sfetch_response_t* response) { vbuf_desc.data.ptr = vertices; vbuf_desc.data.size = num_vertices * sizeof(sb_vertex_t); vbuf_desc.label = "vertices"; - state.bind.vs.storage_buffers[SLOT_vertices] = sg_make_buffer(&vbuf_desc); + state.bind.storage_buffers[SBUF_vertices] = sg_make_buffer(&vbuf_desc); free(vertices); vertices = nullptr; sg_buffer_desc ibuf_desc = { }; diff --git a/sapp/ozz-storagebuffer-sapp.glsl b/sapp/ozz-storagebuffer-sapp.glsl index 3ec26bb3..c967d398 100644 --- a/sapp/ozz-storagebuffer-sapp.glsl +++ b/sapp/ozz-storagebuffer-sapp.glsl @@ -46,7 +46,7 @@ void skin_pos_nrm(in vec4 pos, in vec4 nrm, in vec4 jweights, in uint jindices, @end @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 view_proj; }; @@ -67,15 +67,15 @@ struct sb_joint { vec4 zzzz; }; -readonly buffer vertices { +layout(binding=0) readonly buffer vertices { sb_vertex vtx[]; }; -readonly buffer instances { +layout(binding=1) readonly buffer instances { sb_instance inst[]; }; -readonly buffer joints { +layout(binding=2) readonly buffer joints { sb_joint joint[]; }; diff --git a/sapp/shdfeatures-sapp.c b/sapp/shdfeatures-sapp.c index e3eda5c1..c5f96470 100644 --- a/sapp/shdfeatures-sapp.c +++ b/sapp/shdfeatures-sapp.c @@ -81,7 +81,6 @@ static uint8_t phong_params_buffer[MAX_UNIFORMBLOCK_SIZE]; // defined above. typedef struct { bool valid; - sg_shader_stage stage; int slot; size_t num_bytes; hmm_mat4* mvp; @@ -92,7 +91,6 @@ typedef struct { typedef struct { bool valid; - sg_shader_stage stage; int slot; size_t num_bytes; hmm_vec3* light_dir; @@ -119,12 +117,12 @@ typedef struct { // function pointers to code-generated runtime-reflection functions const sg_shader_desc* (*shader_desc_fn)(sg_backend backend); int (*attr_slot_fn)(const char* attr_name); - int (*image_slot_fn)(sg_shader_stage stage, const char* img_name); - int (*sampler_slot_fn)(sg_shader_stage stage, const char* smp_name); - int (*uniformblock_slot_fn)(sg_shader_stage stage, const char* ub_name); - size_t (*uniformblock_size_fn)(sg_shader_stage stage, const char* ub_name); - int (*uniform_offset_fn)(sg_shader_stage stage, const char* ub_name, const char* u_name); - sg_shader_uniform_desc (*uniform_desc_fn)(sg_shader_stage stage, const char* ub_name, const char* u_name); + int (*image_slot_fn)(const char* img_name); + int (*sampler_slot_fn)(const char* smp_name); + int (*uniformblock_slot_fn)(const char* ub_name); + size_t (*uniformblock_size_fn)(const char* ub_name); + int (*uniform_offset_fn)(const char* ub_name, const char* u_name); + sg_glsl_shader_uniform (*uniform_desc_fn)(const char* ub_name, const char* u_name); } shader_variation_t; // a helper struct to describe a dynamically looked up vertex component @@ -298,10 +296,10 @@ static void draw_ui(void); static sg_vertex_layout_state vertex_layout_for_variation(const shader_variation_t* var); static void fill_vs_params(const shader_variation_t* var); static void fill_phong_params(const shader_variation_t* var); -static hmm_mat4* uniform_ptr_mat4(const shader_variation_t* var, uint8_t* base_ptr, sg_shader_stage stage, const char* ub_name, const char* u_name); -static hmm_vec2* uniform_ptr_vec2(const shader_variation_t* var, uint8_t* base_ptr, sg_shader_stage stage, const char* ub_name, const char* u_name); -static hmm_vec3* uniform_ptr_vec3(const shader_variation_t* var, uint8_t* base_ptr, sg_shader_stage stage, const char* ub_name, const char* u_name); -static float* uniform_ptr_float(const shader_variation_t* var, uint8_t* base_ptr, sg_shader_stage stage, const char* ub_name, const char* u_name); +static hmm_mat4* uniform_ptr_mat4(const shader_variation_t* var, uint8_t* base_ptr, const char* ub_name, const char* u_name); +static hmm_vec2* uniform_ptr_vec2(const shader_variation_t* var, uint8_t* base_ptr, const char* ub_name, const char* u_name); +static hmm_vec3* uniform_ptr_vec3(const shader_variation_t* var, uint8_t* base_ptr, const char* ub_name, const char* u_name); +static float* uniform_ptr_float(const shader_variation_t* var, uint8_t* base_ptr, const char* ub_name, const char* u_name); static void init(void) { // setup sokol-gfx @@ -359,42 +357,40 @@ static void init(void) { } // check if the shader variation needs the joint texture - const int tex_slot = var->image_slot_fn(SG_SHADERSTAGE_VS, "joint_tex"); + const int tex_slot = var->image_slot_fn("joint_tex"); if (tex_slot >= 0) { - const int smp_slot = var->sampler_slot_fn(SG_SHADERSTAGE_VS, "smp"); - var->bind.vs.images[tex_slot] = ozz_joint_texture(); - var->bind.vs.samplers[smp_slot] = ozz_joint_sampler(); + const int smp_slot = var->sampler_slot_fn("smp"); + var->bind.images[tex_slot] = ozz_joint_texture(); + var->bind.samplers[smp_slot] = ozz_joint_sampler(); } // fill the pointerized uniform-block structs, a uniform pointer will be null // if the shader variation doesn't use a specific uniform - if (var->uniformblock_slot_fn(SG_SHADERSTAGE_VS, "vs_params") >= 0) { + if (var->uniformblock_slot_fn("vs_params") >= 0) { vs_params_ptr_t* p = &var->vs_params; uint8_t* base_ptr = vs_params_buffer; p->valid = true; - p->stage = SG_SHADERSTAGE_VS; - p->slot = var->uniformblock_slot_fn(p->stage, "vs_params"); - p->num_bytes = var->uniformblock_size_fn(p->stage, "vs_params"); + p->slot = var->uniformblock_slot_fn("vs_params"); + p->num_bytes = var->uniformblock_size_fn("vs_params"); assert(p->num_bytes <= MAX_UNIFORMBLOCK_SIZE); - p->mvp = uniform_ptr_mat4(var, base_ptr, p->stage, "vs_params", "mvp"); - p->model = uniform_ptr_mat4(var, base_ptr, p->stage, "vs_params", "model"); - p->joint_uv = uniform_ptr_vec2(var, base_ptr, p->stage, "vs_params", "joint_uv"); - p->joint_pixel_width = uniform_ptr_float(var, base_ptr, p->stage, "vs_params", "joint_pixel_width"); + p->mvp = uniform_ptr_mat4(var, base_ptr, "vs_params", "mvp"); + p->model = uniform_ptr_mat4(var, base_ptr, "vs_params", "model"); + p->joint_uv = uniform_ptr_vec2(var, base_ptr, "vs_params", "joint_uv"); + p->joint_pixel_width = uniform_ptr_float(var, base_ptr, "vs_params", "joint_pixel_width"); } - if (var->uniformblock_slot_fn(SG_SHADERSTAGE_FS, "phong_params") >= 0) { + if (var->uniformblock_slot_fn("phong_params") >= 0) { phong_params_ptr_t* p = &var->phong_params; uint8_t* base_ptr = phong_params_buffer; p->valid = true; - p->stage = SG_SHADERSTAGE_FS; - p->slot = var->uniformblock_slot_fn(p->stage, "phong_params"); - p->num_bytes = var->uniformblock_size_fn(SG_SHADERSTAGE_FS, "phong_params"); + p->slot = var->uniformblock_slot_fn("phong_params"); + p->num_bytes = var->uniformblock_size_fn("phong_params"); assert(p->num_bytes <= MAX_UNIFORMBLOCK_SIZE); - p->light_dir = uniform_ptr_vec3(var, base_ptr, SG_SHADERSTAGE_FS, "phong_params", "light_dir"); - p->eye_pos = uniform_ptr_vec3(var, base_ptr, SG_SHADERSTAGE_FS, "phong_params", "eye_pos"); - p->light_color = uniform_ptr_vec3(var, base_ptr, SG_SHADERSTAGE_FS, "phong_params", "light_color"); - p->mat_diffuse = uniform_ptr_vec3(var, base_ptr, SG_SHADERSTAGE_FS, "phong_params", "mat_diffuse"); - p->mat_specular = uniform_ptr_vec3(var, base_ptr, SG_SHADERSTAGE_FS, "phong_params", "mat_specular"); - p->mat_spec_power = uniform_ptr_float(var, base_ptr, SG_SHADERSTAGE_FS, "phong_params", "mat_spec_power"); + p->light_dir = uniform_ptr_vec3(var, base_ptr, "phong_params", "light_dir"); + p->eye_pos = uniform_ptr_vec3(var, base_ptr, "phong_params", "eye_pos"); + p->light_color = uniform_ptr_vec3(var, base_ptr, "phong_params", "light_color"); + p->mat_diffuse = uniform_ptr_vec3(var, base_ptr, "phong_params", "mat_diffuse"); + p->mat_specular = uniform_ptr_vec3(var, base_ptr, "phong_params", "mat_specular"); + p->mat_spec_power = uniform_ptr_float(var, base_ptr, "phong_params", "mat_spec_power"); } // create shader and pipeline object, note that the shader and @@ -495,11 +491,11 @@ static void frame(void) { // update uniform data as needed by the current shader variation if (var->vs_params.valid) { fill_vs_params(var); - sg_apply_uniforms(var->vs_params.stage, var->vs_params.slot, &(sg_range){vs_params_buffer, var->vs_params.num_bytes}); + sg_apply_uniforms(var->vs_params.slot, &(sg_range){vs_params_buffer, var->vs_params.num_bytes}); } if (var->phong_params.valid) { fill_phong_params(var); - sg_apply_uniforms(var->phong_params.stage, var->phong_params.slot, &(sg_range){phong_params_buffer, var->phong_params.num_bytes}); + sg_apply_uniforms(var->phong_params.slot, &(sg_range){phong_params_buffer, var->phong_params.num_bytes}); } sg_draw(0, ozz_num_triangle_indices(state.ozz), 1); @@ -640,31 +636,31 @@ static void fill_phong_params(const shader_variation_t* var) { // type-safe helper function to dynamically resolve a pointer to a uniform-block item, // returns a nullptr if the item doesn't exist, asserts if the type doesn't match -static uint8_t* uniform_ptr(const shader_variation_t* var, uint8_t* base_ptr, sg_uniform_type expected_type, sg_shader_stage stage, const char* ub_name, const char* u_name) { +static uint8_t* uniform_ptr(const shader_variation_t* var, uint8_t* base_ptr, sg_uniform_type expected_type, const char* ub_name, const char* u_name) { assert(var && base_ptr); - int offset = var->uniform_offset_fn(stage, ub_name, u_name); + int offset = var->uniform_offset_fn(ub_name, u_name); if (offset < 0) { return 0; } - assert(var->uniform_desc_fn(stage, ub_name, u_name).type == expected_type); + assert(var->uniform_desc_fn(ub_name, u_name).type == expected_type); (void)expected_type; return base_ptr + offset; } -static hmm_mat4* uniform_ptr_mat4(const shader_variation_t* var, uint8_t* base_ptr, sg_shader_stage stage, const char* ub_name, const char* u_name) { - return (hmm_mat4*) uniform_ptr(var, base_ptr, SG_UNIFORMTYPE_MAT4, stage, ub_name, u_name); +static hmm_mat4* uniform_ptr_mat4(const shader_variation_t* var, uint8_t* base_ptr, const char* ub_name, const char* u_name) { + return (hmm_mat4*) uniform_ptr(var, base_ptr, SG_UNIFORMTYPE_MAT4, ub_name, u_name); } -static hmm_vec2* uniform_ptr_vec2(const shader_variation_t* var, uint8_t* base_ptr, sg_shader_stage stage, const char* ub_name, const char* u_name) { - return (hmm_vec2*) uniform_ptr(var, base_ptr, SG_UNIFORMTYPE_FLOAT2, stage, ub_name, u_name); +static hmm_vec2* uniform_ptr_vec2(const shader_variation_t* var, uint8_t* base_ptr, const char* ub_name, const char* u_name) { + return (hmm_vec2*) uniform_ptr(var, base_ptr, SG_UNIFORMTYPE_FLOAT2, ub_name, u_name); } -static hmm_vec3* uniform_ptr_vec3(const shader_variation_t* var, uint8_t* base_ptr, sg_shader_stage stage, const char* ub_name, const char* u_name) { - return (hmm_vec3*) uniform_ptr(var, base_ptr, SG_UNIFORMTYPE_FLOAT3, stage, ub_name, u_name); +static hmm_vec3* uniform_ptr_vec3(const shader_variation_t* var, uint8_t* base_ptr, const char* ub_name, const char* u_name) { + return (hmm_vec3*) uniform_ptr(var, base_ptr, SG_UNIFORMTYPE_FLOAT3, ub_name, u_name); } -static float* uniform_ptr_float(const shader_variation_t* var, uint8_t* base_ptr, sg_shader_stage stage, const char* ub_name, const char* u_name) { - return (float*) uniform_ptr(var, base_ptr, SG_UNIFORMTYPE_FLOAT, stage, ub_name, u_name); +static float* uniform_ptr_float(const shader_variation_t* var, uint8_t* base_ptr, const char* ub_name, const char* u_name) { + return (float*) uniform_ptr(var, base_ptr, SG_UNIFORMTYPE_FLOAT, ub_name, u_name); } static void draw_ui(void) { diff --git a/sapp/shdfeatures-sapp.glsl b/sapp/shdfeatures-sapp.glsl index 3a9bc4e5..81e4c23e 100644 --- a/sapp/shdfeatures-sapp.glsl +++ b/sapp/shdfeatures-sapp.glsl @@ -49,7 +49,7 @@ void skinned_pos_nrm(in vec4 pos, in vec4 nrm, in vec4 skin_weights, in vec4 ski @block light_utils #if defined(LIGHTING) || defined(MATERIAL) -uniform phong_params { +layout(binding=1) uniform phong_params { #ifdef LIGHTING vec3 light_dir; vec3 eye_pos; @@ -82,7 +82,7 @@ vec4 phong(vec3 pos, vec3 nrm, vec3 l, vec3 eye, vec3 lcolor, vec3 diffuse, vec3 @end @vs vs -uniform vs_params { +layout(binding=0) uniform vs_params { mat4 mvp; mat4 model; #ifdef SKINNING @@ -96,8 +96,8 @@ in vec3 normal; #ifdef SKINNING @image_sample_type joint_tex unfilterable_float @sampler_type smp nonfiltering -uniform texture2D joint_tex; -uniform sampler smp; +layout(binding=0) uniform texture2D joint_tex; +layout(binding=0) uniform sampler smp; in vec4 jindices; in vec4 jweights; @include_block skin_utils From 2053f5e9d42bcceeda3f8be10eb9f5c09c256304 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 26 Oct 2024 19:20:42 +0200 Subject: [PATCH 33/36] add new shared-bindings-sapp sample --- fips-files/verbs/webpage.py | 1 + sapp/CMakeLists.txt | 14 +++ sapp/shared-bindings-sapp.c | 223 +++++++++++++++++++++++++++++++++ sapp/shared-bindings-sapp.glsl | 63 ++++++++++ webpage/shared-bindings.jpg | Bin 0 -> 23612 bytes 5 files changed, 301 insertions(+) create mode 100644 sapp/shared-bindings-sapp.c create mode 100644 sapp/shared-bindings-sapp.glsl create mode 100644 webpage/shared-bindings.jpg diff --git a/fips-files/verbs/webpage.py b/fips-files/verbs/webpage.py index ad164f73..55e031f5 100644 --- a/fips-files/verbs/webpage.py +++ b/fips-files/verbs/webpage.py @@ -71,6 +71,7 @@ def get_build_config(api): [ 'primtypes', 'primtypes-sapp.c', 'primtypes-sapp.glsl'], [ 'uvwrap', 'uvwrap-sapp.c', 'uvwrap-sapp.glsl'], [ 'mipmap', 'mipmap-sapp.c', 'mipmap-sapp.glsl'], + [ 'shared-bindings', 'shared-bindings-sapp.c', 'shared-bindings-sapp.glsl' ], [ 'uniformtypes', 'uniformtypes-sapp.c', 'uniformtypes-sapp.glsl' ], [ 'blend', 'blend-sapp.c', 'blend-sapp.glsl' ], [ 'sdf', 'sdf-sapp.c', 'sdf-sapp.glsl'], diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index 51eb6862..e6539d75 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -300,6 +300,20 @@ fips_begin_app(dyntex-sapp-ui windowed) target_compile_definitions(dyntex-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() +fips_ide_group(Samples) +fips_begin_app(shared-bindings-sapp windowed) + fips_files(shared-bindings-sapp.c) + sokol_shader(shared-bindings-sapp.glsl ${slang}) + fips_deps(sokol) +fips_end_app() +fips_ide_group(SamplesWithDebugUI) +fips_begin_app(shared-bindings-sapp-ui windowed) + fips_files(shared-bindings-sapp.c) + sokol_shader(shared-bindings-sapp.glsl ${slang}) + fips_deps(sokol dbgui) + target_compile_definitions(shared-bindings-sapp-ui PRIVATE USE_DBG_UI) +fips_end_app() + fips_ide_group(Samples) fips_begin_app(mipmap-sapp windowed) fips_files(mipmap-sapp.c) diff --git a/sapp/shared-bindings-sapp.c b/sapp/shared-bindings-sapp.c new file mode 100644 index 00000000..bcf95ce4 --- /dev/null +++ b/sapp/shared-bindings-sapp.c @@ -0,0 +1,223 @@ +//------------------------------------------------------------------------------ +// sharedbindings-sapp.c +// +// Test/demonstrate how to share a common sg_bindings struct between +// different shaders using explicit bindslots, and also test that +// gaps between bind slots work. +//------------------------------------------------------------------------------ +#define HANDMADE_MATH_IMPLEMENTATION +#define HANDMADE_MATH_NO_SSE +#include "HandmadeMath.h" +#include "sokol_gfx.h" +#include "sokol_app.h" +#include "sokol_log.h" +#include "sokol_glue.h" +#include "dbgui/dbgui.h" +#include "shared-bindings-sapp.glsl.h" + +#define RED_CUBE (0) +#define GREEN_CUBE (1) +#define BLUE_CUBE (2) +#define NUM_CUBES (3) + +static struct { + float rx, ry; + sg_bindings bind; + sg_pipeline pip[NUM_CUBES]; + sg_pass_action pass_action; +} state; + +typedef struct { + float x, y, z; + uint32_t color; + int16_t u, v; +} vertex_t; + +static hmm_mat4 compute_mvp(void); + +static void init(void) { + sg_setup(&(sg_desc){ + .environment = sglue_environment(), + .logger.func = slog_func, + }); + __dbgui_setup(sapp_sample_count()); + + // pass action for clearing the framebuffer + state.pass_action = (sg_pass_action){ + .colors[0] = { .load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.0f, 0.0f, 0.0f, 1.0f } }, + }; + + // a cube vertex buffer + vertex_t vertices[] = { + // pos color uvs + { -1.0f, -1.0f, -1.0f, 0xFFFFFFFF, 0, 0 }, + { 1.0f, -1.0f, -1.0f, 0xFFFFFFFF, 32767, 0 }, + { 1.0f, 1.0f, -1.0f, 0xFFFFFFFF, 32767, 32767 }, + { -1.0f, 1.0f, -1.0f, 0xFFFFFFFF, 0, 32767 }, + + { -1.0f, -1.0f, 1.0f, 0xFFDDDDDD, 0, 0 }, + { 1.0f, -1.0f, 1.0f, 0xFFDDDDDD, 32767, 0 }, + { 1.0f, 1.0f, 1.0f, 0xFFDDDDDD, 32767, 32767 }, + { -1.0f, 1.0f, 1.0f, 0xFFDDDDDD, 0, 32767 }, + + { -1.0f, -1.0f, -1.0f, 0xFFBBBBBB, 0, 0 }, + { -1.0f, 1.0f, -1.0f, 0xFFBBBBBB, 32767, 0 }, + { -1.0f, 1.0f, 1.0f, 0xFFBBBBBB, 32767, 32767 }, + { -1.0f, -1.0f, 1.0f, 0xFFBBBBBB, 0, 32767 }, + + { 1.0f, -1.0f, -1.0f, 0xFF999999, 0, 0 }, + { 1.0f, 1.0f, -1.0f, 0xFF999999, 32767, 0 }, + { 1.0f, 1.0f, 1.0f, 0xFF999999, 32767, 32767 }, + { 1.0f, -1.0f, 1.0f, 0xFF999999, 0, 32767 }, + + { -1.0f, -1.0f, -1.0f, 0xFF777777, 0, 0 }, + { -1.0f, -1.0f, 1.0f, 0xFF777777, 32767, 0 }, + { 1.0f, -1.0f, 1.0f, 0xFF777777, 32767, 32767 }, + { 1.0f, -1.0f, -1.0f, 0xFF777777, 0, 32767 }, + + { -1.0f, 1.0f, -1.0f, 0xFF555555, 0, 0 }, + { -1.0f, 1.0f, 1.0f, 0xFF555555, 32767, 0 }, + { 1.0f, 1.0f, 1.0f, 0xFF555555, 32767, 32767 }, + { 1.0f, 1.0f, -1.0f, 0xFF555555, 0, 32767 }, + }; + state.bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){ + .data = SG_RANGE(vertices), + .label = "cube-vertices" + }); + + // create an index buffer for the cube + uint16_t indices[] = { + 0, 1, 2, 0, 2, 3, + 6, 5, 4, 7, 6, 4, + 8, 9, 10, 8, 10, 11, + 14, 13, 12, 15, 14, 12, + 16, 17, 18, 16, 18, 19, + 22, 21, 20, 23, 22, 20 + }; + state.bind.index_buffer = sg_make_buffer(&(sg_buffer_desc){ + .type = SG_BUFFERTYPE_INDEXBUFFER, + .data = SG_RANGE(indices), + .label = "cube-indices" + }); + + // create 3 textures, shaders and pipeline objects + for (int i = 0; i < NUM_CUBES; i++) { + int img_slot, smp_slot; + uint32_t color; + const char* label; + sg_shader shd; + switch (i) { + case RED_CUBE: + img_slot = IMG_tex_red; + smp_slot = SMP_smp_red; + color = 0xFF0000FF; + label = "red"; + shd = sg_make_shader(red_shader_desc(sg_query_backend())); + break; + case GREEN_CUBE: + img_slot = IMG_tex_green; + smp_slot = SMP_smp_green; + color = 0xFF00FF00; + label = "green"; + shd = sg_make_shader(green_shader_desc(sg_query_backend())); + break; + default: + img_slot = IMG_tex_blue; + smp_slot = SMP_smp_blue; + color = 0xFFFF0000; + label = "blue"; + shd = sg_make_shader(blue_shader_desc(sg_query_backend())); + break; + } + uint32_t pixels[4][4]; + for (int y = 0; y < 4; y++) { + for (int x = 0; x < 4; x++) { + // make a checkerboard + pixels[y][x] = ((x ^ y) & 1) ? color : 0xFF000000; + } + } + state.bind.images[img_slot] = sg_make_image(&(sg_image_desc){ + .width = 4, + .height = 4, + .data.subimage[0][0] = SG_RANGE(pixels), + .label = label, + }); + state.bind.samplers[smp_slot] = sg_make_sampler(&(sg_sampler_desc){ + .label = label, + }); + state.pip[i] = sg_make_pipeline(&(sg_pipeline_desc){ + .shader = shd, + .layout.attrs = { + [0].format = SG_VERTEXFORMAT_FLOAT3, + [1].format = SG_VERTEXFORMAT_UBYTE4N, + [2].format = SG_VERTEXFORMAT_SHORT2N, + }, + .index_type = SG_INDEXTYPE_UINT16, + .cull_mode = SG_CULLMODE_BACK, + .depth = { + .compare = SG_COMPAREFUNC_LESS_EQUAL, + .write_enabled = true, + }, + .label = label, + }); + } +} + +static void frame(void) { + const float dt = (float)(sapp_frame_duration() * 60.0); + const float dw = sapp_widthf(); + const float dh = sapp_heightf(); + + state.rx += 1.0f * dt; state.ry += 2.0f * dt; + + const vs_params_t vs_params = { .mvp = compute_mvp() }; + + const float vpw = dw * 0.333f; + const float vph = vpw; + const float vpy = dh * 0.5f - vph * 0.5f; + + sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() }); + for (int i = 0; i < 3; i++) { + const float vpx = dw * 0.5f - 1.5f * vpw + i * vpw; + sg_apply_viewportf(vpx, vpy, vpw, vph, true); + sg_apply_pipeline(state.pip[i]); + sg_apply_bindings(&state.bind); + sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params)); + sg_draw(0, 36, 1); + } + __dbgui_draw(); + sg_end_pass(); + sg_commit(); +} + +static void cleanup(void) { + __dbgui_shutdown(); + sg_shutdown(); +} + +static hmm_mat4 compute_mvp(void) { + hmm_mat4 proj = HMM_Perspective(60.0f, 1.0f, 0.01f, 10.0f); + hmm_mat4 view = HMM_LookAt(HMM_Vec3(0.0f, 0.0f, 4.0f), HMM_Vec3(0.0f, 0.0f, 0.0f), HMM_Vec3(0.0f, 1.0f, 0.0f)); + hmm_mat4 view_proj = HMM_MultiplyMat4(proj, view); + hmm_mat4 rxm = HMM_Rotate(state.rx, HMM_Vec3(1.0f, 0.0f, 0.0f)); + hmm_mat4 rym = HMM_Rotate(state.ry, HMM_Vec3(0.0f, 1.0f, 0.0f)); + hmm_mat4 model = HMM_MultiplyMat4(rxm, rym); + return HMM_MultiplyMat4(view_proj, model); +} + +sapp_desc sokol_main(int argc, char* argv[]) { + (void)argc; + (void)argv; + return (sapp_desc){ + .init_cb = init, + .frame_cb = frame, + .cleanup_cb = cleanup, + .event_cb = __dbgui_event, + .width = 800, + .height = 600, + .sample_count = 4, + .window_title = "shared-bindings-sapp.c", + .icon.sokol_default = true, + .logger.func = slog_func, + }; +} diff --git a/sapp/shared-bindings-sapp.glsl b/sapp/shared-bindings-sapp.glsl new file mode 100644 index 00000000..3bf53047 --- /dev/null +++ b/sapp/shared-bindings-sapp.glsl @@ -0,0 +1,63 @@ +@ctype mat4 hmm_mat4 + +@vs vs +layout(binding=0) uniform vs_params { + mat4 mvp; +}; + +layout(location=0) in vec4 pos; +layout(location=1) in vec4 color0; +layout(location=2) in vec2 texcoord0; + +out vec4 color; +out vec2 uv; + +void main() { + gl_Position = mvp * pos; + color = color0; + uv = texcoord0 * 5.0; +} +@end + +@fs fs_red +layout(binding=0) uniform texture2D tex_red; +layout(binding=8) uniform sampler smp_red; + +in vec4 color; +in vec2 uv; +out vec4 frag_color; + +void main() { + frag_color = texture(sampler2D(tex_red, smp_red), uv) * color; +} +@end + +@fs fs_green +layout(binding=2) uniform texture2D tex_green; +layout(binding=4) uniform sampler smp_green; + +in vec4 color; +in vec2 uv; +out vec4 frag_color; + +void main() { + frag_color = texture(sampler2D(tex_green, smp_green), uv) * color; +} +@end + +@fs fs_blue +layout(binding=4) uniform texture2D tex_blue; +layout(binding=2) uniform sampler smp_blue; + +in vec4 color; +in vec2 uv; +out vec4 frag_color; + +void main() { + frag_color = texture(sampler2D(tex_blue, smp_blue), uv) * color; +} +@end + +@program red vs fs_red +@program green vs fs_green +@program blue vs fs_blue diff --git a/webpage/shared-bindings.jpg b/webpage/shared-bindings.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8ea6c9d1a69d2a2f9dd00d10d5b4531bd284e85c GIT binary patch literal 23612 zcmd43byOTr(?2@P;_i}Q!QFxrAh>&g;K5m7aZQkf1PGp>2^uVfV8LC21`i(G-4U5f!L7Wm=JNT@6%sAygWRgK>tYpg!Gqm)SFM>zc31E4(gvgh{|_KN=HUX z2~p};x>;L0x!XB=0Kn}M9!yC_#!ORNLtaT$4gevn!&@+SadAY#2LPy(hnu#7H0@IZ zLt3;A029Ck2muZN&)m}8MM_gs^|#bN%RBr}Ivv0B699~G-pTrh{(prCtgPKF5nk3r za9dcpTS5`I0^ytnOBXkU&ZsU3I=#1t%N>qKU}86ff(ZQO4%_~L8}6{hANc2Qo+sKe z2%Z&0XJVV1yV(K&E(}4Z^|G`@$ic%$U>+wch!X-oMqmjj)Y%GwUm`FIf(Owi-kp45 zi+{mj@Wi?irR>h z7~!`S2WOQ#jE%r>Cku5A1V)S|BxDG}x<4_gou{HM0weg5SS;OT5WWOR5%`h2qt4xc zxua`anaipmFeL)pI611{_5B@BkPSrsjtAjCqz@1er6&kXj=*26-Q{%tuw>TUpD>Auz&rWOQpM z-8*{`bYyZD59zzM5OtB+TpWMjCwFvdYe$7UIvoN(are^stFD)a+mkywLQmun7Z1%l zA0qTbPPR8!)2*a7jQ!Gxc^;G`uA09zzadY{txOM4e~eb4|$w`&F>mszoj?;Ylv2% zfC}Jwp)BmFW!zqREf$E=iJ^yNv z7Voe6sB);XsEVlasI18MkR_1CkW~@K$B4{_EQ~DjmmUA`qpYC}p)8?{p)8=*Ijv zm;W3yw1^S&hn{!i!=0yqXOrjZ4=EnjJ|2iM4#+sW__{%C?L26u5Hp4~t&)=^7Y8jL z4T;?1|WxAp(fl$!ydR0#1%sQrh=A`AcoSOD;& z*3#3>>koOzcLfUK$$^Ks`zQcvfF58$*uw`10%E{pKn_p_G=L|70bq(4uXc!W?gn@R ze!wdr1c(6M0SQ1dkO5=^Uw|T@45$VgfbT#j&&yn6BMI(Jc%0encszUmX z)QdERw1BjYbOHvzSYT4{128987%T(U02_jBz;56Ga5y*-oCPih*CG0O1iS#=0iPqI zA`>CgB6A`}up+W9vL&)BasYB9ax(H4@Azv5IktNr1_WDUSIB(;o8`<_FAT%nr;M%p)u;EIKR^EG;Yu z)=R7pSl_UIU@c;uV-sStVas3}V|!vpW9MPFU{7Kn;o#sf;XKAM#PPt1#>vNN!M;4$J!;hEw+$4kU3#~Z}k!NjA+jWTO_W2_L9|MY zO3X~GL~KtSL0m*UKnx=xB;hB~Bk>_gA!#I8AO({$kt&folE#phk&csIkWrCIky(?4 zkrk5-lbw;@Cx1+CO&(5OLOw=*K|xC)N8v#6o}!v!_8#&*wtHIlyziyo>$tabpZLDm zearjd_si~2Q6f>YQEF4Zpv}2 zLK9EZOtVExLMuhEviCFE7+4dSiiJ>+BKv*b(R8-0lLQ2t@y z!KqbIYK#Ixn#LHc{+Jp z`2u;Ef`Gycg%(8=MHR*OiW5pyN|s9bN-$+1Wq;*%6>Jq9m1LDARW?;O)jBmKHD$Fp zwHb9rbtm;|4M0OlBTi#hlUdVMvtA2TOH(UFYfYP1+fTbohe*dv=c~@?6X_>0Po{NQ zbUk%j_3-qJ_44)3^kwy9^%tIUKlOjwYjDp1Vo+m_j&M3iX)mXqd#CY6< z*~G`B+w`8PqiLfVo|(B>`7@Mf`p>>TyE4}>&oV!;P_jt1fLY2|CRuJ<~bm%i^trMY> zgHyXRwX=`&kPEv@h|7YjsB3~N%uU7ZvpdM$#J$FY7_rdr^JMW1_FVLm@JjK5d+T|Z z`w;jz`Skg+`G)zfKbL==`vUoe<%?Fo2Y#>o7X79CGXp>Y76Gk+^nq^zS6?c;{PGI( zmBXw4AfBMupySv2uj}4Wy?Oa&IandMAOttWEo358EHvXS@>|H;fv|^RAH#0Kt-^aE zcp?%bt|BcXd!l%wK1AI{+e8n<2*#wpLw)D;Zv4IE`!BHsvCm_d6DUG%G9vbvox!;;q=Gp#Tir?5g8Ys zAfJ9^Dr8n=F=ZuYqh@<$ujT0Fbma=?=6}BTIpXtmo>Sh!7ws?Y`9k^mUn#%F6d)CN z7Hk$87yc}gEvhNzEY2(;Es6LBeDnOaRr;)SyiBF6wOqKoxPq}FwUVeZyb4t1TLr7O zt6r!vs2QqNu5GOotE;T%s?Te9(2&wd(iqc(+4QFAw)uJUNsCL%&Uf4I%dKXu(``@N zM%%U82Rc+bess!rwslE$HUAL*(az2d%dwfbfaXDxA^W<7s{Z=+#Te)H#+(bnp= z%l73?$S%Qd>K@Bp#s1^{KG;*(>VezA?P25*#Zlfd|8eVy=E>YC^z`y998LlMaxQ${ zb)kQ;e(8OMcJ<+!^}6mxdbEpQjzBiSJ0^TRvQ8~|WK$j37V08JbKcp?HI zJ$(3g{!`o^ap&C$Dk845NfD&K^#0EhVa>ybh{e-?l(*Bs8$_6Y zmyi&@U?e0YFftgCkWrBD63Txh#B7a7=ywU@@ASJi5)v}v7XuXq^>6zBHMpHc>{HO* zwg3d^AP*z}459;&2tZ&0&}};?3*l3g-wOWaRsf+VG72ghItC^dK7a%QgOQNICHn6(db->`Ch%xM5mW7{Z67i1Y>w;;TD8}NlHdeagULSnT3^& zUqDbuSVUAtR!&|)QAt_niLRbLVwq@ZWo=_?2eEhe@bvQb@qPaKO>ju)+pzH1xcG#` zqz@mHv$At?Kj(eP|5{dFQCU@8Q(M>C*51+C^`pCIcw}^JeB#&S)Z)_e%Iezs#^%<+ z;nDHQ=^6a|0$c8B2hS@_-kWP)ZBU+?9xq z?-e?+^!v=x?-=wCwP7R{ZbO))4E&3X2X`j@w&?%PprHR(7X59|-}c;20oY&=qQk%h zfFy7WNM5jHy~OC5lxONG*Bn6isEP!y9y?Y?JL5`E;93p(a-0iBju z)>OTRu5>gf)^dy=T)m-;RB~FixY=_ZfG~O_lQsm&noIVS^FQn09hfa&#HY7?={=Ev zy;WHkXqqvxc}CJ8)>}NRZRmXq2pnD$RSSixEfzhWQ5`W<%$mP8pKg71VHuqr-XGg@ zNS^3xVJ&}I_+*#<*Rf=qpKNn^5MJ^UpEqnE2?4TmhQ_@r#r~yzS$kDaN8L zX)Q<{Zvl`F`*h8WI2sj-hk|(QoaDsGwUJIw!D19zu4t5B^I{{vsZo>8I#rIgMbqor z@X`5t6>_3aofI;CWWrMii3z!pD{h&JU)_DYWy0rg#G&J?(ZorUHK&KUUL54uevu!3 z?3(ZnTIMeK>iY2(mh5a5J! zjL)_HDw%S6`uTz0Mh8|l57p^9QpF9GAOBc`r-$0R;P$8Hjw5fGYQT)K*x9iyxau=_ zMgH}9w}81_9ZJJT&|)ME9VtrN-Il6hkXGWA}x-PfB8!sOc}7_v{?F zdvEZZ$HygX#RmOD_r6@2C7q0%{5sbToE+?=TT*dgFAzzK@3jk(#+i|Eq6Sy@I5+SK zt-6U9q{c0T#@w5m+Exv@zma#Yns`L7a6i(T!Hea6%_AtYc)_mGHQxaz7v?YYgvp!? zjp}x(*+?m;ip!Abk#&<`82P$nvazw0FNCSq+8e8A?t#iCbX<|km``D43-s)b>}7O^ zv)Jo%n#9}=crRy0?^Ux#!pZ9Sl%H1kh;#i_bMc%Rs+k`-X3MGARel*(#lY(sDQ`_oA3=|na_g^iE=6U zRhPX^@)MQs^<--*&u@XTiWcZH#eLbVxwfYj)#=|0_usF~Vxb?{99iL$S(*&y%`ks_ z*=E1~2$y$OBWkO_{kvat-nFm2m(J2w#8UW8bIGQCfGzoqn>?Db(?~R$@-^)k$MMJ# z#m%&1={({dC!`zndy9T<6}(axdpdUZtc<~tx63RE^>T6j741k=%W%c7!hIDMUuzzY z=q}8viHARIf~-uxHQbldmN2cH*NEEO?AHj~?!DNl6noI|b0nE&V)5FSCL>;dI=T9L zOz1@2i_LLT@8^!EE#-aZgbEe5WCXMQPSJ&+wrL~`o!38U!f-)LO)+c(cFRPk&yBLh zXQ~Bq!!;&1%~`U-PhwONN8mp*+gN3R#t~5^n$D(1Mfr=@sYqzBb>tZPjVD?1$k0;P zH zh(WLR&^tW1-aKesz+0pw*lYHB9iqLV(EoFJ)#=wGY?{udOM=A^eXrQqk-96cCNrxggE8R+fuM#1hQrTbww z_uL~qd)N`jVA7dK^-aYsK!4nXzc8lj?@V5VGd}24+e!_XZy*rX@R%+DO**#Xwe_7hZ z8uakPheh3n$!WV~=2zFO#fSFZ5uY{KaFhpAe6c7Z-@1Q)GD$=0CXsNsH9v83b~;N_ zRxwswIqBse`@(b{lFZ6o=cluD za=t>k(D!m)qFh)Xt*{@q0G8AI6R`_jf(7OT!DCNN40@Jme?1mLU&5a3Qnpfqpr%*r zS>FO>E9R@+$Pnih>n;NZ#)Ay0C#TaFyVuTjrxt(T3Yy9{cP~YB6IuPd* zf1aYs?!4V z8CoM}`=t^hO=7OaW zOy)(pye7`eAM4abYx^qtSRl8#1Wq%4nLr`H$XKvheTBj}qOf||96WPL00rw!aM8ZE z9C0)lOXT~(SmPOn?M;X@je85!JpO^q>G$*3jMwq5nX=Dk4T4QG?ESsi!JWj5^h_x6 za7sw3%Bli?_dTQ(q-?+4$`A>yp!+e&4jaOrFXEEYGu(F9-48QJzINzk%CQ>?Jr^j5 zt1M1T4HqZW8&Q)EXDP{&WcgpQ+9@9BimzsDXQDIUffn^^C>v)l$AJv5w)86a7Ql?< za~%)7S$eN+0a;9Y>J_zm}4pO{I>g2g7zdcU}-{p=0D&)(^W0c)Wh zXMRZ~(kp^q;}>d4ua7@6LGL|nPnP(6PhQbPhAO&i=l!|0=2d-)i|~R)0i;bEs&{cX z|KnyZoCcn@$^=xU+ ziG{sUkiaI?M}&l%J+V?JJVr|HD>$%ifwu-%$nozxm(+-P8YWON**a1xKT!JH?FXX{mWVo z&a6^FwEo8i#ZEIl`raN=U5~Uli=4UP)Qx&QMg>Y>L!;GO06YPEQNYjhG|gG5>X3sg z_gmTFWb6~~x)J6mDLj;p%P!(~OaoqBgTrqrOa*L%%hG@%iShP@1}Dr z<8gC7n=yk$7HkUGjLhu4$k_cIr|KG9A<6v>?%Ozg&IyldS6QjbNRbP$4<=Rt-THEG z&c4KLoW|%PuTrc=EQ4AD&b=k9zQohSz8(e%v);oKO77<)&Yqiy8UMR!fa#%n-|)Qc z#Vruj{5df)WNXd0I3_f4TrsCQrq6_8&$7BPgu{thofH#0Gs)#}PU}qGM{=_AF#d0Er!U*_Gkjx^*zac?7x>$BX&NM-Sz#1zh`K2~*ht|nc6!w3p*_#G zOyP))si)2*IC61PeqtJM6NR_vTA6fm=06W7-L{`lPCsf5U^sYFRn~zPdVIfMnss<~ zkF)(KK4^Bg^8P0iORuzt7@Fj0PfB_(UuJndSpdH}reZ&CTk^OC2pU8#Md1ZcVwCRb zCcPCfVVXKUs1)JW-e`3yUaqRr0loEglV^^n?^-QMs^F_fx#}*dTVN5wth{eD>3FOp zk+d~`l6i7$UVPl=JiQUHk@MJ_S5qjkSFuavYylJ5zN`0gNQmthvvXcwXJo|y9Ro)8W!}D3 z06EEJK}3U7<&THpxhF1gW*@YZ z>p;^Wf<~EVJEkjs-I3l-^TAj@w#ci;-iJ2veEKP2t4;2kM)H!o#xj!`DO7~v8B)Np zy8HW>MWoMLb3+%t(BXOPqEqkcwtgCqfX4wAmg}oG*o*OjWn^FS*g0hSEQqNKc|P3& z4UJMcl3O9O{rG3Ubj}G`j92)+oi|4_kV|U28|uVG$uTyom8_1lspKwQHG9JZ%uOYa z4c4rMqlB01)3UK&ywIobvft)z8o`a-vHVrm0}|`CwU6cP5uYG{mKsXV*;q`P4UO}hc!?)%ZtYI?OruaeE}sHjutw< zZxZi&9rrpqtLb(6vi3p$=a?KHW-SSFSU?K4rP_gXlj%Zdm{V1G2(P0vpES=EsWB+7 zYf&V}I;4FxTP-JRwt7|RY@1c$y%}By6<5sh>o@E={d|RjLIh|c13dM9O~X#q`?aU6 z+94wa?5v1MsVKLXd1b_p5mp`EVBoNL3xw#X6#B@Y1P*(K{hDQr+=_~~zMks?LOEla zC%}^9slsY65mhH^DuqeURQr%E-cSFzi7Y6$^nvw66z3-s{iWShwxo+E+QcC) zKkBD=tDOi(AouaKB1wM~Z`h8JWN?mEYz7KlRa}ZVkYy_jPQbQtxO~1wbE*$FrdnFf zmq*2U@@na=1+&W+dcLkbFfLvD@m0>W#H46*sAI)tO3W1ZQoQ{7E-&32T(h%`ykU?FxwV%`LJ#Xf z4{o#S0S)XW#Jlc|B#DiYKl7qZp{31B-f#!21U;%;OKr`{3GL`7+{U=&gIHg_V*MR|8_EnFzd)5Vm-=ZhjXpY@}8zp!v@M~ke z%Z&>daxQEfO#h2IfonQVUO!}rIoYmr^3ywCQa8Lh7jdzdqBkTv7on|CG2H|I&rz_Z z*-9Gpxe6)I-qe1Qg2hB*v0!6`3MeJcJeO~=m1alzdWvX@4ag?54$jZE<2+?s;(_(h+k9K`$BJsCI!qS`(Z zI>S$DI|WzDY~Q~+*uNs0mxX5^%rBIL2cT^~Zzs#Z;-CH^AW5`|VlDciO5~%}2m^i} z7DbWJBlZwR46~1&0oRR9qfOj!qgDw_IL#6&+#43!ria)v{bfet=X&l!Mw83%?zh^=tZZBCb*_sh1Avx^#;PT<@tk1+^dP85`;M)=g ze`OrpReDCP?Cb9_E4V#?BoE4i=pQxT0cdan>M zm?P+L&2A_6h2*32CS$x7oEl3^Jo>#NzO(i@@q@hZ8{(Vp0P;%MYlu7aU_2v#x(g-a z?T$0Wg2Odu))5n*sF5nYi=}kzN*t5mVLHJ9^XrO?H-}ef*WsL%R5FWBwVbn6rAzrX z@$){)hZf&wrqoUi7Q<2AYBYui_e$(6P>Vj2iOS1+Sf-+6cu)sb&$$JX=dm9+JCHyb z3f+bWN?r7tx}Bk1#d#u#sTCcuzOdIHp~5%8%zD;MJv=57LTH(sID(uQ&JLDdLso^7Ki4><->;{oaq} zOoAH{cf9(f%QD_o>Fdqk5Fn$cj)Sd2EMnyy=Kfg>&A+ z>BN}S%GW~$G_hy+MA^zyCdGLraEX2IG-uif)vB^dTE;AFx)evL08O53)^HXZ- z;l-boIC>;QIn&o4zijCBi+7Y7@DLhBDgslo_Vd0+ziCSv>roH-l&F5S2LO=t5zCUl%b&IU}bm+t0POgl3mdV$f&9~E{_B5~J0fs5u2 znsUhy&;77ug*SoLv$XK~MZLoDw|)j+cpEB)i-lB3<|b{PNGEO(Bn0Twapp5CBVY-CR`!L9hE1KwySGcCib%3m zFJC>J`*!062OSHon3MiqHO1=l6>L3)P|NyJ{-ml}7sm(C z;V+lVQEg6WCH5OjLTy-x z5aNZ&hg-mkGJphIN7_;TW0viu_^bW_-?t|sl+SR*MTa6``wU-7*p%F>_HnJgGK`vF z5>F{8Vu9 zBkcFb#vUa}B?~vGS;@h+s9y!xr?i6OoZ^XfJYC=Gt>?=BEW&%9TI^VQXd)V@(IZ|` z+Mdw&!mA>2eFB{fty<=lysZ7V`bD2#2e@h9)V$mcJ3!6^_HBKH0QCs4%UOY&S4y2A zb16zsx8=4Qs+fW1ES(twv{3rZ!8`n#Y!}wVaP(t|jAzqEqEM%zo+k#@x6LoP zD~)dqw@c=~XvvYB8%+JN!~5@-&f&~3 z?0OPs&^v`6>2IK{r4{+aQdHtmPRV53xneNZ!e*PgABNSotm*v zPD}4iamF#=N%ZG@e{@>Fg!`yh|M1;zR}U^`K7Vv7h~lfSnQqW2s7A#_|<{ z*lcUK7fC29(FZMdyN`(r!=obOa5r-Q1uyBSP7aA%ERx_x*(m+7b}^K#xI9smV?nK$ zE2~5*gCxX0*w-xd+$qn&^*Rsgd0?>XIY?w?)WcEX0O8Hu>LqOn9)D~Ry~U@YiTb!j z%z?d~zU^?60A8?+d_*PMvqhh`S>?(-U4a3MB$Uo`m;J;AW<_K1x}Jj9^z6D_RW#33 ztT`8^B^^%LckL&zxaD7(@EhNpm6vHX=5hK*(v#NOeeW@@ic)`$qeM+QR&hCq6-Bhj z*J}$K*kVn*)bgd^=1+;HR?D4tiS!G7xy;e!qNO$hfV+~Ea2DQ+GvkusO;&kewHNqye?1a#xyW~e!^fd^Kpn6uib06P#^FmjS zHeWv>(zuz0J-ja0khl*wW3VxbVA2oOE>CCmrT{>tSUtoC8S%$RG4@6MvlsJYo4X8` z?D9rpN_bnb+NbP3^1TWgiL45W3c4Y=WEHE=D^k|-`jxUpg@*a@XpFbVwQy{gPU11E zr~Fh842^@nP-Sz3e>9RV6nsCjw=O_hOj}W21MfJXTU{SMp?Ys`il?>C!IxIbMbtM{ zMEts6M2M7)>OVYQQ}tI%)Pni zvU|F4Y%8FwrjU^HX_c9ZlT3SXPSdQReWG%7Jf0W-EW0=)s%}dtohH`kBge7E>*U=0 z!|zf!qgs7P!6L{dAKib@`%JaL$`=}C)L@oRuQ*{6K^M)zmCU|S&rKo^6^?F(P%pZv zZR)W|g6hcVY_#--Q9t&)##ocAHxX=~nY4k8~q#{?K6ky~f64n{&ovveMSsP1J2KB{eNOkNwSV|J5z96iw2_ z6D&6_>NvHz*QMfdmQpr6z*l*`y|Ht{>&G*)$L*)U+!iyr-C9IxN;Of$oZi)L2;I%P z1#Iu%-@P$EZ0Je=(F-4*i7?gIRs@Cz5?yH(z#SIm5}>fxZJNftTzSNarw8Acrzuw0 zM%p|n+4*%;9EjhPfoTnfs===f0@%NeF&x-@T*8}5(i~|}TTU~ayWqz0(NL?kyAoTP z_MwY157i1;yf@6LO|kxHS9XTJ#hE)&gJ#l4Oa~_B_xQTNwypve5a#Q^m9R*~Hi=rf zka8lcJIlaz&xl_m4J^CS1FP!Ke0-J8*UZc`Z>#QaR9#Oco|B?}6dUObJJi(+OwBh- zN?Oem+?(4PNmnbf8IHQ4HVkhM#Awi6q*7T-O~=2E$*dm<0BvCeLYMq4ww8P<&9F=> z2zogZ`&}P+hS9S=_{FHj5IG%`Pog6?Qn6v$ws6*RKldQCy%xHj^cddCvAbUJmOFj^ zS;J`PR9~DNA$U0Hj4P>E}`i3~$L||7`>1?fjVksf1DrGuW@Xhc_+UGX~Otlw6^U3=rvq_b4 z(+P%z)f`0(Zamem{U{Dr8;lByn!}qN{HaHTo-<`|jMtfd{>=E8-ZwjXzE6#6ToqL& zp7Yx~IgO=BZs>8u{4~~b$LjEgcP|wpbjNQeJ(o=h=y_!h8KXJG`)4N5)yXu%9mYAFWY?zvt9%=An- zLl4#*!rAppz^dsGH5+2>DWb1po4(4(asFP6_q>Jj>92q#&Df!1=U6T!XMZZ?q2{h! zkuIGiGMbqlK0}G9!_UKW7b0V3{W(lAYxAc)={q;W0o)^8o}VX1G)DJ0%^S@RyO9(- zd1>|;uiNb}A5gS}X#&}+W=RDqdT|4z3?H!3#73dI=SB(Vn#gAH(Zqn59yHKnl^pRx z5c0F}T-(UVdeSk_)cS*&c}Si@nM$?#cR6DHEN?`F^Z4JHiaEr3B(stGOV7_>Ae&ol zau3Z>KT`>Ng3U}z3K=W*G$M$xOKgN({Hd#{NtUsS!`JWpEXChnV$OT7o%>#GkE|=| zIX~2tPqu1ftb0~LzV3F^<09GGJdBr>?r`slQwK}9Kqud(a2bQCHmNeBaaYha3e)v0 zw$koNwztZPdyiLPM$(DXT(f8T?$X|zh)v2)oulv}gHC0qgh|ZqG%P=vy`Y@IrM*gT zA%l++V3rws1>k$dtRnsdYcf1)eW?MiybdMWxpIW{e~OFT56Z z9laJjPfts>?v2*c>r8tYpT*``Wmg(p&UF$*gojY4q}Cdnn`Pj!jGD5&`2Bvbxj0?# zIZAoHn&UkUjDKCFBHK6fJm=cZo@Y@%aW{GEZQ!SQkMr++IU5h%#0=?g$ zCU3C6xnQoGvrPs4HMC`a#EHYMExh&X#!k}><_9=71bp>a!7z_)PZ(#SVXA3NoRjXiQw zdc*EN9V2ge_)N)0;#pM7X2v4DIEpgil7HeUTKC~7c}WV+8h7TI_d zIKIlN_l)j{NmsF4j}MhgK%Eo(hDJ_3Gg8Q)!p*HvUd=Zpp=?ZWxDqs%hNk>w*r0`> zsouNM;N=m=#5#eHSqm$&S3#?Zb`NTztdtdbFyu_wM3x{cEeHwHU^+2r6ahufS__n zpPSF;33x_^4UJLfc!%N4q4SHq%SN;O3vrgi4q3#vK8GrI`=^q(|Ndx|AuL>x$_;%p z#&o_Y;ESKcsK;~(#`LV8cxA)LuE(Ve=iu8D0Z#WkH1(=0L@zwAch1#t3Jq4tvy zQ}mLbG_P*xhp%)Oii8voNY*lo2eU{WI5Ed*W92n7jw5_QQZ5BV1RU5#BAbzza4w0~ zBlAU_tiU{I(`i=SyzMpTvF!i}Wlt61rbvg8)%AFVHay`{C*sRaysud^js4K^^rhYU za1)tqY_E^RSpJr~(_wLY!I9Y}m%(zhr$yfoXzcOML;dd)rTzTLgRS`%)C#S^allm~`UJ<+9%EOizaN%ym28(;jnxEHMUp@w!#ocGzbA^6Aw~ zlC7vch|aY1it=+Z4r~u`^TsH`eoNUhnAqz2wkuaJn%zN?+R)S|_S{cp`C}1pZZG6R z#jG-lOc{GxW)>kA)sF>B^J5Yl6E7+<O80xxL<^<}HwE|H|*@ zGoEj3T@=WKzH5r<%a2D&Dm+UoVWw{iIFdg{I8BcBskP11WYBe%M;RgT$tx zBsYPS$J63K5AXL0E1t_t&7mu!7J?V+uPk1x9a-QT_zW7bHfziODsX-z%aCqa^Q-VW zi+npgKNHeKQ8T(%F^K2m=1gXBBzn^H^}G4ESowFAvspdqTG1B6LVM>dWS<@M5K(Tm zKmX>$Y{cgNoW^2oV@dBlWy1~!aqfLn6}^N-8VBK$C^pLYOlOE(owwF7Y^RC0p<$Hk z2F1txk!11YkAklz4z3NXUrGjVik{&29WtFld#k;5QYYfCRH=zaZYX>*+UK#aq^CY- z6ewri%=soigt+t1*<;B~0k$dL$*DKnkD?!LKF@@$mAYq6!*7B1IC$00yy6tjTEb=h zvxS$56L{1c)nb4UK`S^G)nUD4Dy5xUFv1}Vp4V#GX8ORPD_yVB{1meAw9jr*9*ZM2 zrXeL;oe#WlVSv~Rq)^B3G!v8DN4zGPGT>6kO_tDTr|cwu6hUOF_M#LL=s6%bGRdr* znv=IL*ApyDKf9bzoj@-AmZT3mD(HqlzUCZ? zsW^Sf^RRLw!Ljz^8<(9pgvXt_)@a;^cPh@(!*h$Kvz`{J`t9#P{SB7VDVD1hX=n1A zUt~icW8%zH*`0bv2T=GqRfp=DK+^X$;DHNkf>p_>iRB8eoY$$lr}E#%7h{!dYRZlV zPS8LzYo8AG!yhSqHkh39bFTe%4j5MKi2eSU3Wruq-tTf z5nKJslC@v8x<_tT+GflG*?MPo9qfXmPz~6JYMuVx1C?7q*@Sa%Sg#z)?Y4f3_PQb_ zqHb(0EX&N#;y^DZf6ByR+`Ak#;(PT&Xw9Y5+cPbUd*do^29vO85*et7U%z*@%=_hM z{nJn7z^wh1+eYwaD?;Ct-wXuj z>X2Y|NHW8`p@!QpjrXd58=;F0B-*q=c^_C_IfOT@r^aVwxhBW@olY?VzuneptWpwb zV`?Ip-vq1zmsuD(J-?D#bPyV-_s{zPOP&i8sCS;*T#=_o7v!s3Nibf29wy*_Z?)N9 zK>xA?Q+Z%h-Fx-R(vixl!`X<#^+c3_ZB}YYuTVR@UVTV_8`lhS3sms)!JCE7Cu}vc#p6Yy6Tp#g&S?i0>`Q{m80gRNuCp;?OVC zM7Em-6y5Kpv{Y}Xw63c2@%>CVsFrxy#ItiI~0e|lLRsnLpXz${#^ce%PWP$cK#G8uF|NQV?L>*lsVTV*(e%$`TzCo+=qeFhc)w9T}S{goA(?`N9`k(ED zcuk+S5$`j$NuAMZMb#|3JaRJjGDgLgBp)|e=SiaBgN$wFu+)`Eg_!fn;FbWNOqH4K71@F z{NtRa#=PZe0mtSr&P67c7t87F5Wt8OO_lOLcL$`H4YoavwpogUEtbgdC3X3e0_LS9phAK<5L`5XEZxd=VvE9 z^&=`)o`>XUA|_W5EVz=P@#Ia}A~#dleh4aYG&=Le6R(3Q3RSPf&RyAzW+F=T7?U69 zow!QNQ#G5Kd93vchUvSvfKTf9rfI5wqoVxPrsnArR->t(Zke8FC9|7(8}$xer_bXI zD_0^9H%NoVb)PXkjB2v|>3z+Prz7|tLPln&HkgLI;-n|c(!K{m6|~5cscDSMpqgpylF&3+(;!R4WE)$?mXT!N$1sLF_nfEu zoSx^N`)B9=@q6C)dH?x--sgS4%kTUBe10O>10-9>-~ofai7nvQh1#3dAh9!`5K(N@ zo8uI#&W*~jTc?up=WAQYy-Gfq-@Hj-La3f>g=t$?HwF@k+rgvBF74!WWMPi+@s_~$ z4+5?=+t_VBKxukhFFwpI{2D+r^P~}jktp{;XvbWP@11?O`9Dl!{oN$Z{KsC2Q%-YJ zJcA;rx(yW{^CV=i{eminrM7}qOArVz^gXY1K()NjEx*iBlISu=s7G4!dP>LMR;ZA! z2+2yj2Dr9uh4< za{2L*s#?i2luuqQEwq#hXoO1DBcS(Ez?;Zt^V;BEsI+RwVSK}_s7IseT4tGjsB;qJ zC-qmHMh0R8G&}E4z)2Kb#@Fnw(`E$bsTDy8e zM_b}tJZ~SBJHZe34=>x2DZj^xAcA)fc%03f>WiAZHJ)f#mCLZC#u}vWC*{l6M#D%7 z5~W=0hLMA-NVsDaAijR^q;^Z=5vQHMn&+4sGiObr`{WSQVUqh>F~PS~ctqsl9t}|2 zc;}E)`U9?Fv8RRVJrS>Q<(k=^P(+}4CsHk-F;-32+w6UwK)Y8KhU>d^$wNwsYYIecO`Zwj#U-tV{-Xp39PA-** zo;wR{3^{T9tlD7383(>QpQ5o>Yg9i{#p`%2fshwtWs}xfE7kc>;uDLRT(70A8wm?} z!r;$#{sTejo5r+=+)kjyqm81@&Gwy8n?;~04ji{+!bfk%86Q>;K-{$I$^byf*MzuP zt(^{fAh!!ll{3NoSbfmF(;D(T1}^jH-NI5n0+1H!&#aNDAdJ<`UE%i3;T{8@e_Pu{ zu)v(zc|`;p*}1vFzQm%jCr9TWY*@T6x^6G8*s}t?bbTjb5P{w&qX@e zqOnOi9(`TLQanmGerh>~QS%rR~^ISIJyy@j7(4l)gG{#d@|HZyVppzVU?Kdnl#1EDDG~h^1RCWy_96gTvA!i=&3yx!Nd?oD z77v0VPmRuu9Gs_GXva^ajN(5(bV3%L&Uf#Zt0ppcmz@gtPt|&7IGaBXqzuH@k6POf zyk$i$!s=a*USjug3kqre1>D#3b^1aip?V9_AqPNeg1?9p!BVi{Rddi@nqks0saj5- zIh&G!(C>McfM6E!uig-|jsk5eZS8#ES+;mD`LLJ9?8|wNb5Nse%BHv1xgybehnp6{ z(@b!+H7tycGmB0eay1$fwPKixl;V@~r-gA%Up`Sas!DZ=BD{Gggb-Bx5;0{s2%vT& zx`G{^F~YWO?m~+@yVajgQ(=dWdi8Rgt1%8x_xx{PdmPSF*{tV55BC5(vA$B|(YV=p zW~=a}MHXo^fsdWnFs!^#boXuhGhxy7;b2N-WVuKa>vs9REQIf&e+s1VoA>OCx-R9d zAiRRm2w)*~M;%f;Xo$?PM^1ZRum|e<4tz?jTTiy$pt61gL zA6KP@j4Kg>?LQBlSvsLnJdS?64yAl{G%$SO z4PEh-${2xlyHh3G>KykLuiXiiClxp=NK}vLOdV1G7AQs;<)3;RLFO^k`C(;Wz*h3& z?*q8*E%-ZrvYm`x6fJ4$Bz_=Oi|Awc={_yB6r}Ug+RXsLBh9&vTqPb#Q1@E~O2&M0KWZwdpu12Z&)tO{Nm@+1NNBX?zaP84?w4HZXQMY1 z2yB~wa#Y<0;;Cl(6c~6hf5NWbE^iSS1$#7D?VNW?O6i0a^zsMpY>raUoul(d+O`%Dl)a2D#`OtvB_)U7~qO^wXPdX|k=$ZPodzflY2~S)pY)HzuOU z$~!Mg>!AWss!eZlAU8@cQhj;VS~2%Fgr1yK%JVhG;DY}h)a&1H0MemZeN@`2_VgFK zny_(h6wF}l6z>j!++)uQ zTh;7S&ZwF6XZNB+77LoTcJzS^O|pj`Xle^?7T^N`?Gqp*XB|HObfYiT1+sRks-Y&l z8J-YGxQF?g9g_|5%TdIKZ0c|l9OWAHW+3uXE@qC$Ov=TF=mEn+E2 zZOwqp7`YaFzkHidY*VXXFUirNjH9wyiB&`SWsdFDB2J(rU_|r`-=4!)tNr?diR}lc zCH054I<*I1U*Jgk%q2c7+wGqEIYa_)cGLYeRs-;wY(>BlEK8C)eXCs$s2e-Ra?1q08Td;13jk=9&E&-_N}N daZdCzE&tgT_{Y8R-}F`fM=bt{h``(Z{{k9}vHAc2 literal 0 HcmV?d00001 From 060e48cfba19d02001aa99786aa0e1c7c26bb860 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 28 Oct 2024 12:31:26 +0100 Subject: [PATCH 34/36] update metal samples --- metal/mrt-metal.c | 2 +- metal/vertexpulling-metal.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/metal/mrt-metal.c b/metal/mrt-metal.c index 12af407b..2d131c41 100644 --- a/metal/mrt-metal.c +++ b/metal/mrt-metal.c @@ -42,7 +42,7 @@ typedef struct { } params_t; static void init(void) { - /* setup sokol */ + // setup sokol sg_setup(&(sg_desc){ .environment = osx_environment(), .logger.func = slog_func, diff --git a/metal/vertexpulling-metal.c b/metal/vertexpulling-metal.c index 81dbb471..ed6cc0dc 100644 --- a/metal/vertexpulling-metal.c +++ b/metal/vertexpulling-metal.c @@ -103,7 +103,7 @@ static void init(void) { " float4 pos [[position]];\n" " float4 color;\n" "};\n" - "vertex vs_out _main(constant params_t& params [[buffer(0)]], const device ssbo_t& ssbo [[buffer(1)]], uint vidx [[vertex_id]]) {\n" + "vertex vs_out _main(constant params_t& params [[buffer(0)]], const device ssbo_t& ssbo [[buffer(8)]], uint vidx [[vertex_id]]) {\n" " vs_out out;\n" " out.pos = params.mvp * ssbo.vtx[vidx].pos;\n" " out.color = ssbo.vtx[vidx].color;\n" @@ -123,7 +123,7 @@ static void init(void) { .storage_buffers[0] = { .stage = SG_SHADERSTAGE_VERTEX, .readonly = true, - .msl_buffer_n = 1, + .msl_buffer_n = 8, }, }); From b756f0348314dd3c8184462de9357bbbd1fbd40e Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 28 Oct 2024 17:08:23 +0100 Subject: [PATCH 35/36] fix cubemap-jpeg-sapp-ui asset copying --- sapp/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sapp/CMakeLists.txt b/sapp/CMakeLists.txt index e6539d75..f1b2a4dc 100644 --- a/sapp/CMakeLists.txt +++ b/sapp/CMakeLists.txt @@ -340,6 +340,8 @@ fips_ide_group(SamplesWithDebugUI) fips_begin_app(cubemap-jpeg-sapp-ui windowed) fips_files(cubemap-jpeg-sapp.c) sokol_shader(cubemap-jpeg-sapp.glsl ${slang}) + fips_dir(data) + fipsutil_copy(cubemap-jpeg-assets.yml) fips_deps(sokol fileutil stb dbgui) target_compile_definitions(cubemap-jpeg-sapp-ui PRIVATE USE_DBG_UI) fips_end_app() From fbfa2d37b4cc778a4cc35106569c10ffa37b86ef Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Wed, 30 Oct 2024 18:40:38 +0100 Subject: [PATCH 36/36] fix d3d11 samples --- d3d11/blend-d3d11.c | 2 +- d3d11/imgui-d3d11.cc | 6 +++--- d3d11/mrt-d3d11.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/d3d11/blend-d3d11.c b/d3d11/blend-d3d11.c index b005c79f..ea0bfc62 100644 --- a/d3d11/blend-d3d11.c +++ b/d3d11/blend-d3d11.c @@ -69,7 +69,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " float c = xy.x * xy.y;\n" " return float4(c, c, c, 1.0);\n" "};\n", - .vertex_attrs[0].hlsl_sem_name = "POS", + .attrs[0].hlsl_sem_name = "POS", .uniform_blocks[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .size = sizeof(fs_params_t), diff --git a/d3d11/imgui-d3d11.cc b/d3d11/imgui-d3d11.cc index 5d0102ae..27e82188 100644 --- a/d3d11/imgui-d3d11.cc +++ b/d3d11/imgui-d3d11.cc @@ -133,9 +133,9 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float2 uv: TEXCOORD0, float4 color: COLOR0): SV_Target0 {\n" " return tex.Sample(smp, uv) * color;\n" "}\n"; - shd_desc.vertex_attrs[0].hlsl_sem_name = "POSITION"; - shd_desc.vertex_attrs[1].hlsl_sem_name = "TEXCOORD"; - shd_desc.vertex_attrs[2].hlsl_sem_name = "COLOR"; + shd_desc.attrs[0].hlsl_sem_name = "POSITION"; + shd_desc.attrs[1].hlsl_sem_name = "TEXCOORD"; + shd_desc.attrs[2].hlsl_sem_name = "COLOR"; shd_desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; shd_desc.uniform_blocks[0].size = sizeof(vs_params_t); shd_desc.uniform_blocks[0].hlsl_register_b_n = 0; diff --git a/d3d11/mrt-d3d11.c b/d3d11/mrt-d3d11.c index 11110ac8..ecf8d5e4 100644 --- a/d3d11/mrt-d3d11.c +++ b/d3d11/mrt-d3d11.c @@ -268,7 +268,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ " float4 c = float4(c0 + c1 + c2, 1.0);\n" " return c;\n" "}\n", - .vertex_attrs[0].hlsl_sem_name = "POSITION", + .attrs[0].hlsl_sem_name = "POSITION", .uniform_blocks[0] = { .stage = SG_SHADERSTAGE_VERTEX, .size = sizeof(params_t), @@ -331,7 +331,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ "float4 main(float2 uv: TEXCOORD0): SV_Target0 {\n" " return float4(tex.Sample(smp, uv).xyz, 1.0);\n" "}\n", - .vertex_attrs[0].hlsl_sem_name = "POSITION", + .attrs[0].hlsl_sem_name = "POSITION", .images[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .hlsl_register_t_n = 0 }, .samplers[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .hlsl_register_s_n = 0 }, .image_sampler_pairs[0] = { .stage = SG_SHADERSTAGE_FRAGMENT, .image_slot = 0, .sampler_slot = 0 },