radv, ac/nir: Move sin/cos lowering to a common pass.
authorTimur Kristóf <timur.kristof@gmail.com>
Wed, 29 Mar 2023 17:28:42 +0000 (19:28 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 30 Mar 2023 05:59:13 +0000 (05:59 +0000)
Also ran clang-format on the affected code.

Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21971>

src/amd/common/ac_nir.c
src/amd/common/ac_nir.h
src/amd/vulkan/radv_shader.c

index fe9968a..a28193e 100644 (file)
@@ -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)
index 03cffec..7b1c75b 100644 (file)
@@ -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);
index bc30252..38a345c 100644 (file)
@@ -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);