~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/compiler/nir/nir_opt_load_store_vectorize.c

  • 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:
71
71
}
72
72
#define LOAD(mode, op, res, base, deref) INFO(mode, load_##op, false, res, base, deref, -1)
73
73
#define STORE(mode, op, res, base, deref, val) INFO(mode, store_##op, false, res, base, deref, val)
74
 
#define ATOMIC(mode, type, op, res, base, deref, val) INFO(mode, type##_atomic_##op, true, res, base, deref, val)
 
74
#define ATOMIC(mode, type, res, base, deref, val) \
 
75
   INFO(mode, type##_atomic, true, res, base, deref, val) \
 
76
   INFO(mode, type##_atomic_swap, true, res, base, deref, val) \
 
77
 
75
78
   LOAD(nir_var_mem_push_const, push_constant, -1, 0, -1)
76
79
   LOAD(nir_var_mem_ubo, ubo, 0, 1, -1)
77
80
   LOAD(nir_var_mem_ssbo, ssbo, 0, 1, -1)
82
85
   STORE(nir_var_mem_shared, shared, -1, 1, -1, 0)
83
86
   LOAD(nir_var_mem_global, global, -1, 0, -1)
84
87
   STORE(nir_var_mem_global, global, -1, 1, -1, 0)
 
88
   LOAD(nir_var_mem_global, global_constant, -1, 0, -1)
85
89
   LOAD(nir_var_mem_task_payload, task_payload, -1, 0, -1)
86
90
   STORE(nir_var_mem_task_payload, task_payload, -1, 1, -1, 0)
87
 
   ATOMIC(nir_var_mem_ssbo, ssbo, add, 0, 1, -1, 2)
88
 
   ATOMIC(nir_var_mem_ssbo, ssbo, imin, 0, 1, -1, 2)
89
 
   ATOMIC(nir_var_mem_ssbo, ssbo, umin, 0, 1, -1, 2)
90
 
   ATOMIC(nir_var_mem_ssbo, ssbo, imax, 0, 1, -1, 2)
91
 
   ATOMIC(nir_var_mem_ssbo, ssbo, umax, 0, 1, -1, 2)
92
 
   ATOMIC(nir_var_mem_ssbo, ssbo, and, 0, 1, -1, 2)
93
 
   ATOMIC(nir_var_mem_ssbo, ssbo, or, 0, 1, -1, 2)
94
 
   ATOMIC(nir_var_mem_ssbo, ssbo, xor, 0, 1, -1, 2)
95
 
   ATOMIC(nir_var_mem_ssbo, ssbo, exchange, 0, 1, -1, 2)
96
 
   ATOMIC(nir_var_mem_ssbo, ssbo, comp_swap, 0, 1, -1, 2)
97
 
   ATOMIC(nir_var_mem_ssbo, ssbo, fadd, 0, 1, -1, 2)
98
 
   ATOMIC(nir_var_mem_ssbo, ssbo, fmin, 0, 1, -1, 2)
99
 
   ATOMIC(nir_var_mem_ssbo, ssbo, fmax, 0, 1, -1, 2)
100
 
   ATOMIC(nir_var_mem_ssbo, ssbo, fcomp_swap, 0, 1, -1, 2)
101
 
   ATOMIC(0, deref, add, -1, -1, 0, 1)
102
 
   ATOMIC(0, deref, imin, -1, -1, 0, 1)
103
 
   ATOMIC(0, deref, umin, -1, -1, 0, 1)
104
 
   ATOMIC(0, deref, imax, -1, -1, 0, 1)
105
 
   ATOMIC(0, deref, umax, -1, -1, 0, 1)
106
 
   ATOMIC(0, deref, and, -1, -1, 0, 1)
107
 
   ATOMIC(0, deref, or, -1, -1, 0, 1)
108
 
   ATOMIC(0, deref, xor, -1, -1, 0, 1)
109
 
   ATOMIC(0, deref, exchange, -1, -1, 0, 1)
110
 
   ATOMIC(0, deref, comp_swap, -1, -1, 0, 1)
111
 
   ATOMIC(0, deref, fadd, -1, -1, 0, 1)
112
 
   ATOMIC(0, deref, fmin, -1, -1, 0, 1)
113
 
   ATOMIC(0, deref, fmax, -1, -1, 0, 1)
114
 
   ATOMIC(0, deref, fcomp_swap, -1, -1, 0, 1)
115
 
   ATOMIC(nir_var_mem_shared, shared, add, -1, 0, -1, 1)
116
 
   ATOMIC(nir_var_mem_shared, shared, imin, -1, 0, -1, 1)
117
 
   ATOMIC(nir_var_mem_shared, shared, umin, -1, 0, -1, 1)
118
 
   ATOMIC(nir_var_mem_shared, shared, imax, -1, 0, -1, 1)
119
 
   ATOMIC(nir_var_mem_shared, shared, umax, -1, 0, -1, 1)
120
 
   ATOMIC(nir_var_mem_shared, shared, and, -1, 0, -1, 1)
121
 
   ATOMIC(nir_var_mem_shared, shared, or, -1, 0, -1, 1)
122
 
   ATOMIC(nir_var_mem_shared, shared, xor, -1, 0, -1, 1)
123
 
   ATOMIC(nir_var_mem_shared, shared, exchange, -1, 0, -1, 1)
124
 
   ATOMIC(nir_var_mem_shared, shared, comp_swap, -1, 0, -1, 1)
125
 
   ATOMIC(nir_var_mem_shared, shared, fadd, -1, 0, -1, 1)
126
 
   ATOMIC(nir_var_mem_shared, shared, fmin, -1, 0, -1, 1)
127
 
   ATOMIC(nir_var_mem_shared, shared, fmax, -1, 0, -1, 1)
128
 
   ATOMIC(nir_var_mem_shared, shared, fcomp_swap, -1, 0, -1, 1)
129
 
   ATOMIC(nir_var_mem_global, global, add, -1, 0, -1, 1)
130
 
   ATOMIC(nir_var_mem_global, global, imin, -1, 0, -1, 1)
131
 
   ATOMIC(nir_var_mem_global, global, umin, -1, 0, -1, 1)
132
 
   ATOMIC(nir_var_mem_global, global, imax, -1, 0, -1, 1)
133
 
   ATOMIC(nir_var_mem_global, global, umax, -1, 0, -1, 1)
134
 
   ATOMIC(nir_var_mem_global, global, and, -1, 0, -1, 1)
135
 
   ATOMIC(nir_var_mem_global, global, or, -1, 0, -1, 1)
136
 
   ATOMIC(nir_var_mem_global, global, xor, -1, 0, -1, 1)
137
 
   ATOMIC(nir_var_mem_global, global, exchange, -1, 0, -1, 1)
138
 
   ATOMIC(nir_var_mem_global, global, comp_swap, -1, 0, -1, 1)
139
 
   ATOMIC(nir_var_mem_global, global, fadd, -1, 0, -1, 1)
140
 
   ATOMIC(nir_var_mem_global, global, fmin, -1, 0, -1, 1)
141
 
   ATOMIC(nir_var_mem_global, global, fmax, -1, 0, -1, 1)
142
 
   ATOMIC(nir_var_mem_global, global, fcomp_swap, -1, 0, -1, 1)
143
 
   ATOMIC(nir_var_mem_task_payload, task_payload, add, -1, 0, -1, 1)
144
 
   ATOMIC(nir_var_mem_task_payload, task_payload, imin, -1, 0, -1, 1)
145
 
   ATOMIC(nir_var_mem_task_payload, task_payload, umin, -1, 0, -1, 1)
146
 
   ATOMIC(nir_var_mem_task_payload, task_payload, imax, -1, 0, -1, 1)
147
 
   ATOMIC(nir_var_mem_task_payload, task_payload, umax, -1, 0, -1, 1)
148
 
   ATOMIC(nir_var_mem_task_payload, task_payload, and, -1, 0, -1, 1)
149
 
   ATOMIC(nir_var_mem_task_payload, task_payload, or, -1, 0, -1, 1)
150
 
   ATOMIC(nir_var_mem_task_payload, task_payload, xor, -1, 0, -1, 1)
151
 
   ATOMIC(nir_var_mem_task_payload, task_payload, exchange, -1, 0, -1, 1)
152
 
   ATOMIC(nir_var_mem_task_payload, task_payload, comp_swap, -1, 0, -1, 1)
153
 
   ATOMIC(nir_var_mem_task_payload, task_payload, fadd, -1, 0, -1, 1)
154
 
   ATOMIC(nir_var_mem_task_payload, task_payload, fmin, -1, 0, -1, 1)
155
 
   ATOMIC(nir_var_mem_task_payload, task_payload, fmax, -1, 0, -1, 1)
156
 
   ATOMIC(nir_var_mem_task_payload, task_payload, fcomp_swap, -1, 0, -1, 1)
 
91
   ATOMIC(nir_var_mem_ssbo, ssbo, 0, 1, -1, 2)
 
92
   ATOMIC(0, deref, -1, -1, 0, 1)
 
93
   ATOMIC(nir_var_mem_shared, shared, -1, 0, -1, 1)
 
94
   ATOMIC(nir_var_mem_global, global, -1, 0, -1, 1)
 
95
   ATOMIC(nir_var_mem_task_payload, task_payload, -1, 0, -1, 1)
157
96
   LOAD(nir_var_shader_temp, stack, -1, -1, -1)
158
97
   STORE(nir_var_shader_temp, stack, -1, -1, -1, 0)
 
98
   LOAD(nir_var_mem_ubo, ubo_uniform_block_intel, 0, 1, -1)
159
99
   LOAD(nir_var_mem_ssbo, ssbo_uniform_block_intel, 0, 1, -1)
160
100
   LOAD(nir_var_mem_shared, shared_uniform_block_intel, -1, 0, -1)
 
101
   LOAD(nir_var_mem_global, global_constant_uniform_block_intel, -1, 0, -1)
161
102
   default:
162
103
      break;
163
104
#undef ATOMIC
811
752
 
812
753
      nir_intrinsic_set_range_base(first->intrin, low_base);
813
754
      nir_intrinsic_set_range(first->intrin, MAX2(low_end, high_end) - low_base);
 
755
   } else if (nir_intrinsic_has_base(first->intrin) && info->base_src == -1 && info->deref_src == -1) {
 
756
      nir_intrinsic_set_base(first->intrin, nir_intrinsic_base(low->intrin));
814
757
   }
815
758
 
816
759
   first->key = low->key;
1186
1129
   unsigned new_num_components = new_size / new_bit_size;
1187
1130
 
1188
1131
   /* vectorize the loads/stores */
1189
 
   nir_builder b;
1190
 
   nir_builder_init(&b, impl);
 
1132
   nir_builder b = nir_builder_create(impl);
1191
1133
 
1192
1134
   if (first->is_store)
1193
1135
      vectorize_stores(&b, ctx, low, high, first, second,
1200
1142
}
1201
1143
 
1202
1144
static bool
1203
 
try_vectorize_shared2(nir_function_impl *impl, struct vectorize_ctx *ctx,
 
1145
try_vectorize_shared2(struct vectorize_ctx *ctx,
1204
1146
                      struct entry *low, struct entry *high,
1205
1147
                      struct entry *first, struct entry *second)
1206
1148
{
1238
1180
   }
1239
1181
 
1240
1182
   /* vectorize the accesses */
1241
 
   nir_builder b;
1242
 
   nir_builder_init(&b, impl);
1243
 
 
1244
 
   b.cursor = nir_after_instr(first->is_store ? second->instr : first->instr);
 
1183
   nir_builder b = nir_builder_at(nir_after_instr(first->is_store ? second->instr : first->instr));
1245
1184
 
1246
1185
   nir_ssa_def *offset = first->intrin->src[first->is_store].ssa;
1247
1186
   offset = nir_iadd_imm(&b, offset, nir_intrinsic_base(first->intrin));
1308
1247
                get_variable_mode(first) != nir_var_mem_shared)
1309
1248
               break;
1310
1249
 
1311
 
            if (try_vectorize_shared2(impl, ctx, low, high, first, second)) {
 
1250
            if (try_vectorize_shared2(ctx, low, high, first, second)) {
1312
1251
               low = NULL;
1313
1252
               *util_dynarray_element(arr, struct entry *, second_idx) = NULL;
1314
1253
               progress = true;
1368
1307
   if (instr->type == nir_instr_type_intrinsic) {
1369
1308
      nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
1370
1309
      switch (intrin->intrinsic) {
1371
 
      case nir_intrinsic_group_memory_barrier:
1372
 
      case nir_intrinsic_memory_barrier:
1373
 
         modes = nir_var_mem_ssbo | nir_var_mem_shared | nir_var_mem_global |
1374
 
                 nir_var_mem_task_payload;
1375
 
         break;
1376
1310
      /* prevent speculative loads/stores */
1377
1311
      case nir_intrinsic_discard_if:
1378
1312
      case nir_intrinsic_discard:
1386
1320
         acquire = false;
1387
1321
         modes = nir_var_all;
1388
1322
         break;
1389
 
      case nir_intrinsic_memory_barrier_buffer:
1390
 
         modes = nir_var_mem_ssbo | nir_var_mem_global;
1391
 
         break;
1392
 
      case nir_intrinsic_memory_barrier_shared:
1393
 
         modes = nir_var_mem_shared | nir_var_mem_task_payload;
1394
 
         break;
1395
1323
      case nir_intrinsic_scoped_barrier:
1396
 
         if (nir_intrinsic_memory_scope(intrin) == NIR_SCOPE_NONE)
 
1324
         if (nir_intrinsic_memory_scope(intrin) == SCOPE_NONE)
1397
1325
            break;
1398
1326
 
1399
1327
         modes = nir_intrinsic_memory_modes(intrin) & (nir_var_mem_ssbo |
1403
1331
         acquire = nir_intrinsic_memory_semantics(intrin) & NIR_MEMORY_ACQUIRE;
1404
1332
         release = nir_intrinsic_memory_semantics(intrin) & NIR_MEMORY_RELEASE;
1405
1333
         switch (nir_intrinsic_memory_scope(intrin)) {
1406
 
         case NIR_SCOPE_INVOCATION:
 
1334
         case SCOPE_INVOCATION:
1407
1335
            /* a barier should never be required for correctness with these scopes */
1408
1336
            modes = 0;
1409
1337
            break;
1527
1455
 
1528
1456
   nir_shader_index_vars(shader, options->modes);
1529
1457
 
1530
 
   nir_foreach_function(function, shader) {
1531
 
      if (function->impl) {
1532
 
         if (options->modes & nir_var_function_temp)
1533
 
            nir_function_impl_index_vars(function->impl);
1534
 
 
1535
 
         nir_foreach_block(block, function->impl)
1536
 
            progress |= process_block(function->impl, ctx, block);
1537
 
 
1538
 
         nir_metadata_preserve(function->impl,
1539
 
                               nir_metadata_block_index |
1540
 
                               nir_metadata_dominance |
1541
 
                               nir_metadata_live_ssa_defs);
1542
 
      }
 
1458
   nir_foreach_function_impl(impl, shader) {
 
1459
      if (options->modes & nir_var_function_temp)
 
1460
         nir_function_impl_index_vars(impl);
 
1461
 
 
1462
      nir_foreach_block(block, impl)
 
1463
         progress |= process_block(impl, ctx, block);
 
1464
 
 
1465
      nir_metadata_preserve(impl,
 
1466
                            nir_metadata_block_index |
 
1467
                            nir_metadata_dominance |
 
1468
                            nir_metadata_live_ssa_defs);
1543
1469
   }
1544
1470
 
1545
1471
   ralloc_free(ctx);