mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-25 16:08:02 +00:00
cleanup tests, bump version number, prep for release
This commit is contained in:
parent
2dc7c12fdc
commit
08ca02b8ef
@ -4,8 +4,8 @@
|
||||
*
|
||||
* GPU Accelerated JavaScript
|
||||
*
|
||||
* @version 1.3.0
|
||||
* @date Mon Jun 04 2018 20:06:27 GMT-0400 (EDT)
|
||||
* @version 1.4.0
|
||||
* @date Tue Jun 05 2018 20:28:34 GMT-0400 (EDT)
|
||||
*
|
||||
* @license MIT
|
||||
* The MIT License
|
||||
|
||||
4
bin/gpu-core.min.js
vendored
4
bin/gpu-core.min.js
vendored
@ -4,8 +4,8 @@
|
||||
*
|
||||
* GPU Accelerated JavaScript
|
||||
*
|
||||
* @version 1.3.0
|
||||
* @date Mon Jun 04 2018 20:06:27 GMT-0400 (EDT)
|
||||
* @version 1.4.0
|
||||
* @date Tue Jun 05 2018 20:28:34 GMT-0400 (EDT)
|
||||
*
|
||||
* @license MIT
|
||||
* The MIT License
|
||||
|
||||
156
bin/gpu.js
156
bin/gpu.js
File diff suppressed because one or more lines are too long
18
bin/gpu.min.js
vendored
18
bin/gpu.min.js
vendored
File diff suppressed because one or more lines are too long
26
dist/backend/cpu/kernel.js
vendored
26
dist/backend/cpu/kernel.js
vendored
@ -336,8 +336,13 @@ module.exports = function (_KernelBase) {
|
||||
value: function _processInputs() {
|
||||
var result = [];
|
||||
for (var i = 0; i < this.paramTypes.length; i++) {
|
||||
if (this.paramTypes[i] === 'HTMLImage') {
|
||||
result.push(' user_' + this.paramNames[i] + ' = this._imageTo2DArray(user_' + this.paramNames[i] + ')');
|
||||
switch (this.paramTypes[i]) {
|
||||
case 'HTMLImage':
|
||||
result.push(' user_' + this.paramNames[i] + ' = this._imageTo2DArray(user_' + this.paramNames[i] + ')');
|
||||
break;
|
||||
case 'HTMLImageArray':
|
||||
result.push(' user_' + this.paramNames[i] + ' = this._imageTo3DArray(user_' + this.paramNames[i] + ')');
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result.join(';\n');
|
||||
@ -347,15 +352,24 @@ module.exports = function (_KernelBase) {
|
||||
value: function _imageTo2DArray(image) {
|
||||
this._canvasCtx.drawImage(image, 0, 0, image.width, image.height);
|
||||
var pixelsData = this._canvasCtx.getImageData(0, 0, image.width, image.height).data;
|
||||
var result = new Array(image.height);
|
||||
var imageArray = new Array(image.height);
|
||||
var index = 0;
|
||||
for (var y = 0; y < image.height; y++) {
|
||||
result[y] = new Array(image.width);
|
||||
imageArray[y] = new Array(image.width);
|
||||
for (var x = 0; x < image.width; x++) {
|
||||
result[y][x] = [pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255];
|
||||
imageArray[y][x] = [pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return imageArray;
|
||||
}
|
||||
}, {
|
||||
key: '_imageTo3DArray',
|
||||
value: function _imageTo3DArray(images) {
|
||||
var imagesArray = new Array(images.length);
|
||||
for (var i = 0; i < images.length; i++) {
|
||||
imagesArray[i] = this._imageTo2DArray(images[i]);
|
||||
}
|
||||
return imagesArray;
|
||||
}
|
||||
}], [{
|
||||
key: 'compileKernel',
|
||||
|
||||
23
dist/backend/web-gl/function-node.js
vendored
23
dist/backend/web-gl/function-node.js
vendored
@ -718,7 +718,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
var retDeclaration = [];
|
||||
this.astGeneric(declaration, retDeclaration, funcParam);
|
||||
if (retDeclaration[2] === 'getImage(') {
|
||||
if (retDeclaration[2] === 'getImage2D(' || retDeclaration[2] === 'getImage3D(') {
|
||||
if (i === 0) {
|
||||
retArr.push('vec4 ');
|
||||
}
|
||||
@ -993,9 +993,28 @@ module.exports = function (_FunctionNodeBase) {
|
||||
retArr.push(mNode.property.raw);
|
||||
retArr.push(']');
|
||||
break;
|
||||
case 'HTMLImageArray':
|
||||
// Get from image
|
||||
retArr.push('getImage3D(');
|
||||
this.astGeneric(mNode.object, retArr, funcParam);
|
||||
retArr.push(', vec2(');
|
||||
this.astGeneric(mNode.object, retArr, funcParam);
|
||||
retArr.push('Size[0],');
|
||||
this.astGeneric(mNode.object, retArr, funcParam);
|
||||
retArr.push('Size[1]), vec3(');
|
||||
this.astGeneric(mNode.object, retArr, funcParam);
|
||||
retArr.push('Dim[0],');
|
||||
this.astGeneric(mNode.object, retArr, funcParam);
|
||||
retArr.push('Dim[1],');
|
||||
this.astGeneric(mNode.object, retArr, funcParam);
|
||||
retArr.push('Dim[2]');
|
||||
retArr.push('), ');
|
||||
this.astGeneric(mNode.property, retArr, funcParam);
|
||||
retArr.push(')');
|
||||
break;
|
||||
case 'HTMLImage':
|
||||
// Get from image
|
||||
retArr.push('getImage(');
|
||||
retArr.push('getImage2D(');
|
||||
this.astGeneric(mNode.object, retArr, funcParam);
|
||||
retArr.push(', vec2(');
|
||||
this.astGeneric(mNode.object, retArr, funcParam);
|
||||
|
||||
2
dist/backend/web-gl/kernel.js
vendored
2
dist/backend/web-gl/kernel.js
vendored
@ -1041,6 +1041,8 @@ module.exports = function (_KernelBase) {
|
||||
result.push('uniform highp sampler2D user_' + paramName, 'uniform highp vec2 user_' + paramName + 'Size', 'uniform highp vec3 user_' + paramName + 'Dim');
|
||||
} else if (paramType === 'Number') {
|
||||
result.push('uniform highp float user_' + paramName);
|
||||
} else {
|
||||
throw new Error('Param type ' + paramType + ' not supported in WebGL, only WebGL2');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
dist/backend/web-gl/shader-frag.js
vendored
2
dist/backend/web-gl/shader-frag.js
vendored
@ -1,3 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = "__HEADER__;\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nconst float LOOP_MAX = __LOOP_MAX__;\n#define EPSILON 0.0000001;\n\n__CONSTANTS__;\n\nvarying highp vec2 vTexCoord;\n\nvec4 round(vec4 x) {\n return floor(x + 0.5);\n}\n\nhighp float round(highp float x) {\n return floor(x + 0.5);\n}\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nhighp float integerMod(highp float x, highp float y) {\n highp float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nhighp int integerMod(highp int x, highp int y) {\n return int(integerMod(float(x), float(y)));\n}\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nhighp float decode32(highp vec4 rgba) {\n __DECODE32_ENDIANNESS__;\n rgba *= 255.0;\n vec2 gte128;\n gte128.x = rgba.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = rgba.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * rgba.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n rgba.b = rgba.b - 128.0 * gte128.x;\n res = dot(rgba, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nhighp vec4 encode32(highp float f) {\n highp float F = abs(f);\n highp float sign = f < 0.0 ? 1.0 : 0.0;\n highp float exponent = floor(log2(F));\n highp float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 rgba = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n rgba.rg = integerMod(rgba.rg, 256.0);\n rgba.b = integerMod(rgba.b, 128.0);\n rgba.a = exponent*0.5 + 63.5;\n rgba.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n rgba = floor(rgba);\n rgba *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return rgba;\n}\n// Dragons end here\n\nhighp float index;\nhighp vec3 threadId;\n\nhighp vec3 indexTo3D(highp float idx, highp vec3 texDim) {\n highp float z = floor(idx / (texDim.x * texDim.y));\n idx -= z * texDim.x * texDim.y;\n highp float y = floor(idx / texDim.x);\n highp float x = integerMod(idx, texDim.x);\n return vec3(x, y, z);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float z, highp float y, highp float x) {\n highp vec3 xyz = vec3(x, y, z);\n xyz = floor(xyz + 0.5);\n __GET_WRAPAROUND__;\n highp float index = round(xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z));\n __GET_TEXTURE_CHANNEL__;\n highp float w = round(texSize.x);\n vec2 st = vec2(integerMod(index, w), float(int(index) / int(w))) + 0.5;\n __GET_TEXTURE_INDEX__;\n highp vec4 texel = texture2D(tex, st / texSize);\n __GET_RESULT__;\n}\n\nhighp vec4 getImage(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float z, highp float y, highp float x) {\n highp vec3 xyz = vec3(x, y, z);\n xyz = floor(xyz + 0.5);\n __GET_WRAPAROUND__;\n highp float index = round(xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z));\n __GET_TEXTURE_CHANNEL__;\n highp float w = round(texSize.x);\n vec2 st = vec2(integerMod(index, w), float(int(index) / int(w))) + 0.5;\n __GET_TEXTURE_INDEX__;\n return texture2D(tex, st / texSize);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float y, highp float x) {\n return get(tex, texSize, texDim, 0.0, y, x);\n}\n\nhighp vec4 getImage(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float y, highp float x) {\n return getImage(tex, texSize, texDim, 0.0, y, x);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float x) {\n return get(tex, texSize, texDim, 0.0, 0.0, x);\n}\n\nhighp vec4 getImage(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float x) {\n return getImage(tex, texSize, texDim, 0.0, 0.0, x);\n}\n\nhighp vec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\nvoid color(sampler2D image) {\n actualColor = texture2D(image, vTexCoord);\n}\n\n__MAIN_PARAMS__;\n__MAIN_CONSTANTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = floor(vTexCoord.s * float(uTexSize.x)) + floor(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}";
|
||||
module.exports = "__HEADER__;\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nconst float LOOP_MAX = __LOOP_MAX__;\n#define EPSILON 0.0000001;\n\n__CONSTANTS__;\n\nvarying highp vec2 vTexCoord;\n\nvec4 round(vec4 x) {\n return floor(x + 0.5);\n}\n\nhighp float round(highp float x) {\n return floor(x + 0.5);\n}\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nhighp float integerMod(highp float x, highp float y) {\n highp float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nhighp int integerMod(highp int x, highp int y) {\n return int(integerMod(float(x), float(y)));\n}\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nhighp float decode32(highp vec4 rgba) {\n __DECODE32_ENDIANNESS__;\n rgba *= 255.0;\n vec2 gte128;\n gte128.x = rgba.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = rgba.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * rgba.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n rgba.b = rgba.b - 128.0 * gte128.x;\n res = dot(rgba, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nhighp vec4 encode32(highp float f) {\n highp float F = abs(f);\n highp float sign = f < 0.0 ? 1.0 : 0.0;\n highp float exponent = floor(log2(F));\n highp float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 rgba = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n rgba.rg = integerMod(rgba.rg, 256.0);\n rgba.b = integerMod(rgba.b, 128.0);\n rgba.a = exponent*0.5 + 63.5;\n rgba.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n rgba = floor(rgba);\n rgba *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return rgba;\n}\n// Dragons end here\n\nhighp float index;\nhighp vec3 threadId;\n\nhighp vec3 indexTo3D(highp float idx, highp vec3 texDim) {\n highp float z = floor(idx / (texDim.x * texDim.y));\n idx -= z * texDim.x * texDim.y;\n highp float y = floor(idx / texDim.x);\n highp float x = integerMod(idx, texDim.x);\n return vec3(x, y, z);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float z, highp float y, highp float x) {\n highp vec3 xyz = vec3(x, y, z);\n xyz = floor(xyz + 0.5);\n __GET_WRAPAROUND__;\n highp float index = round(xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z));\n __GET_TEXTURE_CHANNEL__;\n highp float w = round(texSize.x);\n vec2 st = vec2(integerMod(index, w), float(int(index) / int(w))) + 0.5;\n __GET_TEXTURE_INDEX__;\n highp vec4 texel = texture2D(tex, st / texSize);\n __GET_RESULT__;\n}\n\nhighp vec4 getImage2D(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float z, highp float y, highp float x) {\n highp vec3 xyz = vec3(x, y, z);\n xyz = floor(xyz + 0.5);\n __GET_WRAPAROUND__;\n highp float index = round(xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z));\n __GET_TEXTURE_CHANNEL__;\n highp float w = round(texSize.x);\n vec2 st = vec2(integerMod(index, w), float(int(index) / int(w))) + 0.5;\n __GET_TEXTURE_INDEX__;\n return texture2D(tex, st / texSize);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float y, highp float x) {\n return get(tex, texSize, texDim, 0.0, y, x);\n}\n\nhighp vec4 getImage2D(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float y, highp float x) {\n return getImage2D(tex, texSize, texDim, 0.0, y, x);\n}\n\nhighp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float x) {\n return get(tex, texSize, texDim, 0.0, 0.0, x);\n}\n\nhighp vec4 getImage2D(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float x) {\n return getImage2D(tex, texSize, texDim, 0.0, 0.0, x);\n}\n\nhighp vec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\nvoid color(sampler2D image) {\n actualColor = texture2D(image, vTexCoord);\n}\n\n__MAIN_PARAMS__;\n__MAIN_CONSTANTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = floor(vTexCoord.s * float(uTexSize.x)) + floor(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}";
|
||||
4
dist/backend/web-gl2/function-builder.js
vendored
4
dist/backend/web-gl2/function-builder.js
vendored
@ -7,7 +7,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var FunctionBuilderBase = require('../function-builder-base');
|
||||
var WebGLFunctionNode = require('./function-node');
|
||||
var WebGL2FunctionNode = require('./function-node');
|
||||
|
||||
/**
|
||||
* @class WebGLFunctionBuilder
|
||||
@ -25,7 +25,7 @@ module.exports = function (_FunctionBuilderBase) {
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (WebGL2FunctionBuilder.__proto__ || Object.getPrototypeOf(WebGL2FunctionBuilder)).call(this));
|
||||
|
||||
_this.Node = WebGLFunctionNode;
|
||||
_this.Node = WebGL2FunctionNode;
|
||||
return _this;
|
||||
}
|
||||
|
||||
|
||||
72
dist/backend/web-gl2/function-node.js
vendored
72
dist/backend/web-gl2/function-node.js
vendored
@ -20,7 +20,7 @@ var DECODE32_ENCODE32 = /decode32\(\s+encode32\(/g;
|
||||
var ENCODE32_DECODE32 = /encode32\(\s+decode32\(/g;
|
||||
|
||||
/**
|
||||
* @class WebGLFunctionNode
|
||||
* @class WebGL2FunctionNode
|
||||
*
|
||||
* @desc [INTERNAL] Takes in a function node, and does all the AST voodoo required to generate its respective webGL code.
|
||||
*
|
||||
@ -32,22 +32,22 @@ var ENCODE32_DECODE32 = /encode32\(\s+decode32\(/g;
|
||||
*
|
||||
*/
|
||||
module.exports = function (_FunctionNodeBase) {
|
||||
_inherits(WebGLFunctionNode, _FunctionNodeBase);
|
||||
_inherits(WebGL2FunctionNode, _FunctionNodeBase);
|
||||
|
||||
function WebGLFunctionNode() {
|
||||
_classCallCheck(this, WebGLFunctionNode);
|
||||
function WebGL2FunctionNode() {
|
||||
_classCallCheck(this, WebGL2FunctionNode);
|
||||
|
||||
return _possibleConstructorReturn(this, (WebGLFunctionNode.__proto__ || Object.getPrototypeOf(WebGLFunctionNode)).apply(this, arguments));
|
||||
return _possibleConstructorReturn(this, (WebGL2FunctionNode.__proto__ || Object.getPrototypeOf(WebGL2FunctionNode)).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(WebGLFunctionNode, [{
|
||||
_createClass(WebGL2FunctionNode, [{
|
||||
key: 'generate',
|
||||
value: function generate() {
|
||||
if (this.debug) {
|
||||
console.log(this);
|
||||
}
|
||||
if (this.prototypeOnly) {
|
||||
return WebGLFunctionNode.astFunctionPrototype(this.getJsAST(), [], this).join('').trim();
|
||||
return WebGL2FunctionNode.astFunctionPrototype(this.getJsAST(), [], this).join('').trim();
|
||||
} else {
|
||||
this.functionStringArray = this.astGeneric(this.getJsAST(), [], this);
|
||||
}
|
||||
@ -56,7 +56,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astGeneric
|
||||
*
|
||||
@ -144,7 +144,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astFunctionDeclaration
|
||||
*
|
||||
@ -167,7 +167,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astFunctionPrototype
|
||||
* @static
|
||||
@ -186,7 +186,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astFunctionExpression
|
||||
*
|
||||
@ -252,7 +252,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astReturnStatement
|
||||
*
|
||||
@ -293,7 +293,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astLiteral
|
||||
*
|
||||
@ -327,7 +327,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astBinaryExpression
|
||||
*
|
||||
@ -371,7 +371,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astIdentifierExpression
|
||||
*
|
||||
@ -427,7 +427,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astForStatement
|
||||
*
|
||||
@ -526,7 +526,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astWhileStatement
|
||||
*
|
||||
@ -561,7 +561,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astWhileStatement
|
||||
*
|
||||
@ -595,7 +595,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astAssignmentExpression
|
||||
*
|
||||
@ -628,7 +628,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astEmptyStatement
|
||||
*
|
||||
@ -649,7 +649,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astBlockStatement
|
||||
*
|
||||
@ -674,7 +674,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astExpressionStatement
|
||||
*
|
||||
@ -696,7 +696,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astVariableDeclaration
|
||||
*
|
||||
@ -733,7 +733,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astVariableDeclarator
|
||||
*
|
||||
@ -758,7 +758,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astIfStatement
|
||||
*
|
||||
@ -799,7 +799,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astBreakStatement
|
||||
*
|
||||
@ -820,7 +820,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astContinueStatement
|
||||
*
|
||||
@ -841,7 +841,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astLogicalExpression
|
||||
*
|
||||
@ -866,7 +866,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astUpdateExpression
|
||||
*
|
||||
@ -894,7 +894,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astUnaryExpression
|
||||
*
|
||||
@ -922,7 +922,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astThisExpression
|
||||
*
|
||||
@ -943,7 +943,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astMemberExpression
|
||||
*
|
||||
@ -1056,7 +1056,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astCallExpression
|
||||
*
|
||||
@ -1143,7 +1143,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name astArrayExpression
|
||||
*
|
||||
@ -1181,7 +1181,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGLFunctionNode#
|
||||
* @memberOf WebGL2FunctionNode#
|
||||
* @function
|
||||
* @name getFunctionPrototypeString
|
||||
*
|
||||
@ -1235,7 +1235,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
}]);
|
||||
|
||||
return WebGLFunctionNode;
|
||||
return WebGL2FunctionNode;
|
||||
}(FunctionNodeBase);
|
||||
|
||||
function isIdentifierKernelParam(paramName, ast, funcParam) {
|
||||
|
||||
90
dist/backend/web-gl2/kernel.js
vendored
90
dist/backend/web-gl2/kernel.js
vendored
@ -386,17 +386,49 @@ module.exports = function (_WebGLKernel) {
|
||||
this.setUniform1i('user_' + name, this.argumentsLength);
|
||||
break;
|
||||
}
|
||||
case 'HTMLImageArray':
|
||||
{
|
||||
var inputImages = value;
|
||||
var _dim3 = [inputImages[0].width, inputImages[0].height, inputImages.length];
|
||||
var _size3 = [inputImages[0].width, inputImages[0].height];
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0 + this.argumentsLength);
|
||||
gl.bindTexture(gl.TEXTURE_2D_ARRAY, argumentTexture);
|
||||
gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
||||
// Upload the images into the texture.
|
||||
var _mipLevel = 0; // the largest mip
|
||||
var _internalFormat = gl.RGBA; // format we want in the texture
|
||||
var width = inputImages[0].width;
|
||||
var height = inputImages[0].height;
|
||||
var textureDepth = inputImages.length;
|
||||
var border = 0;
|
||||
var _srcFormat = gl.RGBA; // format of data we are supplying
|
||||
var _srcType = gl.UNSIGNED_BYTE; // type of data we are supplying
|
||||
gl.texImage3D(gl.TEXTURE_2D_ARRAY, _mipLevel, _internalFormat, width, height, textureDepth, border, _srcFormat, _srcType, null);
|
||||
for (var i = 0; i < inputImages.length; i++) {
|
||||
var xOffset = 0;
|
||||
var yOffset = 0;
|
||||
var imageDepth = 1;
|
||||
gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, _mipLevel, xOffset, yOffset, i, inputImages[i].width, inputImages[i].height, imageDepth, _srcFormat, _srcType, inputImages[i]);
|
||||
}
|
||||
this.setUniform3fv('user_' + name + 'Dim', _dim3);
|
||||
this.setUniform2fv('user_' + name + 'Size', _size3);
|
||||
this.setUniform1i('user_' + name, this.argumentsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
{
|
||||
var inputTexture = value;
|
||||
var _dim3 = inputTexture.dimensions;
|
||||
var _size3 = inputTexture.size;
|
||||
var _dim4 = inputTexture.dimensions;
|
||||
var _size4 = inputTexture.size;
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0 + this.argumentsLength);
|
||||
gl.bindTexture(gl.TEXTURE_2D, inputTexture.texture);
|
||||
|
||||
this.setUniform3fv('user_' + name + 'Dim', _dim3);
|
||||
this.setUniform2fv('user_' + name + 'Size', _size3);
|
||||
this.setUniform3fv('user_' + name + 'Dim', _dim4);
|
||||
this.setUniform2fv('user_' + name + 'Size', _size4);
|
||||
this.setUniform1i('user_' + name, this.argumentsLength);
|
||||
break;
|
||||
}
|
||||
@ -449,6 +481,56 @@ module.exports = function (_WebGLKernel) {
|
||||
/**
|
||||
* @memberOf WebGL2Kernel#
|
||||
* @function
|
||||
* @name _getMainParamsString
|
||||
*
|
||||
* @desc Generate transpiled glsl Strings for user-defined parameters sent to a kernel
|
||||
*
|
||||
* @param {Array} args - The actual parameters sent to the Kernel
|
||||
*
|
||||
* @returns {String} result
|
||||
*
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: '_getMainParamsString',
|
||||
value: function _getMainParamsString(args) {
|
||||
var result = [];
|
||||
var paramTypes = this.paramTypes;
|
||||
var paramNames = this.paramNames;
|
||||
for (var i = 0; i < paramNames.length; i++) {
|
||||
var param = args[i];
|
||||
var paramName = paramNames[i];
|
||||
var paramType = paramTypes[i];
|
||||
if (this.hardcodeConstants) {
|
||||
if (paramType === 'Array' || paramType === 'Texture') {
|
||||
var paramDim = utils.getDimensions(param, true);
|
||||
var paramSize = utils.dimToTexSize({
|
||||
floatTextures: this.floatTextures,
|
||||
floatOutput: this.floatOutput
|
||||
}, paramDim);
|
||||
|
||||
result.push('uniform highp sampler2D user_' + paramName, 'highp vec2 user_' + paramName + 'Size = vec2(' + paramSize[0] + '.0, ' + paramSize[1] + '.0)', 'highp vec3 user_' + paramName + 'Dim = vec3(' + paramDim[0] + '.0, ' + paramDim[1] + '.0, ' + paramDim[2] + '.0)');
|
||||
} else if (paramType === 'Number' && Number.isInteger(param)) {
|
||||
result.push('highp float user_' + paramName + ' = ' + param + '.0');
|
||||
} else if (paramType === 'Number') {
|
||||
result.push('highp float user_' + paramName + ' = ' + param);
|
||||
}
|
||||
} else {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
result.push('uniform highp sampler2D user_' + paramName, 'uniform highp vec2 user_' + paramName + 'Size', 'uniform highp vec3 user_' + paramName + 'Dim');
|
||||
} else if (paramType === 'HTMLImageArray') {
|
||||
result.push('uniform highp sampler2DArray user_' + paramName, 'uniform highp vec2 user_' + paramName + 'Size', 'uniform highp vec3 user_' + paramName + 'Dim');
|
||||
} else if (paramType === 'Number') {
|
||||
result.push('uniform highp float user_' + paramName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._linesToString(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberOf WebGL2Kernel#
|
||||
* @function
|
||||
* @name _getKernelString
|
||||
*
|
||||
* @desc Get Kernel program string (in *glsl*) for a kernel.
|
||||
|
||||
2
dist/backend/web-gl2/shader-frag.js
vendored
2
dist/backend/web-gl2/shader-frag.js
vendored
File diff suppressed because one or more lines are too long
3
dist/core/utils.js
vendored
3
dist/core/utils.js
vendored
@ -322,6 +322,9 @@ var Utils = function (_UtilsCore) {
|
||||
key: 'getArgumentType',
|
||||
value: function getArgumentType(arg) {
|
||||
if (Utils.isArray(arg)) {
|
||||
if (arg[0].nodeName === 'IMG') {
|
||||
return 'HTMLImageArray';
|
||||
}
|
||||
return 'Array';
|
||||
} else if (typeof arg === 'number') {
|
||||
return 'Number';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gpu.js",
|
||||
"version": "1.3.0",
|
||||
"version": "1.4.0",
|
||||
"description": "GPU Accelerated JavaScript",
|
||||
"main": "./dist/index.js",
|
||||
"directories": {
|
||||
|
||||
@ -382,18 +382,22 @@ ${ this.subKernelOutputVariableNames === null
|
||||
_imageTo2DArray(image) {
|
||||
this._canvasCtx.drawImage(image, 0, 0, image.width, image.height);
|
||||
const pixelsData = this._canvasCtx.getImageData(0, 0, image.width, image.height).data;
|
||||
const result = new Array(image.height);
|
||||
const imageArray = new Array(image.height);
|
||||
let index = 0;
|
||||
for (let y = 0; y < image.height; y++) {
|
||||
result[y] = new Array(image.width);
|
||||
imageArray[y] = new Array(image.width);
|
||||
for (let x = 0; x < image.width; x++) {
|
||||
result[y][x] = [pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255];
|
||||
imageArray[y][x] = [pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255, pixelsData[index++] / 255];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return imageArray;
|
||||
}
|
||||
|
||||
_imageTo3DArray(images) {
|
||||
throw new Error('not yet working!');
|
||||
const imagesArray = new Array(images.length);
|
||||
for (let i = 0; i < images.length; i++) {
|
||||
imagesArray[i] = this._imageTo2DArray(images[i]);
|
||||
}
|
||||
return imagesArray;
|
||||
}
|
||||
};
|
||||
@ -28,7 +28,6 @@ module.exports = class BaseFunctionNode {
|
||||
*
|
||||
*/
|
||||
constructor(functionName, jsFunction, options, paramTypes, returnType) {
|
||||
debugger;
|
||||
//
|
||||
// Internal vars setup
|
||||
//
|
||||
|
||||
@ -1012,6 +1012,8 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
);
|
||||
} else if (paramType === 'Number') {
|
||||
result.push(`uniform highp float user_${ paramName }`);
|
||||
} else {
|
||||
throw new Error(`Param type ${paramType} not supported in WebGL, only WebGL2`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,13 +31,18 @@
|
||||
this.color(pixel[0], pixel[1], pixel[2], pixel[3]);
|
||||
}, {
|
||||
graphical: true,
|
||||
debug: true,
|
||||
output : [138, 91]
|
||||
});
|
||||
getImages(function(images) {
|
||||
imageKernel(images);
|
||||
document.body.appendChild(imageKernel.getCanvas());
|
||||
assert.equal(true, true, 'does not throw');
|
||||
if (gpu._runner.constructor.name === 'WebGLRunner') {
|
||||
assert.throws(function() {
|
||||
// TODO: fallback to cpu? Probably not worth it.
|
||||
imageKernel(images);
|
||||
})
|
||||
} else {
|
||||
imageKernel(images);
|
||||
assert.equal(true, true, 'does not throw');
|
||||
}
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user