Skip to content

Commit f78f689

Browse files
Merge pull request #540 from gpujs/pre-2.3.0
Pre 2.3.0 work
2 parents a7a9e1e + 7669b7a commit f78f689

Some content is hidden

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

63 files changed

+6930
-6104
lines changed

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const c = multiplyMatrix(a, b);
5353
```
5454

5555
## Typescript
56-
```js
56+
```typescript
5757
import { GPU } from 'gpu.js';
5858
const gpu = new GPU();
5959
const multiplyMatrix = gpu.createKernel(function(a: number[][], b: number[][]) {
@@ -85,7 +85,7 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
8585
* [Types](#types)
8686
* [Loops](#loops)
8787
* [Pipelining](#pipelining)
88-
* [Cloning Textures](#cloning-textures)
88+
* [Cloning Textures](#cloning-textures-new-in-v2)
8989
* [Offscreen Canvas](#offscreen-canvas)
9090
* [Cleanup](#cleanup)
9191
* [Flattened typed array support](#flattened-typed-array-support)
@@ -95,6 +95,7 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
9595
* [Supported Math functions](#supported-math-functions)
9696
* [How to check what is supported](#how-to-check-what-is-supported)
9797
* [Typescript Typings](#typescript-typings)
98+
* [Destructured Assignments](#destructured-assignments-new-in-v2)
9899
* [Dealing With Transpilation](#dealing-with-transpilation)
99100
* [Full API reference](#full-api-reference)
100101
* [How possible in node](#how-possible-in-node)
@@ -156,7 +157,7 @@ Settings are an object used to create an instance of `GPU`. Example: `new GPU(s
156157
* 'cpu': Use the `CPUKernel` for transpiling a kernel
157158
* `onIstanbulCoverageVariable`: For testing. Used for when coverage is inject into function values, and is desired to be preserved (`cpu` mode ONLY).
158159
Use like this:
159-
```
160+
```js
160161
const { getFileCoverageDataByName } = require('istanbul-spy');
161162
const gpu = new GPU({
162163
mode: 'cpu',
@@ -207,7 +208,7 @@ Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.
207208
* `strictIntegers` or `kernel.setStrictIntegers(boolean)`: boolean, default = `false` - allows undefined argumentTypes and function return values to use strict integer declarations.
208209
* `useLegacyEncoder` or `kernel.setUseLegacyEncoder(boolean)`: boolean, default `false` - more info [here](https://github.com/gpujs/gpu.js/wiki/Encoder-details).
209210
* `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.
210-
* `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'.
211+
* `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.
211212

212213

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

951+
## Destructured Assignments **New in V2!**
952+
Destructured Objects and Arrays work in GPU.js.
953+
* Object destructuring
954+
```js
955+
const gpu = new GPU();
956+
const kernel = gpu.createKernel(function() {
957+
const { thread: {x, y} } = this;
958+
return x + y;
959+
}, { output: [2] });
960+
console.log(kernel());
961+
```
962+
* Array destructuring
963+
```js
964+
const gpu = new GPU();
965+
const kernel = gpu.createKernel(function(array) {
966+
const [first, second] = array;
967+
return first + second;
968+
}, {
969+
output: [2],
970+
argumentTypes: { array: 'Array(2)' }
971+
});
972+
console.log(kernel([1, 2]));
973+
```
974+
950975
## Dealing With Transpilation
951976
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.
952977
Here is a list of a few things that GPU.js does to fix transpilation:
@@ -958,7 +983,9 @@ Here is a list of a few things that GPU.js does to fix transpilation:
958983
```js
959984
const kernel = gpu.createKernel(myKernelFunction)
960985
.setWarnVarUsage(false);
961-
// or
986+
```
987+
or:
988+
```js
962989
const kernel = gpu.createKernel(myKernelFunction, { output: [1], warnVarUsage: false });
963990
```
964991

0 commit comments

Comments
 (0)