title: Usage of `stage_in` in compute function in Metal
body: <p>I was reading <code>Metal Shading Language</code> specification of Apple and I wonder about <code>stage_in</code> parameter. The doc says that this identifier can be used in order to implement per-thread input. </p>
  
  <blockquote>
    <p>The stage_in attribute in a kernel function allows
    you to decouple the data type used to declare the per-thread inputs in
    the function from the actual data type used to store the per-thread
    inputs.</p>
  </blockquote>
  
  <p>Now, it's very typical situation for kernel shader which does some heavy calculation to have in arguments big containers of data. For instance, if you're implementing matrices multiplication via <code>Metal</code> shader, you will have to pass that data to GPU and fetch necessary pieces in each GPU thread in order to perform multiplication. And I noticed that one of the biggest bottle-necks in <code>Metal</code> shader is dynamic indexing of such arrays and sometimes it's very hard to avoid that.</p>
  
  <p>So what I understood from the <code>Metal Shading Language</code> spec that this <code>stage_in</code> parameter solves that issue. That it allows somehow (well, not somehow, but with using <code>attributes</code> mechanic) to link only necessary piece of data to each GPU thread and I will not need to fetch data out of array with dynamic indexes because function will be linked to needed piece of data from the start.</p>
  
  <p>I'm in the middle of figuring out of how to use <code>stage_in</code> with <code>kernel</code> shaders but now I'm getting second thoughts - are my assumptions correct about <code>stage_in</code>? Does it solve the problem with dynamic indexing?</p>