~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/broadcom/compiler/v3d_nir_lower_io.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:
109
109
 
110
110
        nir_instr_rewrite_src(&intr->instr,
111
111
                              &intr->src[0],
112
 
                              nir_src_for_ssa(nir_ishl(b, intr->src[0].ssa,
113
 
                                                       nir_imm_int(b, 4))));
 
112
                              nir_src_for_ssa(nir_ishl_imm(b, intr->src[0].ssa,
 
113
                                                           4)));
114
114
}
115
115
 
116
116
static int
185
185
        if (location == VARYING_SLOT_LAYER) {
186
186
                assert(c->s->info.stage == MESA_SHADER_GEOMETRY);
187
187
                nir_ssa_def *header = nir_load_var(b, state->gs.header_var);
188
 
                header = nir_iand(b, header, nir_imm_int(b, 0xff00ffff));
 
188
                header = nir_iand_imm(b, header, 0xff00ffff);
189
189
 
190
190
                /* From the GLES 3.2 spec:
191
191
                 *
210
210
                nir_ssa_def *layer_id =
211
211
                        nir_bcsel(b, cond,
212
212
                                  nir_imm_int(b, 0),
213
 
                                  nir_ishl(b, src, nir_imm_int(b, 16)));
 
213
                                  nir_ishl_imm(b, src, 16));
214
214
                header = nir_ior(b, header, layer_id);
215
215
                nir_store_var(b, state->gs.header_var, header, 0x1);
216
216
        }
217
217
 
218
218
        /* Scalarize outputs if it hasn't happened already, since we want to
219
 
         * schedule each VPM write individually.  We can skip any outut
 
219
         * schedule each VPM write individually.  We can skip any output
220
220
         * components not read by the FS.
221
221
         */
222
222
        for (int i = 0; i < intr->num_components; i++) {
223
223
                int vpm_offset =
224
224
                        v3d_varying_slot_vpm_offset(c, location, start_comp + i);
225
225
 
 
226
                if (!(nir_intrinsic_write_mask(intr) & (1 << i)))
 
227
                        continue;
226
228
 
227
229
                if (vpm_offset == -1)
228
230
                        continue;
273
275
 
274
276
        /* Update VPM offset for next vertex output data and header */
275
277
        output_offset =
276
 
                nir_iadd(b, output_offset,
277
 
                            nir_imm_int(b, state->gs.output_vertex_data_size));
 
278
                nir_iadd_imm(b, output_offset,
 
279
                             state->gs.output_vertex_data_size);
278
280
 
279
 
        header_offset = nir_iadd(b, header_offset, nir_imm_int(b, 1));
 
281
        header_offset = nir_iadd_imm(b, header_offset, 1);
280
282
 
281
283
        /* Reset the New Primitive bit */
282
 
        header = nir_iand(b, header, nir_imm_int(b, 0xfffffffe));
 
284
        header = nir_iand_imm(b, header, 0xfffffffe);
283
285
 
284
286
        nir_store_var(b, state->gs.output_offset_var, output_offset, 0x1);
285
287
        nir_store_var(b, state->gs.header_offset_var, header_offset, 0x1);
304
306
 * doesn't provide means to do that, so we need to apply the swizzle in the
305
307
 * vertex shader.
306
308
 *
307
 
 * This is required at least in Vulkan to support madatory vertex attribute
 
309
 * This is required at least in Vulkan to support mandatory vertex attribute
308
310
 * format VK_FORMAT_B8G8R8A8_UNORM.
309
311
 */
310
312
static void
371
373
                        break;
372
374
                }
373
375
                if (c->fs_key->point_coord_upper_left && comp == 1)
374
 
                        result = nir_fsub(b, nir_imm_float(b, 1.0), result);
 
376
                        result = nir_fsub_imm(b, 1.0, result);
375
377
                if (result != &intr->dest.ssa) {
376
378
                        nir_ssa_def_rewrite_uses_after(&intr->dest.ssa,
377
379
                                                       result,
679
681
         * have a variable just to keep track of the number of vertices we
680
682
         * emitted and instead we can just compute it here from the header
681
683
         * offset variable by removing the one generic header slot that always
682
 
         * goes at the begining of out header.
 
684
         * goes at the beginning of out header.
683
685
         */
684
686
        nir_ssa_def *header_offset =
685
687
                nir_load_var(b, state->gs.header_offset_var);
686
688
        nir_ssa_def *vertex_count =
687
 
                nir_isub(b, header_offset, nir_imm_int(b, 1));
 
689
                nir_iadd_imm(b, header_offset, -1);
688
690
        nir_ssa_def *header =
689
 
                nir_ior(b, nir_imm_int(b, state->gs.output_header_size),
690
 
                           nir_ishl(b, vertex_count,
691
 
                                    nir_imm_int(b, VERTEX_COUNT_OFFSET)));
 
691
                nir_ior_imm(b,
 
692
                            nir_ishl_imm(b, vertex_count,
 
693
                                         VERTEX_COUNT_OFFSET),
 
694
                            state->gs.output_header_size);
692
695
 
693
696
        v3d_nir_store_output(b, 0, NULL, header);
694
697
}
713
716
                unreachable("Unsupported shader stage");
714
717
        }
715
718
 
716
 
        nir_foreach_function(function, s) {
717
 
                if (function->impl) {
718
 
                        nir_builder b;
719
 
                        nir_builder_init(&b, function->impl);
720
 
 
721
 
                        if (c->s->info.stage == MESA_SHADER_GEOMETRY)
722
 
                                emit_gs_prolog(c, &b, function->impl, &state);
723
 
 
724
 
                        nir_foreach_block(block, function->impl) {
725
 
                                nir_foreach_instr_safe(instr, block)
726
 
                                        v3d_nir_lower_io_instr(c, &b, instr,
727
 
                                                               &state);
728
 
                        }
729
 
 
730
 
                        nir_block *last = nir_impl_last_block(function->impl);
731
 
                        b.cursor = nir_after_block(last);
732
 
                        if (s->info.stage == MESA_SHADER_VERTEX) {
733
 
                                v3d_nir_emit_ff_vpm_outputs(c, &b, &state);
734
 
                        } else if (s->info.stage == MESA_SHADER_GEOMETRY) {
735
 
                                emit_gs_vpm_output_header_prolog(c, &b, &state);
736
 
                        }
737
 
 
738
 
                        nir_metadata_preserve(function->impl,
739
 
                                              nir_metadata_block_index |
740
 
                                              nir_metadata_dominance);
741
 
                }
 
719
        nir_foreach_function_impl(impl, s) {
 
720
                nir_builder b = nir_builder_create(impl);
 
721
 
 
722
                if (c->s->info.stage == MESA_SHADER_GEOMETRY)
 
723
                        emit_gs_prolog(c, &b, impl, &state);
 
724
 
 
725
                nir_foreach_block(block, impl) {
 
726
                        nir_foreach_instr_safe(instr, block)
 
727
                                v3d_nir_lower_io_instr(c, &b, instr,
 
728
                                                       &state);
 
729
                }
 
730
 
 
731
                nir_block *last = nir_impl_last_block(impl);
 
732
                b.cursor = nir_after_block(last);
 
733
                if (s->info.stage == MESA_SHADER_VERTEX) {
 
734
                        v3d_nir_emit_ff_vpm_outputs(c, &b, &state);
 
735
                } else if (s->info.stage == MESA_SHADER_GEOMETRY) {
 
736
                        emit_gs_vpm_output_header_prolog(c, &b, &state);
 
737
                }
 
738
 
 
739
                nir_metadata_preserve(impl,
 
740
                                      nir_metadata_block_index |
 
741
                                      nir_metadata_dominance);
742
742
        }
743
743
 
744
744
        if (s->info.stage == MESA_SHADER_VERTEX ||