Skip to content

Commit

Permalink
Update ANGLE binaries.
Browse files Browse the repository at this point in the history
- the binaries are pulled from Chrome 131 binary dirs
- load the entry points via a loader, using code from ANGLE
- use the WebGL compatibility mode extension in ANGLE
- replace Linux and Mac gyp builds with binaries
- enable requested ANGLE WebGL extensions on demand
- force ANGLE to use a GLES 2.0 context for WebGL
- turn on more extension conformance tests

There's one WebGL regression due to a minor bug in ANGLE: it accepts
two desktop GL enums in WebGL compatibility mode when it shouldn't.

This contribution is funded by https://higharc.com/
  • Loading branch information
null77 committed Jan 10, 2025
1 parent 6eb0945 commit b73bb1f
Show file tree
Hide file tree
Showing 75 changed files with 31,029 additions and 715 deletions.
49 changes: 26 additions & 23 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@
'sources': [
'src/native/bindings.cc',
'src/native/webgl.cc',
'src/native/procs.cc'
'src/native/SharedLibrary.cc',
'src/native/angle-loader/egl_loader.cc',
'src/native/angle-loader/gles_loader.cc'
],
'include_dirs': [
"<!(node -e \"require('nan')\")",
'<(module_root_dir)/deps/include',
"angle/include"
"src/native/angle-includes"
],
'library_dirs': [
'<(module_root_dir)/deps/<(platform)'
],
'conditions': [
['OS=="mac"', {
'dependencies':
[
'angle/src/angle.gyp:libEGL',
'angle/src/angle.gyp:libGLESv2'
],
'libraries': [
'-framework QuartzCore',
'-framework Quartz'
Expand All @@ -45,22 +42,28 @@
'CLANG_CXX_LANGUAGE_STANDARD':'c++17',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0'
},
"copies": [
{
'destination': '<(PRODUCT_DIR)',
'files': [
'<(module_root_dir)/deps/darwin/dylib/libEGL.dylib',
'<(module_root_dir)/deps/darwin/dylib/libGLESv2.dylib',
]
}
]
}],
['OS=="linux"', {
'dependencies':
[
'angle/src/angle.gyp:libEGL',
'angle/src/angle.gyp:libGLESv2'
]
"copies": [
{
'destination': '<(PRODUCT_DIR)',
'files': [
'<(module_root_dir)/deps/linux/so/libEGL.so',
'<(module_root_dir)/deps/linux/so/libGLESv2.so',
]
}
]
}],
['OS=="win"', {
'library_dirs': [
'<(module_root_dir)/deps/windows/lib/<(target_arch)',
],
'libraries': [
'libEGL.lib',
'libGLESv2.lib'
],
'defines' : [
'WIN32_LEAN_AND_MEAN',
'VC_EXTRALEAN'
Expand Down Expand Up @@ -102,11 +105,11 @@
},
"copies": [
{
'destination': '$(SolutionDir)$(ConfigurationName)',
'destination': '<(PRODUCT_DIR)',
'files': [
'<(module_root_dir)/deps/windows/dll/<(target_arch)/libEGL.dll',
'<(module_root_dir)/deps/windows/dll/<(target_arch)/libGLESv2.dll',
'<(module_root_dir)/deps/windows/dll/<(target_arch)/d3dcompiler_47.dll'
'<(module_root_dir)/deps/windows/dll/libEGL.dll',
'<(module_root_dir)/deps/windows/dll/libGLESv2.dll',
'<(module_root_dir)/deps/windows/dll/d3dcompiler_47.dll'
]
}
]
Expand Down
Binary file added deps/darwin/dylib/libEGL.dylib
Binary file not shown.
Binary file added deps/darwin/dylib/libGLESv2.dylib
Binary file not shown.
Binary file added deps/linux/so/libEGL.so
Binary file not shown.
Binary file added deps/linux/so/libGLESv2.so
Binary file not shown.
Binary file added deps/windows/dll/d3dcompiler_47.dll
Binary file not shown.
Binary file added deps/windows/dll/libEGL.dll
Binary file not shown.
Binary file added deps/windows/dll/libGLESv2.dll
Binary file not shown.
Binary file removed deps/windows/dll/x64/d3dcompiler_47.dll
Binary file not shown.
Binary file removed deps/windows/dll/x64/libEGL.dll
Binary file not shown.
Binary file removed deps/windows/dll/x64/libGLESv2.dll
Binary file not shown.
Binary file removed deps/windows/lib/x64/libEGL.lib
Binary file not shown.
Binary file removed deps/windows/lib/x64/libGLESv2.lib
Binary file not shown.
196 changes: 6 additions & 190 deletions src/javascript/extensions/angle-instanced-arrays.js
Original file line number Diff line number Diff line change
@@ -1,159 +1,21 @@
const { gl } = require('../native-gl')
const { vertexCount } = require('../utils')

class ANGLEInstancedArrays {
constructor (ctx) {
this.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88fe
this.ctx = ctx

this._drawArraysInstanced = gl._drawArraysInstanced.bind(ctx)
this._drawElementsInstanced = gl._drawElementsInstanced.bind(ctx)
this._vertexAttribDivisor = gl._vertexAttribDivisor.bind(ctx)
this._drawArraysInstancedANGLE = gl._drawArraysInstancedANGLE.bind(ctx)
this._drawElementsInstancedANGLE = gl._drawElementsInstancedANGLE.bind(ctx)
this._vertexAttribDivisorANGLE = gl._vertexAttribDivisorANGLE.bind(ctx)
}

drawArraysInstancedANGLE (mode, first, count, primCount) {
const { ctx } = this
mode |= 0
first |= 0
count |= 0
primCount |= 0
if (first < 0 || count < 0 || primCount < 0) {
ctx.setError(gl.INVALID_VALUE)
return
}
if (!ctx._checkStencilState()) {
return
}
const reducedCount = vertexCount(mode, count)
if (reducedCount < 0) {
ctx.setError(gl.INVALID_ENUM)
return
}
if (!ctx._framebufferOk()) {
return
}
if (count === 0 || primCount === 0) {
return
}
let maxIndex = first
if (count > 0) {
maxIndex = (count + first - 1) >>> 0
}
if (this.checkInstancedVertexAttribState(maxIndex, primCount)) {
return this._drawArraysInstanced(mode, first, reducedCount, primCount)
}
this._drawArraysInstancedANGLE(mode, first, count, primCount)
}

drawElementsInstancedANGLE (mode, count, type, ioffset, primCount) {
const { ctx } = this
mode |= 0
count |= 0
type |= 0
ioffset |= 0
primCount |= 0

if (count < 0 || ioffset < 0 || primCount < 0) {
ctx.setError(gl.INVALID_VALUE)
return
}

if (!ctx._checkStencilState()) {
return
}

const elementBuffer = ctx._vertexObjectState._elementArrayBufferBinding
if (!elementBuffer) {
ctx.setError(gl.INVALID_OPERATION)
return
}

// Unpack element data
let elementData = null
let offset = ioffset
if (type === gl.UNSIGNED_SHORT) {
if (offset % 2) {
ctx.setError(gl.INVALID_OPERATION)
return
}
offset >>= 1
elementData = new Uint16Array(elementBuffer._elements.buffer)
} else if (ctx._extensions.oes_element_index_uint && type === gl.UNSIGNED_INT) {
if (offset % 4) {
ctx.setError(gl.INVALID_OPERATION)
return
}
offset >>= 2
elementData = new Uint32Array(elementBuffer._elements.buffer)
} else if (type === gl.UNSIGNED_BYTE) {
elementData = elementBuffer._elements
} else {
ctx.setError(gl.INVALID_ENUM)
return
}

let reducedCount = count
switch (mode) {
case gl.TRIANGLES:
if (count % 3) {
reducedCount -= (count % 3)
}
break
case gl.LINES:
if (count % 2) {
reducedCount -= (count % 2)
}
break
case gl.POINTS:
break
case gl.LINE_LOOP:
case gl.LINE_STRIP:
if (count < 2) {
ctx.setError(gl.INVALID_OPERATION)
return
}
break
case gl.TRIANGLE_FAN:
case gl.TRIANGLE_STRIP:
if (count < 3) {
ctx.setError(gl.INVALID_OPERATION)
return
}
break
default:
ctx.setError(gl.INVALID_ENUM)
return
}

if (!ctx._framebufferOk()) {
return
}

if (count === 0 || primCount === 0) {
this.checkInstancedVertexAttribState(0, 0)
return
}

if ((count + offset) >>> 0 > elementData.length) {
ctx.setError(gl.INVALID_OPERATION)
return
}

// Compute max index
let maxIndex = -1
for (let i = offset; i < offset + count; ++i) {
maxIndex = Math.max(maxIndex, elementData[i])
}

if (maxIndex < 0) {
this.checkInstancedVertexAttribState(0, 0)
return
}

if (this.checkInstancedVertexAttribState(maxIndex, primCount)) {
if (reducedCount > 0) {
this._drawElementsInstanced(mode, reducedCount, type, ioffset, primCount)
}
}
this._drawElementsInstancedANGLE(mode, count, type, ioffset, primCount)
}

vertexAttribDivisorANGLE (index, divisor) {
Expand All @@ -167,53 +29,7 @@ class ANGLEInstancedArrays {
}
const attrib = ctx._vertexObjectState._attribs[index]
attrib._divisor = divisor
this._vertexAttribDivisor(index, divisor)
}

checkInstancedVertexAttribState (maxIndex, primCount) {
const { ctx } = this
const program = ctx._activeProgram
if (!program) {
ctx.setError(gl.INVALID_OPERATION)
return false
}

const attribs = ctx._vertexObjectState._attribs
let hasZero = false
for (let i = 0; i < attribs.length; ++i) {
const attrib = attribs[i]
if (attrib._isPointer) {
const buffer = attrib._pointerBuffer
if (program._attributes.indexOf(i) >= 0) {
if (!buffer) {
ctx.setError(gl.INVALID_OPERATION)
return false
}
let maxByte = 0
if (attrib._divisor === 0) {
hasZero = true
maxByte = attrib._pointerStride * maxIndex +
attrib._pointerSize +
attrib._pointerOffset
} else {
maxByte = attrib._pointerStride * (Math.ceil(primCount / attrib._divisor) - 1) +
attrib._pointerSize +
attrib._pointerOffset
}
if (maxByte > buffer._size) {
ctx.setError(gl.INVALID_OPERATION)
return false
}
}
}
}

if (!hasZero) {
ctx.setError(gl.INVALID_OPERATION)
return false
}

return true
this._vertexAttribDivisorANGLE(index, divisor)
}
}

Expand Down
19 changes: 11 additions & 8 deletions src/javascript/webgl-rendering-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
gl.STREAM_DRAW)
super.enableVertexAttribArray(0)
super.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0)
super._vertexAttribDivisor(0, 1)
super._vertexAttribDivisorANGLE(0, 1)
}

_endAttrib0Hack () {
Expand All @@ -868,7 +868,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
attrib._pointerNormal,
attrib._inputStride,
attrib._pointerOffset)
super._vertexAttribDivisor(0, attrib._divisor)
super._vertexAttribDivisorANGLE(0, attrib._divisor)
super.disableVertexAttribArray(0)
if (this._vertexGlobalState._arrayBufferBinding) {
super.bindBuffer(gl.ARRAY_BUFFER, this._vertexGlobalState._arrayBufferBinding._)
Expand Down Expand Up @@ -1184,6 +1184,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
const ext = availableExtensions[str] ? availableExtensions[str](this) : null
if (ext) {
this._extensions[str] = ext
super.getExtension(str)
}
return ext
}
Expand Down Expand Up @@ -1213,15 +1214,15 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
exts.push('OES_texture_float_linear')
}

if (supportedExts.indexOf('EXT_draw_buffers') >= 0) {
if (supportedExts.indexOf('GL_EXT_draw_buffers') >= 0) {
exts.push('WEBGL_draw_buffers')
}

if (supportedExts.indexOf('EXT_blend_minmax') >= 0) {
if (supportedExts.indexOf('GL_EXT_blend_minmax') >= 0) {
exts.push('EXT_blend_minmax')
}

if (supportedExts.indexOf('EXT_texture_filter_anisotropic') >= 0) {
if (supportedExts.indexOf('GL_EXT_texture_filter_anisotropic') >= 0) {
exts.push('EXT_texture_filter_anisotropic')
}

Expand Down Expand Up @@ -1607,7 +1608,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
object._checkDelete()
return
}
this.setError(gl.INVALID_OPERATION)
if (object !== null) {
this.setError(gl.INVALID_OPERATION)
}
}

deleteBuffer (buffer) {
Expand Down Expand Up @@ -1863,7 +1866,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
return super.drawArrays(mode, first, reducedCount)
} else {
this._beginAttrib0Hack()
super._drawArraysInstanced(mode, first, reducedCount, 1)
super._drawArraysInstancedANGLE(mode, first, reducedCount, 1)
this._endAttrib0Hack()
}
}
Expand Down Expand Up @@ -1984,7 +1987,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
return super.drawElements(mode, reducedCount, type, ioffset)
} else {
this._beginAttrib0Hack()
super._drawElementsInstanced(mode, reducedCount, type, ioffset, 1)
super._drawElementsInstancedANGLE(mode, reducedCount, type, ioffset, 1)
this._endAttrib0Hack()
}
}
Expand Down
Loading

0 comments on commit b73bb1f

Please sign in to comment.