title: Metal Shading language for Core Image color kernel, how to pass an array of float3
body: <p>I'm trying to port some <code>CIFilter</code> from this <a href="https://github.com/FlexMonkey/Filterpedia" rel="nofollow noreferrer">source</a> by using metal shading language for Core Image.<br>
  I have a palette of color composed by an array of <code>RGB</code> struct and I want to pass them as an argument to a custom CI color image kernel.<br>
  The RGB struct is converted into an array of <code>SIMD3&lt;Float&gt;</code>.</p>
  
  <pre><code> static func SIMD3Palette(_ palette: [RGB]) -&gt; [SIMD3&lt;Float&gt;] {
          return palette.map{$0.toFloat3()}
      }
  </code></pre>
  
  <p>The kernel should take and array of <code>simd_float3</code> values, the problem is the when I launch the filter it tells me that the argument at index 1 is expecting an <code>NSData</code>.</p>
  
  <pre><code>override var outputImage: CIImage? {
          guard let inputImage = inputImage else
          {
              return nil
          }
           let palette = EightBitColorFilter.palettes[Int(inputPaletteIndex)]
          let extent = inputImage.extent
          let arguments = [inputImage, palette, Float(palette.count)] as [Any]
  
          let final = colorKernel.apply(extent: extent, arguments: arguments)
  
          return final
      }
  </code></pre>
  
  <p>This is the kernel:</p>
  
  <pre><code>float4 eight_bit(sample_t image, simd_float3 palette[], float paletteSize, destination dest) {
          float dist = distance(image.rgb, palette[0]);
          float3 returnColor = palette[0];
          for (int i = 1; i &lt; floor(paletteSize); ++i) {
              float tempDist = distance(image.rgb, palette[i]);
              if (tempDist &lt; dist) {
                  dist = tempDist;
                  returnColor = palette[i];
              }
          }
          return float4(returnColor, 1);
      }
  </code></pre>
  
  <p>I'm wondering how can I pass a data buffer to the kernel since converting it into an NSData seems not enough. <br>I saw some example but they are using "full" shading language that is not available for Core Image that is a sort of <a href="https://developer.apple.com/metal/MetalCIKLReference6.pdf" rel="nofollow noreferrer">subset</a> for dealing only with fragments. </p>