mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-18 16:04:10 +00:00
fix: Documentation for what types are and are not tracked fix: Added documentation for testing and building fix: Some destructuring
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
const { assert, skip, test, module: describe, only } = require('qunit');
|
|
const { GPU } = require('../../../../../../src');
|
|
|
|
describe('feature: to-string unsigned precision arguments Array3D');
|
|
|
|
function testArgument(mode, context, canvas) {
|
|
const gpu = new GPU({ mode });
|
|
const originalKernel = gpu.createKernel(function(a) {
|
|
let sum = 0;
|
|
for (let z = 0; z < 2; z++) {
|
|
for (let y = 0; y < 2; y++) {
|
|
sum += a[z][y][this.thread.x];
|
|
}
|
|
}
|
|
return sum;
|
|
}, {
|
|
canvas,
|
|
context,
|
|
output: [2],
|
|
precision: 'unsigned',
|
|
});
|
|
|
|
const a = [
|
|
[
|
|
[1, 2],
|
|
[3, 4],
|
|
],
|
|
[
|
|
[5, 6],
|
|
[7, 8],
|
|
]
|
|
];
|
|
const expected = new Float32Array([16, 20]);
|
|
const originalResult = originalKernel(a);
|
|
assert.deepEqual(originalResult, expected);
|
|
const kernelString = originalKernel.toString(a);
|
|
const newKernel = new Function('return ' + kernelString)()({ context });
|
|
const newResult = newKernel(a);
|
|
assert.deepEqual(newResult, expected);
|
|
|
|
const b = [
|
|
[
|
|
[1, 1],
|
|
[1, 1],
|
|
],
|
|
[
|
|
[1, 1],
|
|
[1, 1],
|
|
]
|
|
];
|
|
const expected2 = new Float32Array([4, 4]);
|
|
const newResult2 = newKernel(b);
|
|
assert.deepEqual(newResult2, expected2);
|
|
gpu.destroy();
|
|
}
|
|
|
|
(GPU.isWebGLSupported ? test : skip)('webgl', () => {
|
|
const canvas = document.createElement('canvas');
|
|
const context = canvas.getContext('webgl');
|
|
testArgument('webgl', context, canvas);
|
|
});
|
|
|
|
(GPU.isWebGL2Supported ? test : skip)('webgl2', () => {
|
|
const canvas = document.createElement('canvas');
|
|
const context = canvas.getContext('webgl2');
|
|
testArgument('webgl2', context, canvas);
|
|
});
|
|
|
|
(GPU.isHeadlessGLSupported ? test : skip)('headlessgl', () => {
|
|
testArgument('headlessgl', require('gl')(1, 1), null);
|
|
});
|
|
|
|
test('cpu', () => {
|
|
testArgument('cpu');
|
|
});
|