Skip to content

Commit d051256

Browse files
Merge pull request #389 from gpujs/deep-type-detection
Deep type detection
2 parents 43bb07e + d765de4 commit d051256

37 files changed

+1121
-663
lines changed

README.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,72 @@ const myFunc = gpu.createKernel(function() {
167167
myFunc();
168168
// Result: [0, 1, 2, 3, ... 99]
169169
```
170+
171+
### Declaring variables
172+
173+
GPU.js makes variable declaration inside kernel functions easy. Variable types supported are:
174+
Numbers
175+
Array(2)
176+
Array(3)
177+
Array(4)
178+
179+
Numbers example:
180+
```js
181+
const myFunc = gpu.createKernel(function() {
182+
const i = 1;
183+
const j = 0.89;
184+
return i + j;
185+
}).setOutput([100]);
186+
```
187+
188+
Array(2) examples:
189+
Using declaration
190+
```js
191+
const myFunc = gpu.createKernel(function() {
192+
const array2 = [0.08, 2];
193+
return array2;
194+
}).setOutput([100]);
195+
```
196+
197+
Directly returned
198+
```js
199+
const myFunc = gpu.createKernel(function() {
200+
return [0.08, 2];
201+
}).setOutput([100]);
202+
```
203+
204+
Array(3) example:
205+
Using declaration
206+
```js
207+
const myFunc = gpu.createKernel(function() {
208+
const array2 = [0.08, 2, 0.1];
209+
return array2;
210+
}).setOutput([100]);
211+
```
212+
213+
Directly returned
214+
```js
215+
const myFunc = gpu.createKernel(function() {
216+
return [0.08, 2, 0.1];
217+
}).setOutput([100]);
218+
```
219+
220+
Array(4) example:
221+
Using declaration
222+
```js
223+
const myFunc = gpu.createKernel(function() {
224+
const array2 = [0.08, 2, 0.1, 3];
225+
return array2;
226+
}).setOutput([100]);
227+
```
228+
229+
Directly returned
230+
```js
231+
const myFunc = gpu.createKernel(function() {
232+
return [0.08, 2, 0.1, 3];
233+
}).setOutput([100]);
234+
```
235+
170236
## Accepting Input
171237
### Supported Input Types
172238
* Numbers
@@ -346,7 +412,9 @@ megaKernel(a, b, c);
346412
This gives you the flexibility of using parts of a single transformation without the performance penalty, resulting in much much _MUCH_ faster operation.
347413

348414
## Adding custom functions
349-
Do you have a custom function you'd like to use on the gpu? Although limited, you can:
415+
use `gpu.addFunction(function() {}, options)` for adding custom functions. Example:
416+
417+
350418
```js
351419
gpu.addFunction(function mySuperFunction(a, b) {
352420
return a - b;
@@ -360,6 +428,31 @@ const kernel = gpu.createKernel(function(a, b) {
360428
}).setOutput([20]);
361429
```
362430

431+
### Adding strongly typed functions
432+
433+
To strongly type a function you may use options. Options take an optional hash values:
434+
`returnType`: optional, defaults to float, the value you'd like to return from the function
435+
`paramTypes`: optional, defaults to float for each param, a hash of param names with values of the return types
436+
437+
Types: that may be used for `returnType` or for each property of `paramTypes`:
438+
'Array'
439+
'Array(2)'
440+
'Array(3)'
441+
'Array(4)'
442+
'HTMLImage'
443+
'HTMLImageArray'
444+
'Number'
445+
'NumberTexture'
446+
'ArrayTexture(4)'
447+
448+
Example:
449+
```js
450+
gpu.addFunction(function mySuperFunction(a, b) {
451+
return [a - b[1], b[0] - a];
452+
}, { paramTypes: { a: 'Integer', b: 'Array(2)'}, returnType: 'Array(2)' });
453+
```
454+
455+
363456
## Adding custom functions directly to kernel
364457
```js
365458
function mySuperFunction(a, b) {

bin/gpu-core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 1.9.1
8-
* @date Wed Oct 24 2018 15:14:26 GMT-0400 (EDT)
7+
* @version 1.10.0
8+
* @date Tue Oct 30 2018 07:33:44 GMT-0600 (MDT)
99
*
1010
* @license MIT
1111
* The MIT License

bin/gpu-core.min.js

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

0 commit comments

Comments
 (0)