Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with complicated function dependencies #730

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/backend/function-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,6 @@ class FunctionBuilder {
if (functionIndex === -1) {
retList.push(functionName);
functionNode.toString(); //ensure JS trace is done
for (let i = 0; i < functionNode.calledFunctions.length; ++i) {
this.traceFunctionCalls(functionNode.calledFunctions[i], retList);
}
} else {
/**
* https://github.com/gpujs/gpu.js/issues/207
Expand All @@ -304,6 +301,9 @@ class FunctionBuilder {
const dependantFunctionName = retList.splice(functionIndex, 1)[0];
retList.push(dependantFunctionName);
}
for (let i = 0; i < functionNode.calledFunctions.length; ++i) {
this.traceFunctionCalls(functionNode.calledFunctions[i], retList);
}
}

return retList;
Expand Down
109 changes: 109 additions & 0 deletions test/internal/complicated-function-dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const { assert, skip, test, module: describe } = require("qunit");
const { GPU } = require("../../src");

describe("internal: complicated function dependencies");

function a() {
b();
c();
d();
e();
f();
return 1;
}
function b() {
g();
}
function c() {
g();
return 1;
}
function d() {
g();
return 1;
}
function e() {
g();
return 1;
}
function f() {
i();
m();
return 1;
}
function g() {
i();
j();
k();
return 1;
}
function h() {
o();
return 1;
}
function i() {
return 1;
}
function j() {
m();
n();
return 1;
}
function k() {
return 1;
}
function l() {
o();
p();
return 1;
}
function m() {
return 1;
}
function n() {
return 1;
}
function o() {
return 1;
}
function p() {
b();
return 1;
}

function complicatedFunctionDependecies(mode) {
const gpu = new GPU({ mode });
gpu.setFunctions([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p]);
const kernel = gpu
.createKernel(function () {
a();
return 1;
})
.setOutput([1]);

assert.deepEqual(kernel(), new Float32Array([1]));
}

test("auto", () => {
complicatedFunctionDependecies();
});

test("gpu", () => {
complicatedFunctionDependecies("gpu");
});

(GPU.isWebGLSupported ? test : skip)("webgl", () => {
complicatedFunctionDependecies("webgl");
});

(GPU.isWebGL2Supported ? test : skip)("webgl2", () => {
complicatedFunctionDependecies("webgl2");
});

(GPU.isHeadlessGLSupported ? test : skip)("headlessgl", () => {
complicatedFunctionDependecies("headlessgl");
});

test("cpu", () => {
complicatedFunctionDependecies("cpu");
});