From bb71bdcb0751b55e277385c3d275b073d6762d4a Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 12 Oct 2024 19:44:42 +0200 Subject: [PATCH] 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();