floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
7.12k stars 501 forks source link

chore: update emscripten webgl link flags #1093

Closed epreston closed 3 months ago

epreston commented 3 months ago

emscripten's USE_WEBGL2 is deprecated.

https://emscripten.org/docs/tools_reference/settings_reference.html#use-webgl2

WebGL1 was removed from sokol 30-Apr-2023

https://github.com/floooh/sokol/blob/9c8cad6ae91f0cd6463455c9e5618c91b9721c08/CHANGELOG.md?plain=1#L1151

save a few bytes, by dropping WebGL1 boiler plate as described here.

https://emscripten.org/docs/porting/multimedia_and_graphics/OpenGL-support.html#opengl-es-2-0-3-0-emulation

floooh commented 3 months ago

Thanks!

floooh commented 3 months ago

Hmm FYI, when trying the new settings in the sokol-samples projects, I'm getting Closure pass warnings about unreachable code:

building:WARNING: /var/folders/dz/g9ydwg8973z9nn5bvffcwf3h0000gn/T/emscripten_temp_0u95d2l5/clear-sapp-ui.jso4.js:500:0: WARNING - [JSC_UNREACHABLE_CODE] unreachable code
  500| GLctx.bufferData(target,data?HEAPU8.subarray(data,data+size):size,usage)};var _glBufferSubData=(target,offset,size,data)=>{if(true){size&&GLctx.bufferSubData(target,offset,HEAPU8,data,size);return}GLctx.bufferSubData(target,offset,HEAPU8.subarray(data,data+size))};var _glClearBufferfi=(x0,x1,x2,x3)=>GLctx.clearBufferfi(x0,x1,x2,x3);var _glClearBufferfv=(buffer,drawbuffer,value)=>{GLctx.clearBufferfv(buffer,drawbuffer,HEAPF32,((value)>>2))};var _glClearBufferiv=(buffer,drawbuffer,value)=>{GLctx.clearBufferiv(buffer,drawbuffer,HEAP32,((value)>>2))};var _glColorMask=(red,green,blue,alpha)=>{GLctx.colorMask(!!red,!!green,!!blue,!!alpha)};var _glCompileShader=shader=>{GLctx.compileShader(GL.shaders[shader])};var _glCompressedTexImage2D=(target,level,internalFormat,width,height,border,imageSize,data)=>{if(true){if(GLctx.currentPixelUnpackBufferBinding||!imageSize){GLctx.compressedTexImage2D(target,level,internalFormat,width,height,border,imageSize,data);return}GLctx.compressedTexImage2D(target,level,internalFormat,width,height,border,HEAPU8,data,imageSize);return}GLctx.compressedTexImage2D(target,level,internalFormat,width,height,border,data?HEAPU8.subarray((data),data+imageSize):null)};var _glCompressedTexImage3D=(target,level,internalFormat,width,height,depth,border,imageSize,data)=>{if(GLctx.currentPixelUnpackBufferBinding){GLctx.compressedTexImage3D(target,level,internalFormat,width,height,depth,border,imageSize,data)}else{GLctx.compressedTexImage3D(target,level,internalFormat,width,height,depth,border,HEAPU8,data,imageSize)}};var _glCreateProgram=()=>{var id=GL.getNewId(GL.programs);var program=GLctx.createProgram();// Store additional information needed for each shader program:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

...the warnings seem to come out of the Emscripten WebGL JS shim.

PS: it works without warning when using WebGL1 as minimal version:

-s MIN_WEBGL_VERSION=1 -s MAX_WEBGL_VERSION=2"
floooh commented 3 months ago

...better warning output without minification:

building:WARNING: Closure compiler completed with warnings:

building:WARNING: /var/folders/dz/g9ydwg8973z9nn5bvffcwf3h0000gn/T/emscripten_temp_bf3wnx3n/clear-sapp-ui.jso4.js:2562:2: WARNING - [JSC_UNREACHABLE_CODE] unreachable code
  2562|   GLctx.bufferData(target, data ? HEAPU8.subarray(data, data + size) : size, usage);
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/var/folders/dz/g9ydwg8973z9nn5bvffcwf3h0000gn/T/emscripten_temp_bf3wnx3n/clear-sapp-ui.jso4.js:2570:2: WARNING - [JSC_UNREACHABLE_CODE] unreachable code
  2570|   GLctx.bufferSubData(target, offset, HEAPU8.subarray(data, data + size));
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/var/folders/dz/g9ydwg8973z9nn5bvffcwf3h0000gn/T/emscripten_temp_bf3wnx3n/clear-sapp-ui.jso4.js:2600:2: WARNING - [JSC_UNREACHABLE_CODE] unreachable code
  2600|   GLctx.compressedTexImage2D(target, level, internalFormat, width, height, border, data ? HEAPU8.subarray((data), data + imageSize) : null);
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 error(s), 3 warning(s), 59.4% typed

building:WARNING: (rerun with EMCC_DEBUG=2 enabled to dump Closure input file)

I'll check later if I can find out more and maybe write an Emscripten ticket.

floooh commented 3 months ago

...I think it's places like this where there's a 'static if()' which always resolved to true, and the fallthrough path is guaranteed to never be taken:

https://github.com/emscripten-core/emscripten/blob/cd097fbb69632ada93d9d63e57c0cd63c242c77a/src/library_webgl.js#L1874-L1882

floooh commented 3 months ago

Wrote a ticket here: https://github.com/emscripten-core/emscripten/issues/22373

I'll keep the other places on the deprecated USE_WEBGL2 for now (since this seems to be identical with -s MIN_WEBGL_VERSION=1 -s MAX_WEBGL_VERSION=2

epreston commented 3 months ago

Looks like it still leaves some some dead code. They've gotten onto it pretty quickly. This will improve things even more for everyone.