1
votes

I have a buffer that pass the mouse position to the

kernel void compute(texture2d<float, access::write> output [[texture(0)]],
                    constant float2 &mouse [[buffer(1)]],//<-- mouse buffer
                    uint2 gid [[thread_position_in_grid]])
{
... 
}

How can I make it as global constant so that I can access it in any function outside of kernel? For example:

float abc(float p){

float a = p * globalmouseposition.x;

return a;

}
1

1 Answers

2
votes

Metal doesn't support mutable global variables. You should pass the necessary values as parameters to all of the functions that use them. There are other approaches (such as wrapping all of your functions in a struct or class and using member variables to simulate global variables), but I recommend just passing down the values you need from function to function.