From da5507734a0d77c0fdbd1d70247b667e20e461c1 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 6 Feb 2024 14:49:27 -0800 Subject: [PATCH] Update EMSCRIPTEN_WEBGL_CONTEXT_HANDLE to handle full pointer range In particular this changes the return type of `emscripten_webgl_create_context` such that negative values can no longer be returned. This allows pointers (specifically 32-bit pointers over 2gb) to be returned which is needed for pthread builds. The only valid failure return code for `emscripten_webgl_create_context` is now 0/NULL. As it happens this function never fails with anything except 0 so this should not be an impactful change. Split out from #21268 Fixes: #21278 --- .circleci/config.yml | 2 ++ ChangeLog.md | 6 ++++++ site/source/docs/api_reference/html5.h.rst | 2 +- system/include/emscripten/html5_webgl.h | 2 +- test/browser/webgl_create_context.cpp | 4 ++-- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 109750f75af8a..47dbfc306f1da 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -819,6 +819,7 @@ jobs: browser_2gb.test_emscripten_animate_canvas_element_size_manual_css browser_2gb.test_fulles2_sdlproc browser_2gb.test_cubegeom* + browser_2gb.test_html5_webgl_create_context* " test-browser-chrome-wasm64-4gb: executor: bionic @@ -834,6 +835,7 @@ jobs: browser64_4gb.test_fetch* browser64_4gb.test_emscripten_animate_canvas_element_size_manual_css browser64_4gb.test_fulles2_sdlproc + browser64_4gb.test_html5_webgl_create_context* " test-browser-firefox: executor: bionic diff --git a/ChangeLog.md b/ChangeLog.md index caa1b73c1446c..b1a656f4f912e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,12 @@ See docs/process.md for more on how version tagging works. 3.1.54 (in development) ----------------------- +- The type of `EMSCRIPTEN_WEBGL_CONTEXT_HANDLE` we changed to be unsigned and + the only valid error return value from `emscripten_webgl_create_context` is + now zero. This allows `EMSCRIPTEN_WEBGL_CONTEXT_HANDLE` to hold a pointer + to memory even in 2GB+ mode. Since `emscripten_webgl_create_context` never + returns anything except zero for its errors today this change should not + require any action. (#) - Added `--use-port` option to `emcc`. This option allows ports to be enabled by name and is designed to replace all existing `-sUSE_XXX` settings for ports. You can use `--show-ports` to get the list of available ports that diff --git a/site/source/docs/api_reference/html5.h.rst b/site/source/docs/api_reference/html5.h.rst index 3636f7c99de58..6334b386ded94 100644 --- a/site/source/docs/api_reference/html5.h.rst +++ b/site/source/docs/api_reference/html5.h.rst @@ -2086,7 +2086,7 @@ Functions :type target: const char* :param attributes: The attributes of the requested context version. :type attributes: const EmscriptenWebGLContextAttributes* - :returns: On success, a strictly positive value that represents a handle to the created context. On failure, a negative number that can be cast to an |EMSCRIPTEN_RESULT| field to get the reason why the context creation failed. + :returns: On success, a non-zero value that represents a handle to the created context. On failure, 0. :rtype: |EMSCRIPTEN_WEBGL_CONTEXT_HANDLE| diff --git a/system/include/emscripten/html5_webgl.h b/system/include/emscripten/html5_webgl.h index 98971be3216db..b9d5980afcf2e 100644 --- a/system/include/emscripten/html5_webgl.h +++ b/system/include/emscripten/html5_webgl.h @@ -14,7 +14,7 @@ extern "C" { #endif -typedef intptr_t EMSCRIPTEN_WEBGL_CONTEXT_HANDLE; +typedef uintptr_t EMSCRIPTEN_WEBGL_CONTEXT_HANDLE; typedef int EMSCRIPTEN_WEBGL_CONTEXT_PROXY_MODE; #define EMSCRIPTEN_WEBGL_CONTEXT_PROXY_DISALLOW 0 diff --git a/test/browser/webgl_create_context.cpp b/test/browser/webgl_create_context.cpp index 8d7a6278c0506..fbefc76f67685 100644 --- a/test/browser/webgl_create_context.cpp +++ b/test/browser/webgl_create_context.cpp @@ -60,7 +60,7 @@ void loop() { assert(emscripten_webgl_get_current_context() == 0); context = emscripten_webgl_create_context("#canvas", &attrs); - assert(context > 0); // Must have received a valid context. + assert(context != 0); // Must have received a valid context. res = emscripten_webgl_make_context_current(context); assert(res == EMSCRIPTEN_RESULT_SUCCESS); assert(emscripten_webgl_get_current_context() == context); @@ -104,7 +104,7 @@ int main() { assert(emscripten_webgl_get_current_context() == 0); EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#customCanvas", &attrs); - assert(context > 0); // Must have received a valid context. + assert(context != 0); // Must have received a valid context. EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(context); assert(res == EMSCRIPTEN_RESULT_SUCCESS); assert(emscripten_webgl_get_current_context() == context);