Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('Automatic naming support webgl', () => {
function hello_world() {
return 42;
}
// Create a function hello node
const node = new WebGLFunctionNode(hello_world.toString(), { output: [1] });
assert.notEqual(node, null, 'class creation check');
assert.equal(node.name, 'hello_world');
});
test('Automatic naming support webgl2', () => {
function hello_world() {
return 42;
}
// Create a function hello node
const node = new WebGL2FunctionNode(hello_world.toString(), { output: [1] });
assert.notEqual(node, null, 'class creation check');
assert.equal(node.name, 'hello_world');
});
function testKernelTextureDoesNotLeak(precision, done, mode) {
const gpu = new GPU({ mode });
const toTexture = gpu.createKernel(function(value) {
return value[this.thread.x];
}, {
output: [1],
pipeline: true,
precision,
});
const one = toTexture([1]);
assert.equal(one.texture._refs, 2); // one's texture will be used in two places at first, in one and toTexture.texture
assert.equal(toTexture.texture.texture, one.texture); // very important, a clone was mode, but not a deep clone
assert.notEqual(one, toTexture.texture);
const two = toTexture([2]);
assert.equal(one.texture._refs, 1); // was tracked on toTexture.texture, and deleted
assert.equal(toTexture.texture.texture, two.texture);
assert.notEqual(toTexture.texture.texture, one.texture);
assert.equal(two.texture._refs, 2);
one.delete();
two.delete();
assert.equal(one.texture._refs, 0);
assert.equal(two.texture._refs, 1); // still used by toTexture.texture
two.delete(); // already deleted
assert.equal(two.texture._refs, 1); // still used by toTexture
gpu.destroy()
.then(() => {
assert.equal(two.texture._refs, 0);
done();
});
settings = _settings;
this.context = 'context';
this.canvas = 'canvas';
this.subKernels = _settings.subKernels;
}
}
gpu.Kernel = MockKernel;
const subKernels = {
bobResult: bob,
tomResult: tom
};
const kernelSource = function() {};
const masterSettings = {};
const kernel = gpu.createKernelMap(subKernels, kernelSource, masterSettings);
assert.equal(source, kernelSource.toString());
assert.notEqual(settings, masterSettings);
assert.equal(gpu.canvas, 'canvas');
assert.equal(gpu.context, 'context');
assert.equal(settings.functions, gpu.functions);
assert.equal(settings.nativeFunctions, gpu.nativeFunctions);
assert.equal(settings.gpu, gpu);
assert.equal(settings.validate, true);
assert.deepEqual(kernel.subKernels, [
{
name: 'bob',
source: bob.toString(),
property: 'bobResult'
},
{
name: 'tom',
source: tom.toString(),
property: 'tomResult'
.setOutput([10, 10, 10])
.setPipeline(true)
.setPrecision('single')
)();
const expected = texture.toArray();
const kernel = gpu.createKernel(function(value) {
return value[this.thread.z][this.thread.y][this.thread.x];
})
.setArgumentTypes({
value: 'Array3D(4)'
})
.setOutput([10, 10, 10])
.setPipeline(false)
.setPrecision('single');
assert.notEqual(texture.constructor, Array);
assert.equal(expected.constructor, Array);
assert.deepEqual(kernel(texture), expected);
assert.deepEqual(kernel(expected), expected);
gpu.destroy();
}
.setOutput([10])
.setPipeline(true)
.setPrecision('single')
)();
const expected = texture.toArray();
const kernel = gpu.createKernel(function(value) {
return value[this.thread.x];
})
.setArgumentTypes({
value: 'Array1D(2)'
})
.setOutput([10])
.setPipeline(false)
.setPrecision('single');
assert.notEqual(texture.constructor, Array);
assert.equal(expected.constructor, Array);
assert.deepEqual(kernel(texture), expected);
assert.deepEqual(kernel(expected), expected);
gpu.destroy();
}
function copy1DTexture(precision, mode) {
const gpu = new GPU({ mode });
function makeTexture() {
return (gpu.createKernel(function() {
return this.thread.x;
}, {
output: [5],
pipeline: true,
precision
}))();
}
const texture = makeTexture();
const clone = texture.clone();
assert.notEqual(texture, clone);
assert.equal(texture.texture, clone.texture);
assert.deepEqual(texture.toArray(), clone.toArray());
gpu.destroy();
}
.setOutput([10, 10, 10])
.setPipeline(true)
.setPrecision('single')
)();
const expected = texture.toArray();
const kernel = gpu.createKernel(function(value) {
return value[this.thread.z][this.thread.y][this.thread.x];
})
.setArgumentTypes({
value: 'Array3D(2)'
})
.setOutput([10, 10, 10])
.setPipeline(false)
.setPrecision('single');
assert.notEqual(texture.constructor, Array);
assert.equal(expected.constructor, Array);
assert.deepEqual(kernel(texture), expected);
assert.deepEqual(kernel(expected), expected);
gpu.destroy();
}
.setOutput([10])
.setPipeline(true)
.setPrecision('single')
)();
const expected = texture.toArray();
const kernel = gpu.createKernel(function(value) {
return value[this.thread.x];
})
.setArgumentTypes({
value: 'Array'
})
.setOutput([10])
.setPipeline(false)
.setPrecision('single');
assert.notEqual(texture.constructor, Array);
assert.equal(expected.constructor, Float32Array);
assert.deepEqual(kernel(texture), expected);
assert.deepEqual(kernel(expected), expected);
gpu.destroy();
}