<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jan 9, 2017 at 11:37 PM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">v2: Merge more TCS/TES info.<br>
<br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
---<br>
 src/intel/vulkan/anv_pipeline.<wbr>c | 189 ++++++++++++++++++++++++++++++<wbr>+++++++++-<br>
 1 file changed, 187 insertions(+), 2 deletions(-)<br>
<br>
Jason and I figured out caching.  It turns out I had a one line bug.<br>
<br>
diff --git a/src/intel/vulkan/anv_<wbr>pipeline.c b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
index 0dc7019efb1..79536e62458 100644<br>
--- a/src/intel/vulkan/anv_<wbr>pipeline.c<br>
+++ b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
@@ -499,6 +499,184 @@ anv_pipeline_compile_vs(struct anv_pipeline *pipeline,<br>
    return VK_SUCCESS;<br>
 }<br>
<br>
+static void<br>
+merge_tess_info(struct shader_info *tes_info,<br>
+                const struct shader_info *tcs_info)<br>
+{<br>
+   /* The Vulkan 1.0.38 spec, section 21.1 Tessellator says:<br>
+    *<br>
+    *    "PointMode. Controls generation of points rather than triangles<br>
+    *     or lines. This functionality defaults to disabled, and is<br>
+    *     enabled if either shader stage includes the execution mode.<br>
+    *<br>
+    * and about Triangles, Quads, IsoLines, VertexOrderCw, VertexOrderCcw,<br>
+    * PointMode, SpacingEqual, SpacingFractionalEven, SpacingFractionalOdd,<br>
+    * and OutputVertices, it says:<br>
+    *<br>
+    *    "One mode must be set in at least one of the tessellation<br>
+    *     shader stages."<br>
+    *<br>
+    * So, the fields can be set in either the TCS or TES, but they must<br>
+    * agree if set in both.  Our backend looks at TES, so bitwise-or in<br>
+    * the values from the TCS.<br>
+    */<br>
+   assert(tcs_info->tess.tcs_<wbr>vertices_out == 0 ||<br>
+          tes_info->tess.tcs_vertices_<wbr>out == 0 ||<br>
+          tcs_info->tess.tcs_vertices_<wbr>out == tes_info->tess.tcs_vertices_<wbr>out);<br>
+   tes_info->tess.tcs_vertices_<wbr>out |= tcs_info->tess.tcs_vertices_<wbr>out;<br>
+<br>
+   assert(tcs_info->tess.spacing == TESS_SPACING_UNSPECIFIED ||<br>
+          tes_info->tess.spacing == TESS_SPACING_UNSPECIFIED ||<br>
+          tcs_info->tess.spacing == tes_info->tess.spacing);<br>
+   tes_info->tess.spacing |= tcs_info->tess.spacing;<br>
+<br>
+   tes_info->tess.ccw |= tcs_info->tess.ccw;<br>
+   tes_info->tess.point_mode |= tcs_info->tess.point_mode;<br>
+}<br>
+<br>
+static VkResult<br>
+anv_pipeline_compile_tcs_tes(<wbr>struct anv_pipeline *pipeline,<br>
+                             struct anv_pipeline_cache *cache,<br>
+                             const VkGraphicsPipelineCreateInfo *info,<br>
+                             struct anv_shader_module *tcs_module,<br>
+                             const char *tcs_entrypoint,<br>
+                             const VkSpecializationInfo *tcs_spec_info,<br>
+                             struct anv_shader_module *tes_module,<br>
+                             const char *tes_entrypoint,<br>
+                             const VkSpecializationInfo *tes_spec_info)<br>
+{<br>
+   const struct gen_device_info *devinfo = &pipeline->device->info;<br>
+   const struct brw_compiler *compiler =<br>
+      pipeline->device->instance-><wbr>physicalDevice.compiler;<br>
+   struct anv_pipeline_bind_map tcs_map;<br>
+   struct anv_pipeline_bind_map tes_map;<br>
+   struct brw_tcs_prog_key tcs_key = { 0, };<br>
+   struct brw_tes_prog_key tes_key = { 0, };<br>
+   struct anv_shader_bin *tcs_bin = NULL;<br>
+   struct anv_shader_bin *tes_bin = NULL;<br>
+   unsigned char tcs_sha1[20];<br>
+   unsigned char tes_sha1[20];<br>
+<br>
+   populate_sampler_prog_key(&<wbr>pipeline->device->info, &tcs_key.tex);<br>
+   populate_sampler_prog_key(&<wbr>pipeline->device->info, &tes_key.tex);<br>
+   tcs_key.input_vertices = info->pTessellationState-><wbr>patchControlPoints;<br>
+<br>
+   if (cache) {<br>
+      anv_hash_shader(tcs_sha1, &tcs_key, sizeof(tcs_key), tcs_module,<br>
+                      tcs_entrypoint, pipeline->layout, tcs_spec_info);<br>
+      anv_hash_shader(tes_sha1, &tes_key, sizeof(tes_key), tes_module,<br>
+                      tes_entrypoint, pipeline->layout, tes_spec_info);<br>
+      tcs_bin = anv_pipeline_cache_search(<wbr>cache, tcs_sha1, 20);<br>
+      tes_bin = anv_pipeline_cache_search(<wbr>cache, tes_sha1, 20);<br>
+   }<br>
+<br>
+   if (tcs_bin == NULL || tes_bin == NULL) {<br></blockquote><div><br></div><div>So... caching... What happens if one of them succeeds but not the other?  I think we have a fundamental caching problem here in that we assume that they are compiled together but we cache them separately.  My feeling is that they have to somehow be cached together.  This may mean some pipeline cache changes.  Or...<br><br></div><div>Another option would be to hash the two keys together somehow.  Specifically, you could concatenate the two individual hashes and hash that to get a new "joint hash" which includes both.  You then just need to do something to it to ensure that the TES and TCS have different hashes.  We could do something stupid such as XOR in some bits to turn TES into TCS or vice versa or we could just change the order of the concatenation or something.  In any case, we need both hashes to take the other shader into account.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      struct brw_tcs_prog_data tcs_prog_data = { 0, };<br>
+      struct brw_tes_prog_data tes_prog_data = { 0, };<br>
+      struct anv_pipeline_binding tcs_surface_to_descriptor[256]<wbr>;<br>
+      struct anv_pipeline_binding tcs_sampler_to_descriptor[256]<wbr>;<br>
+      struct anv_pipeline_binding tes_surface_to_descriptor[256]<wbr>;<br>
+      struct anv_pipeline_binding tes_sampler_to_descriptor[256]<wbr>;<br>
+<br>
+      tcs_map = (struct anv_pipeline_bind_map) {<br>
+         .surface_to_descriptor = tcs_surface_to_descriptor,<br>
+         .sampler_to_descriptor = tcs_sampler_to_descriptor<br>
+      };<br>
+      tes_map = (struct anv_pipeline_bind_map) {<br>
+         .surface_to_descriptor = tes_surface_to_descriptor,<br>
+         .sampler_to_descriptor = tes_sampler_to_descriptor<br>
+      };<br>
+<br>
+      nir_shader *tcs_nir =<br>
+         anv_pipeline_compile(pipeline, tcs_module, tcs_entrypoint,<br>
+                              MESA_SHADER_TESS_CTRL, tcs_spec_info,<br>
+                              &tcs_prog_data.base.base, &tcs_map);<br>
+      nir_shader *tes_nir =<br>
+         anv_pipeline_compile(pipeline, tes_module, tes_entrypoint,<br>
+                              MESA_SHADER_TESS_EVAL, tes_spec_info,<br>
+                              &tes_prog_data.base.base, &tes_map);<br>
+      if (tcs_nir == NULL || tes_nir == NULL)<br>
+         return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
+<br>
+      nir_lower_tes_patch_vertices(<wbr>tes_nir,<br>
+                                   tcs_nir->info->tess.tcs_<wbr>vertices_out);<br>
+<br>
+      /* Copy TCS info into the TES info */<br>
+      merge_tess_info(tes_nir->info, tcs_nir->info);<br>
+<br>
+      anv_fill_binding_table(&tcs_<wbr>prog_data.base.base, 0);<br>
+      anv_fill_binding_table(&tes_<wbr>prog_data.base.base, 0);<br>
+<br>
+      void *mem_ctx = ralloc_context(NULL);<br>
+<br>
+      ralloc_steal(mem_ctx, tcs_nir);<br>
+      ralloc_steal(mem_ctx, tes_nir);<br>
+<br>
+      /* Whacking the key after cache lookup is a bit sketchy, but all of<br>
+       * this comes from the SPIR-V, which is part of the hash used for the<br>
+       * pipeline cache.  So it should be safe.<br>
+       */<br>
+      tcs_key.tes_primitive_mode = tes_nir->info->tess.primitive_<wbr>mode;<br>
+      tcs_key.outputs_written = tcs_nir->info->outputs_<wbr>written;<br>
+      tcs_key.patch_outputs_written = tcs_nir->info->patch_outputs_<wbr>written;<br>
+      tcs_key.quads_workaround =<br>
+         devinfo->gen < 9 &&<br>
+         tes_nir->info->tess.primitive_<wbr>mode == 7 /* GL_QUADS */ &&<br>
+         tes_nir->info->tess.spacing == TESS_SPACING_EQUAL;<br>
+<br>
+      tes_key.inputs_read = tcs_key.outputs_written;<br>
+      tes_key.patch_inputs_read = tcs_key.patch_outputs_written;<br>
+<br>
+      unsigned code_size;<br>
+      const int shader_time_index = -1;<br>
+      const unsigned *shader_code;<br>
+<br>
+      shader_code =<br>
+         brw_compile_tcs(compiler, NULL, mem_ctx, &tcs_key, &tcs_prog_data,<br>
+                         tcs_nir, shader_time_index, &code_size, NULL);<br>
+      if (shader_code == NULL) {<br>
+         ralloc_free(mem_ctx);<br>
+         return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
+      }<br>
+<br>
+      tcs_bin = anv_pipeline_upload_kernel(<wbr>pipeline, cache, tcs_sha1, 20,<br>
+                                           shader_code, code_size,<br>
+                                           &tcs_prog_data.base.base,<br>
+                                           sizeof(tcs_prog_data),<br>
+                                           &tcs_map);<br>
+      if (!tcs_bin) {<br>
+         ralloc_free(mem_ctx);<br>
+         return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
+      }<br>
+<br>
+      shader_code =<br>
+         brw_compile_tes(compiler, NULL, mem_ctx, &tes_key,<br>
+                         &tcs_prog_data.base.vue_map, &tes_prog_data, tes_nir,<br>
+                         NULL, shader_time_index, &code_size, NULL);<br>
+      if (shader_code == NULL) {<br>
+         ralloc_free(mem_ctx);<br>
+         return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
+      }<br>
+<br>
+      tes_bin = anv_pipeline_upload_kernel(<wbr>pipeline, cache, tes_sha1, 20,<br>
+                                           shader_code, code_size,<br>
+                                           &tes_prog_data.base.base,<br>
+                                           sizeof(tes_prog_data),<br>
+                                           &tes_map);<br>
+      if (!tes_bin) {<br>
+         ralloc_free(mem_ctx);<br>
+         return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
+      }<br>
+<br>
+      ralloc_free(mem_ctx);<br>
+   }<br>
+<br>
+   anv_pipeline_add_compiled_<wbr>stage(pipeline, MESA_SHADER_TESS_CTRL, tcs_bin);<br>
+   anv_pipeline_add_compiled_<wbr>stage(pipeline, MESA_SHADER_TESS_EVAL, tes_bin);<br>
+<br>
+   return VK_SUCCESS;<br>
+}<br>
+<br>
 static VkResult<br>
 anv_pipeline_compile_gs(struct anv_pipeline *pipeline,<br>
                         struct anv_pipeline_cache *cache,<br>
@@ -1032,8 +1210,15 @@ anv_pipeline_init(struct anv_pipeline *pipeline,<br>
          goto compile_fail;<br>
    }<br>
<br>
-   if (modules[MESA_SHADER_TESS_<wbr>CTRL] || modules[MESA_SHADER_TESS_EVAL]<wbr>)<br>
-      anv_finishme("no tessellation support");<br>
+   if (modules[MESA_SHADER_TESS_<wbr>EVAL]) {<br>
+      anv_pipeline_compile_tcs_tes(<wbr>pipeline, cache, pCreateInfo,<br>
+                                   modules[MESA_SHADER_TESS_CTRL]<wbr>,<br>
+                                   pStages[MESA_SHADER_TESS_CTRL]<wbr>->pName,<br>
+                                   pStages[MESA_SHADER_TESS_CTRL]<wbr>->pSpecializationInfo,<br>
+                                   modules[MESA_SHADER_TESS_EVAL]<wbr>,<br>
+                                   pStages[MESA_SHADER_TESS_EVAL]<wbr>->pName,<br>
+                                   pStages[MESA_SHADER_TESS_EVAL]<wbr>->pSpecializationInfo);<br>
+   }<br>
<br>
    if (modules[MESA_SHADER_GEOMETRY]<wbr>) {<br>
       result = anv_pipeline_compile_gs(<wbr>pipeline, cache, pCreateInfo,<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>