Skip to content

Commit 4d46279

Browse files
fix: #472 compilation issue, and add Uint8ClampedArray support
1 parent 181c553 commit 4d46279

File tree

11 files changed

+1127
-332
lines changed

11 files changed

+1127
-332
lines changed

bin/gpu-browser-core.js

Lines changed: 58 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 2.0.0-rc.14
8-
* @date Thu May 23 2019 16:47:13 GMT-0400 (Eastern Daylight Time)
8+
* @date Thu May 23 2019 18:11:32 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -1512,6 +1512,7 @@ class CPUKernel extends Kernel {
15121512
module.exports = {
15131513
CPUKernel
15141514
};
1515+
15151516
},{"../../utils":88,"../function-builder":8,"../kernel":33,"./function-node":5,"./kernel-string":6}],8:[function(require,module,exports){
15161517
class FunctionBuilder {
15171518
static fromKernel(kernel, FunctionNode, extraNodeOptions) {
@@ -4581,7 +4582,6 @@ class HeadlessGLKernel extends WebGLKernel {
45814582
module.exports = {
45824583
HeadlessGLKernel
45834584
};
4584-
45854585
},{"../gl/kernel-string":10,"../web-gl/kernel":55,"gl":2}],32:[function(require,module,exports){
45864586
const { utils } = require('../utils');
45874587

@@ -4973,6 +4973,7 @@ class Kernel {
49734973
return this.getBitRatio(value.value);
49744974
}
49754975
switch (value.constructor) {
4976+
case Uint8ClampedArray:
49764977
case Uint8Array:
49774978
case Int8Array:
49784979
return 1;
@@ -5856,76 +5857,65 @@ class WebGLFunctionNode extends FunctionNode {
58565857
throw this.astErrorOutput('Unexpected expression', varDecNode);
58575858
}
58585859
const result = [];
5859-
const firstDeclaration = declarations[0];
5860-
const init = firstDeclaration.init;
5861-
const actualType = this.getType(init);
5860+
let lastType = null;
58625861
const inForLoopInit = this.isState('in-for-loop-init');
5863-
let type = inForLoopInit ? 'Integer' : actualType;
5864-
if (type === 'LiteralInteger') {
5865-
type = 'Number';
5866-
}
5867-
const markupType = typeMap[type];
5868-
if (!markupType) {
5869-
throw this.astErrorOutput(`Markup type ${ markupType } not handled`, varDecNode);
5870-
}
5871-
let dependencies = this.getDependencies(firstDeclaration.init);
5872-
const initResult = [];
5873-
if (actualType === 'Integer' && type === 'Integer' && !inForLoopInit) {
5874-
this.declarations[firstDeclaration.id.name] = Object.freeze({
5875-
type: 'Number',
5876-
dependencies,
5877-
isSafe: this.isSafeDependencies(dependencies),
5878-
});
5879-
initResult.push('float ');
5880-
initResult.push(`user_${firstDeclaration.id.name}=`);
5881-
initResult.push('float(');
5882-
this.astGeneric(init, initResult);
5883-
initResult.push(')');
5884-
} else {
5885-
this.declarations[firstDeclaration.id.name] = Object.freeze({
5886-
type,
5887-
dependencies,
5888-
isSafe: this.isSafeDependencies(dependencies),
5889-
});
5890-
initResult.push(`${markupType} `);
5891-
initResult.push(`user_${firstDeclaration.id.name}=`);
5892-
if (actualType === 'Number' && type === 'Integer') {
5893-
initResult.push('int(');
5894-
this.astGeneric(init, initResult);
5895-
initResult.push(')');
5896-
} else {
5897-
this.astGeneric(init, initResult);
5898-
}
5899-
}
5900-
result.push(initResult.join(''));
5901-
5902-
let lastType = type;
5903-
for (let i = 1; i < declarations.length; i++) {
5862+
for (let i = 0; i < declarations.length; i++) {
59045863
const declaration = declarations[i];
5905-
const nextResult = [];
5906-
if (!inForLoopInit) {
5907-
let possibleNewType = this.getType(declaration.init);
5908-
if (possibleNewType === 'LiteralInteger') {
5909-
possibleNewType = 'Number';
5910-
}
5911-
if (possibleNewType !== lastType) {
5912-
nextResult.push(';');
5913-
nextResult.push(typeMap[possibleNewType], ' ');
5914-
lastType = possibleNewType;
5864+
const init = declaration.init;
5865+
const actualType = this.getType(init);
5866+
let dependencies = this.getDependencies(init);
5867+
let type = inForLoopInit ? 'Integer' : actualType;
5868+
if (type === 'LiteralInteger') {
5869+
type = 'Number';
5870+
}
5871+
const markupType = typeMap[type];
5872+
if (!markupType) {
5873+
throw this.astErrorOutput(`Markup type ${ markupType } not handled`, varDecNode);
5874+
}
5875+
const declarationResult = [];
5876+
if (actualType === 'Integer' && type === 'Integer' && !inForLoopInit) {
5877+
this.declarations[declaration.id.name] = Object.freeze({
5878+
type: 'Number',
5879+
dependencies,
5880+
isSafe: this.isSafeDependencies(dependencies),
5881+
});
5882+
if (i === 0 || lastType === null) {
5883+
declarationResult.push('float ');
5884+
} else if (actualType !== lastType) {
5885+
throw new Error('Unhandled declaration');
59155886
} else {
5916-
nextResult.push(',');
5887+
declarationResult.push(',');
59175888
}
5889+
lastType = type;
5890+
declarationResult.push(`user_${declaration.id.name}=`);
5891+
declarationResult.push('float(');
5892+
this.astGeneric(init, declarationResult);
5893+
declarationResult.push(')');
59185894
} else {
5919-
nextResult.push(',');
5895+
this.declarations[declaration.id.name] = Object.freeze({
5896+
type,
5897+
dependencies,
5898+
isSafe: this.isSafeDependencies(dependencies),
5899+
});
5900+
if (i === 0 || lastType === null) {
5901+
declarationResult.push(`${markupType} `);
5902+
} else if (actualType !== lastType) {
5903+
result.push(';');
5904+
declarationResult.push(`${markupType} `);
5905+
} else {
5906+
declarationResult.push(',');
5907+
}
5908+
lastType = type;
5909+
declarationResult.push(`user_${declaration.id.name}=`);
5910+
if (actualType === 'Number' && type === 'Integer') {
5911+
declarationResult.push('int(');
5912+
this.astGeneric(init, declarationResult);
5913+
declarationResult.push(')');
5914+
} else {
5915+
this.astGeneric(init, declarationResult);
5916+
}
59205917
}
5921-
dependencies = this.getDependencies(declaration);
5922-
this.declarations[declaration.id.name] = Object.freeze({
5923-
type: lastType,
5924-
dependencies: dependencies,
5925-
isSafe: this.isSafeDependencies(dependencies),
5926-
});
5927-
this.astGeneric(declaration, nextResult);
5928-
result.push(nextResult.join(''));
5918+
result.push(declarationResult.join(''));
59295919
}
59305920

59315921
retArr.push(result.join(''));
@@ -6862,6 +6852,7 @@ class WebGLKernelValue extends KernelValue {
68626852
return valuesFlat;
68636853
} else {
68646854
switch (value.constructor) {
6855+
case Uint8ClampedArray:
68656856
case Uint8Array:
68666857
case Int8Array:
68676858
case Uint16Array:
@@ -6888,6 +6879,7 @@ class WebGLKernelValue extends KernelValue {
68886879
return this.getBitRatio(value.value);
68896880
}
68906881
switch (value.constructor) {
6882+
case Uint8ClampedArray:
68916883
case Uint8Array:
68926884
case Int8Array:
68936885
return 1;

bin/gpu-browser-core.min.js

Lines changed: 59 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 2.0.0-rc.14
8-
* @date Thu May 23 2019 16:47:15 GMT-0400 (Eastern Daylight Time)
8+
* @date Thu May 23 2019 18:11:34 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -18,7 +18,7 @@
1818
* GPU Accelerated JavaScript
1919
*
2020
* @version 2.0.0-rc.14
21-
* @date Thu May 23 2019 16:47:13 GMT-0400 (Eastern Daylight Time)
21+
* @date Thu May 23 2019 18:11:32 GMT-0400 (Eastern Daylight Time)
2222
*
2323
* @license MIT
2424
* The MIT License
@@ -1525,6 +1525,7 @@ class CPUKernel extends Kernel {
15251525
module.exports = {
15261526
CPUKernel
15271527
};
1528+
15281529
},{"../../utils":88,"../function-builder":8,"../kernel":33,"./function-node":5,"./kernel-string":6}],8:[function(require,module,exports){
15291530
class FunctionBuilder {
15301531
static fromKernel(kernel, FunctionNode, extraNodeOptions) {
@@ -4594,7 +4595,6 @@ class HeadlessGLKernel extends WebGLKernel {
45944595
module.exports = {
45954596
HeadlessGLKernel
45964597
};
4597-
45984598
},{"../gl/kernel-string":10,"../web-gl/kernel":55,"gl":2}],32:[function(require,module,exports){
45994599
const { utils } = require('../utils');
46004600

@@ -4986,6 +4986,7 @@ class Kernel {
49864986
return this.getBitRatio(value.value);
49874987
}
49884988
switch (value.constructor) {
4989+
case Uint8ClampedArray:
49894990
case Uint8Array:
49904991
case Int8Array:
49914992
return 1;
@@ -5869,76 +5870,65 @@ class WebGLFunctionNode extends FunctionNode {
58695870
throw this.astErrorOutput('Unexpected expression', varDecNode);
58705871
}
58715872
const result = [];
5872-
const firstDeclaration = declarations[0];
5873-
const init = firstDeclaration.init;
5874-
const actualType = this.getType(init);
5873+
let lastType = null;
58755874
const inForLoopInit = this.isState('in-for-loop-init');
5876-
let type = inForLoopInit ? 'Integer' : actualType;
5877-
if (type === 'LiteralInteger') {
5878-
type = 'Number';
5879-
}
5880-
const markupType = typeMap[type];
5881-
if (!markupType) {
5882-
throw this.astErrorOutput(`Markup type ${ markupType } not handled`, varDecNode);
5883-
}
5884-
let dependencies = this.getDependencies(firstDeclaration.init);
5885-
const initResult = [];
5886-
if (actualType === 'Integer' && type === 'Integer' && !inForLoopInit) {
5887-
this.declarations[firstDeclaration.id.name] = Object.freeze({
5888-
type: 'Number',
5889-
dependencies,
5890-
isSafe: this.isSafeDependencies(dependencies),
5891-
});
5892-
initResult.push('float ');
5893-
initResult.push(`user_${firstDeclaration.id.name}=`);
5894-
initResult.push('float(');
5895-
this.astGeneric(init, initResult);
5896-
initResult.push(')');
5897-
} else {
5898-
this.declarations[firstDeclaration.id.name] = Object.freeze({
5899-
type,
5900-
dependencies,
5901-
isSafe: this.isSafeDependencies(dependencies),
5902-
});
5903-
initResult.push(`${markupType} `);
5904-
initResult.push(`user_${firstDeclaration.id.name}=`);
5905-
if (actualType === 'Number' && type === 'Integer') {
5906-
initResult.push('int(');
5907-
this.astGeneric(init, initResult);
5908-
initResult.push(')');
5909-
} else {
5910-
this.astGeneric(init, initResult);
5911-
}
5912-
}
5913-
result.push(initResult.join(''));
5914-
5915-
let lastType = type;
5916-
for (let i = 1; i < declarations.length; i++) {
5875+
for (let i = 0; i < declarations.length; i++) {
59175876
const declaration = declarations[i];
5918-
const nextResult = [];
5919-
if (!inForLoopInit) {
5920-
let possibleNewType = this.getType(declaration.init);
5921-
if (possibleNewType === 'LiteralInteger') {
5922-
possibleNewType = 'Number';
5923-
}
5924-
if (possibleNewType !== lastType) {
5925-
nextResult.push(';');
5926-
nextResult.push(typeMap[possibleNewType], ' ');
5927-
lastType = possibleNewType;
5877+
const init = declaration.init;
5878+
const actualType = this.getType(init);
5879+
let dependencies = this.getDependencies(init);
5880+
let type = inForLoopInit ? 'Integer' : actualType;
5881+
if (type === 'LiteralInteger') {
5882+
type = 'Number';
5883+
}
5884+
const markupType = typeMap[type];
5885+
if (!markupType) {
5886+
throw this.astErrorOutput(`Markup type ${ markupType } not handled`, varDecNode);
5887+
}
5888+
const declarationResult = [];
5889+
if (actualType === 'Integer' && type === 'Integer' && !inForLoopInit) {
5890+
this.declarations[declaration.id.name] = Object.freeze({
5891+
type: 'Number',
5892+
dependencies,
5893+
isSafe: this.isSafeDependencies(dependencies),
5894+
});
5895+
if (i === 0 || lastType === null) {
5896+
declarationResult.push('float ');
5897+
} else if (actualType !== lastType) {
5898+
throw new Error('Unhandled declaration');
59285899
} else {
5929-
nextResult.push(',');
5900+
declarationResult.push(',');
59305901
}
5902+
lastType = type;
5903+
declarationResult.push(`user_${declaration.id.name}=`);
5904+
declarationResult.push('float(');
5905+
this.astGeneric(init, declarationResult);
5906+
declarationResult.push(')');
59315907
} else {
5932-
nextResult.push(',');
5908+
this.declarations[declaration.id.name] = Object.freeze({
5909+
type,
5910+
dependencies,
5911+
isSafe: this.isSafeDependencies(dependencies),
5912+
});
5913+
if (i === 0 || lastType === null) {
5914+
declarationResult.push(`${markupType} `);
5915+
} else if (actualType !== lastType) {
5916+
result.push(';');
5917+
declarationResult.push(`${markupType} `);
5918+
} else {
5919+
declarationResult.push(',');
5920+
}
5921+
lastType = type;
5922+
declarationResult.push(`user_${declaration.id.name}=`);
5923+
if (actualType === 'Number' && type === 'Integer') {
5924+
declarationResult.push('int(');
5925+
this.astGeneric(init, declarationResult);
5926+
declarationResult.push(')');
5927+
} else {
5928+
this.astGeneric(init, declarationResult);
5929+
}
59335930
}
5934-
dependencies = this.getDependencies(declaration);
5935-
this.declarations[declaration.id.name] = Object.freeze({
5936-
type: lastType,
5937-
dependencies: dependencies,
5938-
isSafe: this.isSafeDependencies(dependencies),
5939-
});
5940-
this.astGeneric(declaration, nextResult);
5941-
result.push(nextResult.join(''));
5931+
result.push(declarationResult.join(''));
59425932
}
59435933

59445934
retArr.push(result.join(''));
@@ -6875,6 +6865,7 @@ class WebGLKernelValue extends KernelValue {
68756865
return valuesFlat;
68766866
} else {
68776867
switch (value.constructor) {
6868+
case Uint8ClampedArray:
68786869
case Uint8Array:
68796870
case Int8Array:
68806871
case Uint16Array:
@@ -6901,6 +6892,7 @@ class WebGLKernelValue extends KernelValue {
69016892
return this.getBitRatio(value.value);
69026893
}
69036894
switch (value.constructor) {
6895+
case Uint8ClampedArray:
69046896
case Uint8Array:
69056897
case Int8Array:
69066898
return 1;

0 commit comments

Comments
 (0)