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