Skip to content

Commit ed1cd94

Browse files
feat: Added features and fixes for the following issues:
...it kind of snowballed from some needs Fixes #521 - If `tactic` is not set, check precision allowed from WebGL, and automatically change based off needs, otherwise use value from `tactic`. Fixes #535 - Internally check if texture from argument is the same as output, if so, clone this texture, and then clean it up after the kernel runs. Fixes #536 - Normalize all declarations to non-destructured, and then parse Fixes #537 - Change logic Fixes #538 - Found the GL script that would work, and reduced the methods to use it Fixes #539 - Found a better way of testing random, and this gives me an error for 1 in 10 runs, acceptable Some refactoring for less duplicate code and documentation
1 parent ae88e1b commit ed1cd94

Some content is hidden

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

61 files changed

+6922
-6096
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)