Skip to content

Commit

Permalink
fix regression for image-sample-pair code generation (fixes #154)
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Nov 9, 2024
1 parent eabd3df commit a7eabc4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGELOG
=========

#### **09-Nov-2024**

Important regression fix: shaders which used textures/samplers both on the vertex-
and fragment-stage didn't code-generate the correct `sg_shader_desc.image_sampler_pairs[]`
array which then causes validation errors in sokol_gfx.h and general breakage when
using the GL backend.

See https://github.com/floooh/sokol-tools/issues/154 for details.

#### **07-Nov-2024**

This is the sokol-shdc update going with the sokol-gfx 'bindings cleanup update':
Expand Down
16 changes: 13 additions & 3 deletions src/shdc/reflection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Reflection Reflection::build(const Args& args, const Input& inp, const std::arra
prog_refl.name = prog.name;
prog_refl.stages[ShaderStage::Vertex] = vs_src->stage_refl;
prog_refl.stages[ShaderStage::Fragment] = fs_src->stage_refl;
prog_refl.bindings = merge_bindings({ vs_src->stage_refl.bindings, fs_src->stage_refl.bindings }, err);
prog_refl.bindings = merge_bindings({ vs_src->stage_refl.bindings, fs_src->stage_refl.bindings }, true, err);
if (err.valid()) {
res.error = inp.error(prog.line_index, err.msg);
return res;
Expand All @@ -117,7 +117,7 @@ Reflection Reflection::build(const Args& args, const Input& inp, const std::arra
for (const auto& prog_refl: res.progs) {
prog_bindings.push_back(prog_refl.bindings);
}
res.bindings = merge_bindings(prog_bindings, err);
res.bindings = merge_bindings(prog_bindings, false, err);
if (err.valid()) {
res.error = inp.error(0, err.msg);
}
Expand Down Expand Up @@ -372,7 +372,7 @@ StageReflection Reflection::parse_snippet_reflection(const Compiler& compiler, c
return refl;
}

Bindings Reflection::merge_bindings(const std::vector<Bindings>& in_bindings, ErrMsg& out_error) {
Bindings Reflection::merge_bindings(const std::vector<Bindings>& in_bindings, bool assign_image_sampler_slots, ErrMsg& out_error) {
Bindings out_bindings;
out_error = ErrMsg();
for (const Bindings& src_bindings: in_bindings) {
Expand Down Expand Up @@ -447,6 +447,16 @@ Bindings Reflection::merge_bindings(const std::vector<Bindings>& in_bindings, Er
}
}
}

// if requested, assign new image-sampler slots which are unique across shader stages, this
// is needed when merging the per-shader-stage bindings into per-program-bindings
if (assign_image_sampler_slots) {
int sokol_slot = 0;
for (ImageSampler& img_smp: out_bindings.image_samplers) {
img_smp.sokol_slot = sokol_slot++;
}
}

return out_bindings;
}

Expand Down
2 changes: 1 addition & 1 deletion src/shdc/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct Reflection {

private:
// create a set of unique resource bindings from shader snippet input bindings
static Bindings merge_bindings(const std::vector<Bindings>& in_bindings, ErrMsg& out_error);
static Bindings merge_bindings(const std::vector<Bindings>& in_bindings, bool assign_image_sampler_slots, ErrMsg& out_error);
// parse a struct
static Type parse_toplevel_struct(const spirv_cross::Compiler& compiler, const spirv_cross::Resource& res, ErrMsg& out_error);
// parse a struct item
Expand Down

0 comments on commit a7eabc4

Please sign in to comment.