@@ -89,14 +89,18 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
89
89
* [ Cleanup] ( #cleanup )
90
90
* [ Flattened typed array support] ( #flattened-typed-array-support )
91
91
* [ Precompiled and Lighter Weight Kernels] ( #precompiled-and-lighter-weight-kernels )
92
+ * [ using JSON] ( #using-json )
93
+ * [ Exporting kernel] ( #exporting-kernel )
92
94
* [ Supported Math functions] ( #supported-math-functions )
93
95
* [ How to check what is supported] ( #how-to-check-what-is-supported )
94
96
* [ Typescript Typings] ( #typescript-typings )
95
97
* [ Dealing With Transpilation] ( #dealing-with-transpilation )
96
98
* [ Full API reference] ( #full-api-reference )
99
+ * [ How possible in node] ( #how-possible-in-node )
100
+ * [ Testing] ( #testing )
101
+ * [ Building] ( #building )
97
102
* [ Contributors] ( #contributors )
98
103
* [ Contributing] ( #contributing )
99
- * [ How possible in node] ( #how-possible-in-node )
100
104
* [ Terms Explained] ( #terms-explained )
101
105
* [ License] ( #license )
102
106
@@ -815,10 +819,39 @@ NOTE: There is lighter weight, pre-built, version of GPU.js to assist with seria
815
819
* [ dist/gpu-browser-core.js] ( dist/gpu-browser-core.js )
816
820
* [ dist/gpu-browser-core.min.js] ( dist/gpu-browser-core.min.js )
817
821
818
- ### using ` kernel.toString(args...) `
822
+ ### Exporting kernel
819
823
GPU.js supports seeing exactly how it is interacting with the graphics processor by means of the ` kernel.toString(...) ` method.
820
- This method, when called, creates a kernel that executes _ exactly the instruction set given to the GPU_ as a function that sets up a kernel.
821
- Here is an example:
824
+ This method, when called, creates a kernel that executes _ exactly the instruction set given to the GPU (or CPU)_ * as a
825
+ very tiny reusable function* that instantiates a kernel.
826
+
827
+ NOTE: When exporting a kernel and using ` constants ` the following constants are * not changeable* :
828
+ * ` Array(2) `
829
+ * ` Array(3) `
830
+ * ` Array(4) `
831
+ * ` Integer `
832
+ * ` Number `
833
+ * ` Float `
834
+ * ` Boolean `
835
+
836
+ Here is an example used to/from file:
837
+ ```
838
+ import { GPU } from 'gpu.js';
839
+ import * as fs from 'fs';
840
+ const gpu = new GPU();
841
+ const kernel = gpu.createKernel(function(v) {
842
+ return this.thread.x + v + this.constants.v1;
843
+ }, { output: [10], constants: { v1: 100 } });
844
+ const result = kernel(1);
845
+ const kernelString = kernel.toString(1);
846
+ fs.writeFileSync('./my-exported-kernel.js', 'module.exports = ' + kernelString);
847
+ import * as MyExportedKernel from './my-exported-kernel';
848
+ import gl from 'gl';
849
+ const myExportedKernel = MyExportedKernel({ context: gl(1,1), constants: { v1: 100 } });
850
+
851
+ ```
852
+
853
+
854
+ Here is an example for just-in-time function creation:
822
855
823
856
``` js
824
857
const gpu = new GPU ();
@@ -831,10 +864,13 @@ const kernel = gpu.createKernel(function(a) {
831
864
}, { output: [6 ] });
832
865
kernel (input (a, [6 , 6 ]));
833
866
const kernelString = kernel .toString (input (a, [6 , 6 ]));
834
- const newKernel = new Function (' return ' + kernelString)()(context);
867
+ const newKernel = new Function (' return ' + kernelString)()({ context } );
835
868
newKernel (input (a, [6 , 6 ]));
836
869
```
837
870
871
+ #### using constants with ` kernel.toString(...args) `
872
+ You can assign _ some_ new constants when using the function output from ` .toString() ` ,
873
+
838
874
## Supported Math functions
839
875
840
876
Since the code running in the kernel is actually compiled to GLSL code, not all functions from the JavaScript Math module are supported.
@@ -914,6 +950,17 @@ GPU.js is written in such a way, you can introduce your own backend. Have a sug
914
950
* Kernel - A function that is tightly coupled to program that runs on the Graphic Processor
915
951
* 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
916
952
953
+ ## Testing
954
+ Testing is done (right now) manually, (help wanted (here)[ https://github.com/gpujs/gpu.js/issues/515 ] if you can!), using the following:
955
+ * For browser, setup a webserver on the root of the gpu.js project and visit htt://url/test/all.html
956
+ * For node, run either of the 3 commands:
957
+ * ` yarn test test/features `
958
+ * ` yarn test test/internal `
959
+ * ` yarn test test/issues `
960
+
961
+ ## Building
962
+ Building isn't required on node, but is for browser. To build the browser's files, run: ` yarn make `
963
+
917
964
# Get Involved!
918
965
919
966
## Contributing
0 commit comments