Repository navigation
Fix implicit swap of proxied WebGL contexts #28455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juj
wants to merge
6
commits into
emscripten-core:main
Choose a base branch
from
juj:fix_proxied_gl_postset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b66cfa2
Fix implicit swap of proxied WebGL contexts
juj c1eba3b
Fix BigInt handle in proxied GL context activation under wasm64
juj cf72a39
Fix write of explicitSwapControl to i32.
juj f68309a
Restore to i8
juj fbb6f68
Address review: keep i8 attribute write, assert in JS in test
juj aa7e8e7
Comment on GL.currentContext holding the handle pointer for proxied c…
juj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Copyright 2026 The Emscripten Authors. All rights reserved. | ||
| // Emscripten is available under two separate licenses, the MIT license and the | ||
| // University of Illinois/NCSA Open Source License. Both these licenses can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include <assert.h> | ||
| #include <stdbool.h> | ||
| #include <stdlib.h> | ||
| #include <GLES2/gl2.h> | ||
| #include <emscripten/em_asm.h> | ||
| #include <emscripten/emscripten.h> | ||
| #include <emscripten/html5.h> | ||
|
|
||
| // Tests that a WebGL context that is proxied to the main thread and uses | ||
| // implicit swap (explicitSwapControl=false) gets presented on behalf of the | ||
| // application at each main loop iteration. | ||
| // | ||
| // A proxied context renders to an offscreen framebuffer, so nothing reaches | ||
| // the canvas unless the runtime calls emscripten_webgl_commit_frame() for us. | ||
|
|
||
| int frame = 0; | ||
|
|
||
| void tick(void) { | ||
| if (frame++ == 0) { | ||
| glClearColor(0, 0, 1, 1); | ||
| glClear(GL_COLOR_BUFFER_BIT); | ||
| return; | ||
| } | ||
|
|
||
| // The frame rendered above has been implicitly presented before this | ||
| // iteration started. Read back what is visible on the canvas. | ||
| MAIN_THREAD_EM_ASM({ | ||
| var canvas = Module['canvas']; | ||
| var copy = document.createElement('canvas'); | ||
| copy.width = canvas.width; | ||
| copy.height = canvas.height; | ||
| var ctx = copy.getContext('2d'); | ||
| ctx.drawImage(canvas, 0, 0); | ||
| var pixel = ctx.getImageData(canvas.width >> 1, canvas.height >> 1, 1, 1).data; | ||
| out('canvas pixel: ' + Array.from(pixel)); | ||
| assert(pixel[0] == 0 && pixel[1] == 0 && pixel[2] == 255 && pixel[3] == 255, | ||
| 'the frame should have been presented without an explicit commit'); | ||
| }); | ||
|
|
||
| emscripten_cancel_main_loop(); | ||
| exit(0); | ||
| } | ||
|
|
||
| int main(void) { | ||
| EmscriptenWebGLContextAttributes attr; | ||
| emscripten_webgl_init_context_attributes(&attr); | ||
| assert(!attr.explicitSwapControl); | ||
| EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr); | ||
| assert(ctx); | ||
| EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(ctx); | ||
| assert(res == EMSCRIPTEN_RESULT_SUCCESS); | ||
|
|
||
| emscripten_set_main_loop(tick, 0, false); | ||
| return 99; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. Elsewhere in this file we do things like
GL.currentContext.tempVertexBuffers1which suggestsGL.currentContextis an object. Is that not the case?It looks like it is, as it is written to from
GL.contextsentries, which are objects?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is indeed a bit confusing by static reading.
What happens is that when GL.currentContextIsProxied is true, then GL.currentContext is not an actual GL context handle (since the proxy target thread owns it), but a pointer to a control block of that context, so a number. Updated this site with a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I see, thanks. But I see this:
So shouldn't this be
i32, noti8? From the PR description it sounds like the write is ofi8, but if so, can we define the field in C to be ani8too for consistency?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, where is that write? I can't seem to find it by grepping.