Passing Functions to Shaders?

I am building a small machine learning implementation using compute shaders and I am wondering if it is possible to pass functions to a compute shader (glsl, hlsl, or spirv) in a storage buffer or via some other method?

My intention is to bind an SSBO containing an array of weights and an array of activation functions indexed to each workgroup/invocation. The idea is to give each workgroup/invocation its own unique activation function.

C++ allows functions to be passed into others by passing a pointer and then dereferencing it:

void foo(int input);

void bar(int input, void(*foo)(int)) {
    *foo(input);
}

However, I don’t think this exact implementation can be done with shaders since the data “lives” on the GPU and I think the GPU has a separate memory pool from the CPU.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.