Search code examples
functioncallbackwgsl

Is there any way to pass a callback to a function in WGSL?


I can't seem to figure out how or if it is acually possible to pass acallback to a function in WGSL. I would like to make something along these lines.

fn foo(x: f32, bar: ?callback?) {
    bar(x);
}


fn baz(y: f32) -> f32 {
    return y + 1;
}

@compute 
fn main() {
    foo(5, baz) // => 6
}

My intelisense hinted me

bar: Fn

but compiler doesn't like that.


Solution

  • WGSL does not have function pointers, so you can't pass a function as a parameter.