anv: Add support for shader constant data to the pipeline cache
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 29 Jun 2018 05:41:21 +0000 (22:41 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 2 Jul 2018 19:09:47 +0000 (12:09 -0700)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
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 5373faaa680dfa22321cd7069c942b9a692a2822..4dbfb7a83fdafb441c0ae2d8105a8382ef9c1f21 100644 (file)
@@ -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)
index 67ede46f2ae63908462e7ff4259b445be2b04db2..dc3b4a0e3baab61a75a67d9dfcda9e38210ac887 100644 (file)
@@ -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) {
index 82551e9f81f293ecadbec7d2a52ca6dfc10a75eb..07b745b9c7abd9e46a3e98f457055b1353b265c1 100644 (file)
@@ -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);
    }
index 510471da6026d3c3bc856520a608bd1f61684693..f82b88df7a016f8eedf30da2f23f1c625838de27 100644 (file)
@@ -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);