Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
GH Action committed Jan 23, 2025
1 parent 6afbc62 commit dbc114c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/sokol/c/sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@
(in HLSL, storage buffers and texture share the same bind space)
- Metal/MSL: the buffer bind slot N (`[[buffer(N)]]`) where N is 8..15
- WebGPU/WGSL: the binding N in `@group(0) @binding(N)` where N is 0..127
- GL/GLSL: the buffer binding N in `layout(binding=N)` where N is 0..16
- GL/GLSL: the buffer binding N in `layout(binding=N)` where N is 0..7
- note that storage buffers are not supported on all backends
and platforms

Expand Down Expand Up @@ -3062,7 +3062,7 @@ typedef struct sg_sampler_desc {
- HLSL: the texture(sic) register `register(t0..23)`
- MSL: the buffer attribute `[[buffer(8..15)]]`
- WGSL: the binding in `@group(1) @binding(0..127)`
- GL: the binding in `layout(binding=0..16)`
- GL: the binding in `layout(binding=0..7)`

- reflection information for each combined image-sampler object
used by the shader:
Expand Down Expand Up @@ -3683,6 +3683,7 @@ typedef struct sg_frame_stats {
_SG_LOGITEM_XMACRO(GL_TEXTURE_FORMAT_NOT_SUPPORTED, "pixel format not supported for texture (gl)") \
_SG_LOGITEM_XMACRO(GL_3D_TEXTURES_NOT_SUPPORTED, "3d textures not supported (gl)") \
_SG_LOGITEM_XMACRO(GL_ARRAY_TEXTURES_NOT_SUPPORTED, "array textures not supported (gl)") \
_SG_LOGITEM_XMACRO(GL_STORAGEBUFFER_GLSL_BINDING_OUT_OF_RANGE, "GLSL storage buffer bindslot is out of range (must be 0..7) (gl)") \
_SG_LOGITEM_XMACRO(GL_SHADER_COMPILATION_FAILED, "shader compilation failed (gl)") \
_SG_LOGITEM_XMACRO(GL_SHADER_LINKING_FAILED, "shader linking failed (gl)") \
_SG_LOGITEM_XMACRO(GL_VERTEX_ATTRIBUTE_NOT_FOUND_IN_SHADER, "vertex attribute not found in shader; NOTE: may be caused by GL driver's GLSL compiler removing unused globals") \
Expand Down Expand Up @@ -3828,7 +3829,7 @@ typedef struct sg_frame_stats {
_SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_STORAGEBUFFER_METAL_BUFFER_SLOT_COLLISION, "storage buffer 'msl_buffer_n' must be unique across uniform blocks and storage buffer in same shader stage") \
_SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_STORAGEBUFFER_HLSL_REGISTER_T_OUT_OF_RANGE, "storage buffer 'hlsl_register_t_n' is out of range (must be 0..23)") \
_SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_STORAGEBUFFER_HLSL_REGISTER_T_COLLISION, "storage_buffer 'hlsl_register_t_n' must be unique across storage buffers and images in same shader stage") \
_SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_STORAGEBUFFER_GLSL_BINDING_OUT_OF_RANGE, "storage buffer 'glsl_binding_n' is out of range (must be 0..15)") \
_SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_STORAGEBUFFER_GLSL_BINDING_OUT_OF_RANGE, "storage buffer 'glsl_binding_n' is out of range (must be 0..7)") \
_SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_STORAGEBUFFER_GLSL_BINDING_COLLISION, "storage buffer 'glsl_binding_n' must be unique across shader stages") \
_SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_STORAGEBUFFER_WGSL_GROUP1_BINDING_OUT_OF_RANGE, "storage buffer 'wgsl_group1_binding_n' is out of range (must be 0..127)") \
_SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_STORAGEBUFFER_WGSL_GROUP1_BINDING_COLLISION, "storage buffer 'wgsl_group1_binding_n' must be unique across all images, samplers and storage buffers") \
Expand Down Expand Up @@ -5566,7 +5567,7 @@ typedef struct {
GLuint sampler;
} _sg_gl_cache_texture_sampler_bind_slot;

#define _SG_GL_MAX_SBUF_BINDINGS (2 * SG_MAX_STORAGEBUFFER_BINDSLOTS)
#define _SG_GL_MAX_SBUF_BINDINGS (SG_MAX_STORAGEBUFFER_BINDSLOTS)
#define _SG_GL_MAX_IMG_SMP_BINDINGS (SG_MAX_IMAGE_SAMPLER_PAIRS)
typedef struct {
sg_depth_state depth;
Expand Down Expand Up @@ -8704,11 +8705,25 @@ _SOKOL_PRIVATE GLuint _sg_gl_compile_shader(sg_shader_stage stage, const char* s
return gl_shd;
}

// NOTE: this is an out-of-range check for GLSL bindslots that's also active in release mode
_SOKOL_PRIVATE void _sg_gl_ensure_glsl_bindslot_ranges(const sg_shader_desc* desc) {
SOKOL_ASSERT(desc);
for (size_t i = 0; i < SG_MAX_STORAGEBUFFER_BINDSLOTS; i++) {
if (desc->storage_buffers[i].glsl_binding_n >= _SG_GL_MAX_SBUF_BINDINGS) {
_SG_PANIC(GL_STORAGEBUFFER_GLSL_BINDING_OUT_OF_RANGE);
}
}
}

_SOKOL_PRIVATE sg_resource_state _sg_gl_create_shader(_sg_shader_t* shd, const sg_shader_desc* desc) {
SOKOL_ASSERT(shd && desc);
SOKOL_ASSERT(!shd->gl.prog);
_SG_GL_CHECK_ERROR();

// perform a fatal range-check on GLSL bindslots that's also active
// in release mode to avoid potential out-of-bounds array accesses
_sg_gl_ensure_glsl_bindslot_ranges(desc);

// copy the optional vertex attribute names over
for (int i = 0; i < SG_MAX_VERTEX_ATTRIBUTES; i++) {
_sg_strcpy(&shd->gl.attrs[i].name, desc->attrs[i].glsl_name);
Expand Down
3 changes: 2 additions & 1 deletion src/sokol/gfx.d
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ struct SamplerDesc {
/// - HLSL: the texture(sic) register `register(t0..23)`
/// - MSL: the buffer attribute `[[buffer(8..15)]]`
/// - WGSL: the binding in `@group(1) @binding(0..127)`
/// - GL: the binding in `layout(binding=0..16)`
/// - GL: the binding in `layout(binding=0..7)`
///
/// - reflection information for each combined image-sampler object
/// used by the shader:
Expand Down Expand Up @@ -1907,6 +1907,7 @@ enum LogItem {
Gl_texture_format_not_supported,
Gl_3d_textures_not_supported,
Gl_array_textures_not_supported,
Gl_storagebuffer_glsl_binding_out_of_range,
Gl_shader_compilation_failed,
Gl_shader_linking_failed,
Gl_vertex_attribute_not_found_in_shader,
Expand Down

0 comments on commit dbc114c

Please sign in to comment.