~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/gallium/drivers/radeonsi/si_state.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:
1
1
/*
2
2
 * Copyright 2012 Advanced Micro Devices, Inc.
3
 
 * All Rights Reserved.
4
 
 *
5
 
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 
 * copy of this software and associated documentation files (the "Software"),
7
 
 * to deal in the Software without restriction, including without limitation
8
 
 * on the rights to use, copy, modify, merge, publish, distribute, sub
9
 
 * license, and/or sell copies of the Software, and to permit persons to whom
10
 
 * the Software is furnished to do so, subject to the following conditions:
11
 
 *
12
 
 * The above copyright notice and this permission notice (including the next
13
 
 * paragraph) shall be included in all copies or substantial portions of the
14
 
 * Software.
15
 
 *
16
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19
 
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20
 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
 
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 
3
 *
 
4
 * SPDX-License-Identifier: MIT
23
5
 */
24
6
 
25
7
#include "si_build_pm4.h"
90
72
   /* GFX9: Flush DFSM when CB_TARGET_MASK changes.
91
73
    * I think we don't have to do anything between IBs.
92
74
    */
93
 
   if (sctx->screen->dpbb_allowed && sctx->last_cb_target_mask != cb_target_mask) {
 
75
   if (sctx->screen->dpbb_allowed && sctx->last_cb_target_mask != cb_target_mask &&
 
76
       sctx->screen->pbb_context_states_per_bin > 1) {
94
77
      sctx->last_cb_target_mask = cb_target_mask;
95
78
 
96
79
      radeon_begin(cs);
452
435
   if (!blend)
453
436
      return NULL;
454
437
 
 
438
   si_pm4_clear_state(pm4, sctx->screen, false);
 
439
 
455
440
   blend->alpha_to_coverage = state->alpha_to_coverage;
456
441
   blend->alpha_to_one = state->alpha_to_one;
457
442
   blend->dual_src_blend = util_blend_state_is_dual(state, 0);
585
570
                            S_028760_ALPHA_SRC_OPT(srcA_opt) | S_028760_ALPHA_DST_OPT(dstA_opt) |
586
571
                            S_028760_ALPHA_COMB_FCN(si_translate_blend_opt_function(eqA));
587
572
 
 
573
      /* Alpha-to-coverage with blending enabled, depth writes enabled, and having no MRTZ export
 
574
       * should disable SX blend optimizations.
 
575
       *
 
576
       * TODO: Add a piglit test for this. It should fail on gfx11 without this.
 
577
       */
 
578
      if (sctx->gfx_level >= GFX11 && state->alpha_to_coverage && i == 0) {
 
579
         sx_mrt_blend_opt[0] = S_028760_COLOR_COMB_FCN(V_028760_OPT_COMB_NONE) |
 
580
                               S_028760_ALPHA_COMB_FCN(V_028760_OPT_COMB_NONE);
 
581
      }
 
582
 
588
583
      /* Set blend state. */
589
584
      blend_cntl |= S_028780_ENABLE(1);
590
585
      blend_cntl |= S_028780_COLOR_COMB_FCN(si_translate_blend_function(eqRGB));
642
637
   }
643
638
 
644
639
   si_pm4_set_reg(pm4, R_028808_CB_COLOR_CONTROL, color_control);
 
640
   si_pm4_finalize(pm4);
645
641
   return blend;
646
642
}
647
643
 
948
944
      return NULL;
949
945
   }
950
946
 
 
947
   si_pm4_clear_state(pm4, sscreen, false);
 
948
 
951
949
   rs->scissor_enable = state->scissor;
952
950
   rs->clip_halfz = state->clip_halfz;
953
951
   rs->two_side = state->light_twoside;
1081
1079
                                                   polygon_mode_enabled ||
1082
1080
                                                   rs->perpendicular_end_caps : 0));
1083
1081
 
 
1082
   if (sscreen->info.gfx_level >= GFX10) {
 
1083
      si_pm4_set_reg(pm4, R_028838_PA_CL_NGG_CNTL,
 
1084
                     S_028838_INDEX_BUF_EDGE_FLAG_ENA(rs->polygon_mode_is_points ||
 
1085
                                                      rs->polygon_mode_is_lines) |
 
1086
                     S_028838_VERTEX_REUSE_DEPTH(sscreen->info.gfx_level >= GFX10_3 ? 30 : 0));
 
1087
   }
 
1088
 
1084
1089
   if (state->bottom_edge_rule) {
1085
1090
      /* OpenGL windows should set this. */
1086
1091
      si_pm4_set_reg(pm4, R_028230_PA_SC_EDGERULE,
1102
1107
                     S_028230_ER_LINE_TB(0xA) |
1103
1108
                     S_028230_ER_LINE_BT(0xA));
1104
1109
   }
 
1110
   si_pm4_finalize(pm4);
1105
1111
 
1106
1112
   if (!rs->uses_poly_offset)
1107
1113
      return rs;
1119
1125
      float offset_scale = state->offset_scale * 16.0f;
1120
1126
      uint32_t pa_su_poly_offset_db_fmt_cntl = 0;
1121
1127
 
 
1128
      si_pm4_clear_state(pm4, sscreen, false);
 
1129
 
1122
1130
      if (!state->offset_units_unscaled) {
1123
1131
         switch (i) {
1124
1132
         case 0: /* 16-bit zbuffer */
1143
1151
      si_pm4_set_reg(pm4, R_028B84_PA_SU_POLY_OFFSET_FRONT_OFFSET, fui(offset_units));
1144
1152
      si_pm4_set_reg(pm4, R_028B88_PA_SU_POLY_OFFSET_BACK_SCALE, fui(offset_scale));
1145
1153
      si_pm4_set_reg(pm4, R_028B8C_PA_SU_POLY_OFFSET_BACK_OFFSET, fui(offset_units));
 
1154
      si_pm4_finalize(pm4);
1146
1155
   }
1147
1156
 
1148
1157
   return rs;
1158
1167
      rs = (struct si_state_rasterizer *)sctx->discard_rasterizer_state;
1159
1168
 
1160
1169
   if (old_rs->multisample_enable != rs->multisample_enable) {
1161
 
      si_mark_atom_dirty(sctx, &sctx->atoms.s.db_render_state);
1162
1170
      si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
1163
1171
 
1164
1172
      /* Update the small primitive filter workaround if necessary. */
1165
 
      if (sctx->screen->info.has_msaa_sample_loc_bug && sctx->framebuffer.nr_samples > 1)
1166
 
         si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_sample_locs);
 
1173
      if (sctx->screen->info.has_small_prim_filter_sample_loc_bug && sctx->framebuffer.nr_samples > 1)
 
1174
         si_mark_atom_dirty(sctx, &sctx->atoms.s.sample_locations);
1167
1175
 
1168
1176
      /* NGG cull state uses multisample_enable. */
1169
1177
      if (sctx->screen->use_ngg_culling)
1338
1346
      return NULL;
1339
1347
   }
1340
1348
 
 
1349
   si_pm4_clear_state(pm4, (struct si_screen*)ctx->screen, false);
 
1350
 
1341
1351
   dsa->stencil_ref.valuemask[0] = state->stencil[0].valuemask;
1342
1352
   dsa->stencil_ref.valuemask[1] = state->stencil[1].valuemask;
1343
1353
   dsa->stencil_ref.writemask[0] = state->stencil[0].writemask;
1387
1397
      si_pm4_set_reg(pm4, R_028020_DB_DEPTH_BOUNDS_MIN, fui(state->depth_bounds_min));
1388
1398
      si_pm4_set_reg(pm4, R_028024_DB_DEPTH_BOUNDS_MAX, fui(state->depth_bounds_max));
1389
1399
   }
 
1400
   si_pm4_finalize(pm4);
1390
1401
 
1391
1402
   dsa->depth_enabled = state->depth_enabled;
1392
1403
   dsa->depth_write_enabled = state->depth_enabled && state->depth_writemask;
1479
1490
 
1480
1491
   /* Pipeline stat & streamout queries. */
1481
1492
   if (enable) {
1482
 
      sctx->flags &= ~SI_CONTEXT_STOP_PIPELINE_STATS;
1483
 
      sctx->flags |= SI_CONTEXT_START_PIPELINE_STATS;
 
1493
      /* Disable pipeline stats if there are no active queries. */
 
1494
      if (sctx->num_hw_pipestat_streamout_queries) {
 
1495
         sctx->flags &= ~SI_CONTEXT_STOP_PIPELINE_STATS;
 
1496
         sctx->flags |= SI_CONTEXT_START_PIPELINE_STATS;
 
1497
      }
1484
1498
   } else {
1485
 
      sctx->flags &= ~SI_CONTEXT_START_PIPELINE_STATS;
1486
 
      sctx->flags |= SI_CONTEXT_STOP_PIPELINE_STATS;
 
1499
      if (sctx->num_hw_pipestat_streamout_queries) {
 
1500
         sctx->flags &= ~SI_CONTEXT_START_PIPELINE_STATS;
 
1501
         sctx->flags |= SI_CONTEXT_STOP_PIPELINE_STATS;
 
1502
      }
1487
1503
   }
1488
1504
 
1489
1505
   /* Occlusion queries. */
1515
1531
 
1516
1532
static void si_emit_db_render_state(struct si_context *sctx)
1517
1533
{
1518
 
   struct si_state_rasterizer *rs = sctx->queued.named.rasterizer;
1519
1534
   unsigned db_shader_control, db_render_control, db_count_control, vrs_override_cntl = 0;
1520
1535
 
1521
1536
   /* DB_RENDER_CONTROL */
1583
1598
 
1584
1599
   db_shader_control = sctx->ps_db_shader_control;
1585
1600
 
1586
 
   /* Disable the gl_SampleMask fragment shader output if MSAA is disabled. */
1587
 
   if (!rs->multisample_enable)
1588
 
      db_shader_control &= C_02880C_MASK_EXPORT_ENABLE;
1589
 
 
1590
1601
   if (sctx->screen->info.has_export_conflict_bug &&
1591
1602
       sctx->queued.named.blend->blend_enable_4bit &&
1592
1603
       si_get_num_coverage_samples(sctx) == 1) {
1652
1663
/*
1653
1664
 * format translation
1654
1665
 */
1655
 
uint32_t si_translate_colorformat(enum amd_gfx_level gfx_level,
1656
 
                                  enum pipe_format format)
1657
 
{
1658
 
   const struct util_format_description *desc = util_format_description(format);
1659
 
 
1660
 
#define HAS_SIZE(x, y, z, w)                                                                       \
1661
 
   (desc->channel[0].size == (x) && desc->channel[1].size == (y) &&                                \
1662
 
    desc->channel[2].size == (z) && desc->channel[3].size == (w))
1663
 
 
1664
 
   if (format == PIPE_FORMAT_R11G11B10_FLOAT) /* isn't plain */
1665
 
      return V_028C70_COLOR_10_11_11;
1666
 
 
1667
 
   if (gfx_level >= GFX10_3 &&
1668
 
       format == PIPE_FORMAT_R9G9B9E5_FLOAT) /* isn't plain */
1669
 
      return V_028C70_COLOR_5_9_9_9;
1670
 
 
1671
 
   if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
1672
 
      return V_028C70_COLOR_INVALID;
1673
 
 
1674
 
   /* hw cannot support mixed formats (except depth/stencil, since
1675
 
    * stencil is not written to). */
1676
 
   if (desc->is_mixed && desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
1677
 
      return V_028C70_COLOR_INVALID;
1678
 
 
1679
 
   int first_non_void = util_format_get_first_non_void_channel(format);
1680
 
 
1681
 
   /* Reject SCALED formats because we don't implement them for CB. */
1682
 
   if (first_non_void >= 0 && first_non_void <= 3 &&
1683
 
       (desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_UNSIGNED ||
1684
 
        desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_SIGNED) &&
1685
 
       !desc->channel[first_non_void].normalized &&
1686
 
       !desc->channel[first_non_void].pure_integer)
1687
 
      return V_028C70_COLOR_INVALID;
1688
 
 
1689
 
   switch (desc->nr_channels) {
1690
 
   case 1:
1691
 
      switch (desc->channel[0].size) {
1692
 
      case 8:
1693
 
         return V_028C70_COLOR_8;
1694
 
      case 16:
1695
 
         return V_028C70_COLOR_16;
1696
 
      case 32:
1697
 
         return V_028C70_COLOR_32;
1698
 
      }
1699
 
      break;
1700
 
   case 2:
1701
 
      if (desc->channel[0].size == desc->channel[1].size) {
1702
 
         switch (desc->channel[0].size) {
1703
 
         case 8:
1704
 
            return V_028C70_COLOR_8_8;
1705
 
         case 16:
1706
 
            return V_028C70_COLOR_16_16;
1707
 
         case 32:
1708
 
            return V_028C70_COLOR_32_32;
1709
 
         }
1710
 
      } else if (HAS_SIZE(8, 24, 0, 0)) {
1711
 
         return V_028C70_COLOR_24_8;
1712
 
      } else if (HAS_SIZE(24, 8, 0, 0)) {
1713
 
         return V_028C70_COLOR_8_24;
1714
 
      }
1715
 
      break;
1716
 
   case 3:
1717
 
      if (HAS_SIZE(5, 6, 5, 0)) {
1718
 
         return V_028C70_COLOR_5_6_5;
1719
 
      } else if (HAS_SIZE(32, 8, 24, 0)) {
1720
 
         return V_028C70_COLOR_X24_8_32_FLOAT;
1721
 
      }
1722
 
      break;
1723
 
   case 4:
1724
 
      if (desc->channel[0].size == desc->channel[1].size &&
1725
 
          desc->channel[0].size == desc->channel[2].size &&
1726
 
          desc->channel[0].size == desc->channel[3].size) {
1727
 
         switch (desc->channel[0].size) {
1728
 
         case 4:
1729
 
            return V_028C70_COLOR_4_4_4_4;
1730
 
         case 8:
1731
 
            return V_028C70_COLOR_8_8_8_8;
1732
 
         case 16:
1733
 
            return V_028C70_COLOR_16_16_16_16;
1734
 
         case 32:
1735
 
            return V_028C70_COLOR_32_32_32_32;
1736
 
         }
1737
 
      } else if (HAS_SIZE(5, 5, 5, 1)) {
1738
 
         return V_028C70_COLOR_1_5_5_5;
1739
 
      } else if (HAS_SIZE(1, 5, 5, 5)) {
1740
 
         return V_028C70_COLOR_5_5_5_1;
1741
 
      } else if (HAS_SIZE(10, 10, 10, 2)) {
1742
 
         return V_028C70_COLOR_2_10_10_10;
1743
 
      } else if (HAS_SIZE(2, 10, 10, 10)) {
1744
 
         return V_028C70_COLOR_10_10_10_2;
1745
 
      }
1746
 
      break;
1747
 
   }
1748
 
   return V_028C70_COLOR_INVALID;
1749
 
}
1750
1666
 
1751
1667
static uint32_t si_colorformat_endian_swap(uint32_t colorformat)
1752
1668
{
2368
2284
 
2369
2285
   if (sscreen->info.gfx_level >= GFX10) {
2370
2286
      const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&sscreen->info)[format];
2371
 
      if (!fmt->img_format || fmt->img_format >= 128)
 
2287
      unsigned first_image_only_format = sscreen->info.gfx_level >= GFX11 ? 64 : 128;
 
2288
 
 
2289
      if (!fmt->img_format || fmt->img_format >= first_image_only_format)
2372
2290
         return 0;
2373
2291
      return usage;
2374
2292
   }
2384
2302
static bool si_is_colorbuffer_format_supported(enum amd_gfx_level gfx_level,
2385
2303
                                               enum pipe_format format)
2386
2304
{
2387
 
   return si_translate_colorformat(gfx_level, format) != V_028C70_COLOR_INVALID &&
 
2305
   return ac_get_cb_format(gfx_level, format) != V_028C70_COLOR_INVALID &&
2388
2306
          si_translate_colorswap(gfx_level, format, false) != ~0U;
2389
2307
}
2390
2308
 
2516
2434
   struct si_texture *tex = (struct si_texture *)surf->base.texture;
2517
2435
   unsigned format, swap, ntype, endian;
2518
2436
   const struct util_format_description *desc;
2519
 
   int firstchan;
2520
2437
   unsigned blend_clamp = 0, blend_bypass = 0;
2521
2438
 
2522
2439
   desc = util_format_description(surf->base.format);
2523
 
   firstchan = util_format_get_first_non_void_channel(surf->base.format);
2524
 
   if (firstchan == -1 || desc->channel[firstchan].type == UTIL_FORMAT_TYPE_FLOAT) {
2525
 
      ntype = V_028C70_NUMBER_FLOAT;
2526
 
   } else {
2527
 
      ntype = V_028C70_NUMBER_UNORM;
2528
 
      if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
2529
 
         ntype = V_028C70_NUMBER_SRGB;
2530
 
      else if (desc->channel[firstchan].type == UTIL_FORMAT_TYPE_SIGNED) {
2531
 
         if (desc->channel[firstchan].pure_integer) {
2532
 
            ntype = V_028C70_NUMBER_SINT;
2533
 
         } else {
2534
 
            assert(desc->channel[firstchan].normalized);
2535
 
            ntype = V_028C70_NUMBER_SNORM;
2536
 
         }
2537
 
      } else if (desc->channel[firstchan].type == UTIL_FORMAT_TYPE_UNSIGNED) {
2538
 
         if (desc->channel[firstchan].pure_integer) {
2539
 
            ntype = V_028C70_NUMBER_UINT;
2540
 
         } else {
2541
 
            assert(desc->channel[firstchan].normalized);
2542
 
            ntype = V_028C70_NUMBER_UNORM;
2543
 
         }
2544
 
      }
2545
 
   }
2546
 
 
2547
 
   format = si_translate_colorformat(sctx->gfx_level, surf->base.format);
 
2440
 
 
2441
   ntype = ac_get_cb_number_type(surf->base.format);
 
2442
   format = ac_get_cb_format(sctx->gfx_level, surf->base.format);
 
2443
 
2548
2444
   if (format == V_028C70_COLOR_INVALID) {
2549
2445
      PRINT_ERR("Invalid CB format: %d, disabling CB.\n", surf->base.format);
2550
2446
   }
2597
2493
                         S_028C70_ROUND_MODE(round_mode) |
2598
2494
                         S_028C70_NUMBER_TYPE(ntype);
2599
2495
 
 
2496
   unsigned width0 = surf->width0;
 
2497
 
 
2498
   /* GFX10.3+ can set a custom pitch for 1D and 2D non-array, but it must be a multiple
 
2499
    * of 256B. Only set it for 2D linear for multi-GPU interop.
 
2500
    *
 
2501
    * We set the pitch in MIP0_WIDTH.
 
2502
    */
 
2503
   if (sctx->gfx_level >= GFX10_3 &&
 
2504
       (tex->buffer.b.b.target == PIPE_TEXTURE_2D ||
 
2505
        tex->buffer.b.b.target == PIPE_TEXTURE_RECT) &&
 
2506
       tex->surface.is_linear) {
 
2507
      assert((tex->surface.u.gfx9.surf_pitch * tex->surface.bpe) % 256 == 0);
 
2508
 
 
2509
      width0 = tex->surface.u.gfx9.surf_pitch;
 
2510
 
 
2511
      /* Subsampled images have the pitch in the units of blocks. */
 
2512
      if (tex->surface.blk_w == 2)
 
2513
         width0 *= 2;
 
2514
   }
 
2515
 
2600
2516
   if (sctx->gfx_level >= GFX10) {
2601
2517
      /* Gfx10-11. */
2602
2518
      surf->cb_color_view = S_028C6C_SLICE_START(surf->base.u.tex.first_layer) |
2603
2519
                            S_028C6C_SLICE_MAX_GFX10(surf->base.u.tex.last_layer) |
2604
2520
                            S_028C6C_MIP_LEVEL_GFX10(surf->base.u.tex.level);
2605
2521
      surf->cb_color_attrib = 0;
2606
 
      surf->cb_color_attrib2 = S_028C68_MIP0_WIDTH(surf->width0 - 1) |
 
2522
      surf->cb_color_attrib2 = S_028C68_MIP0_WIDTH(width0 - 1) |
2607
2523
                               S_028C68_MIP0_HEIGHT(surf->height0 - 1) |
2608
2524
                               S_028C68_MAX_MIP(tex->buffer.b.b.last_level);
2609
2525
      surf->cb_color_attrib3 = S_028EE0_MIP0_DEPTH(util_max_layer(&tex->buffer.b.b, 0)) |
3149
3065
         break;
3150
3066
      case 2:
3151
3067
         constbuf.buffer_offset =
3152
 
            (ubyte *)sctx->sample_positions.x2 - (ubyte *)sctx->sample_positions.x1;
 
3068
            (uint8_t *)sctx->sample_positions.x2 - (uint8_t *)sctx->sample_positions.x1;
3153
3069
         break;
3154
3070
      case 4:
3155
3071
         constbuf.buffer_offset =
3156
 
            (ubyte *)sctx->sample_positions.x4 - (ubyte *)sctx->sample_positions.x1;
 
3072
            (uint8_t *)sctx->sample_positions.x4 - (uint8_t *)sctx->sample_positions.x1;
3157
3073
         break;
3158
3074
      case 8:
3159
3075
         constbuf.buffer_offset =
3160
 
            (ubyte *)sctx->sample_positions.x8 - (ubyte *)sctx->sample_positions.x1;
 
3076
            (uint8_t *)sctx->sample_positions.x8 - (uint8_t *)sctx->sample_positions.x1;
3161
3077
         break;
3162
3078
      case 16:
3163
3079
         constbuf.buffer_offset =
3164
 
            (ubyte *)sctx->sample_positions.x16 - (ubyte *)sctx->sample_positions.x1;
 
3080
            (uint8_t *)sctx->sample_positions.x16 - (uint8_t *)sctx->sample_positions.x1;
3165
3081
         break;
3166
3082
      default:
3167
3083
         PRINT_ERR("Requested an invalid number of samples %i.\n", sctx->framebuffer.nr_samples);
3170
3086
      constbuf.buffer_size = sctx->framebuffer.nr_samples * 2 * 4;
3171
3087
      si_set_internal_const_buffer(sctx, SI_PS_CONST_SAMPLE_POSITIONS, &constbuf);
3172
3088
 
3173
 
      si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_sample_locs);
 
3089
      si_mark_atom_dirty(sctx, &sctx->atoms.s.sample_locations);
3174
3090
   }
3175
3091
 
3176
3092
   si_ps_key_update_framebuffer(sctx);
3621
3537
      else
3622
3538
         radeon_set_context_reg_seq(R_028040_DB_Z_INFO, 2);
3623
3539
 
3624
 
      /* Gfx11 only: DB_Z_INFO.NUM_SAMPLES should always match the framebuffer samples.
3625
 
       * It affects VRS and occlusion queries if depth and stencil are not bound.
 
3540
      /* Gfx11+: DB_Z_INFO.NUM_SAMPLES should match the framebuffer samples if no Z/S is bound.
 
3541
       * It determines the sample count for VRS, primitive-ordered pixel shading, and occlusion
 
3542
       * queries.
3626
3543
       */
3627
3544
      radeon_emit(S_028040_FORMAT(V_028040_Z_INVALID) |       /* DB_Z_INFO */
3628
 
                  S_028040_NUM_SAMPLES(sctx->gfx_level == GFX11 ? sctx->framebuffer.log_samples : 0));
 
3545
                  S_028040_NUM_SAMPLES(sctx->gfx_level >= GFX11 ? sctx->framebuffer.log_samples : 0));
3629
3546
      radeon_emit(S_028044_FORMAT(V_028044_STENCIL_INVALID)); /* DB_STENCIL_INFO */
3630
3547
   }
3631
3548
 
3634
3551
   radeon_set_context_reg(R_028208_PA_SC_WINDOW_SCISSOR_BR,
3635
3552
                          S_028208_BR_X(state->width) | S_028208_BR_Y(state->height));
3636
3553
 
3637
 
   if (sctx->screen->dpbb_allowed) {
 
3554
   if (sctx->screen->dpbb_allowed &&
 
3555
       sctx->screen->pbb_context_states_per_bin > 1) {
3638
3556
      radeon_emit(PKT3(PKT3_EVENT_WRITE, 0, 0));
3639
3557
      radeon_emit(EVENT_TYPE(V_028A90_BREAK_BATCH) | EVENT_INDEX(0));
3640
3558
   }
3646
3564
   sctx->framebuffer.dirty_zsbuf = false;
3647
3565
}
3648
3566
 
3649
 
static void si_emit_msaa_sample_locs(struct si_context *sctx)
3650
 
{
3651
 
   struct radeon_cmdbuf *cs = &sctx->gfx_cs;
3652
 
   struct si_state_rasterizer *rs = sctx->queued.named.rasterizer;
3653
 
   unsigned nr_samples = sctx->framebuffer.nr_samples;
3654
 
   bool has_msaa_sample_loc_bug = sctx->screen->info.has_msaa_sample_loc_bug;
3655
 
 
3656
 
   /* Smoothing (only possible with nr_samples == 1) uses the same
3657
 
    * sample locations as the MSAA it simulates.
3658
 
    */
3659
 
   if (nr_samples <= 1 && sctx->smoothing_enabled)
3660
 
      nr_samples = SI_NUM_SMOOTH_AA_SAMPLES;
3661
 
 
3662
 
   /* On Polaris, the small primitive filter uses the sample locations
3663
 
    * even when MSAA is off, so we need to make sure they're set to 0.
3664
 
    *
3665
 
    * GFX10 uses sample locations unconditionally, so they always need
3666
 
    * to be set up.
3667
 
    */
3668
 
   if ((nr_samples >= 2 || has_msaa_sample_loc_bug || sctx->gfx_level >= GFX10) &&
3669
 
       nr_samples != sctx->sample_locs_num_samples) {
3670
 
      sctx->sample_locs_num_samples = nr_samples;
3671
 
      si_emit_sample_locations(cs, nr_samples);
3672
 
   }
3673
 
 
3674
 
   radeon_begin(cs);
3675
 
 
3676
 
   if (sctx->family >= CHIP_POLARIS10) {
3677
 
      unsigned small_prim_filter_cntl =
3678
 
         S_028830_SMALL_PRIM_FILTER_ENABLE(1) |
3679
 
         /* line bug */
3680
 
         S_028830_LINE_FILTER_DISABLE(sctx->family <= CHIP_POLARIS12);
3681
 
 
3682
 
      /* For hardware with the sample location bug, the problem is that in order to use the small
3683
 
       * primitive filter, we need to explicitly set the sample locations to 0. But the DB doesn't
3684
 
       * properly process the change of sample locations without a flush, and so we can end up
3685
 
       * with incorrect Z values.
3686
 
       *
3687
 
       * Instead of doing a flush, just disable the small primitive filter when MSAA is
3688
 
       * force-disabled.
3689
 
       *
3690
 
       * The alternative of setting sample locations to 0 would require a DB flush to avoid
3691
 
       * Z errors, see https://bugs.freedesktop.org/show_bug.cgi?id=96908
3692
 
       */
3693
 
      if (has_msaa_sample_loc_bug && sctx->framebuffer.nr_samples > 1 && !rs->multisample_enable)
3694
 
         small_prim_filter_cntl &= C_028830_SMALL_PRIM_FILTER_ENABLE;
3695
 
 
3696
 
      radeon_opt_set_context_reg(sctx, R_028830_PA_SU_SMALL_PRIM_FILTER_CNTL,
3697
 
                                 SI_TRACKED_PA_SU_SMALL_PRIM_FILTER_CNTL, small_prim_filter_cntl);
3698
 
   }
3699
 
 
3700
 
   /* The exclusion bits can be set to improve rasterization efficiency
3701
 
    * if no sample lies on the pixel boundary (-8 sample offset).
3702
 
    */
3703
 
   bool exclusion = sctx->gfx_level >= GFX7 && (!rs->multisample_enable || nr_samples != 16);
3704
 
   radeon_opt_set_context_reg(
3705
 
      sctx, R_02882C_PA_SU_PRIM_FILTER_CNTL, SI_TRACKED_PA_SU_PRIM_FILTER_CNTL,
3706
 
      S_02882C_XMAX_RIGHT_EXCLUSION(exclusion) | S_02882C_YMAX_BOTTOM_EXCLUSION(exclusion));
3707
 
   radeon_end();
3708
 
}
3709
 
 
3710
3567
static bool si_out_of_order_rasterization(struct si_context *sctx)
3711
3568
{
3712
3569
   struct si_state_blend *blend = sctx->queued.named.blend;
3846
3703
         4, /* 2x MSAA */
3847
3704
         6, /* 4x MSAA */
3848
3705
         7, /* 8x MSAA */
3849
 
         8, /* 16x MSAA */
 
3706
         7, /* 16x MSAA */
3850
3707
      };
3851
3708
      unsigned log_samples = util_logbase2(coverage_samples);
3852
3709
 
5218
5075
 
5219
5076
      if (sscreen->info.gfx_level >= GFX10) {
5220
5077
         const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&sscreen->info)[elements[i].src_format];
5221
 
         assert(fmt->img_format != 0 && fmt->img_format < 128);
 
5078
         unsigned last_vertex_format = sscreen->info.gfx_level >= GFX11 ? 64 : 128;
 
5079
         assert(fmt->img_format != 0 && fmt->img_format < last_vertex_format);
5222
5080
         v->rsrc_word3[i] |= S_008F0C_FORMAT(fmt->img_format) |
5223
5081
                             S_008F0C_RESOURCE_LEVEL(sscreen->info.gfx_level < GFX11);
5224
5082
      } else {
5561
5419
void si_init_state_functions(struct si_context *sctx)
5562
5420
{
5563
5421
   sctx->atoms.s.framebuffer.emit = si_emit_framebuffer_state;
5564
 
   sctx->atoms.s.msaa_sample_locs.emit = si_emit_msaa_sample_locs;
5565
5422
   sctx->atoms.s.db_render_state.emit = si_emit_db_render_state;
5566
5423
   sctx->atoms.s.dpbb_state.emit = si_emit_dpbb_state;
5567
5424
   sctx->atoms.s.msaa_config.emit = si_emit_msaa_config;
5700
5557
   return u_bit_consecutive(0, sscreen->info.min_good_cu_per_sa);
5701
5558
}
5702
5559
 
5703
 
void si_init_cs_preamble_state(struct si_context *sctx, bool uses_reg_shadowing)
 
5560
static void gfx6_init_gfx_preamble_state(struct si_context *sctx)
5704
5561
{
5705
5562
   struct si_screen *sscreen = sctx->screen;
5706
5563
   uint64_t border_color_va =
5709
5566
                            S_00B858_SH1_CU_EN(sscreen->info.spi_cu_en);
5710
5567
   bool has_clear_state = sscreen->info.has_clear_state;
5711
5568
 
5712
 
   struct si_cs_preamble {
5713
 
      struct si_pm4_state pm4;
5714
 
      uint32_t more_pm4[150]; /* Add more space because the preamble is large. */
5715
 
   };
5716
 
   struct si_pm4_state *pm4 = (struct si_pm4_state *)CALLOC_STRUCT(si_cs_preamble);
5717
 
 
 
5569
   /* We need more space because the preamble is large. */
 
5570
   struct si_pm4_state *pm4 = si_pm4_create_sized(sscreen, 214, sctx->has_graphics);
5718
5571
   if (!pm4)
5719
5572
      return;
5720
5573
 
5721
 
   /* Add all the space that we allocated. */
5722
 
   pm4->max_dw = (sizeof(struct si_cs_preamble) - offsetof(struct si_cs_preamble, pm4.pm4)) / 4;
5723
 
 
5724
 
   if (sctx->has_graphics && !uses_reg_shadowing) {
 
5574
   if (sctx->has_graphics && !sctx->shadowing.registers) {
5725
5575
      si_pm4_cmd_add(pm4, PKT3(PKT3_CONTEXT_CONTROL, 1, 0));
5726
5576
      si_pm4_cmd_add(pm4, CC0_UPDATE_LOAD_ENABLES(1));
5727
5577
      si_pm4_cmd_add(pm4, CC1_UPDATE_SHADOW_ENABLES(1));
5742
5592
   si_pm4_set_reg(pm4, R_00B858_COMPUTE_STATIC_THREAD_MGMT_SE0, compute_cu_en);
5743
5593
   si_pm4_set_reg(pm4, R_00B85C_COMPUTE_STATIC_THREAD_MGMT_SE1, compute_cu_en);
5744
5594
 
5745
 
   if (sctx->gfx_level == GFX6) {
5746
 
      /* This register has been moved to R_00CD20_COMPUTE_MAX_WAVE_ID and is now per pipe,
5747
 
       * so it should be handled in the kernel if we want to use something other than
5748
 
       * the default value.
5749
 
       * TODO: This should be: (number of compute units) * 4 * (waves per simd) - 1
5750
 
       */
5751
 
      si_pm4_set_reg(pm4, R_00B82C_COMPUTE_MAX_WAVE_ID, 0x190 /* Default value */);
5752
 
   }
5753
 
 
5754
5595
   if (sctx->gfx_level >= GFX7) {
5755
5596
      si_pm4_set_reg(pm4, R_00B864_COMPUTE_STATIC_THREAD_MGMT_SE2, compute_cu_en);
5756
5597
      si_pm4_set_reg(pm4, R_00B868_COMPUTE_STATIC_THREAD_MGMT_SE3, compute_cu_en);
5757
 
 
5758
 
      /* Disable profiling on compute chips. */
5759
 
      if (!sscreen->info.has_graphics) {
5760
 
         si_pm4_set_reg(pm4, R_00B82C_COMPUTE_PERFCOUNT_ENABLE, 0);
5761
 
         si_pm4_set_reg(pm4, R_00B878_COMPUTE_THREAD_TRACE_ENABLE, 0);
5762
 
      }
5763
 
   }
5764
 
 
5765
 
   if (!sscreen->info.has_graphics && sscreen->info.family >= CHIP_GFX940) {
5766
 
      si_pm4_set_reg(pm4, R_00B89C_COMPUTE_TG_CHUNK_SIZE, 0);
5767
 
      si_pm4_set_reg(pm4, R_00B8B4_COMPUTE_PGM_RSRC3, 0);
5768
 
   }
5769
 
 
5770
 
   if (sctx->gfx_level >= GFX9 && sctx->gfx_level < GFX11)
5771
 
      si_pm4_set_reg(pm4, R_0301EC_CP_COHER_START_DELAY, sctx->gfx_level >= GFX10 ? 0x20 : 0);
5772
 
 
5773
 
   if (sscreen->info.family == CHIP_MI100 ||
5774
 
       sscreen->info.family == CHIP_MI200) {
5775
 
      si_pm4_set_reg(pm4, R_00B894_COMPUTE_STATIC_THREAD_MGMT_SE4, compute_cu_en);
5776
 
      si_pm4_set_reg(pm4, R_00B898_COMPUTE_STATIC_THREAD_MGMT_SE5, compute_cu_en);
5777
 
      si_pm4_set_reg(pm4, R_00B89C_COMPUTE_STATIC_THREAD_MGMT_SE6, compute_cu_en);
5778
 
      si_pm4_set_reg(pm4, R_00B8A0_COMPUTE_STATIC_THREAD_MGMT_SE7, compute_cu_en);
5779
 
   }
5780
 
 
5781
 
   if (sctx->gfx_level >= GFX10) {
5782
 
      si_pm4_set_reg(pm4, R_00B890_COMPUTE_USER_ACCUM_0, 0);
5783
 
      si_pm4_set_reg(pm4, R_00B894_COMPUTE_USER_ACCUM_1, 0);
5784
 
      si_pm4_set_reg(pm4, R_00B898_COMPUTE_USER_ACCUM_2, 0);
5785
 
      si_pm4_set_reg(pm4, R_00B89C_COMPUTE_USER_ACCUM_3, 0);
5786
 
 
5787
 
      if (sctx->gfx_level < GFX11)
5788
 
         si_pm4_set_reg(pm4, R_00B8A0_COMPUTE_PGM_RSRC3, 0);
5789
 
 
5790
 
      si_pm4_set_reg(pm4, R_00B9F4_COMPUTE_DISPATCH_TUNNEL, 0);
5791
 
   }
5792
 
 
5793
 
   if (sctx->gfx_level >= GFX11) {
5794
 
      si_pm4_set_reg(pm4, R_00B8AC_COMPUTE_STATIC_THREAD_MGMT_SE4, compute_cu_en);
5795
 
      si_pm4_set_reg(pm4, R_00B8B0_COMPUTE_STATIC_THREAD_MGMT_SE5, compute_cu_en);
5796
 
      si_pm4_set_reg(pm4, R_00B8B4_COMPUTE_STATIC_THREAD_MGMT_SE6, compute_cu_en);
5797
 
      si_pm4_set_reg(pm4, R_00B8B8_COMPUTE_STATIC_THREAD_MGMT_SE7, compute_cu_en);
5798
 
 
5799
 
      /* How many threads should go to 1 SE before moving onto the next. Think of GL1 cache hits.
5800
 
       * Only these values are valid: 0 (disabled), 64, 128, 256, 512
5801
 
       * Recommendation: 64 = RT, 256 = non-RT (run benchmarks to be sure)
5802
 
       */
5803
 
      si_pm4_set_reg(pm4, R_00B8BC_COMPUTE_DISPATCH_INTERLEAVE, S_00B8BC_INTERLEAVE(256));
5804
 
   }
 
5598
   }
 
5599
 
 
5600
   if (sctx->gfx_level >= GFX9)
 
5601
      si_pm4_set_reg(pm4, R_0301EC_CP_COHER_START_DELAY, 0);
5805
5602
 
5806
5603
   /* Set the pointer to border colors. MI200 doesn't support border colors. */
5807
5604
   if (sctx->gfx_level >= GFX7 && sctx->border_color_buffer) {
5833
5630
      si_pm4_set_reg(pm4, R_02800C_DB_RENDER_OVERRIDE, 0);
5834
5631
      si_pm4_set_reg(pm4, R_028A8C_VGT_PRIMITIVEID_RESET, 0x0);
5835
5632
 
5836
 
      if (sctx->gfx_level < GFX11) {
5837
 
         si_pm4_set_reg(pm4, R_028B98_VGT_STRMOUT_BUFFER_CONFIG, 0x0);
5838
 
         si_pm4_set_reg(pm4, R_028A5C_VGT_GS_PER_VS, 0x2);
5839
 
         si_pm4_set_reg(pm4, R_028AB8_VGT_VTX_CNT_EN, 0x0);
5840
 
      }
 
5633
      si_pm4_set_reg(pm4, R_028B98_VGT_STRMOUT_BUFFER_CONFIG, 0x0);
 
5634
      si_pm4_set_reg(pm4, R_028A5C_VGT_GS_PER_VS, 0x2);
 
5635
      si_pm4_set_reg(pm4, R_028AB8_VGT_VTX_CNT_EN, 0x0);
5841
5636
   }
5842
5637
 
5843
5638
   si_pm4_set_reg(pm4, R_028080_TA_BC_BASE_ADDR, border_color_va >> 8);
5857
5652
      si_pm4_set_reg(pm4, R_008B10_PA_SC_LINE_STIPPLE_STATE, 0);
5858
5653
   }
5859
5654
 
 
5655
   /* If any sample location uses the -8 coordinate, the EXCLUSION fields should be set to 0. */
 
5656
   si_pm4_set_reg(pm4, R_02882C_PA_SU_PRIM_FILTER_CNTL,
 
5657
                  S_02882C_XMAX_RIGHT_EXCLUSION(sctx->gfx_level >= GFX7) |
 
5658
                  S_02882C_YMAX_BOTTOM_EXCLUSION(sctx->gfx_level >= GFX7));
 
5659
 
 
5660
   if (sctx->family >= CHIP_POLARIS10 && !sctx->screen->info.has_small_prim_filter_sample_loc_bug) {
 
5661
      /* Polaris10-12 should disable small line culling, but those also have the sample loc bug,
 
5662
       * so they never enter this branch.
 
5663
       */
 
5664
      assert(sctx->family > CHIP_POLARIS12);
 
5665
      si_pm4_set_reg(pm4, R_028830_PA_SU_SMALL_PRIM_FILTER_CNTL,
 
5666
                     S_028830_SMALL_PRIM_FILTER_ENABLE(1));
 
5667
   }
 
5668
 
5860
5669
   if (sctx->gfx_level <= GFX7 || !has_clear_state) {
5861
 
      if (sctx->gfx_level < GFX11) {
5862
 
         si_pm4_set_reg(pm4, R_028C58_VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
5863
 
         si_pm4_set_reg(pm4, R_028C5C_VGT_OUT_DEALLOC_CNTL, 16);
5864
 
      }
 
5670
      si_pm4_set_reg(pm4, R_028C58_VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
 
5671
      si_pm4_set_reg(pm4, R_028C5C_VGT_OUT_DEALLOC_CNTL, 16);
5865
5672
 
5866
5673
      /* CLEAR_STATE doesn't clear these correctly on certain generations.
5867
5674
       * I don't know why. Deduced by trial and error.
5873
5680
                     S_028034_BR_X(16384) | S_028034_BR_Y(16384));
5874
5681
   }
5875
5682
 
5876
 
   if (sctx->gfx_level >= GFX10 && sctx->gfx_level < GFX11) {
5877
 
      si_pm4_set_reg(pm4, R_028038_DB_DFSM_CONTROL,
5878
 
                     S_028038_PUNCHOUT_MODE(V_028038_FORCE_OFF) |
5879
 
                     S_028038_POPS_DRAIN_PS_ON_OVERLAP(1));
5880
 
   }
5881
 
 
5882
 
   unsigned cu_mask_ps = 0xffffffff;
5883
 
 
5884
 
   if (sctx->gfx_level >= GFX10_3)
5885
 
      cu_mask_ps = gfx103_get_cu_mask_ps(sscreen);
5886
 
 
5887
5683
   if (sctx->gfx_level >= GFX7) {
5888
 
      si_pm4_set_reg_idx3(sscreen, pm4, R_00B01C_SPI_SHADER_PGM_RSRC3_PS,
5889
 
                          ac_apply_cu_en(S_00B01C_CU_EN(cu_mask_ps) |
5890
 
                                         S_00B01C_WAVE_LIMIT(0x3F) |
5891
 
                                         S_00B01C_LDS_GROUP_SIZE(sctx->gfx_level >= GFX11),
 
5684
      si_pm4_set_reg_idx3(pm4, R_00B01C_SPI_SHADER_PGM_RSRC3_PS,
 
5685
                          ac_apply_cu_en(S_00B01C_CU_EN(0xffffffff) |
 
5686
                                         S_00B01C_WAVE_LIMIT(0x3F),
5892
5687
                                         C_00B01C_CU_EN, 0, &sscreen->info));
5893
5688
   }
5894
5689
 
5908
5703
      si_pm4_set_reg(pm4, R_028408_VGT_INDX_OFFSET, 0);
5909
5704
   }
5910
5705
 
5911
 
   if (sscreen->info.gfx_level >= GFX10) {
5912
 
      si_pm4_set_reg(pm4, R_00B524_SPI_SHADER_PGM_HI_LS,
5913
 
                     S_00B524_MEM_BASE(sscreen->info.address32_hi >> 8));
5914
 
      si_pm4_set_reg(pm4, R_00B324_SPI_SHADER_PGM_HI_ES,
5915
 
                     S_00B324_MEM_BASE(sscreen->info.address32_hi >> 8));
5916
 
   } else if (sscreen->info.gfx_level == GFX9) {
 
5706
   if (sscreen->info.gfx_level == GFX9) {
5917
5707
      si_pm4_set_reg(pm4, R_00B414_SPI_SHADER_PGM_HI_LS,
5918
5708
                     S_00B414_MEM_BASE(sscreen->info.address32_hi >> 8));
5919
5709
      si_pm4_set_reg(pm4, R_00B214_SPI_SHADER_PGM_HI_ES,
5943
5733
   if (sctx->gfx_level >= GFX8) {
5944
5734
      unsigned vgt_tess_distribution;
5945
5735
 
5946
 
      if (sctx->gfx_level >= GFX11) {
5947
 
         /* ACCUM fields changed their meaning. */
5948
 
         vgt_tess_distribution = S_028B50_ACCUM_ISOLINE(128) |
5949
 
                                 S_028B50_ACCUM_TRI(128) |
5950
 
                                 S_028B50_ACCUM_QUAD(128) |
5951
 
                                 S_028B50_DONUT_SPLIT_GFX9(24) |
5952
 
                                 S_028B50_TRAP_SPLIT(6);
5953
 
      } else if (sctx->gfx_level >= GFX9) {
 
5736
      if (sctx->gfx_level == GFX9) {
5954
5737
         vgt_tess_distribution = S_028B50_ACCUM_ISOLINE(12) |
5955
5738
                                 S_028B50_ACCUM_TRI(30) |
5956
5739
                                 S_028B50_ACCUM_QUAD(24) |
5957
5740
                                 S_028B50_DONUT_SPLIT_GFX9(24) |
5958
5741
                                 S_028B50_TRAP_SPLIT(6);
5959
 
      } else if (sctx->gfx_level == GFX8) {
 
5742
      } else {
5960
5743
         vgt_tess_distribution = S_028B50_ACCUM_ISOLINE(32) |
5961
5744
                                 S_028B50_ACCUM_TRI(11) |
5962
5745
                                 S_028B50_ACCUM_QUAD(11) |
5963
5746
                                 S_028B50_DONUT_SPLIT_GFX81(16);
5964
5747
 
5965
 
         /* Testing with Unigine Heaven extreme tesselation yielded best results
 
5748
         /* Testing with Unigine Heaven extreme tessellation yielded best results
5966
5749
          * with TRAP_SPLIT = 3.
5967
5750
          */
5968
5751
         if (sctx->family == CHIP_FIJI || sctx->family >= CHIP_POLARIS10)
5972
5755
      si_pm4_set_reg(pm4, R_028B50_VGT_TESS_DISTRIBUTION, vgt_tess_distribution);
5973
5756
   }
5974
5757
 
5975
 
   if (sscreen->info.gfx_level <= GFX9) {
5976
 
      si_pm4_set_reg(pm4, R_028AA0_VGT_INSTANCE_STEP_RATE_0, 1);
5977
 
   }
 
5758
   si_pm4_set_reg(pm4, R_028AA0_VGT_INSTANCE_STEP_RATE_0, 1);
5978
5759
 
5979
5760
   if (sctx->gfx_level == GFX9) {
5980
5761
      si_pm4_set_reg(pm4, R_030920_VGT_MAX_VTX_INDX, ~0);
5981
5762
      si_pm4_set_reg(pm4, R_030924_VGT_MIN_VTX_INDX, 0);
5982
5763
      si_pm4_set_reg(pm4, R_030928_VGT_INDX_OFFSET, 0);
5983
5764
 
5984
 
      si_pm4_set_reg(pm4, R_028060_DB_DFSM_CONTROL,
5985
 
                     S_028060_PUNCHOUT_MODE(V_028060_FORCE_OFF) |
5986
 
                     S_028060_POPS_DRAIN_PS_ON_OVERLAP(1));
5987
 
   }
 
5765
      si_pm4_set_reg(pm4, R_028060_DB_DFSM_CONTROL, S_028060_PUNCHOUT_MODE(V_028060_FORCE_OFF));
5988
5766
 
5989
 
   if (sctx->gfx_level >= GFX9) {
5990
 
      si_pm4_set_reg_idx3(sscreen, pm4, R_00B41C_SPI_SHADER_PGM_RSRC3_HS,
 
5767
      si_pm4_set_reg_idx3(pm4, R_00B41C_SPI_SHADER_PGM_RSRC3_HS,
5991
5768
                          ac_apply_cu_en(S_00B41C_CU_EN(0xffff) | S_00B41C_WAVE_LIMIT(0x3F),
5992
5769
                                         C_00B41C_CU_EN, 0, &sscreen->info));
5993
5770
 
6001
5778
      si_pm4_set_reg(pm4, R_030968_VGT_INSTANCE_BASE_ID, 0);
6002
5779
   }
6003
5780
 
6004
 
   if (sctx->gfx_level >= GFX10) {
6005
 
      si_pm4_set_reg(pm4, R_00B0C8_SPI_SHADER_USER_ACCUM_PS_0, 0);
6006
 
      si_pm4_set_reg(pm4, R_00B0CC_SPI_SHADER_USER_ACCUM_PS_1, 0);
6007
 
      si_pm4_set_reg(pm4, R_00B0D0_SPI_SHADER_USER_ACCUM_PS_2, 0);
6008
 
      si_pm4_set_reg(pm4, R_00B0D4_SPI_SHADER_USER_ACCUM_PS_3, 0);
6009
 
      si_pm4_set_reg(pm4, R_00B2C8_SPI_SHADER_USER_ACCUM_ESGS_0, 0);
6010
 
      si_pm4_set_reg(pm4, R_00B2CC_SPI_SHADER_USER_ACCUM_ESGS_1, 0);
6011
 
      si_pm4_set_reg(pm4, R_00B2D0_SPI_SHADER_USER_ACCUM_ESGS_2, 0);
6012
 
      si_pm4_set_reg(pm4, R_00B2D4_SPI_SHADER_USER_ACCUM_ESGS_3, 0);
6013
 
      si_pm4_set_reg(pm4, R_00B4C8_SPI_SHADER_USER_ACCUM_LSHS_0, 0);
6014
 
      si_pm4_set_reg(pm4, R_00B4CC_SPI_SHADER_USER_ACCUM_LSHS_1, 0);
6015
 
      si_pm4_set_reg(pm4, R_00B4D0_SPI_SHADER_USER_ACCUM_LSHS_2, 0);
6016
 
      si_pm4_set_reg(pm4, R_00B4D4_SPI_SHADER_USER_ACCUM_LSHS_3, 0);
6017
 
 
6018
 
      si_pm4_set_reg(pm4, R_00B0C0_SPI_SHADER_REQ_CTRL_PS,
6019
 
                     S_00B0C0_SOFT_GROUPING_EN(1) |
6020
 
                     S_00B0C0_NUMBER_OF_REQUESTS_PER_CU(4 - 1));
6021
 
 
6022
 
      /* Enable CMASK/HTILE/DCC caching in L2 for small chips. */
6023
 
      unsigned meta_write_policy, meta_read_policy;
6024
 
      unsigned no_alloc = sctx->gfx_level >= GFX11 ? V_02807C_CACHE_NOA_GFX11:
6025
 
                                                      V_02807C_CACHE_NOA_GFX10;
6026
 
      if (sscreen->info.max_render_backends <= 4) {
6027
 
         meta_write_policy = V_02807C_CACHE_LRU_WR; /* cache writes */
6028
 
         meta_read_policy = V_02807C_CACHE_LRU_RD;  /* cache reads */
6029
 
      } else {
6030
 
         meta_write_policy = V_02807C_CACHE_STREAM; /* write combine */
6031
 
         meta_read_policy = no_alloc; /* don't cache reads that miss */
 
5781
done:
 
5782
   si_pm4_finalize(pm4);
 
5783
   sctx->cs_preamble_state = pm4;
 
5784
   sctx->cs_preamble_state_tmz = si_pm4_clone(pm4); /* Make a copy of the preamble for TMZ. */
 
5785
}
 
5786
 
 
5787
static void cdna_init_compute_preamble_state(struct si_context *sctx)
 
5788
{
 
5789
   struct si_screen *sscreen = sctx->screen;
 
5790
   uint64_t border_color_va =
 
5791
      sctx->border_color_buffer ? sctx->border_color_buffer->gpu_address : 0;
 
5792
   uint32_t compute_cu_en = S_00B858_SH0_CU_EN(sscreen->info.spi_cu_en) |
 
5793
                            S_00B858_SH1_CU_EN(sscreen->info.spi_cu_en);
 
5794
 
 
5795
   struct si_pm4_state *pm4 = si_pm4_create_sized(sscreen, 48, true);
 
5796
   if (!pm4)
 
5797
      return;
 
5798
 
 
5799
   /* Compute registers. */
 
5800
   /* Disable profiling on compute chips. */
 
5801
   si_pm4_set_reg(pm4, R_00B82C_COMPUTE_PERFCOUNT_ENABLE, 0);
 
5802
   si_pm4_set_reg(pm4, R_00B834_COMPUTE_PGM_HI, S_00B834_DATA(sctx->screen->info.address32_hi >> 8));
 
5803
   si_pm4_set_reg(pm4, R_00B858_COMPUTE_STATIC_THREAD_MGMT_SE0, compute_cu_en);
 
5804
   si_pm4_set_reg(pm4, R_00B85C_COMPUTE_STATIC_THREAD_MGMT_SE1, compute_cu_en);
 
5805
   si_pm4_set_reg(pm4, R_00B864_COMPUTE_STATIC_THREAD_MGMT_SE2, compute_cu_en);
 
5806
   si_pm4_set_reg(pm4, R_00B868_COMPUTE_STATIC_THREAD_MGMT_SE3, compute_cu_en);
 
5807
   si_pm4_set_reg(pm4, R_00B878_COMPUTE_THREAD_TRACE_ENABLE, 0);
 
5808
 
 
5809
   if (sscreen->info.family >= CHIP_GFX940) {
 
5810
      si_pm4_set_reg(pm4, R_00B89C_COMPUTE_TG_CHUNK_SIZE, 0);
 
5811
      si_pm4_set_reg(pm4, R_00B8B4_COMPUTE_PGM_RSRC3, 0);
 
5812
   } else {
 
5813
      si_pm4_set_reg(pm4, R_00B894_COMPUTE_STATIC_THREAD_MGMT_SE4, compute_cu_en);
 
5814
      si_pm4_set_reg(pm4, R_00B898_COMPUTE_STATIC_THREAD_MGMT_SE5, compute_cu_en);
 
5815
      si_pm4_set_reg(pm4, R_00B89C_COMPUTE_STATIC_THREAD_MGMT_SE6, compute_cu_en);
 
5816
      si_pm4_set_reg(pm4, R_00B8A0_COMPUTE_STATIC_THREAD_MGMT_SE7, compute_cu_en);
 
5817
   }
 
5818
 
 
5819
   si_pm4_set_reg(pm4, R_0301EC_CP_COHER_START_DELAY, 0);
 
5820
 
 
5821
   /* Set the pointer to border colors. Only MI100 supports border colors. */
 
5822
   if (sscreen->info.family == CHIP_MI100) {
 
5823
      si_pm4_set_reg(pm4, R_030E00_TA_CS_BC_BASE_ADDR, border_color_va >> 8);
 
5824
      si_pm4_set_reg(pm4, R_030E04_TA_CS_BC_BASE_ADDR_HI,
 
5825
                     S_030E04_ADDRESS(border_color_va >> 40));
 
5826
   }
 
5827
 
 
5828
   si_pm4_finalize(pm4);
 
5829
   sctx->cs_preamble_state = pm4;
 
5830
   sctx->cs_preamble_state_tmz = si_pm4_clone(pm4); /* Make a copy of the preamble for TMZ. */
 
5831
}
 
5832
 
 
5833
static void gfx10_init_gfx_preamble_state(struct si_context *sctx)
 
5834
{
 
5835
   struct si_screen *sscreen = sctx->screen;
 
5836
   uint64_t border_color_va =
 
5837
      sctx->border_color_buffer ? sctx->border_color_buffer->gpu_address : 0;
 
5838
   uint32_t compute_cu_en = S_00B858_SH0_CU_EN(sscreen->info.spi_cu_en) |
 
5839
                            S_00B858_SH1_CU_EN(sscreen->info.spi_cu_en);
 
5840
   unsigned meta_write_policy, meta_read_policy;
 
5841
   unsigned no_alloc = sctx->gfx_level >= GFX11 ? V_02807C_CACHE_NOA_GFX11:
 
5842
                                                  V_02807C_CACHE_NOA_GFX10;
 
5843
   /* Enable CMASK/HTILE/DCC caching in L2 for small chips. */
 
5844
   if (sscreen->info.max_render_backends <= 4) {
 
5845
      meta_write_policy = V_02807C_CACHE_LRU_WR; /* cache writes */
 
5846
      meta_read_policy = V_02807C_CACHE_LRU_RD;  /* cache reads */
 
5847
   } else {
 
5848
      meta_write_policy = V_02807C_CACHE_STREAM; /* write combine */
 
5849
      meta_read_policy = no_alloc; /* don't cache reads that miss */
 
5850
   }
 
5851
 
 
5852
   /* We need more space because the preamble is large. */
 
5853
   struct si_pm4_state *pm4 = si_pm4_create_sized(sscreen, 214, sctx->has_graphics);
 
5854
   if (!pm4)
 
5855
      return;
 
5856
 
 
5857
   if (sctx->has_graphics && !sctx->shadowing.registers) {
 
5858
      si_pm4_cmd_add(pm4, PKT3(PKT3_CONTEXT_CONTROL, 1, 0));
 
5859
      si_pm4_cmd_add(pm4, CC0_UPDATE_LOAD_ENABLES(1));
 
5860
      si_pm4_cmd_add(pm4, CC1_UPDATE_SHADOW_ENABLES(1));
 
5861
 
 
5862
      if (sscreen->dpbb_allowed) {
 
5863
         si_pm4_cmd_add(pm4, PKT3(PKT3_EVENT_WRITE, 0, 0));
 
5864
         si_pm4_cmd_add(pm4, EVENT_TYPE(V_028A90_BREAK_BATCH) | EVENT_INDEX(0));
6032
5865
      }
6033
5866
 
6034
 
      si_pm4_set_reg(pm4, R_02807C_DB_RMI_L2_CACHE_CONTROL,
6035
 
                     S_02807C_Z_WR_POLICY(V_02807C_CACHE_STREAM) |
6036
 
                     S_02807C_S_WR_POLICY(V_02807C_CACHE_STREAM) |
6037
 
                     S_02807C_HTILE_WR_POLICY(meta_write_policy) |
6038
 
                     S_02807C_ZPCPSD_WR_POLICY(V_02807C_CACHE_STREAM) |
6039
 
                     S_02807C_Z_RD_POLICY(no_alloc) |
6040
 
                     S_02807C_S_RD_POLICY(no_alloc) |
6041
 
                     S_02807C_HTILE_RD_POLICY(meta_read_policy));
6042
 
 
6043
 
      unsigned gl2_cc;
6044
 
      if (sctx->gfx_level >= GFX11)
6045
 
         gl2_cc = S_028410_DCC_WR_POLICY_GFX11(meta_write_policy) |
6046
 
                  S_028410_COLOR_WR_POLICY_GFX11(V_028410_CACHE_STREAM) |
6047
 
                  S_028410_COLOR_RD_POLICY(V_028410_CACHE_NOA_GFX11);
6048
 
      else
6049
 
         gl2_cc = S_028410_CMASK_WR_POLICY(meta_write_policy) |
6050
 
                  S_028410_FMASK_WR_POLICY(V_028410_CACHE_STREAM) |
6051
 
                  S_028410_DCC_WR_POLICY_GFX10(meta_write_policy) |
6052
 
                  S_028410_COLOR_WR_POLICY_GFX10(V_028410_CACHE_STREAM) |
6053
 
                  S_028410_CMASK_RD_POLICY(meta_read_policy) |
6054
 
                  S_028410_FMASK_RD_POLICY(V_028410_CACHE_NOA_GFX10) |
6055
 
                  S_028410_COLOR_RD_POLICY(V_028410_CACHE_NOA_GFX10);
6056
 
 
6057
 
      si_pm4_set_reg(pm4, R_028410_CB_RMI_GL2_CACHE_CONTROL,
6058
 
                     gl2_cc |
6059
 
                     S_028410_DCC_RD_POLICY(meta_read_policy));
6060
 
 
6061
 
      si_pm4_set_reg(pm4, R_028428_CB_COVERAGE_OUT_CONTROL, 0);
6062
 
      si_pm4_set_reg(pm4, R_028A98_VGT_DRAW_PAYLOAD_CNTL, 0);
6063
 
 
6064
 
      /* Break up a pixel wave if it contains deallocs for more than
6065
 
       * half the parameter cache.
6066
 
       *
6067
 
       * To avoid a deadlock where pixel waves aren't launched
6068
 
       * because they're waiting for more pixels while the frontend
6069
 
       * is stuck waiting for PC space, the maximum allowed value is
6070
 
       * the size of the PC minus the largest possible allocation for
6071
 
       * a single primitive shader subgroup.
 
5867
      si_pm4_cmd_add(pm4, PKT3(PKT3_CLEAR_STATE, 0, 0));
 
5868
      si_pm4_cmd_add(pm4, 0);
 
5869
   }
 
5870
 
 
5871
   /* Non-graphics uconfig registers. */
 
5872
   if (sctx->gfx_level < GFX11)
 
5873
      si_pm4_set_reg(pm4, R_0301EC_CP_COHER_START_DELAY, 0x20);
 
5874
   si_pm4_set_reg(pm4, R_030E00_TA_CS_BC_BASE_ADDR, border_color_va >> 8);
 
5875
   si_pm4_set_reg(pm4, R_030E04_TA_CS_BC_BASE_ADDR_HI, S_030E04_ADDRESS(border_color_va >> 40));
 
5876
 
 
5877
   /* Compute registers. */
 
5878
   si_pm4_set_reg(pm4, R_00B834_COMPUTE_PGM_HI, S_00B834_DATA(sscreen->info.address32_hi >> 8));
 
5879
   si_pm4_set_reg(pm4, R_00B858_COMPUTE_STATIC_THREAD_MGMT_SE0, compute_cu_en);
 
5880
   si_pm4_set_reg(pm4, R_00B85C_COMPUTE_STATIC_THREAD_MGMT_SE1, compute_cu_en);
 
5881
 
 
5882
   si_pm4_set_reg(pm4, R_00B864_COMPUTE_STATIC_THREAD_MGMT_SE2, compute_cu_en);
 
5883
   si_pm4_set_reg(pm4, R_00B868_COMPUTE_STATIC_THREAD_MGMT_SE3, compute_cu_en);
 
5884
 
 
5885
   si_pm4_set_reg(pm4, R_00B890_COMPUTE_USER_ACCUM_0, 0);
 
5886
   si_pm4_set_reg(pm4, R_00B894_COMPUTE_USER_ACCUM_1, 0);
 
5887
   si_pm4_set_reg(pm4, R_00B898_COMPUTE_USER_ACCUM_2, 0);
 
5888
   si_pm4_set_reg(pm4, R_00B89C_COMPUTE_USER_ACCUM_3, 0);
 
5889
 
 
5890
   if (sctx->gfx_level >= GFX11) {
 
5891
      si_pm4_set_reg(pm4, R_00B8AC_COMPUTE_STATIC_THREAD_MGMT_SE4, compute_cu_en);
 
5892
      si_pm4_set_reg(pm4, R_00B8B0_COMPUTE_STATIC_THREAD_MGMT_SE5, compute_cu_en);
 
5893
      si_pm4_set_reg(pm4, R_00B8B4_COMPUTE_STATIC_THREAD_MGMT_SE6, compute_cu_en);
 
5894
      si_pm4_set_reg(pm4, R_00B8B8_COMPUTE_STATIC_THREAD_MGMT_SE7, compute_cu_en);
 
5895
 
 
5896
      /* How many threads should go to 1 SE before moving onto the next. Think of GL1 cache hits.
 
5897
       * Only these values are valid: 0 (disabled), 64, 128, 256, 512
 
5898
       * Recommendation: 64 = RT, 256 = non-RT (run benchmarks to be sure)
6072
5899
       */
6073
 
      si_pm4_set_reg(pm4, R_028C50_PA_SC_NGG_MODE_CNTL,
6074
 
                     S_028C50_MAX_DEALLOCS_IN_WAVE(sctx->gfx_level >= GFX11 ? 16 : 512));
6075
 
 
6076
 
      if (sctx->gfx_level < GFX11) {
6077
 
         /* Reuse for legacy (non-NGG) only. */
6078
 
         si_pm4_set_reg(pm4, R_028C58_VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
6079
 
      }
6080
 
 
6081
 
      if (!has_clear_state) {
6082
 
         si_pm4_set_reg(pm4, R_02835C_PA_SC_TILE_STEERING_OVERRIDE,
6083
 
                        sscreen->info.pa_sc_tile_steering_override);
6084
 
      }
6085
 
 
6086
 
 
6087
 
      si_pm4_set_reg(pm4, R_030964_GE_MAX_VTX_INDX, ~0);
6088
 
      si_pm4_set_reg(pm4, R_030924_GE_MIN_VTX_INDX, 0);
6089
 
      si_pm4_set_reg(pm4, R_030928_GE_INDX_OFFSET, 0);
6090
 
      si_pm4_set_reg(pm4, R_03097C_GE_STEREO_CNTL, 0);
6091
 
      si_pm4_set_reg(pm4, R_030988_GE_USER_VGPR_EN, 0);
 
5900
      si_pm4_set_reg(pm4, R_00B8BC_COMPUTE_DISPATCH_INTERLEAVE, S_00B8BC_INTERLEAVE(256));
 
5901
   } else {
 
5902
      si_pm4_set_reg(pm4, R_00B8A0_COMPUTE_PGM_RSRC3, 0);
6092
5903
   }
6093
5904
 
6094
 
   if (sctx->gfx_level >= GFX10 && sctx->gfx_level <= GFX10_3) {
6095
 
      /* Logical CUs 16 - 31 */
6096
 
      si_pm4_set_reg_idx3(sscreen, pm4, R_00B004_SPI_SHADER_PGM_RSRC4_PS,
6097
 
                          ac_apply_cu_en(S_00B004_CU_EN(cu_mask_ps >> 16),
 
5905
   si_pm4_set_reg(pm4, R_00B9F4_COMPUTE_DISPATCH_TUNNEL, 0);
 
5906
 
 
5907
   if (!sctx->has_graphics)
 
5908
      goto done;
 
5909
 
 
5910
   /* Shader registers - PS. */
 
5911
   unsigned cu_mask_ps = sctx->gfx_level >= GFX10_3 ? gfx103_get_cu_mask_ps(sscreen) : ~0u;
 
5912
   if (sctx->gfx_level < GFX11) {
 
5913
      si_pm4_set_reg_idx3(pm4, R_00B004_SPI_SHADER_PGM_RSRC4_PS,
 
5914
                          ac_apply_cu_en(S_00B004_CU_EN(cu_mask_ps >> 16), /* CUs 16-31 */
6098
5915
                                         C_00B004_CU_EN, 16, &sscreen->info));
6099
 
      si_pm4_set_reg_idx3(sscreen, pm4, R_00B104_SPI_SHADER_PGM_RSRC4_VS,
6100
 
                          ac_apply_cu_en(S_00B104_CU_EN(0xffff),
 
5916
   }
 
5917
   si_pm4_set_reg_idx3(pm4, R_00B01C_SPI_SHADER_PGM_RSRC3_PS,
 
5918
                       ac_apply_cu_en(S_00B01C_CU_EN(cu_mask_ps) |
 
5919
                                      S_00B01C_WAVE_LIMIT(0x3F) |
 
5920
                                      S_00B01C_LDS_GROUP_SIZE(sctx->gfx_level >= GFX11),
 
5921
                                      C_00B01C_CU_EN, 0, &sscreen->info));
 
5922
   si_pm4_set_reg(pm4, R_00B0C0_SPI_SHADER_REQ_CTRL_PS,
 
5923
                  S_00B0C0_SOFT_GROUPING_EN(1) |
 
5924
                  S_00B0C0_NUMBER_OF_REQUESTS_PER_CU(4 - 1));
 
5925
   si_pm4_set_reg(pm4, R_00B0C8_SPI_SHADER_USER_ACCUM_PS_0, 0);
 
5926
   si_pm4_set_reg(pm4, R_00B0CC_SPI_SHADER_USER_ACCUM_PS_1, 0);
 
5927
   si_pm4_set_reg(pm4, R_00B0D0_SPI_SHADER_USER_ACCUM_PS_2, 0);
 
5928
   si_pm4_set_reg(pm4, R_00B0D4_SPI_SHADER_USER_ACCUM_PS_3, 0);
 
5929
 
 
5930
   /* Shader registers - VS. */
 
5931
   if (sctx->gfx_level < GFX11) {
 
5932
      si_pm4_set_reg_idx3(pm4, R_00B104_SPI_SHADER_PGM_RSRC4_VS,
 
5933
                          ac_apply_cu_en(S_00B104_CU_EN(0xffff), /* CUs 16-31 */
6101
5934
                                         C_00B104_CU_EN, 16, &sscreen->info));
6102
 
      si_pm4_set_reg_idx3(sscreen, pm4, R_00B404_SPI_SHADER_PGM_RSRC4_HS,
6103
 
                          ac_apply_cu_en(S_00B404_CU_EN(0xffff),
6104
 
                                         C_00B404_CU_EN, 16, &sscreen->info));
6105
 
 
6106
5935
      si_pm4_set_reg(pm4, R_00B1C0_SPI_SHADER_REQ_CTRL_VS, 0);
6107
5936
      si_pm4_set_reg(pm4, R_00B1C8_SPI_SHADER_USER_ACCUM_VS_0, 0);
6108
5937
      si_pm4_set_reg(pm4, R_00B1CC_SPI_SHADER_USER_ACCUM_VS_1, 0);
6110
5939
      si_pm4_set_reg(pm4, R_00B1D4_SPI_SHADER_USER_ACCUM_VS_3, 0);
6111
5940
   }
6112
5941
 
6113
 
   if (sctx->gfx_level >= GFX10_3) {
 
5942
   /* Shader registers - GS. */
 
5943
   si_pm4_set_reg(pm4, R_00B2C8_SPI_SHADER_USER_ACCUM_ESGS_0, 0);
 
5944
   si_pm4_set_reg(pm4, R_00B2CC_SPI_SHADER_USER_ACCUM_ESGS_1, 0);
 
5945
   si_pm4_set_reg(pm4, R_00B2D0_SPI_SHADER_USER_ACCUM_ESGS_2, 0);
 
5946
   si_pm4_set_reg(pm4, R_00B2D4_SPI_SHADER_USER_ACCUM_ESGS_3, 0);
 
5947
   si_pm4_set_reg(pm4, R_00B324_SPI_SHADER_PGM_HI_ES,
 
5948
                  S_00B324_MEM_BASE(sscreen->info.address32_hi >> 8));
 
5949
 
 
5950
   /* Shader registers - HS. */
 
5951
   if (sctx->gfx_level < GFX11) {
 
5952
      si_pm4_set_reg_idx3(pm4, R_00B404_SPI_SHADER_PGM_RSRC4_HS,
 
5953
                          ac_apply_cu_en(S_00B404_CU_EN(0xffff), /* CUs 16-31 */
 
5954
                                         C_00B404_CU_EN, 16, &sscreen->info));
 
5955
   }
 
5956
   si_pm4_set_reg_idx3(pm4, R_00B41C_SPI_SHADER_PGM_RSRC3_HS,
 
5957
                       ac_apply_cu_en(S_00B41C_CU_EN(0xffff) | S_00B41C_WAVE_LIMIT(0x3F),
 
5958
                                      C_00B41C_CU_EN, 0, &sscreen->info));
 
5959
   si_pm4_set_reg(pm4, R_00B4C8_SPI_SHADER_USER_ACCUM_LSHS_0, 0);
 
5960
   si_pm4_set_reg(pm4, R_00B4CC_SPI_SHADER_USER_ACCUM_LSHS_1, 0);
 
5961
   si_pm4_set_reg(pm4, R_00B4D0_SPI_SHADER_USER_ACCUM_LSHS_2, 0);
 
5962
   si_pm4_set_reg(pm4, R_00B4D4_SPI_SHADER_USER_ACCUM_LSHS_3, 0);
 
5963
   si_pm4_set_reg(pm4, R_00B524_SPI_SHADER_PGM_HI_LS,
 
5964
                  S_00B524_MEM_BASE(sscreen->info.address32_hi >> 8));
 
5965
 
 
5966
   /* Context registers. */
 
5967
   if (sctx->gfx_level < GFX11) {
 
5968
      si_pm4_set_reg(pm4, R_028038_DB_DFSM_CONTROL, S_028038_PUNCHOUT_MODE(V_028038_FORCE_OFF));
 
5969
   }
 
5970
   si_pm4_set_reg(pm4, R_02807C_DB_RMI_L2_CACHE_CONTROL,
 
5971
                  S_02807C_Z_WR_POLICY(V_02807C_CACHE_STREAM) |
 
5972
                  S_02807C_S_WR_POLICY(V_02807C_CACHE_STREAM) |
 
5973
                  S_02807C_HTILE_WR_POLICY(meta_write_policy) |
 
5974
                  S_02807C_ZPCPSD_WR_POLICY(V_02807C_CACHE_STREAM) |
 
5975
                  S_02807C_Z_RD_POLICY(no_alloc) |
 
5976
                  S_02807C_S_RD_POLICY(no_alloc) |
 
5977
                  S_02807C_HTILE_RD_POLICY(meta_read_policy));
 
5978
   si_pm4_set_reg(pm4, R_028080_TA_BC_BASE_ADDR, border_color_va >> 8);
 
5979
   si_pm4_set_reg(pm4, R_028084_TA_BC_BASE_ADDR_HI, S_028084_ADDRESS(border_color_va >> 40));
 
5980
 
 
5981
   si_pm4_set_reg(pm4, R_028410_CB_RMI_GL2_CACHE_CONTROL,
 
5982
                  (sctx->gfx_level >= GFX11 ?
 
5983
                      S_028410_DCC_WR_POLICY_GFX11(meta_write_policy) |
 
5984
                      S_028410_COLOR_WR_POLICY_GFX11(V_028410_CACHE_STREAM) |
 
5985
                      S_028410_COLOR_RD_POLICY(V_028410_CACHE_NOA_GFX11)
 
5986
                    :
 
5987
                      S_028410_CMASK_WR_POLICY(meta_write_policy) |
 
5988
                      S_028410_FMASK_WR_POLICY(V_028410_CACHE_STREAM) |
 
5989
                      S_028410_DCC_WR_POLICY_GFX10(meta_write_policy) |
 
5990
                      S_028410_COLOR_WR_POLICY_GFX10(V_028410_CACHE_STREAM) |
 
5991
                      S_028410_CMASK_RD_POLICY(meta_read_policy) |
 
5992
                      S_028410_FMASK_RD_POLICY(V_028410_CACHE_NOA_GFX10) |
 
5993
                      S_028410_COLOR_RD_POLICY(V_028410_CACHE_NOA_GFX10)) |
 
5994
                  S_028410_DCC_RD_POLICY(meta_read_policy));
 
5995
 
 
5996
   if (sctx->gfx_level >= GFX10_3)
6114
5997
      si_pm4_set_reg(pm4, R_028750_SX_PS_DOWNCONVERT_CONTROL, 0xff);
 
5998
 
 
5999
   /* If any sample location uses the -8 coordinate, the EXCLUSION fields should be set to 0. */
 
6000
   si_pm4_set_reg(pm4, R_02882C_PA_SU_PRIM_FILTER_CNTL,
 
6001
                  S_02882C_XMAX_RIGHT_EXCLUSION(1) |
 
6002
                  S_02882C_YMAX_BOTTOM_EXCLUSION(1));
 
6003
   si_pm4_set_reg(pm4, R_028830_PA_SU_SMALL_PRIM_FILTER_CNTL,
 
6004
                  S_028830_SMALL_PRIM_FILTER_ENABLE(1));
 
6005
   if (sctx->gfx_level >= GFX10_3) {
6115
6006
      /* The rate combiners have no effect if they are disabled like this:
6116
6007
       *   VERTEX_RATE:    BYPASS_VTX_RATE_COMBINER = 1
6117
6008
       *   PRIMITIVE_RATE: BYPASS_PRIM_RATE_COMBINER = 1
6126
6017
                     S_028848_SAMPLE_ITER_COMBINER_MODE(V_028848_SC_VRS_COMB_MODE_OVERRIDE));
6127
6018
   }
6128
6019
 
6129
 
   if (sctx->gfx_level >= GFX11) {
6130
 
      si_pm4_set_reg(pm4, R_028C54_PA_SC_BINNER_CNTL_2, 0);
6131
 
      si_pm4_set_reg(pm4, R_028620_PA_RATE_CNTL,
6132
 
                     S_028620_VERTEX_RATE(2) | S_028620_PRIM_RATE(1));
6133
 
 
6134
 
      uint64_t rb_mask = BITFIELD64_MASK(sctx->screen->info.max_render_backends);
 
6020
   si_pm4_set_reg(pm4, R_028A18_VGT_HOS_MAX_TESS_LEVEL, fui(64));
 
6021
   si_pm4_set_reg(pm4, R_028AAC_VGT_ESGS_RING_ITEMSIZE, 1);
 
6022
   si_pm4_set_reg(pm4, R_028B50_VGT_TESS_DISTRIBUTION,
 
6023
                  sctx->gfx_level >= GFX11 ?
 
6024
                     S_028B50_ACCUM_ISOLINE(128) |
 
6025
                     S_028B50_ACCUM_TRI(128) |
 
6026
                     S_028B50_ACCUM_QUAD(128) |
 
6027
                     S_028B50_DONUT_SPLIT_GFX9(24) |
 
6028
                     S_028B50_TRAP_SPLIT(6)
 
6029
                   :
 
6030
                     S_028B50_ACCUM_ISOLINE(12) |
 
6031
                     S_028B50_ACCUM_TRI(30) |
 
6032
                     S_028B50_ACCUM_QUAD(24) |
 
6033
                     S_028B50_DONUT_SPLIT_GFX9(24) |
 
6034
                     S_028B50_TRAP_SPLIT(6));
 
6035
 
 
6036
   si_pm4_set_reg(pm4, R_028C48_PA_SC_BINNER_CNTL_1,
 
6037
                  S_028C48_MAX_ALLOC_COUNT(sscreen->info.pbb_max_alloc_count - 1) |
 
6038
                  S_028C48_MAX_PRIM_PER_BATCH(1023));
 
6039
   /* Break up a pixel wave if it contains deallocs for more than
 
6040
    * half the parameter cache.
 
6041
    *
 
6042
    * To avoid a deadlock where pixel waves aren't launched
 
6043
    * because they're waiting for more pixels while the frontend
 
6044
    * is stuck waiting for PC space, the maximum allowed value is
 
6045
    * the size of the PC minus the largest possible allocation for
 
6046
    * a single primitive shader subgroup.
 
6047
    */
 
6048
   si_pm4_set_reg(pm4, R_028C50_PA_SC_NGG_MODE_CNTL,
 
6049
                  S_028C50_MAX_DEALLOCS_IN_WAVE(sctx->gfx_level >= GFX11 ? 16 : 512));
 
6050
   if (sctx->gfx_level < GFX11)
 
6051
      si_pm4_set_reg(pm4, R_028C58_VGT_VERTEX_REUSE_BLOCK_CNTL, 14); /* Reuse for legacy (non-NGG) only. */
 
6052
 
 
6053
   /* Uconfig registers. */
 
6054
   si_pm4_set_reg(pm4, R_030924_GE_MIN_VTX_INDX, 0);
 
6055
   si_pm4_set_reg(pm4, R_030928_GE_INDX_OFFSET, 0);
 
6056
   if (sctx->gfx_level >= GFX11) {
 
6057
      /* This is changed by draws for indexed draws, but we need to set DISABLE_FOR_AUTO_INDEX
 
6058
       * here, which disables primitive restart for all non-indexed draws, so that those draws
 
6059
       * won't have to set this state.
 
6060
       */
 
6061
      si_pm4_set_reg(pm4, R_03092C_GE_MULTI_PRIM_IB_RESET_EN, S_03092C_DISABLE_FOR_AUTO_INDEX(1));
 
6062
   }
 
6063
   si_pm4_set_reg(pm4, R_030964_GE_MAX_VTX_INDX, ~0);
 
6064
   si_pm4_set_reg(pm4, R_030968_VGT_INSTANCE_BASE_ID, 0);
 
6065
   si_pm4_set_reg(pm4, R_03097C_GE_STEREO_CNTL, 0);
 
6066
   si_pm4_set_reg(pm4, R_030988_GE_USER_VGPR_EN, 0);
 
6067
 
 
6068
   si_pm4_set_reg(pm4, R_030A00_PA_SU_LINE_STIPPLE_VALUE, 0);
 
6069
   si_pm4_set_reg(pm4, R_030A04_PA_SC_LINE_STIPPLE_STATE, 0);
 
6070
 
 
6071
   if (sctx->gfx_level >= GFX11) {
 
6072
      uint64_t rb_mask = BITFIELD64_MASK(sscreen->info.max_render_backends);
6135
6073
 
6136
6074
      si_pm4_cmd_add(pm4, PKT3(PKT3_EVENT_WRITE, 2, 0));
6137
6075
      si_pm4_cmd_add(pm4, EVENT_TYPE(V_028A90_PIXEL_PIPE_STAT_CONTROL) | EVENT_INDEX(1));
6182
6120
   }
6183
6121
 
6184
6122
done:
 
6123
   si_pm4_finalize(pm4);
6185
6124
   sctx->cs_preamble_state = pm4;
 
6125
   sctx->cs_preamble_state_tmz = si_pm4_clone(pm4); /* Make a copy of the preamble for TMZ. */
 
6126
}
6186
6127
 
6187
 
   /* Make a copy of the preamble for TMZ. */
6188
 
   sctx->cs_preamble_state_tmz = (struct si_pm4_state *)CALLOC_STRUCT(si_cs_preamble);
6189
 
   memcpy(sctx->cs_preamble_state_tmz, sctx->cs_preamble_state, sizeof(struct si_cs_preamble));
 
6128
void si_init_gfx_preamble_state(struct si_context *sctx)
 
6129
{
 
6130
   if (!sctx->screen->info.has_graphics)
 
6131
      cdna_init_compute_preamble_state(sctx);
 
6132
   else if (sctx->gfx_level >= GFX10)
 
6133
      gfx10_init_gfx_preamble_state(sctx);
 
6134
   else
 
6135
      gfx6_init_gfx_preamble_state(sctx);
6190
6136
}