Skip to content

Commit e43e97f

Browse files
authored
Fix preserving layout(std140) directives with -sGL_EXPLICIT_UNIFORM_BINDING (#25839)
Fix preserving layout(std140) directives in WebGL shaders when using `-sGL_EXPLICIT_UNIFORM_BINDING` WebGL extension. Improve the existing test to catch the reported scenario. Fixes #25828.
1 parent 20ab3d4 commit e43e97f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/lib/libwebgl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,9 +3273,9 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
32733273
// Remove all the layout(binding = x) directives so that they do not make
32743274
// their way to the actual WebGL shader compiler. These regexes get quite
32753275
// hairy, check against https://regex101.com/ when working on these.
3276-
source = source.replace(/layout\s*\(.*?binding\s*=\s*([-\d]+).*?\)/g, ''); // "layout(binding = 3)" -> ""
3276+
source = source.replace(/layout\s*\(\s*binding\s*=\s*([-\d]+)\s*\)/g, ''); // "layout(binding = 3)" -> ""
32773277
source = source.replace(/(layout\s*\((.*?)),\s*binding\s*=\s*([-\d]+)\)/g, '$1)'); // "layout(std140, binding = 1)" -> "layout(std140)"
3278-
source = source.replace(/layout\s*\(\s*binding\s*=\s*([-\d]+)\s*,(.*?)\)/g, 'layout($2)'); // "layout(binding = 1, std140)" -> "layout(std140)"
3278+
source = source.replace(/layout\s*\(\s*binding\s*=\s*([-\d]+)\s*,\s*(.*?)\)/g, 'layout($2)'); // "layout(binding = 1, std140)" -> "layout(std140)"
32793279

32803280
#if GL_DEBUG
32813281
dbg(`Shader source after removing layout binding directives: ${source}`;

test/browser/webgl2_ubo_layout_binding.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ int main(int argc, char *argv[])
8383
"out vec4 outColor;\n"
8484
"void main() { outColor = vec4(r, green.g, blue[0].b + blue[1].b, 1.0); }");
8585

86+
// The above shader compilation should preserve the std140 layout part in the uniforms, so
87+
// make sure that did happen. (https://github.com/emscripten-core/emscripten/issues/25828)
88+
assert(strstr(emscripten_webgl_get_shader_source_utf8(ps), "layout(std140) uniform Green"));
89+
assert(strstr(emscripten_webgl_get_shader_source_utf8(ps), "layout(std140) uniform Blue"));
90+
8691
GLuint program = CreateProgram(vs, ps);
8792
glUseProgram(program);
8893

0 commit comments

Comments
 (0)