mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-25 16:08:02 +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
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
const { assert, skip, test, module: describe, only } = require('qunit');
|
|
const { GPU } = require('../../../../../../src');
|
|
|
|
describe('feature: to-string single precision constants Array');
|
|
|
|
function testConstant(mode, context, canvas) {
|
|
const gpu = new GPU({ mode });
|
|
const originalKernel = gpu.createKernel(function() {
|
|
return this.constants.a[this.thread.x];
|
|
}, {
|
|
canvas,
|
|
context,
|
|
output: [4],
|
|
precision: 'single',
|
|
constants: {
|
|
a: [1, 2, 3, 4]
|
|
}
|
|
});
|
|
const expected = new Float32Array([1,2,3,4]);
|
|
const originalResult = originalKernel();
|
|
assert.deepEqual(originalResult, expected);
|
|
const kernelString = originalKernel.toString();
|
|
const newResult = new Function('return ' + kernelString)()({ context, constants: { a: [1, 2, 3, 4] } })();
|
|
assert.deepEqual(newResult, expected);
|
|
gpu.destroy();
|
|
}
|
|
|
|
(GPU.isSinglePrecisionSupported && GPU.isWebGLSupported ? test : skip)('webgl', () => {
|
|
const canvas = document.createElement('canvas');
|
|
const context = canvas.getContext('webgl');
|
|
testConstant('webgl', context, canvas);
|
|
});
|
|
|
|
(GPU.isSinglePrecisionSupported && GPU.isWebGL2Supported ? test : skip)('webgl2', () => {
|
|
const canvas = document.createElement('canvas');
|
|
const context = canvas.getContext('webgl2');
|
|
testConstant('webgl2', context, canvas);
|
|
});
|
|
|
|
(GPU.isSinglePrecisionSupported && GPU.isHeadlessGLSupported ? test : skip)('headlessgl', () => {
|
|
testConstant('headlessgl', require('gl')(1, 1), null);
|
|
});
|
|
|
|
test('cpu', () => {
|
|
testConstant('cpu');
|
|
});
|