I am new to Metal. I need to port OpenCL compute shader programs to Metal compute shaders. I am having trouble in finding sample codes in Metal and Swift, Objective-C. I can see examples with GPU buffer objects only. As in the following OpenCL shader function, I need to pass uniform constant float and integer values along with GPU buffer pointers. I only use compute shaders.
__kernel void testfunction (
float ratio1,
int opr1,
int opr2,
__global float *INPUT1,
__global float *INPUT2,
__global float *OUTPUT
} {
int peIndex = get_global_id(0);
// main compute block
}
How can I code these in Metal? And how can I set/pass these parameter values in Swift and Objective-c main programs?
My shader program has several functions to put together. I need enqueue multiple times using different functions with different parameters. Same functions can be used with different parameters. This means that I need to create different "struct" and buffer objects for each enqueuing task and transfer value to GPU at initialization time. Note that for each enqueuing, parameter set is different but in subsequent operations parameters don't change. Am I correct? Thanks.