nir: Add a find_variable_with_[driver_]location helper
[mesa.git] / src / amd / vulkan / radv_shader.c
index 2aa6b191699093afe3ca1f0f3df7262388a0b31d..810d4055186e2979dd2360ac010b1ca1780d7a21 100644 (file)
@@ -130,6 +130,7 @@ static const struct nir_shader_compiler_options nir_options_aco = {
                                 nir_lower_dsqrt |
                                 nir_lower_drsq |
                                 nir_lower_ddiv,
+       .use_scoped_barrier = true,
 };
 
 bool
@@ -365,7 +366,7 @@ radv_shader_compile_to_nir(struct radv_device *device,
                                .amd_gcn_shader = true,
                                .amd_image_gather_bias_lod = true,
                                .amd_image_read_write_lod = true,
-                               .amd_shader_ballot = device->physical_device->use_shader_ballot,
+                               .amd_shader_ballot = true,
                                .amd_shader_explicit_vertex_parameter = true,
                                .amd_trinary_minmax = true,
                                .demote_to_helper_invocation = true,
@@ -377,6 +378,7 @@ radv_shader_compile_to_nir(struct radv_device *device,
                                .draw_parameters = true,
                                .float_controls = true,
                                .float16 = device->physical_device->rad_info.has_packed_math_16bit,
+                               .float32_atomic_add = true,
                                .float64 = true,
                                .geometry_streams = true,
                                .image_ms_array = true,
@@ -430,6 +432,7 @@ radv_shader_compile_to_nir(struct radv_device *device,
                NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
                NIR_PASS_V(nir, nir_lower_returns);
                NIR_PASS_V(nir, nir_inline_functions);
+               NIR_PASS_V(nir, nir_copy_prop);
                NIR_PASS_V(nir, nir_opt_deref);
 
                /* Pick off the single entrypoint that we want */
@@ -471,7 +474,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);
+
                if (device->instance->debug_flags & RADV_DEBUG_DISCARD_TO_DEMOTE)
                        NIR_PASS_V(nir, nir_lower_discard_to_demote);
 
@@ -531,6 +534,7 @@ radv_shader_compile_to_nir(struct radv_device *device,
                        .lower_vote_eq_to_ballot = 1,
                        .lower_quad_broadcast_dynamic = 1,
                        .lower_quad_broadcast_dynamic_to_const = gfx7minus,
+                       .lower_shuffle_to_swizzle_amd = 1,
                });
 
        nir_lower_load_const_to_scalar(nir);
@@ -538,6 +542,10 @@ radv_shader_compile_to_nir(struct radv_device *device,
        if (!(flags & VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT))
                radv_optimize_nir(nir, false, true);
 
+       /* call radv_nir_lower_ycbcr_textures() late as there might still be
+        * tex with undef texture/sampler before first optimization */
+       NIR_PASS_V(nir, radv_nir_lower_ycbcr_textures, layout);
+
        /* We call nir_lower_var_copies() after the first radv_optimize_nir()
         * to remove any copies introduced by nir_opt_find_array_copies().
         */
@@ -578,14 +586,12 @@ type_size_vec4(const struct glsl_type *type, bool bindless)
 static nir_variable *
 find_layer_in_var(nir_shader *nir)
 {
-       nir_foreach_variable(var, &nir->inputs) {
-               if (var->data.location == VARYING_SLOT_LAYER) {
-                       return var;
-               }
-       }
-
        nir_variable *var =
-               nir_variable_create(nir, nir_var_shader_in, glsl_int_type(), "layer id");
+               nir_find_variable_with_location(nir, nir_var_shader_in, VARYING_SLOT_LAYER);
+       if (var != NULL)
+               return var;
+
+       var = nir_variable_create(nir, nir_var_shader_in, glsl_int_type(), "layer id");
        var->data.location = VARYING_SLOT_LAYER;
        var->data.interpolation = INTERP_MODE_FLAT;
        return var;
@@ -640,7 +646,7 @@ void
 radv_lower_fs_io(nir_shader *nir)
 {
        NIR_PASS_V(nir, lower_view_index);
-       nir_assign_io_var_locations(&nir->inputs, &nir->num_inputs,
+       nir_assign_io_var_locations(nir, nir_var_shader_in, &nir->num_inputs,
                                    MESA_SHADER_FRAGMENT);
 
        NIR_PASS_V(nir, nir_lower_io, nir_var_shader_in, type_size_vec4, 0);
@@ -810,8 +816,10 @@ static void radv_postprocess_config(const struct radv_physical_device *pdevice,
                         */
                        if (pdevice->rad_info.chip_class >= GFX10) {
                                vgpr_comp_cnt = info->vs.needs_instance_id ? 3 : 1;
+                               config_out->rsrc2 |= S_00B42C_LDS_SIZE_GFX10(info->tcs.num_lds_blocks);
                        } else {
                                vgpr_comp_cnt = info->vs.needs_instance_id ? 2 : 1;
+                               config_out->rsrc2 |= S_00B42C_LDS_SIZE_GFX9(info->tcs.num_lds_blocks);
                        }
                } else {
                        config_out->rsrc2 |= S_00B12C_OC_LDS_EN(1);
@@ -1036,13 +1044,6 @@ radv_shader_variant_create(struct radv_device *device,
        radv_postprocess_config(device->physical_device, &config, &binary->info,
                                binary->stage, &variant->config);
 
-       if (radv_device_use_secure_compile(device->instance)) {
-               if (binary->type == RADV_BINARY_TYPE_RTLD)
-                       ac_rtld_close(&rtld_binary);
-
-               return variant;
-       }
-
        void *dest_ptr = radv_alloc_shader_memory(device, variant);
        if (!dest_ptr) {
                if (binary->type == RADV_BINARY_TYPE_RTLD)