Skip to content

Commit

Permalink
all sapp samples updated for bindings cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Oct 16, 2024
1 parent d35ddac commit 54c1428
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 140 deletions.
107 changes: 53 additions & 54 deletions sapp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions sapp/drawcallperf-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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())),
Expand Down Expand Up @@ -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;
Expand All @@ -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++;
Expand Down
6 changes: 3 additions & 3 deletions sapp/dyntex3d-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
30 changes: 15 additions & 15 deletions sapp/ozz-skin-sapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -230,15 +230,15 @@ 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;
smp_desc.mag_filter = SG_FILTER_NEAREST;
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 = { };
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions sapp/ozz-storagebuffer-sapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = { };
Expand Down
8 changes: 4 additions & 4 deletions sapp/ozz-storagebuffer-sapp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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[];
};

Expand Down
Loading

0 comments on commit 54c1428

Please sign in to comment.