forked from fingerecho/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel-string.js
More file actions
94 lines (90 loc) · 3.98 KB
/
Copy pathkernel-string.js
File metadata and controls
94 lines (90 loc) · 3.98 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'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(gpuKernel, name) {
return `() => {
${ kernelRunShortcut.toString() };
const utils = {
allPropertiesOf: ${ removeNoise(utils.allPropertiesOf.toString()) },
clone: ${ removeNoise(utils.clone.toString()) },
splitArray: ${ removeNoise(utils.splitArray.toString()) },
getArgumentType: ${ removeNoise(utils.getArgumentType.toString()) },
getDimensions: ${ removeNoise(utils.getDimensions.toString()) },
dimToTexSize: ${ removeNoise(utils.dimToTexSize.toString()) },
flattenTo: ${ removeNoise(utils.flattenTo.toString()) },
flatten2dArrayTo: ${ removeNoise(utils.flatten2dArrayTo.toString()) },
flatten3dArrayTo: ${ removeNoise(utils.flatten3dArrayTo.toString()) },
systemEndianness: '${ removeNoise(utils.systemEndianness()) }',
initWebGl: ${ removeNoise(utils.initWebGl.toString()) },
isArray: ${ removeNoise(utils.isArray.toString()) },
checkOutput: ${ removeNoise(utils.checkOutput.toString()) }
};
const Utils = utils;
const canvases = [];
const maxTexSizes = {};
class ${ name || 'Kernel' } {
constructor() {
this.maxTexSize = null;
this.argumentsLength = 0;
this._canvas = null;
this._webGl = null;
this.built = false;
this.program = null;
this.paramNames = ${ JSON.stringify(gpuKernel.paramNames) };
this.paramTypes = ${ JSON.stringify(gpuKernel.paramTypes) };
this.texSize = ${ JSON.stringify(gpuKernel.texSize) };
this.output = ${ JSON.stringify(gpuKernel.output) };
this.compiledFragShaderString = \`${ gpuKernel.compiledFragShaderString }\`;
this.compiledVertShaderString = \`${ gpuKernel.compiledVertShaderString }\`;
this.programUniformLocationCache = {};
this.textureCache = {};
this.subKernelOutputTextures = null;
this.subKernelOutputVariableNames = null;
this.uniform1fCache = {};
this.uniform1iCache = {};
this.uniform2fCache = {};
this.uniform2fvCache = {};
this.uniform2ivCache = {};
this.uniform3fvCache = {};
this.uniform3ivCache = {};
}
${ removeFnNoise(gpuKernel._getFragShaderString.toString()) }
${ removeFnNoise(gpuKernel._getVertShaderString.toString()) }
validateOptions() {}
setupParams() {}
setupConstants() {}
setCanvas(canvas) { this._canvas = canvas; return this; }
setWebGl(webGl) { this._webGl = webGl; return this; }
${ removeFnNoise(gpuKernel.getUniformLocation.toString()) }
${ removeFnNoise(gpuKernel.setupParams.toString()) }
${ removeFnNoise(gpuKernel.setupConstants.toString()) }
${ removeFnNoise(gpuKernel.build.toString()) }
${ removeFnNoise(gpuKernel.run.toString()) }
${ removeFnNoise(gpuKernel._addArgument.toString()) }
${ removeFnNoise(gpuKernel.getArgumentTexture.toString()) }
${ removeFnNoise(gpuKernel.getTextureCache.toString()) }
${ removeFnNoise(gpuKernel.getOutputTexture.toString()) }
${ removeFnNoise(gpuKernel.renderOutput.toString()) }
${ removeFnNoise(gpuKernel.updateMaxTexSize.toString()) }
${ removeFnNoise(gpuKernel._setupOutputTexture.toString()) }
${ removeFnNoise(gpuKernel.detachTextureCache.toString()) }
${ removeFnNoise(gpuKernel.setUniform1f.toString()) }
${ removeFnNoise(gpuKernel.setUniform1i.toString()) }
${ removeFnNoise(gpuKernel.setUniform2f.toString()) }
${ removeFnNoise(gpuKernel.setUniform2fv.toString()) }
${ removeFnNoise(gpuKernel.setUniform2iv.toString()) }
${ removeFnNoise(gpuKernel.setUniform3fv.toString()) }
${ removeFnNoise(gpuKernel.setUniform3iv.toString()) }
};
return kernelRunShortcut(new Kernel());
};`;
};