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

[shader-ast-js] Add mechanism to handle function args with out / inout qualifiers #96

Open
postspectacular opened this issue Jul 6, 2019 · 0 comments

Comments

@postspectacular
Copy link
Member

postspectacular commented Jul 6, 2019

As in JS, GLSL functions can only return a single result, however unlike JS, they can write secondary results into args qualified with out/inout. Due to lack of pointers, there's no easy way to achieve this in JS, unless any such args are wrapped in a temp array which also requires the function call itself to be augmented by the codegen...

Possible approach:

  • analyze current scope for function calls with out / inout params
  • if present wrap all such vars as array (boxed values)
/**
 * @param x in float
 */
const foo = (x: number) => x + 10;

/**
 * @param x in float
 * @param y in float
 * @param z out float
 */
const bar = (x: number, y: number, z: number[]) => {
    z[0] = x + y;
};

const baz = () => {
    // after pre-analyzing `baz` scope we have determined that
    // y is used as `out` arg by `bar`, so box as array
    let y = [0];
    // call with unboxed value (since no out arg)
    y[0] = foo(y[0]);
    // call with both unboxed and boxed
    bar(1, y[0], y);
    // return unboxed
    return y[0];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

1 participant