Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exports from modules #3

Open
DanielMazurkiewicz opened this issue Apr 22, 2020 · 5 comments
Open

Exports from modules #3

DanielMazurkiewicz opened this issue Apr 22, 2020 · 5 comments

Comments

@DanielMazurkiewicz
Copy link

I've noticed that you use everywhere something like this:

import { setWebGLContext, getWebGLContext, isWebGL2 } from "./context";
import { ComputeShader, passThruFrag, passThruVert } from "./computeShader";
import { RenderTarget } from "./renderTarget";
import { packBooleans, unpackBooleans } from "./vectorBoolArray";
import { packInt16, unpackInt16, MIN_INT16, MAX_INT16 } from "./vectorInt16";
import { packUint16, unpackUint16, MIN_UINT16, MAX_UINT16 } from "./vectorUint16";
import { functionStrings } from "./functionStrings";

module.exports = {
  setWebGLContext,
  getWebGLContext,
  isWebGL2,
  ComputeShader,
  passThruFrag,
  passThruVert,
  RenderTarget,
  packBooleans,
  unpackBooleans,
  packInt16,
  unpackInt16,
  MIN_INT16,
  MAX_INT16,
  packUint16,
  unpackUint16,
  MIN_UINT16,
  MAX_UINT16,
  functionStrings
};

Do you know that you can do it like that:

export { setWebGLContext, getWebGLContext, isWebGL2 } from "./context";
export { ComputeShader, passThruFrag, passThruVert } from "./computeShader";
export { RenderTarget } from "./renderTarget";
export { packBooleans, unpackBooleans } from "./vectorBoolArray";
export { packInt16, unpackInt16, MIN_INT16, MAX_INT16 } from "./vectorInt16";
export { packUint16, unpackUint16, MIN_UINT16, MAX_UINT16 } from "./vectorUint16";
export { functionStrings } from "./functionStrings";

:-)

@demskie
Copy link
Owner

demskie commented Apr 24, 2020

I don't exactly recall why I fell into this pattern of exporting functions this way.

import { setWebGLContext, getWebGLContext, isWebGL2 } from "./context";

module.exports = {
  setWebGLContext,
  getWebGLContext,
  isWebGL2,
};

export { setWebGLContext, getWebGLContext, isWebGL2 } from "./context";

I recall that for some reason I needed to export things twice.

module.exports = { foo } for NodeJS consumption
export { foo } from "bar" for ES6/browser usage

@DanielMazurkiewicz
Copy link
Author

I like the general idea of your project, but fortunately it seems that WebGPU (which should allow making computations a way, way easier) is already pretty close on horizon. Yesterday saw news that it is already available in Firefox nightly (so it should be in some form available in stable release in 12 weeks).

@demskie
Copy link
Owner

demskie commented Apr 27, 2020

I'm definitely going to transition to WebGPU.

Right now I see the following advantages:

  1. Unlike WebGL 2.0 it seems everyone is onboard with supporting WebGPU
  2. Draw call overhead is supposed to be drastically reduced
  3. Compilation time should be improved (or nearly non-existent in certain scenarios)
  4. 32bits of floating point precision is available

WebGL 1.0 supported ancient hardware (SM 3.0) and had to make some insane compromises. For example - for loop headers must only contain constant expressions. Also, some GPUs of that era didn't implement integer arithmetic and that resulted in bitwise operators being omitted from the spec. And get this - in those older environments the result of division doesn't get truncated! What a mess.

@DanielMazurkiewicz
Copy link
Author

In terms of WebGPU I'm thinking actually of making static transpiller inside my TypeScript bundler I'm currently working on. (basically that is a reason why I've found your project :-) ) I would be way more happy to get all GPU code ready at (typescript) compile time. This is my simple sketch of what would I like to have as transpillation input from developer:

const computer = COMPUTE_ZONE(() => {

  let inputData: U32[] = []; // let allows to assign data with update function
  const notChangeable: F32 = 20


  const transformData = MAPPER((dataElement: U32, result: U32, inputData?: U32[]) => {
     result = dataElement
  });
  
  const populateNewData = POPULATER((index: U32, result: U32) => {
  
  });
  
  const mainProgram = PROGRAM(()=> {
    const dataPopulated = populateNewData(100);
    const dataTransformed = transformData(inputData, dataPopulated);

    return dataTransformed; // can be skipped and then data will not be returned by run method
  })

})

computer.update('inputData', []); // will update gpu buffer defined above as 'let inputData'
const result = computer.run('mainProgram');

As output would have all (and only) necessary code to handle given computations.

@demskie
Copy link
Owner

demskie commented May 1, 2020

That reminds me of GPU.js but with the transpilation done at runtime. Transpiling the code before it hits TSC sounds like a good idea. You'd be able to use all the type hints that Typescript provides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants