anv: Keep the shader stage in anv_shader_bin
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Tue, 3 Mar 2020 20:10:00 +0000 (12:10 -0800)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Thu, 12 Mar 2020 20:18:54 +0000 (13:18 -0700)
This will be used to decouple the logic flush_descriptor_sets() from
the position in the shader array, allowing us to store just the
shaders needed for each pipeline.

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

src/intel/vulkan/anv_blorp.c
src/intel/vulkan/anv_pipeline.c
src/intel/vulkan/anv_pipeline_cache.c
src/intel/vulkan/anv_private.h

index c2fed12aa1dd7860b1c944f4b085974db7273aa6..1d61b7fc4d55897e9712e141650915f995285e24 100644 (file)
@@ -69,8 +69,14 @@ upload_blorp_shader(struct blorp_batch *batch,
       .sampler_count = 0,
    };
 
+   /* The stage in anv_shader_bin is only useful for pipeline shaders, so just pass
+    * a dummy value here so we don't need to change BLORP API.
+    *
+    * TODO: Plumb the stage information to BLORP.
+    */
+   gl_shader_stage stage = MESA_SHADER_NONE;
    struct anv_shader_bin *bin =
-      anv_pipeline_cache_upload_kernel(&device->default_pipeline_cache,
+      anv_pipeline_cache_upload_kernel(&device->default_pipeline_cache, stage,
                                        key, key_size, kernel, kernel_size,
                                        NULL, 0,
                                        prog_data, prog_data_size,
index 9f14fb88f821d7b2727cd0e570f13af41ab743ee..1161e6fa9e03a5a23a216da3027ec48715e545c7 100644 (file)
@@ -1360,7 +1360,7 @@ anv_pipeline_compile_graphics(struct anv_pipeline *pipeline,
                                    &stages[s].bind_map);
 
       struct anv_shader_bin *bin =
-         anv_device_upload_kernel(pipeline->device, cache,
+         anv_device_upload_kernel(pipeline->device, cache, s,
                                   &stages[s].cache_key,
                                   sizeof(stages[s].cache_key),
                                   stages[s].code,
@@ -1547,6 +1547,7 @@ anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
 
       const unsigned code_size = stage.prog_data.base.program_size;
       bin = anv_device_upload_kernel(pipeline->device, cache,
+                                     MESA_SHADER_COMPUTE,
                                      &stage.cache_key, sizeof(stage.cache_key),
                                      stage.code, code_size,
                                      stage.nir->constant_data,
index 4992bf2948f24acf821409a434848d32c1937583..69865951e1cfd4ece0e131e5fa0c230490f9e886 100644 (file)
@@ -32,6 +32,7 @@
 
 struct anv_shader_bin *
 anv_shader_bin_create(struct anv_device *device,
+                      gl_shader_stage stage,
                       const void *key_data, uint32_t key_size,
                       const void *kernel_data, uint32_t kernel_size,
                       const void *constant_data, uint32_t constant_data_size,
@@ -68,6 +69,8 @@ anv_shader_bin_create(struct anv_device *device,
 
    shader->ref_cnt = 1;
 
+   shader->stage = stage;
+
    key->size = key_size;
    memcpy(key->data, key_data, key_size);
    shader->key = key;
@@ -132,6 +135,8 @@ static bool
 anv_shader_bin_write_to_blob(const struct anv_shader_bin *shader,
                              struct blob *blob)
 {
+   blob_write_uint32(blob, shader->stage);
+
    blob_write_uint32(blob, shader->key->size);
    blob_write_bytes(blob, shader->key->data, shader->key->size);
 
@@ -182,6 +187,8 @@ static struct anv_shader_bin *
 anv_shader_bin_create_from_blob(struct anv_device *device,
                                 struct blob_reader *blob)
 {
+   gl_shader_stage stage = blob_read_uint32(blob);
+
    uint32_t key_size = blob_read_uint32(blob);
    const void *key_data = blob_read_bytes(blob, key_size);
 
@@ -223,7 +230,7 @@ anv_shader_bin_create_from_blob(struct anv_device *device,
    if (blob->overrun)
       return NULL;
 
-   return anv_shader_bin_create(device,
+   return anv_shader_bin_create(device, stage,
                                 key_data, key_size,
                                 kernel_data, kernel_size,
                                 constant_data, constant_data_size,
@@ -371,6 +378,7 @@ anv_pipeline_cache_add_shader_bin(struct anv_pipeline_cache *cache,
 
 static struct anv_shader_bin *
 anv_pipeline_cache_add_shader_locked(struct anv_pipeline_cache *cache,
+                                     gl_shader_stage stage,
                                      const void *key_data, uint32_t key_size,
                                      const void *kernel_data,
                                      uint32_t kernel_size,
@@ -389,7 +397,8 @@ anv_pipeline_cache_add_shader_locked(struct anv_pipeline_cache *cache,
       return shader;
 
    struct anv_shader_bin *bin =
-      anv_shader_bin_create(cache->device, key_data, key_size,
+      anv_shader_bin_create(cache->device, stage,
+                            key_data, key_size,
                             kernel_data, kernel_size,
                             constant_data, constant_data_size,
                             prog_data, prog_data_size,
@@ -404,6 +413,7 @@ anv_pipeline_cache_add_shader_locked(struct anv_pipeline_cache *cache,
 
 struct anv_shader_bin *
 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
+                                 gl_shader_stage stage,
                                  const void *key_data, uint32_t key_size,
                                  const void *kernel_data, uint32_t kernel_size,
                                  const void *constant_data,
@@ -419,7 +429,7 @@ anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
       pthread_mutex_lock(&cache->mutex);
 
       struct anv_shader_bin *bin =
-         anv_pipeline_cache_add_shader_locked(cache, key_data, key_size,
+         anv_pipeline_cache_add_shader_locked(cache, stage, key_data, key_size,
                                               kernel_data, kernel_size,
                                               constant_data, constant_data_size,
                                               prog_data, prog_data_size,
@@ -435,7 +445,8 @@ anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
       return bin;
    } else {
       /* In this case, we're not caching it so the caller owns it entirely */
-      return anv_shader_bin_create(cache->device, key_data, key_size,
+      return anv_shader_bin_create(cache->device, stage,
+                                   key_data, key_size,
                                    kernel_data, kernel_size,
                                    constant_data, constant_data_size,
                                    prog_data, prog_data_size,
@@ -675,6 +686,7 @@ anv_device_search_for_kernel(struct anv_device *device,
 struct anv_shader_bin *
 anv_device_upload_kernel(struct anv_device *device,
                          struct anv_pipeline_cache *cache,
+                         gl_shader_stage stage,
                          const void *key_data, uint32_t key_size,
                          const void *kernel_data, uint32_t kernel_size,
                          const void *constant_data,
@@ -688,14 +700,14 @@ anv_device_upload_kernel(struct anv_device *device,
 {
    struct anv_shader_bin *bin;
    if (cache) {
-      bin = anv_pipeline_cache_upload_kernel(cache, key_data, key_size,
+      bin = anv_pipeline_cache_upload_kernel(cache, stage, key_data, key_size,
                                              kernel_data, kernel_size,
                                              constant_data, constant_data_size,
                                              prog_data, prog_data_size,
                                              stats, num_stats,
                                              xfb_info, bind_map);
    } else {
-      bin = anv_shader_bin_create(device, key_data, key_size,
+      bin = anv_shader_bin_create(device, stage, key_data, key_size,
                                   kernel_data, kernel_size,
                                   constant_data, constant_data_size,
                                   prog_data, prog_data_size,
index 3607b7d4fcd80f29722b1701fa3c5e875bd1a620..14a2fe33049fbd7190ad3d35d989c98cc4a1c75e 100644 (file)
@@ -1210,6 +1210,7 @@ anv_pipeline_cache_search(struct anv_pipeline_cache *cache,
                           const void *key, uint32_t key_size);
 struct anv_shader_bin *
 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
+                                 gl_shader_stage stage,
                                  const void *key_data, uint32_t key_size,
                                  const void *kernel_data, uint32_t kernel_size,
                                  const void *constant_data,
@@ -1230,6 +1231,7 @@ anv_device_search_for_kernel(struct anv_device *device,
 struct anv_shader_bin *
 anv_device_upload_kernel(struct anv_device *device,
                          struct anv_pipeline_cache *cache,
+                         gl_shader_stage stage,
                          const void *key_data, uint32_t key_size,
                          const void *kernel_data, uint32_t kernel_size,
                          const void *constant_data,
@@ -3097,6 +3099,8 @@ struct anv_shader_bin_key {
 struct anv_shader_bin {
    uint32_t ref_cnt;
 
+   gl_shader_stage stage;
+
    const struct anv_shader_bin_key *key;
 
    struct anv_state kernel;
@@ -3118,6 +3122,7 @@ struct anv_shader_bin {
 
 struct anv_shader_bin *
 anv_shader_bin_create(struct anv_device *device,
+                      gl_shader_stage stage,
                       const void *key, uint32_t key_size,
                       const void *kernel, uint32_t kernel_size,
                       const void *constant_data, uint32_t constant_data_size,