~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/gallium/drivers/r600/sfn/sfn_nir.cpp

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "nir.h"
32
32
#include "nir_builder.h"
33
33
#include "nir_intrinsics.h"
 
34
#include "r600_asm.h"
34
35
#include "sfn_assembler.h"
35
36
#include "sfn_debug.h"
36
37
#include "sfn_instr_tex.h"
42
43
#include "sfn_ra.h"
43
44
#include "sfn_scheduler.h"
44
45
#include "sfn_shader.h"
 
46
#include "sfn_split_address_loads.h"
45
47
#include "util/u_prim.h"
46
48
 
47
49
#include <vector>
100
102
   }
101
103
 
102
104
   nir_ssa_def *address = instr->src[address_index].ssa;
103
 
   nir_ssa_def *new_address = nir_ishr(b, address, nir_imm_int(b, 4 * align));
 
105
   nir_ssa_def *new_address = nir_ishr_imm(b, address, 4 * align);
104
106
 
105
107
   nir_instr_rewrite_src(&instr->instr,
106
108
                         &instr->src[address_index],
111
113
r600_lower_scratch_addresses(nir_shader *shader)
112
114
{
113
115
   bool progress = false;
114
 
   nir_foreach_function(function, shader)
 
116
   nir_foreach_function_impl(impl, shader)
115
117
   {
116
 
      nir_builder build;
117
 
      nir_builder_init(&build, function->impl);
 
118
      nir_builder build = nir_builder_create(impl);
118
119
 
119
 
      nir_foreach_block(block, function->impl)
 
120
      nir_foreach_block(block, impl)
120
121
      {
121
122
         nir_foreach_instr(instr, block)
122
123
         {
413
414
         array_stride *= glsl_get_aoa_size(d->type);
414
415
 
415
416
      offset =
416
 
         nir_iadd(b, offset, nir_imul(b, d->arr.index.ssa, nir_imm_int(b, array_stride)));
 
417
         nir_iadd(b, offset, nir_imul_imm(b, d->arr.index.ssa, array_stride));
417
418
   }
418
419
 
419
420
   /* Since the first source is a deref and the first source in the lowered
502
503
}
503
504
 
504
505
static bool
505
 
r600_lower_shared_io_impl(nir_function *func)
 
506
r600_lower_shared_io_impl(nir_function_impl *impl)
506
507
{
507
 
   nir_builder b;
508
 
   nir_builder_init(&b, func->impl);
 
508
   nir_builder b = nir_builder_create(impl);
509
509
 
510
510
   bool progress = false;
511
 
   nir_foreach_block(block, func->impl)
 
511
   nir_foreach_block(block, impl)
512
512
   {
513
513
      nir_foreach_instr_safe(instr, block)
514
514
      {
548
548
               nir_intrinsic_instr_create(b.shader, nir_intrinsic_load_local_shared_r600);
549
549
            load->num_components = nir_dest_num_components(op->dest);
550
550
            load->src[0] = nir_src_for_ssa(addr);
551
 
            nir_ssa_dest_init(&load->instr, &load->dest, load->num_components, 32, NULL);
 
551
            nir_ssa_dest_init(&load->instr, &load->dest, load->num_components,
 
552
                              32);
552
553
            nir_ssa_def_rewrite_uses(&op->dest.ssa, &load->dest.ssa);
553
554
            nir_builder_instr_insert(&b, &load->instr);
554
555
         } else {
568
569
               bool start_even = (writemask & (1u << (2 * i)));
569
570
 
570
571
               auto addr2 =
571
 
                  nir_iadd(&b, addr, nir_imm_int(&b, 8 * i + (start_even ? 0 : 4)));
 
572
                  nir_iadd_imm(&b, addr, 8 * i + (start_even ? 0 : 4));
572
573
               store->src[1] = nir_src_for_ssa(addr2);
573
574
 
574
575
               nir_builder_instr_insert(&b, &store->instr);
585
586
r600_lower_shared_io(nir_shader *nir)
586
587
{
587
588
   bool progress = false;
588
 
   nir_foreach_function(function, nir)
 
589
   nir_foreach_function_impl(impl, nir)
589
590
   {
590
 
      if (function->impl && r600_lower_shared_io_impl(function))
 
591
      if (r600_lower_shared_io_impl(impl))
591
592
         progress = true;
592
593
   }
593
594
   return progress;
599
600
   (void)_options;
600
601
   auto old_ir = nir_instr_as_intrinsic(instr);
601
602
   auto load = nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_input);
602
 
   nir_ssa_dest_init(&load->instr,
603
 
                     &load->dest,
 
603
   nir_ssa_dest_init(&load->instr, &load->dest,
604
604
                     old_ir->dest.ssa.num_components,
605
 
                     old_ir->dest.ssa.bit_size,
606
 
                     NULL);
 
605
                     old_ir->dest.ssa.bit_size);
607
606
   nir_intrinsic_set_io_semantics(load, nir_intrinsic_io_semantics(old_ir));
608
607
 
609
608
   nir_intrinsic_set_base(load, nir_intrinsic_base(old_ir));
735
734
   case nir_op_fddy_coarse:
736
735
   case nir_op_fddy_fine:
737
736
      return nir_src_bit_size(alu->src[0].src) == 64;
738
 
   case nir_op_cube_r600:
739
 
      return false;
740
737
   default:
741
738
      return true;
742
739
   }
755
752
 
756
753
   nir_shader *nir = (nir_shader *)shader;
757
754
 
758
 
   NIR_PASS_V(nir, nir_lower_regs_to_ssa);
759
755
   const int nir_lower_flrp_mask = 16 | 32 | 64;
760
756
 
761
757
   NIR_PASS_V(nir, nir_lower_flrp, nir_lower_flrp_mask, false);
870
866
       (sh->info.stage == MESA_SHADER_VERTEX && key->vs.as_ls)) {
871
867
      auto prim_type = sh->info.stage == MESA_SHADER_TESS_EVAL
872
868
                          ? u_tess_prim_from_shader(sh->info.tess._primitive_mode)
873
 
                          : (pipe_prim_type)key->tcs.prim_mode;
874
 
      NIR_PASS_V(sh, r600_lower_tess_io, static_cast<pipe_prim_type>(prim_type));
 
869
                          : (mesa_prim)key->tcs.prim_mode;
 
870
      NIR_PASS_V(sh, r600_lower_tess_io, static_cast<mesa_prim>(prim_type));
875
871
   }
876
872
 
877
873
   if (sh->info.stage == MESA_SHADER_TESS_CTRL)
878
 
      NIR_PASS_V(sh, r600_append_tcs_TF_emission, (pipe_prim_type)key->tcs.prim_mode);
 
874
      NIR_PASS_V(sh, r600_append_tcs_TF_emission, (mesa_prim)key->tcs.prim_mode);
879
875
 
880
876
   if (sh->info.stage == MESA_SHADER_TESS_EVAL) {
881
877
      NIR_PASS_V(sh,
939
935
 
940
936
   NIR_PASS_V(sh, nir_lower_bool_to_int32);
941
937
 
942
 
   NIR_PASS_V(sh, nir_lower_locals_to_regs);
943
 
 
944
 
   NIR_PASS_V(sh,
945
 
              nir_lower_to_source_mods,
946
 
              (nir_lower_to_source_mods_flags)(nir_lower_float_source_mods |
947
 
                                               nir_lower_64bit_source_mods));
948
 
   NIR_PASS_V(sh, nir_convert_from_ssa, true);
 
938
   NIR_PASS_V(sh, nir_lower_locals_to_regs, 32);
 
939
   NIR_PASS_V(sh, nir_convert_from_ssa, true, false);
949
940
   NIR_PASS_V(sh, nir_opt_dce);
950
941
 
951
942
   if (rctx->screen->b.debug_flags & DBG_ALL_SHADERS) {
978
969
   r600_screen *rscreen = rctx->screen;
979
970
 
980
971
   r600::Shader *shader =
981
 
      r600::Shader::translate_from_nir(sh, &sel->so, gs_shader, *key, rctx->isa->hw_class);
 
972
      r600::Shader::translate_from_nir(sh, &sel->so, gs_shader, *key,
 
973
                                       rctx->isa->hw_class, rscreen->b.family);
982
974
 
983
975
   assert(shader);
984
976
   if (!shader)
1004
996
      }
1005
997
   }
1006
998
 
 
999
   if (!r600::sfn_log.has_debug_flag(r600::SfnLog::noaddrsplit))
 
1000
      split_address_loads(*shader);
 
1001
   
 
1002
   if (r600::sfn_log.has_debug_flag(r600::SfnLog::steps)) {
 
1003
      std::cerr << "Shader after splitting address loads\n";
 
1004
      shader->print(std::cerr);
 
1005
   }
 
1006
   
 
1007
   if (!r600::sfn_log.has_debug_flag(r600::SfnLog::noopt)) {
 
1008
      optimize(*shader);
 
1009
 
 
1010
      if (r600::sfn_log.has_debug_flag(r600::SfnLog::steps)) {
 
1011
         std::cerr << "Shader after optimization\n";
 
1012
         shader->print(std::cerr);
 
1013
      }
 
1014
   }
 
1015
 
1007
1016
   auto scheduled_shader = r600::schedule(shader);
1008
1017
   if (r600::sfn_log.has_debug_flag(r600::SfnLog::steps)) {
1009
1018
      std::cerr << "Shader after scheduling\n";
1040
1049
                      rscreen->b.family,
1041
1050
                      rscreen->has_compressed_msaa_texturing);
1042
1051
 
 
1052
   /* We already schedule the code with this in mind, no need to handle this
 
1053
    * in the backend assembler */
 
1054
   if (!r600::sfn_log.has_debug_flag(r600::SfnLog::noaddrsplit)) {
 
1055
      pipeshader->shader.bc.ar_handling = AR_HANDLE_NORMAL;
 
1056
      pipeshader->shader.bc.r6xx_nop_after_rel_dst = 0;
 
1057
   }
1043
1058
 
1044
1059
   r600::sfn_log << r600::SfnLog::shader_info << "pipeshader->shader.processor_type = "
1045
1060
                 << pipeshader->shader.processor_type << "\n";
1063
1078
            sh->info.vs.window_space_position;
1064
1079
   }
1065
1080
 
 
1081
   if (sh->info.stage == MESA_SHADER_FRAGMENT)
 
1082
      pipeshader->shader.ps_conservative_z =
 
1083
            sh->info.fs.depth_layout;
 
1084
 
1066
1085
   if (sh->info.stage == MESA_SHADER_GEOMETRY) {
1067
1086
      r600::sfn_log << r600::SfnLog::shader_info
1068
1087
                    << "Geometry shader, create copy shader\n";