@@ -89,14 +89,18 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
8989* [ Cleanup] ( #cleanup )
9090* [ Flattened typed array support] ( #flattened-typed-array-support )
9191* [ Precompiled and Lighter Weight Kernels] ( #precompiled-and-lighter-weight-kernels )
92+ * [ using JSON] ( #using-json )
93+ * [ Exporting kernel] ( #exporting-kernel )
9294* [ Supported Math functions] ( #supported-math-functions )
9395* [ How to check what is supported] ( #how-to-check-what-is-supported )
9496* [ Typescript Typings] ( #typescript-typings )
9597* [ Dealing With Transpilation] ( #dealing-with-transpilation )
9698* [ Full API reference] ( #full-api-reference )
99+ * [ How possible in node] ( #how-possible-in-node )
100+ * [ Testing] ( #testing )
101+ * [ Building] ( #building )
97102* [ Contributors] ( #contributors )
98103* [ Contributing] ( #contributing )
99- * [ How possible in node] ( #how-possible-in-node )
100104* [ Terms Explained] ( #terms-explained )
101105* [ License] ( #license )
102106
@@ -815,10 +819,38 @@ NOTE: There is lighter weight, pre-built, version of GPU.js to assist with seria
815819* [ dist/gpu-browser-core.js] ( dist/gpu-browser-core.js )
816820* [ dist/gpu-browser-core.min.js] ( dist/gpu-browser-core.min.js )
817821
818- ### using ` kernel.toString(args...) `
822+ ### Exporting kernel
819823GPU.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+ ``` js
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+ Here is an example for just-in-time function creation:
822854
823855``` js
824856const gpu = new GPU ();
@@ -831,10 +863,13 @@ const kernel = gpu.createKernel(function(a) {
831863 }, { output: [6 ] });
832864kernel (input (a, [6 , 6 ]));
833865const kernelString = kernel .toString (input (a, [6 , 6 ]));
834- const newKernel = new Function (' return ' + kernelString)()(context);
866+ const newKernel = new Function (' return ' + kernelString)()({ context } );
835867newKernel (input (a, [6 , 6 ]));
836868```
837869
870+ #### using constants with ` kernel.toString(...args) `
871+ You can assign _ some_ new constants when using the function output from ` .toString() ` ,
872+
838873## Supported Math functions
839874
840875Since the code running in the kernel is actually compiled to GLSL code, not all functions from the JavaScript Math module are supported.
@@ -914,6 +949,17 @@ GPU.js is written in such a way, you can introduce your own backend. Have a sug
914949* Kernel - A function that is tightly coupled to program that runs on the Graphic Processor
915950* 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
916951
952+ ## Testing
953+ Testing is done (right now) manually, (help wanted (here)[ https://github.com/gpujs/gpu.js/issues/515 ] if you can!), using the following:
954+ * For browser, setup a webserver on the root of the gpu.js project and visit htt://url/test/all.html
955+ * For node, run either of the 3 commands:
956+ * ` yarn test test/features `
957+ * ` yarn test test/internal `
958+ * ` yarn test test/issues `
959+
960+ ## Building
961+ Building isn't required on node, but is for browser. To build the browser's files, run: ` yarn make `
962+
917963# Get Involved!
918964
919965## Contributing
0 commit comments