freedreno/ir3: image support
[mesa.git] / src / gallium / drivers / freedreno / ir3 / ir3_nir.c
index 25262224f9844bd6ab287f4fa4f3722e99bb104e..7dd24e5f4eeb64f796f6530179a77cd7fd5f3dbc 100644 (file)
@@ -52,6 +52,23 @@ static const nir_shader_compiler_options options = {
                .lower_extract_word = true,
 };
 
+static const nir_shader_compiler_options options_5xx = {
+               .lower_fpow = true,
+               .lower_fsat = true,
+               .lower_scmp = true,
+               .lower_flrp32 = true,
+               .lower_flrp64 = true,
+               .lower_ffract = true,
+               .lower_fmod32 = true,
+               .lower_fmod64 = true,
+               .lower_fdiv = true,
+               .fuse_ffma = true,
+               .native_integers = true,
+               .vertex_id_zero_based = false,
+               .lower_extract_byte = true,
+               .lower_extract_word = true,
+};
+
 struct nir_shader *
 ir3_tgsi_to_nir(const struct tgsi_token *tokens)
 {
@@ -59,8 +76,10 @@ ir3_tgsi_to_nir(const struct tgsi_token *tokens)
 }
 
 const nir_shader_compiler_options *
-ir3_get_compiler_options(void)
+ir3_get_compiler_options(struct ir3_compiler *compiler)
 {
+       if (compiler->gpu_id >= 500)
+               return &options_5xx;
        return &options;
 }
 
@@ -90,8 +109,9 @@ ir3_optimize_loop(nir_shader *s)
                progress = false;
 
                OPT_V(s, nir_lower_vars_to_ssa);
+               progress |= OPT(s, nir_opt_copy_prop_vars);
                progress |= OPT(s, nir_lower_alu_to_scalar);
-               OPT_V(s, nir_lower_phis_to_scalar);
+               progress |= OPT(s, nir_lower_phis_to_scalar);
 
                progress |= OPT(s, nir_copy_prop);
                progress |= OPT(s, nir_opt_dce);
@@ -114,7 +134,6 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
        if (key) {
                switch (shader->type) {
                case SHADER_FRAGMENT:
-               case SHADER_COMPUTE:
                        tex_options.saturate_s = key->fsaturate_s;
                        tex_options.saturate_t = key->fsaturate_t;
                        tex_options.saturate_r = key->fsaturate_r;
@@ -124,6 +143,9 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
                        tex_options.saturate_t = key->vsaturate_t;
                        tex_options.saturate_r = key->vsaturate_r;
                        break;
+               default:
+                       /* TODO */
+                       break;
                }
        }
 
@@ -142,14 +164,14 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
        }
 
        OPT_V(s, nir_opt_global_to_local);
-       OPT_V(s, nir_convert_to_ssa);
+       OPT_V(s, nir_lower_regs_to_ssa);
 
        if (key) {
-               if (s->stage == MESA_SHADER_VERTEX) {
+               if (s->info.stage == MESA_SHADER_VERTEX) {
                        OPT_V(s, nir_lower_clip_vs, key->ucp_enables);
                        if (key->vclamp_color)
                                OPT_V(s, nir_lower_clamp_color_outputs);
-               } else if (s->stage == MESA_SHADER_FRAGMENT) {
+               } else if (s->info.stage == MESA_SHADER_FRAGMENT) {
                        OPT_V(s, nir_lower_clip_fs, key->ucp_enables);
                        if (key->fclamp_color)
                                OPT_V(s, nir_lower_clamp_color_outputs);
@@ -187,3 +209,47 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
 
        return s;
 }
+
+void
+ir3_nir_scan_driver_consts(nir_shader *shader,
+               struct ir3_driver_const_layout *layout)
+{
+       nir_foreach_function(function, shader) {
+               if (!function->impl)
+                       continue;
+
+               nir_foreach_block(block, function->impl) {
+                       nir_foreach_instr(instr, block) {
+                               if (instr->type != nir_instr_type_intrinsic)
+                                       continue;
+
+                               nir_intrinsic_instr *intr =
+                                       nir_instr_as_intrinsic(instr);
+                               unsigned idx;
+
+                               switch (intr->intrinsic) {
+                               case nir_intrinsic_get_buffer_size:
+                                       idx = nir_src_as_const_value(intr->src[0])->u32[0];
+                                       if (layout->ssbo_size.mask & (1 << idx))
+                                               break;
+                                       layout->ssbo_size.mask |= (1 << idx);
+                                       layout->ssbo_size.off[idx] =
+                                               layout->ssbo_size.count;
+                                       layout->ssbo_size.count += 1; /* one const per */
+                                       break;
+                               case nir_intrinsic_image_store:
+                                       idx = intr->variables[0]->var->data.driver_location;
+                                       if (layout->image_dims.mask & (1 << idx))
+                                               break;
+                                       layout->image_dims.mask |= (1 << idx);
+                                       layout->ssbo_size.off[idx] =
+                                               layout->image_dims.count;
+                                       layout->image_dims.count += 3; /* three const per */
+                                       break;
+                               default:
+                                       break;
+                               }
+                       }
+               }
+       }
+}