Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const c = multiplyMatrix(a, b);
```

## Typescript
```js
```typescript
import { GPU } from 'gpu.js';
const gpu = new GPU();
const multiplyMatrix = gpu.createKernel(function(a: number[][], b: number[][]) {
Expand Down Expand Up @@ -85,7 +85,7 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
* [Types](#types)
* [Loops](#loops)
* [Pipelining](#pipelining)
* [Cloning Textures](#cloning-textures)
* [Cloning Textures](#cloning-textures-new-in-v2)
* [Offscreen Canvas](#offscreen-canvas)
* [Cleanup](#cleanup)
* [Flattened typed array support](#flattened-typed-array-support)
Expand All @@ -95,6 +95,7 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
* [Supported Math functions](#supported-math-functions)
* [How to check what is supported](#how-to-check-what-is-supported)
* [Typescript Typings](#typescript-typings)
* [Destructured Assignments](#destructured-assignments-new-in-v2)
* [Dealing With Transpilation](#dealing-with-transpilation)
* [Full API reference](#full-api-reference)
* [How possible in node](#how-possible-in-node)
Expand Down Expand Up @@ -156,7 +157,7 @@ Settings are an object used to create an instance of `GPU`. Example: `new GPU(s
* 'cpu': Use the `CPUKernel` for transpiling a kernel
* `onIstanbulCoverageVariable`: For testing. Used for when coverage is inject into function values, and is desired to be preserved (`cpu` mode ONLY).
Use like this:
```
```js
const { getFileCoverageDataByName } = require('istanbul-spy');
const gpu = new GPU({
mode: 'cpu',
Expand Down Expand Up @@ -207,7 +208,7 @@ Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.
* `strictIntegers` or `kernel.setStrictIntegers(boolean)`: boolean, default = `false` - allows undefined argumentTypes and function return values to use strict integer declarations.
* `useLegacyEncoder` or `kernel.setUseLegacyEncoder(boolean)`: boolean, default `false` - more info [here](https://github.com/gpujs/gpu.js/wiki/Encoder-details).
* `warnVarUsage` or `kernel.setWarnVarUsage(boolean)`: turn off var usage warnings, they can be irritating, and in transpiled environments, there is nothing we can do about it.
* `tactic` or `kernel.setTactic('speed' | 'balanced' | 'performance')` **New in V2!**: Set the kernel's tactic for compilation. Allows for compilation to better fit how GPU.js is being used (internally uses `lowp` for 'speed', `mediump` for 'balanced', and `highp` for 'precision'). Default is 'balanced'.
* `tactic` or `kernel.setTactic('speed' | 'balanced' | 'precision')` **New in V2!**: Set the kernel's tactic for compilation. Allows for compilation to better fit how GPU.js is being used (internally uses `lowp` for 'speed', `mediump` for 'balanced', and `highp` for 'precision'). Default is lowest resolution supported for output.


## Creating and Running Functions
Expand Down Expand Up @@ -947,6 +948,30 @@ To assist with mostly unit tests, but perhaps in scenarios outside of GPU.js, th
## Typescript Typings
Typescript is supported! Typings can be found [here](src/index.d.ts)!

## Destructured Assignments **New in V2!**
Destructured Objects and Arrays work in GPU.js.
* Object destructuring
```js
const gpu = new GPU();
const kernel = gpu.createKernel(function() {
const { thread: {x, y} } = this;
return x + y;
}, { output: [2] });
console.log(kernel());
```
* Array destructuring
```js
const gpu = new GPU();
const kernel = gpu.createKernel(function(array) {
const [first, second] = array;
return first + second;
}, {
output: [2],
argumentTypes: { array: 'Array(2)' }
});
console.log(kernel([1, 2]));
```

## Dealing With Transpilation
Transpilation doesn't do the best job of keeping code beautiful. To aid in this endeavor GPU.js can handle some scenarios to still aid you harnessing the GPU in less than ideal circumstances.
Here is a list of a few things that GPU.js does to fix transpilation:
Expand All @@ -958,7 +983,9 @@ Here is a list of a few things that GPU.js does to fix transpilation:
```js
const kernel = gpu.createKernel(myKernelFunction)
.setWarnVarUsage(false);
// or
```
or:
```js
const kernel = gpu.createKernel(myKernelFunction, { output: [1], warnVarUsage: false });
```

Expand Down
Loading