mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-25 16:08:02 +00:00
parent
16b77f7c15
commit
439969aeba
@ -250,7 +250,8 @@ module.exports = class BaseFunctionNode {
|
||||
|
||||
getParamType(paramName) {
|
||||
const paramIndex = this.paramNames.indexOf(paramName);
|
||||
if (this.parent === null) return null;
|
||||
if (paramIndex === -1) return null;
|
||||
if (!this.parent) return null;
|
||||
if (this.paramTypes[paramIndex]) return this.paramTypes[paramIndex];
|
||||
const calledFunctionArguments = this.parent.calledFunctionsArguments[this.functionName];
|
||||
for (let i = 0; i < calledFunctionArguments.length; i++) {
|
||||
@ -262,6 +263,20 @@ module.exports = class BaseFunctionNode {
|
||||
return null;
|
||||
}
|
||||
|
||||
getUserParamName(paramName) {
|
||||
const paramIndex = this.paramNames.indexOf(paramName);
|
||||
if (paramIndex === -1) return null;
|
||||
if (!this.parent) return null;
|
||||
const calledFunctionArguments = this.parent.calledFunctionsArguments[this.functionName];
|
||||
for (let i = 0; i < calledFunctionArguments.length; i++) {
|
||||
const calledFunctionArgument = calledFunctionArguments[i];
|
||||
if (calledFunctionArgument[paramIndex] !== null) {
|
||||
return calledFunctionArgument[paramIndex].name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
generate(options) {
|
||||
throw new Error('generate not defined on BaseFunctionNode');
|
||||
}
|
||||
|
||||
@ -400,7 +400,12 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
if (this.constants && this.constants.hasOwnProperty(idtNode.name)) {
|
||||
retArr.push('constants_' + idtNode.name);
|
||||
} else {
|
||||
retArr.push('user_' + idtNode.name);
|
||||
const userParamName = funcParam.getUserParamName(idtNode.name);
|
||||
if (userParamName !== null) {
|
||||
retArr.push('user_' + userParamName);
|
||||
} else {
|
||||
retArr.push('user_' + idtNode.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
test/html/issues/96-param-names.html
Normal file
17
test/html/issues/96-param-names.html
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>GPU.JS : FunctionBuilder unit testing</title>
|
||||
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
|
||||
|
||||
<!-- gpu.js scripts -->
|
||||
<script src="../../../bin/gpu.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="../../../node_modules/qunitjs/qunit/qunit.js"></script>
|
||||
<script src="../../src/issues/96-param-names.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -35,5 +35,6 @@
|
||||
<!-- bug issues -->
|
||||
<script src="../src/issues/31-nested-var-declare-test.js"></script>
|
||||
<script src="../src/issues/91-create-kernels-array.js"></script>
|
||||
<script src="../src/issues/96-param-names.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
34
test/src/issues/96-param-names.js
Normal file
34
test/src/issues/96-param-names.js
Normal file
@ -0,0 +1,34 @@
|
||||
QUnit.test( "Issue #96 - param names (GPU only)", function() {
|
||||
const A = [
|
||||
[1, 1],
|
||||
[1, 1],
|
||||
[1, 1]
|
||||
];
|
||||
|
||||
const B = [
|
||||
[1, 1, 1],
|
||||
[1, 1, 1]
|
||||
];
|
||||
|
||||
const gpu = new GPU();
|
||||
|
||||
function multiply(m, n, y, x) {
|
||||
var sum = 0;
|
||||
for (var i = 0; i < 2; i++) {
|
||||
sum += m[y][i] * n[i][x];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
var kernels = gpu.createKernels({
|
||||
multiplyResult: multiply
|
||||
}, function (a, b) {
|
||||
return multiply(b, a, this.thread.y, this.thread.x);
|
||||
})
|
||||
.setDimensions([B.length, A.length]);
|
||||
|
||||
const result = kernels(A, B).result;
|
||||
QUnit.assert.deepEqual(QUnit.extend([], result[0]), [2,2]);
|
||||
QUnit.assert.deepEqual(QUnit.extend([], result[1]), [2,2]);
|
||||
QUnit.assert.deepEqual(QUnit.extend([], result[2]), [0,0]);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user