Getting the index of a triangle in shader?

I’m kinda new to shader programming and I’m writing a shader where i would like to send custom data (1 byte) accompanying each triangle in the mesh.
Basically I want to have an array of data that is the same size as the number of triangles in the mesh, and then read that data in the shader based on which triangle is currently being drawn.
The problem here is that I need to know the index of a particular triangle in the shader, is that possible at all?

You can use the SV_PrimitiveID semantic. This worked in a quick test but I’m not 100% certain if it does on all platforms. I also don’t know if there is a way to do this in a surface shader (since you don’t write the fragment shader directly in that case but only a small part of it).

float4 frag (v2f i, uint triangleID: SV_PrimitiveID) : SV_Target {
      // fragment shader code