forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction-builder.js
More file actions
98 lines (90 loc) · 3.04 KB
/
function-builder.js
File metadata and controls
98 lines (90 loc) · 3.04 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
95
96
97
98
const FunctionBuilderBase = require('../function-builder-base');
const WebGLFunctionNode = require('./function-node');
const utils = require('../../utils');
module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase {
addFunction(functionName, jsFunction, paramTypes, returnType) {
this.addFunctionNode(
new WebGLFunctionNode(functionName, jsFunction, paramTypes, returnType)
.setAddFunction(this.addFunction.bind(this))
);
}
///
/// Function: getStringFromFunctionNames
///
/// Parameters:
/// functionList - {[String,...]} List of function to build the webgl string.
///
/// Returns:
/// {String} The full webgl string, of all the various functions. Trace optimized if functionName given
///
getStringFromFunctionNames(functionList) {
const ret = [];
for (let i = 0; i < functionList.length; ++i) {
const node = this.nodeMap[functionList[i]];
if (node) {
ret.push(this.nodeMap[functionList[i]].getFunctionString());
}
}
return ret.join('\n');
}
getPrototypeStringFromFunctionNames(functionList, opt) {
const ret = [];
for (let i = 0; i < functionList.length; ++i) {
const node = this.nodeMap[functionList[i]];
if (node) {
ret.push(node.getFunctionPrototypeString(opt));
}
}
return ret.join('\n');
}
///
/// Function: getString
///
/// Parameters:
/// functionName - {String} Function name to trace from. If null, it returns the WHOLE builder stack
///
/// Returns:
/// {String} The full webgl string, of all the various functions. Trace optimized if functionName given
///
getString(functionName, opt) {
if (opt === undefined) {
opt = {};
}
if (functionName) {
return this.getStringFromFunctionNames(this.traceFunctionCalls(functionName, [], opt).reverse(), opt);
}
return this.getStringFromFunctionNames(Object.keys(this.nodeMap), opt);
}
///
/// Function: getPrototypeString
///
/// Parameters:
/// functionName - {String} Function name to trace from. If null, it returns the WHOLE builder stack
///
/// Returns:
/// {String} The full webgl string, of all the various functions. Trace optimized if functionName given
///
getPrototypeString(functionName) {
this.rootKernel.generate();
if (functionName) {
return this.getPrototypeStringFromFunctionNames(this.traceFunctionCalls(functionName, []).reverse());
}
return this.getPrototypeStringFromFunctionNames(Object.keys(this.nodeMap));
}
addKernel(fnString, options, paramNames, paramTypes) {
const kernelNode = new WebGLFunctionNode('kernel', fnString, options, paramTypes);
kernelNode.setAddFunction(this.addFunction.bind(this));
kernelNode.paramNames = paramNames;
kernelNode.paramTypes = paramTypes;
kernelNode.isRootKernel = true;
this.addFunctionNode(kernelNode);
return kernelNode;
}
addSubKernel(jsFunction, options, paramTypes, returnType) {
const kernelNode = new WebGLFunctionNode(null, jsFunction, options, paramTypes, returnType);
kernelNode.setAddFunction(this.addFunction.bind(this));
kernelNode.isSubKernel = true;
this.addFunctionNode(kernelNode);
return kernelNode;
}
};