Skip to content

Commit

Permalink
fix more sapp samples for bindings cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Oct 14, 2024
1 parent 722ae74 commit c17b13b
Show file tree
Hide file tree
Showing 24 changed files with 364 additions and 364 deletions.
598 changes: 299 additions & 299 deletions sapp/CMakeLists.txt

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions sapp/cubemap-jpeg-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ 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"
});

// 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 = {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions sapp/cubemap-jpeg-sapp.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@ctype mat4 hmm_mat4

@vs vs
uniform vs_params {
layout(binding=0) uniform vs_params {
mat4 mvp;
};

Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions sapp/debugtext-context-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions sapp/debugtext-context-sapp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@ctype mat4 hmm_mat4

@vs vs
uniform vs_params {
layout(binding=0) uniform vs_params {
mat4 mvp;
};

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

Expand Down
8 changes: 4 additions & 4 deletions sapp/drawcallperf-sapp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions sapp/dyntex3d-sapp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@ctype mat4 hmm_mat4

@vs vs
uniform vs_params {
layout(binding=0) uniform vs_params {
float w;
};

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

Expand Down
4 changes: 2 additions & 2 deletions sapp/fontstash-layers-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
6 changes: 3 additions & 3 deletions sapp/imgui-usercallback-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion sapp/imgui-usercallback-sapp.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@ctype mat4 hmm_mat4

@vs vs
uniform vs_params {
layout(binding=0) uniform vs_params {
mat4 mvp;
};

Expand Down
8 changes: 4 additions & 4 deletions sapp/instancing-pull-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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),
Expand Down Expand Up @@ -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),
});
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions sapp/instancing-pull-sapp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
};

Expand Down
18 changes: 9 additions & 9 deletions sapp/pixelformats-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand All @@ -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,
Expand Down Expand Up @@ -317,35 +317,35 @@ 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();
}
if (fmt_info.blend) {
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();
}
if (fmt_info.msaa) {
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();
}
Expand Down
4 changes: 2 additions & 2 deletions sapp/pixelformats-sapp.glsl
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,7 +34,7 @@ void main() {
@end

@fs fs_bg
uniform bg_fs_params {
layout(binding=0) uniform bg_fs_params {
float tick;
};

Expand Down
6 changes: 3 additions & 3 deletions sapp/primtypes-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion sapp/primtypes-sapp.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@ctype mat4 hmm_mat4

@vs vs
uniform vs_params {
layout(binding=0) uniform vs_params {
mat4 mvp;
float point_size;
};
Expand Down
12 changes: 6 additions & 6 deletions sapp/restart-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
});
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit c17b13b

Please sign in to comment.