st/nir: Lower TES gl_PatchVerticesIn to a constant if linked with a TCS.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 19 Jul 2018 01:46:09 +0000 (18:46 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Fri, 11 Jan 2019 21:07:54 +0000 (13:07 -0800)
If the TCS and TES are linked together, we can simply replace the TES's
gl_PatchVerticesIn system value with a constant, possibly allowing extra
optimization or letting the driver avoid uploading a special value.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/state_tracker/st_glsl_to_nir.cpp

index 87e4a37a9d9ddd3fa6422e602f7c156c72ba4d8d..3ab7af7c20c385933f3da664715052cc5af88184 100644 (file)
@@ -626,6 +626,27 @@ st_nir_link_shaders(nir_shader **producer, nir_shader **consumer, bool scalar)
    }
 }
 
+static void
+st_lower_patch_vertices_in(struct gl_shader_program *shader_prog)
+{
+   struct gl_linked_shader *linked_tcs =
+      shader_prog->_LinkedShaders[MESA_SHADER_TESS_CTRL];
+   struct gl_linked_shader *linked_tes =
+      shader_prog->_LinkedShaders[MESA_SHADER_TESS_EVAL];
+
+   /* If we have a TCS and TES linked together, lower TES patch vertices. */
+   if (linked_tcs && linked_tes) {
+      nir_shader *tcs_nir = linked_tcs->Program->nir;
+      nir_shader *tes_nir = linked_tes->Program->nir;
+
+      /* The TES input vertex count is the TCS output vertex count,
+       * lower TES gl_PatchVerticesIn to a constant.
+       */
+      uint32_t tes_patch_verts = tcs_nir->info.tess.tcs_vertices_out;
+      NIR_PASS_V(tes_nir, nir_lower_patch_vertices, tes_patch_verts, NULL);
+   }
+}
+
 extern "C" {
 
 void
@@ -747,6 +768,8 @@ st_link_nir(struct gl_context *ctx,
       prev = i;
    }
 
+   st_lower_patch_vertices_in(shader_program);
+
    for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
       struct gl_linked_shader *shader = shader_program->_LinkedShaders[i];
       if (shader == NULL)