forked from fingerecho/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path195-read-from-texture2d.js
More file actions
76 lines (62 loc) · 2.42 KB
/
195-read-from-texture2d.js
File metadata and controls
76 lines (62 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(function() {
function makeKernel(gpu) {
return gpu.createKernel(function(a){
return a[this.thread.y][this.thread.x];
})
.setOutput([matrixSize, matrixSize]);
}
function splitArray(array, part) {
var result = [];
for(var i = 0; i < array.length; i += part) {
result.push(array.slice(i, i + part));
}
return result;
}
var matrixSize = 4;
var A = Array.apply(null, Array(matrixSize*matrixSize)).map(function (_, i) {return i;});
A = splitArray(A, matrixSize);
QUnit.test( "Issue #195 Read from Texture 2D (GPU only) (auto)", function() {
const gpu = new GPU({ mode: null });
const noTexture = makeKernel(gpu);
const texture = makeKernel(gpu).setOutputToTexture(true);
const result = noTexture(A);
const textureResult = texture(A).toArray(gpu);
QUnit.assert.deepValueEqual(result, A);
QUnit.assert.deepValueEqual(textureResult, A);
QUnit.assert.deepValueEqual(textureResult, result);
gpu.destroy();
});
QUnit.test( "Issue #195 Read from Texture 2D (GPU only) (gpu)", function() {
const gpu = new GPU({ mode: 'gpu' });
const noTexture = makeKernel(gpu);
const texture = makeKernel(gpu).setOutputToTexture(true);
const result = noTexture(A);
const textureResult = texture(A).toArray(gpu);
QUnit.assert.deepValueEqual(result, A);
QUnit.assert.deepValueEqual(textureResult, A);
QUnit.assert.deepValueEqual(textureResult, result);
gpu.destroy();
});
QUnit.test( "Issue #195 Read from Texture 2D (GPU only) (webgl)", function() {
const gpu = new GPU({ mode: 'webgl' });
const noTexture = makeKernel(gpu);
const texture = makeKernel(gpu).setOutputToTexture(true);
const result = noTexture(A);
const textureResult = texture(A).toArray(gpu);
QUnit.assert.deepValueEqual(result, A);
QUnit.assert.deepValueEqual(textureResult, A);
QUnit.assert.deepValueEqual(textureResult, result);
gpu.destroy();
});
QUnit.test( "Issue #195 Read from Texture 2D (GPU Only) (webgl2)", function() {
const gpu = new GPU({ mode: 'webgl2' });
const noTexture = makeKernel(gpu);
const texture = makeKernel(gpu).setOutputToTexture(true);
const result = noTexture(A);
const textureResult = texture(A).toArray(gpu);
QUnit.assert.deepValueEqual(result, A);
QUnit.assert.deepValueEqual(textureResult, A);
QUnit.assert.deepValueEqual(textureResult, result);
gpu.destroy();
});
})();