nir: allow specifying a set of opcodes in lower_alu_to_scalar
[mesa.git] / src / amd / vulkan / radv_shader.c
index eecbc6ae7599afe848bebafc5fa903522a379b53..17d6c5bc33adeff28116e7354b0fbdfb08368129 100644 (file)
@@ -53,6 +53,7 @@
 static const struct nir_shader_compiler_options nir_options = {
        .vertex_id_zero_based = true,
        .lower_scmp = true,
+       .lower_flrp16 = true,
        .lower_flrp32 = true,
        .lower_flrp64 = true,
        .lower_device_index_to_zero = true,
@@ -123,6 +124,10 @@ radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively,
                   bool allow_copies)
 {
         bool progress;
+        unsigned lower_flrp =
+                (shader->options->lower_flrp16 ? 16 : 0) |
+                (shader->options->lower_flrp32 ? 32 : 0) |
+                (shader->options->lower_flrp64 ? 64 : 0);
 
         do {
                 progress = false;
@@ -145,7 +150,7 @@ radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively,
                NIR_PASS(progress, shader, nir_opt_copy_prop_vars);
                NIR_PASS(progress, shader, nir_opt_dead_write_vars);
 
-                NIR_PASS_V(shader, nir_lower_alu_to_scalar);
+                NIR_PASS_V(shader, nir_lower_alu_to_scalar, NULL);
                 NIR_PASS_V(shader, nir_lower_phis_to_scalar);
 
                 NIR_PASS(progress, shader, nir_copy_prop);
@@ -157,12 +162,33 @@ radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively,
                        NIR_PASS(progress, shader, nir_opt_remove_phis);
                         NIR_PASS(progress, shader, nir_opt_dce);
                 }
-                NIR_PASS(progress, shader, nir_opt_if);
+                NIR_PASS(progress, shader, nir_opt_if, true);
                 NIR_PASS(progress, shader, nir_opt_dead_cf);
                 NIR_PASS(progress, shader, nir_opt_cse);
                 NIR_PASS(progress, shader, nir_opt_peephole_select, 8, true, true);
-                NIR_PASS(progress, shader, nir_opt_algebraic);
                 NIR_PASS(progress, shader, nir_opt_constant_folding);
+                NIR_PASS(progress, shader, nir_opt_algebraic);
+
+                if (lower_flrp != 0) {
+                        bool lower_flrp_progress = false;
+                        NIR_PASS(lower_flrp_progress,
+                                 shader,
+                                 nir_lower_flrp,
+                                 lower_flrp,
+                                 false /* always_precise */,
+                                 shader->options->lower_ffma);
+                        if (lower_flrp_progress) {
+                                NIR_PASS(progress, shader,
+                                         nir_opt_constant_folding);
+                                progress = true;
+                        }
+
+                        /* Nothing should rematerialize any flrps, so we only
+                         * need to do this lowering once.
+                         */
+                        lower_flrp = 0;
+                }
+
                 NIR_PASS(progress, shader, nir_opt_undef);
                 NIR_PASS(progress, shader, nir_opt_conditional_discard);
                 if (shader->options->max_unroll_iterations) {
@@ -180,7 +206,8 @@ radv_shader_compile_to_nir(struct radv_device *device,
                           const char *entrypoint_name,
                           gl_shader_stage stage,
                           const VkSpecializationInfo *spec_info,
-                          const VkPipelineCreateFlags flags)
+                          const VkPipelineCreateFlags flags,
+                          const struct radv_pipeline_layout *layout)
 {
        nir_shader *nir;
        nir_function *entry_point;
@@ -222,21 +249,28 @@ radv_shader_compile_to_nir(struct radv_device *device,
                const struct spirv_to_nir_options spirv_options = {
                        .lower_ubo_ssbo_access_to_offsets = true,
                        .caps = {
+                               .derivative_group = true,
                                .descriptor_array_dynamic_indexing = true,
+                               .descriptor_array_non_uniform_indexing = true,
+                               .descriptor_indexing = true,
                                .device_group = true,
                                .draw_parameters = true,
+                               .float16 = true,
                                .float64 = true,
                                .gcn_shader = true,
                                .geometry_streams = true,
                                .image_read_without_format = true,
                                .image_write_without_format = true,
+                               .int8 = true,
                                .int16 = true,
                                .int64 = true,
+                               .int64_atomics = true,
                                .multiview = true,
                                .physical_storage_buffer_address = true,
                                .runtime_descriptor_array = true,
                                .shader_viewport_index_layer = true,
                                .stencil_export = true,
+                               .storage_8bit = true,
                                .storage_16bit = true,
                                .storage_image_ms = true,
                                .subgroup_arithmetic = true,
@@ -249,7 +283,6 @@ radv_shader_compile_to_nir(struct radv_device *device,
                                .transform_feedback = true,
                                .trinary_minmax = true,
                                .variable_pointers = true,
-                               .storage_8bit = true,
                        },
                        .ubo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT, 2),
                        .ssbo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT, 2),
@@ -305,6 +338,7 @@ radv_shader_compile_to_nir(struct radv_device *device,
 
                NIR_PASS_V(nir, nir_lower_system_values);
                NIR_PASS_V(nir, nir_lower_clip_cull_distance_arrays);
+               NIR_PASS_V(nir, radv_nir_lower_ycbcr_textures, layout);
        }
 
        /* Vulkan uses the separate-shader linking model */