Skip to content

Commit 5738698

Browse files
Merge pull request #555 from gpujs/refed-textures
Refed textures
2 parents cc88928 + 6e2f1da commit 5738698

24 files changed

+1381
-706
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
9393
* [Loops](#loops)
9494
* [Pipelining](#pipelining)
9595
* [Cloning Textures](#cloning-textures-new-in-v2)
96+
* [Cleanup pipeline texture memory](#cleanup-pipeline-texture-memory-new-in-v2)
9697
* [Offscreen Canvas](#offscreen-canvas)
9798
* [Cleanup](#cleanup)
9899
* [Flattened typed array support](#flattened-typed-array-support)
@@ -236,7 +237,7 @@ Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.
236237
* VERY IMPORTANT! - Use this to add special native functions to your environment when you need specific functionality is needed.
237238
* `injectedNative` or `kernel.setInjectedNative(string)` **New in V2!**: string, defined as: `{ functionName: functionSource }`. This is for injecting native code before translated kernel functions.
238239
* `subKernels` or `kernel.setSubKernels(array)`: array, generally inherited from `GPU` instance.
239-
* `immutable` or `kernel.setImmutable(boolean)`: boolean, default = `false`
240+
* ~~`immutable` or `kernel.setImmutable(boolean)`: boolean, default = `false`~~ Deprecated
240241
* `strictIntegers` or `kernel.setStrictIntegers(boolean)`: boolean, default = `false` - allows undefined argumentTypes and function return values to use strict integer declarations.
241242
* `useLegacyEncoder` or `kernel.setUseLegacyEncoder(boolean)`: boolean, default `false` - more info [here](https://github.com/gpujs/gpu.js/wiki/Encoder-details).
242243
* `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.
@@ -794,6 +795,12 @@ const result2 = kernel2(result1);
794795
// Result: Float32Array[0, 1, 2, 3, ... 99]
795796
```
796797

798+
### Cleanup pipeline texture memory **New in V2.4!**
799+
Handling minimal amounts of GPU memory is handled internally, but a good practice is to clean up memory you no longer need.
800+
Cleanup kernel outputs by using `texture.delete()` to keep GPU memory as small as possible.
801+
802+
NOTE: Internally textures will only release from memory if there are no references to them,
803+
797804
## Offscreen Canvas
798805
GPU.js supports offscreen canvas where available. Here is an example of how to use it with two files, `gpu-worker.js`, and `index.js`:
799806

@@ -831,6 +838,7 @@ worker.onmessage = function(e) {
831838
## Cleanup
832839
* for instances of `GPU` use the `destroy` method. Example: `gpu.destroy()`
833840
* for instances of `Kernel` use the `destroy` method. Example: `kernel.destroy()`
841+
* for instances of `Texture` use the `delete` method. Example: `texture.delete()`
834842

835843
## Flattened typed array support
836844
To use the useful `x`, `y`, `z` `thread` lookup api inside of GPU.js, and yet use flattened arrays, there is the `Input` type.
@@ -984,8 +992,8 @@ To assist with mostly unit tests, but perhaps in scenarios outside of GPU.js, th
984992
## Typescript Typings
985993
Typescript is supported! Typings can be found [here](src/index.d.ts)!
986994
For strongly typed kernels:
987-
```ts
988-
import { GPU, IKernelFunctionThis } from './src';
995+
```typescript
996+
import { GPU, IKernelFunctionThis } from 'gpu.js';
989997
const gpu = new GPU();
990998

991999
function kernelFunction(this: IKernelFunctionThis): number {
@@ -1001,8 +1009,8 @@ console.log(result as number[][][]);
10011009
```
10021010

10031011
For strongly typed mapped kernels:
1004-
```ts
1005-
import { GPU, Texture, IKernelFunctionThis } from './src';
1012+
```typescript
1013+
import { GPU, Texture, IKernelFunctionThis } from 'gpu.js';
10061014
const gpu = new GPU();
10071015

10081016
function kernelFunction(this: IKernelFunctionThis): [number, number] {
@@ -1025,8 +1033,8 @@ console.log((result.test as Texture).toArray() as [number, number][]);
10251033
```
10261034

10271035
For extending constants:
1028-
```ts
1029-
import { GPU, IKernelFunctionThis } from './src';
1036+
```typescript
1037+
import { GPU, IKernelFunctionThis } from 'gpu.js';
10301038
const gpu = new GPU();
10311039

10321040
interface IConstants {

0 commit comments

Comments
 (0)