Skip to content

Commit a7a9e1e

Browse files
Merge branch 'master' into develop
2 parents 64330ba + 67f3b3c commit a7a9e1e

32 files changed

+2028
-1572
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +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)
8889
* [Offscreen Canvas](#offscreen-canvas)
8990
* [Cleanup](#cleanup)
9091
* [Flattened typed array support](#flattened-typed-array-support)
@@ -153,6 +154,26 @@ Settings are an object used to create an instance of `GPU`. Example: `new GPU(s
153154
* 'webgl2': Use the `WebGL2Kernel` for transpiling a kernel
154155
* 'headlessgl' **New in V2!**: Use the `HeadlessGLKernel` for transpiling a kernel
155156
* 'cpu': Use the `CPUKernel` for transpiling a kernel
157+
* `onIstanbulCoverageVariable`: For testing. Used for when coverage is inject into function values, and is desired to be preserved (`cpu` mode ONLY).
158+
Use like this:
159+
```
160+
const { getFileCoverageDataByName } = require('istanbul-spy');
161+
const gpu = new GPU({
162+
mode: 'cpu',
163+
onIstanbulCoverageVariable: (name, kernel) => {
164+
const data = getFileCoverageDataByName(name);
165+
if (!data) {
166+
throw new Error(`Could not find istanbul identifier ${name}`);
167+
}
168+
const { path } = getFileCoverageDataByName(name);
169+
const variable = `const ${name} = __coverage__['${path}'];\n`;
170+
if (!kernel.hasPrependString(variable)) {
171+
kernel.prependString(variable);
172+
}
173+
}
174+
});
175+
```
176+
* `removeIstanbulCoverage`: Boolean. For testing and code coverage. Removes istanbul artifacts that were injected at testing runtime.
156177

157178
## `gpu.createKernel` Settings
158179
Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.createKernel(settings)`
@@ -712,6 +733,9 @@ const matMult = gpu.createKernel(function(a, b) {
712733
[Pipeline](https://en.wikipedia.org/wiki/Pipeline_(computing)) is a feature where values are sent directly from kernel to kernel via a texture.
713734
This results in extremely fast computing. This is achieved with the kernel setting `pipeline: boolean` or by calling `kernel.setPipeline(true)`
714735

736+
### Cloning Textures **New in V2!**
737+
When using pipeline mode the outputs from kernels can be cloned using `texture.clone()`.
738+
715739
```js
716740
const kernel1 = gpu.createKernel(function(v) {
717741
return v[this.thread.x];
@@ -891,13 +915,14 @@ This is a list of the supported ones:
891915
* `Math.min()`
892916
* `Math.pow()`
893917
* `Math.random()`
894-
* A note on random. We use [a plugin](src/plugins/triangle-noise.js) to generate random.
918+
* A note on random. We use [a plugin](src/plugins/math-random-uniformly-distributed.js) to generate random.
895919
Random seeded _and_ generated, _both from the GPU_, is not as good as random from the CPU as there are more things that the CPU can seed random from.
896920
However, we seed random on the GPU, _from a random value in the CPU_.
897921
We then seed the subsequent randoms from the previous random value.
898922
So we seed from CPU, and generate from GPU.
899923
Which is still not as good as CPU, but closer.
900924
While this isn't perfect, it should suffice in most scenarios.
925+
In any case, we must give thanks to [RandomPower](https://www.randompower.eu/), and this [issue](https://github.com/gpujs/gpu.js/issues/498), for assisting in improving our implementation of random.
901926
* `Math.round()`
902927
* `Math.sign()`
903928
* `Math.sin()`

0 commit comments

Comments
 (0)