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
64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
const { assert, skip, test, module: describe, only } = require('qunit');
|
|
const { GPU } = require('../../../../../../src');
|
|
|
|
describe('feature: to-string single precision constants Boolean');
|
|
|
|
function testConstant(mode, context, canvas) {
|
|
const gpu = new GPU({ mode });
|
|
const originalKernel1 = gpu.createKernel(function() {
|
|
return this.constants.a ? 42 : -42;
|
|
}, {
|
|
canvas,
|
|
context,
|
|
output: [1],
|
|
precision: 'single',
|
|
constants: {
|
|
a: true
|
|
}
|
|
});
|
|
const originalKernel2 = gpu.createKernel(function() {
|
|
return this.constants.a ? 42 : -42;
|
|
}, {
|
|
canvas,
|
|
context,
|
|
output: [1],
|
|
precision: 'single',
|
|
constants: {
|
|
a: false
|
|
}
|
|
});
|
|
assert.deepEqual(originalKernel1()[0], 42);
|
|
assert.deepEqual(originalKernel2()[0], -42);
|
|
const kernelString1 = originalKernel1.toString();
|
|
const kernelString2 = originalKernel2.toString();
|
|
const newKernel1 = new Function('return ' + kernelString1)()({ context, constants: { a: true } });
|
|
const newKernel2 = new Function('return ' + kernelString1)()({ context, constants: { a: false } });
|
|
const newKernel3 = new Function('return ' + kernelString2)()({ context, constants: { a: false } });
|
|
const newKernel4 = new Function('return ' + kernelString2)()({ context, constants: { a: true } });
|
|
assert.deepEqual(newKernel1()[0], 42);
|
|
assert.deepEqual(newKernel2()[0], 42);
|
|
assert.deepEqual(newKernel3()[0], -42);
|
|
assert.deepEqual(newKernel4()[0], -42);
|
|
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');
|
|
});
|