Skip to content

Commit af7060d

Browse files
webgl1 and webgl2, together at last, and tested.
1 parent ed247f5 commit af7060d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4441
-1411
lines changed

bin/gpu-core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 1.2.0
8-
* @date Thu Mar 08 2018 14:35:39 GMT-0500 (EST)
8+
* @date Thu Mar 08 2018 17:26:16 GMT-0500 (EST)
99
*
1010
* @license MIT
1111
* The MIT License

bin/gpu-core.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/gpu.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 1.2.0
8-
* @date Thu Mar 08 2018 14:35:39 GMT-0500 (EST)
8+
* @date Thu Mar 08 2018 17:26:16 GMT-0500 (EST)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -927,7 +927,16 @@ module.exports = function (_KernelBase) {
927927
}
928928

929929
var prototypes = builder.getPrototypes();
930-
var kernel = prototypes.shift();
930+
var kernel = null;
931+
if (prototypes.length > 1) {
932+
prototypes = prototypes.filter(function (fn) {
933+
if (/^function/.test(fn)) return fn;
934+
kernel = fn;
935+
return false;
936+
});
937+
} else {
938+
kernel = prototypes.shift();
939+
}
931940
var kernelString = this._kernelString = '\n\t\tvar LOOP_MAX = ' + this._getLoopMaxString() + ';\n\t\tvar _this = this;\n ' + (this.subKernelOutputVariableNames === null ? '' : this.subKernelOutputVariableNames.map(function (name) {
932941
return ' var ' + name + ' = null;\n';
933942
}).join('')) + '\n return function (' + this.paramNames.map(function (paramName) {
@@ -4303,19 +4312,25 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
43034312
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; }
43044313

43054314
var WebGLRunner = require('../web-gl/runner');
4315+
var WebGL2FunctionBuilder = require('./function-builder');
4316+
var WebGL2Kernel = require('./kernel');
43064317

43074318
module.exports = function (_WebGLRunner) {
4308-
_inherits(WebGL2Runner, _WebGLRunner);
4319+
_inherits(WebGL2Runner, _WebGLRunner);
43094320

4310-
function WebGL2Runner() {
4311-
_classCallCheck(this, WebGL2Runner);
4321+
function WebGL2Runner(settings) {
4322+
_classCallCheck(this, WebGL2Runner);
43124323

4313-
return _possibleConstructorReturn(this, (WebGL2Runner.__proto__ || Object.getPrototypeOf(WebGL2Runner)).apply(this, arguments));
4314-
}
4324+
var _this = _possibleConstructorReturn(this, (WebGL2Runner.__proto__ || Object.getPrototypeOf(WebGL2Runner)).call(this, new WebGL2FunctionBuilder(), settings));
43154325

4316-
return WebGL2Runner;
4326+
_this.Kernel = WebGL2Kernel;
4327+
_this.kernel = null;
4328+
return _this;
4329+
}
4330+
4331+
return WebGL2Runner;
43174332
}(WebGLRunner);
4318-
},{"../web-gl/runner":15}],23:[function(require,module,exports){
4333+
},{"../web-gl/runner":15,"./function-builder":19,"./kernel":21}],23:[function(require,module,exports){
43194334
"use strict";
43204335

43214336
module.exports = "#version 300 es\n__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\nin highp vec2 vTexCoord;\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 = texture(tex, st / texSize);\n __GET_RESULT__;\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 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 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\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}";
@@ -5097,7 +5112,7 @@ var Utils = function (_UtilsCore) {
50975112

50985113
var GPU = require('../index');
50995114
var x = new GPU({
5100-
mode: 'webgl-validator'
5115+
mode: 'webgl2-validator'
51015116
}).createKernel(function () {
51025117
return 1;
51035118
}, {
@@ -9960,12 +9975,7 @@ pp$8.readEscapedChar = function(inTemplate) {
99609975
this.pos += octalStr.length - 1;
99619976
ch = this.input.charCodeAt(this.pos);
99629977
if ((octalStr !== "0" || ch == 56 || ch == 57) && (this.strict || inTemplate)) {
9963-
this.invalidStringToken(
9964-
this.pos - 1 - octalStr.length,
9965-
inTemplate
9966-
? "Octal literal in template string"
9967-
: "Octal literal in strict mode"
9968-
);
9978+
this.invalidStringToken(this.pos - 1 - octalStr.length, "Octal literal in strict mode");
99699979
}
99709980
return String.fromCharCode(octal)
99719981
}
@@ -10024,7 +10034,7 @@ pp$8.readWord = function() {
1002410034
};
1002510035

1002610036

10027-
var version = "5.5.3";
10037+
var version = "5.5.0";
1002810038

1002910039

1003010040
function parse(input, options) {

bin/gpu.min.js

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

dist/backend/cpu/kernel.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,16 @@ module.exports = function (_KernelBase) {
226226
}
227227

228228
var prototypes = builder.getPrototypes();
229-
var kernel = prototypes.shift();
229+
var kernel = null;
230+
if (prototypes.length > 1) {
231+
prototypes = prototypes.filter(function (fn) {
232+
if (/^function/.test(fn)) return fn;
233+
kernel = fn;
234+
return false;
235+
});
236+
} else {
237+
kernel = prototypes.shift();
238+
}
230239
var kernelString = this._kernelString = '\n\t\tvar LOOP_MAX = ' + this._getLoopMaxString() + ';\n\t\tvar _this = this;\n ' + (this.subKernelOutputVariableNames === null ? '' : this.subKernelOutputVariableNames.map(function (name) {
231240
return ' var ' + name + ' = null;\n';
232241
}).join('')) + '\n return function (' + this.paramNames.map(function (paramName) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4+
5+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
6+
7+
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; }
8+
9+
var FunctionBuilderBase = require('../function-builder-base');
10+
var WebGLFunctionNode = require('./function-node');
11+
12+
/**
13+
* @class WebGLFunctionBuilder
14+
*
15+
* @extends FunctionBuilderBase
16+
*
17+
* @desc Builds webGl functions (shaders) from JavaScript function Strings
18+
*
19+
*/
20+
module.exports = function (_FunctionBuilderBase) {
21+
_inherits(WebGL2FunctionBuilder, _FunctionBuilderBase);
22+
23+
function WebGL2FunctionBuilder() {
24+
_classCallCheck(this, WebGL2FunctionBuilder);
25+
26+
var _this = _possibleConstructorReturn(this, (WebGL2FunctionBuilder.__proto__ || Object.getPrototypeOf(WebGL2FunctionBuilder)).call(this));
27+
28+
_this.Node = WebGLFunctionNode;
29+
return _this;
30+
}
31+
32+
return WebGL2FunctionBuilder;
33+
}(FunctionBuilderBase);

0 commit comments

Comments
 (0)