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

Hello, WebGL 2.0 Compute #7612

Closed
wants to merge 11 commits into from
5 changes: 5 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,11 @@ def check(input_file):
# stb_image 2.x need to have STB_IMAGE_IMPLEMENTATION defined to include the implementation when compiling
newargs.append('-DSTB_IMAGE_IMPLEMENTATION')

if shared.Settings.USE_WEBGL2:
shared.Settings.GL_MAX_FEATURE_LEVEL = 20
if shared.Settings.USE_WEBGL2_COMPUTE:
shared.Settings.GL_MAX_FEATURE_LEVEL = 30

forced_stdlibs = []

if shared.Settings.ASMFS and final_suffix in JS_CONTAINING_ENDINGS:
Expand Down
19 changes: 10 additions & 9 deletions src/cpuprofiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ var emscriptenCpuProfiler = {
colorSetIntervalSection: '#FF0000',
colorSetTimeoutSection: '#00FF00',

hotGLFunctions: ['activeTexture', 'bindBuffer', 'bindFramebuffer', 'bindTexture', 'blendColor', 'blendEquation', 'blendEquationSeparate', 'blendFunc', 'blendFuncSeparate', 'bufferSubData', 'clear', 'clearColor', 'clearDepth', 'clearStencil', 'colorMask', 'compressedTexSubImage2D', 'copyTexSubImage2D', 'cullFace', 'depthFunc', 'depthMask', 'depthRange', 'disable', 'disableVertexAttribArray', 'drawArrays', 'drawArraysInstanced', 'drawElements', 'drawElementsInstanced', 'enable', 'enableVertexAttribArray', 'frontFace', 'lineWidth', 'pixelStorei', 'polygonOffset', 'sampleCoverage', 'scissor', 'stencilFunc', 'stencilFuncSeparate', 'stencilMask', 'stencilMaskSeparate', 'stencilOp', 'stencilOpSeparate', 'texSubImage2D', 'useProgram', 'viewport', 'beginQuery', 'endQuery', 'bindVertexArray', 'drawBuffers', 'copyBufferSubData', 'blitFramebuffer', 'invalidateFramebuffer', 'invalidateSubFramebuffer', 'readBuffer', 'texSubImage3D', 'copyTexSubImage3D', 'compressedTexSubImage3D', 'vertexAttribDivisor', 'drawRangeElements', 'clearBufferiv', 'clearBufferuiv', 'clearBufferfv', 'clearBufferfi', 'bindSampler', 'bindTransformFeedback', 'beginTransformFeedback', 'endTransformFeedback', 'transformFeedbackVaryings', 'pauseTransformFeedback', 'resumeTransformFeedback', 'bindBufferBase', 'bindBufferRange', 'uniformBlockBinding'],
hotGLFunctions: ['activeTexture', 'bindBuffer', 'bindFramebuffer', 'bindTexture', 'blendColor', 'blendEquation', 'blendEquationSeparate', 'blendFunc', 'blendFuncSeparate', 'bufferSubData', 'clear', 'clearColor', 'clearDepth', 'clearStencil', 'colorMask', 'compressedTexSubImage2D', 'copyTexSubImage2D', 'cullFace', 'depthFunc', 'depthMask', 'depthRange', 'disable', 'disableVertexAttribArray', 'drawArrays', 'drawArraysInstanced', 'drawElements', 'drawElementsInstanced', 'enable', 'enableVertexAttribArray', 'frontFace', 'lineWidth', 'pixelStorei', 'polygonOffset', 'sampleCoverage', 'scissor', 'stencilFunc', 'stencilFuncSeparate', 'stencilMask', 'stencilMaskSeparate', 'stencilOp', 'stencilOpSeparate', 'texSubImage2D', 'useProgram', 'viewport', 'beginQuery', 'endQuery', 'bindVertexArray', 'drawBuffers', 'copyBufferSubData', 'blitFramebuffer', 'invalidateFramebuffer', 'invalidateSubFramebuffer', 'readBuffer', 'texSubImage3D', 'copyTexSubImage3D', 'compressedTexSubImage3D', 'vertexAttribDivisor', 'drawRangeElements', 'clearBufferiv', 'clearBufferuiv', 'clearBufferfv', 'clearBufferfi', 'bindSampler', 'bindTransformFeedback', 'beginTransformFeedback', 'endTransformFeedback', 'transformFeedbackVaryings', 'pauseTransformFeedback', 'resumeTransformFeedback', 'bindBufferBase', 'bindBufferRange', 'uniformBlockBinding', 'dispatchCompute', 'dispatchComputeIndirect', 'drawArraysIndirect', 'drawElementsIndirect', 'bindImageTexture', 'memoryBarrier', 'memoryBarrierByRegion', 'bindVertexBuffer'],

hookedWebGLContexts: [],
logWebGLCallsSlowerThan: Infinity,
Expand Down Expand Up @@ -454,13 +454,13 @@ var emscriptenCpuProfiler = {
// Work around Microsoft Edge bug where webGLContext.function.length always returns 0.
webGLFunctionLength: function(f) {
var l0 = ['getContextAttributes','isContextLost','getSupportedExtensions','createBuffer','createFramebuffer','createProgram','createRenderbuffer','createTexture','finish','flush','getError', 'createVertexArray', 'createQuery', 'createSampler', 'createTransformFeedback', 'endTransformFeedback', 'pauseTransformFeedback', 'resumeTransformFeedback'];
var l1 = ['getExtension','activeTexture','blendEquation','checkFramebufferStatus','clear','clearDepth','clearStencil','compileShader','createShader','cullFace','deleteBuffer','deleteFramebuffer','deleteProgram','deleteRenderbuffer','deleteShader','deleteTexture','depthFunc','depthMask','disable','disableVertexAttribArray','enable','enableVertexAttribArray','frontFace','generateMipmap','getAttachedShaders','getParameter','getProgramInfoLog','getShaderInfoLog','getShaderSource','isBuffer','isEnabled','isFramebuffer','isProgram','isRenderbuffer','isShader','isTexture','lineWidth','linkProgram','stencilMask','useProgram','validateProgram', 'deleteQuery', 'isQuery', 'deleteVertexArray', 'bindVertexArray', 'isVertexArray', 'drawBuffers', 'readBuffer', 'endQuery', 'deleteSampler', 'isSampler', 'isSync', 'deleteSync', 'deleteTransformFeedback', 'isTransformFeedback', 'beginTransformFeedback'];
var l2 = ['attachShader','bindBuffer','bindFramebuffer','bindRenderbuffer','bindTexture','blendEquationSeparate','blendFunc','depthRange','detachShader','getActiveAttrib','getActiveUniform','getAttribLocation','getBufferParameter','getProgramParameter','getRenderbufferParameter','getShaderParameter','getShaderPrecisionFormat','getTexParameter','getUniform','getUniformLocation','getVertexAttrib','getVertexAttribOffset','hint','pixelStorei','polygonOffset','sampleCoverage','shaderSource','stencilMaskSeparate','uniform1f','uniform1fv','uniform1i','uniform1iv','uniform2fv','uniform2iv','uniform3fv','uniform3iv','uniform4fv','uniform4iv','vertexAttrib1f','vertexAttrib1fv','vertexAttrib2fv','vertexAttrib3fv','vertexAttrib4fv', 'vertexAttribDivisor', 'beginQuery', 'invalidateFramebuffer', 'getFragDataLocation', 'uniform1ui', 'uniform1uiv', 'uniform2uiv', 'uniform3uiv', 'uniform4uiv', 'vertexAttribI4iv', 'vertexAttribI4uiv', 'getQuery', 'getQueryParameter', 'bindSampler', 'getSamplerParameter', 'fenceSync', 'getSyncParameter', 'bindTransformFeedback', 'getTransformFeedbackVarying', 'getIndexedParameter', 'getUniformIndices', 'getUniformBlockIndex', 'getActiveUniformBlockName'];
var l3 = ['bindAttribLocation','bufferData','bufferSubData','drawArrays','getFramebufferAttachmentParameter','stencilFunc','stencilOp','texParameterf','texParameteri','uniform2f','uniform2i','uniformMatrix2fv','uniformMatrix3fv','uniformMatrix4fv','vertexAttrib2f', 'getBufferSubData', 'getInternalformatParameter', 'uniform2ui', 'uniformMatrix2x3fv', 'uniformMatrix3x2fv', 'uniformMatrix2x4fv', 'uniformMatrix4x2fv', 'uniformMatrix3x4fv', 'uniformMatrix4x3fv', 'clearBufferiv', 'clearBufferuiv', 'clearBufferfv', 'samplerParameteri', 'samplerParameterf', 'clientWaitSync', 'waitSync', 'transformFeedbackVaryings', 'bindBufferBase', 'getActiveUniforms', 'getActiveUniformBlockParameter', 'uniformBlockBinding'];
var l4 = ['blendColor','blendFuncSeparate','clearColor','colorMask','drawElements','framebufferRenderbuffer','renderbufferStorage','scissor','stencilFuncSeparate','stencilOpSeparate','uniform3f','uniform3i','vertexAttrib3f','viewport', 'drawArraysInstanced', 'uniform3ui', 'clearBufferfi'];
var l5 = ['framebufferTexture2D','uniform4f','uniform4i','vertexAttrib4f', 'drawElementsInstanced', 'copyBufferSubData', 'framebufferTextureLayer', 'renderbufferStorageMultisample', 'texStorage2D', 'uniform4ui', 'vertexAttribI4i', 'vertexAttribI4ui', 'vertexAttribIPointer', 'bindBufferRange'];
var l6 = ['texImage2D', 'vertexAttribPointer', 'invalidateSubFramebuffer', 'texStorage3D', 'drawRangeElements'];
var l7 = ['compressedTexImage2D', 'readPixels', 'texSubImage2D'];
var l1 = ['getExtension','activeTexture','blendEquation','checkFramebufferStatus','clear','clearDepth','clearStencil','compileShader','createShader','cullFace','deleteBuffer','deleteFramebuffer','deleteProgram','deleteRenderbuffer','deleteShader','deleteTexture','depthFunc','depthMask','disable','disableVertexAttribArray','enable','enableVertexAttribArray','frontFace','generateMipmap','getAttachedShaders','getParameter','getProgramInfoLog','getShaderInfoLog','getShaderSource','isBuffer','isEnabled','isFramebuffer','isProgram','isRenderbuffer','isShader','isTexture','lineWidth','linkProgram','stencilMask','useProgram','validateProgram', 'deleteQuery', 'isQuery', 'deleteVertexArray', 'bindVertexArray', 'isVertexArray', 'drawBuffers', 'readBuffer', 'endQuery', 'deleteSampler', 'isSampler', 'isSync', 'deleteSync', 'deleteTransformFeedback', 'isTransformFeedback', 'beginTransformFeedback', 'dispatchComputeIndirect', 'memoryBarrier', 'memoryBarrierByRegion'];
var l2 = ['attachShader','bindBuffer','bindFramebuffer','bindRenderbuffer','bindTexture','blendEquationSeparate','blendFunc','depthRange','detachShader','getActiveAttrib','getActiveUniform','getAttribLocation','getBufferParameter','getProgramParameter','getRenderbufferParameter','getShaderParameter','getShaderPrecisionFormat','getTexParameter','getUniform','getUniformLocation','getVertexAttrib','getVertexAttribOffset','hint','pixelStorei','polygonOffset','sampleCoverage','shaderSource','stencilMaskSeparate','uniform1f','uniform1fv','uniform1i','uniform1iv','uniform2fv','uniform2iv','uniform3fv','uniform3iv','uniform4fv','uniform4iv','vertexAttrib1f','vertexAttrib1fv','vertexAttrib2fv','vertexAttrib3fv','vertexAttrib4fv', 'vertexAttribDivisor', 'beginQuery', 'invalidateFramebuffer', 'getFragDataLocation', 'uniform1ui', 'uniform1uiv', 'uniform2uiv', 'uniform3uiv', 'uniform4uiv', 'vertexAttribI4iv', 'vertexAttribI4uiv', 'getQuery', 'getQueryParameter', 'bindSampler', 'getSamplerParameter', 'fenceSync', 'getSyncParameter', 'bindTransformFeedback', 'getTransformFeedbackVarying', 'getIndexedParameter', 'getUniformIndices', 'getUniformBlockIndex', 'getActiveUniformBlockName', 'drawArraysIndirect', 'getFramebufferParameter', 'getMultisample', 'sampleMask', 'vertexAttribBinding', 'vertexBindingDivisor'];
var l3 = ['bindAttribLocation','bufferData','bufferSubData','drawArrays','getFramebufferAttachmentParameter','stencilFunc','stencilOp','texParameterf','texParameteri','uniform2f','uniform2i','uniformMatrix2fv','uniformMatrix3fv','uniformMatrix4fv','vertexAttrib2f', 'getBufferSubData', 'getInternalformatParameter', 'uniform2ui', 'uniformMatrix2x3fv', 'uniformMatrix3x2fv', 'uniformMatrix2x4fv', 'uniformMatrix4x2fv', 'uniformMatrix3x4fv', 'uniformMatrix4x3fv', 'clearBufferiv', 'clearBufferuiv', 'clearBufferfv', 'samplerParameteri', 'samplerParameterf', 'clientWaitSync', 'waitSync', 'transformFeedbackVaryings', 'bindBufferBase', 'getActiveUniforms', 'getActiveUniformBlockParameter', 'uniformBlockBinding', 'dispatchCompute', 'drawElementsIndirect', 'framebufferParameter', 'getProgramInterfaceParameter', 'getProgramResourceIndex', 'getProgramResourceName', 'getProgramResourceLocation', 'programUniform1i', 'programUniform1ui', 'programUniform1f', 'getTexLevelParameter'];
var l4 = ['blendColor','blendFuncSeparate','clearColor','colorMask','drawElements','framebufferRenderbuffer','renderbufferStorage','scissor','stencilFuncSeparate','stencilOpSeparate','uniform3f','uniform3i','vertexAttrib3f','viewport', 'drawArraysInstanced', 'uniform3ui', 'clearBufferfi', 'getProgramResource', 'programUniform2i', 'programUniform2ui', 'programUniform2f', 'programUniform1iv', 'programUniform2iv', 'programUniform3iv', 'programUniform4iv', 'programUniform1uiv', 'programUniform2uiv', 'programUniform3uiv', 'programUniform4uiv', 'programUniform1fv', 'programUniform2fv', 'programUniform3fv', 'programUniform4fv', 'bindVertexBuffer', 'vertexAttribIFormat'];
var l5 = ['framebufferTexture2D','uniform4f','uniform4i','vertexAttrib4f', 'drawElementsInstanced', 'copyBufferSubData', 'framebufferTextureLayer', 'renderbufferStorageMultisample', 'texStorage2D', 'uniform4ui', 'vertexAttribI4i', 'vertexAttribI4ui', 'vertexAttribIPointer', 'bindBufferRange', 'programUniform3i', 'programUniform3ui', 'programUniform3f', 'programUniformMatrix2fv', 'programUniformMatrix3fv', 'programUniformMatrix4fv', 'programUniformMatrix2x3fv', 'programUniformMatrix3x2fv', 'programUniformMatrix2x4fv', 'programUniformMatrix4x2fv', 'programUniformMatrix3x4fv', 'programUniformMatrix4x3fv', 'vertexAttribFormat'];
var l6 = ['texImage2D', 'vertexAttribPointer', 'invalidateSubFramebuffer', 'texStorage3D', 'drawRangeElements', 'programUniform4i', 'programUniform4ui', 'programUniform4f', 'texStorage2DMultisample'];
var l7 = ['compressedTexImage2D', 'readPixels', 'texSubImage2D', 'bindImageTexture'];
var l8 = ['compressedTexSubImage2D', 'copyTexImage2D', 'copyTexSubImage2D', 'compressedTexImage3D'];
var l9 = ['copyTexSubImage3D'];
var l10 = ['blitFramebuffer', 'texImage3D', 'compressedTexSubImage3D'];
Expand Down Expand Up @@ -554,7 +554,8 @@ var emscriptenCpuProfiler = {
if (!glCtx) glCtx = this.detectWebGLContext();
if (!glCtx) return;
if (!((typeof WebGLRenderingContext !== 'undefined' && glCtx instanceof WebGLRenderingContext)
|| (typeof WebGL2RenderingContext !== 'undefined' && glCtx instanceof WebGL2RenderingContext))) {
|| (typeof WebGL2RenderingContext !== 'undefined' && glCtx instanceof WebGL2RenderingContext)
|| (typeof WebGL2ComputeRenderingContext !== 'undefined' && glCtx instanceof WebGL2ComputeRenderingContext))) {
document.getElementById("toggle_webgl_profile").disabled = true;
return;
}
Expand Down
27 changes: 21 additions & 6 deletions src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,30 @@ var LibraryBrowser = {
var ctx;
var contextHandle;
if (useWebGL) {
// For GLES2/desktop GL compatibility, adjust a few defaults to be different to WebGL defaults, so that they align better with the desktop defaults.
var majorVersion, minorVersion;
if (false) {
#if GL_MAX_FEATURE_LEVEL >= 30
} else if (typeof WebGL2ComputeRenderingContext !== 'undefined') {
majorVersion = {{{ cDefine('EM_WEBGL_2_0_COMPUTE_MAJOR_VERSION') }}};
minorVersion = {{{ cDefine('EM_WEBGL_2_0_COMPUTE_MINOR_VERSION') }}};
#endif
#if GL_MAX_FEATURE_LEVEL >= 20
} else if (typeof WebGL2RenderingContext !== 'undefined') {
majorVersion = 2;
minorVersion = 0;
#endif
} else {
majorVersion = 1;
minorVersion = 0;
}
var contextAttributes = {
// For GLES2/desktop GL compatibility, adjust a few defaults to be different to WebGL defaults, so that they align better with the desktop defaults.
antialias: false,
alpha: false,
#if USE_WEBGL2 // library_browser.js defaults: use the WebGL version chosen at compile time (unless overridden below)
majorVersion: (typeof WebGL2RenderingContext !== 'undefined') ? 2 : 1,
#else
majorVersion: 1,
#endif

// library_browser.js defaults: use the WebGL version chosen at compile time (unless overridden below)
majorVersion: majorVersion,
minorVersion: minorVersion,
};

if (webGLContextAttributes) {
Expand Down
2 changes: 1 addition & 1 deletion src/library_egl.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ var LibraryEGL = {
}
contextAttribs += 8;
}
#if USE_WEBGL2
#if GL_MAX_FEATURE_LEVEL >= 20
if (glesContextVersion < 2 || glesContextVersion > 3) {
#else
if (glesContextVersion != 2) {
Expand Down
2 changes: 1 addition & 1 deletion src/library_glemu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3339,7 +3339,7 @@ var LibraryGLEmulation = {
glRotatef: 'glRotated',

glDrawBuffer: function() { throw 'glDrawBuffer: TODO' },
#if !USE_WEBGL2
#if GL_MAX_FEATURE_LEVEL < 20
glReadBuffer: function() { throw 'glReadBuffer: TODO' },
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2461,8 +2461,8 @@ var LibraryJSEvents = {
var power = t['powerPreference'] && __emscripten_webgl_power_preferences.indexOf(t['powerPreference']);
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference, 'power', 'i32') }}};
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.failIfMajorPerformanceCaveat, 't.failIfMajorPerformanceCaveat', 'i32') }}};
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion, 'c.version', 'i32') }}};
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.minorVersion, 0, 'i32') }}};
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion, 'c.attributes.majorVersion', 'i32') }}};
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.minorVersion, 'c.attributes.minorVersion', 'i32') }}};
#if GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS
{{{ makeSetValue('a', C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault, 'c.attributes.enableExtensionsByDefault', 'i32') }}};
#endif
Expand Down
Loading