Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
69 lines (61 loc) · 1.97 KB

File metadata and controls

69 lines (61 loc) · 1.97 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
const { assert, skip, test, module: describe } = require('qunit');
const { GPU, WebGLKernel } = require('../../src');
describe('features: constants image array');
function feature(mode, done) {
const gpu = new GPU({ mode });
const image = new Image();
const imageArray = [image, image];
function fn() {
const pixel1 = this.constants.imageArray[0][this.thread.y][this.thread.x];
const pixel2 = this.constants.imageArray[1][this.thread.y][this.thread.x];
let color = 0;
if (this.thread.z === 0) {
color = (pixel1.r + pixel2.r) / 2;
}
if (this.thread.z === 1) {
color = (pixel1.g + pixel2.g) / 2;
}
if (this.thread.z === 2) {
color = (pixel1.b + pixel2.b) / 2;
}
if (this.thread.z === 3) {
color = 1;
}
return Math.floor(255 * color);
}
const settings = {
constants: { imageArray },
output: [1, 1, 4]
};
if (mode === 'webgl' || gpu.Kernel === WebGLKernel) {
// make fail early in this exact scenario
gpu.createKernel(fn, settings)();
}
image.src = 'jellyfish-1.jpeg';
image.onload = () => {
settings[0] = image.width;
settings[1] = image.height;
const tryConst = gpu.createKernel(fn, settings);
const result = tryConst();
assert.ok(result[0][0][0] > 0, 'image array constant passed test');
gpu.destroy();
done();
};
}
(GPU.isGPUHTMLImageArraySupported && typeof Image !== 'undefined' ? test : skip)('auto', t => {
feature(null, t.async());
});
(GPU.isGPUHTMLImageArraySupported && typeof Image !== 'undefined' ? test : skip)('gpu', t => {
feature('gpu', t.async());
});
(GPU.isWebGLSupported && typeof Image !== 'undefined' ? test : skip)('webgl', t => {
assert.throws(() => {
feature('webgl')
}, 'imageArray are not compatible with webgl');
});
(GPU.isWebGL2Supported && typeof Image !== 'undefined' ? test : skip)('webgl2', t => {
feature('webgl2', t.async());
});
(typeof Image !== 'undefined' ? test : skip)('cpu', t => {
feature('cpu', t.async());
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.