Allow alternative GLContexts to be set globally.
See original GitHub issueCurrently, canvas_util.ts
has some caching of WebGL context versions with a retrieval function that attempts to load a WebGL context by creating a new canvas
DOM element.
Ideally, we have a flag or global override to set the WebGL/GL context object.
For instance, setting WEBGL_FENCE_API_ENABLED
to false will result in this exception when running outside of the browser:
(node:89462) UnhandledPromiseRejectionWarning: ReferenceError: document is not defined
at getWebGLRenderingContext (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/backends/webgl/canvas_util.ts:63:18)
at getWebGLContext (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/backends/webgl/canvas_util.ts:37:30)
at Object.getWebGLContext (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/backends/webgl/canvas_util.ts:42:12)
at Object.getWebGLDisjointQueryTimerVersion (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/backends/webgl/webgl_util.ts:516:14)
at Object.evaluationFn (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/backends/webgl/flags_webgl.ts:104:21)
at Environment.evaluateFlag (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/environment.ts:98:40)
at Environment.get (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/environment.ts:61:33)
at Environment.getNumber (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/environment.ts:67:17)
at GPGPUContext.createFence (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/backends/webgl/gpgpu_context.ts:254:13)
at GPGPUContext.createAndWaitForFence (/Users/kreeger/workspace/tfjs-backend-nodegl/node_modules/@tensorflow/tfjs-core/src/backends/webgl/gpgpu_context.ts:232:31)
I tried importing setWebGLContext
but the key as a number
does not work on contexts
. I’ll whip up a patch tomorrow for this.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:26
Top Results From Across the Web
Avoid using a global GL context on Android (we'll see later if ...
3. (Hypothetical) We have had strange context creation crashes in bug 736123 which I can't reproduce in my builds that disable the global...
Read more >ModernGL Documentation
Then set an environment variable GLCONTEXT_WIN_LIBGL=C:\msys64\mingw64\bin\opengl32.dll. This will make glcontext use C:\msys64\mingw64\bin\ ...
Read more >gfx.crash-guard.glcontext.gfx.driver-init.webgl-angle-force ...
Value Name, gfx.crash-guard.glcontext.gfx.driver-init.webgl-angle-force-d3d11. Value Type, REG_DWORD. Enabled Value, 1. Disabled Value, 0 ...
Read more >GL::Context class | Magnum C++ docs
Once all needed instances are created, switch between them right after making the underlying GL context current: Platform::GLContext::makeCurrent(&context); ...
Read more >Gluegen Manual - JogAmp
The first mode, "AllStatic", exposes the underlying C functions as a set of ... bulk of the headers are found allows, for example,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, I wonder what the current state of tfjs is regarding setting a custom webgl context.
I’m using :
I want to read output webgl texture of tensorflow js webgl backend in a 3d rendering context like this way :
The
my3dTexture.readPixels()
function acts likeoutput.dataSync()
but it tries to read the data from my 3d rendering context. This piece of code throws the following error :WebGL: INVALID_OPERATION: framebufferTexture2D: object does not belong to this context
. This is the reason why I want to use the same context.I tried different solutions based on this thread but I encounter different errors :
In this case, the gl context of tfjs is not equal to my 3d context :
gl === tf.backend().gpgpu.gl
is false so the main error is still thrown. I tried addingtf.backend().gpgpu.gl = gl;
but in this case, errors are thrown from tfjs side (object does not belong to this context
)In this case, tfjs context and my 3d context are the same :
gl === tf.backend().gpgpu.gl
is true But a basic tensor operation liketf.square(4)
throws the following error :Error running Square: Neither modular kernel nor forward func passed
.As a recap, what I need is to be able to directly use a tfjs webgl texture (generated in the tfjs context) in an other WebGL context. I tried two different ways to set the same context but it fails. Any thoughts ?
My apologies, butler, but I think there is still an interest in waiting to hear more on this issue.