forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel-string.js
More file actions
61 lines (57 loc) · 1.99 KB
/
kernel-string.js
File metadata and controls
61 lines (57 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const utils = require('../../core/utils');
const kernelRunShortcut = require('../kernel-run-shortcut');
function removeFnNoise(fn) {
if (/^function /.test(fn)) {
fn = fn.substring(9);
}
return fn.replace(/[_]typeof/g, 'typeof');
}
function removeNoise(str) {
return str.replace(/[_]typeof/g, 'typeof');
}
module.exports = function(cpuKernel, name) {
return `() => {
${ kernelRunShortcut.toString() };
const utils = {
allPropertiesOf: ${ removeNoise(utils.allPropertiesOf.toString()) },
clone: ${ removeNoise(utils.clone.toString()) },
checkOutput: ${ removeNoise(utils.checkOutput.toString()) }
};
const Utils = utils;
class ${ name || 'Kernel' } {
constructor() {
this.argumentsLength = 0;
this._canvas = null;
this._webGl = null;
this.built = false;
this.program = null;
this.paramNames = ${ JSON.stringify(cpuKernel.paramNames) };
this.paramTypes = ${ JSON.stringify(cpuKernel.paramTypes) };
this.texSize = ${ JSON.stringify(cpuKernel.texSize) };
this.output = ${ JSON.stringify(cpuKernel.output) };
this._kernelString = \`${ cpuKernel._kernelString }\`;
this.output = ${ JSON.stringify(cpuKernel.output) };
this.run = function() {
this.run = null;
this.build();
return this.run.apply(this, arguments);
}.bind(this);
this.thread = {
x: 0,
y: 0,
z: 0
};
}
setCanvas(canvas) { this._canvas = canvas; return this; }
setWebGl(webGl) { this._webGl = webGl; return this; }
${ removeFnNoise(cpuKernel.build.toString()) }
${ removeFnNoise(cpuKernel.setupParams.toString()) }
${ removeFnNoise(cpuKernel.setupConstants.toString()) }
run () { ${ cpuKernel.kernelString } }
getKernelString() { return this._kernelString; }
${ removeFnNoise(cpuKernel.validateOptions.toString()) }
};
return kernelRunShortcut(new Kernel());
};`;
};