gpu.js/test/issues/346-uint8array-converted.js
Robert Plummer 00ee2ba982 feat: Refactor dimensional values and expose the bitRatio all the way to the function node
fix: Added test suite for arrays and inputs for webgl and webgl2
fix: Rename "floatOutput" feature to "precision".  Values can be "unsigned" or "single"
fix: Add input and Input to typings
fix: Use Int32Array for input.size
2019-04-20 09:59:49 -04:00

57 lines
1.7 KiB
JavaScript

const { assert, skip, test, module: describe } = require('qunit');
const { GPU } = require('../../src');
describe('issue #346');
const DATA_MAX = 1024;
const uint8data = new Uint8Array(DATA_MAX);
const uint16data = new Uint16Array(DATA_MAX);
for (let i = 0; i < DATA_MAX; i++) {
uint8data[i] = Math.random() * 255;
uint16data[i] = Math.random() * 255 * 255;
}
function buildUintArrayInputKernel(mode, data) {
const gpu = new GPU({ mode });
const largeArrayAddressKernel = gpu.createKernel(function(data) {
return data[this.thread.x];
}, { precision: 'unsigned' })
.setOutput([DATA_MAX]);
const result = largeArrayAddressKernel(data);
let same = true;
let i = 0;
for (; i < DATA_MAX; i++) {
if (result[i] !== data[i]) {
same = false;
break;
}
}
assert.ok(same, "not all elements are the same, failed on index:" + i);
gpu.destroy();
}
(GPU.isWebGLSupported ? test : skip)('Issue #346 uint8 input array - webgl', () => {
buildUintArrayInputKernel('webgl', uint8data);
});
(GPU.isWebGL2Supported ? test : skip)('Issue #346 uint8 input array - webgl2', () => {
buildUintArrayInputKernel('webgl2', uint8data);
});
(GPU.isHeadlessGLSupported ? test : skip)('Issue #346 uint8 input array - headlessgl', () => {
buildUintArrayInputKernel('headlessgl', uint8data);
});
(GPU.isWebGLSupported ? test : skip)('Issue #346 uint16 input array - webgl', () => {
buildUintArrayInputKernel('webgl', uint16data);
});
(GPU.isWebGL2Supported ? test : skip)('Issue #346 uint16 input array - webgl2', () => {
buildUintArrayInputKernel('webgl2', uint16data);
});
(GPU.isHeadlessGLSupported ? test : skip)('Issue #346 uint16 input array - headlessgl', () => {
buildUintArrayInputKernel('headlessgl', uint16data);
});