gpu.js/test/features/to-string/precision/unsigned/kernel-map/array/memory-optimized-number-texture.js
Robert Plummer 27f4efb8d9 fix: Proper kernel.toString() unit tests (good grief, so many!) for CPU and GPU
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
2019-06-03 19:32:21 -04:00

52 lines
1.7 KiB
JavaScript

const { assert, skip, test, module: describe, only } = require('qunit');
const { GPU } = require('../../../../../../../src');
describe('feature: to-string unsigned precision array style kernel map returns MemoryOptimizedNumberTexture');
function testReturn(mode, context, canvas) {
const gpu = new GPU({ mode });
function addOne(value) {
return value + 1;
}
const originalKernel = gpu.createKernelMap([addOne], function(a) {
const result = a[this.thread.x] + 1;
addOne(result);
return result;
}, {
canvas,
context,
output: [6],
precision: 'unsigned',
pipeline: true,
optimizeFloatMemory: true,
});
const a = [1, 2, 3, 4, 5, 6];
const expected = new Float32Array([2, 3, 4, 5, 6, 7]);
const expectedZero = new Float32Array([3, 4, 5, 6, 7, 8]);
const originalResult = originalKernel(a);
assert.deepEqual(originalResult.result.toArray(), expected);
assert.deepEqual(originalResult[0].toArray(), expectedZero);
const kernelString = originalKernel.toString(a);
const newResult = new Function('return ' + kernelString)()({ context })(a);
assert.deepEqual(newResult.result.toArray(), expected);
assert.deepEqual(newResult[0].toArray(), expectedZero);
gpu.destroy();
}
(GPU.isWebGLSupported ? test : skip)('webgl', () => {
const canvas = document.createElement('canvas');
const context = canvas.getContext('webgl');
testReturn('webgl', context, canvas);
});
(GPU.isWebGL2Supported ? test : skip)('webgl2', () => {
const canvas = document.createElement('canvas');
const context = canvas.getContext('webgl2');
testReturn('webgl2', context, canvas);
});
(GPU.isHeadlessGLSupported ? test : skip)('headlessgl', () => {
testReturn('headlessgl', require('gl')(1, 1), null);
});