diff options
author | Dave Airlie <[email protected]> | 2017-04-18 10:21:59 +1000 |
---|---|---|
committer | Dave Airlie <[email protected]> | 2017-04-19 09:00:43 +1000 |
commit | 25a5ee391d786b6d0b48b2b9aa0553e6972d97a0 (patch) | |
tree | ef9eb964cbe1f7768e0d8d52fe44234e2dabffbd /src/amd/common | |
parent | d0991b135b90b5ce90da51b6d4db7302ddd65a24 (diff) |
radv/ac: add support for indirect access of descriptor sets.
We want to expose more descriptor sets to the applications,
but currently we have a 1:1 mapping between shader descriptor
sets and 2 user sgprs, limiting us to 4 per stage. This commit
check if we don't have enough user sgprs for the number of
bound sets for this shader, we can ask for them to be indirected.
Two sgprs are then used to point to a buffer or 64-bit pointers
to the number of allocated descriptor sets. All shaders point
to the same buffer.
We can use some user sgprs to inline one or two descriptor sets
in future, but until we have a workload that needs this I don't
think we should spend too much time on it.
Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src/amd/common')
-rw-r--r-- | src/amd/common/ac_nir_to_llvm.c | 52 | ||||
-rw-r--r-- | src/amd/common/ac_nir_to_llvm.h | 5 |
2 files changed, 41 insertions, 16 deletions
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index 31c3a6c2240..540de62d594 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -537,7 +537,7 @@ static void set_userdata_location_shader(struct nir_to_llvm_context *ctx, set_userdata_location(&ctx->shader_info->user_sgprs_locs.shader_data[idx], sgpr_idx, num_sgprs); } -#if 0 + static void set_userdata_location_indirect(struct ac_userdata_info *ud_info, uint8_t sgpr_idx, uint8_t num_sgprs, uint32_t indirect_offset) { @@ -546,7 +546,6 @@ static void set_userdata_location_indirect(struct ac_userdata_info *ud_info, uin ud_info->indirect = true; ud_info->indirect_offset = indirect_offset; } -#endif static void declare_tess_lds(struct nir_to_llvm_context *ctx) { @@ -559,6 +558,7 @@ static void declare_tess_lds(struct nir_to_llvm_context *ctx) struct user_sgpr_info { bool need_ring_offsets; uint8_t sgpr_count; + bool indirect_all_descriptor_sets; }; static void allocate_user_sgprs(struct nir_to_llvm_context *ctx, @@ -623,6 +623,8 @@ static void allocate_user_sgprs(struct nir_to_llvm_context *ctx, fprintf(stderr, "radv: TODO: add support for indirect sgprs\n"); /* need to add support for indirect descriptor sets */ assert(0); + user_sgpr_info->sgpr_count += 2; + user_sgpr_info->indirect_all_descriptor_sets = true; } else { user_sgpr_info->sgpr_count += util_bitcount(ctx->shader_info->info.desc_set_used_mask) * 2; } @@ -645,11 +647,16 @@ static void create_function(struct nir_to_llvm_context *ctx) } /* 1 for each descriptor set */ - for (unsigned i = 0; i < num_sets; ++i) { - if (ctx->options->layout->set[i].layout->shader_stages & (1 << ctx->stage)) { - array_params_mask |= (1 << arg_idx); - arg_types[arg_idx++] = const_array(ctx->i8, 1024 * 1024); + if (!user_sgpr_info.indirect_all_descriptor_sets) { + for (unsigned i = 0; i < num_sets; ++i) { + if (ctx->options->layout->set[i].layout->shader_stages & (1 << ctx->stage)) { + array_params_mask |= (1 << arg_idx); + arg_types[arg_idx++] = const_array(ctx->i8, 1024 * 1024); + } } + } else { + array_params_mask |= (1 << arg_idx); + arg_types[arg_idx++] = const_array(const_array(ctx->i8, 1024 * 1024), 32); } if (ctx->shader_info->info.needs_push_constants) { @@ -801,14 +808,31 @@ static void create_function(struct nir_to_llvm_context *ctx) ctx->ring_offsets = LLVMGetParam(ctx->main_function, arg_idx++); } - for (unsigned i = 0; i < num_sets; ++i) { - if (ctx->options->layout->set[i].layout->shader_stages & (1 << ctx->stage)) { - set_userdata_location(&ctx->shader_info->user_sgprs_locs.descriptor_sets[i], user_sgpr_idx, 2); - user_sgpr_idx += 2; - ctx->descriptor_sets[i] = - LLVMGetParam(ctx->main_function, arg_idx++); - } else - ctx->descriptor_sets[i] = NULL; + if (!user_sgpr_info.indirect_all_descriptor_sets) { + for (unsigned i = 0; i < num_sets; ++i) { + if (ctx->options->layout->set[i].layout->shader_stages & (1 << ctx->stage)) { + set_userdata_location(&ctx->shader_info->user_sgprs_locs.descriptor_sets[i], user_sgpr_idx, 2); + user_sgpr_idx += 2; + ctx->descriptor_sets[i] = + LLVMGetParam(ctx->main_function, arg_idx++); + } else + ctx->descriptor_sets[i] = NULL; + } + } else { + uint32_t desc_sgpr_idx = user_sgpr_idx; + LLVMValueRef desc_sets = LLVMGetParam(ctx->main_function, arg_idx++); + set_userdata_location_shader(ctx, AC_UD_INDIRECT_DESCRIPTOR_SETS, user_sgpr_idx, 2); + user_sgpr_idx += 2; + + for (unsigned i = 0; i < num_sets; ++i) { + if (ctx->options->layout->set[i].layout->shader_stages & (1 << ctx->stage)) { + set_userdata_location_indirect(&ctx->shader_info->user_sgprs_locs.descriptor_sets[i], desc_sgpr_idx, 2, i * 8); + ctx->descriptor_sets[i] = ac_build_indexed_load_const(&ctx->ac, desc_sets, LLVMConstInt(ctx->i32, i, false)); + + } else + ctx->descriptor_sets[i] = NULL; + } + ctx->shader_info->need_indirect_descriptor_sets = true; } if (ctx->shader_info->info.needs_push_constants) { diff --git a/src/amd/common/ac_nir_to_llvm.h b/src/amd/common/ac_nir_to_llvm.h index 7a4065ac5fa..401d284a7c4 100644 --- a/src/amd/common/ac_nir_to_llvm.h +++ b/src/amd/common/ac_nir_to_llvm.h @@ -83,7 +83,8 @@ struct ac_userdata_info { enum ac_ud_index { AC_UD_SCRATCH_RING_OFFSETS = 0, AC_UD_PUSH_CONSTANTS = 1, - AC_UD_SHADER_START = 2, + AC_UD_INDIRECT_DESCRIPTOR_SETS = 2, + AC_UD_SHADER_START = 3, AC_UD_VS_VERTEX_BUFFERS = AC_UD_SHADER_START, AC_UD_VS_BASE_VERTEX_START_INSTANCE, AC_UD_VS_LS_TCS_IN_LAYOUT, @@ -142,7 +143,7 @@ struct ac_shader_variant_info { unsigned num_user_sgprs; unsigned num_input_sgprs; unsigned num_input_vgprs; - + bool need_indirect_descriptor_sets; union { struct { struct ac_vs_output_info outinfo; |