Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/libwebgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3273,9 +3273,9 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
// Remove all the layout(binding = x) directives so that they do not make
// their way to the actual WebGL shader compiler. These regexes get quite
// hairy, check against https://regex101.com/ when working on these.
source = source.replace(/layout\s*\(.*?binding\s*=\s*([-\d]+).*?\)/g, ''); // "layout(binding = 3)" -> ""
source = source.replace(/layout\s*\(\s*binding\s*=\s*([-\d]+)\s*\)/g, ''); // "layout(binding = 3)" -> ""
source = source.replace(/(layout\s*\((.*?)),\s*binding\s*=\s*([-\d]+)\)/g, '$1)'); // "layout(std140, binding = 1)" -> "layout(std140)"
source = source.replace(/layout\s*\(\s*binding\s*=\s*([-\d]+)\s*,(.*?)\)/g, 'layout($2)'); // "layout(binding = 1, std140)" -> "layout(std140)"
source = source.replace(/layout\s*\(\s*binding\s*=\s*([-\d]+)\s*,\s*(.*?)\)/g, 'layout($2)'); // "layout(binding = 1, std140)" -> "layout(std140)"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This \s* addition is not part of the fix itself, but just to improve cleanliness of the string replace for the assert() in the test below. Without this, layout(binding = 1, std140) was converted to form layout( std140), so the \s* here swallows the stray space before std140.


#if GL_DEBUG
dbg(`Shader source after removing layout binding directives: ${source}`;
Expand Down
5 changes: 5 additions & 0 deletions test/browser/webgl2_ubo_layout_binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ int main(int argc, char *argv[])
"out vec4 outColor;\n"
"void main() { outColor = vec4(r, green.g, blue[0].b + blue[1].b, 1.0); }");

// The above shader compilation should preserve the std140 layout part in the uniforms, so
// make sure that did happen. (https://github.com/emscripten-core/emscripten/issues/25828)
assert(strstr(emscripten_webgl_get_shader_source_utf8(ps), "layout(std140) uniform Green"));
assert(strstr(emscripten_webgl_get_shader_source_utf8(ps), "layout(std140) uniform Blue"));

GLuint program = CreateProgram(vs, ps);
glUseProgram(program);

Expand Down