iris: Remove context from iris_upload_shader()
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 9 Feb 2021 02:01:31 +0000 (18:01 -0800)
committerMarge Bot <eric+marge@anholt.net>
Thu, 11 Feb 2021 20:51:18 +0000 (20:51 +0000)
Shaders are now shared across contexts, so we'd like to avoid requiring
access to a full context.  Instead, we pass the screen and an uploader
to use.

Fixes: 84a38ec1336 ("iris: Enable PIPE_CAP_SHAREABLE_SHADERS.")
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8922>

src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_disk_cache.c
src/gallium/drivers/iris/iris_program.c
src/gallium/drivers/iris/iris_program_cache.c

index c93b053..591454d 100644 (file)
@@ -919,8 +919,10 @@ 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_upload_shader(struct iris_context *ice,
+struct iris_compiled_shader *iris_upload_shader(struct iris_screen *screen,
                                                 struct iris_uncompiled_shader *,
+                                                struct hash_table *driver_ht,
+                                                struct u_upload_mgr *uploader,
                                                 enum iris_program_cache_id,
                                                 uint32_t key_size,
                                                 const void *key,
index cbf5e7e..d5b415d 100644 (file)
@@ -149,6 +149,7 @@ iris_disk_cache_retrieve(struct iris_context *ice,
 {
 #ifdef ENABLE_SHADER_CACHE
    struct iris_screen *screen = (void *) ice->ctx.screen;
+   struct u_upload_mgr *uploader = ice->shaders.uploader;
    struct disk_cache *cache = screen->disk_cache;
    gl_shader_stage stage = ish->nir->info.stage;
 
@@ -245,7 +246,8 @@ iris_disk_cache_retrieve(struct iris_context *ice,
     * return it to the caller.
     */
    struct iris_compiled_shader *shader =
-      iris_upload_shader(ice, ish, cache_id, key_size, prog_key, assembly,
+      iris_upload_shader(screen, ish, NULL, uploader,
+                         cache_id, key_size, prog_key, assembly,
                          prog_data, so_decls, system_values,
                          num_system_values, kernel_input_size, num_cbufs, &bt);
 
index 57fc9c8..10c39aa 100644 (file)
@@ -1216,7 +1216,8 @@ iris_compile_vs(struct iris_context *ice,
                                     &vue_prog_data->vue_map);
 
    struct iris_compiled_shader *shader =
-      iris_upload_shader(ice, ish, IRIS_CACHE_VS, sizeof(*key), key, program,
+      iris_upload_shader(screen, ish, NULL, ice->shaders.uploader,
+                         IRIS_CACHE_VS, sizeof(*key), key, program,
                          prog_data, so_decls, system_values, num_system_values,
                          0, num_cbufs, &bt);
 
@@ -1400,7 +1401,8 @@ iris_compile_tcs(struct iris_context *ice,
    iris_debug_recompile(screen, &ice->dbg, ish, &brw_key.base);
 
    struct iris_compiled_shader *shader =
-      iris_upload_shader(ice, ish, IRIS_CACHE_TCS, sizeof(*key), key, program,
+      iris_upload_shader(screen, ish, ice->shaders.cache, ice->shaders.uploader,
+                         IRIS_CACHE_TCS, sizeof(*key), key, program,
                          prog_data, NULL, system_values, num_system_values,
                          0, num_cbufs, &bt);
 
@@ -1530,7 +1532,8 @@ iris_compile_tes(struct iris_context *ice,
 
 
    struct iris_compiled_shader *shader =
-      iris_upload_shader(ice, ish, IRIS_CACHE_TES, sizeof(*key), key, program,
+      iris_upload_shader(screen, ish, NULL, ice->shaders.uploader,
+                         IRIS_CACHE_TES, sizeof(*key), key, program,
                          prog_data, so_decls, system_values, num_system_values,
                          0, num_cbufs, &bt);
 
@@ -1651,7 +1654,8 @@ iris_compile_gs(struct iris_context *ice,
                                     &vue_prog_data->vue_map);
 
    struct iris_compiled_shader *shader =
-      iris_upload_shader(ice, ish, IRIS_CACHE_GS, sizeof(*key), key, program,
+      iris_upload_shader(screen, ish, NULL, ice->shaders.uploader,
+                         IRIS_CACHE_GS, sizeof(*key), key, program,
                          prog_data, so_decls, system_values, num_system_values,
                          0, num_cbufs, &bt);
 
@@ -1766,7 +1770,8 @@ iris_compile_fs(struct iris_context *ice,
    iris_debug_recompile(screen, &ice->dbg, ish, &brw_key.base);
 
    struct iris_compiled_shader *shader =
-      iris_upload_shader(ice, ish, IRIS_CACHE_FS, sizeof(*key), key, program,
+      iris_upload_shader(screen, ish, NULL, ice->shaders.uploader,
+                         IRIS_CACHE_FS, sizeof(*key), key, program,
                          prog_data, NULL, system_values, num_system_values,
                          0, num_cbufs, &bt);
 
@@ -2018,7 +2023,8 @@ iris_compile_cs(struct iris_context *ice,
    iris_debug_recompile(screen, &ice->dbg, ish, &brw_key.base);
 
    struct iris_compiled_shader *shader =
-      iris_upload_shader(ice, ish, IRIS_CACHE_CS, sizeof(*key), key, program,
+      iris_upload_shader(screen, ish, NULL, ice->shaders.uploader,
+                         IRIS_CACHE_CS, sizeof(*key), key, program,
                          prog_data, NULL, system_values, num_system_values,
                          ish->kernel_input_size, num_cbufs, &bt);
 
index 4184596..de7fe4d 100644 (file)
@@ -107,8 +107,10 @@ iris_delete_shader_variant(struct iris_compiled_shader *shader)
 }
 
 struct iris_compiled_shader *
-iris_upload_shader(struct iris_context *ice,
+iris_upload_shader(struct iris_screen *screen,
                    struct iris_uncompiled_shader *ish,
+                   struct hash_table *driver_shaders,
+                   struct u_upload_mgr *uploader,
                    enum iris_program_cache_id cache_id,
                    uint32_t key_size,
                    const void *key,
@@ -121,10 +123,9 @@ iris_upload_shader(struct iris_context *ice,
                    unsigned num_cbufs,
                    const struct iris_binding_table *bt)
 {
-   struct hash_table *cache = ice->shaders.cache;
-   void *mem_ctx = ish ? NULL : (void *) cache;
-   struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
    const struct gen_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));
@@ -132,7 +133,7 @@ iris_upload_shader(struct iris_context *ice,
    pipe_reference_init(&shader->ref, 1);
 
    shader->assembly.res = NULL;
-   u_upload_alloc(ice->shaders.uploader, 0, prog_data->program_size, 64,
+   u_upload_alloc(uploader, 0, prog_data->program_size, 64,
                   &shader->assembly.offset, &shader->assembly.res,
                   &shader->map);
    memcpy(shader->map, assembly, prog_data->program_size);
@@ -198,7 +199,7 @@ iris_upload_shader(struct iris_context *ice,
       simple_mtx_unlock(&ish->lock);
    } else {
       struct keybox *keybox = make_keybox(shader, cache_id, key, key_size);
-      _mesa_hash_table_insert(ice->shaders.cache, keybox, shader);
+      _mesa_hash_table_insert(driver_shaders, keybox, shader);
    }
 
    return shader;
@@ -239,6 +240,7 @@ iris_blorp_upload_shader(struct blorp_batch *blorp_batch, uint32_t stage,
    struct blorp_context *blorp = blorp_batch->blorp;
    struct iris_context *ice = blorp->driver_ctx;
    struct iris_batch *batch = blorp_batch->driver_batch;
+   struct iris_screen *screen = batch->screen;
 
    void *prog_data = ralloc_size(NULL, prog_data_size);
    memcpy(prog_data, prog_data_templ, prog_data_size);
@@ -247,7 +249,9 @@ iris_blorp_upload_shader(struct blorp_batch *blorp_batch, uint32_t stage,
    memset(&bt, 0, sizeof(bt));
 
    struct iris_compiled_shader *shader =
-      iris_upload_shader(ice, NULL, IRIS_CACHE_BLORP, key_size, key, kernel,
+      iris_upload_shader(screen, NULL, ice->shaders.cache,
+                         ice->shaders.uploader,
+                         IRIS_CACHE_BLORP, key_size, key, kernel,
                          prog_data, NULL, NULL, 0, 0, 0, &bt);
 
    struct iris_bo *bo = iris_resource_bo(shader->assembly.res);