|
@@ -776,7 +776,7 @@
|
|
(in HLSL, storage buffers and texture share the same bind space)
|
|
(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
|
|
- 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
|
|
- 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
|
|
- note that storage buffers are not supported on all backends
|
|
and platforms
|
|
and platforms
|
|
|
|
|
|
@@ -3062,7 +3062,7 @@ typedef struct sg_sampler_desc {
|
|
- HLSL: the texture(sic) register `register(t0..23)`
|
|
- HLSL: the texture(sic) register `register(t0..23)`
|
|
- MSL: the buffer attribute `[[buffer(8..15)]]`
|
|
- MSL: the buffer attribute `[[buffer(8..15)]]`
|
|
- WGSL: the binding in `@group(1) @binding(0..127)`
|
|
- 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
|
|
- reflection information for each combined image-sampler object
|
|
used by the shader:
|
|
used by the shader:
|
|
@@ -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_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_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_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_COMPILATION_FAILED, "shader compilation failed (gl)") \
|
|
_SG_LOGITEM_XMACRO(GL_SHADER_LINKING_FAILED, "shader linking 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") \
|
|
_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") \
|
|
@@ -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_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_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_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_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_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") \
|
|
_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") \
|
|
@@ -5566,7 +5567,7 @@ typedef struct {
|
|
GLuint sampler;
|
|
GLuint sampler;
|
|
} _sg_gl_cache_texture_sampler_bind_slot;
|
|
} _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)
|
|
#define _SG_GL_MAX_IMG_SMP_BINDINGS (SG_MAX_IMAGE_SAMPLER_PAIRS)
|
|
typedef struct {
|
|
typedef struct {
|
|
sg_depth_state depth;
|
|
sg_depth_state depth;
|
|
@@ -8704,11 +8705,25 @@ _SOKOL_PRIVATE GLuint _sg_gl_compile_shader(sg_shader_stage stage, const char* s
|
|
return gl_shd;
|
|
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_PRIVATE sg_resource_state _sg_gl_create_shader(_sg_shader_t* shd, const sg_shader_desc* desc) {
|
|
SOKOL_ASSERT(shd && desc);
|
|
SOKOL_ASSERT(shd && desc);
|
|
SOKOL_ASSERT(!shd->gl.prog);
|
|
SOKOL_ASSERT(!shd->gl.prog);
|
|
_SG_GL_CHECK_ERROR();
|
|
_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
|
|
// copy the optional vertex attribute names over
|
|
for (int i = 0; i < SG_MAX_VERTEX_ATTRIBUTES; i++) {
|
|
for (int i = 0; i < SG_MAX_VERTEX_ATTRIBUTES; i++) {
|
|
_sg_strcpy(&shd->gl.attrs[i].name, desc->attrs[i].glsl_name);
|
|
_sg_strcpy(&shd->gl.attrs[i].name, desc->attrs[i].glsl_name);
|