util: Add and use util_is_power_of_two_nonzero
[mesa.git] / src / intel / compiler / brw_compiler.c
index e86ab0fc687b7789b42cac8c5fbc2db25ed66950..d5f483798a9def7f905d7d69339be3b16f8d9d3f 100644 (file)
    .lower_usub_borrow = true,                                                 \
    .lower_fdiv = true,                                                        \
    .lower_flrp64 = true,                                                      \
+   .lower_ldexp = true,                                                       \
+   .lower_device_index_to_zero = true,                                        \
    .native_integers = true,                                                   \
    .use_interpolated_input_intrinsics = true,                                 \
    .vertex_id_zero_based = true
 
+#define COMMON_SCALAR_OPTIONS                                                 \
+   .lower_pack_half_2x16 = true,                                              \
+   .lower_pack_snorm_2x16 = true,                                             \
+   .lower_pack_snorm_4x8 = true,                                              \
+   .lower_pack_unorm_2x16 = true,                                             \
+   .lower_pack_unorm_4x8 = true,                                              \
+   .lower_unpack_half_2x16 = true,                                            \
+   .lower_unpack_snorm_2x16 = true,                                           \
+   .lower_unpack_snorm_4x8 = true,                                            \
+   .lower_unpack_unorm_2x16 = true,                                           \
+   .lower_unpack_unorm_4x8 = true,                                            \
+   .vs_inputs_dual_locations = true,                                          \
+   .max_unroll_iterations = 32
+
 static const struct nir_shader_compiler_options scalar_nir_options = {
    COMMON_OPTIONS,
-   .lower_pack_half_2x16 = true,
-   .lower_pack_snorm_2x16 = true,
-   .lower_pack_snorm_4x8 = true,
-   .lower_pack_unorm_2x16 = true,
-   .lower_pack_unorm_4x8 = true,
-   .lower_unpack_half_2x16 = true,
-   .lower_unpack_snorm_2x16 = true,
-   .lower_unpack_snorm_4x8 = true,
-   .lower_unpack_unorm_2x16 = true,
-   .lower_unpack_unorm_4x8 = true,
-   .lower_subgroup_masks = true,
-   .max_subgroup_size = 64, /* FIXME */
-   .max_unroll_iterations = 32,
+   COMMON_SCALAR_OPTIONS,
+};
+
+static const struct nir_shader_compiler_options scalar_nir_options_gen11 = {
+   COMMON_OPTIONS,
+   COMMON_SCALAR_OPTIONS,
+   .lower_flrp32 = true,
 };
 
 static const struct nir_shader_compiler_options vector_nir_options = {
@@ -80,7 +90,7 @@ static const struct nir_shader_compiler_options vector_nir_options = {
    .lower_unpack_unorm_2x16 = true,
    .lower_extract_byte = true,
    .lower_extract_word = true,
-   .lower_vote_trivial = true,
+   .vs_inputs_dual_locations = true,
    .max_unroll_iterations = 32,
 };
 
@@ -99,6 +109,7 @@ static const struct nir_shader_compiler_options vector_nir_options_gen6 = {
    .lower_unpack_unorm_2x16 = true,
    .lower_extract_byte = true,
    .lower_extract_word = true,
+   .vs_inputs_dual_locations = true,
    .max_unroll_iterations = 32,
 };
 
@@ -148,7 +159,8 @@ brw_compiler_create(void *mem_ctx, const struct gen_device_info *devinfo)
       compiler->glsl_compiler_options[i].OptimizeForAOS = !is_scalar;
 
       if (is_scalar) {
-         compiler->glsl_compiler_options[i].NirOptions = &scalar_nir_options;
+         compiler->glsl_compiler_options[i].NirOptions =
+            devinfo->gen < 11 ? &scalar_nir_options : &scalar_nir_options_gen11;
       } else {
          compiler->glsl_compiler_options[i].NirOptions =
             devinfo->gen < 6 ? &vector_nir_options : &vector_nir_options_gen6;
@@ -167,3 +179,39 @@ brw_compiler_create(void *mem_ctx, const struct gen_device_info *devinfo)
 
    return compiler;
 }
+
+unsigned
+brw_prog_data_size(gl_shader_stage stage)
+{
+   STATIC_ASSERT(MESA_SHADER_VERTEX == 0);
+   STATIC_ASSERT(MESA_SHADER_TESS_CTRL == 1);
+   STATIC_ASSERT(MESA_SHADER_TESS_EVAL == 2);
+   STATIC_ASSERT(MESA_SHADER_GEOMETRY == 3);
+   STATIC_ASSERT(MESA_SHADER_FRAGMENT == 4);
+   STATIC_ASSERT(MESA_SHADER_COMPUTE == 5);
+   static const size_t stage_sizes[] = {
+      sizeof(struct brw_vs_prog_data),
+      sizeof(struct brw_tcs_prog_data),
+      sizeof(struct brw_tes_prog_data),
+      sizeof(struct brw_gs_prog_data),
+      sizeof(struct brw_wm_prog_data),
+      sizeof(struct brw_cs_prog_data),
+   };
+   assert((int)stage >= 0 && stage < ARRAY_SIZE(stage_sizes));
+   return stage_sizes[stage];
+}
+
+unsigned
+brw_prog_key_size(gl_shader_stage stage)
+{
+   static const size_t stage_sizes[] = {
+      sizeof(struct brw_vs_prog_key),
+      sizeof(struct brw_tcs_prog_key),
+      sizeof(struct brw_tes_prog_key),
+      sizeof(struct brw_gs_prog_key),
+      sizeof(struct brw_wm_prog_key),
+      sizeof(struct brw_cs_prog_key),
+   };
+   assert((int)stage >= 0 && stage < ARRAY_SIZE(stage_sizes));
+   return stage_sizes[stage];
+}