Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Advanced Micro Devices, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
| 8 | * license, and/or sell copies of the Software, and to permit persons to whom |
| 9 | * the Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 21 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Christian König <christian.koenig@amd.com> |
| 25 | */ |
| 26 | |
Andreas Hartmetz | 786af2f | 2014-01-04 18:44:33 +0100 | [diff] [blame] | 27 | #include "si_pipe.h" |
| 28 | #include "si_shader.h" |
Emil Velikov | a131263 | 2014-08-16 17:58:25 +0100 | [diff] [blame] | 29 | #include "radeon/r600_cs.h" |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 30 | #include "sid.h" |
| 31 | |
Marek Olšák | 7209703 | 2014-01-22 18:50:36 +0100 | [diff] [blame] | 32 | #include "util/u_index_modify.h" |
Marek Olšák | 7209703 | 2014-01-22 18:50:36 +0100 | [diff] [blame] | 33 | #include "util/u_upload_mgr.h" |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 34 | #include "util/u_prim.h" |
Marek Olšák | 7209703 | 2014-01-22 18:50:36 +0100 | [diff] [blame] | 35 | |
Marek Olšák | 508c1ca | 2014-12-07 16:02:07 +0100 | [diff] [blame] | 36 | static unsigned si_conv_pipe_prim(unsigned mode) |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 37 | { |
| 38 | static const unsigned prim_conv[] = { |
| 39 | [PIPE_PRIM_POINTS] = V_008958_DI_PT_POINTLIST, |
| 40 | [PIPE_PRIM_LINES] = V_008958_DI_PT_LINELIST, |
| 41 | [PIPE_PRIM_LINE_LOOP] = V_008958_DI_PT_LINELOOP, |
| 42 | [PIPE_PRIM_LINE_STRIP] = V_008958_DI_PT_LINESTRIP, |
| 43 | [PIPE_PRIM_TRIANGLES] = V_008958_DI_PT_TRILIST, |
| 44 | [PIPE_PRIM_TRIANGLE_STRIP] = V_008958_DI_PT_TRISTRIP, |
| 45 | [PIPE_PRIM_TRIANGLE_FAN] = V_008958_DI_PT_TRIFAN, |
| 46 | [PIPE_PRIM_QUADS] = V_008958_DI_PT_QUADLIST, |
| 47 | [PIPE_PRIM_QUAD_STRIP] = V_008958_DI_PT_QUADSTRIP, |
| 48 | [PIPE_PRIM_POLYGON] = V_008958_DI_PT_POLYGON, |
Michel Dänzer | 2863071 | 2014-01-09 16:35:46 +0900 | [diff] [blame] | 49 | [PIPE_PRIM_LINES_ADJACENCY] = V_008958_DI_PT_LINELIST_ADJ, |
| 50 | [PIPE_PRIM_LINE_STRIP_ADJACENCY] = V_008958_DI_PT_LINESTRIP_ADJ, |
| 51 | [PIPE_PRIM_TRIANGLES_ADJACENCY] = V_008958_DI_PT_TRILIST_ADJ, |
Marek Olšák | db51ab6 | 2014-08-18 00:55:40 +0200 | [diff] [blame] | 52 | [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY] = V_008958_DI_PT_TRISTRIP_ADJ, |
Marek Olšák | d9d0de4 | 2014-09-18 23:39:44 +0200 | [diff] [blame] | 53 | [PIPE_PRIM_PATCHES] = V_008958_DI_PT_PATCH, |
Marek Olšák | db51ab6 | 2014-08-18 00:55:40 +0200 | [diff] [blame] | 54 | [R600_PRIM_RECTANGLE_LIST] = V_008958_DI_PT_RECTLIST |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 55 | }; |
Marek Olšák | 508c1ca | 2014-12-07 16:02:07 +0100 | [diff] [blame] | 56 | assert(mode < Elements(prim_conv)); |
| 57 | return prim_conv[mode]; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 58 | } |
| 59 | |
Andreas Hartmetz | b902298 | 2014-01-07 03:18:25 +0100 | [diff] [blame] | 60 | static unsigned si_conv_prim_to_gs_out(unsigned mode) |
Marek Olšák | e4c5d3e | 2013-08-18 03:05:34 +0200 | [diff] [blame] | 61 | { |
| 62 | static const int prim_conv[] = { |
| 63 | [PIPE_PRIM_POINTS] = V_028A6C_OUTPRIM_TYPE_POINTLIST, |
| 64 | [PIPE_PRIM_LINES] = V_028A6C_OUTPRIM_TYPE_LINESTRIP, |
| 65 | [PIPE_PRIM_LINE_LOOP] = V_028A6C_OUTPRIM_TYPE_LINESTRIP, |
| 66 | [PIPE_PRIM_LINE_STRIP] = V_028A6C_OUTPRIM_TYPE_LINESTRIP, |
| 67 | [PIPE_PRIM_TRIANGLES] = V_028A6C_OUTPRIM_TYPE_TRISTRIP, |
| 68 | [PIPE_PRIM_TRIANGLE_STRIP] = V_028A6C_OUTPRIM_TYPE_TRISTRIP, |
| 69 | [PIPE_PRIM_TRIANGLE_FAN] = V_028A6C_OUTPRIM_TYPE_TRISTRIP, |
| 70 | [PIPE_PRIM_QUADS] = V_028A6C_OUTPRIM_TYPE_TRISTRIP, |
| 71 | [PIPE_PRIM_QUAD_STRIP] = V_028A6C_OUTPRIM_TYPE_TRISTRIP, |
| 72 | [PIPE_PRIM_POLYGON] = V_028A6C_OUTPRIM_TYPE_TRISTRIP, |
| 73 | [PIPE_PRIM_LINES_ADJACENCY] = V_028A6C_OUTPRIM_TYPE_LINESTRIP, |
| 74 | [PIPE_PRIM_LINE_STRIP_ADJACENCY] = V_028A6C_OUTPRIM_TYPE_LINESTRIP, |
| 75 | [PIPE_PRIM_TRIANGLES_ADJACENCY] = V_028A6C_OUTPRIM_TYPE_TRISTRIP, |
Marek Olšák | db51ab6 | 2014-08-18 00:55:40 +0200 | [diff] [blame] | 76 | [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY] = V_028A6C_OUTPRIM_TYPE_TRISTRIP, |
Marek Olšák | d9d0de4 | 2014-09-18 23:39:44 +0200 | [diff] [blame] | 77 | [PIPE_PRIM_PATCHES] = V_028A6C_OUTPRIM_TYPE_POINTLIST, |
Marek Olšák | db51ab6 | 2014-08-18 00:55:40 +0200 | [diff] [blame] | 78 | [R600_PRIM_RECTANGLE_LIST] = V_028A6C_OUTPRIM_TYPE_TRISTRIP |
Marek Olšák | e4c5d3e | 2013-08-18 03:05:34 +0200 | [diff] [blame] | 79 | }; |
| 80 | assert(mode < Elements(prim_conv)); |
| 81 | |
| 82 | return prim_conv[mode]; |
| 83 | } |
| 84 | |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 85 | /** |
| 86 | * This calculates the LDS size for tessellation shaders (VS, TCS, TES). |
| 87 | * LS.LDS_SIZE is shared by all 3 shader stages. |
| 88 | * |
| 89 | * The information about LDS and other non-compile-time parameters is then |
| 90 | * written to userdata SGPRs. |
| 91 | */ |
| 92 | static void si_emit_derived_tess_state(struct si_context *sctx, |
| 93 | const struct pipe_draw_info *info, |
| 94 | unsigned *num_patches) |
| 95 | { |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 96 | struct radeon_winsys_cs *cs = sctx->b.gfx.cs; |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 97 | struct si_shader_ctx_state *ls = &sctx->vs_shader; |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 98 | /* The TES pointer will only be used for sctx->last_tcs. |
| 99 | * It would be wrong to think that TCS = TES. */ |
| 100 | struct si_shader_selector *tcs = |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 101 | sctx->tcs_shader.cso ? sctx->tcs_shader.cso : sctx->tes_shader.cso; |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 102 | unsigned tes_sh_base = sctx->shader_userdata.sh_base[PIPE_SHADER_TESS_EVAL]; |
| 103 | unsigned num_tcs_input_cp = info->vertices_per_patch; |
| 104 | unsigned num_tcs_output_cp, num_tcs_inputs, num_tcs_outputs; |
| 105 | unsigned num_tcs_patch_outputs; |
| 106 | unsigned input_vertex_size, output_vertex_size, pervertex_output_patch_size; |
| 107 | unsigned input_patch_size, output_patch_size, output_patch0_offset; |
| 108 | unsigned perpatch_output_offset, lds_size, ls_rsrc2; |
| 109 | unsigned tcs_in_layout, tcs_out_layout, tcs_out_offsets; |
| 110 | |
| 111 | *num_patches = 1; /* TODO: calculate this */ |
| 112 | |
| 113 | if (sctx->last_ls == ls->current && |
| 114 | sctx->last_tcs == tcs && |
| 115 | sctx->last_tes_sh_base == tes_sh_base && |
| 116 | sctx->last_num_tcs_input_cp == num_tcs_input_cp) |
| 117 | return; |
| 118 | |
| 119 | sctx->last_ls = ls->current; |
| 120 | sctx->last_tcs = tcs; |
| 121 | sctx->last_tes_sh_base = tes_sh_base; |
| 122 | sctx->last_num_tcs_input_cp = num_tcs_input_cp; |
| 123 | |
| 124 | /* This calculates how shader inputs and outputs among VS, TCS, and TES |
| 125 | * are laid out in LDS. */ |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 126 | num_tcs_inputs = util_last_bit64(ls->cso->outputs_written); |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 127 | |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 128 | if (sctx->tcs_shader.cso) { |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 129 | num_tcs_outputs = util_last_bit64(tcs->outputs_written); |
| 130 | num_tcs_output_cp = tcs->info.properties[TGSI_PROPERTY_TCS_VERTICES_OUT]; |
| 131 | num_tcs_patch_outputs = util_last_bit64(tcs->patch_outputs_written); |
| 132 | } else { |
| 133 | /* No TCS. Route varyings from LS to TES. */ |
| 134 | num_tcs_outputs = num_tcs_inputs; |
| 135 | num_tcs_output_cp = num_tcs_input_cp; |
| 136 | num_tcs_patch_outputs = 2; /* TESSINNER + TESSOUTER */ |
| 137 | } |
| 138 | |
| 139 | input_vertex_size = num_tcs_inputs * 16; |
| 140 | output_vertex_size = num_tcs_outputs * 16; |
| 141 | |
| 142 | input_patch_size = num_tcs_input_cp * input_vertex_size; |
| 143 | |
| 144 | pervertex_output_patch_size = num_tcs_output_cp * output_vertex_size; |
| 145 | output_patch_size = pervertex_output_patch_size + num_tcs_patch_outputs * 16; |
| 146 | |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 147 | output_patch0_offset = sctx->tcs_shader.cso ? input_patch_size * *num_patches : 0; |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 148 | perpatch_output_offset = output_patch0_offset + pervertex_output_patch_size; |
| 149 | |
| 150 | lds_size = output_patch0_offset + output_patch_size * *num_patches; |
Marek Olšák | 20b9b5d | 2015-12-28 00:14:05 +0100 | [diff] [blame] | 151 | ls_rsrc2 = ls->current->config.rsrc2; |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 152 | |
| 153 | if (sctx->b.chip_class >= CIK) { |
| 154 | assert(lds_size <= 65536); |
| 155 | ls_rsrc2 |= S_00B52C_LDS_SIZE(align(lds_size, 512) / 512); |
| 156 | } else { |
| 157 | assert(lds_size <= 32768); |
| 158 | ls_rsrc2 |= S_00B52C_LDS_SIZE(align(lds_size, 256) / 256); |
| 159 | } |
| 160 | |
| 161 | /* Due to a hw bug, RSRC2_LS must be written twice with another |
| 162 | * LS register written in between. */ |
| 163 | if (sctx->b.chip_class == CIK && sctx->b.family != CHIP_HAWAII) |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 164 | radeon_set_sh_reg(cs, R_00B52C_SPI_SHADER_PGM_RSRC2_LS, ls_rsrc2); |
| 165 | radeon_set_sh_reg_seq(cs, R_00B528_SPI_SHADER_PGM_RSRC1_LS, 2); |
Marek Olšák | 20b9b5d | 2015-12-28 00:14:05 +0100 | [diff] [blame] | 166 | radeon_emit(cs, ls->current->config.rsrc1); |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 167 | radeon_emit(cs, ls_rsrc2); |
| 168 | |
| 169 | /* Compute userdata SGPRs. */ |
| 170 | assert(((input_vertex_size / 4) & ~0xff) == 0); |
| 171 | assert(((output_vertex_size / 4) & ~0xff) == 0); |
| 172 | assert(((input_patch_size / 4) & ~0x1fff) == 0); |
| 173 | assert(((output_patch_size / 4) & ~0x1fff) == 0); |
| 174 | assert(((output_patch0_offset / 16) & ~0xffff) == 0); |
| 175 | assert(((perpatch_output_offset / 16) & ~0xffff) == 0); |
| 176 | assert(num_tcs_input_cp <= 32); |
| 177 | assert(num_tcs_output_cp <= 32); |
| 178 | |
| 179 | tcs_in_layout = (input_patch_size / 4) | |
| 180 | ((input_vertex_size / 4) << 13); |
| 181 | tcs_out_layout = (output_patch_size / 4) | |
| 182 | ((output_vertex_size / 4) << 13); |
| 183 | tcs_out_offsets = (output_patch0_offset / 16) | |
| 184 | ((perpatch_output_offset / 16) << 16); |
| 185 | |
| 186 | /* Set them for LS. */ |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 187 | radeon_set_sh_reg(cs, |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 188 | R_00B530_SPI_SHADER_USER_DATA_LS_0 + SI_SGPR_LS_OUT_LAYOUT * 4, |
| 189 | tcs_in_layout); |
| 190 | |
| 191 | /* Set them for TCS. */ |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 192 | radeon_set_sh_reg_seq(cs, |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 193 | R_00B430_SPI_SHADER_USER_DATA_HS_0 + SI_SGPR_TCS_OUT_OFFSETS * 4, 3); |
| 194 | radeon_emit(cs, tcs_out_offsets); |
| 195 | radeon_emit(cs, tcs_out_layout | (num_tcs_input_cp << 26)); |
| 196 | radeon_emit(cs, tcs_in_layout); |
| 197 | |
| 198 | /* Set them for TES. */ |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 199 | radeon_set_sh_reg_seq(cs, tes_sh_base + SI_SGPR_TCS_OUT_OFFSETS * 4, 2); |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 200 | radeon_emit(cs, tcs_out_offsets); |
| 201 | radeon_emit(cs, tcs_out_layout | (num_tcs_output_cp << 26)); |
| 202 | } |
| 203 | |
Marek Olšák | 0f9519b | 2015-12-09 22:14:32 +0100 | [diff] [blame] | 204 | static unsigned si_num_prims_for_vertices(const struct pipe_draw_info *info) |
| 205 | { |
| 206 | switch (info->mode) { |
| 207 | case PIPE_PRIM_PATCHES: |
| 208 | return info->count / info->vertices_per_patch; |
| 209 | case R600_PRIM_RECTANGLE_LIST: |
| 210 | return info->count / 3; |
| 211 | default: |
| 212 | return u_prims_for_vertices(info->mode, info->count); |
| 213 | } |
| 214 | } |
| 215 | |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 216 | static unsigned si_get_ia_multi_vgt_param(struct si_context *sctx, |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 217 | const struct pipe_draw_info *info, |
| 218 | unsigned num_patches) |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 219 | { |
| 220 | struct si_state_rasterizer *rs = sctx->queued.named.rasterizer; |
| 221 | unsigned prim = info->mode; |
Marek Olšák | f62f882 | 2014-08-18 23:14:34 +0200 | [diff] [blame] | 222 | unsigned primgroup_size = 128; /* recommended without a GS */ |
Marek Olšák | 2070af2 | 2015-10-18 22:07:01 +0200 | [diff] [blame] | 223 | unsigned max_primgroup_in_wave = 2; |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 224 | |
| 225 | /* SWITCH_ON_EOP(0) is always preferable. */ |
| 226 | bool wd_switch_on_eop = false; |
| 227 | bool ia_switch_on_eop = false; |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 228 | bool ia_switch_on_eoi = false; |
Marek Olšák | 4be7ff5 | 2014-08-15 22:45:10 +0200 | [diff] [blame] | 229 | bool partial_vs_wave = false; |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 230 | bool partial_es_wave = false; |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 231 | |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 232 | if (sctx->gs_shader.cso) |
Marek Olšák | f62f882 | 2014-08-18 23:14:34 +0200 | [diff] [blame] | 233 | primgroup_size = 64; /* recommended with a GS */ |
| 234 | |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 235 | if (sctx->tes_shader.cso) { |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 236 | unsigned num_cp_out = |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 237 | sctx->tcs_shader.cso ? |
| 238 | sctx->tcs_shader.cso->info.properties[TGSI_PROPERTY_TCS_VERTICES_OUT] : |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 239 | info->vertices_per_patch; |
| 240 | unsigned max_size = 256 / MAX2(info->vertices_per_patch, num_cp_out); |
| 241 | |
| 242 | primgroup_size = MIN2(primgroup_size, max_size); |
| 243 | |
| 244 | /* primgroup_size must be set to a multiple of NUM_PATCHES */ |
| 245 | primgroup_size = (primgroup_size / num_patches) * num_patches; |
| 246 | |
Marek Olšák | ca18f12 | 2015-10-18 22:17:04 +0200 | [diff] [blame] | 247 | /* SWITCH_ON_EOI must be set if PrimID is used. */ |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 248 | if ((sctx->tcs_shader.cso && sctx->tcs_shader.cso->info.uses_primid) || |
Marek Olšák | ca18f12 | 2015-10-18 22:17:04 +0200 | [diff] [blame] | 249 | sctx->tes_shader.cso->info.uses_primid) |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 250 | ia_switch_on_eoi = true; |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 251 | |
| 252 | /* Bug with tessellation and GS on Bonaire and older 2 SE chips. */ |
| 253 | if ((sctx->b.family == CHIP_TAHITI || |
| 254 | sctx->b.family == CHIP_PITCAIRN || |
| 255 | sctx->b.family == CHIP_BONAIRE) && |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 256 | sctx->gs_shader.cso) |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 257 | partial_vs_wave = true; |
| 258 | } |
| 259 | |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 260 | /* This is a hardware requirement. */ |
| 261 | if ((rs && rs->line_stipple_enable) || |
| 262 | (sctx->b.screen->debug_flags & DBG_SWITCH_ON_EOP)) { |
| 263 | ia_switch_on_eop = true; |
| 264 | wd_switch_on_eop = true; |
| 265 | } |
| 266 | |
| 267 | if (sctx->b.chip_class >= CIK) { |
| 268 | /* WD_SWITCH_ON_EOP has no effect on GPUs with less than |
| 269 | * 4 shader engines. Set 1 to pass the assertion below. |
| 270 | * The other cases are hardware requirements. */ |
| 271 | if (sctx->b.screen->info.max_se < 4 || |
| 272 | prim == PIPE_PRIM_POLYGON || |
| 273 | prim == PIPE_PRIM_LINE_LOOP || |
| 274 | prim == PIPE_PRIM_TRIANGLE_FAN || |
| 275 | prim == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY || |
Marek Olšák | 0d2cb35 | 2015-10-18 22:22:22 +0200 | [diff] [blame] | 276 | info->primitive_restart || |
| 277 | info->count_from_stream_output) |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 278 | wd_switch_on_eop = true; |
| 279 | |
| 280 | /* Hawaii hangs if instancing is enabled and WD_SWITCH_ON_EOP is 0. |
| 281 | * We don't know that for indirect drawing, so treat it as |
| 282 | * always problematic. */ |
| 283 | if (sctx->b.family == CHIP_HAWAII && |
| 284 | (info->indirect || info->instance_count > 1)) |
| 285 | wd_switch_on_eop = true; |
| 286 | |
Marek Olšák | 96d5879 | 2015-10-18 21:43:30 +0200 | [diff] [blame] | 287 | /* Required on CIK and later. */ |
| 288 | if (sctx->b.screen->info.max_se > 2 && !wd_switch_on_eop) |
| 289 | ia_switch_on_eoi = true; |
| 290 | |
Marek Olšák | 2070af2 | 2015-10-18 22:07:01 +0200 | [diff] [blame] | 291 | /* Required by Hawaii and, for some special cases, by VI. */ |
| 292 | if (ia_switch_on_eoi && |
| 293 | (sctx->b.family == CHIP_HAWAII || |
| 294 | (sctx->b.chip_class == VI && |
| 295 | (sctx->gs_shader.cso || max_primgroup_in_wave != 2)))) |
| 296 | partial_vs_wave = true; |
| 297 | |
Marek Olšák | a6b5684 | 2015-10-18 21:51:41 +0200 | [diff] [blame] | 298 | /* Instancing bug on Bonaire. */ |
| 299 | if (sctx->b.family == CHIP_BONAIRE && ia_switch_on_eoi && |
| 300 | (info->indirect || info->instance_count > 1)) |
| 301 | partial_vs_wave = true; |
| 302 | |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 303 | /* If the WD switch is false, the IA switch must be false too. */ |
| 304 | assert(wd_switch_on_eop || !ia_switch_on_eop); |
| 305 | } |
| 306 | |
Marek Olšák | ca18f12 | 2015-10-18 22:17:04 +0200 | [diff] [blame] | 307 | /* If SWITCH_ON_EOI is set, PARTIAL_ES_WAVE must be set too. */ |
| 308 | if (ia_switch_on_eoi) |
| 309 | partial_es_wave = true; |
| 310 | |
Marek Olšák | 0608304 | 2015-10-19 02:45:56 +0200 | [diff] [blame] | 311 | /* GS requirement. */ |
| 312 | if (SI_GS_PER_ES / primgroup_size >= sctx->screen->gs_table_depth - 3) |
| 313 | partial_es_wave = true; |
| 314 | |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 315 | /* Hw bug with single-primitive instances and SWITCH_ON_EOI |
| 316 | * on multi-SE chips. */ |
| 317 | if (sctx->b.screen->info.max_se >= 2 && ia_switch_on_eoi && |
| 318 | (info->indirect || |
| 319 | (info->instance_count > 1 && |
Marek Olšák | 0f9519b | 2015-12-09 22:14:32 +0100 | [diff] [blame] | 320 | si_num_prims_for_vertices(info) <= 1))) |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 321 | sctx->b.flags |= SI_CONTEXT_VGT_FLUSH; |
| 322 | |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 323 | return S_028AA8_SWITCH_ON_EOP(ia_switch_on_eop) | |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 324 | S_028AA8_SWITCH_ON_EOI(ia_switch_on_eoi) | |
Marek Olšák | 4be7ff5 | 2014-08-15 22:45:10 +0200 | [diff] [blame] | 325 | S_028AA8_PARTIAL_VS_WAVE_ON(partial_vs_wave) | |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 326 | S_028AA8_PARTIAL_ES_WAVE_ON(partial_es_wave) | |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 327 | S_028AA8_PRIMGROUP_SIZE(primgroup_size - 1) | |
Marek Olšák | 2d1952e | 2015-04-16 20:44:54 +0200 | [diff] [blame] | 328 | S_028AA8_WD_SWITCH_ON_EOP(sctx->b.chip_class >= CIK ? wd_switch_on_eop : 0) | |
Marek Olšák | 2070af2 | 2015-10-18 22:07:01 +0200 | [diff] [blame] | 329 | S_028AA8_MAX_PRIMGRP_IN_WAVE(sctx->b.chip_class >= VI ? |
| 330 | max_primgroup_in_wave : 0); |
Marek Olšák | 94e474f | 2014-08-15 16:32:03 +0200 | [diff] [blame] | 331 | } |
| 332 | |
Marek Olšák | 3344699 | 2015-02-22 18:07:51 +0100 | [diff] [blame] | 333 | static unsigned si_get_ls_hs_config(struct si_context *sctx, |
| 334 | const struct pipe_draw_info *info, |
| 335 | unsigned num_patches) |
| 336 | { |
| 337 | unsigned num_output_cp; |
| 338 | |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 339 | if (!sctx->tes_shader.cso) |
Marek Olšák | 3344699 | 2015-02-22 18:07:51 +0100 | [diff] [blame] | 340 | return 0; |
| 341 | |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 342 | num_output_cp = sctx->tcs_shader.cso ? |
| 343 | sctx->tcs_shader.cso->info.properties[TGSI_PROPERTY_TCS_VERTICES_OUT] : |
Marek Olšák | 3344699 | 2015-02-22 18:07:51 +0100 | [diff] [blame] | 344 | info->vertices_per_patch; |
| 345 | |
| 346 | return S_028B58_NUM_PATCHES(num_patches) | |
| 347 | S_028B58_HS_NUM_INPUT_CP(info->vertices_per_patch) | |
| 348 | S_028B58_HS_NUM_OUTPUT_CP(num_output_cp); |
| 349 | } |
| 350 | |
Marek Olšák | dc39413 | 2015-03-15 20:13:52 +0100 | [diff] [blame] | 351 | static void si_emit_scratch_reloc(struct si_context *sctx) |
| 352 | { |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 353 | struct radeon_winsys_cs *cs = sctx->b.gfx.cs; |
Marek Olšák | dc39413 | 2015-03-15 20:13:52 +0100 | [diff] [blame] | 354 | |
| 355 | if (!sctx->emit_scratch_reloc) |
| 356 | return; |
| 357 | |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 358 | radeon_set_context_reg(cs, R_0286E8_SPI_TMPRING_SIZE, |
Marek Olšák | dc39413 | 2015-03-15 20:13:52 +0100 | [diff] [blame] | 359 | sctx->spi_tmpring_size); |
| 360 | |
| 361 | if (sctx->scratch_buffer) { |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 362 | radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx, |
Marek Olšák | dc39413 | 2015-03-15 20:13:52 +0100 | [diff] [blame] | 363 | sctx->scratch_buffer, RADEON_USAGE_READWRITE, |
Marek Olšák | 2edb060 | 2015-09-26 23:18:55 +0200 | [diff] [blame] | 364 | RADEON_PRIO_SCRATCH_BUFFER); |
Marek Olšák | dc39413 | 2015-03-15 20:13:52 +0100 | [diff] [blame] | 365 | |
| 366 | } |
| 367 | sctx->emit_scratch_reloc = false; |
| 368 | } |
| 369 | |
Marek Olšák | 1fe7ba8 | 2015-01-31 20:09:46 +0100 | [diff] [blame] | 370 | /* rast_prim is the primitive type after GS. */ |
Marek Olšák | fdf2c04 | 2015-02-22 17:42:20 +0100 | [diff] [blame] | 371 | static void si_emit_rasterizer_prim_state(struct si_context *sctx) |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 372 | { |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 373 | struct radeon_winsys_cs *cs = sctx->b.gfx.cs; |
Marek Olšák | fdf2c04 | 2015-02-22 17:42:20 +0100 | [diff] [blame] | 374 | unsigned rast_prim = sctx->current_rast_prim; |
Marek Olšák | 1f4bb38 | 2015-03-15 19:21:31 +0100 | [diff] [blame] | 375 | struct si_state_rasterizer *rs = sctx->emitted.named.rasterizer; |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 376 | |
Marek Olšák | 567c8d7 | 2015-03-15 19:24:13 +0100 | [diff] [blame] | 377 | /* Skip this if not rendering lines. */ |
| 378 | if (rast_prim != PIPE_PRIM_LINES && |
| 379 | rast_prim != PIPE_PRIM_LINE_LOOP && |
| 380 | rast_prim != PIPE_PRIM_LINE_STRIP && |
| 381 | rast_prim != PIPE_PRIM_LINES_ADJACENCY && |
| 382 | rast_prim != PIPE_PRIM_LINE_STRIP_ADJACENCY) |
| 383 | return; |
| 384 | |
Marek Olšák | 1f4bb38 | 2015-03-15 19:21:31 +0100 | [diff] [blame] | 385 | if (rast_prim == sctx->last_rast_prim && |
| 386 | rs->pa_sc_line_stipple == sctx->last_sc_line_stipple) |
Marek Olšák | 3291eed | 2014-12-08 13:35:36 +0100 | [diff] [blame] | 387 | return; |
| 388 | |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 389 | radeon_set_context_reg(cs, R_028A0C_PA_SC_LINE_STIPPLE, |
Marek Olšák | 1f4bb38 | 2015-03-15 19:21:31 +0100 | [diff] [blame] | 390 | rs->pa_sc_line_stipple | |
Marek Olšák | 1fe7ba8 | 2015-01-31 20:09:46 +0100 | [diff] [blame] | 391 | S_028A0C_AUTO_RESET_CNTL(rast_prim == PIPE_PRIM_LINES ? 1 : |
| 392 | rast_prim == PIPE_PRIM_LINE_STRIP ? 2 : 0)); |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 393 | |
Marek Olšák | 1fe7ba8 | 2015-01-31 20:09:46 +0100 | [diff] [blame] | 394 | sctx->last_rast_prim = rast_prim; |
Marek Olšák | 1f4bb38 | 2015-03-15 19:21:31 +0100 | [diff] [blame] | 395 | sctx->last_sc_line_stipple = rs->pa_sc_line_stipple; |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | static void si_emit_draw_registers(struct si_context *sctx, |
Marek Olšák | fdf2c04 | 2015-02-22 17:42:20 +0100 | [diff] [blame] | 399 | const struct pipe_draw_info *info) |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 400 | { |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 401 | struct radeon_winsys_cs *cs = sctx->b.gfx.cs; |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 402 | unsigned prim = si_conv_pipe_prim(info->mode); |
Marek Olšák | fdf2c04 | 2015-02-22 17:42:20 +0100 | [diff] [blame] | 403 | unsigned gs_out_prim = si_conv_prim_to_gs_out(sctx->current_rast_prim); |
Marek Olšák | 3344699 | 2015-02-22 18:07:51 +0100 | [diff] [blame] | 404 | unsigned ia_multi_vgt_param, ls_hs_config, num_patches = 0; |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 405 | |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 406 | if (sctx->tes_shader.cso) |
Marek Olšák | 74c1001 | 2015-02-22 18:01:18 +0100 | [diff] [blame] | 407 | si_emit_derived_tess_state(sctx, info, &num_patches); |
| 408 | |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 409 | ia_multi_vgt_param = si_get_ia_multi_vgt_param(sctx, info, num_patches); |
Marek Olšák | 3344699 | 2015-02-22 18:07:51 +0100 | [diff] [blame] | 410 | ls_hs_config = si_get_ls_hs_config(sctx, info, num_patches); |
Marek Olšák | 09d02fa | 2015-02-22 18:06:34 +0100 | [diff] [blame] | 411 | |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 412 | /* Draw state. */ |
Marek Olšák | 834bee4 | 2014-12-07 20:23:56 +0100 | [diff] [blame] | 413 | if (prim != sctx->last_prim || |
Marek Olšák | 3344699 | 2015-02-22 18:07:51 +0100 | [diff] [blame] | 414 | ia_multi_vgt_param != sctx->last_multi_vgt_param || |
| 415 | ls_hs_config != sctx->last_ls_hs_config) { |
Marek Olšák | 834bee4 | 2014-12-07 20:23:56 +0100 | [diff] [blame] | 416 | if (sctx->b.chip_class >= CIK) { |
| 417 | radeon_emit(cs, PKT3(PKT3_DRAW_PREAMBLE, 2, 0)); |
| 418 | radeon_emit(cs, prim); /* VGT_PRIMITIVE_TYPE */ |
| 419 | radeon_emit(cs, ia_multi_vgt_param); /* IA_MULTI_VGT_PARAM */ |
Marek Olšák | 3344699 | 2015-02-22 18:07:51 +0100 | [diff] [blame] | 420 | radeon_emit(cs, ls_hs_config); /* VGT_LS_HS_CONFIG */ |
Marek Olšák | 834bee4 | 2014-12-07 20:23:56 +0100 | [diff] [blame] | 421 | } else { |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 422 | radeon_set_config_reg(cs, R_008958_VGT_PRIMITIVE_TYPE, prim); |
| 423 | radeon_set_context_reg(cs, R_028AA8_IA_MULTI_VGT_PARAM, ia_multi_vgt_param); |
| 424 | radeon_set_context_reg(cs, R_028B58_VGT_LS_HS_CONFIG, ls_hs_config); |
Marek Olšák | 834bee4 | 2014-12-07 20:23:56 +0100 | [diff] [blame] | 425 | } |
| 426 | sctx->last_prim = prim; |
| 427 | sctx->last_multi_vgt_param = ia_multi_vgt_param; |
Marek Olšák | 3344699 | 2015-02-22 18:07:51 +0100 | [diff] [blame] | 428 | sctx->last_ls_hs_config = ls_hs_config; |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 429 | } |
| 430 | |
Marek Olšák | 6fde194 | 2014-12-07 20:15:49 +0100 | [diff] [blame] | 431 | if (gs_out_prim != sctx->last_gs_out_prim) { |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 432 | radeon_set_context_reg(cs, R_028A6C_VGT_GS_OUT_PRIM_TYPE, gs_out_prim); |
Marek Olšák | 6fde194 | 2014-12-07 20:15:49 +0100 | [diff] [blame] | 433 | sctx->last_gs_out_prim = gs_out_prim; |
| 434 | } |
Marek Olšák | 3435013 | 2014-12-07 20:14:41 +0100 | [diff] [blame] | 435 | |
| 436 | /* Primitive restart. */ |
| 437 | if (info->primitive_restart != sctx->last_primitive_restart_en) { |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 438 | radeon_set_context_reg(cs, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN, info->primitive_restart); |
Marek Olšák | 3435013 | 2014-12-07 20:14:41 +0100 | [diff] [blame] | 439 | sctx->last_primitive_restart_en = info->primitive_restart; |
| 440 | |
| 441 | if (info->primitive_restart && |
| 442 | (info->restart_index != sctx->last_restart_index || |
| 443 | sctx->last_restart_index == SI_RESTART_INDEX_UNKNOWN)) { |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 444 | radeon_set_context_reg(cs, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX, |
Marek Olšák | 3435013 | 2014-12-07 20:14:41 +0100 | [diff] [blame] | 445 | info->restart_index); |
| 446 | sctx->last_restart_index = info->restart_index; |
| 447 | } |
| 448 | } |
Marek Olšák | ca7f1cf | 2014-12-07 16:40:09 +0100 | [diff] [blame] | 449 | } |
| 450 | |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 451 | static void si_emit_draw_packets(struct si_context *sctx, |
| 452 | const struct pipe_draw_info *info, |
| 453 | const struct pipe_index_buffer *ib) |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 454 | { |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 455 | struct radeon_winsys_cs *cs = sctx->b.gfx.cs; |
Marek Olšák | 3ce91c7 | 2014-09-15 23:34:28 +0200 | [diff] [blame] | 456 | unsigned sh_base_reg = sctx->shader_userdata.sh_base[PIPE_SHADER_VERTEX]; |
Marek Olšák | eb0d3e8 | 2015-11-07 16:30:01 +0100 | [diff] [blame] | 457 | bool render_cond_bit = sctx->b.render_cond && !sctx->b.render_cond_force_off; |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 458 | |
Marek Olšák | 9d16e70 | 2013-08-26 18:17:09 +0200 | [diff] [blame] | 459 | if (info->count_from_stream_output) { |
| 460 | struct r600_so_target *t = |
| 461 | (struct r600_so_target*)info->count_from_stream_output; |
Marek Olšák | 1c03a69 | 2014-08-06 22:29:27 +0200 | [diff] [blame] | 462 | uint64_t va = t->buf_filled_size->gpu_address + |
| 463 | t->buf_filled_size_offset; |
Marek Olšák | 9d16e70 | 2013-08-26 18:17:09 +0200 | [diff] [blame] | 464 | |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 465 | radeon_set_context_reg(cs, R_028B30_VGT_STRMOUT_DRAW_OPAQUE_VERTEX_STRIDE, |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 466 | t->stride_in_dw); |
Marek Olšák | 9d16e70 | 2013-08-26 18:17:09 +0200 | [diff] [blame] | 467 | |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 468 | radeon_emit(cs, PKT3(PKT3_COPY_DATA, 4, 0)); |
| 469 | radeon_emit(cs, COPY_DATA_SRC_SEL(COPY_DATA_MEM) | |
| 470 | COPY_DATA_DST_SEL(COPY_DATA_REG) | |
| 471 | COPY_DATA_WR_CONFIRM); |
| 472 | radeon_emit(cs, va); /* src address lo */ |
| 473 | radeon_emit(cs, va >> 32); /* src address hi */ |
| 474 | radeon_emit(cs, R_028B2C_VGT_STRMOUT_DRAW_OPAQUE_BUFFER_FILLED_SIZE >> 2); |
| 475 | radeon_emit(cs, 0); /* unused */ |
| 476 | |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 477 | radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx, |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 478 | t->buf_filled_size, RADEON_USAGE_READ, |
Marek Olšák | 2edb060 | 2015-09-26 23:18:55 +0200 | [diff] [blame] | 479 | RADEON_PRIO_SO_FILLED_SIZE); |
Marek Olšák | 9d16e70 | 2013-08-26 18:17:09 +0200 | [diff] [blame] | 480 | } |
| 481 | |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 482 | /* draw packet */ |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 483 | if (info->indexed) { |
| 484 | radeon_emit(cs, PKT3(PKT3_INDEX_TYPE, 0, 0)); |
| 485 | |
Marek Olšák | 2d1952e | 2015-04-16 20:44:54 +0200 | [diff] [blame] | 486 | /* index type */ |
| 487 | switch (ib->index_size) { |
| 488 | case 1: |
| 489 | radeon_emit(cs, V_028A7C_VGT_INDEX_8); |
| 490 | break; |
| 491 | case 2: |
| 492 | radeon_emit(cs, V_028A7C_VGT_INDEX_16 | |
| 493 | (SI_BIG_ENDIAN && sctx->b.chip_class <= CIK ? |
| 494 | V_028A7C_VGT_DMA_SWAP_16_BIT : 0)); |
| 495 | break; |
| 496 | case 4: |
| 497 | radeon_emit(cs, V_028A7C_VGT_INDEX_32 | |
| 498 | (SI_BIG_ENDIAN && sctx->b.chip_class <= CIK ? |
| 499 | V_028A7C_VGT_DMA_SWAP_32_BIT : 0)); |
| 500 | break; |
| 501 | default: |
| 502 | assert(!"unreachable"); |
| 503 | return; |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 504 | } |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 505 | } |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 506 | |
Marek Olšák | 09056b3 | 2014-04-23 16:15:36 +0200 | [diff] [blame] | 507 | if (!info->indirect) { |
Marek Olšák | 3382036 | 2014-12-07 20:04:40 +0100 | [diff] [blame] | 508 | int base_vertex; |
| 509 | |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 510 | radeon_emit(cs, PKT3(PKT3_NUM_INSTANCES, 0, 0)); |
| 511 | radeon_emit(cs, info->instance_count); |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 512 | |
Marek Olšák | 3382036 | 2014-12-07 20:04:40 +0100 | [diff] [blame] | 513 | /* Base vertex and start instance. */ |
| 514 | base_vertex = info->indexed ? info->index_bias : info->start; |
| 515 | |
| 516 | if (base_vertex != sctx->last_base_vertex || |
| 517 | sctx->last_base_vertex == SI_BASE_VERTEX_UNKNOWN || |
| 518 | info->start_instance != sctx->last_start_instance || |
| 519 | sh_base_reg != sctx->last_sh_base_reg) { |
Marek Olšák | d2e63ac | 2015-08-30 01:54:00 +0200 | [diff] [blame] | 520 | radeon_set_sh_reg_seq(cs, sh_base_reg + SI_SGPR_BASE_VERTEX * 4, 2); |
Marek Olšák | 3382036 | 2014-12-07 20:04:40 +0100 | [diff] [blame] | 521 | radeon_emit(cs, base_vertex); |
| 522 | radeon_emit(cs, info->start_instance); |
| 523 | |
| 524 | sctx->last_base_vertex = base_vertex; |
| 525 | sctx->last_start_instance = info->start_instance; |
| 526 | sctx->last_sh_base_reg = sh_base_reg; |
| 527 | } |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 528 | } else { |
Marek Olšák | 3382036 | 2014-12-07 20:04:40 +0100 | [diff] [blame] | 529 | si_invalidate_draw_sh_constants(sctx); |
| 530 | |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 531 | radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx, |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 532 | (struct r600_resource *)info->indirect, |
Marek Olšák | 2edb060 | 2015-09-26 23:18:55 +0200 | [diff] [blame] | 533 | RADEON_USAGE_READ, RADEON_PRIO_DRAW_INDIRECT); |
Marek Olšák | 09056b3 | 2014-04-23 16:15:36 +0200 | [diff] [blame] | 534 | } |
| 535 | |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 536 | if (info->indexed) { |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 537 | uint32_t index_max_size = (ib->buffer->width0 - ib->offset) / |
| 538 | ib->index_size; |
| 539 | uint64_t index_va = r600_resource(ib->buffer)->gpu_address + ib->offset; |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 540 | |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 541 | radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx, |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 542 | (struct r600_resource *)ib->buffer, |
Marek Olšák | 2edb060 | 2015-09-26 23:18:55 +0200 | [diff] [blame] | 543 | RADEON_USAGE_READ, RADEON_PRIO_INDEX_BUFFER); |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 544 | |
| 545 | if (info->indirect) { |
Marek Olšák | 1c03a69 | 2014-08-06 22:29:27 +0200 | [diff] [blame] | 546 | uint64_t indirect_va = r600_resource(info->indirect)->gpu_address; |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 547 | |
| 548 | assert(indirect_va % 8 == 0); |
| 549 | assert(index_va % 2 == 0); |
| 550 | assert(info->indirect_offset % 4 == 0); |
| 551 | |
| 552 | radeon_emit(cs, PKT3(PKT3_SET_BASE, 2, 0)); |
| 553 | radeon_emit(cs, 1); |
| 554 | radeon_emit(cs, indirect_va); |
| 555 | radeon_emit(cs, indirect_va >> 32); |
| 556 | |
| 557 | radeon_emit(cs, PKT3(PKT3_INDEX_BASE, 1, 0)); |
| 558 | radeon_emit(cs, index_va); |
| 559 | radeon_emit(cs, index_va >> 32); |
| 560 | |
| 561 | radeon_emit(cs, PKT3(PKT3_INDEX_BUFFER_SIZE, 0, 0)); |
| 562 | radeon_emit(cs, index_max_size); |
| 563 | |
Marek Olšák | 6eff541 | 2015-11-07 14:45:58 +0100 | [diff] [blame] | 564 | radeon_emit(cs, PKT3(PKT3_DRAW_INDEX_INDIRECT, 3, render_cond_bit)); |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 565 | radeon_emit(cs, info->indirect_offset); |
| 566 | radeon_emit(cs, (sh_base_reg + SI_SGPR_BASE_VERTEX * 4 - SI_SH_REG_OFFSET) >> 2); |
| 567 | radeon_emit(cs, (sh_base_reg + SI_SGPR_START_INSTANCE * 4 - SI_SH_REG_OFFSET) >> 2); |
| 568 | radeon_emit(cs, V_0287F0_DI_SRC_SEL_DMA); |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 569 | } else { |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 570 | index_va += info->start * ib->index_size; |
| 571 | |
Marek Olšák | 6eff541 | 2015-11-07 14:45:58 +0100 | [diff] [blame] | 572 | radeon_emit(cs, PKT3(PKT3_DRAW_INDEX_2, 4, render_cond_bit)); |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 573 | radeon_emit(cs, index_max_size); |
| 574 | radeon_emit(cs, index_va); |
| 575 | radeon_emit(cs, (index_va >> 32UL) & 0xFF); |
| 576 | radeon_emit(cs, info->count); |
| 577 | radeon_emit(cs, V_0287F0_DI_SRC_SEL_DMA); |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 578 | } |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 579 | } else { |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 580 | if (info->indirect) { |
Marek Olšák | 1c03a69 | 2014-08-06 22:29:27 +0200 | [diff] [blame] | 581 | uint64_t indirect_va = r600_resource(info->indirect)->gpu_address; |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 582 | |
| 583 | assert(indirect_va % 8 == 0); |
| 584 | assert(info->indirect_offset % 4 == 0); |
| 585 | |
| 586 | radeon_emit(cs, PKT3(PKT3_SET_BASE, 2, 0)); |
| 587 | radeon_emit(cs, 1); |
| 588 | radeon_emit(cs, indirect_va); |
| 589 | radeon_emit(cs, indirect_va >> 32); |
| 590 | |
Marek Olšák | 6eff541 | 2015-11-07 14:45:58 +0100 | [diff] [blame] | 591 | radeon_emit(cs, PKT3(PKT3_DRAW_INDIRECT, 3, render_cond_bit)); |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 592 | radeon_emit(cs, info->indirect_offset); |
| 593 | radeon_emit(cs, (sh_base_reg + SI_SGPR_BASE_VERTEX * 4 - SI_SH_REG_OFFSET) >> 2); |
| 594 | radeon_emit(cs, (sh_base_reg + SI_SGPR_START_INSTANCE * 4 - SI_SH_REG_OFFSET) >> 2); |
| 595 | radeon_emit(cs, V_0287F0_DI_SRC_SEL_AUTO_INDEX); |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 596 | } else { |
Marek Olšák | 6eff541 | 2015-11-07 14:45:58 +0100 | [diff] [blame] | 597 | radeon_emit(cs, PKT3(PKT3_DRAW_INDEX_AUTO, 1, render_cond_bit)); |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 598 | radeon_emit(cs, info->count); |
| 599 | radeon_emit(cs, V_0287F0_DI_SRC_SEL_AUTO_INDEX | |
| 600 | S_0287F0_USE_OPAQUE(!!info->count_from_stream_output)); |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 601 | } |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 602 | } |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 603 | } |
| 604 | |
Marek Olšák | 5bb0ad7 | 2015-08-28 23:52:47 +0200 | [diff] [blame] | 605 | void si_emit_cache_flush(struct si_context *si_ctx, struct r600_atom *atom) |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 606 | { |
Marek Olšák | 5bb0ad7 | 2015-08-28 23:52:47 +0200 | [diff] [blame] | 607 | struct r600_common_context *sctx = &si_ctx->b; |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 608 | struct radeon_winsys_cs *cs = sctx->gfx.cs; |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 609 | uint32_t cp_coher_cntl = 0; |
Marek Olšák | 604b58b | 2014-09-20 11:48:58 +0200 | [diff] [blame] | 610 | uint32_t compute = |
Marek Olšák | 2bfe9d4 | 2014-12-29 14:02:46 +0100 | [diff] [blame] | 611 | PKT3_SHADER_TYPE_S(!!(sctx->flags & SI_CONTEXT_FLAG_COMPUTE)); |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 612 | |
Marek Olšák | 73c2b0d | 2014-12-28 23:11:38 +0100 | [diff] [blame] | 613 | /* SI has a bug that it always flushes ICACHE and KCACHE if either |
Marek Olšák | 7692704 | 2015-02-19 13:03:54 +0100 | [diff] [blame] | 614 | * bit is set. An alternative way is to write SQC_CACHES, but that |
| 615 | * doesn't seem to work reliably. Since the bug doesn't affect |
| 616 | * correctness (it only does more work than necessary) and |
| 617 | * the performance impact is likely negligible, there is no plan |
Marek Olšák | 3faecdd | 2016-04-17 15:34:24 +0200 | [diff] [blame] | 618 | * to add a workaround for it. |
Marek Olšák | 7692704 | 2015-02-19 13:03:54 +0100 | [diff] [blame] | 619 | */ |
| 620 | |
| 621 | if (sctx->flags & SI_CONTEXT_INV_ICACHE) |
| 622 | cp_coher_cntl |= S_0085F0_SH_ICACHE_ACTION_ENA(1); |
Marek Olšák | c6012a6 | 2015-11-06 21:11:16 +0100 | [diff] [blame] | 623 | if (sctx->flags & SI_CONTEXT_INV_SMEM_L1) |
Marek Olšák | 7692704 | 2015-02-19 13:03:54 +0100 | [diff] [blame] | 624 | cp_coher_cntl |= S_0085F0_SH_KCACHE_ACTION_ENA(1); |
Marek Olšák | 2bfe9d4 | 2014-12-29 14:02:46 +0100 | [diff] [blame] | 625 | |
Marek Olšák | c6012a6 | 2015-11-06 21:11:16 +0100 | [diff] [blame] | 626 | if (sctx->flags & SI_CONTEXT_INV_VMEM_L1) |
Marek Olšák | 2bfe9d4 | 2014-12-29 14:02:46 +0100 | [diff] [blame] | 627 | cp_coher_cntl |= S_0085F0_TCL1_ACTION_ENA(1); |
Marek Olšák | c6012a6 | 2015-11-06 21:11:16 +0100 | [diff] [blame] | 628 | if (sctx->flags & SI_CONTEXT_INV_GLOBAL_L2) { |
Marek Olšák | 2bfe9d4 | 2014-12-29 14:02:46 +0100 | [diff] [blame] | 629 | cp_coher_cntl |= S_0085F0_TC_ACTION_ENA(1); |
| 630 | |
Marek Olšák | 2d1952e | 2015-04-16 20:44:54 +0200 | [diff] [blame] | 631 | if (sctx->chip_class >= VI) |
| 632 | cp_coher_cntl |= S_0301F0_TC_WB_ACTION_ENA(1); |
| 633 | } |
| 634 | |
Marek Olšák | 2bfe9d4 | 2014-12-29 14:02:46 +0100 | [diff] [blame] | 635 | if (sctx->flags & SI_CONTEXT_FLUSH_AND_INV_CB) { |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 636 | cp_coher_cntl |= S_0085F0_CB_ACTION_ENA(1) | |
| 637 | S_0085F0_CB0_DEST_BASE_ENA(1) | |
| 638 | S_0085F0_CB1_DEST_BASE_ENA(1) | |
| 639 | S_0085F0_CB2_DEST_BASE_ENA(1) | |
| 640 | S_0085F0_CB3_DEST_BASE_ENA(1) | |
| 641 | S_0085F0_CB4_DEST_BASE_ENA(1) | |
| 642 | S_0085F0_CB5_DEST_BASE_ENA(1) | |
| 643 | S_0085F0_CB6_DEST_BASE_ENA(1) | |
| 644 | S_0085F0_CB7_DEST_BASE_ENA(1); |
Bas Nieuwenhuizen | 81ebd6a | 2015-10-21 00:10:38 +0200 | [diff] [blame] | 645 | |
| 646 | /* Necessary for DCC */ |
| 647 | if (sctx->chip_class >= VI) { |
| 648 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE_EOP, 4, 0) | compute); |
| 649 | radeon_emit(cs, EVENT_TYPE(V_028A90_FLUSH_AND_INV_CB_DATA_TS) | |
| 650 | EVENT_INDEX(5)); |
| 651 | radeon_emit(cs, 0); |
| 652 | radeon_emit(cs, 0); |
| 653 | radeon_emit(cs, 0); |
| 654 | radeon_emit(cs, 0); |
| 655 | } |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 656 | } |
Marek Olšák | 2bfe9d4 | 2014-12-29 14:02:46 +0100 | [diff] [blame] | 657 | if (sctx->flags & SI_CONTEXT_FLUSH_AND_INV_DB) { |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 658 | cp_coher_cntl |= S_0085F0_DB_ACTION_ENA(1) | |
| 659 | S_0085F0_DB_DEST_BASE_ENA(1); |
| 660 | } |
| 661 | |
Marek Olšák | d8185aa | 2014-12-30 18:41:25 +0100 | [diff] [blame] | 662 | if (sctx->flags & SI_CONTEXT_FLUSH_AND_INV_CB_META) { |
| 663 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0) | compute); |
| 664 | radeon_emit(cs, EVENT_TYPE(V_028A90_FLUSH_AND_INV_CB_META) | EVENT_INDEX(0)); |
Marek Olšák | 58494b42 | 2016-04-17 16:14:32 +0200 | [diff] [blame] | 665 | /* needed for wait for idle in SURFACE_SYNC */ |
| 666 | assert(sctx->flags & SI_CONTEXT_FLUSH_AND_INV_CB); |
Marek Olšák | d8185aa | 2014-12-30 18:41:25 +0100 | [diff] [blame] | 667 | } |
| 668 | if (sctx->flags & SI_CONTEXT_FLUSH_AND_INV_DB_META) { |
| 669 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0) | compute); |
| 670 | radeon_emit(cs, EVENT_TYPE(V_028A90_FLUSH_AND_INV_DB_META) | EVENT_INDEX(0)); |
Marek Olšák | 58494b42 | 2016-04-17 16:14:32 +0200 | [diff] [blame] | 671 | /* needed for wait for idle in SURFACE_SYNC */ |
| 672 | assert(sctx->flags & SI_CONTEXT_FLUSH_AND_INV_DB); |
Marek Olšák | d8185aa | 2014-12-30 18:41:25 +0100 | [diff] [blame] | 673 | } |
| 674 | if (sctx->flags & SI_CONTEXT_FLUSH_WITH_INV_L2) { |
| 675 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0) | compute); |
| 676 | radeon_emit(cs, EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH) | EVENT_INDEX(7) | |
| 677 | EVENT_WRITE_INV_L2); |
| 678 | } |
| 679 | |
Marek Olšák | 1db5678 | 2016-04-17 16:18:54 +0200 | [diff] [blame] | 680 | /* Wait for shader engines to go idle. |
| 681 | * VS and PS waits are unnecessary if SURFACE_SYNC is going to wait |
| 682 | * for everything including CB/DB cache flushes. |
Marek Olšák | d8185aa | 2014-12-30 18:41:25 +0100 | [diff] [blame] | 683 | */ |
Marek Olšák | 1db5678 | 2016-04-17 16:18:54 +0200 | [diff] [blame] | 684 | if (!(sctx->flags & (SI_CONTEXT_FLUSH_AND_INV_CB | |
| 685 | SI_CONTEXT_FLUSH_AND_INV_DB))) { |
| 686 | if (sctx->flags & SI_CONTEXT_PS_PARTIAL_FLUSH) { |
| 687 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0) | compute); |
| 688 | radeon_emit(cs, EVENT_TYPE(V_028A90_PS_PARTIAL_FLUSH) | EVENT_INDEX(4)); |
| 689 | } else if (sctx->flags & SI_CONTEXT_VS_PARTIAL_FLUSH) { |
| 690 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0) | compute); |
| 691 | radeon_emit(cs, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH) | EVENT_INDEX(4)); |
| 692 | } |
Marek Olšák | d8185aa | 2014-12-30 18:41:25 +0100 | [diff] [blame] | 693 | } |
| 694 | if (sctx->flags & SI_CONTEXT_CS_PARTIAL_FLUSH) { |
| 695 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0) | compute); |
| 696 | radeon_emit(cs, EVENT_TYPE(V_028A90_CS_PARTIAL_FLUSH | EVENT_INDEX(4))); |
| 697 | } |
Marek Olšák | 1db5678 | 2016-04-17 16:18:54 +0200 | [diff] [blame] | 698 | |
| 699 | /* VGT state synchronization. */ |
Marek Olšák | d8185aa | 2014-12-30 18:41:25 +0100 | [diff] [blame] | 700 | if (sctx->flags & SI_CONTEXT_VGT_FLUSH) { |
| 701 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0) | compute); |
| 702 | radeon_emit(cs, EVENT_TYPE(V_028A90_VGT_FLUSH) | EVENT_INDEX(0)); |
| 703 | } |
| 704 | if (sctx->flags & SI_CONTEXT_VGT_STREAMOUT_SYNC) { |
| 705 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0) | compute); |
| 706 | radeon_emit(cs, EVENT_TYPE(V_028A90_VGT_STREAMOUT_SYNC) | EVENT_INDEX(0)); |
| 707 | } |
| 708 | |
Marek Olšák | dd9ca77 | 2016-04-17 17:28:25 +0200 | [diff] [blame^] | 709 | /* Make sure ME is idle (it executes most packets) before continuing. |
| 710 | * This prevents read-after-write hazards between PFP and ME. |
| 711 | */ |
| 712 | if (cp_coher_cntl || (sctx->flags & SI_CONTEXT_CS_PARTIAL_FLUSH)) { |
| 713 | radeon_emit(cs, PKT3(PKT3_PFP_SYNC_ME, 0, 0)); |
| 714 | radeon_emit(cs, 0); |
| 715 | } |
| 716 | |
Marek Olšák | 78f58a4 | 2016-04-17 15:52:55 +0200 | [diff] [blame] | 717 | /* When one of the DEST_BASE flags is set, SURFACE_SYNC waits for idle. |
Marek Olšák | dd9ca77 | 2016-04-17 17:28:25 +0200 | [diff] [blame^] | 718 | * Therefore, it should be last. Done in PFP. |
Marek Olšák | d8185aa | 2014-12-30 18:41:25 +0100 | [diff] [blame] | 719 | */ |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 720 | if (cp_coher_cntl) { |
Marek Olšák | 78f58a4 | 2016-04-17 15:52:55 +0200 | [diff] [blame] | 721 | /* ACQUIRE_MEM is only required on a compute ring. */ |
| 722 | radeon_emit(cs, PKT3(PKT3_SURFACE_SYNC, 3, 0)); |
| 723 | radeon_emit(cs, cp_coher_cntl); /* CP_COHER_CNTL */ |
| 724 | radeon_emit(cs, 0xffffffff); /* CP_COHER_SIZE */ |
| 725 | radeon_emit(cs, 0); /* CP_COHER_BASE */ |
| 726 | radeon_emit(cs, 0x0000000A); /* POLL_INTERVAL */ |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 727 | } |
| 728 | |
Marek Olšák | b82893f | 2016-04-08 20:29:08 +0200 | [diff] [blame] | 729 | if (sctx->flags & R600_CONTEXT_START_PIPELINE_STATS) { |
Marek Olšák | f3eebb84e | 2016-04-07 02:59:09 +0200 | [diff] [blame] | 730 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0)); |
| 731 | radeon_emit(cs, EVENT_TYPE(V_028A90_PIPELINESTAT_START) | |
| 732 | EVENT_INDEX(0)); |
Marek Olšák | b82893f | 2016-04-08 20:29:08 +0200 | [diff] [blame] | 733 | } else if (sctx->flags & R600_CONTEXT_STOP_PIPELINE_STATS) { |
Marek Olšák | f3eebb84e | 2016-04-07 02:59:09 +0200 | [diff] [blame] | 734 | radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0)); |
| 735 | radeon_emit(cs, EVENT_TYPE(V_028A90_PIPELINESTAT_STOP) | |
| 736 | EVENT_INDEX(0)); |
| 737 | } |
| 738 | |
Andreas Hartmetz | 8662e66 | 2014-01-11 16:00:50 +0100 | [diff] [blame] | 739 | sctx->flags = 0; |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 740 | } |
| 741 | |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 742 | static void si_get_draw_start_count(struct si_context *sctx, |
| 743 | const struct pipe_draw_info *info, |
| 744 | unsigned *start, unsigned *count) |
| 745 | { |
| 746 | if (info->indirect) { |
| 747 | struct r600_resource *indirect = |
| 748 | (struct r600_resource*)info->indirect; |
| 749 | int *data = r600_buffer_map_sync_with_rings(&sctx->b, |
| 750 | indirect, PIPE_TRANSFER_READ); |
| 751 | data += info->indirect_offset/sizeof(int); |
| 752 | *start = data[2]; |
| 753 | *count = data[0]; |
| 754 | } else { |
| 755 | *start = info->start; |
| 756 | *count = info->count; |
| 757 | } |
| 758 | } |
| 759 | |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 760 | void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info) |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 761 | { |
Andreas Hartmetz | 8662e66 | 2014-01-11 16:00:50 +0100 | [diff] [blame] | 762 | struct si_context *sctx = (struct si_context *)ctx; |
Marek Olšák | 50bb2de | 2015-10-22 22:18:49 +0200 | [diff] [blame] | 763 | struct si_state_rasterizer *rs = sctx->queued.named.rasterizer; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 764 | struct pipe_index_buffer ib = {}; |
Marek Olšák | 60c08aa | 2016-02-24 22:04:47 +0100 | [diff] [blame] | 765 | unsigned mask, dirty_fb_counter; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 766 | |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 767 | if (!info->count && !info->indirect && |
| 768 | (info->indexed || !info->count_from_stream_output)) |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 769 | return; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 770 | |
Marek Olšák | 50bb2de | 2015-10-22 22:18:49 +0200 | [diff] [blame] | 771 | if (!sctx->vs_shader.cso) { |
| 772 | assert(0); |
| 773 | return; |
| 774 | } |
| 775 | if (!sctx->ps_shader.cso && (!rs || !rs->rasterizer_discard)) { |
Marek Olšák | 99bf47f | 2015-02-22 18:10:38 +0100 | [diff] [blame] | 776 | assert(0); |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 777 | return; |
Marek Olšák | 99bf47f | 2015-02-22 18:10:38 +0100 | [diff] [blame] | 778 | } |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 779 | if (!!sctx->tes_shader.cso != (info->mode == PIPE_PRIM_PATCHES)) { |
Marek Olšák | 99bf47f | 2015-02-22 18:10:38 +0100 | [diff] [blame] | 780 | assert(0); |
| 781 | return; |
| 782 | } |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 783 | |
Marek Olšák | 60c08aa | 2016-02-24 22:04:47 +0100 | [diff] [blame] | 784 | /* Re-emit the framebuffer state if needed. */ |
| 785 | dirty_fb_counter = p_atomic_read(&sctx->b.screen->dirty_fb_counter); |
| 786 | if (dirty_fb_counter != sctx->b.last_dirty_fb_counter) { |
| 787 | sctx->b.last_dirty_fb_counter = dirty_fb_counter; |
| 788 | sctx->framebuffer.dirty_cbufs |= |
| 789 | ((1 << sctx->framebuffer.state.nr_cbufs) - 1); |
| 790 | sctx->framebuffer.dirty_zsbuf = true; |
| 791 | si_mark_atom_dirty(sctx, &sctx->framebuffer.atom); |
| 792 | } |
| 793 | |
Marek Olšák | 0b1f31a | 2015-02-22 19:14:42 +0100 | [diff] [blame] | 794 | si_decompress_textures(sctx); |
| 795 | |
| 796 | /* Set the rasterization primitive type. |
| 797 | * |
| 798 | * This must be done after si_decompress_textures, which can call |
| 799 | * draw_vbo recursively, and before si_update_shaders, which uses |
| 800 | * current_rast_prim for this draw_vbo call. */ |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 801 | if (sctx->gs_shader.cso) |
| 802 | sctx->current_rast_prim = sctx->gs_shader.cso->gs_output_prim; |
| 803 | else if (sctx->tes_shader.cso) |
Marek Olšák | 5aa5f90 | 2015-02-22 18:09:18 +0100 | [diff] [blame] | 804 | sctx->current_rast_prim = |
Marek Olšák | 9b54ce3 | 2015-10-07 01:48:18 +0200 | [diff] [blame] | 805 | sctx->tes_shader.cso->info.properties[TGSI_PROPERTY_TES_PRIM_MODE]; |
Marek Olšák | 1fe7ba8 | 2015-01-31 20:09:46 +0100 | [diff] [blame] | 806 | else |
| 807 | sctx->current_rast_prim = info->mode; |
| 808 | |
Marek Olšák | 22d3ccf | 2015-09-10 18:27:53 +0200 | [diff] [blame] | 809 | if (!si_update_shaders(sctx) || |
| 810 | !si_upload_shader_descriptors(sctx)) |
Marek Olšák | b052811 | 2015-07-25 00:53:16 +0200 | [diff] [blame] | 811 | return; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 812 | |
Christian König | 9f5ff59 | 2012-08-03 10:26:01 +0200 | [diff] [blame] | 813 | if (info->indexed) { |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 814 | /* Initialize the index buffer struct. */ |
Andreas Hartmetz | 8662e66 | 2014-01-11 16:00:50 +0100 | [diff] [blame] | 815 | pipe_resource_reference(&ib.buffer, sctx->index_buffer.buffer); |
| 816 | ib.user_buffer = sctx->index_buffer.user_buffer; |
| 817 | ib.index_size = sctx->index_buffer.index_size; |
Marek Olšák | 887b69a | 2014-04-24 16:13:54 +0200 | [diff] [blame] | 818 | ib.offset = sctx->index_buffer.offset; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 819 | |
| 820 | /* Translate or upload, if needed. */ |
Marek Olšák | 2d1952e | 2015-04-16 20:44:54 +0200 | [diff] [blame] | 821 | /* 8-bit indices are supported on VI. */ |
| 822 | if (sctx->b.chip_class <= CIK && ib.index_size == 1) { |
Marek Olšák | 9f5c037 | 2014-01-22 03:05:21 +0100 | [diff] [blame] | 823 | struct pipe_resource *out_buffer = NULL; |
Marek Olšák | 887b69a | 2014-04-24 16:13:54 +0200 | [diff] [blame] | 824 | unsigned out_offset, start, count, start_offset; |
Marek Olšák | 9f5c037 | 2014-01-22 03:05:21 +0100 | [diff] [blame] | 825 | void *ptr; |
| 826 | |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 827 | si_get_draw_start_count(sctx, info, &start, &count); |
Marek Olšák | 887b69a | 2014-04-24 16:13:54 +0200 | [diff] [blame] | 828 | start_offset = start * ib.index_size; |
| 829 | |
Marek Olšák | 020009f | 2015-12-19 17:15:02 +0100 | [diff] [blame] | 830 | u_upload_alloc(sctx->b.uploader, start_offset, count * 2, 256, |
Marek Olšák | 9f5c037 | 2014-01-22 03:05:21 +0100 | [diff] [blame] | 831 | &out_offset, &out_buffer, &ptr); |
Marek Olšák | 29dff6f | 2015-09-10 17:42:31 +0200 | [diff] [blame] | 832 | if (!out_buffer) { |
| 833 | pipe_resource_reference(&ib.buffer, NULL); |
| 834 | return; |
| 835 | } |
Marek Olšák | 9f5c037 | 2014-01-22 03:05:21 +0100 | [diff] [blame] | 836 | |
Marek Olšák | 887b69a | 2014-04-24 16:13:54 +0200 | [diff] [blame] | 837 | util_shorten_ubyte_elts_to_userptr(&sctx->b.b, &ib, 0, |
| 838 | ib.offset + start_offset, |
| 839 | count, ptr); |
Marek Olšák | 9f5c037 | 2014-01-22 03:05:21 +0100 | [diff] [blame] | 840 | |
| 841 | pipe_resource_reference(&ib.buffer, NULL); |
| 842 | ib.user_buffer = NULL; |
| 843 | ib.buffer = out_buffer; |
Marek Olšák | 887b69a | 2014-04-24 16:13:54 +0200 | [diff] [blame] | 844 | /* info->start will be added by the drawing code */ |
| 845 | ib.offset = out_offset - start_offset; |
Marek Olšák | 9f5c037 | 2014-01-22 03:05:21 +0100 | [diff] [blame] | 846 | ib.index_size = 2; |
Marek Olšák | 887b69a | 2014-04-24 16:13:54 +0200 | [diff] [blame] | 847 | } else if (ib.user_buffer && !ib.buffer) { |
| 848 | unsigned start, count, start_offset; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 849 | |
Marek Olšák | 2a7b57a | 2014-04-24 03:03:43 +0200 | [diff] [blame] | 850 | si_get_draw_start_count(sctx, info, &start, &count); |
Marek Olšák | 887b69a | 2014-04-24 16:13:54 +0200 | [diff] [blame] | 851 | start_offset = start * ib.index_size; |
| 852 | |
| 853 | u_upload_data(sctx->b.uploader, start_offset, count * ib.index_size, |
Marek Olšák | e0f9328 | 2015-12-19 17:15:02 +0100 | [diff] [blame] | 854 | 256, (char*)ib.user_buffer + start_offset, |
Marek Olšák | 887b69a | 2014-04-24 16:13:54 +0200 | [diff] [blame] | 855 | &ib.offset, &ib.buffer); |
Marek Olšák | 29dff6f | 2015-09-10 17:42:31 +0200 | [diff] [blame] | 856 | if (!ib.buffer) |
| 857 | return; |
Marek Olšák | 887b69a | 2014-04-24 16:13:54 +0200 | [diff] [blame] | 858 | /* info->start will be added by the drawing code */ |
| 859 | ib.offset -= start_offset; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 860 | } |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 861 | } |
| 862 | |
Marek Olšák | 5749676 | 2015-09-06 15:43:23 +0200 | [diff] [blame] | 863 | /* VI reads index buffers through TC L2. */ |
| 864 | if (info->indexed && sctx->b.chip_class <= CIK && |
| 865 | r600_resource(ib.buffer)->TC_L2_dirty) { |
Marek Olšák | c6012a6 | 2015-11-06 21:11:16 +0100 | [diff] [blame] | 866 | sctx->b.flags |= SI_CONTEXT_INV_GLOBAL_L2; |
Marek Olšák | 18a30c9 | 2014-12-29 14:53:11 +0100 | [diff] [blame] | 867 | r600_resource(ib.buffer)->TC_L2_dirty = false; |
| 868 | } |
| 869 | |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 870 | /* Check flush flags. */ |
Andreas Hartmetz | 8662e66 | 2014-01-11 16:00:50 +0100 | [diff] [blame] | 871 | if (sctx->b.flags) |
Grazvydas Ignotas | 3206d4e | 2015-08-10 00:42:32 +0300 | [diff] [blame] | 872 | si_mark_atom_dirty(sctx, sctx->atoms.s.cache_flush); |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 873 | |
Marek Olšák | 28b34b4 | 2015-08-30 03:56:13 +0200 | [diff] [blame] | 874 | si_need_cs_space(sctx); |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 875 | |
Marek Olšák | a77ee8b | 2013-08-26 17:19:39 +0200 | [diff] [blame] | 876 | /* Emit states. */ |
Marek Olšák | 87c1e9e | 2015-08-29 00:49:40 +0200 | [diff] [blame] | 877 | mask = sctx->dirty_atoms; |
| 878 | while (mask) { |
| 879 | struct r600_atom *atom = sctx->atoms.array[u_bit_scan(&mask)]; |
| 880 | |
| 881 | atom->emit(&sctx->b, atom); |
Marek Olšák | c8e70e6 | 2013-08-06 06:42:22 +0200 | [diff] [blame] | 882 | } |
Marek Olšák | 87c1e9e | 2015-08-29 00:49:40 +0200 | [diff] [blame] | 883 | sctx->dirty_atoms = 0; |
Marek Olšák | c8e70e6 | 2013-08-06 06:42:22 +0200 | [diff] [blame] | 884 | |
Andreas Hartmetz | 8662e66 | 2014-01-11 16:00:50 +0100 | [diff] [blame] | 885 | si_pm4_emit_dirty(sctx); |
Marek Olšák | dc39413 | 2015-03-15 20:13:52 +0100 | [diff] [blame] | 886 | si_emit_scratch_reloc(sctx); |
Marek Olšák | fdf2c04 | 2015-02-22 17:42:20 +0100 | [diff] [blame] | 887 | si_emit_rasterizer_prim_state(sctx); |
| 888 | si_emit_draw_registers(sctx, info); |
Marek Olšák | 384213c | 2014-12-07 15:52:15 +0100 | [diff] [blame] | 889 | si_emit_draw_packets(sctx, info, &ib); |
| 890 | |
Marek Olšák | 2c14a6d | 2015-08-19 11:53:25 +0200 | [diff] [blame] | 891 | if (sctx->trace_buf) |
Andreas Hartmetz | 8662e66 | 2014-01-11 16:00:50 +0100 | [diff] [blame] | 892 | si_trace_emit(sctx); |
Jerome Glisse | 3f7d971 | 2013-03-25 11:46:38 -0400 | [diff] [blame] | 893 | |
Marek Olšák | 0e7f563 | 2014-07-26 03:16:22 +0200 | [diff] [blame] | 894 | /* Workaround for a VGT hang when streamout is enabled. |
| 895 | * It must be done after drawing. */ |
Marek Olšák | 787ada6 | 2015-12-04 21:24:21 +0100 | [diff] [blame] | 896 | if ((sctx->b.family == CHIP_HAWAII || |
| 897 | sctx->b.family == CHIP_TONGA || |
| 898 | sctx->b.family == CHIP_FIJI) && |
Marek Olšák | a4c288d | 2016-04-07 03:24:06 +0200 | [diff] [blame] | 899 | r600_get_strmout_en(&sctx->b)) { |
Marek Olšák | 2bfe9d4 | 2014-12-29 14:02:46 +0100 | [diff] [blame] | 900 | sctx->b.flags |= SI_CONTEXT_VGT_STREAMOUT_SYNC; |
Marek Olšák | 0e7f563 | 2014-07-26 03:16:22 +0200 | [diff] [blame] | 901 | } |
| 902 | |
Marek Olšák | 6f6112a | 2013-01-17 19:36:41 +0100 | [diff] [blame] | 903 | /* Set the depth buffer as dirty. */ |
Marek Olšák | 6a5499b | 2014-03-04 17:49:39 +0100 | [diff] [blame] | 904 | if (sctx->framebuffer.state.zsbuf) { |
| 905 | struct pipe_surface *surf = sctx->framebuffer.state.zsbuf; |
Marek Olšák | 363b280 | 2013-08-05 03:42:11 +0200 | [diff] [blame] | 906 | struct r600_texture *rtex = (struct r600_texture *)surf->texture; |
Marek Olšák | 6f6112a | 2013-01-17 19:36:41 +0100 | [diff] [blame] | 907 | |
Marek Olšák | 0469171 | 2013-08-05 14:40:43 +0200 | [diff] [blame] | 908 | rtex->dirty_level_mask |= 1 << surf->u.tex.level; |
Marek Olšák | 5804c6a | 2015-09-06 17:35:06 +0200 | [diff] [blame] | 909 | |
| 910 | if (rtex->surface.flags & RADEON_SURF_SBUFFER) |
| 911 | rtex->stencil_dirty_level_mask |= 1 << surf->u.tex.level; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 912 | } |
Marek Olšák | 6a5499b | 2014-03-04 17:49:39 +0100 | [diff] [blame] | 913 | if (sctx->framebuffer.compressed_cb_mask) { |
Marek Olšák | 3c3feb3 | 2013-08-06 08:48:07 +0200 | [diff] [blame] | 914 | struct pipe_surface *surf; |
| 915 | struct r600_texture *rtex; |
Marek Olšák | 6a5499b | 2014-03-04 17:49:39 +0100 | [diff] [blame] | 916 | unsigned mask = sctx->framebuffer.compressed_cb_mask; |
Marek Olšák | 3c3feb3 | 2013-08-06 08:48:07 +0200 | [diff] [blame] | 917 | |
| 918 | do { |
| 919 | unsigned i = u_bit_scan(&mask); |
Marek Olšák | 6a5499b | 2014-03-04 17:49:39 +0100 | [diff] [blame] | 920 | surf = sctx->framebuffer.state.cbufs[i]; |
Marek Olšák | 3c3feb3 | 2013-08-06 08:48:07 +0200 | [diff] [blame] | 921 | rtex = (struct r600_texture*)surf->texture; |
| 922 | |
| 923 | rtex->dirty_level_mask |= 1 << surf->u.tex.level; |
| 924 | } while (mask); |
| 925 | } |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 926 | |
| 927 | pipe_resource_reference(&ib.buffer, NULL); |
Marek Olšák | ba0c16f | 2014-01-22 01:29:18 +0100 | [diff] [blame] | 928 | sctx->b.num_draw_calls++; |
Christian König | ca9cf61 | 2012-07-19 15:20:45 +0200 | [diff] [blame] | 929 | } |
Marek Olšák | 837907b | 2014-09-05 11:59:10 +0200 | [diff] [blame] | 930 | |
Marek Olšák | 837907b | 2014-09-05 11:59:10 +0200 | [diff] [blame] | 931 | void si_trace_emit(struct si_context *sctx) |
| 932 | { |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 933 | struct radeon_winsys_cs *cs = sctx->b.gfx.cs; |
Marek Olšák | 837907b | 2014-09-05 11:59:10 +0200 | [diff] [blame] | 934 | |
Marek Olšák | 2c14a6d | 2015-08-19 11:53:25 +0200 | [diff] [blame] | 935 | sctx->trace_id++; |
Marek Olšák | 6cc8f6c | 2015-11-07 14:00:30 +0100 | [diff] [blame] | 936 | radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx, sctx->trace_buf, |
Marek Olšák | 2edb060 | 2015-09-26 23:18:55 +0200 | [diff] [blame] | 937 | RADEON_USAGE_READWRITE, RADEON_PRIO_TRACE); |
Marek Olšák | 2c14a6d | 2015-08-19 11:53:25 +0200 | [diff] [blame] | 938 | radeon_emit(cs, PKT3(PKT3_WRITE_DATA, 3, 0)); |
Marek Olšák | 16e5d8a | 2015-08-19 18:45:11 +0200 | [diff] [blame] | 939 | radeon_emit(cs, S_370_DST_SEL(V_370_MEMORY_SYNC) | |
| 940 | S_370_WR_CONFIRM(1) | |
| 941 | S_370_ENGINE_SEL(V_370_ME)); |
Marek Olšák | 2c14a6d | 2015-08-19 11:53:25 +0200 | [diff] [blame] | 942 | radeon_emit(cs, sctx->trace_buf->gpu_address); |
| 943 | radeon_emit(cs, sctx->trace_buf->gpu_address >> 32); |
| 944 | radeon_emit(cs, sctx->trace_id); |
| 945 | radeon_emit(cs, PKT3(PKT3_NOP, 0, 0)); |
| 946 | radeon_emit(cs, SI_ENCODE_TRACE_POINT(sctx->trace_id)); |
Marek Olšák | 837907b | 2014-09-05 11:59:10 +0200 | [diff] [blame] | 947 | } |