Skip to content

Commit cd80caf

Browse files
committed
Get many more tests working.
2 parents 0a6df4f + 2bc76ad commit cd80caf

File tree

256 files changed

+1099
-20238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+1099
-20238
lines changed

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.
174174
* `precision` or `kernel.setPrecision('unsigned' | 'single')` **New in V2!**: 'single' or 'unsigned' - if 'single' output texture uses float32 for each colour channel rather than 8
175175
* `fixIntegerDivisionAccuracy` or `kernel.setFixIntegerDivisionAccuracy(boolean)` : boolean - some cards have accuracy issues dividing by factors of three and some other primes (most apple kit?). Default on for affected cards, disable if accuracy not required.
176176
* `functions` or `kernel.setFunctions(object)`: array, array of functions to be used inside kernel. If undefined, inherits from `GPU` instance.
177-
* `nativeFunctions` or `kernel.setNativeFunctions(object)`: object, defined as: `{ functionName: functionSource }`
177+
* `nativeFunctions` or `kernel.setNativeFunctions(object)`: object, defined as: `{ name: string, source: string, settings: object }`. This is generally set via using GPU.addNativeFunction()
178178
* VERY IMPORTANT! - Use this to add special native functions to your environment when you need specific functionality is needed.
179+
* `injectedNative` or `kernel.setInjectedNative(string)` **New in V2!**: string, defined as: `{ functionName: functionSource }`. This is for injecting native code before translated kernel functions.
179180
* `subKernels` or `kernel.setSubKernels(array)`: array, generally inherited from `GPU` instance.
180181
* `immutable` or `kernel.setImmutable(boolean)`: boolean, default = `false`
181182
* `strictIntegers` or `kernel.setStrictIntegers(boolean)`: boolean, default = `false` - allows undefined argumentTypes and function return values to use strict integer declarations.
@@ -376,6 +377,7 @@ Debugging can be done in a variety of ways, and there are different levels of de
376377
```
377378
* HTML Image
378379
* Array of HTML Images
380+
* Video Element **New in V2!**
379381
To define an argument, simply add it to the kernel function like regular JavaScript.
380382
381383
### Input Examples
@@ -407,7 +409,7 @@ const kernel = gpu.createKernel(function(image) {
407409
this.color(pixel[0], pixel[1], pixel[2], pixel[3]);
408410
})
409411
.setGraphical(true)
410-
.setOutput([100]);
412+
.setOutput([100, 100]);
411413
412414
const image = new document.createElement('img');
413415
image.src = 'my/image/source.png';
@@ -425,7 +427,7 @@ const kernel = gpu.createKernel(function(image) {
425427
this.color(pixel[0], pixel[1], pixel[2], pixel[3]);
426428
})
427429
.setGraphical(true)
428-
.setOutput([100]);
430+
.setOutput([100, 100]);
429431
430432
const image1 = new document.createElement('img');
431433
image1.src = 'my/image/source1.png';
@@ -447,6 +449,22 @@ function onload() {
447449
};
448450
```
449451
452+
An HTML Video: **New in V2!**
453+
454+
```js
455+
const kernel = gpu.createKernel(function(videoFrame) {
456+
const pixel = videoFrame[this.thread.y][this.thread.x];
457+
this.color(pixel[0], pixel[1], pixel[2], pixel[3]);
458+
})
459+
.setGraphical(true)
460+
.setOutput([100, 100]);
461+
462+
const video = new document.createElement('video');
463+
video.src = 'my/video/source.webm';
464+
kernel(image); //note, try and use requestAnimationFrame, and the video should be ready or playing
465+
// Result: video frame
466+
```
467+
450468
## Graphical Output
451469
452470
Sometimes, you want to produce a `canvas` image instead of doing numeric computations. To achieve this, set the `graphical` flag to `true` and the output dimensions to `[width, height]`. The thread identifiers will now refer to the `x` and `y` coordinate of the pixel you are producing. Inside your kernel function, use `this.color(r,g,b)` or `this.color(r,g,b,a)` to specify the color of the pixel.
@@ -633,6 +651,7 @@ Types that can be used with GPU.js are as follows:
633651
* 'Array3D(4)' **New in V2!**
634652
* 'HTMLImage'
635653
* 'HTMLImageArray'
654+
* 'HTMLVideo' **New in V2!**
636655
* 'Number'
637656
* 'Float'
638657
* 'Integer'

dist/gpu-browser-core.js

Lines changed: 83 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gpu-browser-core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gpu-browser-core.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gpu-browser-core.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)