mirror of
https://github.com/gpujs/gpu.js.git
synced 2025-12-08 20:35:56 +00:00
feat: `switch` statements
feat: `kernel.toString()` has as well `.getPixels()`
fix: Proper fallback when arguments or constants are not supported
fix: Removal of infamous `|| 'Number'` for argument types and return types
fix: detect circlical logic in `FunctionBuilder.lookupReturnType()` and tests
fix: Allow subKernels to get their type detected as well
fix: `FunctionNode`'s `typeLookupMap` didn't have 'Float' or 'Integer'
feat: Turn off context checking in kernel, via `{ checkContext: false }`, used for `kernel.toString()`
fix: `GPU.upgradeDeprecatedCreateKernelSettings` to have a default return value
fix: Typings
fix: `kernelRunShortcut()` to better switch kernel when replacing
feat: It order to flatten methods, for `kernel.toString()` `utils.flattenFunctionToString()` and light unit testing of it
fix: Added sinon for testing
fix: Bump gl-wiretap
92 lines
2.5 KiB
JavaScript
92 lines
2.5 KiB
JavaScript
const { assert, test, skip, module: describe, only } = require('qunit');
|
|
const { GPU } = require('../../src');
|
|
|
|
describe('internal: GPU methods');
|
|
|
|
test('.createKernelMap() object map with settings', () => {
|
|
const gpu = new GPU();
|
|
let source = null;
|
|
let settings = null;
|
|
function bob() {}
|
|
function tom() {}
|
|
class MockKernel {
|
|
constructor(_source, _settings) {
|
|
source = _source;
|
|
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'
|
|
}
|
|
]);
|
|
});
|
|
|
|
test('.createKernelMap() array map with settings', () => {
|
|
const gpu = new GPU();
|
|
let source = null;
|
|
let settings = null;
|
|
function bob() {}
|
|
function tom() {}
|
|
class MockKernel {
|
|
constructor(_source, _settings) {
|
|
source = _source;
|
|
settings = _settings;
|
|
this.context = 'context';
|
|
this.canvas = 'canvas';
|
|
this.subKernels = _settings.subKernels;
|
|
}
|
|
}
|
|
gpu.Kernel = MockKernel;
|
|
const subKernels = [bob, 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: 0
|
|
},
|
|
{
|
|
name: 'tom',
|
|
source: tom.toString(),
|
|
property: 1
|
|
}
|
|
]);
|
|
});
|