title: In a GLSL vertex shader can you access the index of a vertex in the index buffer, not just the vertex buffer?
body: <p>I am rendering a primitive in Vulkan which has repeated vertices which are processed differently by the vertex shader depending on their index in the vertex buffer. All repeated vertices are consecutive, so if a, b, c are vertices the buffer might look like <code>[a,a,a,b,b,b,c,c,c]</code>, and I need to be able to tell in my vertex shader whether this is the first, second or third time it's seeing the same vertex.</p>
  <p>If I simply submit the same vertex a number of times into the vertex buffer, I can use <code>gl_VertexIndex</code> (or <code>gl_VertexID</code> in OpenGL) to determine what number repetition of the same vertex it is, and then process each repetition differently as needed.</p>
  <p>However, I would like to use index buffers to avoid duplicating the vertices in memory. When using index buffers <code>gl_VertexIndex</code> is the same value each time the same index appears, as it is an index into the vertex buffer which only has one copy of each vertex for index buffers to be worthwhile. This means in the vertex shader I cannot differentiate between the first, second or third repetition of a vertex.</p>
  <p>Is there a built-in variable like <code>gl_VertexIndex</code> I can use, eg <code>gl_IndexBufferIndex</code> which tells me what index in the index buffer this vertex came from? Or, how many times this vertex has already been encountered in the index buffer? And if not, is there an efficient means to send this information to the vertex shader on a per-vertex basis?</p>
  <p>According to the Vulkan Specification 1.2.146 §8.7.1, the vertex shading must be repeated for the same index unless it is guaranteed an identical result, so this should be possible:</p>
  <blockquote>
  <p>If the same vertex is specified multiple times in a draw command (e.g. by including the same index value multiple times in an index buffer) the implementation may reuse the results of vertex shading if it can statically determine that the vertex shader invocations will produce identical results.</p>
  </blockquote>