The sg_bindings structure defines the resource bindings for
the next draw call.
To update the resource bindings, call sg_apply_bindings() with
a pointer to a populated sg_bindings struct. Note that
sg_apply_bindings() must be called after sg_apply_pipeline()
and that bindings are not preserved across sg_apply_pipeline()
calls, even when the new pipeline uses the same 'bindings layout'.
Note that inside compute passes vertex- and index-buffer-bindings are
disallowed.
When using sokol-shdc for shader authoring, the layout(binding=N)
for texture-, storage-image- and storage-buffer-bindings directly
maps to the views-array index, for instance the following vertex-
and fragment-shader interface for sokol-shdc:
Resource bindslots for a specific shader/pipeline may have gaps, and an
sg_bindings struct may have populated bind slots which are not used by a
specific shader. This allows to use the same sg_bindings struct across
different shader variants.
When not using sokol-shdc, the bindslot indices in the sg_bindings
struct need to match the per-binding reflection info slot indices
in the sg_shader_desc struct (for details about that see the
sg_shader_desc struct documentation).
The optional buffer offsets can be used to put different unrelated
chunks of vertex- and/or index-data into the same buffer objects.
sg_bindings
The sg_bindings structure defines the resource bindings for the next draw call.
To update the resource bindings, call sg_apply_bindings() with a pointer to a populated sg_bindings struct. Note that sg_apply_bindings() must be called after sg_apply_pipeline() and that bindings are not preserved across sg_apply_pipeline() calls, even when the new pipeline uses the same 'bindings layout'.
A resource binding struct contains:
- 1..N vertex buffers - 1..N vertex buffer offsets - 0..1 index buffer - 0..1 index buffer offset - 0..N resource views (texture-, storage-image, storage-buffer-views) - 0..N samplers
Where 'N' is defined in the following constants:
- SG_MAX_VERTEXBUFFER_BINDSLOTS - SG_MAX_VIEW_BINDSLOTS - SG_MAX_SAMPLER_BINDSLOTS
Note that inside compute passes vertex- and index-buffer-bindings are disallowed.
When using sokol-shdc for shader authoring, the layout(binding=N) for texture-, storage-image- and storage-buffer-bindings directly maps to the views-array index, for instance the following vertex- and fragment-shader interface for sokol-shdc:
@vs vs layout(binding=0) uniform vs_params { ... }; layout(binding=0) readonly buffer ssbo { ... }; layout(binding=1) uniform texture2D vs_tex; layout(binding=0) uniform sampler vs_smp; ... @end
@fs fs layout(binding=1) uniform fs_params { ... }; layout(binding=2) uniform texture2D fs_tex; layout(binding=1) uniform sampler fs_smp; ... @end
...would map to the following sg_bindings struct:
const sg_bindings bnd = { .vertex_buffers[0] = ..., .views[0] = ssbo_view, .views[1] = vs_tex_view, .views[2] = fs_tex_view, .samplers[0] = vs_smp, .samplers[1] = fs_smp, };
...alternatively you can use code-generated slot indices:
const sg_bindings bnd = { .vertex_buffers[0] = ..., .viewsVIEW_ssbo = ssbo_view, .viewsVIEW_vs_tex = vs_tex_view, .viewsVIEW_fs_tex = fs_tex_view, .samplersSMP_vs_smp = vs_smp, .samplersSMP_fs_smp = fs_smp, };
Resource bindslots for a specific shader/pipeline may have gaps, and an sg_bindings struct may have populated bind slots which are not used by a specific shader. This allows to use the same sg_bindings struct across different shader variants.
When not using sokol-shdc, the bindslot indices in the sg_bindings struct need to match the per-binding reflection info slot indices in the sg_shader_desc struct (for details about that see the sg_shader_desc struct documentation).
The optional buffer offsets can be used to put different unrelated chunks of vertex- and/or index-data into the same buffer objects.