radv: improve gathering of load_push_constants with dynamic bindings
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 22 Jan 2019 18:30:20 +0000 (19:30 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 23 Jan 2019 08:43:53 +0000 (09:43 +0100)
For example, if a pipeline has two stages VS and FS. And if only
the fragment stage needs dynamic bindings, we shouldn't allocate
an extra user SGPR for the vertex stage. Of course, if the vertex
stage loads constants, it needs an user SGPR.

This should reduce the number of SET_SH_REG packets that are emitted.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_descriptor_set.c
src/amd/vulkan/radv_descriptor_set.h
src/amd/vulkan/radv_shader_info.c

index 526bb77a553021d781e7836db211cdff743298f7..30f982252bbea08af1223e5c96b74f05e8c53270 100644 (file)
@@ -345,6 +345,7 @@ VkResult radv_CreatePipelineLayout(
        layout->num_sets = pCreateInfo->setLayoutCount;
 
        unsigned dynamic_offset_count = 0;
+       uint16_t dynamic_shader_stages = 0;
 
 
        _mesa_sha1_init(&ctx);
@@ -356,6 +357,7 @@ VkResult radv_CreatePipelineLayout(
                layout->set[set].dynamic_offset_start = dynamic_offset_count;
                for (uint32_t b = 0; b < set_layout->binding_count; b++) {
                        dynamic_offset_count += set_layout->binding[b].array_size * set_layout->binding[b].dynamic_offset_count;
+                       dynamic_shader_stages |= set_layout->dynamic_shader_stages;
                        if (set_layout->binding[b].immutable_samplers_offset)
                                _mesa_sha1_update(&ctx, radv_immutable_samplers(set_layout, set_layout->binding + b),
                                                  set_layout->binding[b].array_size * 4 * sizeof(uint32_t));
@@ -365,6 +367,7 @@ VkResult radv_CreatePipelineLayout(
        }
 
        layout->dynamic_offset_count = dynamic_offset_count;
+       layout->dynamic_shader_stages = dynamic_shader_stages;
        layout->push_constant_size = 0;
 
        for (unsigned i = 0; i < pCreateInfo->pushConstantRangeCount; ++i) {
index d8431241fd917c11420864e72f30f77a152b1759..7b13c6fb621c17ad76aee9db1cdeb36aadfaef24 100644 (file)
@@ -85,6 +85,7 @@ struct radv_pipeline_layout {
    uint32_t num_sets;
    uint32_t push_constant_size;
    uint32_t dynamic_offset_count;
+   uint16_t dynamic_shader_stages;
 
    unsigned char sha1[20];
 };
index c2e005e63dd6a79c16567c0fab0647f13b742741..7e5a3789af2b0619942e31d0e22b12cee0e15e83 100644 (file)
@@ -512,8 +512,10 @@ radv_nir_shader_info_pass(const struct nir_shader *nir,
        struct nir_function *func =
                (struct nir_function *)exec_list_get_head_const(&nir->functions);
 
-       if (options->layout && options->layout->dynamic_offset_count)
+       if (options->layout && options->layout->dynamic_offset_count &&
+           (options->layout->dynamic_shader_stages & mesa_to_vk_shader_stage(nir->info.stage))) {
                info->loads_push_constants = true;
+       }
 
        nir_foreach_variable(variable, &nir->inputs)
                gather_info_input_decl(nir, variable, info);