Skip to content

Commit bcae4ba

Browse files
Merge branch 'develop' into refed-textures
2 parents b051d84 + cc88928 commit bcae4ba

File tree

7 files changed

+248
-137
lines changed

7 files changed

+248
-137
lines changed

README.md

Lines changed: 109 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ Matrix multiplication (perform matrix multiplication on 2 matrices of size 512 x
3737
</script>
3838
```
3939

40+
## CDN
41+
```
42+
https://unpkg.com/gpu.js@latest/dist/gpu-browser.min.js
43+
https://cdn.jsdelivr.net/npm/gpu.js@latest/dist/gpu-browser.min.js
44+
```
45+
4046
## Node
4147
```js
4248
const { GPU } = require('gpu.js');
@@ -71,6 +77,7 @@ const c = multiplyMatrix(a, b) as number[][];
7177

7278
NOTE: documentation is slightly out of date for the upcoming release of v2. We will fix it! In the mean time, if you'd like to assist (PLEASE) let us know.
7379

80+
* [Demos](#demos)
7481
* [Installation](#installation)
7582
* [`GPU` Settings](#gpu-settings)
7683
* [`gpu.createKernel` Settings](#gpucreatekernel-settings)
@@ -106,6 +113,31 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
106113
* [Terms Explained](#terms-explained)
107114
* [License](#license)
108115

116+
## Demos
117+
GPU.js in the wild, all around the net. Add yours here!
118+
* [Temperature interpolation using GPU.js](https://observablehq.com/@rveciana/temperature-interpolation-using-gpu-js)
119+
* [Julia Set Fractal using GPU.js](https://observablehq.com/@ukabuer/julia-set-fractal-using-gpu-js)
120+
* [Hello, gpu.js v2](https://observablehq.com/@fil/hello-gpu-js-v2)
121+
* [Basic gpu.js canvas example](https://observablehq.com/@rveciana/basic-gpu-js-canvas-example)
122+
* [Raster projection with GPU.js](https://observablehq.com/@fil/raster-projection-with-gpu-js)
123+
* [GPU.js Example: Slow Fade](https://observablehq.com/@robertleeplummerjr/gpu-js-example-slow-fade)
124+
* [GPU.JS CA Proof of Concept](https://observablehq.com/@alexlamb/gpu-js-ca-proof-of-concept)
125+
* [Image Convolution using GPU.js](https://observablehq.com/@ukabuer/image-convolution-using-gpu-js)
126+
* [Leaflet + gpu.js canvas](https://observablehq.com/@rveciana/leaflet-gpu-js-canvas)
127+
* [Image to GPU.js](https://observablehq.com/@fil/image-to-gpu)
128+
* [GPU Accelerated Heatmap using gpu.js](https://observablehq.com/@tracyhenry/gpu-accelerated-heatmap-using-gpu-js)
129+
* [Dijkstra’s algorithm in gpu.js](https://observablehq.com/@fil/dijkstras-algorithm-in-gpu-js)
130+
* [Voronoi with gpu.js](https://observablehq.com/@fil/voronoi-with-gpu-js)
131+
* [The gpu.js loop](https://observablehq.com/@fil/the-gpu-js-loop)
132+
* [GPU.js Example: Mandelbrot Set](https://observablehq.com/@robertleeplummerjr/gpu-js-example-mandelbrot-set)
133+
* [GPU.js Example: Mandelbulb](https://observablehq.com/@robertleeplummerjr/gpu-js-example-mandelbulb)
134+
* [Inverse of the distance with gpu.js](https://observablehq.com/@rveciana/inverse-of-the-distance-with-gpu-js)
135+
* [gpu.js laser detection v2](https://observablehq.com/@robertleeplummerjr/gpu-js-laser-detection-v2)
136+
* [GPU.js Canvas](https://observablehq.com/@hubgit/gpu-js-canvas)
137+
* [Video Convolution using GPU.js](https://observablehq.com/@robertleeplummerjr/video-convolution-using-gpu-js)
138+
* [GPU Rock Paper Scissors](https://observablehq.com/@alexlamb/gpu-rock-paper-scissors)
139+
* [Shaded relief with gpujs and d3js](https://observablehq.com/@rveciana/shaded-relief-with-gpujs-and-d3js/2)
140+
109141
## Installation
110142
On Linux, ensure you have the correct header files installed: `sudo apt install mesa-common-dev libxi-dev` (adjust for your distribution)
111143

@@ -437,11 +469,13 @@ const kernel = gpu.createKernel(function(image) {
437469
.setGraphical(true)
438470
.setOutput([100, 100]);
439471
440-
const image = new document.createElement('img');
472+
const image = document.createElement('img');
441473
image.src = 'my/image/source.png';
442474
image.onload = () => {
443475
kernel(image);
444476
// Result: colorful image
477+
478+
document.getElementsByTagName('body')[0].appendChild(kernel.canvas);
445479
};
446480
```
447481
@@ -455,13 +489,13 @@ const kernel = gpu.createKernel(function(image) {
455489
.setGraphical(true)
456490
.setOutput([100, 100]);
457491
458-
const image1 = new document.createElement('img');
492+
const image1 = document.createElement('img');
459493
image1.src = 'my/image/source1.png';
460494
image1.onload = onload;
461-
const image2 = new document.createElement('img');
495+
const image2 = document.createElement('img');
462496
image2.src = 'my/image/source2.png';
463497
image2.onload = onload;
464-
const image3 = new document.createElement('img');
498+
const image3 = document.createElement('img');
465499
image3.src = 'my/image/source3.png';
466500
image3.onload = onload;
467501
const totalImages = 3;
@@ -471,6 +505,8 @@ function onload() {
471505
if (loadedImages === totalImages) {
472506
kernel([image1, image2, image3]);
473507
// Result: colorful image composed of many images
508+
509+
document.getElementsByTagName('body')[0].appendChild(kernel.canvas);
474510
}
475511
};
476512
```
@@ -947,6 +983,75 @@ To assist with mostly unit tests, but perhaps in scenarios outside of GPU.js, th
947983

948984
## Typescript Typings
949985
Typescript is supported! Typings can be found [here](src/index.d.ts)!
986+
For strongly typed kernels:
987+
```ts
988+
import { GPU, IKernelFunctionThis } from './src';
989+
const gpu = new GPU();
990+
991+
function kernelFunction(this: IKernelFunctionThis): number {
992+
return 1 + this.thread.x;
993+
}
994+
995+
const kernelMap = gpu.createKernel<typeof kernelFunction>(kernelFunction)
996+
.setOutput([3,3,3]);
997+
998+
const result = kernelMap();
999+
1000+
console.log(result as number[][][]);
1001+
```
1002+
1003+
For strongly typed mapped kernels:
1004+
```ts
1005+
import { GPU, Texture, IKernelFunctionThis } from './src';
1006+
const gpu = new GPU();
1007+
1008+
function kernelFunction(this: IKernelFunctionThis): [number, number] {
1009+
return [1, 1];
1010+
}
1011+
1012+
function subKernel(): [number, number] {
1013+
return [1, 1];
1014+
}
1015+
1016+
const kernelMap = gpu.createKernelMap<typeof kernelFunction>({
1017+
test: subKernel,
1018+
}, kernelFunction)
1019+
.setOutput([1])
1020+
.setPipeline(true);
1021+
1022+
const result = kernelMap();
1023+
1024+
console.log((result.test as Texture).toArray() as [number, number][]);
1025+
```
1026+
1027+
For extending constants:
1028+
```ts
1029+
import { GPU, IKernelFunctionThis } from './src';
1030+
const gpu = new GPU();
1031+
1032+
interface IConstants {
1033+
screen: [number, number];
1034+
}
1035+
1036+
type This = {
1037+
constants: IConstants
1038+
} & IKernelFunctionThis;
1039+
1040+
function kernelFunction(this: This): number {
1041+
const { screen } = this.constants;
1042+
return 1 + screen[0];
1043+
}
1044+
1045+
const kernelMap = gpu.createKernel<typeof kernelFunction>(kernelFunction)
1046+
.setOutput([3,3,3])
1047+
.setConstants<IConstants>({
1048+
screen: [1, 1]
1049+
});
1050+
1051+
const result = kernelMap();
1052+
1053+
console.log(result as number[][][]);
1054+
```
9501055

9511056
## Destructured Assignments **New in V2!**
9521057
Destructured Objects and Arrays work in GPU.js.

dist/gpu-browser-core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.3.0
8-
* @date Tue Nov 26 2019 09:51:10 GMT-0500 (Eastern Standard Time)
7+
* @version 2.3.1
8+
* @date Tue Dec 17 2019 09:39:34 GMT-0500 (Eastern Standard Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -13389,7 +13389,7 @@ const utils = {
1338913389

1339013390
getVariableType(value, strictIntegers) {
1339113391
if (utils.isArray(value)) {
13392-
if (value[0].nodeName === 'IMG') {
13392+
if (value.length > 0 && value[0].nodeName === 'IMG') {
1339313393
return 'HTMLImageArray';
1339413394
}
1339513395
return 'Array';

dist/gpu-browser-core.min.js

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

dist/gpu-browser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.3.0
8-
* @date Tue Nov 26 2019 09:51:10 GMT-0500 (Eastern Standard Time)
7+
* @version 2.3.1
8+
* @date Tue Dec 17 2019 09:39:34 GMT-0500 (Eastern Standard Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -17823,7 +17823,7 @@ const utils = {
1782317823

1782417824
getVariableType(value, strictIntegers) {
1782517825
if (utils.isArray(value)) {
17826-
if (value[0].nodeName === 'IMG') {
17826+
if (value.length > 0 && value[0].nodeName === 'IMG') {
1782717827
return 'HTMLImageArray';
1782817828
}
1782917829
return 'Array';

dist/gpu-browser.min.js

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gpu.js",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"description": "GPU Accelerated JavaScript",
55
"engines": {
66
"node": ">=8.0.0"

0 commit comments

Comments
 (0)