<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">I had a few nits below.  With those fixed,</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></div><div class="gmail_quote"><br></div><div class="gmail_quote">On Thu, Jan 25, 2018 at 4:24 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">The Vulkan spec states that VkPipelineLayout objects must not be<br>
destroyed while any command buffer that uses them is in the recording<br>
state, but it permits them to be destroyed otherwise. This means that<br>
applications are allowed to free pipeline layouts after command recording<br>
is finished even if there are pipeline objects that still exist and were<br>
created with these layouts.<br>
<br>
There are two solutions to this, one is to use reference counting on<br>
pipeline layout objects. The other is to avoid holding references to<br>
pipeline layouts where they are not really needed.<br>
<br>
This patch takes a step towards the second option by making the<br>
pipeline shader compile code take pipeline layout from the<br>
VkGraphicsPipelineCreateInfo provided rather than the pipeline<br>
object.<br>
<br>
A follow-up patch will remove any remaining uses of the layout field<br>
so we can remove it from the pipeline object and avoid the need<br>
for reference counting.<br>
<br>
Suggested-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
---<br>
 src/intel/vulkan/anv_nir.h                       |  3 +-<br>
 src/intel/vulkan/anv_nir_<wbr>apply_pipeline_layout.c |  2 +-<br>
 src/intel/vulkan/anv_nir_<wbr>lower_ycbcr_textures.c  |  9 ++--<br>
 src/intel/vulkan/anv_pipeline.<wbr>c                  | 54 ++++++++++++++++--------<br>
 4 files changed, 44 insertions(+), 24 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_nir.h b/src/intel/vulkan/anv_nir.h<br>
index 8ac0a119dac..ce95b40b014 100644<br>
--- a/src/intel/vulkan/anv_nir.h<br>
+++ b/src/intel/vulkan/anv_nir.h<br>
@@ -38,9 +38,10 @@ void anv_nir_lower_push_constants(<wbr>nir_shader *shader);<br>
 bool anv_nir_lower_multiview(nir_<wbr>shader *shader, uint32_t view_mask);<br>
<br>
 bool anv_nir_lower_ycbcr_textures(<wbr>nir_shader *shader,<br>
-                                  struct anv_pipeline *pipeline);<br>
+                                  struct anv_pipeline_layout *layout);<br>
<br>
 void anv_nir_apply_pipeline_layout(<wbr>struct anv_pipeline *pipeline,<br>
+                                   struct anv_pipeline_layout *layout,<br>
                                    nir_shader *shader,<br>
                                    struct brw_stage_prog_data *prog_data,<br>
                                    struct anv_pipeline_bind_map *map);<br>
diff --git a/src/intel/vulkan/anv_nir_<wbr>apply_pipeline_layout.c b/src/intel/vulkan/anv_nir_<wbr>apply_pipeline_layout.c<br>
index 6775f9b464e..acabc5426be 100644<br>
--- a/src/intel/vulkan/anv_nir_<wbr>apply_pipeline_layout.c<br>
+++ b/src/intel/vulkan/anv_nir_<wbr>apply_pipeline_layout.c<br>
@@ -326,11 +326,11 @@ setup_vec4_uniform_value(<wbr>uint32_t *params, uint32_t offset, unsigned n)<br>
<br>
 void<br>
 anv_nir_apply_pipeline_layout(<wbr>struct anv_pipeline *pipeline,<br>
+                              struct anv_pipeline_layout *layout,<br>
                               nir_shader *shader,<br>
                               struct brw_stage_prog_data *prog_data,<br>
                               struct anv_pipeline_bind_map *map)<br>
 {<br>
-   struct anv_pipeline_layout *layout = pipeline->layout;<br>
    gl_shader_stage stage = shader->info.stage;<br>
<br>
    struct apply_pipeline_layout_state state = {<br>
diff --git a/src/intel/vulkan/anv_nir_<wbr>lower_ycbcr_textures.c b/src/intel/vulkan/anv_nir_<wbr>lower_ycbcr_textures.c<br>
index 028f24e2f60..ad793ee0a0c 100644<br>
--- a/src/intel/vulkan/anv_nir_<wbr>lower_ycbcr_textures.c<br>
+++ b/src/intel/vulkan/anv_nir_<wbr>lower_ycbcr_textures.c<br>
@@ -316,13 +316,13 @@ swizzle_channel(struct isl_swizzle swizzle, unsigned channel)<br>
 }<br>
<br>
 static bool<br>
-try_lower_tex_ycbcr(struct anv_pipeline *pipeline,<br>
+try_lower_tex_ycbcr(struct anv_pipeline_layout *layout,<br>
                     nir_builder *builder,<br>
                     nir_tex_instr *tex)<br>
 {<br>
    nir_variable *var = tex->texture->var;<br>
    const struct anv_descriptor_set_layout *set_layout =<br>
-      pipeline->layout->set[var-><wbr>data.descriptor_set].layout;<br>
+      layout->set[var->data.<wbr>descriptor_set].layout;<br>
    const struct anv_descriptor_set_binding_<wbr>layout *binding =<br>
       &set_layout->binding[var-><wbr>data.binding];<br>
<br>
@@ -440,7 +440,8 @@ try_lower_tex_ycbcr(struct anv_pipeline *pipeline,<br>
 }<br>
<br>
 bool<br>
-anv_nir_lower_ycbcr_textures(<wbr>nir_shader *shader, struct anv_pipeline *pipeline)<br>
+anv_nir_lower_ycbcr_textures(<wbr>nir_shader *shader,<br>
+                             struct anv_pipeline_layout *layout)<br>
 {<br>
    bool progress = false;<br>
<br>
@@ -458,7 +459,7 @@ anv_nir_lower_ycbcr_textures(<wbr>nir_shader *shader, struct anv_pipeline *pipeline)<br>
                continue;<br>
<br>
             nir_tex_instr *tex = nir_instr_as_tex(instr);<br>
-            function_progress |= try_lower_tex_ycbcr(pipeline, &builder, tex);<br>
+            function_progress |= try_lower_tex_ycbcr(layout, &builder, tex);<br>
          }<br>
       }<br>
<br>
diff --git a/src/intel/vulkan/anv_<wbr>pipeline.c b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
index 4e66f8665fa..4dc18096af5 100644<br>
--- a/src/intel/vulkan/anv_<wbr>pipeline.c<br>
+++ b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
@@ -349,6 +349,7 @@ populate_cs_prog_key(const struct gen_device_info *devinfo,<br>
<br>
 static void<br>
 anv_pipeline_hash_shader(<wbr>struct anv_pipeline *pipeline,<br>
+                         struct anv_pipeline_layout *layout,<br>
                          struct anv_shader_module *module,<br>
                          const char *entrypoint,<br>
                          gl_shader_stage stage,<br>
@@ -363,9 +364,8 @@ anv_pipeline_hash_shader(<wbr>struct anv_pipeline *pipeline,<br>
       _mesa_sha1_update(&ctx, &pipeline->subpass->view_mask,<br>
                         sizeof(pipeline->subpass-><wbr>view_mask));<br>
    }<br>
-   if (pipeline->layout) {<br>
-      _mesa_sha1_update(&ctx, pipeline->layout->sha1,<br>
-                        sizeof(pipeline->layout->sha1)<wbr>);<br>
+   if (layout) {<br>
+      _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));<br>
    }<br></blockquote><div><br></div><div>Now that it's one line, we can drop the braces.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));<br>
    _mesa_sha1_update(&ctx, entrypoint, strlen(entrypoint));<br>
@@ -382,6 +382,7 @@ anv_pipeline_hash_shader(<wbr>struct anv_pipeline *pipeline,<br>
 static nir_shader *<br>
 anv_pipeline_compile(struct anv_pipeline *pipeline,<br>
                      void *mem_ctx,<br>
+                     struct anv_pipeline_layout *layout,<br>
                      struct anv_shader_module *module,<br>
                      const char *entrypoint,<br>
                      gl_shader_stage stage,<br>
@@ -398,7 +399,7 @@ anv_pipeline_compile(struct anv_pipeline *pipeline,<br>
    if (nir == NULL)<br>
       return NULL;<br>
<br>
-   NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, pipeline);<br>
+   NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, layout);<br>
<br>
    NIR_PASS_V(nir, anv_nir_lower_push_constants);<br>
<br>
@@ -438,8 +439,8 @@ anv_pipeline_compile(struct anv_pipeline *pipeline,<br>
       pipeline->needs_data_cache = true;<br>
<br>
    /* Apply the actual pipeline layout to UBOs, SSBOs, and textures */<br>
-   if (pipeline->layout)<br>
-      anv_nir_apply_pipeline_layout(<wbr>pipeline, nir, prog_data, map);<br>
+   if (layout)<br>
+      anv_nir_apply_pipeline_layout(<wbr>pipeline, layout, nir, prog_data, map);<br>
<br>
    if (stage != MESA_SHADER_COMPUTE)<br>
       brw_nir_analyze_ubo_ranges(<wbr>compiler, nir, prog_data->ubo_ranges);<br>
@@ -508,8 +509,11 @@ anv_pipeline_compile_vs(struct anv_pipeline *pipeline,<br>
<br>
    populate_vs_prog_key(&<wbr>pipeline->device->info, &key);<br>
<br>
+   struct anv_pipeline_layout *layout =<br>
+      anv_pipeline_layout_from_<wbr>handle(info->layout);<br></blockquote><div><br></div><div>ANV_FROM_HANDLE<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
    if (cache) {<br>
-      anv_pipeline_hash_shader(<wbr>pipeline, module, entrypoint,<br>
+      anv_pipeline_hash_shader(<wbr>pipeline, layout, module, entrypoint,<br>
                                MESA_SHADER_VERTEX, spec_info,<br>
                                &key, sizeof(key), sha1);<br>
       bin = anv_pipeline_cache_search(<wbr>cache, sha1, 20);<br>
@@ -527,7 +531,7 @@ anv_pipeline_compile_vs(struct anv_pipeline *pipeline,<br>
<br>
       void *mem_ctx = ralloc_context(NULL);<br>
<br>
-      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx,<br>
+      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, layout,<br>
                                              module, entrypoint,<br>
                                              MESA_SHADER_VERTEX, spec_info,<br>
                                              &prog_data.base.base, &map);<br>
@@ -633,11 +637,14 @@ anv_pipeline_compile_tcs_tes(<wbr>struct anv_pipeline *pipeline,<br>
    populate_sampler_prog_key(&<wbr>pipeline->device->info, &tes_key.tex);<br>
    tcs_key.input_vertices = info->pTessellationState-><wbr>patchControlPoints;<br>
<br>
+   struct anv_pipeline_layout *layout =<br>
+      anv_pipeline_layout_from_<wbr>handle(info->layout);<br></blockquote><div><br></div><div>ANV_FROM_HANDLE<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
    if (cache) {<br>
-      anv_pipeline_hash_shader(<wbr>pipeline, tcs_module, tcs_entrypoint,<br>
+      anv_pipeline_hash_shader(<wbr>pipeline, layout, tcs_module, tcs_entrypoint,<br>
                                MESA_SHADER_TESS_CTRL, tcs_spec_info,<br>
                                &tcs_key, sizeof(tcs_key), tcs_sha1);<br>
-      anv_pipeline_hash_shader(<wbr>pipeline, tes_module, tes_entrypoint,<br>
+      anv_pipeline_hash_shader(<wbr>pipeline, layout, tes_module, tes_entrypoint,<br>
                                MESA_SHADER_TESS_EVAL, tes_spec_info,<br>
                                &tes_key, sizeof(tes_key), tes_sha1);<br>
       memcpy(&tcs_sha1[20], tes_sha1, 20);<br>
@@ -666,11 +673,13 @@ anv_pipeline_compile_tcs_tes(<wbr>struct anv_pipeline *pipeline,<br>
       void *mem_ctx = ralloc_context(NULL);<br>
<br>
       nir_shader *tcs_nir =<br>
-         anv_pipeline_compile(pipeline, mem_ctx, tcs_module, tcs_entrypoint,<br>
+         anv_pipeline_compile(pipeline, mem_ctx, layout,<br>
+                              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, mem_ctx, tes_module, tes_entrypoint,<br>
+         anv_pipeline_compile(pipeline, mem_ctx, layout,<br>
+                              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>
@@ -771,8 +780,11 @@ anv_pipeline_compile_gs(struct anv_pipeline *pipeline,<br>
<br>
    populate_gs_prog_key(&<wbr>pipeline->device->info, &key);<br>
<br>
+   struct anv_pipeline_layout *layout =<br>
+      anv_pipeline_layout_from_<wbr>handle(info->layout);<br></blockquote><div><br></div><div>ANV_FROM_HANDLE<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
    if (cache) {<br>
-      anv_pipeline_hash_shader(<wbr>pipeline, module, entrypoint,<br>
+      anv_pipeline_hash_shader(<wbr>pipeline, layout, module, entrypoint,<br>
                                MESA_SHADER_GEOMETRY, spec_info,<br>
                                &key, sizeof(key), sha1);<br>
       bin = anv_pipeline_cache_search(<wbr>cache, sha1, 20);<br>
@@ -790,7 +802,7 @@ anv_pipeline_compile_gs(struct anv_pipeline *pipeline,<br>
<br>
       void *mem_ctx = ralloc_context(NULL);<br>
<br>
-      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx,<br>
+      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, layout,<br>
                                              module, entrypoint,<br>
                                              MESA_SHADER_GEOMETRY, spec_info,<br>
                                              &prog_data.base.base, &map);<br>
@@ -849,8 +861,11 @@ anv_pipeline_compile_fs(struct anv_pipeline *pipeline,<br>
<br>
    populate_wm_prog_key(pipeline, info, &key);<br>
<br>
+   struct anv_pipeline_layout *layout =<br>
+      anv_pipeline_layout_from_<wbr>handle(info->layout);<br></blockquote><div><br></div><div>ANV_FROM_HANDLE<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
    if (cache) {<br>
-      anv_pipeline_hash_shader(<wbr>pipeline, module, entrypoint,<br>
+      anv_pipeline_hash_shader(<wbr>pipeline, layout, module, entrypoint,<br>
                                MESA_SHADER_FRAGMENT, spec_info,<br>
                                &key, sizeof(key), sha1);<br>
       bin = anv_pipeline_cache_search(<wbr>cache, sha1, 20);<br>
@@ -868,7 +883,7 @@ anv_pipeline_compile_fs(struct anv_pipeline *pipeline,<br>
<br>
       void *mem_ctx = ralloc_context(NULL);<br>
<br>
-      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx,<br>
+      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, layout,<br>
                                              module, entrypoint,<br>
                                              MESA_SHADER_FRAGMENT, spec_info,<br>
                                              &prog_data.base, &map);<br>
@@ -997,8 +1012,11 @@ anv_pipeline_compile_cs(struct anv_pipeline *pipeline,<br>
<br>
    populate_cs_prog_key(&<wbr>pipeline->device->info, &key);<br>
<br>
+   struct anv_pipeline_layout *layout =<br>
+      anv_pipeline_layout_from_<wbr>handle(info->layout);<br></blockquote><div><br></div><div>ANV_FROM_HANDLE<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
    if (cache) {<br>
-      anv_pipeline_hash_shader(<wbr>pipeline, module, entrypoint,<br>
+      anv_pipeline_hash_shader(<wbr>pipeline, layout, module, entrypoint,<br>
                                MESA_SHADER_COMPUTE, spec_info,<br>
                                &key, sizeof(key), sha1);<br>
       bin = anv_pipeline_cache_search(<wbr>cache, sha1, 20);<br>
@@ -1016,7 +1034,7 @@ anv_pipeline_compile_cs(struct anv_pipeline *pipeline,<br>
<br>
       void *mem_ctx = ralloc_context(NULL);<br>
<br>
-      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx,<br>
+      nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, layout,<br>
                                              module, entrypoint,<br>
                                              MESA_SHADER_COMPUTE, spec_info,<br>
                                              &prog_data.base, &map);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.14.1<br>
<br>
</font></span></blockquote></div><br></div></div>