Mesa (main): iris: Extract allocation bits from iris_upload_shader to iris_create_shader_variant

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jul 28 18:00:25 UTC 2021


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jun  2 11:18:35 2021 -0700

iris: Extract allocation bits from iris_upload_shader to iris_create_shader_variant

The added assertion in iris_create_shader_variant helped catch a bug in
the next commit.

v2: Drop (unnecessary) initialization of shader->assembly.res when
moving to iris_create_shader_variant.  Suggested by Ken.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11229>

---

 src/gallium/drivers/iris/iris_context.h       |  7 ++++
 src/gallium/drivers/iris/iris_program_cache.c | 47 ++++++++++++++++++++++-----
 2 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/iris/iris_context.h b/src/gallium/drivers/iris/iris_context.h
index f8691421676..05d85ec9a51 100644
--- a/src/gallium/drivers/iris/iris_context.h
+++ b/src/gallium/drivers/iris/iris_context.h
@@ -940,6 +940,13 @@ struct iris_compiled_shader *iris_find_cached_shader(struct iris_context *ice,
                                                      enum iris_program_cache_id,
                                                      uint32_t key_size,
                                                      const void *key);
+
+struct iris_compiled_shader *iris_create_shader_variant(const struct iris_screen *,
+                                                        void *mem_ctx,
+                                                        enum iris_program_cache_id cache_id,
+                                                        uint32_t key_size,
+                                                        const void *key);
+
 struct iris_compiled_shader *iris_upload_shader(struct iris_screen *screen,
                                                 struct iris_uncompiled_shader *,
                                                 struct hash_table *driver_ht,
diff --git a/src/gallium/drivers/iris/iris_program_cache.c b/src/gallium/drivers/iris/iris_program_cache.c
index 254cc2709fb..4fdee1ea5d6 100644
--- a/src/gallium/drivers/iris/iris_program_cache.c
+++ b/src/gallium/drivers/iris/iris_program_cache.c
@@ -106,6 +106,43 @@ iris_delete_shader_variant(struct iris_compiled_shader *shader)
    ralloc_free(shader);
 }
 
+struct iris_compiled_shader *
+iris_create_shader_variant(const struct iris_screen *screen,
+                           void *mem_ctx,
+                           enum iris_program_cache_id cache_id,
+                           uint32_t key_size,
+                           const void *key)
+{
+#ifndef NDEBUG
+   if (cache_id == IRIS_CACHE_BLORP) {
+      /* Blorp shader must have a mem_ctx. */
+      assert(mem_ctx != NULL);
+   } else if (cache_id == IRIS_CACHE_TCS) {
+      /* Pass-through tessellation control shaders (generated by the driver)
+       * will have a mem_ctx, and other tessellation control shaders will not.
+       */
+   } else {
+      /* Shaders that are neither blorp nor tessellation control must not have
+       * a mem_ctx.
+       */
+      assert(mem_ctx == NULL);
+   }
+#endif
+
+   struct iris_compiled_shader *shader =
+      rzalloc_size(mem_ctx, sizeof(struct iris_compiled_shader) +
+                   screen->vtbl.derived_program_state_size(cache_id));
+
+   pipe_reference_init(&shader->ref, 1);
+
+   if (cache_id != IRIS_CACHE_BLORP) {
+      assert(key_size <= sizeof(union iris_any_prog_key));
+      memcpy(&shader->key, key, key_size);
+   }
+
+   return shader;
+}
+
 struct iris_compiled_shader *
 iris_upload_shader(struct iris_screen *screen,
                    struct iris_uncompiled_shader *ish,
@@ -126,13 +163,10 @@ iris_upload_shader(struct iris_screen *screen,
    const struct intel_device_info *devinfo = &screen->devinfo;
 
    void *mem_ctx = ish ? NULL : (void *) driver_shaders;
-   struct iris_compiled_shader *shader =
-      rzalloc_size(mem_ctx, sizeof(struct iris_compiled_shader) +
-                   screen->vtbl.derived_program_state_size(cache_id));
 
-   pipe_reference_init(&shader->ref, 1);
+   struct iris_compiled_shader *shader =
+      iris_create_shader_variant(screen, mem_ctx, cache_id, key_size, key);
 
-   shader->assembly.res = NULL;
    u_upload_alloc(uploader, 0, prog_data->program_size, 64,
                   &shader->assembly.offset, &shader->assembly.res,
                   &shader->map);
@@ -175,9 +209,6 @@ iris_upload_shader(struct iris_screen *screen,
    screen->vtbl.store_derived_program_state(devinfo, cache_id, shader);
 
    if (ish) {
-      assert(key_size <= sizeof(union iris_any_prog_key));
-      memcpy(&shader->key, key, key_size);
-
       simple_mtx_lock(&ish->lock);
 
       /* While unlikely, it's possible that another thread concurrently



More information about the mesa-commit mailing list