From 93e438243863f540bf8cd883f8ba58e2702e6002 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timur=20Krist=C3=B3f?= Date: Wed, 29 Mar 2023 19:28:42 +0200 Subject: [PATCH] radv, ac/nir: Move sin/cos lowering to a common pass. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also ran clang-format on the affected code. Signed-off-by: Timur Kristóf Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/common/ac_nir.c | 21 +++++++++++++++++++++ src/amd/common/ac_nir.h | 2 ++ src/amd/vulkan/radv_shader.c | 17 +---------------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/amd/common/ac_nir.c b/src/amd/common/ac_nir.c index fe9968a..a28193e 100644 --- a/src/amd/common/ac_nir.c +++ b/src/amd/common/ac_nir.c @@ -45,6 +45,27 @@ ac_nir_unpack_arg(nir_builder *b, const struct ac_shader_args *ac_args, struct a return nir_ubfe_imm(b, value, rshift, bitwidth); } +static bool +is_sin_cos(const nir_instr *instr, UNUSED const void *_) +{ + return instr->type == nir_instr_type_alu && (nir_instr_as_alu(instr)->op == nir_op_fsin || + nir_instr_as_alu(instr)->op == nir_op_fcos); +} + +static nir_ssa_def * +lower_sin_cos(struct nir_builder *b, nir_instr *instr, UNUSED void *_) +{ + nir_alu_instr *sincos = nir_instr_as_alu(instr); + nir_ssa_def *src = nir_fmul_imm(b, nir_ssa_for_alu_src(b, sincos, 0), 0.15915493667125702); + return sincos->op == nir_op_fsin ? nir_fsin_amd(b, src) : nir_fcos_amd(b, src); +} + +bool +ac_nir_lower_sin_cos(nir_shader *shader) +{ + return nir_shader_lower_instructions(shader, is_sin_cos, lower_sin_cos, NULL); +} + void ac_nir_store_var_components(nir_builder *b, nir_variable *var, nir_ssa_def *value, unsigned component, unsigned writemask) diff --git a/src/amd/common/ac_nir.h b/src/amd/common/ac_nir.h index 03cffec..7b1c75b 100644 --- a/src/amd/common/ac_nir.h +++ b/src/amd/common/ac_nir.h @@ -73,6 +73,8 @@ nir_ssa_def * ac_nir_unpack_arg(nir_builder *b, const struct ac_shader_args *ac_args, struct ac_arg arg, unsigned rshift, unsigned bitwidth); +bool ac_nir_lower_sin_cos(nir_shader *shader); + void ac_nir_store_var_components(nir_builder *b, nir_variable *var, nir_ssa_def *value, unsigned component, unsigned writemask); diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index bc30252..38a345c 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -329,21 +329,6 @@ radv_compiler_debug(void *private_data, enum aco_compiler_debug_level level, con } static bool -is_sincos(const nir_instr *instr, const void *_) -{ - return instr->type == nir_instr_type_alu && - (nir_instr_as_alu(instr)->op == nir_op_fsin || nir_instr_as_alu(instr)->op == nir_op_fcos); -} - -static nir_ssa_def * -lower_sincos(struct nir_builder *b, nir_instr *instr, void *_) -{ - nir_alu_instr *sincos = nir_instr_as_alu(instr); - nir_ssa_def *src = nir_fmul_imm(b, nir_ssa_for_alu_src(b, sincos, 0), 0.15915493667125702); - return sincos->op == nir_op_fsin ? nir_fsin_amd(b, src) : nir_fcos_amd(b, src); -} - -static bool is_not_xfb_output(nir_variable *var, void *data) { if (var->data.mode != nir_var_shader_out) @@ -573,7 +558,7 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_pipeline_ NIR_PASS(_, nir, nir_lower_doubles, NULL, lower_doubles); - NIR_PASS(_, nir, nir_shader_lower_instructions, &is_sincos, &lower_sincos, NULL); + NIR_PASS(_, nir, ac_nir_lower_sin_cos); } NIR_PASS(_, nir, nir_lower_system_values); -- 2.7.4