~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/gallium/drivers/vc4/vc4_nir_lower_blend.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:
83
83
                if (channel != 3) {
84
84
                        return nir_fmin(b,
85
85
                                        src[3],
86
 
                                        nir_fsub(b,
87
 
                                                 nir_imm_float(b, 1.0),
88
 
                                                 dst[3]));
 
86
                                        nir_fsub_imm(b, 1.0,
 
87
                                                     dst[3]));
89
88
                } else {
90
89
                        return nir_imm_float(b, 1.0);
91
90
                }
99
98
        case PIPE_BLENDFACTOR_ZERO:
100
99
                return nir_imm_float(b, 0.0);
101
100
        case PIPE_BLENDFACTOR_INV_SRC_COLOR:
102
 
                return nir_fsub(b, nir_imm_float(b, 1.0), src[channel]);
 
101
                return nir_fsub_imm(b, 1.0, src[channel]);
103
102
        case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
104
 
                return nir_fsub(b, nir_imm_float(b, 1.0), src[3]);
 
103
                return nir_fsub_imm(b, 1.0, src[3]);
105
104
        case PIPE_BLENDFACTOR_INV_DST_ALPHA:
106
 
                return nir_fsub(b, nir_imm_float(b, 1.0), dst[3]);
 
105
                return nir_fsub_imm(b, 1.0, dst[3]);
107
106
        case PIPE_BLENDFACTOR_INV_DST_COLOR:
108
 
                return nir_fsub(b, nir_imm_float(b, 1.0), dst[channel]);
 
107
                return nir_fsub_imm(b, 1.0, dst[channel]);
109
108
        case PIPE_BLENDFACTOR_INV_CONST_COLOR:
110
 
                return nir_fsub(b, nir_imm_float(b, 1.0),
111
 
                                nir_load_system_value(b,
112
 
                                                      nir_intrinsic_load_blend_const_color_r_float +
113
 
                                                      channel,
114
 
                                                      0, 1, 32));
 
109
                return nir_fsub_imm(b, 1.0,
 
110
                                    nir_load_system_value(b,
 
111
                                                          nir_intrinsic_load_blend_const_color_r_float +
 
112
                                                          channel,
 
113
                                                          0, 1, 32));
115
114
        case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
116
 
                return nir_fsub(b, nir_imm_float(b, 1.0),
117
 
                                nir_load_blend_const_color_a_float(b));
 
115
                return nir_fsub_imm(b, 1.0,
 
116
                                    nir_load_blend_const_color_a_float(b));
118
117
 
119
118
        default:
120
119
        case PIPE_BLENDFACTOR_SRC1_COLOR:
133
132
{
134
133
        unsigned chan_mask = 0xff << (chan * 8);
135
134
        return nir_ior(b,
136
 
                       nir_iand(b, src0, nir_imm_int(b, ~chan_mask)),
137
 
                       nir_iand(b, src1, nir_imm_int(b, chan_mask)));
 
135
                       nir_iand_imm(b, src0, ~chan_mask),
 
136
                       nir_iand_imm(b, src1, chan_mask));
138
137
}
139
138
 
140
139
static nir_ssa_def *
286
285
static nir_ssa_def *
287
286
vc4_nir_splat(nir_builder *b, nir_ssa_def *src)
288
287
{
289
 
        nir_ssa_def *or1 = nir_ior(b, src, nir_ishl(b, src, nir_imm_int(b, 8)));
290
 
        return nir_ior(b, or1, nir_ishl(b, or1, nir_imm_int(b, 16)));
 
288
        nir_ssa_def *or1 = nir_ior(b, src, nir_ishl_imm(b, src, 8));
 
289
        return nir_ior(b, or1, nir_ishl_imm(b, or1, 16));
291
290
}
292
291
 
293
292
static nir_ssa_def *
302
301
 
303
302
        enum pipe_format color_format = c->fs_key->color_format;
304
303
        const uint8_t *format_swiz = vc4_get_format_swizzle(color_format);
305
 
        nir_ssa_def *imm_0xff = nir_imm_int(b, 0xff);
306
304
        nir_ssa_def *src_a = nir_pack_unorm_4x8(b, src_float_a);
307
305
        nir_ssa_def *dst_a;
308
306
        int alpha_chan;
311
309
                        break;
312
310
        }
313
311
        if (alpha_chan != 4) {
314
 
                nir_ssa_def *shift = nir_imm_int(b, alpha_chan * 8);
315
 
                dst_a = vc4_nir_splat(b, nir_iand(b, nir_ushr(b, dst_color,
316
 
                                                              shift), imm_0xff));
 
312
                dst_a = vc4_nir_splat(b, nir_iand_imm(b, nir_ushr_imm(b, dst_color,
 
313
                                                                     alpha_chan * 8),
 
314
                                                      0xff));
317
315
        } else {
318
316
                dst_a = nir_imm_int(b, ~0);
319
317
        }
499
497
        }
500
498
 
501
499
        return nir_ior(b,
502
 
                       nir_iand(b, packed_color,
503
 
                                nir_imm_int(b, colormask)),
504
 
                       nir_iand(b, packed_dst_color,
505
 
                                nir_imm_int(b, ~colormask)));
 
500
                       nir_iand_imm(b, packed_color, colormask),
 
501
                       nir_iand_imm(b, packed_dst_color, ~colormask));
506
502
}
507
503
 
508
504
static void
531
527
                /* XXX: We should do a nice dither based on the fragment
532
528
                 * coordinate, instead.
533
529
                 */
534
 
                nir_ssa_def *num_samples = nir_imm_float(b, VC4_MAX_SAMPLES);
535
 
                nir_ssa_def *num_bits = nir_f2i32(b, nir_fmul(b, a, num_samples));
536
 
                nir_ssa_def *bitmask = nir_isub(b,
537
 
                                                nir_ishl(b,
538
 
                                                         nir_imm_int(b, 1),
539
 
                                                         num_bits),
540
 
                                                nir_imm_int(b, 1));
 
530
                nir_ssa_def *num_bits = nir_f2i32(b, nir_fmul_imm(b, a, VC4_MAX_SAMPLES));
 
531
                nir_ssa_def *bitmask = nir_iadd_imm(b,
 
532
                                                    nir_ishl(b,
 
533
                                                             nir_imm_int(b, 1),
 
534
                                                             num_bits),
 
535
                                                    -1);
541
536
                vc4_nir_store_sample_mask(c, b, bitmask);
542
537
        }
543
538
 
594
589
                        continue;
595
590
                }
596
591
 
597
 
                nir_function_impl *impl =
598
 
                        nir_cf_node_get_function(&block->cf_node);
599
 
                nir_builder b;
600
 
                nir_builder_init(&b, impl);
601
 
                b.cursor = nir_before_instr(&intr->instr);
 
592
                nir_builder b = nir_builder_at(nir_before_instr(&intr->instr));
602
593
                vc4_nir_lower_blend_instr(c, &b, intr);
603
594
        }
604
595
        return true;
607
598
void
608
599
vc4_nir_lower_blend(nir_shader *s, struct vc4_compile *c)
609
600
{
610
 
        nir_foreach_function(function, s) {
611
 
                if (function->impl) {
612
 
                        nir_foreach_block(block, function->impl) {
613
 
                                vc4_nir_lower_blend_block(block, c);
614
 
                        }
615
 
 
616
 
                        nir_metadata_preserve(function->impl,
617
 
                                              nir_metadata_block_index |
618
 
                                              nir_metadata_dominance);
 
601
        nir_foreach_function_impl(impl, s) {
 
602
                nir_foreach_block(block, impl) {
 
603
                        vc4_nir_lower_blend_block(block, c);
619
604
                }
 
605
 
 
606
                nir_metadata_preserve(impl,
 
607
                                      nir_metadata_block_index |
 
608
                                      nir_metadata_dominance);
620
609
        }
621
610
 
622
611
        /* If we didn't do alpha-to-coverage on the output color, we still
624
613
         */
625
614
        if (c->fs_key->sample_coverage && !c->fs_key->sample_alpha_to_coverage) {
626
615
                nir_function_impl *impl = nir_shader_get_entrypoint(s);
627
 
                nir_builder b;
628
 
                nir_builder_init(&b, impl);
629
 
                b.cursor = nir_after_block(nir_impl_last_block(impl));
 
616
                nir_builder b = nir_builder_at(nir_after_block(nir_impl_last_block(impl)));
630
617
 
631
618
                vc4_nir_store_sample_mask(c, &b, nir_load_sample_mask_in(&b));
632
619
        }