Mesa (main): microsoft/compiler: Fix dxil_nir_create_bare_samplers()

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 1 08:09:03 UTC 2021


Module: Mesa
Branch: main
Commit: 83280b8e23e721cb39f66a4d7cad4fd2d7143045
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=83280b8e23e721cb39f66a4d7cad4fd2d7143045

Author: Boris Brezillon <boris.brezillon at collabora.com>
Date:   Mon Nov 22 07:31:00 2021 -0800

microsoft/compiler: Fix dxil_nir_create_bare_samplers()

_mesa_hash_table_u64_search() returns the data directly, not an
hash_entry object. We also need to take the descriptor set into account
for this pass to work properly on Vulkan shaders.

Fixes: 46bc7cf6783 ("microsoft/compiler: Rewrite sampler splitting pass to be smarter and handle derefs")
Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13912>

---

 src/microsoft/compiler/dxil_nir.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/src/microsoft/compiler/dxil_nir.c b/src/microsoft/compiler/dxil_nir.c
index 2d50ec2e34e..88cfdb08a8c 100644
--- a/src/microsoft/compiler/dxil_nir.c
+++ b/src/microsoft/compiler/dxil_nir.c
@@ -1385,10 +1385,10 @@ redirect_sampler_derefs(struct nir_builder *b, nir_instr *instr, void *data)
    int sampler_idx = nir_tex_instr_src_index(tex, nir_tex_src_sampler_deref);
    if (sampler_idx == -1) {
       /* No derefs, must be using indices */
-      struct hash_entry *hash_entry = _mesa_hash_table_u64_search(data, tex->sampler_index);
+      nir_variable *bare_sampler = _mesa_hash_table_u64_search(data, tex->sampler_index);
 
       /* Already have a bare sampler here */
-      if (hash_entry)
+      if (bare_sampler)
          return false;
 
       nir_variable *old_sampler = NULL;
@@ -1411,7 +1411,6 @@ redirect_sampler_derefs(struct nir_builder *b, nir_instr *instr, void *data)
       }
 
       assert(old_sampler);
-      nir_variable *bare_sampler = NULL;
 
       /* If it is already bare, we just need to fix the shadow information */
       if (glsl_type_is_bare_sampler(glsl_without_array(old_sampler->type)))
@@ -1442,11 +1441,10 @@ redirect_sampler_derefs(struct nir_builder *b, nir_instr *instr, void *data)
       return false;
    }
 
-   struct hash_entry *hash_entry = _mesa_hash_table_u64_search(data, old_var->data.binding);
-   nir_variable *new_var;
-   if (hash_entry) {
-      new_var = hash_entry->data;
-   } else {
+   uint64_t var_key = ((uint64_t)old_var->data.descriptor_set << 32) |
+                      old_var->data.binding;
+   nir_variable *new_var = _mesa_hash_table_u64_search(data, var_key);
+   if (!new_var) {
       if (glsl_type_is_bare_sampler(glsl_without_array(old_var->type)))
          new_var = old_var;
       else {
@@ -1455,7 +1453,7 @@ redirect_sampler_derefs(struct nir_builder *b, nir_instr *instr, void *data)
       }
       new_var->type = 
          get_bare_samplers_for_type(old_var->type, tex->is_shadow);
-      _mesa_hash_table_u64_insert(data, old_var->data.binding, new_var);
+      _mesa_hash_table_u64_insert(data, var_key, new_var);
    }
 
    b->cursor = nir_after_instr(&old_tail->instr);
@@ -1485,10 +1483,10 @@ redirect_texture_derefs(struct nir_builder *b, nir_instr *instr, void *data)
    int texture_idx = nir_tex_instr_src_index(tex, nir_tex_src_texture_deref);
    if (texture_idx == -1) {
       /* No derefs, must be using indices */
-      struct hash_entry *hash_entry = _mesa_hash_table_u64_search(data, tex->texture_index);
+      nir_variable *bare_sampler = _mesa_hash_table_u64_search(data, tex->texture_index);
 
       /* Already have a texture here */
-      if (hash_entry)
+      if (bare_sampler)
          return false;
 
       nir_variable *typed_sampler = NULL;
@@ -1509,7 +1507,7 @@ redirect_texture_derefs(struct nir_builder *b, nir_instr *instr, void *data)
 
       /* Clone the typed sampler to a texture and we're done */
       assert(typed_sampler);
-      nir_variable *bare_sampler = nir_variable_clone(typed_sampler, b->shader);
+      bare_sampler = nir_variable_clone(typed_sampler, b->shader);
       bare_sampler->type = get_textures_for_sampler_type(typed_sampler->type);
       nir_shader_add_variable(b->shader, bare_sampler);
       _mesa_hash_table_u64_insert(data, tex->texture_index, bare_sampler);
@@ -1529,15 +1527,14 @@ redirect_texture_derefs(struct nir_builder *b, nir_instr *instr, void *data)
       return false;
    }
 
-   struct hash_entry *hash_entry = _mesa_hash_table_u64_search(data, old_var->data.binding);
-   nir_variable *new_var;
-   if (hash_entry) {
-      new_var = hash_entry->data;
-   } else {
+   uint64_t var_key = ((uint64_t)old_var->data.descriptor_set << 32) |
+                      old_var->data.binding;
+   nir_variable *new_var = _mesa_hash_table_u64_search(data, var_key);
+   if (!new_var) {
       new_var = nir_variable_clone(old_var, b->shader);
       new_var->type = get_textures_for_sampler_type(old_var->type);
       nir_shader_add_variable(b->shader, new_var);
-      _mesa_hash_table_u64_insert(data, old_var->data.binding, new_var);
+      _mesa_hash_table_u64_insert(data, var_key, new_var);
    }
 
    b->cursor = nir_after_instr(&old_tail->instr);



More information about the mesa-commit mailing list