101e04c3fSmrg/*
201e04c3fSmrg * Copyright © 2016 Red Hat.
301e04c3fSmrg * Copyright © 2016 Bas Nieuwenhuizen
401e04c3fSmrg *
501e04c3fSmrg * based on si_state.c
601e04c3fSmrg * Copyright © 2015 Advanced Micro Devices, Inc.
701e04c3fSmrg *
801e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
901e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
1001e04c3fSmrg * to deal in the Software without restriction, including without limitation
1101e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1201e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
1301e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1401e04c3fSmrg *
1501e04c3fSmrg * The above copyright notice and this permission notice (including the next
1601e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1701e04c3fSmrg * Software.
1801e04c3fSmrg *
1901e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2001e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2101e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2201e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2301e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2401e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2501e04c3fSmrg * IN THE SOFTWARE.
2601e04c3fSmrg */
2701e04c3fSmrg
287ec681f3Smrg/* command buffer handling for AMD GCN */
2901e04c3fSmrg
307ec681f3Smrg#include "radv_cs.h"
3101e04c3fSmrg#include "radv_private.h"
3201e04c3fSmrg#include "radv_shader.h"
3301e04c3fSmrg#include "sid.h"
3401e04c3fSmrg
3501e04c3fSmrgstatic void
3601e04c3fSmrgsi_write_harvested_raster_configs(struct radv_physical_device *physical_device,
377ec681f3Smrg                                  struct radeon_cmdbuf *cs, unsigned raster_config,
387ec681f3Smrg                                  unsigned raster_config_1)
3901e04c3fSmrg{
407ec681f3Smrg   unsigned num_se = MAX2(physical_device->rad_info.max_se, 1);
417ec681f3Smrg   unsigned raster_config_se[4];
427ec681f3Smrg   unsigned se;
437ec681f3Smrg
447ec681f3Smrg   ac_get_harvested_configs(&physical_device->rad_info, raster_config, &raster_config_1,
457ec681f3Smrg                            raster_config_se);
467ec681f3Smrg
477ec681f3Smrg   for (se = 0; se < num_se; se++) {
487ec681f3Smrg      /* GRBM_GFX_INDEX has a different offset on GFX6 and GFX7+ */
497ec681f3Smrg      if (physical_device->rad_info.chip_class < GFX7)
507ec681f3Smrg         radeon_set_config_reg(cs, R_00802C_GRBM_GFX_INDEX,
517ec681f3Smrg                               S_00802C_SE_INDEX(se) | S_00802C_SH_BROADCAST_WRITES(1) |
527ec681f3Smrg                                  S_00802C_INSTANCE_BROADCAST_WRITES(1));
537ec681f3Smrg      else
547ec681f3Smrg         radeon_set_uconfig_reg(cs, R_030800_GRBM_GFX_INDEX,
557ec681f3Smrg                                S_030800_SE_INDEX(se) | S_030800_SH_BROADCAST_WRITES(1) |
567ec681f3Smrg                                   S_030800_INSTANCE_BROADCAST_WRITES(1));
577ec681f3Smrg      radeon_set_context_reg(cs, R_028350_PA_SC_RASTER_CONFIG, raster_config_se[se]);
587ec681f3Smrg   }
597ec681f3Smrg
607ec681f3Smrg   /* GRBM_GFX_INDEX has a different offset on GFX6 and GFX7+ */
617ec681f3Smrg   if (physical_device->rad_info.chip_class < GFX7)
627ec681f3Smrg      radeon_set_config_reg(cs, R_00802C_GRBM_GFX_INDEX,
637ec681f3Smrg                            S_00802C_SE_BROADCAST_WRITES(1) | S_00802C_SH_BROADCAST_WRITES(1) |
647ec681f3Smrg                               S_00802C_INSTANCE_BROADCAST_WRITES(1));
657ec681f3Smrg   else
667ec681f3Smrg      radeon_set_uconfig_reg(cs, R_030800_GRBM_GFX_INDEX,
677ec681f3Smrg                             S_030800_SE_BROADCAST_WRITES(1) | S_030800_SH_BROADCAST_WRITES(1) |
687ec681f3Smrg                                S_030800_INSTANCE_BROADCAST_WRITES(1));
697ec681f3Smrg
707ec681f3Smrg   if (physical_device->rad_info.chip_class >= GFX7)
717ec681f3Smrg      radeon_set_context_reg(cs, R_028354_PA_SC_RASTER_CONFIG_1, raster_config_1);
7201e04c3fSmrg}
7301e04c3fSmrg
7401e04c3fSmrgvoid
757ec681f3Smrgsi_emit_compute(struct radv_device *device, struct radeon_cmdbuf *cs)
7601e04c3fSmrg{
777ec681f3Smrg   radeon_set_sh_reg_seq(cs, R_00B810_COMPUTE_START_X, 3);
787ec681f3Smrg   radeon_emit(cs, 0);
797ec681f3Smrg   radeon_emit(cs, 0);
807ec681f3Smrg   radeon_emit(cs, 0);
817ec681f3Smrg
827ec681f3Smrg   radeon_set_sh_reg(cs, R_00B834_COMPUTE_PGM_HI,
837ec681f3Smrg                     S_00B834_DATA(device->physical_device->rad_info.address32_hi >> 8));
847ec681f3Smrg
857ec681f3Smrg   radeon_set_sh_reg_seq(cs, R_00B858_COMPUTE_STATIC_THREAD_MGMT_SE0, 2);
867ec681f3Smrg   /* R_00B858_COMPUTE_STATIC_THREAD_MGMT_SE0 / SE1,
877ec681f3Smrg    * renamed COMPUTE_DESTINATION_EN_SEn on gfx10. */
887ec681f3Smrg   radeon_emit(cs, S_00B858_SH0_CU_EN(0xffff) | S_00B858_SH1_CU_EN(0xffff));
897ec681f3Smrg   radeon_emit(cs, S_00B858_SH0_CU_EN(0xffff) | S_00B858_SH1_CU_EN(0xffff));
907ec681f3Smrg
917ec681f3Smrg   if (device->physical_device->rad_info.chip_class >= GFX7) {
927ec681f3Smrg      /* Also set R_00B858_COMPUTE_STATIC_THREAD_MGMT_SE2 / SE3 */
937ec681f3Smrg      radeon_set_sh_reg_seq(cs, R_00B864_COMPUTE_STATIC_THREAD_MGMT_SE2, 2);
947ec681f3Smrg      radeon_emit(cs, S_00B858_SH0_CU_EN(0xffff) | S_00B858_SH1_CU_EN(0xffff));
957ec681f3Smrg      radeon_emit(cs, S_00B858_SH0_CU_EN(0xffff) | S_00B858_SH1_CU_EN(0xffff));
967ec681f3Smrg
977ec681f3Smrg      if (device->border_color_data.bo) {
987ec681f3Smrg         uint64_t bc_va = radv_buffer_get_va(device->border_color_data.bo);
997ec681f3Smrg
1007ec681f3Smrg         radeon_set_uconfig_reg_seq(cs, R_030E00_TA_CS_BC_BASE_ADDR, 2);
1017ec681f3Smrg         radeon_emit(cs, bc_va >> 8);
1027ec681f3Smrg         radeon_emit(cs, S_030E04_ADDRESS(bc_va >> 40));
1037ec681f3Smrg      }
1047ec681f3Smrg   }
1057ec681f3Smrg
1067ec681f3Smrg   if (device->physical_device->rad_info.chip_class >= GFX9) {
1077ec681f3Smrg      radeon_set_uconfig_reg(cs, R_0301EC_CP_COHER_START_DELAY,
1087ec681f3Smrg                             device->physical_device->rad_info.chip_class >= GFX10 ? 0x20 : 0);
1097ec681f3Smrg   }
1107ec681f3Smrg
1117ec681f3Smrg   if (device->physical_device->rad_info.chip_class >= GFX10) {
1127ec681f3Smrg      radeon_set_sh_reg_seq(cs, R_00B890_COMPUTE_USER_ACCUM_0, 5);
1137ec681f3Smrg      radeon_emit(cs, 0); /* R_00B890_COMPUTE_USER_ACCUM_0 */
1147ec681f3Smrg      radeon_emit(cs, 0); /* R_00B894_COMPUTE_USER_ACCUM_1 */
1157ec681f3Smrg      radeon_emit(cs, 0); /* R_00B898_COMPUTE_USER_ACCUM_2 */
1167ec681f3Smrg      radeon_emit(cs, 0); /* R_00B89C_COMPUTE_USER_ACCUM_3 */
1177ec681f3Smrg      radeon_emit(cs, 0); /* R_00B8A0_COMPUTE_PGM_RSRC3 */
1187ec681f3Smrg   }
1197ec681f3Smrg
1207ec681f3Smrg   /* This register has been moved to R_00CD20_COMPUTE_MAX_WAVE_ID
1217ec681f3Smrg    * and is now per pipe, so it should be handled in the
1227ec681f3Smrg    * kernel if we want to use something other than the default value,
1237ec681f3Smrg    * which is now 0x22f.
1247ec681f3Smrg    */
1257ec681f3Smrg   if (device->physical_device->rad_info.chip_class <= GFX6) {
1267ec681f3Smrg      /* XXX: This should be:
1277ec681f3Smrg       * (number of compute units) * 4 * (waves per simd) - 1 */
1287ec681f3Smrg
1297ec681f3Smrg      radeon_set_sh_reg(cs, R_00B82C_COMPUTE_MAX_WAVE_ID, 0x190 /* Default value */);
1307ec681f3Smrg
1317ec681f3Smrg      if (device->border_color_data.bo) {
1327ec681f3Smrg         uint64_t bc_va = radv_buffer_get_va(device->border_color_data.bo);
1337ec681f3Smrg         radeon_set_config_reg(cs, R_00950C_TA_CS_BC_BASE_ADDR, bc_va >> 8);
1347ec681f3Smrg      }
1357ec681f3Smrg   }
1367ec681f3Smrg
1377ec681f3Smrg   if (device->tma_bo) {
1387ec681f3Smrg      uint64_t tba_va, tma_va;
1397ec681f3Smrg
1407ec681f3Smrg      assert(device->physical_device->rad_info.chip_class == GFX8);
1417ec681f3Smrg
1427ec681f3Smrg      tba_va = radv_shader_variant_get_va(device->trap_handler_shader);
1437ec681f3Smrg      tma_va = radv_buffer_get_va(device->tma_bo);
1447ec681f3Smrg
1457ec681f3Smrg      radeon_set_sh_reg_seq(cs, R_00B838_COMPUTE_TBA_LO, 4);
1467ec681f3Smrg      radeon_emit(cs, tba_va >> 8);
1477ec681f3Smrg      radeon_emit(cs, tba_va >> 40);
1487ec681f3Smrg      radeon_emit(cs, tma_va >> 8);
1497ec681f3Smrg      radeon_emit(cs, tma_va >> 40);
1507ec681f3Smrg   }
15101e04c3fSmrg}
15201e04c3fSmrg
15301e04c3fSmrg/* 12.4 fixed-point */
1547ec681f3Smrgstatic unsigned
1557ec681f3Smrgradv_pack_float_12p4(float x)
15601e04c3fSmrg{
1577ec681f3Smrg   return x <= 0 ? 0 : x >= 4096 ? 0xffff : x * 16;
15801e04c3fSmrg}
15901e04c3fSmrg
16001e04c3fSmrgstatic void
1617ec681f3Smrgsi_set_raster_config(struct radv_physical_device *physical_device, struct radeon_cmdbuf *cs)
16201e04c3fSmrg{
1637ec681f3Smrg   unsigned num_rb = MIN2(physical_device->rad_info.max_render_backends, 16);
1647ec681f3Smrg   unsigned rb_mask = physical_device->rad_info.enabled_rb_mask;
1657ec681f3Smrg   unsigned raster_config, raster_config_1;
1667ec681f3Smrg
1677ec681f3Smrg   ac_get_raster_config(&physical_device->rad_info, &raster_config, &raster_config_1, NULL);
1687ec681f3Smrg
1697ec681f3Smrg   /* Always use the default config when all backends are enabled
1707ec681f3Smrg    * (or when we failed to determine the enabled backends).
1717ec681f3Smrg    */
1727ec681f3Smrg   if (!rb_mask || util_bitcount(rb_mask) >= num_rb) {
1737ec681f3Smrg      radeon_set_context_reg(cs, R_028350_PA_SC_RASTER_CONFIG, raster_config);
1747ec681f3Smrg      if (physical_device->rad_info.chip_class >= GFX7)
1757ec681f3Smrg         radeon_set_context_reg(cs, R_028354_PA_SC_RASTER_CONFIG_1, raster_config_1);
1767ec681f3Smrg   } else {
1777ec681f3Smrg      si_write_harvested_raster_configs(physical_device, cs, raster_config, raster_config_1);
1787ec681f3Smrg   }
17901e04c3fSmrg}
18001e04c3fSmrg
18101e04c3fSmrgvoid
1827ec681f3Smrgsi_emit_graphics(struct radv_device *device, struct radeon_cmdbuf *cs)
18301e04c3fSmrg{
1847ec681f3Smrg   struct radv_physical_device *physical_device = device->physical_device;
1857ec681f3Smrg
1867ec681f3Smrg   bool has_clear_state = physical_device->rad_info.has_clear_state;
1877ec681f3Smrg   int i;
1887ec681f3Smrg
1897ec681f3Smrg   radeon_emit(cs, PKT3(PKT3_CONTEXT_CONTROL, 1, 0));
1907ec681f3Smrg   radeon_emit(cs, CC0_UPDATE_LOAD_ENABLES(1));
1917ec681f3Smrg   radeon_emit(cs, CC1_UPDATE_SHADOW_ENABLES(1));
1927ec681f3Smrg
1937ec681f3Smrg   if (has_clear_state) {
1947ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_CLEAR_STATE, 0, 0));
1957ec681f3Smrg      radeon_emit(cs, 0);
1967ec681f3Smrg   }
1977ec681f3Smrg
1987ec681f3Smrg   if (physical_device->rad_info.chip_class <= GFX8)
1997ec681f3Smrg      si_set_raster_config(physical_device, cs);
2007ec681f3Smrg
2017ec681f3Smrg   radeon_set_context_reg(cs, R_028A18_VGT_HOS_MAX_TESS_LEVEL, fui(64));
2027ec681f3Smrg   if (!has_clear_state)
2037ec681f3Smrg      radeon_set_context_reg(cs, R_028A1C_VGT_HOS_MIN_TESS_LEVEL, fui(0));
2047ec681f3Smrg
2057ec681f3Smrg   /* FIXME calculate these values somehow ??? */
2067ec681f3Smrg   if (physical_device->rad_info.chip_class <= GFX8) {
2077ec681f3Smrg      radeon_set_context_reg(cs, R_028A54_VGT_GS_PER_ES, SI_GS_PER_ES);
2087ec681f3Smrg      radeon_set_context_reg(cs, R_028A58_VGT_ES_PER_GS, 0x40);
2097ec681f3Smrg   }
2107ec681f3Smrg
2117ec681f3Smrg   if (!has_clear_state) {
2127ec681f3Smrg      radeon_set_context_reg(cs, R_028A5C_VGT_GS_PER_VS, 0x2);
2137ec681f3Smrg      radeon_set_context_reg(cs, R_028A8C_VGT_PRIMITIVEID_RESET, 0x0);
2147ec681f3Smrg      radeon_set_context_reg(cs, R_028B98_VGT_STRMOUT_BUFFER_CONFIG, 0x0);
2157ec681f3Smrg   }
2167ec681f3Smrg
2177ec681f3Smrg   if (physical_device->rad_info.chip_class <= GFX9)
2187ec681f3Smrg      radeon_set_context_reg(cs, R_028AA0_VGT_INSTANCE_STEP_RATE_0, 1);
2197ec681f3Smrg   if (!has_clear_state)
2207ec681f3Smrg      radeon_set_context_reg(cs, R_028AB8_VGT_VTX_CNT_EN, 0x0);
2217ec681f3Smrg   if (physical_device->rad_info.chip_class < GFX7)
2227ec681f3Smrg      radeon_set_config_reg(cs, R_008A14_PA_CL_ENHANCE,
2237ec681f3Smrg                            S_008A14_NUM_CLIP_SEQ(3) | S_008A14_CLIP_VTX_REORDER_ENA(1));
2247ec681f3Smrg
2257ec681f3Smrg   if (!has_clear_state)
2267ec681f3Smrg      radeon_set_context_reg(cs, R_02882C_PA_SU_PRIM_FILTER_CNTL, 0);
2277ec681f3Smrg
2287ec681f3Smrg   /* CLEAR_STATE doesn't clear these correctly on certain generations.
2297ec681f3Smrg    * I don't know why. Deduced by trial and error.
2307ec681f3Smrg    */
2317ec681f3Smrg   if (physical_device->rad_info.chip_class <= GFX7 || !has_clear_state) {
2327ec681f3Smrg      radeon_set_context_reg(cs, R_028B28_VGT_STRMOUT_DRAW_OPAQUE_OFFSET, 0);
2337ec681f3Smrg      radeon_set_context_reg(cs, R_028204_PA_SC_WINDOW_SCISSOR_TL,
2347ec681f3Smrg                             S_028204_WINDOW_OFFSET_DISABLE(1));
2357ec681f3Smrg      radeon_set_context_reg(cs, R_028240_PA_SC_GENERIC_SCISSOR_TL,
2367ec681f3Smrg                             S_028240_WINDOW_OFFSET_DISABLE(1));
2377ec681f3Smrg      radeon_set_context_reg(cs, R_028244_PA_SC_GENERIC_SCISSOR_BR,
2387ec681f3Smrg                             S_028244_BR_X(16384) | S_028244_BR_Y(16384));
2397ec681f3Smrg      radeon_set_context_reg(cs, R_028030_PA_SC_SCREEN_SCISSOR_TL, 0);
2407ec681f3Smrg      radeon_set_context_reg(cs, R_028034_PA_SC_SCREEN_SCISSOR_BR,
2417ec681f3Smrg                             S_028034_BR_X(16384) | S_028034_BR_Y(16384));
2427ec681f3Smrg   }
2437ec681f3Smrg
2447ec681f3Smrg   if (!has_clear_state) {
2457ec681f3Smrg      for (i = 0; i < 16; i++) {
2467ec681f3Smrg         radeon_set_context_reg(cs, R_0282D0_PA_SC_VPORT_ZMIN_0 + i * 8, 0);
2477ec681f3Smrg         radeon_set_context_reg(cs, R_0282D4_PA_SC_VPORT_ZMAX_0 + i * 8, fui(1.0));
2487ec681f3Smrg      }
2497ec681f3Smrg   }
2507ec681f3Smrg
2517ec681f3Smrg   if (!has_clear_state) {
2527ec681f3Smrg      radeon_set_context_reg(cs, R_02820C_PA_SC_CLIPRECT_RULE, 0xFFFF);
2537ec681f3Smrg      radeon_set_context_reg(cs, R_028230_PA_SC_EDGERULE, 0xAAAAAAAA);
2547ec681f3Smrg      /* PA_SU_HARDWARE_SCREEN_OFFSET must be 0 due to hw bug on GFX6 */
2557ec681f3Smrg      radeon_set_context_reg(cs, R_028234_PA_SU_HARDWARE_SCREEN_OFFSET, 0);
2567ec681f3Smrg      radeon_set_context_reg(cs, R_028820_PA_CL_NANINF_CNTL, 0);
2577ec681f3Smrg      radeon_set_context_reg(cs, R_028AC0_DB_SRESULTS_COMPARE_STATE0, 0x0);
2587ec681f3Smrg      radeon_set_context_reg(cs, R_028AC4_DB_SRESULTS_COMPARE_STATE1, 0x0);
2597ec681f3Smrg      radeon_set_context_reg(cs, R_028AC8_DB_PRELOAD_CONTROL, 0x0);
2607ec681f3Smrg   }
2617ec681f3Smrg
2627ec681f3Smrg   radeon_set_context_reg(cs, R_02800C_DB_RENDER_OVERRIDE,
2637ec681f3Smrg                          S_02800C_FORCE_HIS_ENABLE0(V_02800C_FORCE_DISABLE) |
2647ec681f3Smrg                             S_02800C_FORCE_HIS_ENABLE1(V_02800C_FORCE_DISABLE));
2657ec681f3Smrg
2667ec681f3Smrg   if (physical_device->rad_info.chip_class >= GFX10) {
2677ec681f3Smrg      radeon_set_context_reg(cs, R_028A98_VGT_DRAW_PAYLOAD_CNTL, 0);
2687ec681f3Smrg      radeon_set_uconfig_reg(cs, R_030964_GE_MAX_VTX_INDX, ~0);
2697ec681f3Smrg      radeon_set_uconfig_reg(cs, R_030924_GE_MIN_VTX_INDX, 0);
2707ec681f3Smrg      radeon_set_uconfig_reg(cs, R_030928_GE_INDX_OFFSET, 0);
2717ec681f3Smrg      radeon_set_uconfig_reg(cs, R_03097C_GE_STEREO_CNTL, 0);
2727ec681f3Smrg      radeon_set_uconfig_reg(cs, R_030988_GE_USER_VGPR_EN, 0);
2737ec681f3Smrg
2747ec681f3Smrg      radeon_set_context_reg(cs, R_028038_DB_DFSM_CONTROL,
2757ec681f3Smrg                             S_028038_PUNCHOUT_MODE(V_028038_FORCE_OFF) |
2767ec681f3Smrg                             S_028038_POPS_DRAIN_PS_ON_OVERLAP(1));
2777ec681f3Smrg   } else if (physical_device->rad_info.chip_class == GFX9) {
2787ec681f3Smrg      radeon_set_uconfig_reg(cs, R_030920_VGT_MAX_VTX_INDX, ~0);
2797ec681f3Smrg      radeon_set_uconfig_reg(cs, R_030924_VGT_MIN_VTX_INDX, 0);
2807ec681f3Smrg      radeon_set_uconfig_reg(cs, R_030928_VGT_INDX_OFFSET, 0);
2817ec681f3Smrg
2827ec681f3Smrg      radeon_set_context_reg(cs, R_028060_DB_DFSM_CONTROL,
2837ec681f3Smrg                             S_028060_PUNCHOUT_MODE(V_028060_FORCE_OFF) |
2847ec681f3Smrg                             S_028060_POPS_DRAIN_PS_ON_OVERLAP(1));
2857ec681f3Smrg   } else {
2867ec681f3Smrg      /* These registers, when written, also overwrite the
2877ec681f3Smrg       * CLEAR_STATE context, so we can't rely on CLEAR_STATE setting
2887ec681f3Smrg       * them.  It would be an issue if there was another UMD
2897ec681f3Smrg       * changing them.
2907ec681f3Smrg       */
2917ec681f3Smrg      radeon_set_context_reg(cs, R_028400_VGT_MAX_VTX_INDX, ~0);
2927ec681f3Smrg      radeon_set_context_reg(cs, R_028404_VGT_MIN_VTX_INDX, 0);
2937ec681f3Smrg      radeon_set_context_reg(cs, R_028408_VGT_INDX_OFFSET, 0);
2947ec681f3Smrg   }
2957ec681f3Smrg
2967ec681f3Smrg   if (device->physical_device->rad_info.chip_class >= GFX10) {
2977ec681f3Smrg      radeon_set_sh_reg(cs, R_00B524_SPI_SHADER_PGM_HI_LS,
2987ec681f3Smrg                        S_00B524_MEM_BASE(device->physical_device->rad_info.address32_hi >> 8));
2997ec681f3Smrg      radeon_set_sh_reg(cs, R_00B324_SPI_SHADER_PGM_HI_ES,
3007ec681f3Smrg                        S_00B324_MEM_BASE(device->physical_device->rad_info.address32_hi >> 8));
3017ec681f3Smrg   } else if (device->physical_device->rad_info.chip_class == GFX9) {
3027ec681f3Smrg      radeon_set_sh_reg(cs, R_00B414_SPI_SHADER_PGM_HI_LS,
3037ec681f3Smrg                        S_00B414_MEM_BASE(device->physical_device->rad_info.address32_hi >> 8));
3047ec681f3Smrg      radeon_set_sh_reg(cs, R_00B214_SPI_SHADER_PGM_HI_ES,
3057ec681f3Smrg                        S_00B214_MEM_BASE(device->physical_device->rad_info.address32_hi >> 8));
3067ec681f3Smrg   } else {
3077ec681f3Smrg      radeon_set_sh_reg(cs, R_00B524_SPI_SHADER_PGM_HI_LS,
3087ec681f3Smrg                        S_00B524_MEM_BASE(device->physical_device->rad_info.address32_hi >> 8));
3097ec681f3Smrg      radeon_set_sh_reg(cs, R_00B324_SPI_SHADER_PGM_HI_ES,
3107ec681f3Smrg                        S_00B324_MEM_BASE(device->physical_device->rad_info.address32_hi >> 8));
3117ec681f3Smrg   }
3127ec681f3Smrg
3137ec681f3Smrg   unsigned cu_mask_ps = 0xffffffff;
3147ec681f3Smrg
3157ec681f3Smrg   /* It's wasteful to enable all CUs for PS if shader arrays have a
3167ec681f3Smrg    * different number of CUs. The reason is that the hardware sends the
3177ec681f3Smrg    * same number of PS waves to each shader array, so the slowest shader
3187ec681f3Smrg    * array limits the performance.  Disable the extra CUs for PS in
3197ec681f3Smrg    * other shader arrays to save power and thus increase clocks for busy
3207ec681f3Smrg    * CUs. In the future, we might disable or enable this tweak only for
3217ec681f3Smrg    * certain apps.
3227ec681f3Smrg    */
3237ec681f3Smrg   if (physical_device->rad_info.chip_class >= GFX10_3)
3247ec681f3Smrg      cu_mask_ps = u_bit_consecutive(0, physical_device->rad_info.min_good_cu_per_sa);
3257ec681f3Smrg
3267ec681f3Smrg   if (physical_device->rad_info.chip_class >= GFX7) {
3277ec681f3Smrg      if (physical_device->rad_info.chip_class >= GFX10) {
3287ec681f3Smrg         /* Logical CUs 16 - 31 */
3297ec681f3Smrg         radeon_set_sh_reg_idx(physical_device, cs, R_00B404_SPI_SHADER_PGM_RSRC4_HS, 3,
3307ec681f3Smrg                               S_00B404_CU_EN(0xffff));
3317ec681f3Smrg         radeon_set_sh_reg_idx(physical_device, cs, R_00B104_SPI_SHADER_PGM_RSRC4_VS, 3,
3327ec681f3Smrg                               S_00B104_CU_EN(0xffff));
3337ec681f3Smrg         radeon_set_sh_reg_idx(physical_device, cs, R_00B004_SPI_SHADER_PGM_RSRC4_PS, 3,
3347ec681f3Smrg                               S_00B004_CU_EN(cu_mask_ps >> 16));
3357ec681f3Smrg      }
3367ec681f3Smrg
3377ec681f3Smrg      if (physical_device->rad_info.chip_class >= GFX9) {
3387ec681f3Smrg         radeon_set_sh_reg_idx(physical_device, cs, R_00B41C_SPI_SHADER_PGM_RSRC3_HS, 3,
3397ec681f3Smrg                               S_00B41C_CU_EN(0xffff) | S_00B41C_WAVE_LIMIT(0x3F));
3407ec681f3Smrg      } else {
3417ec681f3Smrg         radeon_set_sh_reg(cs, R_00B51C_SPI_SHADER_PGM_RSRC3_LS,
3427ec681f3Smrg                           S_00B51C_CU_EN(0xffff) | S_00B51C_WAVE_LIMIT(0x3F));
3437ec681f3Smrg         radeon_set_sh_reg(cs, R_00B41C_SPI_SHADER_PGM_RSRC3_HS, S_00B41C_WAVE_LIMIT(0x3F));
3447ec681f3Smrg         radeon_set_sh_reg(cs, R_00B31C_SPI_SHADER_PGM_RSRC3_ES,
3457ec681f3Smrg                           S_00B31C_CU_EN(0xffff) | S_00B31C_WAVE_LIMIT(0x3F));
3467ec681f3Smrg         /* If this is 0, Bonaire can hang even if GS isn't being used.
3477ec681f3Smrg          * Other chips are unaffected. These are suboptimal values,
3487ec681f3Smrg          * but we don't use on-chip GS.
3497ec681f3Smrg          */
3507ec681f3Smrg         radeon_set_context_reg(cs, R_028A44_VGT_GS_ONCHIP_CNTL,
3517ec681f3Smrg                                S_028A44_ES_VERTS_PER_SUBGRP(64) | S_028A44_GS_PRIMS_PER_SUBGRP(4));
3527ec681f3Smrg      }
3537ec681f3Smrg
3547ec681f3Smrg      radeon_set_sh_reg_idx(physical_device, cs, R_00B01C_SPI_SHADER_PGM_RSRC3_PS, 3,
3557ec681f3Smrg                            S_00B01C_CU_EN(cu_mask_ps) | S_00B01C_WAVE_LIMIT(0x3F));
3567ec681f3Smrg   }
3577ec681f3Smrg
3587ec681f3Smrg   if (physical_device->rad_info.chip_class >= GFX10) {
3597ec681f3Smrg      /* Break up a pixel wave if it contains deallocs for more than
3607ec681f3Smrg       * half the parameter cache.
3617ec681f3Smrg       *
3627ec681f3Smrg       * To avoid a deadlock where pixel waves aren't launched
3637ec681f3Smrg       * because they're waiting for more pixels while the frontend
3647ec681f3Smrg       * is stuck waiting for PC space, the maximum allowed value is
3657ec681f3Smrg       * the size of the PC minus the largest possible allocation for
3667ec681f3Smrg       * a single primitive shader subgroup.
3677ec681f3Smrg       */
3687ec681f3Smrg      radeon_set_context_reg(cs, R_028C50_PA_SC_NGG_MODE_CNTL, S_028C50_MAX_DEALLOCS_IN_WAVE(512));
3697ec681f3Smrg      radeon_set_context_reg(cs, R_028C58_VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
3707ec681f3Smrg
3717ec681f3Smrg      /* Vulkan doesn't support user edge flags and it also doesn't
3727ec681f3Smrg       * need to prevent drawing lines on internal edges of
3737ec681f3Smrg       * decomposed primitives (such as quads) with polygon mode = lines.
3747ec681f3Smrg       */
3757ec681f3Smrg      unsigned vertex_reuse_depth = physical_device->rad_info.chip_class >= GFX10_3 ? 30 : 0;
3767ec681f3Smrg      radeon_set_context_reg(cs, R_028838_PA_CL_NGG_CNTL,
3777ec681f3Smrg                             S_028838_INDEX_BUF_EDGE_FLAG_ENA(0) |
3787ec681f3Smrg                             S_028838_VERTEX_REUSE_DEPTH(vertex_reuse_depth));
3797ec681f3Smrg
3807ec681f3Smrg      /* Enable CMASK/FMASK/HTILE/DCC caching in L2 for small chips. */
3817ec681f3Smrg      unsigned meta_write_policy, meta_read_policy;
3827ec681f3Smrg
3837ec681f3Smrg      /* TODO: investigate whether LRU improves performance on other chips too */
3847ec681f3Smrg      if (physical_device->rad_info.max_render_backends <= 4) {
3857ec681f3Smrg         meta_write_policy = V_02807C_CACHE_LRU_WR; /* cache writes */
3867ec681f3Smrg         meta_read_policy = V_02807C_CACHE_LRU_RD;  /* cache reads */
3877ec681f3Smrg      } else {
3887ec681f3Smrg         meta_write_policy = V_02807C_CACHE_STREAM; /* write combine */
3897ec681f3Smrg         meta_read_policy = V_02807C_CACHE_NOA;     /* don't cache reads */
3907ec681f3Smrg      }
3917ec681f3Smrg
3927ec681f3Smrg      radeon_set_context_reg(
3937ec681f3Smrg         cs, R_02807C_DB_RMI_L2_CACHE_CONTROL,
3947ec681f3Smrg         S_02807C_Z_WR_POLICY(V_02807C_CACHE_STREAM) | S_02807C_S_WR_POLICY(V_02807C_CACHE_STREAM) |
3957ec681f3Smrg            S_02807C_HTILE_WR_POLICY(meta_write_policy) |
3967ec681f3Smrg            S_02807C_ZPCPSD_WR_POLICY(V_02807C_CACHE_STREAM) |
3977ec681f3Smrg            S_02807C_Z_RD_POLICY(V_02807C_CACHE_NOA) | S_02807C_S_RD_POLICY(V_02807C_CACHE_NOA) |
3987ec681f3Smrg            S_02807C_HTILE_RD_POLICY(meta_read_policy));
3997ec681f3Smrg
4007ec681f3Smrg      radeon_set_context_reg(
4017ec681f3Smrg         cs, R_028410_CB_RMI_GL2_CACHE_CONTROL,
4027ec681f3Smrg         S_028410_CMASK_WR_POLICY(meta_write_policy) | S_028410_FMASK_WR_POLICY(meta_write_policy) |
4037ec681f3Smrg            S_028410_DCC_WR_POLICY(meta_write_policy) |
4047ec681f3Smrg            S_028410_COLOR_WR_POLICY(V_028410_CACHE_STREAM) |
4057ec681f3Smrg            S_028410_CMASK_RD_POLICY(meta_read_policy) |
4067ec681f3Smrg            S_028410_FMASK_RD_POLICY(meta_read_policy) | S_028410_DCC_RD_POLICY(meta_read_policy) |
4077ec681f3Smrg            S_028410_COLOR_RD_POLICY(V_028410_CACHE_NOA));
4087ec681f3Smrg      radeon_set_context_reg(cs, R_028428_CB_COVERAGE_OUT_CONTROL, 0);
4097ec681f3Smrg
4107ec681f3Smrg      radeon_set_sh_reg_seq(cs, R_00B0C8_SPI_SHADER_USER_ACCUM_PS_0, 4);
4117ec681f3Smrg      radeon_emit(cs, 0); /* R_00B0C8_SPI_SHADER_USER_ACCUM_PS_0 */
4127ec681f3Smrg      radeon_emit(cs, 0); /* R_00B0CC_SPI_SHADER_USER_ACCUM_PS_1 */
4137ec681f3Smrg      radeon_emit(cs, 0); /* R_00B0D0_SPI_SHADER_USER_ACCUM_PS_2 */
4147ec681f3Smrg      radeon_emit(cs, 0); /* R_00B0D4_SPI_SHADER_USER_ACCUM_PS_3 */
4157ec681f3Smrg      radeon_set_sh_reg_seq(cs, R_00B1C8_SPI_SHADER_USER_ACCUM_VS_0, 4);
4167ec681f3Smrg      radeon_emit(cs, 0); /* R_00B1C8_SPI_SHADER_USER_ACCUM_VS_0 */
4177ec681f3Smrg      radeon_emit(cs, 0); /* R_00B1CC_SPI_SHADER_USER_ACCUM_VS_1 */
4187ec681f3Smrg      radeon_emit(cs, 0); /* R_00B1D0_SPI_SHADER_USER_ACCUM_VS_2 */
4197ec681f3Smrg      radeon_emit(cs, 0); /* R_00B1D4_SPI_SHADER_USER_ACCUM_VS_3 */
4207ec681f3Smrg      radeon_set_sh_reg_seq(cs, R_00B2C8_SPI_SHADER_USER_ACCUM_ESGS_0, 4);
4217ec681f3Smrg      radeon_emit(cs, 0); /* R_00B2C8_SPI_SHADER_USER_ACCUM_ESGS_0 */
4227ec681f3Smrg      radeon_emit(cs, 0); /* R_00B2CC_SPI_SHADER_USER_ACCUM_ESGS_1 */
4237ec681f3Smrg      radeon_emit(cs, 0); /* R_00B2D0_SPI_SHADER_USER_ACCUM_ESGS_2 */
4247ec681f3Smrg      radeon_emit(cs, 0); /* R_00B2D4_SPI_SHADER_USER_ACCUM_ESGS_3 */
4257ec681f3Smrg      radeon_set_sh_reg_seq(cs, R_00B4C8_SPI_SHADER_USER_ACCUM_LSHS_0, 4);
4267ec681f3Smrg      radeon_emit(cs, 0); /* R_00B4C8_SPI_SHADER_USER_ACCUM_LSHS_0 */
4277ec681f3Smrg      radeon_emit(cs, 0); /* R_00B4CC_SPI_SHADER_USER_ACCUM_LSHS_1 */
4287ec681f3Smrg      radeon_emit(cs, 0); /* R_00B4D0_SPI_SHADER_USER_ACCUM_LSHS_2 */
4297ec681f3Smrg      radeon_emit(cs, 0); /* R_00B4D4_SPI_SHADER_USER_ACCUM_LSHS_3 */
4307ec681f3Smrg
4317ec681f3Smrg      radeon_set_sh_reg(cs, R_00B0C0_SPI_SHADER_REQ_CTRL_PS,
4327ec681f3Smrg                        S_00B0C0_SOFT_GROUPING_EN(1) | S_00B0C0_NUMBER_OF_REQUESTS_PER_CU(4 - 1));
4337ec681f3Smrg      radeon_set_sh_reg(cs, R_00B1C0_SPI_SHADER_REQ_CTRL_VS, 0);
4347ec681f3Smrg
4357ec681f3Smrg      if (physical_device->rad_info.chip_class >= GFX10_3) {
4367ec681f3Smrg         radeon_set_context_reg(cs, R_028750_SX_PS_DOWNCONVERT_CONTROL, 0xff);
4377ec681f3Smrg         /* This allows sample shading. */
4387ec681f3Smrg         radeon_set_context_reg(
4397ec681f3Smrg            cs, R_028848_PA_CL_VRS_CNTL,
4407ec681f3Smrg            S_028848_SAMPLE_ITER_COMBINER_MODE(V_028848_VRS_COMB_MODE_OVERRIDE));
4417ec681f3Smrg      }
4427ec681f3Smrg   }
4437ec681f3Smrg
4447ec681f3Smrg   if (physical_device->rad_info.chip_class >= GFX9) {
4457ec681f3Smrg      radeon_set_context_reg(cs, R_028B50_VGT_TESS_DISTRIBUTION,
4467ec681f3Smrg                             S_028B50_ACCUM_ISOLINE(40) | S_028B50_ACCUM_TRI(30) |
4477ec681f3Smrg                                S_028B50_ACCUM_QUAD(24) | S_028B50_DONUT_SPLIT_GFX9(24) |
4487ec681f3Smrg                                S_028B50_TRAP_SPLIT(6));
4497ec681f3Smrg   } else if (physical_device->rad_info.chip_class >= GFX8) {
4507ec681f3Smrg      uint32_t vgt_tess_distribution;
4517ec681f3Smrg
4527ec681f3Smrg      vgt_tess_distribution = S_028B50_ACCUM_ISOLINE(32) | S_028B50_ACCUM_TRI(11) |
4537ec681f3Smrg                              S_028B50_ACCUM_QUAD(11) | S_028B50_DONUT_SPLIT_GFX81(16);
4547ec681f3Smrg
4557ec681f3Smrg      if (physical_device->rad_info.family == CHIP_FIJI ||
4567ec681f3Smrg          physical_device->rad_info.family >= CHIP_POLARIS10)
4577ec681f3Smrg         vgt_tess_distribution |= S_028B50_TRAP_SPLIT(3);
4587ec681f3Smrg
4597ec681f3Smrg      radeon_set_context_reg(cs, R_028B50_VGT_TESS_DISTRIBUTION, vgt_tess_distribution);
4607ec681f3Smrg   } else if (!has_clear_state) {
4617ec681f3Smrg      radeon_set_context_reg(cs, R_028C58_VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
4627ec681f3Smrg      radeon_set_context_reg(cs, R_028C5C_VGT_OUT_DEALLOC_CNTL, 16);
4637ec681f3Smrg   }
4647ec681f3Smrg
4657ec681f3Smrg   if (device->border_color_data.bo) {
4667ec681f3Smrg      uint64_t border_color_va = radv_buffer_get_va(device->border_color_data.bo);
4677ec681f3Smrg
4687ec681f3Smrg      radeon_set_context_reg(cs, R_028080_TA_BC_BASE_ADDR, border_color_va >> 8);
4697ec681f3Smrg      if (physical_device->rad_info.chip_class >= GFX7) {
4707ec681f3Smrg         radeon_set_context_reg(cs, R_028084_TA_BC_BASE_ADDR_HI,
4717ec681f3Smrg                                S_028084_ADDRESS(border_color_va >> 40));
4727ec681f3Smrg      }
4737ec681f3Smrg   }
4747ec681f3Smrg
4757ec681f3Smrg   if (physical_device->rad_info.chip_class >= GFX9) {
4767ec681f3Smrg      radeon_set_context_reg(
4777ec681f3Smrg         cs, R_028C48_PA_SC_BINNER_CNTL_1,
4787ec681f3Smrg         S_028C48_MAX_ALLOC_COUNT(physical_device->rad_info.pbb_max_alloc_count - 1) |
4797ec681f3Smrg            S_028C48_MAX_PRIM_PER_BATCH(1023));
4807ec681f3Smrg      radeon_set_context_reg(cs, R_028C4C_PA_SC_CONSERVATIVE_RASTERIZATION_CNTL,
4817ec681f3Smrg                             S_028C4C_NULL_SQUAD_AA_MASK_ENABLE(1));
4827ec681f3Smrg      radeon_set_uconfig_reg(cs, R_030968_VGT_INSTANCE_BASE_ID, 0);
4837ec681f3Smrg   }
4847ec681f3Smrg
4857ec681f3Smrg   unsigned tmp = (unsigned)(1.0 * 8.0);
4867ec681f3Smrg   radeon_set_context_reg(cs, R_028A00_PA_SU_POINT_SIZE,
4877ec681f3Smrg                              S_028A00_HEIGHT(tmp) | S_028A00_WIDTH(tmp));
4887ec681f3Smrg   radeon_set_context_reg(cs, R_028A04_PA_SU_POINT_MINMAX,
4897ec681f3Smrg                              S_028A04_MIN_SIZE(radv_pack_float_12p4(0)) |
4907ec681f3Smrg                              S_028A04_MAX_SIZE(radv_pack_float_12p4(8191.875 / 2)));
4917ec681f3Smrg
4927ec681f3Smrg   if (!has_clear_state) {
4937ec681f3Smrg      radeon_set_context_reg(cs, R_028004_DB_COUNT_CONTROL, S_028004_ZPASS_INCREMENT_DISABLE(1));
4947ec681f3Smrg   }
4957ec681f3Smrg
4967ec681f3Smrg   /* Enable the Polaris small primitive filter control.
4977ec681f3Smrg    * XXX: There is possibly an issue when MSAA is off (see RadeonSI
4987ec681f3Smrg    * has_msaa_sample_loc_bug). But this doesn't seem to regress anything,
4997ec681f3Smrg    * and AMDVLK doesn't have a workaround as well.
5007ec681f3Smrg    */
5017ec681f3Smrg   if (physical_device->rad_info.family >= CHIP_POLARIS10) {
5027ec681f3Smrg      unsigned small_prim_filter_cntl =
5037ec681f3Smrg         S_028830_SMALL_PRIM_FILTER_ENABLE(1) |
5047ec681f3Smrg         /* Workaround for a hw line bug. */
5057ec681f3Smrg         S_028830_LINE_FILTER_DISABLE(physical_device->rad_info.family <= CHIP_POLARIS12);
5067ec681f3Smrg
5077ec681f3Smrg      radeon_set_context_reg(cs, R_028830_PA_SU_SMALL_PRIM_FILTER_CNTL, small_prim_filter_cntl);
5087ec681f3Smrg   }
5097ec681f3Smrg
5107ec681f3Smrg   radeon_set_context_reg(
5117ec681f3Smrg      cs, R_0286D4_SPI_INTERP_CONTROL_0,
5127ec681f3Smrg      S_0286D4_FLAT_SHADE_ENA(1) | S_0286D4_PNT_SPRITE_ENA(1) |
5137ec681f3Smrg         S_0286D4_PNT_SPRITE_OVRD_X(V_0286D4_SPI_PNT_SPRITE_SEL_S) |
5147ec681f3Smrg         S_0286D4_PNT_SPRITE_OVRD_Y(V_0286D4_SPI_PNT_SPRITE_SEL_T) |
5157ec681f3Smrg         S_0286D4_PNT_SPRITE_OVRD_Z(V_0286D4_SPI_PNT_SPRITE_SEL_0) |
5167ec681f3Smrg         S_0286D4_PNT_SPRITE_OVRD_W(V_0286D4_SPI_PNT_SPRITE_SEL_1) |
5177ec681f3Smrg         S_0286D4_PNT_SPRITE_TOP_1(0)); /* vulkan is top to bottom - 1.0 at bottom */
5187ec681f3Smrg
5197ec681f3Smrg   radeon_set_context_reg(cs, R_028BE4_PA_SU_VTX_CNTL,
5207ec681f3Smrg                          S_028BE4_PIX_CENTER(1) | S_028BE4_ROUND_MODE(V_028BE4_X_ROUND_TO_EVEN) |
5217ec681f3Smrg                             S_028BE4_QUANT_MODE(V_028BE4_X_16_8_FIXED_POINT_1_256TH));
5227ec681f3Smrg
5237ec681f3Smrg   radeon_set_context_reg(cs, R_028818_PA_CL_VTE_CNTL,
5247ec681f3Smrg                          S_028818_VTX_W0_FMT(1) | S_028818_VPORT_X_SCALE_ENA(1) |
5257ec681f3Smrg                             S_028818_VPORT_X_OFFSET_ENA(1) | S_028818_VPORT_Y_SCALE_ENA(1) |
5267ec681f3Smrg                             S_028818_VPORT_Y_OFFSET_ENA(1) | S_028818_VPORT_Z_SCALE_ENA(1) |
5277ec681f3Smrg                             S_028818_VPORT_Z_OFFSET_ENA(1));
5287ec681f3Smrg
5297ec681f3Smrg   if (device->tma_bo) {
5307ec681f3Smrg      uint64_t tba_va, tma_va;
5317ec681f3Smrg
5327ec681f3Smrg      assert(device->physical_device->rad_info.chip_class == GFX8);
5337ec681f3Smrg
5347ec681f3Smrg      tba_va = radv_shader_variant_get_va(device->trap_handler_shader);
5357ec681f3Smrg      tma_va = radv_buffer_get_va(device->tma_bo);
5367ec681f3Smrg
5377ec681f3Smrg      uint32_t regs[] = {R_00B000_SPI_SHADER_TBA_LO_PS, R_00B100_SPI_SHADER_TBA_LO_VS,
5387ec681f3Smrg                         R_00B200_SPI_SHADER_TBA_LO_GS, R_00B300_SPI_SHADER_TBA_LO_ES,
5397ec681f3Smrg                         R_00B400_SPI_SHADER_TBA_LO_HS, R_00B500_SPI_SHADER_TBA_LO_LS};
5407ec681f3Smrg
5417ec681f3Smrg      for (i = 0; i < ARRAY_SIZE(regs); ++i) {
5427ec681f3Smrg         radeon_set_sh_reg_seq(cs, regs[i], 4);
5437ec681f3Smrg         radeon_emit(cs, tba_va >> 8);
5447ec681f3Smrg         radeon_emit(cs, tba_va >> 40);
5457ec681f3Smrg         radeon_emit(cs, tma_va >> 8);
5467ec681f3Smrg         radeon_emit(cs, tma_va >> 40);
5477ec681f3Smrg      }
5487ec681f3Smrg   }
5497ec681f3Smrg
5507ec681f3Smrg   /* The DX10 diamond test is unnecessary with Vulkan and it decreases line rasterization
5517ec681f3Smrg    * performance.
5527ec681f3Smrg    */
5537ec681f3Smrg   radeon_set_context_reg(cs, R_028BDC_PA_SC_LINE_CNTL, 0);
5547ec681f3Smrg
5557ec681f3Smrg   si_emit_compute(device, cs);
55601e04c3fSmrg}
55701e04c3fSmrg
55801e04c3fSmrgvoid
55901e04c3fSmrgcik_create_gfx_config(struct radv_device *device)
56001e04c3fSmrg{
5617ec681f3Smrg   struct radeon_cmdbuf *cs = device->ws->cs_create(device->ws, RING_GFX);
5627ec681f3Smrg   if (!cs)
5637ec681f3Smrg      return;
5647ec681f3Smrg
5657ec681f3Smrg   si_emit_graphics(device, cs);
5667ec681f3Smrg
5677ec681f3Smrg   while (cs->cdw & 7) {
5687ec681f3Smrg      if (device->physical_device->rad_info.gfx_ib_pad_with_type2)
5697ec681f3Smrg         radeon_emit(cs, PKT2_NOP_PAD);
5707ec681f3Smrg      else
5717ec681f3Smrg         radeon_emit(cs, PKT3_NOP_PAD);
5727ec681f3Smrg   }
5737ec681f3Smrg
5747ec681f3Smrg   VkResult result =
5757ec681f3Smrg      device->ws->buffer_create(device->ws, cs->cdw * 4, 4096, device->ws->cs_domain(device->ws),
5767ec681f3Smrg                                RADEON_FLAG_CPU_ACCESS | RADEON_FLAG_NO_INTERPROCESS_SHARING |
5777ec681f3Smrg                                   RADEON_FLAG_READ_ONLY | RADEON_FLAG_GTT_WC,
5787ec681f3Smrg                                RADV_BO_PRIORITY_CS, 0, &device->gfx_init);
5797ec681f3Smrg   if (result != VK_SUCCESS)
5807ec681f3Smrg      goto fail;
5817ec681f3Smrg
5827ec681f3Smrg   void *map = device->ws->buffer_map(device->gfx_init);
5837ec681f3Smrg   if (!map) {
5847ec681f3Smrg      device->ws->buffer_destroy(device->ws, device->gfx_init);
5857ec681f3Smrg      device->gfx_init = NULL;
5867ec681f3Smrg      goto fail;
5877ec681f3Smrg   }
5887ec681f3Smrg   memcpy(map, cs->buf, cs->cdw * 4);
5897ec681f3Smrg
5907ec681f3Smrg   device->ws->buffer_unmap(device->gfx_init);
5917ec681f3Smrg   device->gfx_init_size_dw = cs->cdw;
59201e04c3fSmrgfail:
5937ec681f3Smrg   device->ws->cs_destroy(cs);
59401e04c3fSmrg}
59501e04c3fSmrg
59601e04c3fSmrgvoid
5977ec681f3Smrgradv_get_viewport_xform(const VkViewport *viewport, float scale[3], float translate[3])
59801e04c3fSmrg{
5997ec681f3Smrg   float x = viewport->x;
6007ec681f3Smrg   float y = viewport->y;
6017ec681f3Smrg   float half_width = 0.5f * viewport->width;
6027ec681f3Smrg   float half_height = 0.5f * viewport->height;
6037ec681f3Smrg   double n = viewport->minDepth;
6047ec681f3Smrg   double f = viewport->maxDepth;
6057ec681f3Smrg
6067ec681f3Smrg   scale[0] = half_width;
6077ec681f3Smrg   translate[0] = half_width + x;
6087ec681f3Smrg   scale[1] = half_height;
6097ec681f3Smrg   translate[1] = half_height + y;
6107ec681f3Smrg
6117ec681f3Smrg   scale[2] = (f - n);
6127ec681f3Smrg   translate[2] = n;
61301e04c3fSmrg}
61401e04c3fSmrg
6157ec681f3Smrgstatic VkRect2D
6167ec681f3Smrgsi_scissor_from_viewport(const VkViewport *viewport)
61701e04c3fSmrg{
6187ec681f3Smrg   float scale[3], translate[3];
6197ec681f3Smrg   VkRect2D rect;
62001e04c3fSmrg
6217ec681f3Smrg   radv_get_viewport_xform(viewport, scale, translate);
62201e04c3fSmrg
6237ec681f3Smrg   rect.offset.x = translate[0] - fabsf(scale[0]);
6247ec681f3Smrg   rect.offset.y = translate[1] - fabsf(scale[1]);
6257ec681f3Smrg   rect.extent.width = ceilf(translate[0] + fabsf(scale[0])) - rect.offset.x;
6267ec681f3Smrg   rect.extent.height = ceilf(translate[1] + fabsf(scale[1])) - rect.offset.y;
62701e04c3fSmrg
6287ec681f3Smrg   return rect;
62901e04c3fSmrg}
63001e04c3fSmrg
6317ec681f3Smrgstatic VkRect2D
6327ec681f3Smrgsi_intersect_scissor(const VkRect2D *a, const VkRect2D *b)
6337ec681f3Smrg{
6347ec681f3Smrg   VkRect2D ret;
6357ec681f3Smrg   ret.offset.x = MAX2(a->offset.x, b->offset.x);
6367ec681f3Smrg   ret.offset.y = MAX2(a->offset.y, b->offset.y);
6377ec681f3Smrg   ret.extent.width =
6387ec681f3Smrg      MIN2(a->offset.x + a->extent.width, b->offset.x + b->extent.width) - ret.offset.x;
6397ec681f3Smrg   ret.extent.height =
6407ec681f3Smrg      MIN2(a->offset.y + a->extent.height, b->offset.y + b->extent.height) - ret.offset.y;
6417ec681f3Smrg   return ret;
64201e04c3fSmrg}
64301e04c3fSmrg
64401e04c3fSmrgvoid
6457ec681f3Smrgsi_write_scissors(struct radeon_cmdbuf *cs, int first, int count, const VkRect2D *scissors,
64601e04c3fSmrg                  const VkViewport *viewports, bool can_use_guardband)
64701e04c3fSmrg{
6487ec681f3Smrg   int i;
6497ec681f3Smrg   float scale[3], translate[3], guardband_x = INFINITY, guardband_y = INFINITY;
6507ec681f3Smrg   const float max_range = 32767.0f;
6517ec681f3Smrg   if (!count)
6527ec681f3Smrg      return;
6537ec681f3Smrg
6547ec681f3Smrg   radeon_set_context_reg_seq(cs, R_028250_PA_SC_VPORT_SCISSOR_0_TL + first * 4 * 2, count * 2);
6557ec681f3Smrg   for (i = 0; i < count; i++) {
6567ec681f3Smrg      VkRect2D viewport_scissor = si_scissor_from_viewport(viewports + i);
6577ec681f3Smrg      VkRect2D scissor = si_intersect_scissor(&scissors[i], &viewport_scissor);
6587ec681f3Smrg
6597ec681f3Smrg      radv_get_viewport_xform(viewports + i, scale, translate);
6607ec681f3Smrg      scale[0] = fabsf(scale[0]);
6617ec681f3Smrg      scale[1] = fabsf(scale[1]);
6627ec681f3Smrg
6637ec681f3Smrg      if (scale[0] < 0.5)
6647ec681f3Smrg         scale[0] = 0.5;
6657ec681f3Smrg      if (scale[1] < 0.5)
6667ec681f3Smrg         scale[1] = 0.5;
6677ec681f3Smrg
6687ec681f3Smrg      guardband_x = MIN2(guardband_x, (max_range - fabsf(translate[0])) / scale[0]);
6697ec681f3Smrg      guardband_y = MIN2(guardband_y, (max_range - fabsf(translate[1])) / scale[1]);
6707ec681f3Smrg
6717ec681f3Smrg      radeon_emit(cs, S_028250_TL_X(scissor.offset.x) | S_028250_TL_Y(scissor.offset.y) |
6727ec681f3Smrg                         S_028250_WINDOW_OFFSET_DISABLE(1));
6737ec681f3Smrg      radeon_emit(cs, S_028254_BR_X(scissor.offset.x + scissor.extent.width) |
6747ec681f3Smrg                         S_028254_BR_Y(scissor.offset.y + scissor.extent.height));
6757ec681f3Smrg   }
6767ec681f3Smrg   if (!can_use_guardband) {
6777ec681f3Smrg      guardband_x = 1.0;
6787ec681f3Smrg      guardband_y = 1.0;
6797ec681f3Smrg   }
6807ec681f3Smrg
6817ec681f3Smrg   radeon_set_context_reg_seq(cs, R_028BE8_PA_CL_GB_VERT_CLIP_ADJ, 4);
6827ec681f3Smrg   radeon_emit(cs, fui(guardband_y));
6837ec681f3Smrg   radeon_emit(cs, fui(1.0));
6847ec681f3Smrg   radeon_emit(cs, fui(guardband_x));
6857ec681f3Smrg   radeon_emit(cs, fui(1.0));
68601e04c3fSmrg}
68701e04c3fSmrg
68801e04c3fSmrgstatic inline unsigned
68901e04c3fSmrgradv_prims_for_vertices(struct radv_prim_vertex_count *info, unsigned num)
69001e04c3fSmrg{
6917ec681f3Smrg   if (num == 0)
6927ec681f3Smrg      return 0;
69301e04c3fSmrg
6947ec681f3Smrg   if (info->incr == 0)
6957ec681f3Smrg      return 0;
69601e04c3fSmrg
6977ec681f3Smrg   if (num < info->min)
6987ec681f3Smrg      return 0;
69901e04c3fSmrg
7007ec681f3Smrg   return 1 + ((num - info->min) / info->incr);
70101e04c3fSmrg}
70201e04c3fSmrg
7037ec681f3Smrgstatic const struct radv_prim_vertex_count prim_size_table[] = {
7047ec681f3Smrg   [V_008958_DI_PT_NONE] = {0, 0},          [V_008958_DI_PT_POINTLIST] = {1, 1},
7057ec681f3Smrg   [V_008958_DI_PT_LINELIST] = {2, 2},      [V_008958_DI_PT_LINESTRIP] = {2, 1},
7067ec681f3Smrg   [V_008958_DI_PT_TRILIST] = {3, 3},       [V_008958_DI_PT_TRIFAN] = {3, 1},
7077ec681f3Smrg   [V_008958_DI_PT_TRISTRIP] = {3, 1},      [V_008958_DI_PT_LINELIST_ADJ] = {4, 4},
7087ec681f3Smrg   [V_008958_DI_PT_LINESTRIP_ADJ] = {4, 1}, [V_008958_DI_PT_TRILIST_ADJ] = {6, 6},
7097ec681f3Smrg   [V_008958_DI_PT_TRISTRIP_ADJ] = {6, 2},  [V_008958_DI_PT_RECTLIST] = {3, 3},
7107ec681f3Smrg   [V_008958_DI_PT_LINELOOP] = {2, 1},      [V_008958_DI_PT_POLYGON] = {3, 1},
7117ec681f3Smrg   [V_008958_DI_PT_2D_TRI_STRIP] = {0, 0},
7127ec681f3Smrg};
7137ec681f3Smrg
71401e04c3fSmrguint32_t
7157ec681f3Smrgsi_get_ia_multi_vgt_param(struct radv_cmd_buffer *cmd_buffer, bool instanced_draw,
7167ec681f3Smrg                          bool indirect_draw, bool count_from_stream_output,
7177ec681f3Smrg                          uint32_t draw_vertex_count, unsigned topology, bool prim_restart_enable)
71801e04c3fSmrg{
7197ec681f3Smrg   enum chip_class chip_class = cmd_buffer->device->physical_device->rad_info.chip_class;
7207ec681f3Smrg   enum radeon_family family = cmd_buffer->device->physical_device->rad_info.family;
7217ec681f3Smrg   struct radeon_info *info = &cmd_buffer->device->physical_device->rad_info;
7227ec681f3Smrg   const unsigned max_primgroup_in_wave = 2;
7237ec681f3Smrg   /* SWITCH_ON_EOP(0) is always preferable. */
7247ec681f3Smrg   bool wd_switch_on_eop = false;
7257ec681f3Smrg   bool ia_switch_on_eop = false;
7267ec681f3Smrg   bool ia_switch_on_eoi = false;
7277ec681f3Smrg   bool partial_vs_wave = false;
7287ec681f3Smrg   bool partial_es_wave = cmd_buffer->state.pipeline->graphics.ia_multi_vgt_param.partial_es_wave;
7297ec681f3Smrg   bool multi_instances_smaller_than_primgroup;
7307ec681f3Smrg   struct radv_prim_vertex_count prim_vertex_count = prim_size_table[topology];
7317ec681f3Smrg
7327ec681f3Smrg   if (radv_pipeline_has_tess(cmd_buffer->state.pipeline)) {
7337ec681f3Smrg      if (topology == V_008958_DI_PT_PATCH) {
7347ec681f3Smrg         prim_vertex_count.min = cmd_buffer->state.pipeline->graphics.tess_patch_control_points;
7357ec681f3Smrg         prim_vertex_count.incr = 1;
7367ec681f3Smrg      }
7377ec681f3Smrg   }
7387ec681f3Smrg
7397ec681f3Smrg   multi_instances_smaller_than_primgroup = indirect_draw;
7407ec681f3Smrg   if (!multi_instances_smaller_than_primgroup && instanced_draw) {
7417ec681f3Smrg      uint32_t num_prims = radv_prims_for_vertices(&prim_vertex_count, draw_vertex_count);
7427ec681f3Smrg      if (num_prims < cmd_buffer->state.pipeline->graphics.ia_multi_vgt_param.primgroup_size)
7437ec681f3Smrg         multi_instances_smaller_than_primgroup = true;
7447ec681f3Smrg   }
7457ec681f3Smrg
7467ec681f3Smrg   ia_switch_on_eoi = cmd_buffer->state.pipeline->graphics.ia_multi_vgt_param.ia_switch_on_eoi;
7477ec681f3Smrg   partial_vs_wave = cmd_buffer->state.pipeline->graphics.ia_multi_vgt_param.partial_vs_wave;
7487ec681f3Smrg
7497ec681f3Smrg   if (chip_class >= GFX7) {
7507ec681f3Smrg      /* WD_SWITCH_ON_EOP has no effect on GPUs with less than
7517ec681f3Smrg       * 4 shader engines. Set 1 to pass the assertion below.
7527ec681f3Smrg       * The other cases are hardware requirements. */
7537ec681f3Smrg      if (cmd_buffer->device->physical_device->rad_info.max_se < 4 ||
7547ec681f3Smrg          topology == V_008958_DI_PT_POLYGON || topology == V_008958_DI_PT_LINELOOP ||
7557ec681f3Smrg          topology == V_008958_DI_PT_TRIFAN || topology == V_008958_DI_PT_TRISTRIP_ADJ ||
7567ec681f3Smrg          (prim_restart_enable &&
7577ec681f3Smrg           (cmd_buffer->device->physical_device->rad_info.family < CHIP_POLARIS10 ||
7587ec681f3Smrg            (topology != V_008958_DI_PT_POINTLIST && topology != V_008958_DI_PT_LINESTRIP))))
7597ec681f3Smrg         wd_switch_on_eop = true;
7607ec681f3Smrg
7617ec681f3Smrg      /* Hawaii hangs if instancing is enabled and WD_SWITCH_ON_EOP is 0.
7627ec681f3Smrg       * We don't know that for indirect drawing, so treat it as
7637ec681f3Smrg       * always problematic. */
7647ec681f3Smrg      if (family == CHIP_HAWAII && (instanced_draw || indirect_draw))
7657ec681f3Smrg         wd_switch_on_eop = true;
7667ec681f3Smrg
7677ec681f3Smrg      /* Performance recommendation for 4 SE Gfx7-8 parts if
7687ec681f3Smrg       * instances are smaller than a primgroup.
7697ec681f3Smrg       * Assume indirect draws always use small instances.
7707ec681f3Smrg       * This is needed for good VS wave utilization.
7717ec681f3Smrg       */
7727ec681f3Smrg      if (chip_class <= GFX8 && info->max_se == 4 && multi_instances_smaller_than_primgroup)
7737ec681f3Smrg         wd_switch_on_eop = true;
7747ec681f3Smrg
7757ec681f3Smrg      /* Required on GFX7 and later. */
7767ec681f3Smrg      if (info->max_se > 2 && !wd_switch_on_eop)
7777ec681f3Smrg         ia_switch_on_eoi = true;
7787ec681f3Smrg
7797ec681f3Smrg      /* Required by Hawaii and, for some special cases, by GFX8. */
7807ec681f3Smrg      if (ia_switch_on_eoi &&
7817ec681f3Smrg          (family == CHIP_HAWAII ||
7827ec681f3Smrg           (chip_class == GFX8 &&
7837ec681f3Smrg            /* max primgroup in wave is always 2 - leave this for documentation */
7847ec681f3Smrg            (radv_pipeline_has_gs(cmd_buffer->state.pipeline) || max_primgroup_in_wave != 2))))
7857ec681f3Smrg         partial_vs_wave = true;
7867ec681f3Smrg
7877ec681f3Smrg      /* Instancing bug on Bonaire. */
7887ec681f3Smrg      if (family == CHIP_BONAIRE && ia_switch_on_eoi && (instanced_draw || indirect_draw))
7897ec681f3Smrg         partial_vs_wave = true;
7907ec681f3Smrg
7917ec681f3Smrg      /* Hardware requirement when drawing primitives from a stream
7927ec681f3Smrg       * output buffer.
7937ec681f3Smrg       */
7947ec681f3Smrg      if (count_from_stream_output)
7957ec681f3Smrg         wd_switch_on_eop = true;
7967ec681f3Smrg
7977ec681f3Smrg      /* If the WD switch is false, the IA switch must be false too. */
7987ec681f3Smrg      assert(wd_switch_on_eop || !ia_switch_on_eop);
7997ec681f3Smrg   }
8007ec681f3Smrg   /* If SWITCH_ON_EOI is set, PARTIAL_ES_WAVE must be set too. */
8017ec681f3Smrg   if (chip_class <= GFX8 && ia_switch_on_eoi)
8027ec681f3Smrg      partial_es_wave = true;
8037ec681f3Smrg
8047ec681f3Smrg   if (radv_pipeline_has_gs(cmd_buffer->state.pipeline)) {
8057ec681f3Smrg      /* GS hw bug with single-primitive instances and SWITCH_ON_EOI.
8067ec681f3Smrg       * The hw doc says all multi-SE chips are affected, but amdgpu-pro Vulkan
8077ec681f3Smrg       * only applies it to Hawaii. Do what amdgpu-pro Vulkan does.
8087ec681f3Smrg       */
8097ec681f3Smrg      if (family == CHIP_HAWAII && ia_switch_on_eoi) {
8107ec681f3Smrg         bool set_vgt_flush = indirect_draw;
8117ec681f3Smrg         if (!set_vgt_flush && instanced_draw) {
8127ec681f3Smrg            uint32_t num_prims = radv_prims_for_vertices(&prim_vertex_count, draw_vertex_count);
8137ec681f3Smrg            if (num_prims <= 1)
8147ec681f3Smrg               set_vgt_flush = true;
8157ec681f3Smrg         }
8167ec681f3Smrg         if (set_vgt_flush)
8177ec681f3Smrg            cmd_buffer->state.flush_bits |= RADV_CMD_FLAG_VGT_FLUSH;
8187ec681f3Smrg      }
8197ec681f3Smrg   }
8207ec681f3Smrg
8217ec681f3Smrg   /* Workaround for a VGT hang when strip primitive types are used with
8227ec681f3Smrg    * primitive restart.
8237ec681f3Smrg    */
8247ec681f3Smrg   if (prim_restart_enable &&
8257ec681f3Smrg       (topology == V_008958_DI_PT_LINESTRIP || topology == V_008958_DI_PT_TRISTRIP ||
8267ec681f3Smrg        topology == V_008958_DI_PT_LINESTRIP_ADJ || topology == V_008958_DI_PT_TRISTRIP_ADJ)) {
8277ec681f3Smrg      partial_vs_wave = true;
8287ec681f3Smrg   }
8297ec681f3Smrg
8307ec681f3Smrg   return cmd_buffer->state.pipeline->graphics.ia_multi_vgt_param.base |
8317ec681f3Smrg          S_028AA8_SWITCH_ON_EOP(ia_switch_on_eop) | S_028AA8_SWITCH_ON_EOI(ia_switch_on_eoi) |
8327ec681f3Smrg          S_028AA8_PARTIAL_VS_WAVE_ON(partial_vs_wave) |
8337ec681f3Smrg          S_028AA8_PARTIAL_ES_WAVE_ON(partial_es_wave) |
8347ec681f3Smrg          S_028AA8_WD_SWITCH_ON_EOP(chip_class >= GFX7 ? wd_switch_on_eop : 0);
83501e04c3fSmrg}
83601e04c3fSmrg
8377ec681f3Smrgvoid
8387ec681f3Smrgsi_cs_emit_write_event_eop(struct radeon_cmdbuf *cs, enum chip_class chip_class, bool is_mec,
8397ec681f3Smrg                           unsigned event, unsigned event_flags, unsigned dst_sel,
8407ec681f3Smrg                           unsigned data_sel, uint64_t va, uint32_t new_fence,
8417ec681f3Smrg                           uint64_t gfx9_eop_bug_va)
84201e04c3fSmrg{
8437ec681f3Smrg   unsigned op = EVENT_TYPE(event) |
8447ec681f3Smrg                 EVENT_INDEX(event == V_028A90_CS_DONE || event == V_028A90_PS_DONE ? 6 : 5) |
8457ec681f3Smrg                 event_flags;
8467ec681f3Smrg   unsigned is_gfx8_mec = is_mec && chip_class < GFX9;
8477ec681f3Smrg   unsigned sel = EOP_DST_SEL(dst_sel) | EOP_DATA_SEL(data_sel);
8487ec681f3Smrg
8497ec681f3Smrg   /* Wait for write confirmation before writing data, but don't send
8507ec681f3Smrg    * an interrupt. */
8517ec681f3Smrg   if (data_sel != EOP_DATA_SEL_DISCARD)
8527ec681f3Smrg      sel |= EOP_INT_SEL(EOP_INT_SEL_SEND_DATA_AFTER_WR_CONFIRM);
8537ec681f3Smrg
8547ec681f3Smrg   if (chip_class >= GFX9 || is_gfx8_mec) {
8557ec681f3Smrg      /* A ZPASS_DONE or PIXEL_STAT_DUMP_EVENT (of the DB occlusion
8567ec681f3Smrg       * counters) must immediately precede every timestamp event to
8577ec681f3Smrg       * prevent a GPU hang on GFX9.
8587ec681f3Smrg       */
8597ec681f3Smrg      if (chip_class == GFX9 && !is_mec) {
8607ec681f3Smrg         radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 2, 0));
8617ec681f3Smrg         radeon_emit(cs, EVENT_TYPE(EVENT_TYPE_ZPASS_DONE) | EVENT_INDEX(1));
8627ec681f3Smrg         radeon_emit(cs, gfx9_eop_bug_va);
8637ec681f3Smrg         radeon_emit(cs, gfx9_eop_bug_va >> 32);
8647ec681f3Smrg      }
8657ec681f3Smrg
8667ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_RELEASE_MEM, is_gfx8_mec ? 5 : 6, false));
8677ec681f3Smrg      radeon_emit(cs, op);
8687ec681f3Smrg      radeon_emit(cs, sel);
8697ec681f3Smrg      radeon_emit(cs, va);        /* address lo */
8707ec681f3Smrg      radeon_emit(cs, va >> 32);  /* address hi */
8717ec681f3Smrg      radeon_emit(cs, new_fence); /* immediate data lo */
8727ec681f3Smrg      radeon_emit(cs, 0);         /* immediate data hi */
8737ec681f3Smrg      if (!is_gfx8_mec)
8747ec681f3Smrg         radeon_emit(cs, 0); /* unused */
8757ec681f3Smrg   } else {
8767ec681f3Smrg      /* On GFX6, EOS events are always emitted with EVENT_WRITE_EOS.
8777ec681f3Smrg       * On GFX7+, EOS events are emitted with EVENT_WRITE_EOS on
8787ec681f3Smrg       * the graphics queue, and with RELEASE_MEM on the compute
8797ec681f3Smrg       * queue.
8807ec681f3Smrg       */
8817ec681f3Smrg      if (event == V_028B9C_CS_DONE || event == V_028B9C_PS_DONE) {
8827ec681f3Smrg         assert(event_flags == 0 && dst_sel == EOP_DST_SEL_MEM &&
8837ec681f3Smrg                data_sel == EOP_DATA_SEL_VALUE_32BIT);
8847ec681f3Smrg
8857ec681f3Smrg         if (is_mec) {
8867ec681f3Smrg            radeon_emit(cs, PKT3(PKT3_RELEASE_MEM, 5, false));
8877ec681f3Smrg            radeon_emit(cs, op);
8887ec681f3Smrg            radeon_emit(cs, sel);
8897ec681f3Smrg            radeon_emit(cs, va);        /* address lo */
8907ec681f3Smrg            radeon_emit(cs, va >> 32);  /* address hi */
8917ec681f3Smrg            radeon_emit(cs, new_fence); /* immediate data lo */
8927ec681f3Smrg            radeon_emit(cs, 0);         /* immediate data hi */
8937ec681f3Smrg         } else {
8947ec681f3Smrg            radeon_emit(cs, PKT3(PKT3_EVENT_WRITE_EOS, 3, false));
8957ec681f3Smrg            radeon_emit(cs, op);
8967ec681f3Smrg            radeon_emit(cs, va);
8977ec681f3Smrg            radeon_emit(cs, ((va >> 32) & 0xffff) | EOS_DATA_SEL(EOS_DATA_SEL_VALUE_32BIT));
8987ec681f3Smrg            radeon_emit(cs, new_fence);
8997ec681f3Smrg         }
9007ec681f3Smrg      } else {
9017ec681f3Smrg         if (chip_class == GFX7 || chip_class == GFX8) {
9027ec681f3Smrg            /* Two EOP events are required to make all
9037ec681f3Smrg             * engines go idle (and optional cache flushes
9047ec681f3Smrg             * executed) before the timestamp is written.
9057ec681f3Smrg             */
9067ec681f3Smrg            radeon_emit(cs, PKT3(PKT3_EVENT_WRITE_EOP, 4, false));
9077ec681f3Smrg            radeon_emit(cs, op);
9087ec681f3Smrg            radeon_emit(cs, va);
9097ec681f3Smrg            radeon_emit(cs, ((va >> 32) & 0xffff) | sel);
9107ec681f3Smrg            radeon_emit(cs, 0); /* immediate data */
9117ec681f3Smrg            radeon_emit(cs, 0); /* unused */
9127ec681f3Smrg         }
9137ec681f3Smrg
9147ec681f3Smrg         radeon_emit(cs, PKT3(PKT3_EVENT_WRITE_EOP, 4, false));
9157ec681f3Smrg         radeon_emit(cs, op);
9167ec681f3Smrg         radeon_emit(cs, va);
9177ec681f3Smrg         radeon_emit(cs, ((va >> 32) & 0xffff) | sel);
9187ec681f3Smrg         radeon_emit(cs, new_fence); /* immediate data */
9197ec681f3Smrg         radeon_emit(cs, 0);         /* unused */
9207ec681f3Smrg      }
9217ec681f3Smrg   }
92201e04c3fSmrg}
92301e04c3fSmrg
92401e04c3fSmrgvoid
9257ec681f3Smrgradv_cp_wait_mem(struct radeon_cmdbuf *cs, uint32_t op, uint64_t va, uint32_t ref, uint32_t mask)
92601e04c3fSmrg{
9277ec681f3Smrg   assert(op == WAIT_REG_MEM_EQUAL || op == WAIT_REG_MEM_NOT_EQUAL ||
9287ec681f3Smrg          op == WAIT_REG_MEM_GREATER_OR_EQUAL);
9297ec681f3Smrg
9307ec681f3Smrg   radeon_emit(cs, PKT3(PKT3_WAIT_REG_MEM, 5, false));
9317ec681f3Smrg   radeon_emit(cs, op | WAIT_REG_MEM_MEM_SPACE(1));
9327ec681f3Smrg   radeon_emit(cs, va);
9337ec681f3Smrg   radeon_emit(cs, va >> 32);
9347ec681f3Smrg   radeon_emit(cs, ref);  /* reference value */
9357ec681f3Smrg   radeon_emit(cs, mask); /* mask */
9367ec681f3Smrg   radeon_emit(cs, 4);    /* poll interval */
93701e04c3fSmrg}
93801e04c3fSmrg
93901e04c3fSmrgstatic void
9407ec681f3Smrgsi_emit_acquire_mem(struct radeon_cmdbuf *cs, bool is_mec, bool is_gfx9, unsigned cp_coher_cntl)
94101e04c3fSmrg{
9427ec681f3Smrg   if (is_mec || is_gfx9) {
9437ec681f3Smrg      uint32_t hi_val = is_gfx9 ? 0xffffff : 0xff;
9447ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_ACQUIRE_MEM, 5, false) | PKT3_SHADER_TYPE_S(is_mec));
9457ec681f3Smrg      radeon_emit(cs, cp_coher_cntl); /* CP_COHER_CNTL */
9467ec681f3Smrg      radeon_emit(cs, 0xffffffff);    /* CP_COHER_SIZE */
9477ec681f3Smrg      radeon_emit(cs, hi_val);        /* CP_COHER_SIZE_HI */
9487ec681f3Smrg      radeon_emit(cs, 0);             /* CP_COHER_BASE */
9497ec681f3Smrg      radeon_emit(cs, 0);             /* CP_COHER_BASE_HI */
9507ec681f3Smrg      radeon_emit(cs, 0x0000000A);    /* POLL_INTERVAL */
9517ec681f3Smrg   } else {
9527ec681f3Smrg      /* ACQUIRE_MEM is only required on a compute ring. */
9537ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_SURFACE_SYNC, 3, false));
9547ec681f3Smrg      radeon_emit(cs, cp_coher_cntl); /* CP_COHER_CNTL */
9557ec681f3Smrg      radeon_emit(cs, 0xffffffff);    /* CP_COHER_SIZE */
9567ec681f3Smrg      radeon_emit(cs, 0);             /* CP_COHER_BASE */
9577ec681f3Smrg      radeon_emit(cs, 0x0000000A);    /* POLL_INTERVAL */
9587ec681f3Smrg   }
9597ec681f3Smrg}
9607ec681f3Smrg
9617ec681f3Smrgstatic void
9627ec681f3Smrggfx10_cs_emit_cache_flush(struct radeon_cmdbuf *cs, enum chip_class chip_class, uint32_t *flush_cnt,
9637ec681f3Smrg                          uint64_t flush_va, bool is_mec, enum radv_cmd_flush_bits flush_bits,
9647ec681f3Smrg                          enum rgp_flush_bits *sqtt_flush_bits, uint64_t gfx9_eop_bug_va)
9657ec681f3Smrg{
9667ec681f3Smrg   uint32_t gcr_cntl = 0;
9677ec681f3Smrg   unsigned cb_db_event = 0;
9687ec681f3Smrg
9697ec681f3Smrg   /* We don't need these. */
9707ec681f3Smrg   assert(!(flush_bits & (RADV_CMD_FLAG_VGT_STREAMOUT_SYNC)));
9717ec681f3Smrg
9727ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_INV_ICACHE) {
9737ec681f3Smrg      gcr_cntl |= S_586_GLI_INV(V_586_GLI_ALL);
9747ec681f3Smrg
9757ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_INVAL_ICACHE;
9767ec681f3Smrg   }
9777ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_INV_SCACHE) {
9787ec681f3Smrg      /* TODO: When writing to the SMEM L1 cache, we need to set SEQ
9797ec681f3Smrg       * to FORWARD when both L1 and L2 are written out (WB or INV).
9807ec681f3Smrg       */
9817ec681f3Smrg      gcr_cntl |= S_586_GL1_INV(1) | S_586_GLK_INV(1);
9827ec681f3Smrg
9837ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_INVAL_SMEM_L0;
9847ec681f3Smrg   }
9857ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_INV_VCACHE) {
9867ec681f3Smrg      gcr_cntl |= S_586_GL1_INV(1) | S_586_GLV_INV(1);
9877ec681f3Smrg
9887ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_INVAL_VMEM_L0 | RGP_FLUSH_INVAL_L1;
9897ec681f3Smrg   }
9907ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_INV_L2) {
9917ec681f3Smrg      /* Writeback and invalidate everything in L2. */
9927ec681f3Smrg      gcr_cntl |= S_586_GL2_INV(1) | S_586_GL2_WB(1) | S_586_GLM_INV(1) | S_586_GLM_WB(1);
9937ec681f3Smrg
9947ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_INVAL_L2;
9957ec681f3Smrg   } else if (flush_bits & RADV_CMD_FLAG_WB_L2) {
9967ec681f3Smrg      /* Writeback but do not invalidate.
9977ec681f3Smrg       * GLM doesn't support WB alone. If WB is set, INV must be set too.
9987ec681f3Smrg       */
9997ec681f3Smrg      gcr_cntl |= S_586_GL2_WB(1) | S_586_GLM_WB(1) | S_586_GLM_INV(1);
10007ec681f3Smrg
10017ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_FLUSH_L2;
10027ec681f3Smrg   } else if (flush_bits & RADV_CMD_FLAG_INV_L2_METADATA) {
10037ec681f3Smrg      gcr_cntl |= S_586_GLM_INV(1) | S_586_GLM_WB(1);
10047ec681f3Smrg   }
10057ec681f3Smrg
10067ec681f3Smrg   if (flush_bits & (RADV_CMD_FLAG_FLUSH_AND_INV_CB | RADV_CMD_FLAG_FLUSH_AND_INV_DB)) {
10077ec681f3Smrg      /* TODO: trigger on RADV_CMD_FLAG_FLUSH_AND_INV_CB_META */
10087ec681f3Smrg      if (flush_bits & RADV_CMD_FLAG_FLUSH_AND_INV_CB) {
10097ec681f3Smrg         /* Flush CMASK/FMASK/DCC. Will wait for idle later. */
10107ec681f3Smrg         radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
10117ec681f3Smrg         radeon_emit(cs, EVENT_TYPE(V_028A90_FLUSH_AND_INV_CB_META) | EVENT_INDEX(0));
10127ec681f3Smrg
10137ec681f3Smrg         *sqtt_flush_bits |= RGP_FLUSH_FLUSH_CB | RGP_FLUSH_INVAL_CB;
10147ec681f3Smrg      }
10157ec681f3Smrg
10167ec681f3Smrg      /* TODO: trigger on RADV_CMD_FLAG_FLUSH_AND_INV_DB_META ? */
10177ec681f3Smrg      if (flush_bits & RADV_CMD_FLAG_FLUSH_AND_INV_DB) {
10187ec681f3Smrg         /* Flush HTILE. Will wait for idle later. */
10197ec681f3Smrg         radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
10207ec681f3Smrg         radeon_emit(cs, EVENT_TYPE(V_028A90_FLUSH_AND_INV_DB_META) | EVENT_INDEX(0));
10217ec681f3Smrg
10227ec681f3Smrg         *sqtt_flush_bits |= RGP_FLUSH_FLUSH_DB | RGP_FLUSH_INVAL_DB;
10237ec681f3Smrg      }
10247ec681f3Smrg
10257ec681f3Smrg      /* First flush CB/DB, then L1/L2. */
10267ec681f3Smrg      gcr_cntl |= S_586_SEQ(V_586_SEQ_FORWARD);
10277ec681f3Smrg
10287ec681f3Smrg      if ((flush_bits & (RADV_CMD_FLAG_FLUSH_AND_INV_CB | RADV_CMD_FLAG_FLUSH_AND_INV_DB)) ==
10297ec681f3Smrg          (RADV_CMD_FLAG_FLUSH_AND_INV_CB | RADV_CMD_FLAG_FLUSH_AND_INV_DB)) {
10307ec681f3Smrg         cb_db_event = V_028A90_CACHE_FLUSH_AND_INV_TS_EVENT;
10317ec681f3Smrg      } else if (flush_bits & RADV_CMD_FLAG_FLUSH_AND_INV_CB) {
10327ec681f3Smrg         cb_db_event = V_028A90_FLUSH_AND_INV_CB_DATA_TS;
10337ec681f3Smrg      } else if (flush_bits & RADV_CMD_FLAG_FLUSH_AND_INV_DB) {
10347ec681f3Smrg         cb_db_event = V_028A90_FLUSH_AND_INV_DB_DATA_TS;
10357ec681f3Smrg      } else {
10367ec681f3Smrg         assert(0);
10377ec681f3Smrg      }
10387ec681f3Smrg   } else {
10397ec681f3Smrg      /* Wait for graphics shaders to go idle if requested. */
10407ec681f3Smrg      if (flush_bits & RADV_CMD_FLAG_PS_PARTIAL_FLUSH) {
10417ec681f3Smrg         radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
10427ec681f3Smrg         radeon_emit(cs, EVENT_TYPE(V_028A90_PS_PARTIAL_FLUSH) | EVENT_INDEX(4));
10437ec681f3Smrg
10447ec681f3Smrg         *sqtt_flush_bits |= RGP_FLUSH_PS_PARTIAL_FLUSH;
10457ec681f3Smrg      } else if (flush_bits & RADV_CMD_FLAG_VS_PARTIAL_FLUSH) {
10467ec681f3Smrg         radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
10477ec681f3Smrg         radeon_emit(cs, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH) | EVENT_INDEX(4));
10487ec681f3Smrg
10497ec681f3Smrg         *sqtt_flush_bits |= RGP_FLUSH_VS_PARTIAL_FLUSH;
10507ec681f3Smrg      }
10517ec681f3Smrg   }
10527ec681f3Smrg
10537ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_CS_PARTIAL_FLUSH) {
10547ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
10557ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_CS_PARTIAL_FLUSH | EVENT_INDEX(4)));
10567ec681f3Smrg
10577ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_CS_PARTIAL_FLUSH;
10587ec681f3Smrg   }
10597ec681f3Smrg
10607ec681f3Smrg   if (cb_db_event) {
10617ec681f3Smrg      /* CB/DB flush and invalidate (or possibly just a wait for a
10627ec681f3Smrg       * meta flush) via RELEASE_MEM.
10637ec681f3Smrg       *
10647ec681f3Smrg       * Combine this with other cache flushes when possible; this
10657ec681f3Smrg       * requires affected shaders to be idle, so do it after the
10667ec681f3Smrg       * CS_PARTIAL_FLUSH before (VS/PS partial flushes are always
10677ec681f3Smrg       * implied).
10687ec681f3Smrg       */
10697ec681f3Smrg      /* Get GCR_CNTL fields, because the encoding is different in RELEASE_MEM. */
10707ec681f3Smrg      unsigned glm_wb = G_586_GLM_WB(gcr_cntl);
10717ec681f3Smrg      unsigned glm_inv = G_586_GLM_INV(gcr_cntl);
10727ec681f3Smrg      unsigned glv_inv = G_586_GLV_INV(gcr_cntl);
10737ec681f3Smrg      unsigned gl1_inv = G_586_GL1_INV(gcr_cntl);
10747ec681f3Smrg      assert(G_586_GL2_US(gcr_cntl) == 0);
10757ec681f3Smrg      assert(G_586_GL2_RANGE(gcr_cntl) == 0);
10767ec681f3Smrg      assert(G_586_GL2_DISCARD(gcr_cntl) == 0);
10777ec681f3Smrg      unsigned gl2_inv = G_586_GL2_INV(gcr_cntl);
10787ec681f3Smrg      unsigned gl2_wb = G_586_GL2_WB(gcr_cntl);
10797ec681f3Smrg      unsigned gcr_seq = G_586_SEQ(gcr_cntl);
10807ec681f3Smrg
10817ec681f3Smrg      gcr_cntl &= C_586_GLM_WB & C_586_GLM_INV & C_586_GLV_INV & C_586_GL1_INV & C_586_GL2_INV &
10827ec681f3Smrg                  C_586_GL2_WB; /* keep SEQ */
10837ec681f3Smrg
10847ec681f3Smrg      assert(flush_cnt);
10857ec681f3Smrg      (*flush_cnt)++;
10867ec681f3Smrg
10877ec681f3Smrg      si_cs_emit_write_event_eop(
10887ec681f3Smrg         cs, chip_class, false, cb_db_event,
10897ec681f3Smrg         S_490_GLM_WB(glm_wb) | S_490_GLM_INV(glm_inv) | S_490_GLV_INV(glv_inv) |
10907ec681f3Smrg            S_490_GL1_INV(gl1_inv) | S_490_GL2_INV(gl2_inv) | S_490_GL2_WB(gl2_wb) |
10917ec681f3Smrg            S_490_SEQ(gcr_seq),
10927ec681f3Smrg         EOP_DST_SEL_MEM, EOP_DATA_SEL_VALUE_32BIT, flush_va, *flush_cnt, gfx9_eop_bug_va);
10937ec681f3Smrg
10947ec681f3Smrg      radv_cp_wait_mem(cs, WAIT_REG_MEM_EQUAL, flush_va, *flush_cnt, 0xffffffff);
10957ec681f3Smrg   }
10967ec681f3Smrg
10977ec681f3Smrg   /* VGT state sync */
10987ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_VGT_FLUSH) {
10997ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
11007ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_VGT_FLUSH) | EVENT_INDEX(0));
11017ec681f3Smrg   }
11027ec681f3Smrg
11037ec681f3Smrg   /* Ignore fields that only modify the behavior of other fields. */
11047ec681f3Smrg   if (gcr_cntl & C_586_GL1_RANGE & C_586_GL2_RANGE & C_586_SEQ) {
11057ec681f3Smrg      /* Flush caches and wait for the caches to assert idle.
11067ec681f3Smrg       * The cache flush is executed in the ME, but the PFP waits
11077ec681f3Smrg       * for completion.
11087ec681f3Smrg       */
11097ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_ACQUIRE_MEM, 6, 0));
11107ec681f3Smrg      radeon_emit(cs, 0);          /* CP_COHER_CNTL */
11117ec681f3Smrg      radeon_emit(cs, 0xffffffff); /* CP_COHER_SIZE */
11127ec681f3Smrg      radeon_emit(cs, 0xffffff);   /* CP_COHER_SIZE_HI */
11137ec681f3Smrg      radeon_emit(cs, 0);          /* CP_COHER_BASE */
11147ec681f3Smrg      radeon_emit(cs, 0);          /* CP_COHER_BASE_HI */
11157ec681f3Smrg      radeon_emit(cs, 0x0000000A); /* POLL_INTERVAL */
11167ec681f3Smrg      radeon_emit(cs, gcr_cntl);   /* GCR_CNTL */
11177ec681f3Smrg   } else if ((cb_db_event ||
11187ec681f3Smrg               (flush_bits & (RADV_CMD_FLAG_VS_PARTIAL_FLUSH | RADV_CMD_FLAG_PS_PARTIAL_FLUSH |
11197ec681f3Smrg                              RADV_CMD_FLAG_CS_PARTIAL_FLUSH))) &&
11207ec681f3Smrg              !is_mec) {
11217ec681f3Smrg      /* We need to ensure that PFP waits as well. */
11227ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_PFP_SYNC_ME, 0, 0));
11237ec681f3Smrg      radeon_emit(cs, 0);
11247ec681f3Smrg
11257ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_PFP_SYNC_ME;
11267ec681f3Smrg   }
11277ec681f3Smrg
11287ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_START_PIPELINE_STATS) {
11297ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
11307ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_PIPELINESTAT_START) | EVENT_INDEX(0));
11317ec681f3Smrg   } else if (flush_bits & RADV_CMD_FLAG_STOP_PIPELINE_STATS) {
11327ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
11337ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_PIPELINESTAT_STOP) | EVENT_INDEX(0));
11347ec681f3Smrg   }
113501e04c3fSmrg}
113601e04c3fSmrg
113701e04c3fSmrgvoid
11387ec681f3Smrgsi_cs_emit_cache_flush(struct radeon_cmdbuf *cs, enum chip_class chip_class, uint32_t *flush_cnt,
11397ec681f3Smrg                       uint64_t flush_va, bool is_mec, enum radv_cmd_flush_bits flush_bits,
11407ec681f3Smrg                       enum rgp_flush_bits *sqtt_flush_bits, uint64_t gfx9_eop_bug_va)
114101e04c3fSmrg{
11427ec681f3Smrg   unsigned cp_coher_cntl = 0;
11437ec681f3Smrg   uint32_t flush_cb_db =
11447ec681f3Smrg      flush_bits & (RADV_CMD_FLAG_FLUSH_AND_INV_CB | RADV_CMD_FLAG_FLUSH_AND_INV_DB);
11457ec681f3Smrg
11467ec681f3Smrg   if (chip_class >= GFX10) {
11477ec681f3Smrg      /* GFX10 cache flush handling is quite different. */
11487ec681f3Smrg      gfx10_cs_emit_cache_flush(cs, chip_class, flush_cnt, flush_va, is_mec, flush_bits,
11497ec681f3Smrg                                sqtt_flush_bits, gfx9_eop_bug_va);
11507ec681f3Smrg      return;
11517ec681f3Smrg   }
11527ec681f3Smrg
11537ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_INV_ICACHE) {
11547ec681f3Smrg      cp_coher_cntl |= S_0085F0_SH_ICACHE_ACTION_ENA(1);
11557ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_INVAL_ICACHE;
11567ec681f3Smrg   }
11577ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_INV_SCACHE) {
11587ec681f3Smrg      cp_coher_cntl |= S_0085F0_SH_KCACHE_ACTION_ENA(1);
11597ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_INVAL_SMEM_L0;
11607ec681f3Smrg   }
11617ec681f3Smrg
11627ec681f3Smrg   if (chip_class <= GFX8) {
11637ec681f3Smrg      if (flush_bits & RADV_CMD_FLAG_FLUSH_AND_INV_CB) {
11647ec681f3Smrg         cp_coher_cntl |= S_0085F0_CB_ACTION_ENA(1) | S_0085F0_CB0_DEST_BASE_ENA(1) |
11657ec681f3Smrg                          S_0085F0_CB1_DEST_BASE_ENA(1) | S_0085F0_CB2_DEST_BASE_ENA(1) |
11667ec681f3Smrg                          S_0085F0_CB3_DEST_BASE_ENA(1) | S_0085F0_CB4_DEST_BASE_ENA(1) |
11677ec681f3Smrg                          S_0085F0_CB5_DEST_BASE_ENA(1) | S_0085F0_CB6_DEST_BASE_ENA(1) |
11687ec681f3Smrg                          S_0085F0_CB7_DEST_BASE_ENA(1);
11697ec681f3Smrg
11707ec681f3Smrg         /* Necessary for DCC */
11717ec681f3Smrg         if (chip_class >= GFX8) {
11727ec681f3Smrg            si_cs_emit_write_event_eop(cs, chip_class, is_mec, V_028A90_FLUSH_AND_INV_CB_DATA_TS, 0,
11737ec681f3Smrg                                       EOP_DST_SEL_MEM, EOP_DATA_SEL_DISCARD, 0, 0,
11747ec681f3Smrg                                       gfx9_eop_bug_va);
11757ec681f3Smrg         }
11767ec681f3Smrg
11777ec681f3Smrg         *sqtt_flush_bits |= RGP_FLUSH_FLUSH_CB | RGP_FLUSH_INVAL_CB;
11787ec681f3Smrg      }
11797ec681f3Smrg      if (flush_bits & RADV_CMD_FLAG_FLUSH_AND_INV_DB) {
11807ec681f3Smrg         cp_coher_cntl |= S_0085F0_DB_ACTION_ENA(1) | S_0085F0_DB_DEST_BASE_ENA(1);
11817ec681f3Smrg
11827ec681f3Smrg         *sqtt_flush_bits |= RGP_FLUSH_FLUSH_DB | RGP_FLUSH_INVAL_DB;
11837ec681f3Smrg      }
11847ec681f3Smrg   }
11857ec681f3Smrg
11867ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_FLUSH_AND_INV_CB_META) {
11877ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
11887ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_FLUSH_AND_INV_CB_META) | EVENT_INDEX(0));
11897ec681f3Smrg
11907ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_FLUSH_CB | RGP_FLUSH_INVAL_CB;
11917ec681f3Smrg   }
11927ec681f3Smrg
11937ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_FLUSH_AND_INV_DB_META) {
11947ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
11957ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_FLUSH_AND_INV_DB_META) | EVENT_INDEX(0));
11967ec681f3Smrg
11977ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_FLUSH_DB | RGP_FLUSH_INVAL_DB;
11987ec681f3Smrg   }
11997ec681f3Smrg
12007ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_PS_PARTIAL_FLUSH) {
12017ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
12027ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_PS_PARTIAL_FLUSH) | EVENT_INDEX(4));
12037ec681f3Smrg
12047ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_PS_PARTIAL_FLUSH;
12057ec681f3Smrg   } else if (flush_bits & RADV_CMD_FLAG_VS_PARTIAL_FLUSH) {
12067ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
12077ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH) | EVENT_INDEX(4));
12087ec681f3Smrg
12097ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_VS_PARTIAL_FLUSH;
12107ec681f3Smrg   }
12117ec681f3Smrg
12127ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_CS_PARTIAL_FLUSH) {
12137ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
12147ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_CS_PARTIAL_FLUSH) | EVENT_INDEX(4));
12157ec681f3Smrg
12167ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_CS_PARTIAL_FLUSH;
12177ec681f3Smrg   }
12187ec681f3Smrg
12197ec681f3Smrg   if (chip_class == GFX9 && flush_cb_db) {
12207ec681f3Smrg      unsigned cb_db_event, tc_flags;
12217ec681f3Smrg
12227ec681f3Smrg      /* Set the CB/DB flush event. */
12237ec681f3Smrg      cb_db_event = V_028A90_CACHE_FLUSH_AND_INV_TS_EVENT;
12247ec681f3Smrg
12257ec681f3Smrg      /* These are the only allowed combinations. If you need to
12267ec681f3Smrg       * do multiple operations at once, do them separately.
12277ec681f3Smrg       * All operations that invalidate L2 also seem to invalidate
12287ec681f3Smrg       * metadata. Volatile (VOL) and WC flushes are not listed here.
12297ec681f3Smrg       *
12307ec681f3Smrg       * TC    | TC_WB         = writeback & invalidate L2 & L1
12317ec681f3Smrg       * TC    | TC_WB | TC_NC = writeback & invalidate L2 for MTYPE == NC
12327ec681f3Smrg       *         TC_WB | TC_NC = writeback L2 for MTYPE == NC
12337ec681f3Smrg       * TC            | TC_NC = invalidate L2 for MTYPE == NC
12347ec681f3Smrg       * TC    | TC_MD         = writeback & invalidate L2 metadata (DCC, etc.)
12357ec681f3Smrg       * TCL1                  = invalidate L1
12367ec681f3Smrg       */
12377ec681f3Smrg      tc_flags = EVENT_TC_ACTION_ENA | EVENT_TC_MD_ACTION_ENA;
12387ec681f3Smrg
12397ec681f3Smrg      *sqtt_flush_bits |=
12407ec681f3Smrg         RGP_FLUSH_FLUSH_CB | RGP_FLUSH_INVAL_CB | RGP_FLUSH_FLUSH_DB | RGP_FLUSH_INVAL_DB;
12417ec681f3Smrg
12427ec681f3Smrg      /* Ideally flush TC together with CB/DB. */
12437ec681f3Smrg      if (flush_bits & RADV_CMD_FLAG_INV_L2) {
12447ec681f3Smrg         /* Writeback and invalidate everything in L2 & L1. */
12457ec681f3Smrg         tc_flags = EVENT_TC_ACTION_ENA | EVENT_TC_WB_ACTION_ENA;
12467ec681f3Smrg
12477ec681f3Smrg         /* Clear the flags. */
12487ec681f3Smrg         flush_bits &= ~(RADV_CMD_FLAG_INV_L2 | RADV_CMD_FLAG_WB_L2 | RADV_CMD_FLAG_INV_VCACHE);
12497ec681f3Smrg
12507ec681f3Smrg         *sqtt_flush_bits |= RGP_FLUSH_INVAL_L2;
12517ec681f3Smrg      }
12527ec681f3Smrg
12537ec681f3Smrg      assert(flush_cnt);
12547ec681f3Smrg      (*flush_cnt)++;
12557ec681f3Smrg
12567ec681f3Smrg      si_cs_emit_write_event_eop(cs, chip_class, false, cb_db_event, tc_flags, EOP_DST_SEL_MEM,
12577ec681f3Smrg                                 EOP_DATA_SEL_VALUE_32BIT, flush_va, *flush_cnt, gfx9_eop_bug_va);
12587ec681f3Smrg      radv_cp_wait_mem(cs, WAIT_REG_MEM_EQUAL, flush_va, *flush_cnt, 0xffffffff);
12597ec681f3Smrg   }
12607ec681f3Smrg
12617ec681f3Smrg   /* VGT state sync */
12627ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_VGT_FLUSH) {
12637ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
12647ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_VGT_FLUSH) | EVENT_INDEX(0));
12657ec681f3Smrg   }
12667ec681f3Smrg
12677ec681f3Smrg   /* VGT streamout state sync */
12687ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_VGT_STREAMOUT_SYNC) {
12697ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
12707ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_VGT_STREAMOUT_SYNC) | EVENT_INDEX(0));
12717ec681f3Smrg   }
12727ec681f3Smrg
12737ec681f3Smrg   /* Make sure ME is idle (it executes most packets) before continuing.
12747ec681f3Smrg    * This prevents read-after-write hazards between PFP and ME.
12757ec681f3Smrg    */
12767ec681f3Smrg   if ((cp_coher_cntl || (flush_bits & (RADV_CMD_FLAG_CS_PARTIAL_FLUSH | RADV_CMD_FLAG_INV_VCACHE |
12777ec681f3Smrg                                        RADV_CMD_FLAG_INV_L2 | RADV_CMD_FLAG_WB_L2))) &&
12787ec681f3Smrg       !is_mec) {
12797ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_PFP_SYNC_ME, 0, 0));
12807ec681f3Smrg      radeon_emit(cs, 0);
12817ec681f3Smrg
12827ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_PFP_SYNC_ME;
12837ec681f3Smrg   }
12847ec681f3Smrg
12857ec681f3Smrg   if ((flush_bits & RADV_CMD_FLAG_INV_L2) ||
12867ec681f3Smrg       (chip_class <= GFX7 && (flush_bits & RADV_CMD_FLAG_WB_L2))) {
12877ec681f3Smrg      si_emit_acquire_mem(cs, is_mec, chip_class == GFX9,
12887ec681f3Smrg                          cp_coher_cntl | S_0085F0_TC_ACTION_ENA(1) | S_0085F0_TCL1_ACTION_ENA(1) |
12897ec681f3Smrg                             S_0301F0_TC_WB_ACTION_ENA(chip_class >= GFX8));
12907ec681f3Smrg      cp_coher_cntl = 0;
12917ec681f3Smrg
12927ec681f3Smrg      *sqtt_flush_bits |= RGP_FLUSH_INVAL_L2 | RGP_FLUSH_INVAL_VMEM_L0;
12937ec681f3Smrg   } else {
12947ec681f3Smrg      if (flush_bits & RADV_CMD_FLAG_WB_L2) {
12957ec681f3Smrg         /* WB = write-back
12967ec681f3Smrg          * NC = apply to non-coherent MTYPEs
12977ec681f3Smrg          *      (i.e. MTYPE <= 1, which is what we use everywhere)
12987ec681f3Smrg          *
12997ec681f3Smrg          * WB doesn't work without NC.
13007ec681f3Smrg          */
13017ec681f3Smrg         si_emit_acquire_mem(
13027ec681f3Smrg            cs, is_mec, chip_class == GFX9,
13037ec681f3Smrg            cp_coher_cntl | S_0301F0_TC_WB_ACTION_ENA(1) | S_0301F0_TC_NC_ACTION_ENA(1));
13047ec681f3Smrg         cp_coher_cntl = 0;
13057ec681f3Smrg
13067ec681f3Smrg         *sqtt_flush_bits |= RGP_FLUSH_FLUSH_L2 | RGP_FLUSH_INVAL_VMEM_L0;
13077ec681f3Smrg      }
13087ec681f3Smrg      if (flush_bits & RADV_CMD_FLAG_INV_VCACHE) {
13097ec681f3Smrg         si_emit_acquire_mem(cs, is_mec, chip_class == GFX9,
13107ec681f3Smrg                             cp_coher_cntl | S_0085F0_TCL1_ACTION_ENA(1));
13117ec681f3Smrg         cp_coher_cntl = 0;
13127ec681f3Smrg
13137ec681f3Smrg         *sqtt_flush_bits |= RGP_FLUSH_INVAL_VMEM_L0;
13147ec681f3Smrg      }
13157ec681f3Smrg   }
13167ec681f3Smrg
13177ec681f3Smrg   /* When one of the DEST_BASE flags is set, SURFACE_SYNC waits for idle.
13187ec681f3Smrg    * Therefore, it should be last. Done in PFP.
13197ec681f3Smrg    */
13207ec681f3Smrg   if (cp_coher_cntl)
13217ec681f3Smrg      si_emit_acquire_mem(cs, is_mec, chip_class == GFX9, cp_coher_cntl);
13227ec681f3Smrg
13237ec681f3Smrg   if (flush_bits & RADV_CMD_FLAG_START_PIPELINE_STATS) {
13247ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
13257ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_PIPELINESTAT_START) | EVENT_INDEX(0));
13267ec681f3Smrg   } else if (flush_bits & RADV_CMD_FLAG_STOP_PIPELINE_STATS) {
13277ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
13287ec681f3Smrg      radeon_emit(cs, EVENT_TYPE(V_028A90_PIPELINESTAT_STOP) | EVENT_INDEX(0));
13297ec681f3Smrg   }
133001e04c3fSmrg}
133101e04c3fSmrg
133201e04c3fSmrgvoid
133301e04c3fSmrgsi_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer)
133401e04c3fSmrg{
13357ec681f3Smrg   bool is_compute = cmd_buffer->queue_family_index == RADV_QUEUE_COMPUTE;
13367ec681f3Smrg
13377ec681f3Smrg   if (is_compute)
13387ec681f3Smrg      cmd_buffer->state.flush_bits &=
13397ec681f3Smrg         ~(RADV_CMD_FLAG_FLUSH_AND_INV_CB | RADV_CMD_FLAG_FLUSH_AND_INV_CB_META |
13407ec681f3Smrg           RADV_CMD_FLAG_FLUSH_AND_INV_DB | RADV_CMD_FLAG_FLUSH_AND_INV_DB_META |
13417ec681f3Smrg           RADV_CMD_FLAG_INV_L2_METADATA | RADV_CMD_FLAG_PS_PARTIAL_FLUSH |
13427ec681f3Smrg           RADV_CMD_FLAG_VS_PARTIAL_FLUSH | RADV_CMD_FLAG_VGT_FLUSH |
13437ec681f3Smrg           RADV_CMD_FLAG_START_PIPELINE_STATS | RADV_CMD_FLAG_STOP_PIPELINE_STATS);
13447ec681f3Smrg
13457ec681f3Smrg   if (!cmd_buffer->state.flush_bits) {
13467ec681f3Smrg      radv_describe_barrier_end_delayed(cmd_buffer);
13477ec681f3Smrg      return;
13487ec681f3Smrg   }
13497ec681f3Smrg
13507ec681f3Smrg   radeon_check_space(cmd_buffer->device->ws, cmd_buffer->cs, 128);
13517ec681f3Smrg
13527ec681f3Smrg   si_cs_emit_cache_flush(cmd_buffer->cs, cmd_buffer->device->physical_device->rad_info.chip_class,
13537ec681f3Smrg                          &cmd_buffer->gfx9_fence_idx, cmd_buffer->gfx9_fence_va,
13547ec681f3Smrg                          radv_cmd_buffer_uses_mec(cmd_buffer), cmd_buffer->state.flush_bits,
13557ec681f3Smrg                          &cmd_buffer->state.sqtt_flush_bits, cmd_buffer->gfx9_eop_bug_va);
13567ec681f3Smrg
13577ec681f3Smrg   if (unlikely(cmd_buffer->device->trace_bo))
13587ec681f3Smrg      radv_cmd_buffer_trace_emit(cmd_buffer);
13597ec681f3Smrg
13607ec681f3Smrg   if (cmd_buffer->state.flush_bits & RADV_CMD_FLAG_INV_L2)
13617ec681f3Smrg      cmd_buffer->state.rb_noncoherent_dirty = false;
13627ec681f3Smrg
13637ec681f3Smrg   /* Clear the caches that have been flushed to avoid syncing too much
13647ec681f3Smrg    * when there is some pending active queries.
13657ec681f3Smrg    */
13667ec681f3Smrg   cmd_buffer->active_query_flush_bits &= ~cmd_buffer->state.flush_bits;
13677ec681f3Smrg
13687ec681f3Smrg   cmd_buffer->state.flush_bits = 0;
13697ec681f3Smrg
13707ec681f3Smrg   /* If the driver used a compute shader for resetting a query pool, it
13717ec681f3Smrg    * should be finished at this point.
13727ec681f3Smrg    */
13737ec681f3Smrg   cmd_buffer->pending_reset_query = false;
13747ec681f3Smrg
13757ec681f3Smrg   radv_describe_barrier_end_delayed(cmd_buffer);
137601e04c3fSmrg}
137701e04c3fSmrg
137801e04c3fSmrg/* sets the CP predication state using a boolean stored at va */
137901e04c3fSmrgvoid
13807ec681f3Smrgsi_emit_set_predication_state(struct radv_cmd_buffer *cmd_buffer, bool draw_visible,
13817ec681f3Smrg                              unsigned pred_op, uint64_t va)
138201e04c3fSmrg{
13837ec681f3Smrg   uint32_t op = 0;
13847ec681f3Smrg
13857ec681f3Smrg   if (va) {
13867ec681f3Smrg      assert(pred_op == PREDICATION_OP_BOOL32 || pred_op == PREDICATION_OP_BOOL64);
13877ec681f3Smrg
13887ec681f3Smrg      op = PRED_OP(pred_op);
13897ec681f3Smrg
13907ec681f3Smrg      /* PREDICATION_DRAW_VISIBLE means that if the 32-bit value is
13917ec681f3Smrg       * zero, all rendering commands are discarded. Otherwise, they
13927ec681f3Smrg       * are discarded if the value is non zero.
13937ec681f3Smrg       */
13947ec681f3Smrg      op |= draw_visible ? PREDICATION_DRAW_VISIBLE : PREDICATION_DRAW_NOT_VISIBLE;
13957ec681f3Smrg   }
13967ec681f3Smrg   if (cmd_buffer->device->physical_device->rad_info.chip_class >= GFX9) {
13977ec681f3Smrg      radeon_emit(cmd_buffer->cs, PKT3(PKT3_SET_PREDICATION, 2, 0));
13987ec681f3Smrg      radeon_emit(cmd_buffer->cs, op);
13997ec681f3Smrg      radeon_emit(cmd_buffer->cs, va);
14007ec681f3Smrg      radeon_emit(cmd_buffer->cs, va >> 32);
14017ec681f3Smrg   } else {
14027ec681f3Smrg      radeon_emit(cmd_buffer->cs, PKT3(PKT3_SET_PREDICATION, 1, 0));
14037ec681f3Smrg      radeon_emit(cmd_buffer->cs, va);
14047ec681f3Smrg      radeon_emit(cmd_buffer->cs, op | ((va >> 32) & 0xFF));
14057ec681f3Smrg   }
140601e04c3fSmrg}
140701e04c3fSmrg
140801e04c3fSmrg/* Set this if you want the 3D engine to wait until CP DMA is done.
140901e04c3fSmrg * It should be set on the last CP DMA packet. */
14107ec681f3Smrg#define CP_DMA_SYNC (1 << 0)
141101e04c3fSmrg
141201e04c3fSmrg/* Set this if the source data was used as a destination in a previous CP DMA
141301e04c3fSmrg * packet. It's for preventing a read-after-write (RAW) hazard between two
141401e04c3fSmrg * CP DMA packets. */
14157ec681f3Smrg#define CP_DMA_RAW_WAIT (1 << 1)
14167ec681f3Smrg#define CP_DMA_USE_L2   (1 << 2)
14177ec681f3Smrg#define CP_DMA_CLEAR    (1 << 3)
141801e04c3fSmrg
141901e04c3fSmrg/* Alignment for optimal performance. */
14207ec681f3Smrg#define SI_CPDMA_ALIGNMENT 32
142101e04c3fSmrg
142201e04c3fSmrg/* The max number of bytes that can be copied per packet. */
14237ec681f3Smrgstatic inline unsigned
14247ec681f3Smrgcp_dma_max_byte_count(struct radv_cmd_buffer *cmd_buffer)
142501e04c3fSmrg{
14267ec681f3Smrg   unsigned max = cmd_buffer->device->physical_device->rad_info.chip_class >= GFX9
14277ec681f3Smrg                     ? S_415_BYTE_COUNT_GFX9(~0u)
14287ec681f3Smrg                     : S_415_BYTE_COUNT_GFX6(~0u);
142901e04c3fSmrg
14307ec681f3Smrg   /* make it aligned for optimal performance */
14317ec681f3Smrg   return max & ~(SI_CPDMA_ALIGNMENT - 1);
143201e04c3fSmrg}
143301e04c3fSmrg
143401e04c3fSmrg/* Emit a CP DMA packet to do a copy from one buffer to another, or to clear
143501e04c3fSmrg * a buffer. The size must fit in bits [20:0]. If CP_DMA_CLEAR is set, src_va is a 32-bit
143601e04c3fSmrg * clear value.
143701e04c3fSmrg */
14387ec681f3Smrgstatic void
14397ec681f3Smrgsi_emit_cp_dma(struct radv_cmd_buffer *cmd_buffer, uint64_t dst_va, uint64_t src_va, unsigned size,
14407ec681f3Smrg               unsigned flags)
144101e04c3fSmrg{
14427ec681f3Smrg   struct radeon_cmdbuf *cs = cmd_buffer->cs;
14437ec681f3Smrg   uint32_t header = 0, command = 0;
14447ec681f3Smrg
14457ec681f3Smrg   assert(size <= cp_dma_max_byte_count(cmd_buffer));
14467ec681f3Smrg
14477ec681f3Smrg   radeon_check_space(cmd_buffer->device->ws, cmd_buffer->cs, 9);
14487ec681f3Smrg   if (cmd_buffer->device->physical_device->rad_info.chip_class >= GFX9)
14497ec681f3Smrg      command |= S_415_BYTE_COUNT_GFX9(size);
14507ec681f3Smrg   else
14517ec681f3Smrg      command |= S_415_BYTE_COUNT_GFX6(size);
14527ec681f3Smrg
14537ec681f3Smrg   /* Sync flags. */
14547ec681f3Smrg   if (flags & CP_DMA_SYNC)
14557ec681f3Smrg      header |= S_411_CP_SYNC(1);
14567ec681f3Smrg   else {
14577ec681f3Smrg      if (cmd_buffer->device->physical_device->rad_info.chip_class >= GFX9)
14587ec681f3Smrg         command |= S_415_DISABLE_WR_CONFIRM_GFX9(1);
14597ec681f3Smrg      else
14607ec681f3Smrg         command |= S_415_DISABLE_WR_CONFIRM_GFX6(1);
14617ec681f3Smrg   }
14627ec681f3Smrg
14637ec681f3Smrg   if (flags & CP_DMA_RAW_WAIT)
14647ec681f3Smrg      command |= S_415_RAW_WAIT(1);
14657ec681f3Smrg
14667ec681f3Smrg   /* Src and dst flags. */
14677ec681f3Smrg   if (cmd_buffer->device->physical_device->rad_info.chip_class >= GFX9 &&
14687ec681f3Smrg       !(flags & CP_DMA_CLEAR) && src_va == dst_va)
14697ec681f3Smrg      header |= S_411_DST_SEL(V_411_NOWHERE); /* prefetch only */
14707ec681f3Smrg   else if (flags & CP_DMA_USE_L2)
14717ec681f3Smrg      header |= S_411_DST_SEL(V_411_DST_ADDR_TC_L2);
14727ec681f3Smrg
14737ec681f3Smrg   if (flags & CP_DMA_CLEAR)
14747ec681f3Smrg      header |= S_411_SRC_SEL(V_411_DATA);
14757ec681f3Smrg   else if (flags & CP_DMA_USE_L2)
14767ec681f3Smrg      header |= S_411_SRC_SEL(V_411_SRC_ADDR_TC_L2);
14777ec681f3Smrg
14787ec681f3Smrg   if (cmd_buffer->device->physical_device->rad_info.chip_class >= GFX7) {
14797ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_DMA_DATA, 5, cmd_buffer->state.predicating));
14807ec681f3Smrg      radeon_emit(cs, header);
14817ec681f3Smrg      radeon_emit(cs, src_va);       /* SRC_ADDR_LO [31:0] */
14827ec681f3Smrg      radeon_emit(cs, src_va >> 32); /* SRC_ADDR_HI [31:0] */
14837ec681f3Smrg      radeon_emit(cs, dst_va);       /* DST_ADDR_LO [31:0] */
14847ec681f3Smrg      radeon_emit(cs, dst_va >> 32); /* DST_ADDR_HI [31:0] */
14857ec681f3Smrg      radeon_emit(cs, command);
14867ec681f3Smrg   } else {
14877ec681f3Smrg      assert(!(flags & CP_DMA_USE_L2));
14887ec681f3Smrg      header |= S_411_SRC_ADDR_HI(src_va >> 32);
14897ec681f3Smrg      radeon_emit(cs, PKT3(PKT3_CP_DMA, 4, cmd_buffer->state.predicating));
14907ec681f3Smrg      radeon_emit(cs, src_va);                  /* SRC_ADDR_LO [31:0] */
14917ec681f3Smrg      radeon_emit(cs, header);                  /* SRC_ADDR_HI [15:0] + flags. */
14927ec681f3Smrg      radeon_emit(cs, dst_va);                  /* DST_ADDR_LO [31:0] */
14937ec681f3Smrg      radeon_emit(cs, (dst_va >> 32) & 0xffff); /* DST_ADDR_HI [15:0] */
14947ec681f3Smrg      radeon_emit(cs, command);
14957ec681f3Smrg   }
14967ec681f3Smrg
14977ec681f3Smrg   /* CP DMA is executed in ME, but index buffers are read by PFP.
14987ec681f3Smrg    * This ensures that ME (CP DMA) is idle before PFP starts fetching
14997ec681f3Smrg    * indices. If we wanted to execute CP DMA in PFP, this packet
15007ec681f3Smrg    * should precede it.
15017ec681f3Smrg    */
15027ec681f3Smrg   if (flags & CP_DMA_SYNC) {
15037ec681f3Smrg      if (cmd_buffer->queue_family_index == RADV_QUEUE_GENERAL) {
15047ec681f3Smrg         radeon_emit(cs, PKT3(PKT3_PFP_SYNC_ME, 0, cmd_buffer->state.predicating));
15057ec681f3Smrg         radeon_emit(cs, 0);
15067ec681f3Smrg      }
15077ec681f3Smrg
15087ec681f3Smrg      /* CP will see the sync flag and wait for all DMAs to complete. */
15097ec681f3Smrg      cmd_buffer->state.dma_is_busy = false;
15107ec681f3Smrg   }
15117ec681f3Smrg
15127ec681f3Smrg   if (unlikely(cmd_buffer->device->trace_bo))
15137ec681f3Smrg      radv_cmd_buffer_trace_emit(cmd_buffer);
151401e04c3fSmrg}
151501e04c3fSmrg
15167ec681f3Smrgvoid
15177ec681f3Smrgsi_cp_dma_prefetch(struct radv_cmd_buffer *cmd_buffer, uint64_t va, unsigned size)
151801e04c3fSmrg{
15197ec681f3Smrg   uint64_t aligned_va = va & ~(SI_CPDMA_ALIGNMENT - 1);
15207ec681f3Smrg   uint64_t aligned_size =
15217ec681f3Smrg      ((va + size + SI_CPDMA_ALIGNMENT - 1) & ~(SI_CPDMA_ALIGNMENT - 1)) - aligned_va;
152201e04c3fSmrg
15237ec681f3Smrg   si_emit_cp_dma(cmd_buffer, aligned_va, aligned_va, aligned_size, CP_DMA_USE_L2);
152401e04c3fSmrg}
152501e04c3fSmrg
15267ec681f3Smrgstatic void
15277ec681f3Smrgsi_cp_dma_prepare(struct radv_cmd_buffer *cmd_buffer, uint64_t byte_count, uint64_t remaining_size,
15287ec681f3Smrg                  unsigned *flags)
152901e04c3fSmrg{
153001e04c3fSmrg
15317ec681f3Smrg   /* Flush the caches for the first copy only.
15327ec681f3Smrg    * Also wait for the previous CP DMA operations.
15337ec681f3Smrg    */
15347ec681f3Smrg   if (cmd_buffer->state.flush_bits) {
15357ec681f3Smrg      si_emit_cache_flush(cmd_buffer);
15367ec681f3Smrg      *flags |= CP_DMA_RAW_WAIT;
15377ec681f3Smrg   }
15387ec681f3Smrg
15397ec681f3Smrg   /* Do the synchronization after the last dma, so that all data
15407ec681f3Smrg    * is written to memory.
15417ec681f3Smrg    */
15427ec681f3Smrg   if (byte_count == remaining_size)
15437ec681f3Smrg      *flags |= CP_DMA_SYNC;
154401e04c3fSmrg}
154501e04c3fSmrg
15467ec681f3Smrgstatic void
15477ec681f3Smrgsi_cp_dma_realign_engine(struct radv_cmd_buffer *cmd_buffer, unsigned size)
154801e04c3fSmrg{
15497ec681f3Smrg   uint64_t va;
15507ec681f3Smrg   uint32_t offset;
15517ec681f3Smrg   unsigned dma_flags = 0;
15527ec681f3Smrg   unsigned buf_size = SI_CPDMA_ALIGNMENT * 2;
15537ec681f3Smrg   void *ptr;
155401e04c3fSmrg
15557ec681f3Smrg   assert(size < SI_CPDMA_ALIGNMENT);
155601e04c3fSmrg
15577ec681f3Smrg   radv_cmd_buffer_upload_alloc(cmd_buffer, buf_size, &offset, &ptr);
155801e04c3fSmrg
15597ec681f3Smrg   va = radv_buffer_get_va(cmd_buffer->upload.upload_bo);
15607ec681f3Smrg   va += offset;
156101e04c3fSmrg
15627ec681f3Smrg   si_cp_dma_prepare(cmd_buffer, size, size, &dma_flags);
156301e04c3fSmrg
15647ec681f3Smrg   si_emit_cp_dma(cmd_buffer, va, va + SI_CPDMA_ALIGNMENT, size, dma_flags);
156501e04c3fSmrg}
156601e04c3fSmrg
15677ec681f3Smrgvoid
15687ec681f3Smrgsi_cp_dma_buffer_copy(struct radv_cmd_buffer *cmd_buffer, uint64_t src_va, uint64_t dest_va,
15697ec681f3Smrg                      uint64_t size)
157001e04c3fSmrg{
15717ec681f3Smrg   uint64_t main_src_va, main_dest_va;
15727ec681f3Smrg   uint64_t skipped_size = 0, realign_size = 0;
15737ec681f3Smrg
15747ec681f3Smrg   /* Assume that we are not going to sync after the last DMA operation. */
15757ec681f3Smrg   cmd_buffer->state.dma_is_busy = true;
15767ec681f3Smrg
15777ec681f3Smrg   if (cmd_buffer->device->physical_device->rad_info.family <= CHIP_CARRIZO ||
15787ec681f3Smrg       cmd_buffer->device->physical_device->rad_info.family == CHIP_STONEY) {
15797ec681f3Smrg      /* If the size is not aligned, we must add a dummy copy at the end
15807ec681f3Smrg       * just to align the internal counter. Otherwise, the DMA engine
15817ec681f3Smrg       * would slow down by an order of magnitude for following copies.
15827ec681f3Smrg       */
15837ec681f3Smrg      if (size % SI_CPDMA_ALIGNMENT)
15847ec681f3Smrg         realign_size = SI_CPDMA_ALIGNMENT - (size % SI_CPDMA_ALIGNMENT);
15857ec681f3Smrg
15867ec681f3Smrg      /* If the copy begins unaligned, we must start copying from the next
15877ec681f3Smrg       * aligned block and the skipped part should be copied after everything
15887ec681f3Smrg       * else has been copied. Only the src alignment matters, not dst.
15897ec681f3Smrg       */
15907ec681f3Smrg      if (src_va % SI_CPDMA_ALIGNMENT) {
15917ec681f3Smrg         skipped_size = SI_CPDMA_ALIGNMENT - (src_va % SI_CPDMA_ALIGNMENT);
15927ec681f3Smrg         /* The main part will be skipped if the size is too small. */
15937ec681f3Smrg         skipped_size = MIN2(skipped_size, size);
15947ec681f3Smrg         size -= skipped_size;
15957ec681f3Smrg      }
15967ec681f3Smrg   }
15977ec681f3Smrg   main_src_va = src_va + skipped_size;
15987ec681f3Smrg   main_dest_va = dest_va + skipped_size;
15997ec681f3Smrg
16007ec681f3Smrg   while (size) {
16017ec681f3Smrg      unsigned dma_flags = 0;
16027ec681f3Smrg      unsigned byte_count = MIN2(size, cp_dma_max_byte_count(cmd_buffer));
16037ec681f3Smrg
16047ec681f3Smrg      if (cmd_buffer->device->physical_device->rad_info.chip_class >= GFX9) {
16057ec681f3Smrg         /* DMA operations via L2 are coherent and faster.
16067ec681f3Smrg          * TODO: GFX7-GFX8 should also support this but it
16077ec681f3Smrg          * requires tests/benchmarks.
16087ec681f3Smrg          *
16097ec681f3Smrg          * Also enable on GFX9 so we can use L2 at rest on GFX9+. On Raven
16107ec681f3Smrg          * this didn't seem to be worse.
16117ec681f3Smrg          *
16127ec681f3Smrg          * Note that we only use CP DMA for sizes < RADV_BUFFER_OPS_CS_THRESHOLD,
16137ec681f3Smrg          * which is 4k at the moment, so this is really unlikely to cause
16147ec681f3Smrg          * significant thrashing.
16157ec681f3Smrg          */
16167ec681f3Smrg         dma_flags |= CP_DMA_USE_L2;
16177ec681f3Smrg      }
16187ec681f3Smrg
16197ec681f3Smrg      si_cp_dma_prepare(cmd_buffer, byte_count, size + skipped_size + realign_size, &dma_flags);
16207ec681f3Smrg
16217ec681f3Smrg      dma_flags &= ~CP_DMA_SYNC;
16227ec681f3Smrg
16237ec681f3Smrg      si_emit_cp_dma(cmd_buffer, main_dest_va, main_src_va, byte_count, dma_flags);
16247ec681f3Smrg
16257ec681f3Smrg      size -= byte_count;
16267ec681f3Smrg      main_src_va += byte_count;
16277ec681f3Smrg      main_dest_va += byte_count;
16287ec681f3Smrg   }
16297ec681f3Smrg
16307ec681f3Smrg   if (skipped_size) {
16317ec681f3Smrg      unsigned dma_flags = 0;
16327ec681f3Smrg
16337ec681f3Smrg      si_cp_dma_prepare(cmd_buffer, skipped_size, size + skipped_size + realign_size, &dma_flags);
16347ec681f3Smrg
16357ec681f3Smrg      si_emit_cp_dma(cmd_buffer, dest_va, src_va, skipped_size, dma_flags);
16367ec681f3Smrg   }
16377ec681f3Smrg   if (realign_size)
16387ec681f3Smrg      si_cp_dma_realign_engine(cmd_buffer, realign_size);
163901e04c3fSmrg}
164001e04c3fSmrg
16417ec681f3Smrgvoid
16427ec681f3Smrgsi_cp_dma_clear_buffer(struct radv_cmd_buffer *cmd_buffer, uint64_t va, uint64_t size,
16437ec681f3Smrg                       unsigned value)
164401e04c3fSmrg{
164501e04c3fSmrg
16467ec681f3Smrg   if (!size)
16477ec681f3Smrg      return;
164801e04c3fSmrg
16497ec681f3Smrg   assert(va % 4 == 0 && size % 4 == 0);
165001e04c3fSmrg
16517ec681f3Smrg   /* Assume that we are not going to sync after the last DMA operation. */
16527ec681f3Smrg   cmd_buffer->state.dma_is_busy = true;
165301e04c3fSmrg
16547ec681f3Smrg   while (size) {
16557ec681f3Smrg      unsigned byte_count = MIN2(size, cp_dma_max_byte_count(cmd_buffer));
16567ec681f3Smrg      unsigned dma_flags = CP_DMA_CLEAR;
165701e04c3fSmrg
16587ec681f3Smrg      if (cmd_buffer->device->physical_device->rad_info.chip_class >= GFX9) {
16597ec681f3Smrg         /* DMA operations via L2 are coherent and faster.
16607ec681f3Smrg          * TODO: GFX7-GFX8 should also support this but it
16617ec681f3Smrg          * requires tests/benchmarks.
16627ec681f3Smrg          *
16637ec681f3Smrg          * Also enable on GFX9 so we can use L2 at rest on GFX9+.
16647ec681f3Smrg          */
16657ec681f3Smrg         dma_flags |= CP_DMA_USE_L2;
16667ec681f3Smrg      }
166701e04c3fSmrg
16687ec681f3Smrg      si_cp_dma_prepare(cmd_buffer, byte_count, size, &dma_flags);
166901e04c3fSmrg
16707ec681f3Smrg      /* Emit the clear packet. */
16717ec681f3Smrg      si_emit_cp_dma(cmd_buffer, va, value, byte_count, dma_flags);
16727ec681f3Smrg
16737ec681f3Smrg      size -= byte_count;
16747ec681f3Smrg      va += byte_count;
16757ec681f3Smrg   }
167601e04c3fSmrg}
167701e04c3fSmrg
16787ec681f3Smrgvoid
16797ec681f3Smrgsi_cp_dma_wait_for_idle(struct radv_cmd_buffer *cmd_buffer)
168001e04c3fSmrg{
16817ec681f3Smrg   if (cmd_buffer->device->physical_device->rad_info.chip_class < GFX7)
16827ec681f3Smrg      return;
168301e04c3fSmrg
16847ec681f3Smrg   if (!cmd_buffer->state.dma_is_busy)
16857ec681f3Smrg      return;
168601e04c3fSmrg
16877ec681f3Smrg   /* Issue a dummy DMA that copies zero bytes.
16887ec681f3Smrg    *
16897ec681f3Smrg    * The DMA engine will see that there's no work to do and skip this
16907ec681f3Smrg    * DMA request, however, the CP will see the sync flag and still wait
16917ec681f3Smrg    * for all DMAs to complete.
16927ec681f3Smrg    */
16937ec681f3Smrg   si_emit_cp_dma(cmd_buffer, 0, 0, 0, CP_DMA_SYNC);
169401e04c3fSmrg
16957ec681f3Smrg   cmd_buffer->state.dma_is_busy = false;
169601e04c3fSmrg}
169701e04c3fSmrg
169801e04c3fSmrg/* For MSAA sample positions. */
16997ec681f3Smrg#define FILL_SREG(s0x, s0y, s1x, s1y, s2x, s2y, s3x, s3y)                                          \
17007ec681f3Smrg   ((((unsigned)(s0x)&0xf) << 0) | (((unsigned)(s0y)&0xf) << 4) | (((unsigned)(s1x)&0xf) << 8) |   \
17017ec681f3Smrg    (((unsigned)(s1y)&0xf) << 12) | (((unsigned)(s2x)&0xf) << 16) |                                \
17027ec681f3Smrg    (((unsigned)(s2y)&0xf) << 20) | (((unsigned)(s3x)&0xf) << 24) | (((unsigned)(s3y)&0xf) << 28))
17037ec681f3Smrg
17047ec681f3Smrg/* For obtaining location coordinates from registers */
17057ec681f3Smrg#define SEXT4(x)               ((int)((x) | ((x)&0x8 ? 0xfffffff0 : 0)))
17067ec681f3Smrg#define GET_SFIELD(reg, index) SEXT4(((reg) >> ((index)*4)) & 0xf)
17077ec681f3Smrg#define GET_SX(reg, index)     GET_SFIELD((reg)[(index) / 4], ((index) % 4) * 2)
17087ec681f3Smrg#define GET_SY(reg, index)     GET_SFIELD((reg)[(index) / 4], ((index) % 4) * 2 + 1)
17097ec681f3Smrg
17107ec681f3Smrg/* 1x MSAA */
17117ec681f3Smrgstatic const uint32_t sample_locs_1x = FILL_SREG(0, 0, 0, 0, 0, 0, 0, 0);
17127ec681f3Smrgstatic const unsigned max_dist_1x = 0;
17137ec681f3Smrgstatic const uint64_t centroid_priority_1x = 0x0000000000000000ull;
17147ec681f3Smrg
17157ec681f3Smrg/* 2xMSAA */
17167ec681f3Smrgstatic const uint32_t sample_locs_2x = FILL_SREG(4, 4, -4, -4, 0, 0, 0, 0);
17177ec681f3Smrgstatic const unsigned max_dist_2x = 4;
17187ec681f3Smrgstatic const uint64_t centroid_priority_2x = 0x1010101010101010ull;
17197ec681f3Smrg
17207ec681f3Smrg/* 4xMSAA */
17217ec681f3Smrgstatic const uint32_t sample_locs_4x = FILL_SREG(-2, -6, 6, -2, -6, 2, 2, 6);
17227ec681f3Smrgstatic const unsigned max_dist_4x = 6;
17237ec681f3Smrgstatic const uint64_t centroid_priority_4x = 0x3210321032103210ull;
17247ec681f3Smrg
17257ec681f3Smrg/* 8xMSAA */
17267ec681f3Smrgstatic const uint32_t sample_locs_8x[] = {
17277ec681f3Smrg   FILL_SREG(1, -3, -1, 3, 5, 1, -3, -5),
17287ec681f3Smrg   FILL_SREG(-5, 5, -7, -1, 3, 7, 7, -7),
17297ec681f3Smrg   /* The following are unused by hardware, but we emit them to IBs
17307ec681f3Smrg    * instead of multiple SET_CONTEXT_REG packets. */
17317ec681f3Smrg   0,
17327ec681f3Smrg   0,
173301e04c3fSmrg};
17347ec681f3Smrgstatic const unsigned max_dist_8x = 7;
17357ec681f3Smrgstatic const uint64_t centroid_priority_8x = 0x7654321076543210ull;
173601e04c3fSmrg
17377ec681f3Smrgunsigned
17387ec681f3Smrgradv_get_default_max_sample_dist(int log_samples)
173901e04c3fSmrg{
17407ec681f3Smrg   unsigned max_dist[] = {
17417ec681f3Smrg      max_dist_1x,
17427ec681f3Smrg      max_dist_2x,
17437ec681f3Smrg      max_dist_4x,
17447ec681f3Smrg      max_dist_8x,
17457ec681f3Smrg   };
17467ec681f3Smrg   return max_dist[log_samples];
174701e04c3fSmrg}
174801e04c3fSmrg
17497ec681f3Smrgvoid
17507ec681f3Smrgradv_emit_default_sample_locations(struct radeon_cmdbuf *cs, int nr_samples)
175101e04c3fSmrg{
17527ec681f3Smrg   switch (nr_samples) {
17537ec681f3Smrg   default:
17547ec681f3Smrg   case 1:
17557ec681f3Smrg      radeon_set_context_reg_seq(cs, R_028BD4_PA_SC_CENTROID_PRIORITY_0, 2);
17567ec681f3Smrg      radeon_emit(cs, (uint32_t)centroid_priority_1x);
17577ec681f3Smrg      radeon_emit(cs, centroid_priority_1x >> 32);
17587ec681f3Smrg      radeon_set_context_reg(cs, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, sample_locs_1x);
17597ec681f3Smrg      radeon_set_context_reg(cs, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0, sample_locs_1x);
17607ec681f3Smrg      radeon_set_context_reg(cs, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0, sample_locs_1x);
17617ec681f3Smrg      radeon_set_context_reg(cs, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0, sample_locs_1x);
17627ec681f3Smrg      break;
17637ec681f3Smrg   case 2:
17647ec681f3Smrg      radeon_set_context_reg_seq(cs, R_028BD4_PA_SC_CENTROID_PRIORITY_0, 2);
17657ec681f3Smrg      radeon_emit(cs, (uint32_t)centroid_priority_2x);
17667ec681f3Smrg      radeon_emit(cs, centroid_priority_2x >> 32);
17677ec681f3Smrg      radeon_set_context_reg(cs, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, sample_locs_2x);
17687ec681f3Smrg      radeon_set_context_reg(cs, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0, sample_locs_2x);
17697ec681f3Smrg      radeon_set_context_reg(cs, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0, sample_locs_2x);
17707ec681f3Smrg      radeon_set_context_reg(cs, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0, sample_locs_2x);
17717ec681f3Smrg      break;
17727ec681f3Smrg   case 4:
17737ec681f3Smrg      radeon_set_context_reg_seq(cs, R_028BD4_PA_SC_CENTROID_PRIORITY_0, 2);
17747ec681f3Smrg      radeon_emit(cs, (uint32_t)centroid_priority_4x);
17757ec681f3Smrg      radeon_emit(cs, centroid_priority_4x >> 32);
17767ec681f3Smrg      radeon_set_context_reg(cs, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, sample_locs_4x);
17777ec681f3Smrg      radeon_set_context_reg(cs, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0, sample_locs_4x);
17787ec681f3Smrg      radeon_set_context_reg(cs, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0, sample_locs_4x);
17797ec681f3Smrg      radeon_set_context_reg(cs, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0, sample_locs_4x);
17807ec681f3Smrg      break;
17817ec681f3Smrg   case 8:
17827ec681f3Smrg      radeon_set_context_reg_seq(cs, R_028BD4_PA_SC_CENTROID_PRIORITY_0, 2);
17837ec681f3Smrg      radeon_emit(cs, (uint32_t)centroid_priority_8x);
17847ec681f3Smrg      radeon_emit(cs, centroid_priority_8x >> 32);
17857ec681f3Smrg      radeon_set_context_reg_seq(cs, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, 14);
17867ec681f3Smrg      radeon_emit_array(cs, sample_locs_8x, 4);
17877ec681f3Smrg      radeon_emit_array(cs, sample_locs_8x, 4);
17887ec681f3Smrg      radeon_emit_array(cs, sample_locs_8x, 4);
17897ec681f3Smrg      radeon_emit_array(cs, sample_locs_8x, 2);
17907ec681f3Smrg      break;
17917ec681f3Smrg   }
179201e04c3fSmrg}
179301e04c3fSmrg
17947ec681f3Smrgstatic void
17957ec681f3Smrgradv_get_sample_position(struct radv_device *device, unsigned sample_count, unsigned sample_index,
17967ec681f3Smrg                         float *out_value)
179701e04c3fSmrg{
17987ec681f3Smrg   const uint32_t *sample_locs;
17997ec681f3Smrg
18007ec681f3Smrg   switch (sample_count) {
18017ec681f3Smrg   case 1:
18027ec681f3Smrg   default:
18037ec681f3Smrg      sample_locs = &sample_locs_1x;
18047ec681f3Smrg      break;
18057ec681f3Smrg   case 2:
18067ec681f3Smrg      sample_locs = &sample_locs_2x;
18077ec681f3Smrg      break;
18087ec681f3Smrg   case 4:
18097ec681f3Smrg      sample_locs = &sample_locs_4x;
18107ec681f3Smrg      break;
18117ec681f3Smrg   case 8:
18127ec681f3Smrg      sample_locs = sample_locs_8x;
18137ec681f3Smrg      break;
18147ec681f3Smrg   }
18157ec681f3Smrg
18167ec681f3Smrg   out_value[0] = (GET_SX(sample_locs, sample_index) + 8) / 16.0f;
18177ec681f3Smrg   out_value[1] = (GET_SY(sample_locs, sample_index) + 8) / 16.0f;
181801e04c3fSmrg}
181901e04c3fSmrg
18207ec681f3Smrgvoid
18217ec681f3Smrgradv_device_init_msaa(struct radv_device *device)
182201e04c3fSmrg{
18237ec681f3Smrg   int i;
18247ec681f3Smrg
18257ec681f3Smrg   radv_get_sample_position(device, 1, 0, device->sample_locations_1x[0]);
18267ec681f3Smrg
18277ec681f3Smrg   for (i = 0; i < 2; i++)
18287ec681f3Smrg      radv_get_sample_position(device, 2, i, device->sample_locations_2x[i]);
18297ec681f3Smrg   for (i = 0; i < 4; i++)
18307ec681f3Smrg      radv_get_sample_position(device, 4, i, device->sample_locations_4x[i]);
18317ec681f3Smrg   for (i = 0; i < 8; i++)
18327ec681f3Smrg      radv_get_sample_position(device, 8, i, device->sample_locations_8x[i]);
183301e04c3fSmrg}
1834