Skip to content

Commit 141a810

Browse files
Merge branch 'master' into develop
2 parents 3379378 + 586ab02 commit 141a810

22 files changed

+914
-123
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ worker.onmessage = function(e) {
891891
* for instances of `GPU` use the `destroy` method. Example: `gpu.destroy()`
892892
* for instances of `Kernel` use the `destroy` method. Example: `kernel.destroy()`
893893
* for instances of `Texture` use the `delete` method. Example: `texture.delete()`
894+
* for instances of `Texture` that you might want to reuse/reset to zeros, use the `empty` method. Example: `texture.empty()`
894895

895896
## Flattened typed array support
896897
To use the useful `x`, `y`, `z` `thread` lookup api inside of GPU.js, and yet use flattened arrays, there is the `Input` type.

dist/gpu-browser-core.js

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.6.6
8-
* @date Fri Jan 24 2020 10:39:16 GMT-0500 (Eastern Standard Time)
7+
* @version 2.7.0
8+
* @date Tue Mar 10 2020 15:46:55 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -2984,6 +2984,7 @@ class FunctionNode {
29842984
'sin',
29852985
'sqrt',
29862986
'tan',
2987+
'tanh'
29872988
];
29882989
return ast.type === 'CallExpression' &&
29892990
ast.callee &&
@@ -4352,12 +4353,13 @@ function getToArrayString(kernelResult, textureName) {
43524353
throw new Error('unhandled fromObject');
43534354
}
43544355
},
4355-
thisLookup: (property) => {
4356+
thisLookup: (property, isDeclaration) => {
43564357
if (property === 'texture') {
43574358
return textureName;
43584359
}
43594360
if (property === 'context') {
4360-
return null;
4361+
if (isDeclaration) return null;
4362+
return 'gl';
43614363
}
43624364
if (property === '_framebuffer') {
43634365
return '_framebuffer';
@@ -5502,10 +5504,7 @@ class GLTextureFloat extends GLTexture {
55025504
}
55035505
renderRawOutput() {
55045506
const { context: gl, size } = this;
5505-
if (!this._framebuffer) {
5506-
this._framebuffer = gl.createFramebuffer();
5507-
}
5508-
gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);
5507+
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer());
55095508
gl.framebufferTexture2D(
55105509
gl.FRAMEBUFFER,
55115510
gl.COLOR_ATTACHMENT0,
@@ -5570,12 +5569,7 @@ class GLTexture extends Texture {
55705569
console.warn('cloning internal texture');
55715570
}
55725571
const existingFramebuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
5573-
if (!this._framebuffer) {
5574-
this._framebuffer = gl.createFramebuffer();
5575-
}
5576-
this._framebuffer.width = size[0];
5577-
this._framebuffer.height = size[1];
5578-
gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);
5572+
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer());
55795573
selectTexture(gl, texture);
55805574
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
55815575
const target = gl.createTexture();
@@ -5589,13 +5583,32 @@ class GLTexture extends Texture {
55895583
}
55905584
}
55915585

5586+
clear() {
5587+
const { context: gl, size, texture } = this;
5588+
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer());
5589+
gl.bindTexture(gl.TEXTURE_2D, texture);
5590+
selectTexture(gl, texture);
5591+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
5592+
gl.clearColor(0, 0, 0, 0);
5593+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
5594+
}
5595+
55925596
delete() {
55935597
super.delete();
55945598
if (this.texture._refs === 0 && this._framebuffer) {
55955599
this.context.deleteFramebuffer(this._framebuffer);
55965600
this._framebuffer = null;
55975601
}
55985602
}
5603+
5604+
framebuffer() {
5605+
if (!this._framebuffer) {
5606+
this._framebuffer = this.context.createFramebuffer();
5607+
}
5608+
this._framebuffer.width = this.size[0];
5609+
this._framebuffer.height = this.size[1];
5610+
return this._framebuffer;
5611+
}
55995612
}
56005613

56015614
function selectTexture(gl, texture) {
@@ -5908,7 +5921,6 @@ class KernelValue {
59085921
this.name = name;
59095922
this.origin = origin;
59105923
this.tactic = tactic;
5911-
this.id = `${this.origin}_${name}`;
59125924
this.varName = origin === 'constants' ? `constants.${name}` : name;
59135925
this.kernel = kernel;
59145926
this.strictIntegers = strictIntegers;
@@ -5923,6 +5935,10 @@ class KernelValue {
59235935
this.forceUploadEachRun = null;
59245936
}
59255937

5938+
get id() {
5939+
return `${this.origin}_${name}`;
5940+
}
5941+
59265942
getSource() {
59275943
throw new Error(`"getSource" not defined on ${ this.constructor.name }`);
59285944
}
@@ -7962,7 +7978,7 @@ class WebGLFunctionNode extends FunctionNode {
79627978
case 'Array(2)':
79637979
case 'Array(3)':
79647980
case 'Array(4)':
7965-
retArr.push(`constants_${ name }`);
7981+
retArr.push(`constants_${ utils.sanitizeName(name) }`);
79667982
return retArr;
79677983
}
79687984
}
@@ -7998,12 +8014,12 @@ class WebGLFunctionNode extends FunctionNode {
79988014
case 'Integer':
79998015
case 'Float':
80008016
case 'Boolean':
8001-
retArr.push(`${origin}_${name}`);
8017+
retArr.push(`${origin}_${utils.sanitizeName(name)}`);
80028018
return retArr;
80038019
}
80048020
}
80058021

8006-
const markupName = `${origin}_${name}`;
8022+
const markupName = `${origin}_${utils.sanitizeName(name)}`;
80078023

80088024
switch (type) {
80098025
case 'Array(2)':
@@ -8235,7 +8251,7 @@ class WebGLFunctionNode extends FunctionNode {
82358251
if (targetType === argumentType) {
82368252
if (argument.type === 'Identifier') {
82378253
retArr.push(`user_${utils.sanitizeName(argument.name)}`);
8238-
} else if (argument.type === 'ArrayExpression' || argument.type === 'MemberExpression') {
8254+
} else if (argument.type === 'ArrayExpression' || argument.type === 'MemberExpression' || argument.type === 'CallExpression') {
82398255
this.astGeneric(argument, retArr);
82408256
} else {
82418257
throw this.astErrorOutput(`Unhandled argument type ${ argument.type }`, ast);
@@ -9013,6 +9029,7 @@ module.exports = {
90139029
WebGLKernelValueHTMLVideo
90149030
};
90159031
},{"./html-image":53}],55:[function(require,module,exports){
9032+
const { utils } = require('../../../utils');
90169033
const { KernelValue } = require('../../kernel-value');
90179034

90189035
class WebGLKernelValue extends KernelValue {
@@ -9029,6 +9046,10 @@ class WebGLKernelValue extends KernelValue {
90299046
this.prevArg = null;
90309047
}
90319048

9049+
get id() {
9050+
return `${this.origin}_${utils.sanitizeName(this.name)}`;
9051+
}
9052+
90329053
setup() {}
90339054

90349055
getTransferArrayType(value) {
@@ -9067,7 +9088,7 @@ class WebGLKernelValue extends KernelValue {
90679088
module.exports = {
90689089
WebGLKernelValue
90699090
};
9070-
},{"../../kernel-value":34}],56:[function(require,module,exports){
9091+
},{"../../../utils":113,"../../kernel-value":34}],56:[function(require,module,exports){
90719092
const { utils } = require('../../../utils');
90729093
const { WebGLKernelValue } = require('./index');
90739094

@@ -9977,7 +9998,7 @@ class WebGLKernel extends GLKernel {
99779998

99789999
for (let index = 0; index < args.length; index++) {
997910000
const value = args[index];
9980-
const name = utils.sanitizeName(this.argumentNames[index]);
10001+
const name = this.argumentNames[index];
998110002
let type;
998210003
if (needsArgumentTypes) {
998310004
type = utils.getVariableType(value, this.strictIntegers);
@@ -10026,8 +10047,7 @@ class WebGLKernel extends GLKernel {
1002610047
}
1002710048
this.constantBitRatios = {};
1002810049
let textureIndexes = 0;
10029-
for (const p in this.constants) {
10030-
const name = utils.sanitizeName(p);
10050+
for (const name in this.constants) {
1003110051
const value = this.constants[name];
1003210052
let type;
1003310053
if (needsConstantTypes) {
@@ -14246,7 +14266,7 @@ const utils = {
1424614266
}
1424714267
case 'VariableDeclarator':
1424814268
if (ast.init.object && ast.init.object.type === 'ThisExpression') {
14249-
const lookup = thisLookup(ast.init.property.name);
14269+
const lookup = thisLookup(ast.init.property.name, true);
1425014270
if (lookup) {
1425114271
return `${ast.id.name} = ${flatten(ast.init)}`;
1425214272
} else {

dist/gpu-browser-core.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)