title: Metal write to buffer from vertex function
body: <p>I'm building an app rendering 2D geometry in Metal.</p>
  
  <p>Right now, the positions of the vertices are solved from within the vertex function. What I'd like is to write the solved positions back to a buffer from inside that same vertex function. </p>
  
  <p>I'm under the impression that this is <a href="https://forums.developer.apple.com/thread/21104" rel="noreferrer">possible</a> although in my first attempt to do it i.e.:</p>
  
  <pre><code>vertex VertexOut basic_vertex(device VertexIn *vertices [[ buffer(0) ]],
                                device VertexOut *solvedVertices [[ buffer(1) ]],
                                vid [[ vertex_id ]])
  {
      VertexIn in vertices[vid];
      VertexOut out;
      out.position = ... // Solve the position of the vertex 
  
      solvedVertices[vid] = out // Write to the buffer later to be read by CPU
  
      return out;
  }
  </code></pre>
  
  <p>I was graced with the presence of this compile time error:</p>
  
  <p><a href="https://i.stack.imgur.com/PQMfL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PQMfL.png" alt="enter image description here"></a></p>
  
  <p>Okay, so a few solutions come to my head - I could solve for the vertex positions in a first - <em>non-rasterizing</em> - pass through a vertex function declared like:</p>
  
  <pre><code>vertex void solve_vertex(device VertexIn *unsolved [[ buffer(0) ]],
                           device VertexOut *solved [[ buffer(1) ]],
                           vid [[ vertex_id ]])
  {
      solved[vid] = ... 
  }
  </code></pre>
  
  <p>And then pipe those solved vertices into a now much simpler - <em>rasterizing</em> - vertex function.</p>
  
  <p>Another solution that could work but seems less appealing could be to solve them in a compute function.</p>
  
  <p><strong>So,</strong> what is the best way forward in a situation like this? From my little bits of research, I could track down that this same sort of procedure is done in <a href="https://www.opengl.org/wiki/Transform_Feedback" rel="noreferrer">Transform Feedback</a> but I've had no luck (other than the <a href="https://forums.developer.apple.com/thread/21104" rel="noreferrer">link</a> at the begging of the question) finding examples in Apple's documentation/sample code or elsewhere on the web for best practices when facing this sort of problem.</p>