|
1 |
| -const { assert, skip, test, module: describe } = require('qunit'); |
| 1 | +const { assert, skip, test, module: describe, only } = require('qunit'); |
2 | 2 | const { GPU } = require('../../src');
|
3 | 3 |
|
4 |
| -describe('function return'); |
| 4 | +describe('features: function return'); |
5 | 5 |
|
6 |
| -function functionReturn( mode ) { |
| 6 | +function functionReturnFloat( mode ) { |
7 | 7 | const gpu = new GPU({ mode });
|
8 | 8 | const f = gpu.createKernel(function() {
|
9 |
| - return 42.0; |
| 9 | + return 42; |
10 | 10 | }, {
|
11 | 11 | output : [1]
|
12 | 12 | });
|
13 |
| - assert.ok( f !== null, "function generated test"); |
14 |
| - assert.equal(f()[0], 42.0, "basic return function test"); |
| 13 | + assert.ok( f !== null, 'function generated test'); |
| 14 | + assert.equal(f()[0], 42); |
15 | 15 | gpu.destroy();
|
16 | 16 | }
|
17 | 17 |
|
18 |
| -test("auto", () => { |
19 |
| - functionReturn(null); |
| 18 | +test('float auto', () => { |
| 19 | + functionReturnFloat(null); |
20 | 20 | });
|
21 | 21 |
|
22 |
| -test("gpu", () => { |
23 |
| - functionReturn("gpu"); |
| 22 | +test('float gpu', () => { |
| 23 | + functionReturnFloat('gpu'); |
24 | 24 | });
|
25 | 25 |
|
26 |
| -(GPU.isWebGLSupported ? test : skip)("webgl", () => { |
27 |
| - functionReturn("webgl"); |
| 26 | +(GPU.isWebGLSupported ? test : skip)('float webgl', () => { |
| 27 | + functionReturnFloat('webgl'); |
28 | 28 | });
|
29 | 29 |
|
30 |
| -(GPU.isWebGL2Supported ? test : skip)("webgl2", () => { |
31 |
| - functionReturn("webgl2"); |
| 30 | +(GPU.isWebGL2Supported ? test : skip)('float webgl2', () => { |
| 31 | + functionReturnFloat('webgl2'); |
32 | 32 | });
|
33 | 33 |
|
34 |
| -(GPU.isHeadlessGLSupported ? test : skip)("headlessgl", () => { |
35 |
| - functionReturn("headlessgl"); |
| 34 | +(GPU.isHeadlessGLSupported ? test : skip)('float headlessgl', () => { |
| 35 | + functionReturnFloat('headlessgl'); |
36 | 36 | });
|
37 | 37 |
|
38 |
| -test("cpu", () => { |
39 |
| - functionReturn("cpu"); |
| 38 | +test('float cpu', () => { |
| 39 | + functionReturnFloat('cpu'); |
| 40 | +}); |
| 41 | + |
| 42 | + |
| 43 | +function functionReturnArray2( mode ) { |
| 44 | + const gpu = new GPU({ mode }); |
| 45 | + const f = gpu.createKernel(function() { |
| 46 | + return [42, 43]; |
| 47 | + }, { |
| 48 | + output : [1] |
| 49 | + }); |
| 50 | + assert.ok( f !== null, 'function generated test'); |
| 51 | + const result = f(); |
| 52 | + // TODO, make assertion work |
| 53 | + // assert(result[0].constructor, Float32Array); |
| 54 | + assert.equal(result[0][0], 42); |
| 55 | + assert.equal(result[0][1], 43); |
| 56 | + gpu.destroy(); |
| 57 | +} |
| 58 | + |
| 59 | +test('Array(2) auto', () => { |
| 60 | + functionReturnArray2(null); |
| 61 | +}); |
| 62 | + |
| 63 | +test('Array(2) gpu', () => { |
| 64 | + functionReturnArray2('gpu'); |
| 65 | +}); |
| 66 | + |
| 67 | +(GPU.isWebGLSupported ? test : skip)('Array(2) webgl', () => { |
| 68 | + functionReturnArray2('webgl'); |
| 69 | +}); |
| 70 | + |
| 71 | +(GPU.isWebGL2Supported ? test : skip)('Array(2) webgl2', () => { |
| 72 | + functionReturnArray2('webgl2'); |
| 73 | +}); |
| 74 | + |
| 75 | +(GPU.isHeadlessGLSupported ? test : skip)('Array(2) headlessgl', () => { |
| 76 | + functionReturnArray2('headlessgl'); |
| 77 | +}); |
| 78 | + |
| 79 | +test('Array(2) cpu', () => { |
| 80 | + functionReturnArray2('cpu'); |
| 81 | +}); |
| 82 | + |
| 83 | +function functionReturnArray3( mode ) { |
| 84 | + const gpu = new GPU({ mode }); |
| 85 | + const f = gpu.createKernel(function() { |
| 86 | + return [42, 43, 44]; |
| 87 | + }, { |
| 88 | + output : [1] |
| 89 | + }); |
| 90 | + assert.ok( f !== null, 'function generated test'); |
| 91 | + const result = f(); |
| 92 | + // TODO, make assertion work |
| 93 | + // assert(result[0].constructor, Float32Array); |
| 94 | + assert.equal(result[0][0], 42); |
| 95 | + assert.equal(result[0][1], 43); |
| 96 | + assert.equal(result[0][2], 44); |
| 97 | + gpu.destroy(); |
| 98 | +} |
| 99 | + |
| 100 | +test('Array(3) auto', () => { |
| 101 | + functionReturnArray3(null); |
| 102 | +}); |
| 103 | + |
| 104 | +test('Array(3) gpu', () => { |
| 105 | + functionReturnArray3('gpu'); |
| 106 | +}); |
| 107 | + |
| 108 | +(GPU.isWebGLSupported ? test : skip)('Array(3) webgl', () => { |
| 109 | + functionReturnArray3('webgl'); |
| 110 | +}); |
| 111 | + |
| 112 | +(GPU.isWebGL2Supported ? test : skip)('Array(3) webgl2', () => { |
| 113 | + functionReturnArray3('webgl2'); |
| 114 | +}); |
| 115 | + |
| 116 | +(GPU.isHeadlessGLSupported ? test : skip)('Array(3) headlessgl', () => { |
| 117 | + functionReturnArray3('headlessgl'); |
| 118 | +}); |
| 119 | + |
| 120 | +test('Array(3) cpu', () => { |
| 121 | + functionReturnArray3('cpu'); |
| 122 | +}); |
| 123 | + |
| 124 | + |
| 125 | +function functionReturnArray4( mode ) { |
| 126 | + const gpu = new GPU({ mode }); |
| 127 | + const f = gpu.createKernel(function() { |
| 128 | + return [42, 43, 44, 45]; |
| 129 | + }, { |
| 130 | + output : [1] |
| 131 | + }); |
| 132 | + assert.ok( f !== null, 'function generated test'); |
| 133 | + const result = f(); |
| 134 | + // TODO, make assertion work |
| 135 | + // assert(result[0].constructor, Float32Array); |
| 136 | + assert.equal(result[0][0], 42); |
| 137 | + assert.equal(result[0][1], 43); |
| 138 | + assert.equal(result[0][2], 44); |
| 139 | + assert.equal(result[0][3], 45); |
| 140 | + gpu.destroy(); |
| 141 | +} |
| 142 | + |
| 143 | +test('Array(4) auto', () => { |
| 144 | + functionReturnArray4(null); |
| 145 | +}); |
| 146 | + |
| 147 | +test('Array(4) gpu', () => { |
| 148 | + functionReturnArray4('gpu'); |
| 149 | +}); |
| 150 | + |
| 151 | +(GPU.isWebGLSupported ? test : skip)('Array(4) webgl', () => { |
| 152 | + functionReturnArray4('webgl'); |
| 153 | +}); |
| 154 | + |
| 155 | +(GPU.isWebGL2Supported ? test : skip)('Array(4) webgl2', () => { |
| 156 | + functionReturnArray4('webgl2'); |
| 157 | +}); |
| 158 | + |
| 159 | +(GPU.isHeadlessGLSupported ? test : skip)('Array(4) headlessgl', () => { |
| 160 | + functionReturnArray4('headlessgl'); |
| 161 | +}); |
| 162 | + |
| 163 | +test('Array(4) cpu', () => { |
| 164 | + functionReturnArray4('cpu'); |
40 | 165 | });
|
0 commit comments