<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 9, 2018 at 3:21 AM, Iago Toral Quiroga <span dir="ltr"><<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">When a TCS is present at link time we know the number of vertices in the<br>
patch and we can lower gl_PatchVerticesIn in the TesEval stage directly<br>
to a constant. We already have a pass for this that we use in the<br>
Vulkan pipeline, so we just reuse that.<br>
<br>
Notice that the GLSL linker also implements this optimization, which<br>
we are not removing because other drivers may still depend on it, so<br>
this should only be useful for OpenGL SPIR-V shaders for now.<br>
---<br>
 src/mesa/drivers/dri/i965/brw_<wbr>program.c | 26 ++++++++++++++++++++++----<br>
 1 file changed, 22 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_program.c b/src/mesa/drivers/dri/i965/<wbr>brw_program.c<br>
index f6c7e4515c..7fae22c620 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_program.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_program.c<br>
@@ -89,15 +89,33 @@ brw_create_nir(struct brw_context *brw,<br>
    nir_validate_shader(nir);<br>
<br>
    /* Lower PatchVerticesIn from system value to uniform. This needs to<br>
-    * happen before brw_preprocess_nir, since that will lower system values.<br>
+    * happen before brw_preprocess_nir, since that will lower system values<br>
+    * to intrinsics.<br>
+    *<br>
+    * We only do this for TES if no TCS is present, since otherwise we know<br>
+    * the number of vertices in the patch at link time and we can lower it<br>
+    * directly to a constant. We do this in nir_lower_patch_vertices, which<br>
+    * needs to run after brw_nir_preprocess has turned the system values<br>
+    * into intrinsics.<br>
     */<br>
-   if ((stage == MESA_SHADER_TESS_CTRL && brw->screen->devinfo.gen >= 8) ||<br>
-       stage == MESA_SHADER_TESS_EVAL) {<br>
+   const bool lower_patch_vertices_in_to_<wbr>uniform =<br>
+      (stage == MESA_SHADER_TESS_CTRL && brw->screen->devinfo.gen >= 8) ||<br>
+      (stage == MESA_SHADER_TESS_EVAL &&<br>
+       !shader_prog->_LinkedShaders[<wbr>MESA_SHADER_TESS_CTRL]);<br>
+<br>
+   if (lower_patch_vertices_in_to_<wbr>uniform)<br>
       brw_nir_lower_patch_vertices_<wbr>in_to_uniform(nir);<br>
-   }<br>
<br>
    nir = brw_preprocess_nir(brw-><wbr>screen->compiler, nir);<br>
<br>
+   if (stage == MESA_SHADER_TESS_EVAL && !lower_patch_vertices_in_to_<wbr>uniform) {<br>
+      assert(shader_prog->_<wbr>LinkedShaders[MESA_SHADER_<wbr>TESS_CTRL]);<br>
+      struct gl_linked_shader *linked_tcs =<br>
+         shader_prog->_LinkedShaders[<wbr>MESA_SHADER_TESS_CTRL];<br>
+      uint32_t patch_vertices = linked_tcs->Program->info.<wbr>tess.tcs_vertices_out;<br>
+      nir_lower_tes_patch_vertices(<wbr>nir, patch_vertices);<br>
+   }<br></blockquote><div><br></div>Ugh...  This would be way cleaner if we could put nir_lower_tes_patch_vertices higher up.  But I went and read the pass and it's not really set up for that.  We could always tweak the patch_vertices_to_uniform pass to look for system value intrinsics instead of uniforms.  But that's a mess for other reasons.  Hopefully one day, we can clean this up.  Until then, the series is</div><div class="gmail_quote"><br></div><div class="gmail_quote">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
    if (stage == MESA_SHADER_FRAGMENT) {<br>
       static const struct nir_lower_wpos_ytransform_<wbr>options wpos_options = {<br>
          .state_tokens = {STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM, 0, 0, 0},<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.11.0<br>
<br>
</font></span></blockquote></div><br></div></div>