iris: Drop find_existing_assembly optimization from program cache
authorKenneth Graunke <kenneth@whitecape.org>
Sat, 19 Oct 2019 19:21:17 +0000 (12:21 -0700)
committerMarge Bot <eric+marge@anholt.net>
Fri, 22 Jan 2021 00:20:27 +0000 (00:20 +0000)
This tried to de-duplicate identical copies of the same shader
assembly, but in the least efficient way possible: it did a linear
walk through every shader in the entire context memcmp'ing the
final assembly (after going through the effort to compile it).
In the end, all it saved was space and number of BOs, not even
state changes.

This optimization has been mostly replaced by st/mesa's cache
mechanism, which looks for multiple shaders that compile to the
same NIR and go further than this did, and actually reuse the
same pipe shader state.  That's even more efficient than this.

This seems to still trigger some times, because the NIR that
st/mesa hashes hasn't quite been finalized and stripped.  But
it would be better to improve that, not this.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8634>

src/gallium/drivers/iris/iris_program_cache.c

index 5a07585..b5d1c7a 100644 (file)
@@ -169,27 +169,6 @@ iris_delete_shader_variants(struct iris_context *ice,
 }
 
 
-/**
- * Look for an existing entry in the cache that has identical assembly code.
- *
- * This is useful for programs generating shaders at runtime, where multiple
- * distinct shaders (from an API perspective) may compile to the same assembly
- * in our backend.  This saves space in the program cache buffer.
- */
-static const struct iris_compiled_shader *
-find_existing_assembly(struct hash_table *cache,
-                       const void *assembly,
-                       unsigned assembly_size)
-{
-   hash_table_foreach(cache, entry) {
-      const struct iris_compiled_shader *existing = entry->data;
-      if (existing->prog_data->program_size == assembly_size &&
-          memcmp(existing->map, assembly, assembly_size) == 0)
-         return existing;
-   }
-   return NULL;
-}
-
 struct iris_compiled_shader *
 iris_upload_shader(struct iris_context *ice,
                    enum iris_program_cache_id cache_id,
@@ -209,44 +188,30 @@ iris_upload_shader(struct iris_context *ice,
    struct iris_compiled_shader *shader =
       rzalloc_size(cache, sizeof(struct iris_compiled_shader) +
                    screen->vtbl.derived_program_state_size(cache_id));
-   const struct iris_compiled_shader *existing =
-      find_existing_assembly(cache, assembly, prog_data->program_size);
-
-   /* If we can find a matching prog in the cache already, then reuse the
-    * existing stuff without creating new copy into the underlying buffer
-    * object.  This is notably useful for programs generating shaders at
-    * runtime, where multiple shaders may compile to the same thing in our
-    * backend.
-    */
-   if (existing) {
-      pipe_resource_reference(&shader->assembly.res, existing->assembly.res);
-      shader->assembly.offset = existing->assembly.offset;
-      shader->map = existing->map;
-   } else {
-      shader->assembly.res = NULL;
-      u_upload_alloc(ice->shaders.uploader, 0, prog_data->program_size, 64,
-                     &shader->assembly.offset, &shader->assembly.res,
-                     &shader->map);
-      memcpy(shader->map, assembly, prog_data->program_size);
-
-      struct iris_resource *res = (void *) shader->assembly.res;
-      uint64_t shader_data_addr = res->bo->gtt_offset +
-                                  shader->assembly.offset +
-                                  prog_data->const_data_offset;
-
-      struct brw_shader_reloc_value reloc_values[] = {
-         {
-            .id = IRIS_SHADER_RELOC_CONST_DATA_ADDR_LOW,
-            .value = shader_data_addr,
-         },
-         {
-            .id = IRIS_SHADER_RELOC_CONST_DATA_ADDR_HIGH,
-            .value = shader_data_addr >> 32,
-         },
-      };
-      brw_write_shader_relocs(&screen->devinfo, shader->map, prog_data,
-                              reloc_values, ARRAY_SIZE(reloc_values));
-   }
+
+   shader->assembly.res = NULL;
+   u_upload_alloc(ice->shaders.uploader, 0, prog_data->program_size, 64,
+                  &shader->assembly.offset, &shader->assembly.res,
+                  &shader->map);
+   memcpy(shader->map, assembly, prog_data->program_size);
+
+   struct iris_resource *res = (void *) shader->assembly.res;
+   uint64_t shader_data_addr = res->bo->gtt_offset +
+                               shader->assembly.offset +
+                               prog_data->const_data_offset;
+
+   struct brw_shader_reloc_value reloc_values[] = {
+      {
+         .id = IRIS_SHADER_RELOC_CONST_DATA_ADDR_LOW,
+         .value = shader_data_addr,
+      },
+      {
+         .id = IRIS_SHADER_RELOC_CONST_DATA_ADDR_HIGH,
+         .value = shader_data_addr >> 32,
+      },
+   };
+   brw_write_shader_relocs(&screen->devinfo, shader->map, prog_data,
+                           reloc_values, ARRAY_SIZE(reloc_values));
 
    list_inithead(&shader->link);