gpu.js/test/internal/deep-types.js
Robert Plummer ee7baf70ba fix: Array handling (2,3,4) for webgl2 & webgl1 (headlessgl next)
fix: Float handling
feat: added `optimizeFloatMemory` to better exemplify what it does and replace `floatTextures` and its voodoo in webgl2
feat: end to end strong type detection
Note: added a bunch of TODO's this is just a good resting point.
2019-04-11 19:41:58 -04:00

89 lines
2.8 KiB
JavaScript

const { assert, test, module: describe, only, skip } = require('qunit');
const { GPU } = require('../../src');
describe('internal: deep types');
function oneLayerDeepFloat(mode) {
const gpu = new GPU({ mode });
function childFunction(childFunctionArgument1) {
return childFunctionArgument1 + 1;
}
gpu.addFunction(childFunction);
const kernel = gpu.createKernel(function(kernelArgument1) {
return childFunction(kernelArgument1);
}, { output: [1] });
const result = kernel(1.5);
assert.equal(result[0], 2.5);
}
(GPU.isWebGLSupported ? test : skip)('one layer deep float WebGL', () => {
oneLayerDeepFloat('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('one layer deep float WebGL2', () => {
oneLayerDeepFloat('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('one layer deep float HeadlessGL', () => {
oneLayerDeepFloat('headlessgl');
});
function twoLayerDeepFloat(mode) {
const gpu = new GPU({ mode });
function child1Function(child1FunctionArgument1) {
return child2Function(child1FunctionArgument1);
}
function child2Function(child2FunctionArgument1) {
return child2FunctionArgument1 + 1;
}
gpu
.addFunction(child1Function)
.addFunction(child2Function);
const kernel = gpu.createKernel(function(kernelArgument1) {
return child1Function(kernelArgument1);
}, { output: [1] });
const result = kernel(1.5);
assert.equal(result[0], 2.5);
}
(GPU.isWebGLSupported ? test : skip)('two layer deep float WebGL', () => {
twoLayerDeepFloat('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('two layer deep float WebGL2', () => {
twoLayerDeepFloat('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('two layer deep float HeadlessGL', () => {
twoLayerDeepFloat('headlessgl');
});
function threeLayerDeepFloat(mode) {
const gpu = new GPU({ mode });
function child1Function(child1FunctionArgument1) {
return child2Function(child1FunctionArgument1);
}
function child2Function(child2FunctionArgument1) {
return child3Function(child2FunctionArgument1 + 1);
}
function child3Function(child3FunctionArgument1) {
return child3FunctionArgument1 + 1;
}
gpu
.addFunction(child1Function)
.addFunction(child2Function)
.addFunction(child3Function);
const kernel = gpu.createKernel(function(kernelArgument1) {
return child1Function(kernelArgument1);
}, { output: [1] });
const result = kernel(1.5);
assert.equal(result[0], 3.5);
}
(GPU.isWebGLSupported ? test : skip)('three layer deep float WebGL', () => {
threeLayerDeepFloat('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('three layer deep float WebGL2', () => {
threeLayerDeepFloat('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('three layer deep float HeadlessGL', () => {
threeLayerDeepFloat('headlessgl');
});