Add sk_InstanceID

Bug: skia:
Change-Id: I79b0dce96d9af7632f027afa5317a7725e96cda3
Reviewed-on: https://skia-review.googlesource.com/59861
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/sksl/README b/src/sksl/README
index c8fba50..d33217b 100644
--- a/src/sksl/README
+++ b/src/sksl/README
@@ -41,6 +41,7 @@
 * use sk_Position instead of gl_Position
 * use sk_PointSize instead of gl_PointSize
 * use sk_VertexID instead of gl_VertexID
+* use sk_InstanceID instead of gl_InstanceID
 * the fragment coordinate is sk_FragCoord, and is always relative to the upper
   left.
 * you do not need to include ".0" to make a number a float (meaning that
diff --git a/src/sksl/SkSLCompiler.h b/src/sksl/SkSLCompiler.h
index 1c8ef4f..53cde1a 100644
--- a/src/sksl/SkSLCompiler.h
+++ b/src/sksl/SkSLCompiler.h
@@ -26,6 +26,7 @@
 #define SK_TEXTURESAMPLERS_BUILTIN     10006
 #define SK_FRAGCOORD_BUILTIN              15
 #define SK_VERTEXID_BUILTIN                5
+#define SK_INSTANCEID_BUILTIN              6
 #define SK_CLIPDISTANCE_BUILTIN            3
 #define SK_INVOCATIONID_BUILTIN            8
 
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
index 229b183..5edb883 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.cpp
+++ b/src/sksl/SkSLGLSLCodeGenerator.cpp
@@ -449,6 +449,9 @@
         case SK_VERTEXID_BUILTIN:
             this->write("gl_VertexID");
             break;
+        case SK_INSTANCEID_BUILTIN:
+            this->write("gl_InstanceID");
+            break;
         case SK_CLIPDISTANCE_BUILTIN:
             this->write("gl_ClipDistance");
             break;
diff --git a/src/sksl/sksl_vert.include b/src/sksl/sksl_vert.include
index b4dd63a..9e797b3 100644
--- a/src/sksl/sksl_vert.include
+++ b/src/sksl/sksl_vert.include
@@ -9,6 +9,7 @@
 };
 
 layout(builtin=5) in int sk_VertexID;
+layout(builtin=6) in int sk_InstanceID;
 
 )
 
diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp
index 28d5039..29b3129 100644
--- a/tests/SkSLGLSLTest.cpp
+++ b/tests/SkSLGLSLTest.cpp
@@ -1037,6 +1037,18 @@
          SkSL::Program::kVertex_Kind);
 }
 
+DEF_TEST(SkSLInstanceID, r) {
+    test(r,
+         "out int id; void main() { id = sk_InstanceID; }",
+         *SkSL::ShaderCapsFactory::Default(),
+         "#version 400\n"
+         "out int id;\n"
+         "void main() {\n"
+         "    id = gl_InstanceID;\n"
+         "}\n",
+         SkSL::Program::kVertex_Kind);
+}
+
 DEF_TEST(SkSLClipDistance, r) {
     test(r,
          "void main() { sk_ClipDistance[0] = 0; }",