Syntax for functions other than vertices | fragment | core in a metal shader file

I am porting some OpenCL core code to Metal compute shader. Get in touch early enough when trying to convert various helper functions. For example, for example, something like the following function in the .metalXcode (7.1) file gives me the warning "There is no previous function prototype" warning

float maxComponent(float4 a) {
    return fmax(a.x, fmax(a.y, fmax(a.z, a.w)));
}

What is the "metallic" way to do this?

+4
source share
1 answer

Three ways I know about:

(I rewrote the function as overload and became more readable for me.)

Actually declare a prototype:

float fmax(float4 float4);
float fmax(float4 float4) {
   return fmax(
      fmax(float4[0], float4[1]),
      fmax(float4[2], float4[3])
   );
}

Copy it to the statics file:

static float fmax(float4 float4) {
   return fmax(
      fmax(float4[0], float4[1]),
      fmax(float4[2], float4[3])
   );
}

:

namespace {
   float fmax(float4 float4) {
      return metal::fmax(
         metal::fmax(float4[0], float4[1]),
         metal::fmax(float4[2], float4[3])
      );
   }
}
+6

Source: https://habr.com/ru/post/1617858/


All Articles