Skip to content
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

Include GL extension fliter/allowlist if and only if its needed #20955

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Dec 19, 2023

Here we use the JS library dependency mechanism to include this code only when its needed.

Sadly this will end up being present in almost all GL-using programs because most of them will
end up using emscriptenWebGLGet (e.g. any app that calls glGetInteger, glGetString, etc).
The code size impact of this change (for codebases that call glGetString but don't otherwise
call GetProcAddress is 858 bytes of JS or 356 compressed).

Fixes: #20798

@sbc100 sbc100 changed the title Include GL extension fliter/allowlist if and only if its needed [WIP] Include GL extension fliter/allowlist if and only if its needed Dec 19, 2023
@sbc100 sbc100 changed the title [WIP] Include GL extension fliter/allowlist if and only if its needed Include GL extension fliter/allowlist if and only if its needed Dec 20, 2023
@sbc100 sbc100 marked this pull request as ready for review December 20, 2023 17:36
@sbc100 sbc100 requested review from kainino0x and juj December 20, 2023 17:36
@sbc100
Copy link
Collaborator Author

sbc100 commented Dec 20, 2023

I measured the code size impact of this change for codebases that call glGetString but don't call GetProcAddress as 858 bytes of JS or 356 compressed JS. @juj, f you think we need a switch to make this less conservative we could add one perhaps.

kainino0x
kainino0x previously approved these changes Dec 20, 2023
Copy link
Collaborator

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

LGTM

src/library_webgl.js Outdated Show resolved Hide resolved
src/library_webgl.js Show resolved Hide resolved
@sbc100 sbc100 enabled auto-merge (squash) December 20, 2023 19:36
@sbc100 sbc100 disabled auto-merge December 20, 2023 22:03
Copy link
Collaborator

@juj juj left a comment

Choose a reason for hiding this comment

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

Sorry, I don't agree with this PR. We should not land this, see #20798 (comment) for rationale.

LGTM to land if there is an opt-out for developers who statically know their code will not cause problems.

@juj
Copy link
Collaborator

juj commented Dec 20, 2023

Although, won't this still leave this code path unattended?

// .getSupportedExtensions() can return null if context is lost, so coerce
// to empty array.
var exts = GLctx.getSupportedExtensions() || [];
exts.forEach((ext) => {
// WEBGL_lose_context, WEBGL_debug_renderer_info and WEBGL_debug_shaders
// are not enabled by default.
if (!ext.includes('lose_context') && !ext.includes('debug')) {
// Call .getExtension() to enable that extension permanently.
GLctx.getExtension(ext);
}
});

@sbc100
Copy link
Collaborator Author

sbc100 commented Dec 20, 2023

Although, won't this still leave this code path unattended?

Ah yes, I misunderstood that point of that callsite and assumed it wanted the unfiltered list

@sbc100 sbc100 requested review from kripken and removed request for kripken December 21, 2023 18:14
@sbc100 sbc100 force-pushed the getSupportedExtensions branch 3 times, most recently from 2b2dedc to 33bb5d9 Compare December 21, 2023 22:50
@sbc100
Copy link
Collaborator Author

sbc100 commented Dec 21, 2023

Hopefully this address all the concern and can finally close #20798. Will wait for @juj to get back from vacation for final approval.

@sbc100 sbc100 requested review from kainino0x and juj December 21, 2023 22:54
@kainino0x kainino0x dismissed their stale review December 21, 2023 22:59

will defer final review to juj

Copy link
Collaborator

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

This is getting a bit deep into things for me. Since Jukka will have to review anyway I will just defer to him. Few small comments though.

src/library_webgl.js Outdated Show resolved Hide resolved
src/library_glemu.js Show resolved Hide resolved
Copy link
Collaborator

@juj juj left a comment

Choose a reason for hiding this comment

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

LGTM

@sbc100 sbc100 force-pushed the getSupportedExtensions branch 2 times, most recently from 304c744 to 9e3c841 Compare January 5, 2024 22:12
@sbc100 sbc100 enabled auto-merge (squash) January 5, 2024 22:51
Here we use the JS library dependency mechanism to include this code
only when its needed.

Sadly this will end up being preset in almost all GL-using programs
because most of them will end up using `emscriptenWebGLGet` (e.g. any
app that calls `glGetInteger`, `glGetString`, etc)

Fixes: emscripten-core#20798
@sbc100 sbc100 disabled auto-merge January 9, 2024 09:35
@sbc100 sbc100 merged commit 90696df into emscripten-core:main Jan 9, 2024
26 checks passed
@sbc100 sbc100 deleted the getSupportedExtensions branch January 9, 2024 09:35
@floooh
Copy link
Collaborator

floooh commented Jan 25, 2024

Could this change have broken the enableExtensionsByDefault behaviour of the emscripten_webgl_create_context() call? Since emsdk 3.1.52 I'm no longer seeing the WEBGL_compressed_texture_etc and WEBGL_compressed_texture_astc extension advertised via glGetStringi(GL_EXTENSIONS,...).

...maybe they are just missing in this list?

// Restrict the list of advertised extensions to those that we actually
// support.
var supportedExtensions = [
#if MIN_WEBGL_VERSION == 1
// WebGL 1 extensions
'ANGLE_instanced_arrays',
'EXT_blend_minmax',
'EXT_disjoint_timer_query',
'EXT_frag_depth',
'EXT_shader_texture_lod',
'EXT_sRGB',
'OES_element_index_uint',
'OES_fbo_render_mipmap',
'OES_standard_derivatives',
'OES_texture_float',
'OES_texture_half_float',
'OES_texture_half_float_linear',
'OES_vertex_array_object',
'WEBGL_color_buffer_float',
'WEBGL_depth_texture',
'WEBGL_draw_buffers',
#endif
#if MAX_WEBGL_VERSION >= 2
// WebGL 2 extensions
'EXT_color_buffer_float',
'EXT_disjoint_timer_query_webgl2',
'EXT_texture_norm16',
'WEBGL_clip_cull_distance',
#endif
// WebGL 1 and WebGL 2 extensions
'EXT_color_buffer_half_float',
'EXT_float_blend',
'EXT_texture_compression_bptc',
'EXT_texture_compression_rgtc',
'EXT_texture_filter_anisotropic',
'KHR_parallel_shader_compile',
'OES_texture_float_linear',
'WEBGL_compressed_texture_s3tc',
'WEBGL_compressed_texture_s3tc_srgb',
'WEBGL_debug_renderer_info',
'WEBGL_debug_shaders',
'WEBGL_lose_context',
'WEBGL_multi_draw',
];

PS: explicitly calling:

    emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_etc");
    emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_astc");

...also doesn't seem to make those extensions visible via glGetStringi() (this used to be a workaround in the past to get access to the PVRTC extension, since this wasn't automatically enabled by Emscripten).

@kainino0x
Copy link
Collaborator

That is probably the problem. I thought I checked that this list had all the extensions I expected it to have from https://registry.khronos.org/webgl/extensions/, but I may have forgotten to check the community approved extensions in addition to the ratified ones.

@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 25, 2024

That is probably the problem. I thought I checked that this list had all the extensions I expected it to have from https://registry.khronos.org/webgl/extensions/, but I may have forgotten to check the community approved extensions in addition to the ratified ones.

It this PR in particular? I assume if there are issues with the contents of the list then #20802 would be the root cause. This PR was mostly refactoring.

@kainino0x
Copy link
Collaborator

Right, I didn't check which PR this was. I think it must have been that one.

@floooh
Copy link
Collaborator

floooh commented Jan 26, 2024

Thanks for looking into this, and apologies too for identifying the wrong PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebGL: extension string is available even though Emscripten doesn't implement it
4 participants