[Mesa-dev] [PATCH 4/6] anv: Add support for shader constant data to the pipeline cache

Jason Ekstrand jason at jlekstrand.net
Fri Jun 29 20:06:53 UTC 2018


---
 src/intel/vulkan/anv_blorp.c          |  1 +
 src/intel/vulkan/anv_pipeline.c       | 12 ++++++++++++
 src/intel/vulkan/anv_pipeline_cache.c | 26 ++++++++++++++++++++++++++
 src/intel/vulkan/anv_private.h        |  6 ++++++
 4 files changed, 45 insertions(+)

diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index 5373faaa680..4dbfb7a83fd 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -70,6 +70,7 @@ upload_blorp_shader(struct blorp_context *blorp,
    struct anv_shader_bin *bin =
       anv_pipeline_cache_upload_kernel(&device->blorp_shader_cache,
                                        key, key_size, kernel, kernel_size,
+                                       NULL, 0,
                                        prog_data, prog_data_size, &bind_map);
 
    if (!bin)
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index 67ede46f2ae..8b630f7a85a 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -485,6 +485,8 @@ anv_pipeline_upload_kernel(struct anv_pipeline *pipeline,
                            struct anv_pipeline_cache *cache,
                            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,
                            const struct brw_stage_prog_data *prog_data,
                            uint32_t prog_data_size,
                            const struct anv_pipeline_bind_map *bind_map)
@@ -492,11 +494,13 @@ anv_pipeline_upload_kernel(struct anv_pipeline *pipeline,
    if (cache) {
       return anv_pipeline_cache_upload_kernel(cache, key_data, key_size,
                                               kernel_data, kernel_size,
+                                              constant_data, constant_data_size,
                                               prog_data, prog_data_size,
                                               bind_map);
    } else {
       return anv_shader_bin_create(pipeline->device, key_data, key_size,
                                    kernel_data, kernel_size,
+                                   constant_data, constant_data_size,
                                    prog_data, prog_data_size,
                                    prog_data->param, bind_map);
    }
@@ -575,6 +579,7 @@ anv_pipeline_compile_vs(struct anv_pipeline *pipeline,
       unsigned code_size = prog_data.base.base.program_size;
       bin = anv_pipeline_upload_kernel(pipeline, cache, sha1, 20,
                                        shader_code, code_size,
+                                       nir->constant_data, nir->num_constants,
                                        &prog_data.base.base, sizeof(prog_data),
                                        &map);
       if (!bin) {
@@ -742,6 +747,8 @@ anv_pipeline_compile_tcs_tes(struct anv_pipeline *pipeline,
       tcs_bin = anv_pipeline_upload_kernel(pipeline, cache,
                                            tcs_sha1, sizeof(tcs_sha1),
                                            shader_code, code_size,
+                                           tcs_nir->constant_data,
+                                           tcs_nir->num_constants,
                                            &tcs_prog_data.base.base,
                                            sizeof(tcs_prog_data),
                                            &tcs_map);
@@ -763,6 +770,8 @@ anv_pipeline_compile_tcs_tes(struct anv_pipeline *pipeline,
       tes_bin = anv_pipeline_upload_kernel(pipeline, cache,
                                            tes_sha1, sizeof(tes_sha1),
                                            shader_code, code_size,
+                                           tes_nir->constant_data,
+                                           tes_nir->num_constants,
                                            &tes_prog_data.base.base,
                                            sizeof(tes_prog_data),
                                            &tes_map);
@@ -845,6 +854,7 @@ anv_pipeline_compile_gs(struct anv_pipeline *pipeline,
       const unsigned code_size = prog_data.base.base.program_size;
       bin = anv_pipeline_upload_kernel(pipeline, cache, sha1, 20,
                                        shader_code, code_size,
+                                       nir->constant_data, nir->num_constants,
                                        &prog_data.base.base, sizeof(prog_data),
                                        &map);
       if (!bin) {
@@ -995,6 +1005,7 @@ anv_pipeline_compile_fs(struct anv_pipeline *pipeline,
       unsigned code_size = prog_data.base.program_size;
       bin = anv_pipeline_upload_kernel(pipeline, cache, sha1, 20,
                                        shader_code, code_size,
+                                       nir->constant_data, nir->num_constants,
                                        &prog_data.base, sizeof(prog_data),
                                        &map);
       if (!bin) {
@@ -1071,6 +1082,7 @@ anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
       const unsigned code_size = prog_data.base.program_size;
       bin = anv_pipeline_upload_kernel(pipeline, cache, sha1, 20,
                                        shader_code, code_size,
+                                       nir->constant_data, nir->num_constants,
                                        &prog_data.base, sizeof(prog_data),
                                        &map);
       if (!bin) {
diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c
index 82551e9f81f..aa2e813aef6 100644
--- a/src/intel/vulkan/anv_pipeline_cache.c
+++ b/src/intel/vulkan/anv_pipeline_cache.c
@@ -30,6 +30,7 @@ struct anv_shader_bin *
 anv_shader_bin_create(struct anv_device *device,
                       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,
                       const struct brw_stage_prog_data *prog_data_in,
                       uint32_t prog_data_size, const void *prog_data_param_in,
                       const struct anv_pipeline_bind_map *bind_map)
@@ -65,6 +66,16 @@ anv_shader_bin_create(struct anv_device *device,
    memcpy(shader->kernel.map, kernel_data, kernel_size);
    shader->kernel_size = kernel_size;
 
+   if (constant_data_size) {
+      shader->constant_data =
+         anv_state_pool_alloc(&device->dynamic_state_pool,
+                              constant_data_size, 32);
+      memcpy(shader->constant_data.map, constant_data, constant_data_size);
+   } else {
+      shader->constant_data = ANV_STATE_NULL;
+   }
+   shader->constant_data_size = constant_data_size;
+
    memcpy(prog_data, prog_data_in, prog_data_size);
    memcpy(prog_data_param, prog_data_param_in,
           prog_data->nr_params * sizeof(*prog_data_param));
@@ -104,6 +115,10 @@ anv_shader_bin_write_to_blob(const struct anv_shader_bin *shader,
    ok = blob_write_uint32(blob, shader->kernel_size);
    ok = blob_write_bytes(blob, shader->kernel.map, shader->kernel_size);
 
+   ok = blob_write_uint32(blob, shader->constant_data_size);
+   ok = blob_write_bytes(blob, shader->constant_data.map,
+                         shader->constant_data_size);
+
    ok = blob_write_uint32(blob, shader->prog_data_size);
    ok = blob_write_bytes(blob, shader->prog_data, shader->prog_data_size);
    ok = blob_write_bytes(blob, shader->prog_data->param,
@@ -133,6 +148,9 @@ anv_shader_bin_create_from_blob(struct anv_device *device,
    uint32_t kernel_size = blob_read_uint32(blob);
    const void *kernel_data = blob_read_bytes(blob, kernel_size);
 
+   uint32_t constant_data_size = blob_read_uint32(blob);
+   const void *constant_data = blob_read_bytes(blob, constant_data_size);
+
    uint32_t prog_data_size = blob_read_uint32(blob);
    const struct brw_stage_prog_data *prog_data =
       blob_read_bytes(blob, prog_data_size);
@@ -158,6 +176,7 @@ anv_shader_bin_create_from_blob(struct anv_device *device,
    return anv_shader_bin_create(device,
                                 key_data, key_size,
                                 kernel_data, kernel_size,
+                                constant_data, constant_data_size,
                                 prog_data, prog_data_size, prog_data_param,
                                 &bind_map);
 }
@@ -264,6 +283,8 @@ static struct anv_shader_bin *
 anv_pipeline_cache_add_shader(struct anv_pipeline_cache *cache,
                               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,
                               const struct brw_stage_prog_data *prog_data,
                               uint32_t prog_data_size,
                               const void *prog_data_param,
@@ -277,6 +298,7 @@ anv_pipeline_cache_add_shader(struct anv_pipeline_cache *cache,
    struct anv_shader_bin *bin =
       anv_shader_bin_create(cache->device, key_data, key_size,
                             kernel_data, kernel_size,
+                            constant_data, constant_data_size,
                             prog_data, prog_data_size, prog_data_param,
                             bind_map);
    if (!bin)
@@ -291,6 +313,8 @@ struct anv_shader_bin *
 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
                                  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,
                                  const struct brw_stage_prog_data *prog_data,
                                  uint32_t prog_data_size,
                                  const struct anv_pipeline_bind_map *bind_map)
@@ -301,6 +325,7 @@ anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
       struct anv_shader_bin *bin =
          anv_pipeline_cache_add_shader(cache, key_data, key_size,
                                        kernel_data, kernel_size,
+                                       constant_data, constant_data_size,
                                        prog_data, prog_data_size,
                                        prog_data->param, bind_map);
 
@@ -315,6 +340,7 @@ anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
       /* 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,
                                    kernel_data, kernel_size,
+                                   constant_data, constant_data_size,
                                    prog_data, prog_data_size,
                                    prog_data->param, bind_map);
    }
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 510471da602..f82b88df7a0 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -930,6 +930,8 @@ struct anv_shader_bin *
 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
                                  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,
                                  const struct brw_stage_prog_data *prog_data,
                                  uint32_t prog_data_size,
                                  const struct anv_pipeline_bind_map *bind_map);
@@ -2300,6 +2302,9 @@ struct anv_shader_bin {
    struct anv_state kernel;
    uint32_t kernel_size;
 
+   struct anv_state constant_data;
+   uint32_t constant_data_size;
+
    const struct brw_stage_prog_data *prog_data;
    uint32_t prog_data_size;
 
@@ -2310,6 +2315,7 @@ struct anv_shader_bin *
 anv_shader_bin_create(struct anv_device *device,
                       const void *key, uint32_t key_size,
                       const void *kernel, uint32_t kernel_size,
+                      const void *constant_data, uint32_t constant_data_size,
                       const struct brw_stage_prog_data *prog_data,
                       uint32_t prog_data_size, const void *prog_data_param,
                       const struct anv_pipeline_bind_map *bind_map);
-- 
2.17.1



More information about the mesa-dev mailing list