[Mesa-dev] [PATCH v2 7/9] anv: Add support for shader constant data to the pipeline cache

Jason Ekstrand jason at jlekstrand.net
Sat Jun 30 00:13:55 UTC 2018


---
 src/intel/vulkan/anv_blorp.c          |  1 +
 src/intel/vulkan/anv_pipeline.c       | 16 ++++++++++++++++
 src/intel/vulkan/anv_pipeline_cache.c | 27 +++++++++++++++++++++++++++
 src/intel/vulkan/anv_private.h        |  6 ++++++
 4 files changed, 50 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..dc3b4a0e3ba 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,8 @@ 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->constant_data_size,
                                        &prog_data.base.base, sizeof(prog_data),
                                        &map);
       if (!bin) {
@@ -742,6 +748,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->constant_data_size,
                                            &tcs_prog_data.base.base,
                                            sizeof(tcs_prog_data),
                                            &tcs_map);
@@ -763,6 +771,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->constant_data_size,
                                            &tes_prog_data.base.base,
                                            sizeof(tes_prog_data),
                                            &tes_map);
@@ -845,6 +855,8 @@ 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->constant_data_size,
                                        &prog_data.base.base, sizeof(prog_data),
                                        &map);
       if (!bin) {
@@ -995,6 +1007,8 @@ 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->constant_data_size,
                                        &prog_data.base, sizeof(prog_data),
                                        &map);
       if (!bin) {
@@ -1071,6 +1085,8 @@ 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->constant_data_size,
                                        &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..07b745b9c7a 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));
@@ -89,6 +100,7 @@ anv_shader_bin_destroy(struct anv_device *device,
 {
    assert(shader->ref_cnt == 0);
    anv_state_pool_free(&device->instruction_state_pool, shader->kernel);
+   anv_state_pool_free(&device->dynamic_state_pool, shader->constant_data);
    vk_free(&device->alloc, shader);
 }
 
@@ -104,6 +116,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 +149,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 +177,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 +284,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 +299,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 +314,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 +326,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 +341,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