Skip to content

Commit

Permalink
Merge pull request #420 from gpujs/gl-headless-experimental
Browse files Browse the repository at this point in the history
Gl headless experimental
  • Loading branch information
robertleeplummerjr authored Feb 11, 2019
2 parents 3aba32e + 85eba0e commit f78b032
Show file tree
Hide file tree
Showing 205 changed files with 55,479 additions and 37,548 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

6 changes: 0 additions & 6 deletions .gitattributes

This file was deleted.

9 changes: 0 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Built files
doc/*

# Logs
logs
*.log
Expand All @@ -17,15 +14,9 @@ lib-cov
# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
node_modules

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2018 gpu.js Team
Copyright (c) 2019 gpu.js Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
74 changes: 37 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Or alternatively you can experiment around with the [kernel playground here](htt
# Table of Contents

* [Installation](#installation)
* [`GPU` Options](#gpu-options)
* [`gpu.createKernel` Options](#gpu-createkernel-options)
* [`GPU` Settings](#gpu-settings)
* [`gpu.createKernel` Settings](#gpu-createkernel-settings)
* [Creating and Running Functions](#creating-and-running-functions)
* [Accepting Input](#accepting-input)
* [Graphical Output](#graphical-output)
Expand Down Expand Up @@ -82,7 +82,7 @@ yarn add gpu.js
Download the latest version of GPU.js and include the files in your HTML page using the following tags:

```html
<script src="/path/to/js/gpu.min.js"></script>
<script src="/path/to/js/gpu-browser.min.js"></script>
```

In JavaScript, initialize the library:
Expand All @@ -91,17 +91,17 @@ In JavaScript, initialize the library:
const gpu = new GPU();
```

## `GPU` Options
Options are an object used to create an instance of `GPU`. Example: `new GPU(options)`
## `GPU` Settings
Settings are an object used to create an instance of `GPU`. Example: `new GPU(settings)`
* `canvas`: `HTMLCanvasElement`. Optional. For sharing canvas. Example: use THREE.js and GPU.js on same canvas.
* `webGl`: `WebGL2RenderingContext` or `WebGLRenderingContext`. For sharing rendering context. Example: use THREE.js and GPU.js on same rendering context.

## `gpu.createKernel` Options
Options are an object used to create a `kernel` or `kernelMap`. Example: `gpu.createKernel(options)`
## `gpu.createKernel` Settings
Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.createKernel(settings)`
* `output`: array or object that describes the output of kernel.
* as array: `[width]`, `[width, height]`, or `[width, height, depth]`
* as object: `{ x: width, y: height, z: depth }`
* outputToTexture: boolean
* pipeline: boolean
* graphical: boolean
* loopMaxIterations: number
* constants: object
Expand All @@ -110,12 +110,12 @@ Options are an object used to create a `kernel` or `kernelMap`. Example: `gpu.c
* floatTextures: boolean - input/working textures use float32 for each colour channel
* floatOutput: boolean - output texture uses float32 for each colour channel
* fixIntegerDivisionAccuracy: boolean - some cards have accuracy issues dividing by factors of three and some other primes (most apple kit?). Default on for affected cards, disable if accuracy not required.
* functions: array or boolean
* functions: array or object
* nativeFunctions: object
* subKernels: array
* outputImmutable: boolean
* immutable: boolean
* default to `false`



## Creating and Running Functions
Expand Down Expand Up @@ -157,13 +157,13 @@ myFunc();
// Result: [0, 1, 2, 3, ... 99]
```

Note: Instead of creating an object, you can use the chainable shortcut methods as a neater way of specifying options.
Note: Instead of creating an object, you can use the chainable shortcut methods as a neater way of specifying settings.

```js
const myFunc = gpu.createKernel(function() {
return this.thread.x;
}).setOutput([100]);

myFunc();
// Result: [0, 1, 2, 3, ... 99]
```
Expand All @@ -186,7 +186,7 @@ Numbers example:
```

Array(2) examples:
Using declaration
Using declaration
```js
const myFunc = gpu.createKernel(function() {
const array2 = [0.08, 2];
Expand All @@ -202,7 +202,7 @@ Directly returned
```

Array(3) example:
Using declaration
Using declaration
```js
const myFunc = gpu.createKernel(function() {
const array2 = [0.08, 2, 0.1];
Expand All @@ -218,7 +218,7 @@ Directly returned
```

Array(4) example:
Using declaration
Using declaration
```js
const myFunc = gpu.createKernel(function() {
const array2 = [0.08, 2, 0.1, 3];
Expand Down Expand Up @@ -248,7 +248,7 @@ To define an argument, simply add it to the kernel function like regular JavaScr
const myFunc = gpu.createKernel(function(x) {
return x;
}).setOutput([100]);

myFunc(42);
// Result: [42, 42, 42, 42, ... 42]
```
Expand All @@ -259,7 +259,7 @@ Similarly, with array inputs:
const myFunc = gpu.createKernel(function(x) {
return x[this.thread.x % 3];
}).setOutput([100]);

myFunc([1, 2, 3]);
// Result: [1, 2, 3, 1, ... 1 ]
```
Expand Down Expand Up @@ -324,10 +324,10 @@ const render = gpu.createKernel(function() {
})
.setOutput([20, 20])
.setGraphical(true);

render();

const canvas = render.getCanvas();
const canvas = render.canvas;
document.getElementsByTagName('body')[0].appendChild(canvas);
```

Expand All @@ -343,7 +343,7 @@ const gl = canvas.getContext('webgl2', { premultipliedAlpha: false });

const gpu = new GPU({
canvas,
webGl: gl
context: gl
});
const krender = gpu.createKernel(function(x) {
this.color(this.thread.x / 500, this.thread.y / 500, x[0], x[1]);
Expand Down Expand Up @@ -412,7 +412,7 @@ megaKernel(a, b, c);
This gives you the flexibility of using parts of a single transformation without the performance penalty, resulting in much much _MUCH_ faster operation.

## Adding custom functions
use `gpu.addFunction(function() {}, options)` for adding custom functions. Example:
use `gpu.addFunction(function() {}, settings)` for adding custom functions. Example:


```js
Expand All @@ -430,11 +430,11 @@ const kernel = gpu.createKernel(function(a, b) {

### Adding strongly typed functions

To strongly type a function you may use options. Options take an optional hash values:
To strongly type a function you may use settings. Settings take an optional hash values:
`returnType`: optional, defaults to float, the value you'd like to return from the function
`paramTypes`: optional, defaults to float for each param, a hash of param names with values of the return types
`argumentTypes`: optional, defaults to float for each param, a hash of param names with values of the return types

Types: that may be used for `returnType` or for each property of `paramTypes`:
Types: that may be used for `returnType` or for each property of `argumentTypes`:
* 'Array'
* 'Array(2)'
* 'Array(3)'
Expand All @@ -449,7 +449,7 @@ Example:
```js
gpu.addFunction(function mySuperFunction(a, b) {
return [a - b[1], b[0] - a];
}, { paramTypes: { a: 'Number', b: 'Array(2)'}, returnType: 'Array(2)' });
}, { argumentTypes: { a: 'Number', b: 'Array(2)'}, returnType: 'Array(2)' });
```


Expand Down Expand Up @@ -497,7 +497,7 @@ const matMult = gpu.createKernel(function(a, b) {

## Pipelining
[Pipeline](https://en.wikipedia.org/wiki/Pipeline_(computing)) is a feature where values are sent directly from kernel to kernel via a texture.
This results in extremely fast computing. This is achieved with the kernel option `outputToTexture: boolean` option or by calling `kernel.setOutputToTexture(true)`
This results in extremely fast computing. This is achieved with the kernel option `pipeline: boolean` option or by calling `kernel.pipeline(true)`

## Offscreen Canvas
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`:
Expand All @@ -508,17 +508,17 @@ importScripts('path/to/gpu.js');
onmessage = function() {
// define gpu instance
const gpu = new GPU();

// input values
const a = [1,2,3];
const b = [3,2,1];

// setup kernel
const kernel = gpu.createKernel(function(a, b) {
return a[this.thread.x] - b[this.thread.x];
})
.setOutput([3]);

// output some results!
postMessage(kernel(a, b));
};
Expand Down Expand Up @@ -574,7 +574,7 @@ log2
max
min
round
sign
sign
sin
sqrt
tan
Expand All @@ -590,7 +590,7 @@ You can find a [complete API reference here](https://doxdox.org/gpujs/gpu.js/1.2
Documentation of the codebase is [automatically built](https://github.com/gpujs/gpu.js/wiki/Automatic-Documentation).

## Contributors

* Fazli Sapuan
* Eugene Cheah
* Matthew Saw
Expand All @@ -600,26 +600,26 @@ Documentation of the codebase is [automatically built](https://github.com/gpujs/
* Daniel X Moore
* Mark Theng
* Varun Patro

## Contributing

Contributors are welcome! Create a merge request to the `develop` branch and we
will gladly review it. If you wish to get write access to the repository,
please email us and we will review your application and grant you access to
the `develop` branch.

We promise never to pass off your code as ours.

## Terms Explained
* Kernel - A function that is tightly coupled to program that runs on the Graphic Processor
* Texture - A graphical artifact that is packed with data, in the case of GPU.js, bit shifted parts of a 32 bit floating point decimal

## License
## License

The MIT License

Copyright (c) 2018 GPU.js Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
Loading

0 comments on commit f78b032

Please sign in to comment.