diff options
author | Dave Airlie <[email protected]> | 2017-04-18 05:15:46 +1000 |
---|---|---|
committer | Dave Airlie <[email protected]> | 2017-04-19 09:00:42 +1000 |
commit | 31174069d2f0bbf016f3a581f4703b8c3417d0f0 (patch) | |
tree | 1e4d9fa346005de3ec734888bbe2f2c673d1ccad /src/amd/common | |
parent | 224cf2906a8f38ce47411afc93a223ac0e41795f (diff) |
radv: start conditionalising vertex inputs. (v2)
In practice this will probably just drop draw id in a few places.
v2: just do draw_id for now. (Bas)
it might be possible to do something more if we need it in the
future. (nha)
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 | 26 | ||||
-rw-r--r-- | src/amd/common/ac_shader_info.c | 21 | ||||
-rw-r--r-- | src/amd/common/ac_shader_info.h | 4 |
3 files changed, 43 insertions, 8 deletions
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index dbb3b67b511..31b772f5669 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -614,10 +614,12 @@ static void create_function(struct nir_to_llvm_context *ctx) break; case MESA_SHADER_VERTEX: if (!ctx->is_gs_copy_shader) { - arg_types[arg_idx++] = const_array(ctx->v16i8, 16); /* vertex buffers */ + if (ctx->shader_info->info.vs.has_vertex_buffers) + arg_types[arg_idx++] = const_array(ctx->v16i8, 16); /* vertex buffers */ arg_types[arg_idx++] = ctx->i32; // base vertex arg_types[arg_idx++] = ctx->i32; // start instance - arg_types[arg_idx++] = ctx->i32; // draw index + if (ctx->shader_info->info.vs.needs_draw_id) + arg_types[arg_idx++] = ctx->i32; // draw index } user_sgpr_count = arg_idx; if (ctx->options->key.vs.as_es) @@ -773,14 +775,22 @@ static void create_function(struct nir_to_llvm_context *ctx) break; case MESA_SHADER_VERTEX: if (!ctx->is_gs_copy_shader) { - set_userdata_location_shader(ctx, AC_UD_VS_VERTEX_BUFFERS, user_sgpr_idx, 2); - user_sgpr_idx += 2; - ctx->vertex_buffers = LLVMGetParam(ctx->main_function, arg_idx++); - set_userdata_location_shader(ctx, AC_UD_VS_BASE_VERTEX_START_INSTANCE, user_sgpr_idx, 3); - user_sgpr_idx += 3; + if (ctx->shader_info->info.vs.has_vertex_buffers) { + set_userdata_location_shader(ctx, AC_UD_VS_VERTEX_BUFFERS, user_sgpr_idx, 2); + user_sgpr_idx += 2; + ctx->vertex_buffers = LLVMGetParam(ctx->main_function, arg_idx++); + } + unsigned vs_num = 2; + if (ctx->shader_info->info.vs.needs_draw_id) + vs_num++; + + set_userdata_location_shader(ctx, AC_UD_VS_BASE_VERTEX_START_INSTANCE, user_sgpr_idx, vs_num); + user_sgpr_idx += vs_num; + ctx->base_vertex = LLVMGetParam(ctx->main_function, arg_idx++); ctx->start_instance = LLVMGetParam(ctx->main_function, arg_idx++); - ctx->draw_index = LLVMGetParam(ctx->main_function, arg_idx++); + if (ctx->shader_info->info.vs.needs_draw_id) + ctx->draw_index = LLVMGetParam(ctx->main_function, arg_idx++); } if (ctx->options->key.vs.as_es) ctx->es2gs_offset = LLVMGetParam(ctx->main_function, arg_idx++); diff --git a/src/amd/common/ac_shader_info.c b/src/amd/common/ac_shader_info.c index 85252fea146..6ad562505cf 100644 --- a/src/amd/common/ac_shader_info.c +++ b/src/amd/common/ac_shader_info.c @@ -30,6 +30,9 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, struct ac_shader_info *info) case nir_intrinsic_interp_var_at_sample: info->ps.needs_sample_positions = true; break; + case nir_intrinsic_load_draw_id: + info->vs.needs_draw_id = true; + break; default: break; } @@ -49,12 +52,30 @@ gather_info_block(nir_block *block, struct ac_shader_info *info) } } +static void +gather_info_input_decl(nir_shader *nir, + const struct ac_nir_compiler_options *options, + nir_variable *var, + struct ac_shader_info *info) +{ + switch (nir->stage) { + case MESA_SHADER_VERTEX: + info->vs.has_vertex_buffers = true; + break; + default: + break; + } +} + void ac_nir_shader_info_pass(struct nir_shader *nir, const struct ac_nir_compiler_options *options, struct ac_shader_info *info) { struct nir_function *func = (struct nir_function *)exec_list_get_head(&nir->functions); + nir_foreach_variable(variable, &nir->inputs) + gather_info_input_decl(nir, options, variable, info); + nir_foreach_block(block, func->impl) { gather_info_block(block, info); } diff --git a/src/amd/common/ac_shader_info.h b/src/amd/common/ac_shader_info.h index 5576c3b4bac..7e2b6c885a6 100644 --- a/src/amd/common/ac_shader_info.h +++ b/src/amd/common/ac_shader_info.h @@ -29,6 +29,10 @@ struct ac_nir_compiler_options; struct ac_shader_info { struct { + bool has_vertex_buffers; /* needs vertex buffers and base/start */ + bool needs_draw_id; + } vs; + struct { bool needs_sample_positions; } ps; }; |