2012-07-19 15:20:45 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright 2012 Advanced Micro Devices, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* on the rights to use, copy, modify, merge, publish, distribute, sub
|
|
|
|
|
* license, and/or sell copies of the Software, and to permit persons to whom
|
|
|
|
|
* the Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-01-04 18:44:33 +01:00
|
|
|
#include "si_pipe.h"
|
2014-08-16 17:58:25 +01:00
|
|
|
#include "radeon/r600_cs.h"
|
2012-07-19 15:20:45 +02:00
|
|
|
#include "sid.h"
|
2016-10-15 15:00:33 +02:00
|
|
|
#include "gfx9d.h"
|
2012-07-19 15:20:45 +02:00
|
|
|
|
2014-01-22 18:50:36 +01:00
|
|
|
#include "util/u_index_modify.h"
|
2017-08-04 18:24:33 +02:00
|
|
|
#include "util/u_log.h"
|
2014-01-22 18:50:36 +01:00
|
|
|
#include "util/u_upload_mgr.h"
|
2015-02-22 18:06:34 +01:00
|
|
|
#include "util/u_prim.h"
|
2014-01-22 18:50:36 +01:00
|
|
|
|
2016-12-24 13:08:00 +01:00
|
|
|
#include "ac_debug.h"
|
|
|
|
|
|
2014-12-07 16:02:07 +01:00
|
|
|
static unsigned si_conv_pipe_prim(unsigned mode)
|
2012-07-19 15:20:45 +02:00
|
|
|
{
|
|
|
|
|
static const unsigned prim_conv[] = {
|
|
|
|
|
[PIPE_PRIM_POINTS] = V_008958_DI_PT_POINTLIST,
|
|
|
|
|
[PIPE_PRIM_LINES] = V_008958_DI_PT_LINELIST,
|
|
|
|
|
[PIPE_PRIM_LINE_LOOP] = V_008958_DI_PT_LINELOOP,
|
|
|
|
|
[PIPE_PRIM_LINE_STRIP] = V_008958_DI_PT_LINESTRIP,
|
|
|
|
|
[PIPE_PRIM_TRIANGLES] = V_008958_DI_PT_TRILIST,
|
|
|
|
|
[PIPE_PRIM_TRIANGLE_STRIP] = V_008958_DI_PT_TRISTRIP,
|
|
|
|
|
[PIPE_PRIM_TRIANGLE_FAN] = V_008958_DI_PT_TRIFAN,
|
|
|
|
|
[PIPE_PRIM_QUADS] = V_008958_DI_PT_QUADLIST,
|
|
|
|
|
[PIPE_PRIM_QUAD_STRIP] = V_008958_DI_PT_QUADSTRIP,
|
|
|
|
|
[PIPE_PRIM_POLYGON] = V_008958_DI_PT_POLYGON,
|
2014-01-09 16:35:46 +09:00
|
|
|
[PIPE_PRIM_LINES_ADJACENCY] = V_008958_DI_PT_LINELIST_ADJ,
|
|
|
|
|
[PIPE_PRIM_LINE_STRIP_ADJACENCY] = V_008958_DI_PT_LINESTRIP_ADJ,
|
|
|
|
|
[PIPE_PRIM_TRIANGLES_ADJACENCY] = V_008958_DI_PT_TRILIST_ADJ,
|
2014-08-18 00:55:40 +02:00
|
|
|
[PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY] = V_008958_DI_PT_TRISTRIP_ADJ,
|
2014-09-18 23:39:44 +02:00
|
|
|
[PIPE_PRIM_PATCHES] = V_008958_DI_PT_PATCH,
|
2014-08-18 00:55:40 +02:00
|
|
|
[R600_PRIM_RECTANGLE_LIST] = V_008958_DI_PT_RECTLIST
|
2012-07-19 15:20:45 +02:00
|
|
|
};
|
2016-05-17 09:25:44 -04:00
|
|
|
assert(mode < ARRAY_SIZE(prim_conv));
|
2014-12-07 16:02:07 +01:00
|
|
|
return prim_conv[mode];
|
2012-07-19 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-01-07 03:18:25 +01:00
|
|
|
static unsigned si_conv_prim_to_gs_out(unsigned mode)
|
2013-08-18 03:05:34 +02:00
|
|
|
{
|
|
|
|
|
static const int prim_conv[] = {
|
|
|
|
|
[PIPE_PRIM_POINTS] = V_028A6C_OUTPRIM_TYPE_POINTLIST,
|
|
|
|
|
[PIPE_PRIM_LINES] = V_028A6C_OUTPRIM_TYPE_LINESTRIP,
|
|
|
|
|
[PIPE_PRIM_LINE_LOOP] = V_028A6C_OUTPRIM_TYPE_LINESTRIP,
|
|
|
|
|
[PIPE_PRIM_LINE_STRIP] = V_028A6C_OUTPRIM_TYPE_LINESTRIP,
|
|
|
|
|
[PIPE_PRIM_TRIANGLES] = V_028A6C_OUTPRIM_TYPE_TRISTRIP,
|
|
|
|
|
[PIPE_PRIM_TRIANGLE_STRIP] = V_028A6C_OUTPRIM_TYPE_TRISTRIP,
|
|
|
|
|
[PIPE_PRIM_TRIANGLE_FAN] = V_028A6C_OUTPRIM_TYPE_TRISTRIP,
|
|
|
|
|
[PIPE_PRIM_QUADS] = V_028A6C_OUTPRIM_TYPE_TRISTRIP,
|
|
|
|
|
[PIPE_PRIM_QUAD_STRIP] = V_028A6C_OUTPRIM_TYPE_TRISTRIP,
|
|
|
|
|
[PIPE_PRIM_POLYGON] = V_028A6C_OUTPRIM_TYPE_TRISTRIP,
|
|
|
|
|
[PIPE_PRIM_LINES_ADJACENCY] = V_028A6C_OUTPRIM_TYPE_LINESTRIP,
|
|
|
|
|
[PIPE_PRIM_LINE_STRIP_ADJACENCY] = V_028A6C_OUTPRIM_TYPE_LINESTRIP,
|
|
|
|
|
[PIPE_PRIM_TRIANGLES_ADJACENCY] = V_028A6C_OUTPRIM_TYPE_TRISTRIP,
|
2014-08-18 00:55:40 +02:00
|
|
|
[PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY] = V_028A6C_OUTPRIM_TYPE_TRISTRIP,
|
2014-09-18 23:39:44 +02:00
|
|
|
[PIPE_PRIM_PATCHES] = V_028A6C_OUTPRIM_TYPE_POINTLIST,
|
2014-08-18 00:55:40 +02:00
|
|
|
[R600_PRIM_RECTANGLE_LIST] = V_028A6C_OUTPRIM_TYPE_TRISTRIP
|
2013-08-18 03:05:34 +02:00
|
|
|
};
|
2016-05-17 09:25:44 -04:00
|
|
|
assert(mode < ARRAY_SIZE(prim_conv));
|
2013-08-18 03:05:34 +02:00
|
|
|
|
|
|
|
|
return prim_conv[mode];
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-22 18:01:18 +01:00
|
|
|
/**
|
|
|
|
|
* This calculates the LDS size for tessellation shaders (VS, TCS, TES).
|
|
|
|
|
* LS.LDS_SIZE is shared by all 3 shader stages.
|
|
|
|
|
*
|
|
|
|
|
* The information about LDS and other non-compile-time parameters is then
|
|
|
|
|
* written to userdata SGPRs.
|
|
|
|
|
*/
|
|
|
|
|
static void si_emit_derived_tess_state(struct si_context *sctx,
|
|
|
|
|
const struct pipe_draw_info *info,
|
|
|
|
|
unsigned *num_patches)
|
|
|
|
|
{
|
2015-11-07 14:00:30 +01:00
|
|
|
struct radeon_winsys_cs *cs = sctx->b.gfx.cs;
|
2017-02-15 11:57:47 +01:00
|
|
|
struct si_shader *ls_current;
|
|
|
|
|
struct si_shader_selector *ls;
|
2015-02-22 18:01:18 +01:00
|
|
|
/* The TES pointer will only be used for sctx->last_tcs.
|
|
|
|
|
* It would be wrong to think that TCS = TES. */
|
|
|
|
|
struct si_shader_selector *tcs =
|
2015-10-07 01:48:18 +02:00
|
|
|
sctx->tcs_shader.cso ? sctx->tcs_shader.cso : sctx->tes_shader.cso;
|
2017-06-06 15:23:42 +02:00
|
|
|
unsigned tess_uses_primid = sctx->ia_multi_vgt_param_key.u.tess_uses_prim_id;
|
|
|
|
|
bool has_primid_instancing_bug = sctx->b.chip_class == SI &&
|
|
|
|
|
sctx->b.screen->info.max_se == 1;
|
2017-08-04 03:26:38 +02:00
|
|
|
unsigned tes_sh_base = sctx->shader_pointers.sh_base[PIPE_SHADER_TESS_EVAL];
|
2015-02-22 18:01:18 +01:00
|
|
|
unsigned num_tcs_input_cp = info->vertices_per_patch;
|
|
|
|
|
unsigned num_tcs_output_cp, num_tcs_inputs, num_tcs_outputs;
|
|
|
|
|
unsigned num_tcs_patch_outputs;
|
|
|
|
|
unsigned input_vertex_size, output_vertex_size, pervertex_output_patch_size;
|
|
|
|
|
unsigned input_patch_size, output_patch_size, output_patch0_offset;
|
2016-11-11 22:37:39 +01:00
|
|
|
unsigned perpatch_output_offset, lds_size;
|
2015-02-22 18:01:18 +01:00
|
|
|
unsigned tcs_in_layout, tcs_out_layout, tcs_out_offsets;
|
2016-09-30 22:37:14 +02:00
|
|
|
unsigned offchip_layout, hardware_lds_size, ls_hs_config;
|
2015-02-22 18:01:18 +01:00
|
|
|
|
2017-02-15 11:57:47 +01:00
|
|
|
/* Since GFX9 has merged LS-HS in the TCS state, set LS = TCS. */
|
|
|
|
|
if (sctx->b.chip_class >= GFX9) {
|
|
|
|
|
if (sctx->tcs_shader.cso)
|
|
|
|
|
ls_current = sctx->tcs_shader.current;
|
|
|
|
|
else
|
|
|
|
|
ls_current = sctx->fixed_func_tcs_shader.current;
|
|
|
|
|
|
|
|
|
|
ls = ls_current->key.part.tcs.ls;
|
|
|
|
|
} else {
|
|
|
|
|
ls_current = sctx->vs_shader.current;
|
|
|
|
|
ls = sctx->vs_shader.cso;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sctx->last_ls == ls_current &&
|
2016-11-11 22:36:17 +01:00
|
|
|
sctx->last_tcs == tcs &&
|
|
|
|
|
sctx->last_tes_sh_base == tes_sh_base &&
|
2017-06-06 15:23:42 +02:00
|
|
|
sctx->last_num_tcs_input_cp == num_tcs_input_cp &&
|
|
|
|
|
(!has_primid_instancing_bug ||
|
|
|
|
|
(sctx->last_tess_uses_primid == tess_uses_primid))) {
|
2016-11-11 22:36:17 +01:00
|
|
|
*num_patches = sctx->last_num_patches;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-15 11:57:47 +01:00
|
|
|
sctx->last_ls = ls_current;
|
2016-11-11 22:36:17 +01:00
|
|
|
sctx->last_tcs = tcs;
|
|
|
|
|
sctx->last_tes_sh_base = tes_sh_base;
|
|
|
|
|
sctx->last_num_tcs_input_cp = num_tcs_input_cp;
|
2017-06-06 15:23:42 +02:00
|
|
|
sctx->last_tess_uses_primid = tess_uses_primid;
|
2016-11-11 22:36:17 +01:00
|
|
|
|
2015-02-22 18:01:18 +01:00
|
|
|
/* This calculates how shader inputs and outputs among VS, TCS, and TES
|
|
|
|
|
* are laid out in LDS. */
|
2017-02-15 11:57:47 +01:00
|
|
|
num_tcs_inputs = util_last_bit64(ls->outputs_written);
|
2015-02-22 18:01:18 +01:00
|
|
|
|
2015-10-07 01:48:18 +02:00
|
|
|
if (sctx->tcs_shader.cso) {
|
2015-02-22 18:01:18 +01:00
|
|
|
num_tcs_outputs = util_last_bit64(tcs->outputs_written);
|
|
|
|
|
num_tcs_output_cp = tcs->info.properties[TGSI_PROPERTY_TCS_VERTICES_OUT];
|
|
|
|
|
num_tcs_patch_outputs = util_last_bit64(tcs->patch_outputs_written);
|
|
|
|
|
} else {
|
|
|
|
|
/* No TCS. Route varyings from LS to TES. */
|
|
|
|
|
num_tcs_outputs = num_tcs_inputs;
|
|
|
|
|
num_tcs_output_cp = num_tcs_input_cp;
|
|
|
|
|
num_tcs_patch_outputs = 2; /* TESSINNER + TESSOUTER */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
input_vertex_size = num_tcs_inputs * 16;
|
|
|
|
|
output_vertex_size = num_tcs_outputs * 16;
|
|
|
|
|
|
|
|
|
|
input_patch_size = num_tcs_input_cp * input_vertex_size;
|
|
|
|
|
|
|
|
|
|
pervertex_output_patch_size = num_tcs_output_cp * output_vertex_size;
|
|
|
|
|
output_patch_size = pervertex_output_patch_size + num_tcs_patch_outputs * 16;
|
|
|
|
|
|
2016-05-02 15:00:21 +02:00
|
|
|
/* Ensure that we only need one wave per SIMD so we don't need to check
|
|
|
|
|
* resource usage. Also ensures that the number of tcs in and out
|
|
|
|
|
* vertices per threadgroup are at most 256.
|
|
|
|
|
*/
|
|
|
|
|
*num_patches = 64 / MAX2(num_tcs_input_cp, num_tcs_output_cp) * 4;
|
|
|
|
|
|
|
|
|
|
/* Make sure that the data fits in LDS. This assumes the shaders only
|
|
|
|
|
* use LDS for the inputs and outputs.
|
2017-05-23 21:52:11 +02:00
|
|
|
*
|
|
|
|
|
* While CIK can use 64K per threadgroup, there is a hang on Stoney
|
|
|
|
|
* with 2 CUs if we use more than 32K. The closed Vulkan driver also
|
|
|
|
|
* uses 32K at most on all GCN chips.
|
2016-05-02 15:00:21 +02:00
|
|
|
*/
|
2017-05-23 21:52:11 +02:00
|
|
|
hardware_lds_size = 32768;
|
2016-05-02 15:00:21 +02:00
|
|
|
*num_patches = MIN2(*num_patches, hardware_lds_size / (input_patch_size +
|
|
|
|
|
output_patch_size));
|
|
|
|
|
|
|
|
|
|
/* Make sure the output data fits in the offchip buffer */
|
2016-06-28 14:11:12 +02:00
|
|
|
*num_patches = MIN2(*num_patches,
|
|
|
|
|
(sctx->screen->tess_offchip_block_dw_size * 4) /
|
|
|
|
|
output_patch_size);
|
2016-05-02 15:00:21 +02:00
|
|
|
|
|
|
|
|
/* Not necessary for correctness, but improves performance. The
|
|
|
|
|
* specific value is taken from the proprietary driver.
|
|
|
|
|
*/
|
|
|
|
|
*num_patches = MIN2(*num_patches, 40);
|
2016-11-29 20:41:23 +01:00
|
|
|
|
2017-08-29 23:11:38 +02:00
|
|
|
if (sctx->b.chip_class == SI) {
|
2017-05-03 11:34:33 +02:00
|
|
|
/* SI bug workaround, related to power management. Limit LS-HS
|
|
|
|
|
* threadgroups to only one wave.
|
|
|
|
|
*/
|
2016-11-29 20:41:23 +01:00
|
|
|
unsigned one_wave = 64 / MAX2(num_tcs_input_cp, num_tcs_output_cp);
|
|
|
|
|
*num_patches = MIN2(*num_patches, one_wave);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-06 15:23:42 +02:00
|
|
|
/* The VGT HS block increments the patch ID unconditionally
|
|
|
|
|
* within a single threadgroup. This results in incorrect
|
|
|
|
|
* patch IDs when instanced draws are used.
|
|
|
|
|
*
|
|
|
|
|
* The intended solution is to restrict threadgroups to
|
|
|
|
|
* a single instance by setting SWITCH_ON_EOI, which
|
|
|
|
|
* should cause IA to split instances up. However, this
|
|
|
|
|
* doesn't work correctly on SI when there is no other
|
|
|
|
|
* SE to switch to.
|
|
|
|
|
*/
|
2017-09-05 17:04:31 +02:00
|
|
|
if (has_primid_instancing_bug && tess_uses_primid)
|
2017-06-06 15:23:42 +02:00
|
|
|
*num_patches = 1;
|
|
|
|
|
|
2016-11-11 22:36:17 +01:00
|
|
|
sctx->last_num_patches = *num_patches;
|
2016-05-02 15:00:21 +02:00
|
|
|
|
|
|
|
|
output_patch0_offset = input_patch_size * *num_patches;
|
2015-02-22 18:01:18 +01:00
|
|
|
perpatch_output_offset = output_patch0_offset + pervertex_output_patch_size;
|
|
|
|
|
|
|
|
|
|
/* Compute userdata SGPRs. */
|
|
|
|
|
assert(((input_vertex_size / 4) & ~0xff) == 0);
|
|
|
|
|
assert(((output_vertex_size / 4) & ~0xff) == 0);
|
|
|
|
|
assert(((input_patch_size / 4) & ~0x1fff) == 0);
|
|
|
|
|
assert(((output_patch_size / 4) & ~0x1fff) == 0);
|
|
|
|
|
assert(((output_patch0_offset / 16) & ~0xffff) == 0);
|
|
|
|
|
assert(((perpatch_output_offset / 16) & ~0xffff) == 0);
|
|
|
|
|
assert(num_tcs_input_cp <= 32);
|
|
|
|
|
assert(num_tcs_output_cp <= 32);
|
|
|
|
|
|
2017-04-12 10:16:07 +02:00
|
|
|
tcs_in_layout = S_VS_STATE_LS_OUT_PATCH_SIZE(input_patch_size / 4) |
|
|
|
|
|
S_VS_STATE_LS_OUT_VERTEX_SIZE(input_vertex_size / 4);
|
2017-09-05 19:52:23 +02:00
|
|
|
tcs_out_layout = output_patch_size / 4;
|
2015-02-22 18:01:18 +01:00
|
|
|
tcs_out_offsets = (output_patch0_offset / 16) |
|
|
|
|
|
((perpatch_output_offset / 16) << 16);
|
2017-04-22 21:12:08 +02:00
|
|
|
offchip_layout = *num_patches |
|
|
|
|
|
(num_tcs_output_cp << 6) |
|
|
|
|
|
(pervertex_output_patch_size * *num_patches << 12);
|
2015-02-22 18:01:18 +01:00
|
|
|
|
2016-11-11 22:37:39 +01:00
|
|
|
/* Compute the LDS size. */
|
|
|
|
|
lds_size = output_patch0_offset + output_patch_size * *num_patches;
|
|
|
|
|
|
|
|
|
|
if (sctx->b.chip_class >= CIK) {
|
|
|
|
|
assert(lds_size <= 65536);
|
|
|
|
|
lds_size = align(lds_size, 512) / 512;
|
|
|
|
|
} else {
|
|
|
|
|
assert(lds_size <= 32768);
|
|
|
|
|
lds_size = align(lds_size, 256) / 256;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set SI_SGPR_VS_STATE_BITS. */
|
2017-04-12 10:46:22 +02:00
|
|
|
sctx->current_vs_state &= C_VS_STATE_LS_OUT_PATCH_SIZE &
|
|
|
|
|
C_VS_STATE_LS_OUT_VERTEX_SIZE;
|
|
|
|
|
sctx->current_vs_state |= tcs_in_layout;
|
2015-02-22 18:01:18 +01:00
|
|
|
|
2016-11-11 22:37:39 +01:00
|
|
|
if (sctx->b.chip_class >= GFX9) {
|
2017-02-15 11:57:47 +01:00
|
|
|
unsigned hs_rsrc2 = ls_current->config.rsrc2 |
|
|
|
|
|
S_00B42C_LDS_SIZE(lds_size);
|
|
|
|
|
|
|
|
|
|
radeon_set_sh_reg(cs, R_00B42C_SPI_SHADER_PGM_RSRC2_HS, hs_rsrc2);
|
2017-02-15 22:47:57 +01:00
|
|
|
|
|
|
|
|
/* Set userdata SGPRs for merged LS-HS. */
|
|
|
|
|
radeon_set_sh_reg_seq(cs,
|
|
|
|
|
R_00B430_SPI_SHADER_USER_DATA_LS_0 +
|
|
|
|
|
GFX9_SGPR_TCS_OFFCHIP_LAYOUT * 4, 3);
|
|
|
|
|
radeon_emit(cs, offchip_layout);
|
|
|
|
|
radeon_emit(cs, tcs_out_offsets);
|
|
|
|
|
radeon_emit(cs, tcs_out_layout | (num_tcs_input_cp << 26));
|
2016-11-11 22:37:39 +01:00
|
|
|
} else {
|
2017-02-15 11:57:47 +01:00
|
|
|
unsigned ls_rsrc2 = ls_current->config.rsrc2;
|
2016-11-11 22:37:39 +01:00
|
|
|
|
|
|
|
|
si_multiwave_lds_size_workaround(sctx->screen, &lds_size);
|
|
|
|
|
ls_rsrc2 |= S_00B52C_LDS_SIZE(lds_size);
|
|
|
|
|
|
|
|
|
|
/* Due to a hw bug, RSRC2_LS must be written twice with another
|
|
|
|
|
* LS register written in between. */
|
|
|
|
|
if (sctx->b.chip_class == CIK && sctx->b.family != CHIP_HAWAII)
|
|
|
|
|
radeon_set_sh_reg(cs, R_00B52C_SPI_SHADER_PGM_RSRC2_LS, ls_rsrc2);
|
|
|
|
|
radeon_set_sh_reg_seq(cs, R_00B528_SPI_SHADER_PGM_RSRC1_LS, 2);
|
2017-02-15 11:57:47 +01:00
|
|
|
radeon_emit(cs, ls_current->config.rsrc1);
|
2016-11-11 22:37:39 +01:00
|
|
|
radeon_emit(cs, ls_rsrc2);
|
|
|
|
|
|
|
|
|
|
/* Set userdata SGPRs for TCS. */
|
|
|
|
|
radeon_set_sh_reg_seq(cs,
|
2017-02-15 22:47:57 +01:00
|
|
|
R_00B430_SPI_SHADER_USER_DATA_HS_0 + GFX6_SGPR_TCS_OFFCHIP_LAYOUT * 4, 4);
|
2016-11-11 22:37:39 +01:00
|
|
|
radeon_emit(cs, offchip_layout);
|
|
|
|
|
radeon_emit(cs, tcs_out_offsets);
|
|
|
|
|
radeon_emit(cs, tcs_out_layout | (num_tcs_input_cp << 26));
|
|
|
|
|
radeon_emit(cs, tcs_in_layout);
|
|
|
|
|
}
|
2015-02-22 18:01:18 +01:00
|
|
|
|
2016-11-11 22:37:39 +01:00
|
|
|
/* Set userdata SGPRs for TES. */
|
2017-04-22 19:34:26 +02:00
|
|
|
radeon_set_sh_reg_seq(cs, tes_sh_base + SI_SGPR_TES_OFFCHIP_LAYOUT * 4, 2);
|
2016-05-10 00:48:55 +02:00
|
|
|
radeon_emit(cs, offchip_layout);
|
2017-04-22 19:34:26 +02:00
|
|
|
radeon_emit(cs, r600_resource(sctx->tess_offchip_ring)->gpu_address >> 16);
|
2016-09-30 22:37:14 +02:00
|
|
|
|
|
|
|
|
ls_hs_config = S_028B58_NUM_PATCHES(*num_patches) |
|
|
|
|
|
S_028B58_HS_NUM_INPUT_CP(num_tcs_input_cp) |
|
|
|
|
|
S_028B58_HS_NUM_OUTPUT_CP(num_tcs_output_cp);
|
|
|
|
|
|
|
|
|
|
if (sctx->b.chip_class >= CIK)
|
|
|
|
|
radeon_set_context_reg_idx(cs, R_028B58_VGT_LS_HS_CONFIG, 2,
|
|
|
|
|
ls_hs_config);
|
|
|
|
|
else
|
|
|
|
|
radeon_set_context_reg(cs, R_028B58_VGT_LS_HS_CONFIG,
|
|
|
|
|
ls_hs_config);
|
2015-02-22 18:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-09 22:14:32 +01:00
|
|
|
static unsigned si_num_prims_for_vertices(const struct pipe_draw_info *info)
|
|
|
|
|
{
|
|
|
|
|
switch (info->mode) {
|
|
|
|
|
case PIPE_PRIM_PATCHES:
|
|
|
|
|
return info->count / info->vertices_per_patch;
|
|
|
|
|
case R600_PRIM_RECTANGLE_LIST:
|
|
|
|
|
return info->count / 3;
|
|
|
|
|
default:
|
|
|
|
|
return u_prims_for_vertices(info->mode, info->count);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-25 02:47:15 +01:00
|
|
|
static unsigned
|
|
|
|
|
si_get_init_multi_vgt_param(struct si_screen *sscreen,
|
|
|
|
|
union si_vgt_param_key *key)
|
2014-08-15 16:32:03 +02:00
|
|
|
{
|
2017-01-25 02:47:15 +01:00
|
|
|
STATIC_ASSERT(sizeof(union si_vgt_param_key) == 4);
|
2015-10-18 22:07:01 +02:00
|
|
|
unsigned max_primgroup_in_wave = 2;
|
2014-08-15 16:32:03 +02:00
|
|
|
|
|
|
|
|
/* SWITCH_ON_EOP(0) is always preferable. */
|
|
|
|
|
bool wd_switch_on_eop = false;
|
|
|
|
|
bool ia_switch_on_eop = false;
|
2015-02-22 18:06:34 +01:00
|
|
|
bool ia_switch_on_eoi = false;
|
2014-08-15 22:45:10 +02:00
|
|
|
bool partial_vs_wave = false;
|
2015-02-22 18:06:34 +01:00
|
|
|
bool partial_es_wave = false;
|
2014-08-15 16:32:03 +02:00
|
|
|
|
2017-01-25 02:47:15 +01:00
|
|
|
if (key->u.uses_tess) {
|
2015-10-18 22:17:04 +02:00
|
|
|
/* SWITCH_ON_EOI must be set if PrimID is used. */
|
2017-05-15 11:13:44 +02:00
|
|
|
if (key->u.tess_uses_prim_id)
|
2015-02-22 18:06:34 +01:00
|
|
|
ia_switch_on_eoi = true;
|
|
|
|
|
|
|
|
|
|
/* Bug with tessellation and GS on Bonaire and older 2 SE chips. */
|
2017-01-25 02:47:15 +01:00
|
|
|
if ((sscreen->b.family == CHIP_TAHITI ||
|
|
|
|
|
sscreen->b.family == CHIP_PITCAIRN ||
|
|
|
|
|
sscreen->b.family == CHIP_BONAIRE) &&
|
|
|
|
|
key->u.uses_gs)
|
2015-02-22 18:06:34 +01:00
|
|
|
partial_vs_wave = true;
|
2016-04-12 20:28:46 +02:00
|
|
|
|
|
|
|
|
/* Needed for 028B6C_DISTRIBUTION_MODE != 0 */
|
2017-01-25 02:47:15 +01:00
|
|
|
if (sscreen->has_distributed_tess) {
|
|
|
|
|
if (key->u.uses_gs) {
|
2017-04-23 20:29:04 +02:00
|
|
|
if (sscreen->b.chip_class <= VI)
|
|
|
|
|
partial_es_wave = true;
|
2016-11-29 21:19:52 +01:00
|
|
|
|
|
|
|
|
/* GPU hang workaround. */
|
2017-01-25 02:47:15 +01:00
|
|
|
if (sscreen->b.family == CHIP_TONGA ||
|
|
|
|
|
sscreen->b.family == CHIP_FIJI ||
|
|
|
|
|
sscreen->b.family == CHIP_POLARIS10 ||
|
2017-05-05 17:05:05 +02:00
|
|
|
sscreen->b.family == CHIP_POLARIS11 ||
|
|
|
|
|
sscreen->b.family == CHIP_POLARIS12)
|
2016-11-29 21:19:52 +01:00
|
|
|
partial_vs_wave = true;
|
|
|
|
|
} else {
|
2016-04-12 20:28:46 +02:00
|
|
|
partial_vs_wave = true;
|
2016-11-29 21:19:52 +01:00
|
|
|
}
|
2016-04-12 20:28:46 +02:00
|
|
|
}
|
2015-02-22 18:06:34 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-15 16:32:03 +02:00
|
|
|
/* This is a hardware requirement. */
|
2017-01-25 02:47:15 +01:00
|
|
|
if (key->u.line_stipple_enabled ||
|
2017-10-07 18:10:26 +02:00
|
|
|
(sscreen->b.debug_flags & DBG(SWITCH_ON_EOP))) {
|
2014-08-15 16:32:03 +02:00
|
|
|
ia_switch_on_eop = true;
|
|
|
|
|
wd_switch_on_eop = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-25 02:47:15 +01:00
|
|
|
if (sscreen->b.chip_class >= CIK) {
|
2014-08-15 16:32:03 +02:00
|
|
|
/* WD_SWITCH_ON_EOP has no effect on GPUs with less than
|
|
|
|
|
* 4 shader engines. Set 1 to pass the assertion below.
|
2016-04-08 12:57:43 +02:00
|
|
|
* The other cases are hardware requirements.
|
|
|
|
|
*
|
|
|
|
|
* Polaris supports primitive restart with WD_SWITCH_ON_EOP=0
|
|
|
|
|
* for points, line strips, and tri strips.
|
|
|
|
|
*/
|
2017-01-25 02:47:15 +01:00
|
|
|
if (sscreen->b.info.max_se < 4 ||
|
|
|
|
|
key->u.prim == PIPE_PRIM_POLYGON ||
|
|
|
|
|
key->u.prim == PIPE_PRIM_LINE_LOOP ||
|
|
|
|
|
key->u.prim == PIPE_PRIM_TRIANGLE_FAN ||
|
|
|
|
|
key->u.prim == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY ||
|
|
|
|
|
(key->u.primitive_restart &&
|
|
|
|
|
(sscreen->b.family < CHIP_POLARIS10 ||
|
|
|
|
|
(key->u.prim != PIPE_PRIM_POINTS &&
|
|
|
|
|
key->u.prim != PIPE_PRIM_LINE_STRIP &&
|
|
|
|
|
key->u.prim != PIPE_PRIM_TRIANGLE_STRIP))) ||
|
|
|
|
|
key->u.count_from_stream_output)
|
2014-08-15 16:32:03 +02:00
|
|
|
wd_switch_on_eop = true;
|
|
|
|
|
|
|
|
|
|
/* Hawaii hangs if instancing is enabled and WD_SWITCH_ON_EOP is 0.
|
|
|
|
|
* We don't know that for indirect drawing, so treat it as
|
|
|
|
|
* always problematic. */
|
2017-01-25 02:47:15 +01:00
|
|
|
if (sscreen->b.family == CHIP_HAWAII &&
|
|
|
|
|
key->u.uses_instancing)
|
2014-08-15 16:32:03 +02:00
|
|
|
wd_switch_on_eop = true;
|
|
|
|
|
|
2016-06-03 16:20:17 +02:00
|
|
|
/* Performance recommendation for 4 SE Gfx7-8 parts if
|
2016-09-08 01:42:06 +02:00
|
|
|
* instances are smaller than a primgroup.
|
|
|
|
|
* Assume indirect draws always use small instances.
|
|
|
|
|
* This is needed for good VS wave utilization.
|
2016-06-03 16:20:17 +02:00
|
|
|
*/
|
2017-01-25 02:47:15 +01:00
|
|
|
if (sscreen->b.chip_class <= VI &&
|
|
|
|
|
sscreen->b.info.max_se == 4 &&
|
|
|
|
|
key->u.multi_instances_smaller_than_primgroup)
|
2016-06-03 16:20:17 +02:00
|
|
|
wd_switch_on_eop = true;
|
|
|
|
|
|
2015-10-18 21:43:30 +02:00
|
|
|
/* Required on CIK and later. */
|
2017-01-25 02:47:15 +01:00
|
|
|
if (sscreen->b.info.max_se > 2 && !wd_switch_on_eop)
|
2015-10-18 21:43:30 +02:00
|
|
|
ia_switch_on_eoi = true;
|
|
|
|
|
|
2015-10-18 22:07:01 +02:00
|
|
|
/* Required by Hawaii and, for some special cases, by VI. */
|
|
|
|
|
if (ia_switch_on_eoi &&
|
2017-01-25 02:47:15 +01:00
|
|
|
(sscreen->b.family == CHIP_HAWAII ||
|
|
|
|
|
(sscreen->b.chip_class == VI &&
|
|
|
|
|
(key->u.uses_gs || max_primgroup_in_wave != 2))))
|
2015-10-18 22:07:01 +02:00
|
|
|
partial_vs_wave = true;
|
|
|
|
|
|
2015-10-18 21:51:41 +02:00
|
|
|
/* Instancing bug on Bonaire. */
|
2017-01-25 02:47:15 +01:00
|
|
|
if (sscreen->b.family == CHIP_BONAIRE && ia_switch_on_eoi &&
|
|
|
|
|
key->u.uses_instancing)
|
2015-10-18 21:51:41 +02:00
|
|
|
partial_vs_wave = true;
|
|
|
|
|
|
2014-08-15 16:32:03 +02:00
|
|
|
/* If the WD switch is false, the IA switch must be false too. */
|
|
|
|
|
assert(wd_switch_on_eop || !ia_switch_on_eop);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-18 22:17:04 +02:00
|
|
|
/* If SWITCH_ON_EOI is set, PARTIAL_ES_WAVE must be set too. */
|
2017-04-23 20:29:04 +02:00
|
|
|
if (sscreen->b.chip_class <= VI && ia_switch_on_eoi)
|
2015-10-18 22:17:04 +02:00
|
|
|
partial_es_wave = true;
|
|
|
|
|
|
2014-08-15 16:32:03 +02:00
|
|
|
return S_028AA8_SWITCH_ON_EOP(ia_switch_on_eop) |
|
2015-02-22 18:06:34 +01:00
|
|
|
S_028AA8_SWITCH_ON_EOI(ia_switch_on_eoi) |
|
2014-08-15 22:45:10 +02:00
|
|
|
S_028AA8_PARTIAL_VS_WAVE_ON(partial_vs_wave) |
|
2015-02-22 18:06:34 +01:00
|
|
|
S_028AA8_PARTIAL_ES_WAVE_ON(partial_es_wave) |
|
2017-01-25 02:47:15 +01:00
|
|
|
S_028AA8_WD_SWITCH_ON_EOP(sscreen->b.chip_class >= CIK ? wd_switch_on_eop : 0) |
|
2017-04-23 20:14:42 +02:00
|
|
|
/* The following field was moved to VGT_SHADER_STAGES_EN in GFX9. */
|
|
|
|
|
S_028AA8_MAX_PRIMGRP_IN_WAVE(sscreen->b.chip_class == VI ?
|
2016-10-15 15:00:33 +02:00
|
|
|
max_primgroup_in_wave : 0) |
|
|
|
|
|
S_030960_EN_INST_OPT_BASIC(sscreen->b.chip_class >= GFX9) |
|
|
|
|
|
S_030960_EN_INST_OPT_ADV(sscreen->b.chip_class >= GFX9);
|
2014-08-15 16:32:03 +02:00
|
|
|
}
|
|
|
|
|
|
2017-01-25 02:47:15 +01:00
|
|
|
void si_init_ia_multi_vgt_param_table(struct si_context *sctx)
|
|
|
|
|
{
|
|
|
|
|
for (int prim = 0; prim <= R600_PRIM_RECTANGLE_LIST; prim++)
|
|
|
|
|
for (int uses_instancing = 0; uses_instancing < 2; uses_instancing++)
|
|
|
|
|
for (int multi_instances = 0; multi_instances < 2; multi_instances++)
|
|
|
|
|
for (int primitive_restart = 0; primitive_restart < 2; primitive_restart++)
|
|
|
|
|
for (int count_from_so = 0; count_from_so < 2; count_from_so++)
|
|
|
|
|
for (int line_stipple = 0; line_stipple < 2; line_stipple++)
|
|
|
|
|
for (int uses_tess = 0; uses_tess < 2; uses_tess++)
|
|
|
|
|
for (int tess_uses_primid = 0; tess_uses_primid < 2; tess_uses_primid++)
|
|
|
|
|
for (int uses_gs = 0; uses_gs < 2; uses_gs++) {
|
|
|
|
|
union si_vgt_param_key key;
|
|
|
|
|
|
|
|
|
|
key.index = 0;
|
|
|
|
|
key.u.prim = prim;
|
|
|
|
|
key.u.uses_instancing = uses_instancing;
|
|
|
|
|
key.u.multi_instances_smaller_than_primgroup = multi_instances;
|
|
|
|
|
key.u.primitive_restart = primitive_restart;
|
|
|
|
|
key.u.count_from_stream_output = count_from_so;
|
|
|
|
|
key.u.line_stipple_enabled = line_stipple;
|
|
|
|
|
key.u.uses_tess = uses_tess;
|
2017-05-15 11:13:44 +02:00
|
|
|
key.u.tess_uses_prim_id = tess_uses_primid;
|
2017-01-25 02:47:15 +01:00
|
|
|
key.u.uses_gs = uses_gs;
|
|
|
|
|
|
|
|
|
|
sctx->ia_multi_vgt_param[key.index] =
|
|
|
|
|
si_get_init_multi_vgt_param(sctx->screen, &key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned si_get_ia_multi_vgt_param(struct si_context *sctx,
|
|
|
|
|
const struct pipe_draw_info *info,
|
|
|
|
|
unsigned num_patches)
|
|
|
|
|
{
|
|
|
|
|
union si_vgt_param_key key = sctx->ia_multi_vgt_param_key;
|
|
|
|
|
unsigned primgroup_size;
|
|
|
|
|
unsigned ia_multi_vgt_param;
|
|
|
|
|
|
|
|
|
|
if (sctx->tes_shader.cso) {
|
|
|
|
|
primgroup_size = num_patches; /* must be a multiple of NUM_PATCHES */
|
|
|
|
|
} else if (sctx->gs_shader.cso) {
|
|
|
|
|
primgroup_size = 64; /* recommended with a GS */
|
|
|
|
|
} else {
|
|
|
|
|
primgroup_size = 128; /* recommended without a GS and tess */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
key.u.prim = info->mode;
|
|
|
|
|
key.u.uses_instancing = info->indirect || info->instance_count > 1;
|
|
|
|
|
key.u.multi_instances_smaller_than_primgroup =
|
|
|
|
|
info->indirect ||
|
|
|
|
|
(info->instance_count > 1 &&
|
2017-01-29 22:28:04 +01:00
|
|
|
(info->count_from_stream_output ||
|
|
|
|
|
si_num_prims_for_vertices(info) < primgroup_size));
|
2017-01-25 02:47:15 +01:00
|
|
|
key.u.primitive_restart = info->primitive_restart;
|
|
|
|
|
key.u.count_from_stream_output = info->count_from_stream_output != NULL;
|
|
|
|
|
|
|
|
|
|
ia_multi_vgt_param = sctx->ia_multi_vgt_param[key.index] |
|
|
|
|
|
S_028AA8_PRIMGROUP_SIZE(primgroup_size - 1);
|
|
|
|
|
|
|
|
|
|
if (sctx->gs_shader.cso) {
|
|
|
|
|
/* GS requirement. */
|
2017-04-19 03:21:16 +02:00
|
|
|
if (sctx->b.chip_class <= VI &&
|
|
|
|
|
SI_GS_PER_ES / primgroup_size >= sctx->screen->gs_table_depth - 3)
|
2017-01-25 02:47:15 +01:00
|
|
|
ia_multi_vgt_param |= S_028AA8_PARTIAL_ES_WAVE_ON(1);
|
|
|
|
|
|
|
|
|
|
/* GS hw bug with single-primitive instances and SWITCH_ON_EOI.
|
|
|
|
|
* The hw doc says all multi-SE chips are affected, but Vulkan
|
|
|
|
|
* only applies it to Hawaii. Do what Vulkan does.
|
|
|
|
|
*/
|
|
|
|
|
if (sctx->b.family == CHIP_HAWAII &&
|
|
|
|
|
G_028AA8_SWITCH_ON_EOI(ia_multi_vgt_param) &&
|
|
|
|
|
(info->indirect ||
|
|
|
|
|
(info->instance_count > 1 &&
|
2017-01-29 22:28:04 +01:00
|
|
|
(info->count_from_stream_output ||
|
|
|
|
|
si_num_prims_for_vertices(info) <= 1))))
|
2017-01-25 02:47:15 +01:00
|
|
|
sctx->b.flags |= SI_CONTEXT_VGT_FLUSH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ia_multi_vgt_param;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-31 20:09:46 +01:00
|
|
|
/* rast_prim is the primitive type after GS. */
|
2015-02-22 17:42:20 +01:00
|
|
|
static void si_emit_rasterizer_prim_state(struct si_context *sctx)
|
2014-12-07 16:40:09 +01:00
|
|
|
{
|
2015-11-07 14:00:30 +01:00
|
|
|
struct radeon_winsys_cs *cs = sctx->b.gfx.cs;
|
2017-09-26 17:57:59 +02:00
|
|
|
enum pipe_prim_type rast_prim = sctx->current_rast_prim;
|
2015-03-15 19:21:31 +01:00
|
|
|
struct si_state_rasterizer *rs = sctx->emitted.named.rasterizer;
|
2014-12-07 16:40:09 +01:00
|
|
|
|
2015-03-15 19:24:13 +01:00
|
|
|
/* Skip this if not rendering lines. */
|
|
|
|
|
if (rast_prim != PIPE_PRIM_LINES &&
|
|
|
|
|
rast_prim != PIPE_PRIM_LINE_LOOP &&
|
|
|
|
|
rast_prim != PIPE_PRIM_LINE_STRIP &&
|
|
|
|
|
rast_prim != PIPE_PRIM_LINES_ADJACENCY &&
|
|
|
|
|
rast_prim != PIPE_PRIM_LINE_STRIP_ADJACENCY)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-03-15 19:21:31 +01:00
|
|
|
if (rast_prim == sctx->last_rast_prim &&
|
|
|
|
|
rs->pa_sc_line_stipple == sctx->last_sc_line_stipple)
|
2014-12-08 13:35:36 +01:00
|
|
|
return;
|
|
|
|
|
|
2016-06-28 13:04:07 +02:00
|
|
|
/* For lines, reset the stipple pattern at each primitive. Otherwise,
|
|
|
|
|
* reset the stipple pattern at each packet (line strips, line loops).
|
|
|
|
|
*/
|
2015-08-30 01:54:00 +02:00
|
|
|
radeon_set_context_reg(cs, R_028A0C_PA_SC_LINE_STIPPLE,
|
2015-03-15 19:21:31 +01:00
|
|
|
rs->pa_sc_line_stipple |
|
2016-06-28 13:04:07 +02:00
|
|
|
S_028A0C_AUTO_RESET_CNTL(rast_prim == PIPE_PRIM_LINES ? 1 : 2));
|
2014-12-07 16:40:09 +01:00
|
|
|
|
2015-01-31 20:09:46 +01:00
|
|
|
sctx->last_rast_prim = rast_prim;
|
2015-03-15 19:21:31 +01:00
|
|
|
sctx->last_sc_line_stipple = rs->pa_sc_line_stipple;
|
2014-12-07 16:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-12 11:01:19 +02:00
|
|
|
static void si_emit_vs_state(struct si_context *sctx,
|
|
|
|
|
const struct pipe_draw_info *info)
|
2017-04-12 10:00:18 +02:00
|
|
|
{
|
2017-04-12 11:01:19 +02:00
|
|
|
sctx->current_vs_state &= C_VS_STATE_INDEXED;
|
2017-04-02 16:24:39 +02:00
|
|
|
sctx->current_vs_state |= S_VS_STATE_INDEXED(!!info->index_size);
|
2017-04-12 11:01:19 +02:00
|
|
|
|
2017-10-05 20:28:29 +02:00
|
|
|
if (sctx->num_vs_blit_sgprs) {
|
|
|
|
|
/* Re-emit the state after we leave u_blitter. */
|
|
|
|
|
sctx->last_vs_state = ~0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-12 10:00:18 +02:00
|
|
|
if (sctx->current_vs_state != sctx->last_vs_state) {
|
|
|
|
|
struct radeon_winsys_cs *cs = sctx->b.gfx.cs;
|
|
|
|
|
|
|
|
|
|
radeon_set_sh_reg(cs,
|
2017-08-04 03:26:38 +02:00
|
|
|
sctx->shader_pointers.sh_base[PIPE_SHADER_VERTEX] +
|
2017-04-12 10:46:22 +02:00
|
|
|
SI_SGPR_VS_STATE_BITS * 4,
|
2017-04-12 10:00:18 +02:00
|
|
|
sctx->current_vs_state);
|
|
|
|
|
|
|
|
|
|
sctx->last_vs_state = sctx->current_vs_state;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-07 16:40:09 +01:00
|
|
|
static void si_emit_draw_registers(struct si_context *sctx,
|
2017-04-12 09:40:28 +02:00
|
|
|
const struct pipe_draw_info *info,
|
|
|
|
|
unsigned num_patches)
|
2014-12-07 16:40:09 +01:00
|
|
|
{
|
2015-11-07 14:00:30 +01:00
|
|
|
struct radeon_winsys_cs *cs = sctx->b.gfx.cs;
|
2014-12-07 16:40:09 +01:00
|
|
|
unsigned prim = si_conv_pipe_prim(info->mode);
|
2017-09-26 17:57:59 +02:00
|
|
|
unsigned gs_out_prim = si_conv_prim_to_gs_out(sctx->current_rast_prim);
|
2017-04-12 09:40:28 +02:00
|
|
|
unsigned ia_multi_vgt_param;
|
2015-02-22 18:01:18 +01:00
|
|
|
|
2015-02-22 18:06:34 +01:00
|
|
|
ia_multi_vgt_param = si_get_ia_multi_vgt_param(sctx, info, num_patches);
|
|
|
|
|
|
2014-12-07 16:40:09 +01:00
|
|
|
/* Draw state. */
|
2016-09-30 22:47:20 +02:00
|
|
|
if (ia_multi_vgt_param != sctx->last_multi_vgt_param) {
|
2016-10-15 15:00:33 +02:00
|
|
|
if (sctx->b.chip_class >= GFX9)
|
|
|
|
|
radeon_set_uconfig_reg_idx(cs, R_030960_IA_MULTI_VGT_PARAM, 4, ia_multi_vgt_param);
|
|
|
|
|
else if (sctx->b.chip_class >= CIK)
|
2016-06-24 01:11:09 +02:00
|
|
|
radeon_set_context_reg_idx(cs, R_028AA8_IA_MULTI_VGT_PARAM, 1, ia_multi_vgt_param);
|
2016-09-30 22:47:20 +02:00
|
|
|
else
|
|
|
|
|
radeon_set_context_reg(cs, R_028AA8_IA_MULTI_VGT_PARAM, ia_multi_vgt_param);
|
|
|
|
|
|
|
|
|
|
sctx->last_multi_vgt_param = ia_multi_vgt_param;
|
|
|
|
|
}
|
|
|
|
|
if (prim != sctx->last_prim) {
|
|
|
|
|
if (sctx->b.chip_class >= CIK)
|
2016-06-24 01:11:09 +02:00
|
|
|
radeon_set_uconfig_reg_idx(cs, R_030908_VGT_PRIMITIVE_TYPE, 1, prim);
|
2016-09-30 22:47:20 +02:00
|
|
|
else
|
2015-08-30 01:54:00 +02:00
|
|
|
radeon_set_config_reg(cs, R_008958_VGT_PRIMITIVE_TYPE, prim);
|
2016-06-24 01:11:09 +02:00
|
|
|
|
2014-12-07 20:23:56 +01:00
|
|
|
sctx->last_prim = prim;
|
2014-12-07 16:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-07 20:15:49 +01:00
|
|
|
if (gs_out_prim != sctx->last_gs_out_prim) {
|
2015-08-30 01:54:00 +02:00
|
|
|
radeon_set_context_reg(cs, R_028A6C_VGT_GS_OUT_PRIM_TYPE, gs_out_prim);
|
2014-12-07 20:15:49 +01:00
|
|
|
sctx->last_gs_out_prim = gs_out_prim;
|
|
|
|
|
}
|
2014-12-07 20:14:41 +01:00
|
|
|
|
|
|
|
|
/* Primitive restart. */
|
|
|
|
|
if (info->primitive_restart != sctx->last_primitive_restart_en) {
|
2016-10-15 15:00:33 +02:00
|
|
|
if (sctx->b.chip_class >= GFX9)
|
|
|
|
|
radeon_set_uconfig_reg(cs, R_03092C_VGT_MULTI_PRIM_IB_RESET_EN,
|
|
|
|
|
info->primitive_restart);
|
|
|
|
|
else
|
|
|
|
|
radeon_set_context_reg(cs, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN,
|
|
|
|
|
info->primitive_restart);
|
|
|
|
|
|
2014-12-07 20:14:41 +01:00
|
|
|
sctx->last_primitive_restart_en = info->primitive_restart;
|
|
|
|
|
|
2016-10-04 14:30:11 +01:00
|
|
|
}
|
|
|
|
|
if (info->primitive_restart &&
|
|
|
|
|
(info->restart_index != sctx->last_restart_index ||
|
|
|
|
|
sctx->last_restart_index == SI_RESTART_INDEX_UNKNOWN)) {
|
|
|
|
|
radeon_set_context_reg(cs, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX,
|
|
|
|
|
info->restart_index);
|
|
|
|
|
sctx->last_restart_index = info->restart_index;
|
2014-12-07 20:14:41 +01:00
|
|
|
}
|
2014-12-07 16:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-07 15:52:15 +01:00
|
|
|
static void si_emit_draw_packets(struct si_context *sctx,
|
|
|
|
|
const struct pipe_draw_info *info,
|
2017-04-02 16:24:39 +02:00
|
|
|
struct pipe_resource *indexbuf,
|
|
|
|
|
unsigned index_size,
|
|
|
|
|
unsigned index_offset)
|
2012-08-03 10:26:01 +02:00
|
|
|
{
|
2017-04-02 15:24:19 +02:00
|
|
|
struct pipe_draw_indirect_info *indirect = info->indirect;
|
2015-11-07 14:00:30 +01:00
|
|
|
struct radeon_winsys_cs *cs = sctx->b.gfx.cs;
|
2017-08-04 03:26:38 +02:00
|
|
|
unsigned sh_base_reg = sctx->shader_pointers.sh_base[PIPE_SHADER_VERTEX];
|
2015-11-07 16:30:01 +01:00
|
|
|
bool render_cond_bit = sctx->b.render_cond && !sctx->b.render_cond_force_off;
|
2016-07-29 17:56:21 +01:00
|
|
|
uint32_t index_max_size = 0;
|
|
|
|
|
uint64_t index_va = 0;
|
2012-08-03 10:26:01 +02:00
|
|
|
|
2013-08-26 18:17:09 +02:00
|
|
|
if (info->count_from_stream_output) {
|
2017-10-07 22:54:31 +02:00
|
|
|
struct si_streamout_target *t =
|
|
|
|
|
(struct si_streamout_target*)info->count_from_stream_output;
|
2014-08-06 22:29:27 +02:00
|
|
|
uint64_t va = t->buf_filled_size->gpu_address +
|
|
|
|
|
t->buf_filled_size_offset;
|
2013-08-26 18:17:09 +02:00
|
|
|
|
2015-08-30 01:54:00 +02:00
|
|
|
radeon_set_context_reg(cs, R_028B30_VGT_STRMOUT_DRAW_OPAQUE_VERTEX_STRIDE,
|
2014-12-07 15:52:15 +01:00
|
|
|
t->stride_in_dw);
|
|
|
|
|
|
|
|
|
|
radeon_emit(cs, PKT3(PKT3_COPY_DATA, 4, 0));
|
|
|
|
|
radeon_emit(cs, COPY_DATA_SRC_SEL(COPY_DATA_MEM) |
|
|
|
|
|
COPY_DATA_DST_SEL(COPY_DATA_REG) |
|
|
|
|
|
COPY_DATA_WR_CONFIRM);
|
|
|
|
|
radeon_emit(cs, va); /* src address lo */
|
|
|
|
|
radeon_emit(cs, va >> 32); /* src address hi */
|
|
|
|
|
radeon_emit(cs, R_028B2C_VGT_STRMOUT_DRAW_OPAQUE_BUFFER_FILLED_SIZE >> 2);
|
|
|
|
|
radeon_emit(cs, 0); /* unused */
|
|
|
|
|
|
2015-11-07 14:00:30 +01:00
|
|
|
radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx,
|
2014-12-07 15:52:15 +01:00
|
|
|
t->buf_filled_size, RADEON_USAGE_READ,
|
2015-09-26 23:18:55 +02:00
|
|
|
RADEON_PRIO_SO_FILLED_SIZE);
|
2013-08-26 18:17:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-03 10:26:01 +02:00
|
|
|
/* draw packet */
|
2017-04-02 16:24:39 +02:00
|
|
|
if (index_size) {
|
|
|
|
|
if (index_size != sctx->last_index_size) {
|
2016-10-15 15:00:33 +02:00
|
|
|
unsigned index_type;
|
2016-09-06 00:35:12 +02:00
|
|
|
|
|
|
|
|
/* index type */
|
2017-04-02 16:24:39 +02:00
|
|
|
switch (index_size) {
|
2016-09-06 00:35:12 +02:00
|
|
|
case 1:
|
2016-10-15 15:00:33 +02:00
|
|
|
index_type = V_028A7C_VGT_INDEX_8;
|
2016-09-06 00:35:12 +02:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2016-10-15 15:00:33 +02:00
|
|
|
index_type = V_028A7C_VGT_INDEX_16 |
|
|
|
|
|
(SI_BIG_ENDIAN && sctx->b.chip_class <= CIK ?
|
|
|
|
|
V_028A7C_VGT_DMA_SWAP_16_BIT : 0);
|
2016-09-06 00:35:12 +02:00
|
|
|
break;
|
|
|
|
|
case 4:
|
2016-10-15 15:00:33 +02:00
|
|
|
index_type = V_028A7C_VGT_INDEX_32 |
|
|
|
|
|
(SI_BIG_ENDIAN && sctx->b.chip_class <= CIK ?
|
|
|
|
|
V_028A7C_VGT_DMA_SWAP_32_BIT : 0);
|
2016-09-06 00:35:12 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"unreachable");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-15 15:00:33 +02:00
|
|
|
if (sctx->b.chip_class >= GFX9) {
|
|
|
|
|
radeon_set_uconfig_reg_idx(cs, R_03090C_VGT_INDEX_TYPE,
|
|
|
|
|
2, index_type);
|
|
|
|
|
} else {
|
|
|
|
|
radeon_emit(cs, PKT3(PKT3_INDEX_TYPE, 0, 0));
|
|
|
|
|
radeon_emit(cs, index_type);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
sctx->last_index_size = index_size;
|
2014-12-07 15:52:15 +01:00
|
|
|
}
|
2016-07-29 17:56:21 +01:00
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
index_max_size = (indexbuf->width0 - index_offset) /
|
|
|
|
|
index_size;
|
|
|
|
|
index_va = r600_resource(indexbuf)->gpu_address + index_offset;
|
2016-07-29 17:56:21 +01:00
|
|
|
|
|
|
|
|
radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx,
|
2017-04-02 16:24:39 +02:00
|
|
|
(struct r600_resource *)indexbuf,
|
2016-07-29 17:56:21 +01:00
|
|
|
RADEON_USAGE_READ, RADEON_PRIO_INDEX_BUFFER);
|
2016-09-06 00:35:12 +02:00
|
|
|
} else {
|
|
|
|
|
/* On CI and later, non-indexed draws overwrite VGT_INDEX_TYPE,
|
|
|
|
|
* so the state must be re-emitted before the next indexed draw.
|
|
|
|
|
*/
|
|
|
|
|
if (sctx->b.chip_class >= CIK)
|
|
|
|
|
sctx->last_index_size = -1;
|
2012-08-03 10:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-02 15:24:19 +02:00
|
|
|
if (indirect) {
|
|
|
|
|
uint64_t indirect_va = r600_resource(indirect->buffer)->gpu_address;
|
2016-07-29 17:51:23 +01:00
|
|
|
|
|
|
|
|
assert(indirect_va % 8 == 0);
|
|
|
|
|
|
2014-12-07 20:04:40 +01:00
|
|
|
si_invalidate_draw_sh_constants(sctx);
|
|
|
|
|
|
2016-07-29 17:51:23 +01:00
|
|
|
radeon_emit(cs, PKT3(PKT3_SET_BASE, 2, 0));
|
|
|
|
|
radeon_emit(cs, 1);
|
|
|
|
|
radeon_emit(cs, indirect_va);
|
|
|
|
|
radeon_emit(cs, indirect_va >> 32);
|
|
|
|
|
|
2015-11-07 14:00:30 +01:00
|
|
|
radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx,
|
2017-04-02 15:24:19 +02:00
|
|
|
(struct r600_resource *)indirect->buffer,
|
2015-09-26 23:18:55 +02:00
|
|
|
RADEON_USAGE_READ, RADEON_PRIO_DRAW_INDIRECT);
|
2014-04-23 16:15:36 +02:00
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
unsigned di_src_sel = index_size ? V_0287F0_DI_SRC_SEL_DMA
|
2016-07-29 18:05:30 +01:00
|
|
|
: V_0287F0_DI_SRC_SEL_AUTO_INDEX;
|
|
|
|
|
|
2017-04-02 15:24:19 +02:00
|
|
|
assert(indirect->offset % 4 == 0);
|
2014-12-07 15:52:15 +01:00
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
if (index_size) {
|
2014-12-07 15:52:15 +01:00
|
|
|
radeon_emit(cs, PKT3(PKT3_INDEX_BASE, 1, 0));
|
|
|
|
|
radeon_emit(cs, index_va);
|
|
|
|
|
radeon_emit(cs, index_va >> 32);
|
|
|
|
|
|
|
|
|
|
radeon_emit(cs, PKT3(PKT3_INDEX_BUFFER_SIZE, 0, 0));
|
|
|
|
|
radeon_emit(cs, index_max_size);
|
2016-07-29 18:05:30 +01:00
|
|
|
}
|
2014-12-07 15:52:15 +01:00
|
|
|
|
2016-07-29 17:59:11 +01:00
|
|
|
if (!sctx->screen->has_draw_indirect_multi) {
|
2017-04-02 16:24:39 +02:00
|
|
|
radeon_emit(cs, PKT3(index_size ? PKT3_DRAW_INDEX_INDIRECT
|
2016-07-29 18:05:30 +01:00
|
|
|
: PKT3_DRAW_INDIRECT,
|
|
|
|
|
3, render_cond_bit));
|
2017-04-02 15:24:19 +02:00
|
|
|
radeon_emit(cs, indirect->offset);
|
2016-07-29 18:05:30 +01:00
|
|
|
radeon_emit(cs, (sh_base_reg + SI_SGPR_BASE_VERTEX * 4 - SI_SH_REG_OFFSET) >> 2);
|
|
|
|
|
radeon_emit(cs, (sh_base_reg + SI_SGPR_START_INSTANCE * 4 - SI_SH_REG_OFFSET) >> 2);
|
|
|
|
|
radeon_emit(cs, di_src_sel);
|
2014-04-24 03:03:43 +02:00
|
|
|
} else {
|
2016-08-08 16:00:29 +02:00
|
|
|
uint64_t count_va = 0;
|
|
|
|
|
|
2017-04-02 15:24:19 +02:00
|
|
|
if (indirect->indirect_draw_count) {
|
2016-08-08 16:00:29 +02:00
|
|
|
struct r600_resource *params_buf =
|
2017-04-02 15:24:19 +02:00
|
|
|
(struct r600_resource *)indirect->indirect_draw_count;
|
2016-08-08 16:00:29 +02:00
|
|
|
|
|
|
|
|
radeon_add_to_buffer_list(
|
|
|
|
|
&sctx->b, &sctx->b.gfx, params_buf,
|
|
|
|
|
RADEON_USAGE_READ, RADEON_PRIO_DRAW_INDIRECT);
|
|
|
|
|
|
2017-04-02 15:24:19 +02:00
|
|
|
count_va = params_buf->gpu_address + indirect->indirect_draw_count_offset;
|
2016-08-08 16:00:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
radeon_emit(cs, PKT3(index_size ? PKT3_DRAW_INDEX_INDIRECT_MULTI :
|
2016-07-29 18:05:30 +01:00
|
|
|
PKT3_DRAW_INDIRECT_MULTI,
|
|
|
|
|
8, render_cond_bit));
|
2017-04-02 15:24:19 +02:00
|
|
|
radeon_emit(cs, indirect->offset);
|
2016-07-29 18:05:30 +01:00
|
|
|
radeon_emit(cs, (sh_base_reg + SI_SGPR_BASE_VERTEX * 4 - SI_SH_REG_OFFSET) >> 2);
|
|
|
|
|
radeon_emit(cs, (sh_base_reg + SI_SGPR_START_INSTANCE * 4 - SI_SH_REG_OFFSET) >> 2);
|
2016-08-08 15:54:50 +02:00
|
|
|
radeon_emit(cs, ((sh_base_reg + SI_SGPR_DRAWID * 4 - SI_SH_REG_OFFSET) >> 2) |
|
2016-08-08 16:00:29 +02:00
|
|
|
S_2C3_DRAW_INDEX_ENABLE(1) |
|
2017-04-02 15:24:19 +02:00
|
|
|
S_2C3_COUNT_INDIRECT_ENABLE(!!indirect->indirect_draw_count));
|
|
|
|
|
radeon_emit(cs, indirect->draw_count);
|
2016-08-08 16:00:29 +02:00
|
|
|
radeon_emit(cs, count_va);
|
|
|
|
|
radeon_emit(cs, count_va >> 32);
|
2017-04-02 15:24:19 +02:00
|
|
|
radeon_emit(cs, indirect->stride);
|
2016-07-29 18:05:30 +01:00
|
|
|
radeon_emit(cs, di_src_sel);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-04-02 15:27:02 +02:00
|
|
|
int base_vertex;
|
|
|
|
|
|
|
|
|
|
radeon_emit(cs, PKT3(PKT3_NUM_INSTANCES, 0, 0));
|
|
|
|
|
radeon_emit(cs, info->instance_count);
|
|
|
|
|
|
|
|
|
|
/* Base vertex and start instance. */
|
2017-04-02 16:24:39 +02:00
|
|
|
base_vertex = index_size ? info->index_bias : info->start;
|
2017-04-02 15:27:02 +02:00
|
|
|
|
2017-10-05 20:28:29 +02:00
|
|
|
if (sctx->num_vs_blit_sgprs) {
|
|
|
|
|
/* Re-emit draw constants after we leave u_blitter. */
|
|
|
|
|
si_invalidate_draw_sh_constants(sctx);
|
|
|
|
|
|
|
|
|
|
/* Blit VS doesn't use BASE_VERTEX, START_INSTANCE, and DRAWID. */
|
|
|
|
|
radeon_set_sh_reg_seq(cs, sh_base_reg + SI_SGPR_VS_BLIT_DATA * 4,
|
|
|
|
|
sctx->num_vs_blit_sgprs);
|
|
|
|
|
radeon_emit_array(cs, sctx->vs_blit_sh_data,
|
|
|
|
|
sctx->num_vs_blit_sgprs);
|
|
|
|
|
} else if (base_vertex != sctx->last_base_vertex ||
|
|
|
|
|
sctx->last_base_vertex == SI_BASE_VERTEX_UNKNOWN ||
|
|
|
|
|
info->start_instance != sctx->last_start_instance ||
|
|
|
|
|
info->drawid != sctx->last_drawid ||
|
|
|
|
|
sh_base_reg != sctx->last_sh_base_reg) {
|
2017-04-02 15:27:02 +02:00
|
|
|
radeon_set_sh_reg_seq(cs, sh_base_reg + SI_SGPR_BASE_VERTEX * 4, 3);
|
|
|
|
|
radeon_emit(cs, base_vertex);
|
|
|
|
|
radeon_emit(cs, info->start_instance);
|
|
|
|
|
radeon_emit(cs, info->drawid);
|
|
|
|
|
|
|
|
|
|
sctx->last_base_vertex = base_vertex;
|
|
|
|
|
sctx->last_start_instance = info->start_instance;
|
|
|
|
|
sctx->last_drawid = info->drawid;
|
|
|
|
|
sctx->last_sh_base_reg = sh_base_reg;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
if (index_size) {
|
|
|
|
|
index_va += info->start * index_size;
|
2014-12-07 15:52:15 +01:00
|
|
|
|
2015-11-07 14:45:58 +01:00
|
|
|
radeon_emit(cs, PKT3(PKT3_DRAW_INDEX_2, 4, render_cond_bit));
|
2014-12-07 15:52:15 +01:00
|
|
|
radeon_emit(cs, index_max_size);
|
|
|
|
|
radeon_emit(cs, index_va);
|
2016-10-15 15:00:33 +02:00
|
|
|
radeon_emit(cs, index_va >> 32);
|
2014-12-07 15:52:15 +01:00
|
|
|
radeon_emit(cs, info->count);
|
|
|
|
|
radeon_emit(cs, V_0287F0_DI_SRC_SEL_DMA);
|
2014-04-24 03:03:43 +02:00
|
|
|
} else {
|
2015-11-07 14:45:58 +01:00
|
|
|
radeon_emit(cs, PKT3(PKT3_DRAW_INDEX_AUTO, 1, render_cond_bit));
|
2014-12-07 15:52:15 +01:00
|
|
|
radeon_emit(cs, info->count);
|
|
|
|
|
radeon_emit(cs, V_0287F0_DI_SRC_SEL_AUTO_INDEX |
|
2016-07-29 18:05:30 +01:00
|
|
|
S_0287F0_USE_OPAQUE(!!info->count_from_stream_output));
|
2014-04-24 03:03:43 +02:00
|
|
|
}
|
2012-08-03 10:26:01 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 18:49:22 +02:00
|
|
|
static void si_emit_surface_sync(struct r600_common_context *rctx,
|
|
|
|
|
unsigned cp_coher_cntl)
|
|
|
|
|
{
|
|
|
|
|
struct radeon_winsys_cs *cs = rctx->gfx.cs;
|
|
|
|
|
|
2016-10-15 16:09:26 +02:00
|
|
|
if (rctx->chip_class >= GFX9) {
|
|
|
|
|
/* Flush caches and wait for the caches to assert idle. */
|
|
|
|
|
radeon_emit(cs, PKT3(PKT3_ACQUIRE_MEM, 5, 0));
|
|
|
|
|
radeon_emit(cs, cp_coher_cntl); /* CP_COHER_CNTL */
|
|
|
|
|
radeon_emit(cs, 0xffffffff); /* CP_COHER_SIZE */
|
|
|
|
|
radeon_emit(cs, 0xffffff); /* CP_COHER_SIZE_HI */
|
|
|
|
|
radeon_emit(cs, 0); /* CP_COHER_BASE */
|
|
|
|
|
radeon_emit(cs, 0); /* CP_COHER_BASE_HI */
|
|
|
|
|
radeon_emit(cs, 0x0000000A); /* POLL_INTERVAL */
|
|
|
|
|
} else {
|
|
|
|
|
/* ACQUIRE_MEM is only required on a compute ring. */
|
|
|
|
|
radeon_emit(cs, PKT3(PKT3_SURFACE_SYNC, 3, 0));
|
|
|
|
|
radeon_emit(cs, cp_coher_cntl); /* CP_COHER_CNTL */
|
|
|
|
|
radeon_emit(cs, 0xffffffff); /* CP_COHER_SIZE */
|
|
|
|
|
radeon_emit(cs, 0); /* CP_COHER_BASE */
|
|
|
|
|
radeon_emit(cs, 0x0000000A); /* POLL_INTERVAL */
|
|
|
|
|
}
|
2016-10-10 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-08 00:59:55 +02:00
|
|
|
void si_emit_cache_flush(struct si_context *sctx)
|
radeonsi: simplify and improve flushing
This mimics r600g. The R600_CONTEXT_xxx flags are added to rctx->b.flags
and si_emit_cache_flush emits the packets. That's it. The shared radeon code
tells us when the streamout cache should be flushed, so we have to check
the flags anyway.
There is a new atom "cache_flush", because caches must be flushed *after*
resource descriptors are changed in memory.
Functional changes:
* Write caches are flushed at the end of CS and read caches are flushed
at its beginning.
* Sampler view states are removed from si_state, they only held the flush
flags.
* Everytime a shader is changed, the I cache is flushed. Is this needed?
Due to a hw bug, this also flushes the K cache.
* The WRITE_DATA packet is changed to use TC, which fixes a rendering issue
in openarena. I'm not sure how TC interacts with CP DMA, but for now it
seems to work better than any other solution I tried. (BTW CIK allows us
to use TC for CP DMA.)
* Flush the K cache instead of the texture cache when updating resource
descriptors (due to a hw bug, this also flushes the I cache).
I think the K cache flush is correct here, but I'm not sure if the texture
cache should be flushed too (probably not considering we use TC
for WRITE_DATA, but we don't use TC for CP DMA).
* The number of resource contexts is decreased to 16. With all of these cache
changes, 4 doesn't work, but 8 works, which suggests I'm actually doing
the right thing here and the pipeline isn't drained during flushes.
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Tested-by: Tom Stellard <thomas.stellard@amd.com>
2013-08-26 17:19:39 +02:00
|
|
|
{
|
2016-08-25 14:08:24 +02:00
|
|
|
struct r600_common_context *rctx = &sctx->b;
|
|
|
|
|
struct radeon_winsys_cs *cs = rctx->gfx.cs;
|
radeonsi: simplify and improve flushing
This mimics r600g. The R600_CONTEXT_xxx flags are added to rctx->b.flags
and si_emit_cache_flush emits the packets. That's it. The shared radeon code
tells us when the streamout cache should be flushed, so we have to check
the flags anyway.
There is a new atom "cache_flush", because caches must be flushed *after*
resource descriptors are changed in memory.
Functional changes:
* Write caches are flushed at the end of CS and read caches are flushed
at its beginning.
* Sampler view states are removed from si_state, they only held the flush
flags.
* Everytime a shader is changed, the I cache is flushed. Is this needed?
Due to a hw bug, this also flushes the K cache.
* The WRITE_DATA packet is changed to use TC, which fixes a rendering issue
in openarena. I'm not sure how TC interacts with CP DMA, but for now it
seems to work better than any other solution I tried. (BTW CIK allows us
to use TC for CP DMA.)
* Flush the K cache instead of the texture cache when updating resource
descriptors (due to a hw bug, this also flushes the I cache).
I think the K cache flush is correct here, but I'm not sure if the texture
cache should be flushed too (probably not considering we use TC
for WRITE_DATA, but we don't use TC for CP DMA).
* The number of resource contexts is decreased to 16. With all of these cache
changes, 4 doesn't work, but 8 works, which suggests I'm actually doing
the right thing here and the pipeline isn't drained during flushes.
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Tested-by: Tom Stellard <thomas.stellard@amd.com>
2013-08-26 17:19:39 +02:00
|
|
|
uint32_t cp_coher_cntl = 0;
|
2016-10-15 16:21:20 +02:00
|
|
|
uint32_t flush_cb_db = rctx->flags & (SI_CONTEXT_FLUSH_AND_INV_CB |
|
|
|
|
|
SI_CONTEXT_FLUSH_AND_INV_DB);
|
radeonsi: simplify and improve flushing
This mimics r600g. The R600_CONTEXT_xxx flags are added to rctx->b.flags
and si_emit_cache_flush emits the packets. That's it. The shared radeon code
tells us when the streamout cache should be flushed, so we have to check
the flags anyway.
There is a new atom "cache_flush", because caches must be flushed *after*
resource descriptors are changed in memory.
Functional changes:
* Write caches are flushed at the end of CS and read caches are flushed
at its beginning.
* Sampler view states are removed from si_state, they only held the flush
flags.
* Everytime a shader is changed, the I cache is flushed. Is this needed?
Due to a hw bug, this also flushes the K cache.
* The WRITE_DATA packet is changed to use TC, which fixes a rendering issue
in openarena. I'm not sure how TC interacts with CP DMA, but for now it
seems to work better than any other solution I tried. (BTW CIK allows us
to use TC for CP DMA.)
* Flush the K cache instead of the texture cache when updating resource
descriptors (due to a hw bug, this also flushes the I cache).
I think the K cache flush is correct here, but I'm not sure if the texture
cache should be flushed too (probably not considering we use TC
for WRITE_DATA, but we don't use TC for CP DMA).
* The number of resource contexts is decreased to 16. With all of these cache
changes, 4 doesn't work, but 8 works, which suggests I'm actually doing
the right thing here and the pipeline isn't drained during flushes.
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Tested-by: Tom Stellard <thomas.stellard@amd.com>
2013-08-26 17:19:39 +02:00
|
|
|
|
2017-06-15 00:29:41 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_FLUSH_AND_INV_CB)
|
|
|
|
|
sctx->b.num_cb_cache_flushes++;
|
|
|
|
|
if (rctx->flags & SI_CONTEXT_FLUSH_AND_INV_DB)
|
|
|
|
|
sctx->b.num_db_cache_flushes++;
|
2016-12-25 19:48:55 +01:00
|
|
|
|
2014-12-28 23:11:38 +01:00
|
|
|
/* SI has a bug that it always flushes ICACHE and KCACHE if either
|
2015-02-19 13:03:54 +01:00
|
|
|
* bit is set. An alternative way is to write SQC_CACHES, but that
|
|
|
|
|
* doesn't seem to work reliably. Since the bug doesn't affect
|
|
|
|
|
* correctness (it only does more work than necessary) and
|
|
|
|
|
* the performance impact is likely negligible, there is no plan
|
2016-04-17 15:34:24 +02:00
|
|
|
* to add a workaround for it.
|
2015-02-19 13:03:54 +01:00
|
|
|
*/
|
|
|
|
|
|
2016-08-25 14:08:24 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_INV_ICACHE)
|
2015-02-19 13:03:54 +01:00
|
|
|
cp_coher_cntl |= S_0085F0_SH_ICACHE_ACTION_ENA(1);
|
2016-08-25 14:08:24 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_INV_SMEM_L1)
|
2015-02-19 13:03:54 +01:00
|
|
|
cp_coher_cntl |= S_0085F0_SH_KCACHE_ACTION_ENA(1);
|
2014-12-29 14:02:46 +01:00
|
|
|
|
2016-10-15 16:21:20 +02:00
|
|
|
if (rctx->chip_class <= VI) {
|
|
|
|
|
if (rctx->flags & SI_CONTEXT_FLUSH_AND_INV_CB) {
|
|
|
|
|
cp_coher_cntl |= S_0085F0_CB_ACTION_ENA(1) |
|
|
|
|
|
S_0085F0_CB0_DEST_BASE_ENA(1) |
|
|
|
|
|
S_0085F0_CB1_DEST_BASE_ENA(1) |
|
|
|
|
|
S_0085F0_CB2_DEST_BASE_ENA(1) |
|
|
|
|
|
S_0085F0_CB3_DEST_BASE_ENA(1) |
|
|
|
|
|
S_0085F0_CB4_DEST_BASE_ENA(1) |
|
|
|
|
|
S_0085F0_CB5_DEST_BASE_ENA(1) |
|
|
|
|
|
S_0085F0_CB6_DEST_BASE_ENA(1) |
|
|
|
|
|
S_0085F0_CB7_DEST_BASE_ENA(1);
|
|
|
|
|
|
|
|
|
|
/* Necessary for DCC */
|
|
|
|
|
if (rctx->chip_class == VI)
|
2017-09-13 02:26:26 +02:00
|
|
|
si_gfx_write_event_eop(rctx, V_028A90_FLUSH_AND_INV_CB_DATA_TS,
|
2017-08-18 21:14:01 +02:00
|
|
|
0, EOP_DATA_SEL_DISCARD, NULL,
|
|
|
|
|
0, 0, R600_NOT_QUERY);
|
2016-10-15 16:21:20 +02:00
|
|
|
}
|
|
|
|
|
if (rctx->flags & SI_CONTEXT_FLUSH_AND_INV_DB)
|
|
|
|
|
cp_coher_cntl |= S_0085F0_DB_ACTION_ENA(1) |
|
|
|
|
|
S_0085F0_DB_DEST_BASE_ENA(1);
|
|
|
|
|
}
|
2017-02-08 03:01:32 +01:00
|
|
|
|
2016-10-15 16:21:20 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_FLUSH_AND_INV_CB) {
|
2017-02-08 03:01:32 +01:00
|
|
|
/* Flush CMASK/FMASK/DCC. SURFACE_SYNC will wait for idle. */
|
|
|
|
|
radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
|
|
|
|
|
radeon_emit(cs, EVENT_TYPE(V_028A90_FLUSH_AND_INV_CB_META) | EVENT_INDEX(0));
|
radeonsi: simplify and improve flushing
This mimics r600g. The R600_CONTEXT_xxx flags are added to rctx->b.flags
and si_emit_cache_flush emits the packets. That's it. The shared radeon code
tells us when the streamout cache should be flushed, so we have to check
the flags anyway.
There is a new atom "cache_flush", because caches must be flushed *after*
resource descriptors are changed in memory.
Functional changes:
* Write caches are flushed at the end of CS and read caches are flushed
at its beginning.
* Sampler view states are removed from si_state, they only held the flush
flags.
* Everytime a shader is changed, the I cache is flushed. Is this needed?
Due to a hw bug, this also flushes the K cache.
* The WRITE_DATA packet is changed to use TC, which fixes a rendering issue
in openarena. I'm not sure how TC interacts with CP DMA, but for now it
seems to work better than any other solution I tried. (BTW CIK allows us
to use TC for CP DMA.)
* Flush the K cache instead of the texture cache when updating resource
descriptors (due to a hw bug, this also flushes the I cache).
I think the K cache flush is correct here, but I'm not sure if the texture
cache should be flushed too (probably not considering we use TC
for WRITE_DATA, but we don't use TC for CP DMA).
* The number of resource contexts is decreased to 16. With all of these cache
changes, 4 doesn't work, but 8 works, which suggests I'm actually doing
the right thing here and the pipeline isn't drained during flushes.
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Tested-by: Tom Stellard <thomas.stellard@amd.com>
2013-08-26 17:19:39 +02:00
|
|
|
}
|
2017-09-04 11:09:46 +02:00
|
|
|
if (rctx->flags & (SI_CONTEXT_FLUSH_AND_INV_DB |
|
|
|
|
|
SI_CONTEXT_FLUSH_AND_INV_DB_META)) {
|
2017-02-08 03:01:32 +01:00
|
|
|
/* Flush HTILE. SURFACE_SYNC will wait for idle. */
|
2016-04-02 11:37:06 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
|
2013-12-17 00:46:45 +01:00
|
|
|
radeon_emit(cs, EVENT_TYPE(V_028A90_FLUSH_AND_INV_DB_META) | EVENT_INDEX(0));
|
|
|
|
|
}
|
radeonsi: simplify and improve flushing
This mimics r600g. The R600_CONTEXT_xxx flags are added to rctx->b.flags
and si_emit_cache_flush emits the packets. That's it. The shared radeon code
tells us when the streamout cache should be flushed, so we have to check
the flags anyway.
There is a new atom "cache_flush", because caches must be flushed *after*
resource descriptors are changed in memory.
Functional changes:
* Write caches are flushed at the end of CS and read caches are flushed
at its beginning.
* Sampler view states are removed from si_state, they only held the flush
flags.
* Everytime a shader is changed, the I cache is flushed. Is this needed?
Due to a hw bug, this also flushes the K cache.
* The WRITE_DATA packet is changed to use TC, which fixes a rendering issue
in openarena. I'm not sure how TC interacts with CP DMA, but for now it
seems to work better than any other solution I tried. (BTW CIK allows us
to use TC for CP DMA.)
* Flush the K cache instead of the texture cache when updating resource
descriptors (due to a hw bug, this also flushes the I cache).
I think the K cache flush is correct here, but I'm not sure if the texture
cache should be flushed too (probably not considering we use TC
for WRITE_DATA, but we don't use TC for CP DMA).
* The number of resource contexts is decreased to 16. With all of these cache
changes, 4 doesn't work, but 8 works, which suggests I'm actually doing
the right thing here and the pipeline isn't drained during flushes.
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Tested-by: Tom Stellard <thomas.stellard@amd.com>
2013-08-26 17:19:39 +02:00
|
|
|
|
2016-04-17 16:18:54 +02:00
|
|
|
/* Wait for shader engines to go idle.
|
|
|
|
|
* VS and PS waits are unnecessary if SURFACE_SYNC is going to wait
|
|
|
|
|
* for everything including CB/DB cache flushes.
|
2014-12-30 18:41:25 +01:00
|
|
|
*/
|
2016-10-15 16:21:20 +02:00
|
|
|
if (!flush_cb_db) {
|
2016-08-25 14:08:24 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_PS_PARTIAL_FLUSH) {
|
2016-04-02 11:37:06 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
|
2016-04-17 16:18:54 +02:00
|
|
|
radeon_emit(cs, EVENT_TYPE(V_028A90_PS_PARTIAL_FLUSH) | EVENT_INDEX(4));
|
2016-08-23 15:17:35 +02:00
|
|
|
/* Only count explicit shader flushes, not implicit ones
|
|
|
|
|
* done by SURFACE_SYNC.
|
|
|
|
|
*/
|
2016-08-25 14:08:24 +02:00
|
|
|
rctx->num_vs_flushes++;
|
|
|
|
|
rctx->num_ps_flushes++;
|
|
|
|
|
} else if (rctx->flags & SI_CONTEXT_VS_PARTIAL_FLUSH) {
|
2016-04-02 11:37:06 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
|
2016-04-17 16:18:54 +02:00
|
|
|
radeon_emit(cs, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH) | EVENT_INDEX(4));
|
2016-08-25 14:08:24 +02:00
|
|
|
rctx->num_vs_flushes++;
|
2016-04-17 16:18:54 +02:00
|
|
|
}
|
2013-09-02 12:57:46 +02:00
|
|
|
}
|
2016-08-23 15:17:35 +02:00
|
|
|
|
2016-08-25 14:08:24 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_CS_PARTIAL_FLUSH &&
|
|
|
|
|
sctx->compute_is_busy) {
|
2016-04-02 11:37:06 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
|
2014-09-20 11:54:46 +02:00
|
|
|
radeon_emit(cs, EVENT_TYPE(V_028A90_CS_PARTIAL_FLUSH | EVENT_INDEX(4)));
|
2016-08-25 14:08:24 +02:00
|
|
|
rctx->num_cs_flushes++;
|
|
|
|
|
sctx->compute_is_busy = false;
|
2014-09-20 11:54:46 +02:00
|
|
|
}
|
2016-04-17 16:18:54 +02:00
|
|
|
|
|
|
|
|
/* VGT state synchronization. */
|
2016-08-25 14:08:24 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_VGT_FLUSH) {
|
2016-04-02 11:37:06 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
|
2013-11-21 16:45:28 +09:00
|
|
|
radeon_emit(cs, EVENT_TYPE(V_028A90_VGT_FLUSH) | EVENT_INDEX(0));
|
|
|
|
|
}
|
2016-08-25 14:08:24 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_VGT_STREAMOUT_SYNC) {
|
2016-04-02 11:37:06 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
|
2014-07-26 03:16:22 +02:00
|
|
|
radeon_emit(cs, EVENT_TYPE(V_028A90_VGT_STREAMOUT_SYNC) | EVENT_INDEX(0));
|
|
|
|
|
}
|
2013-11-21 16:45:28 +09:00
|
|
|
|
2016-10-15 16:21:20 +02:00
|
|
|
/* GFX9: Wait for idle if we're flushing CB or DB. ACQUIRE_MEM doesn't
|
|
|
|
|
* wait for idle on GFX9. We have to use a TS event.
|
|
|
|
|
*/
|
|
|
|
|
if (sctx->b.chip_class >= GFX9 && flush_cb_db) {
|
|
|
|
|
uint64_t va;
|
2017-06-07 00:16:46 +02:00
|
|
|
unsigned tc_flags, cb_db_event;
|
2016-10-15 16:21:20 +02:00
|
|
|
|
|
|
|
|
/* Set the CB/DB flush event. */
|
|
|
|
|
switch (flush_cb_db) {
|
|
|
|
|
case SI_CONTEXT_FLUSH_AND_INV_CB:
|
|
|
|
|
cb_db_event = V_028A90_FLUSH_AND_INV_CB_DATA_TS;
|
|
|
|
|
break;
|
|
|
|
|
case SI_CONTEXT_FLUSH_AND_INV_DB:
|
|
|
|
|
cb_db_event = V_028A90_FLUSH_AND_INV_DB_DATA_TS;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* both CB & DB */
|
|
|
|
|
cb_db_event = V_028A90_CACHE_FLUSH_AND_INV_TS_EVENT;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 00:34:12 +02:00
|
|
|
/* These are the only allowed combinations. If you need to
|
|
|
|
|
* do multiple operations at once, do them separately.
|
|
|
|
|
* All operations that invalidate L2 also seem to invalidate
|
|
|
|
|
* metadata. Volatile (VOL) and WC flushes are not listed here.
|
|
|
|
|
*
|
|
|
|
|
* TC | TC_WB = writeback & invalidate L2 & L1
|
|
|
|
|
* TC | TC_WB | TC_NC = writeback & invalidate L2 for MTYPE == NC
|
|
|
|
|
* TC_WB | TC_NC = writeback L2 for MTYPE == NC
|
|
|
|
|
* TC | TC_NC = invalidate L2 for MTYPE == NC
|
|
|
|
|
* TC | TC_MD = writeback & invalidate L2 metadata (DCC, etc.)
|
|
|
|
|
* TCL1 = invalidate L1
|
|
|
|
|
*/
|
2017-08-19 15:06:22 +02:00
|
|
|
tc_flags = 0;
|
2017-08-19 00:34:12 +02:00
|
|
|
|
2017-08-19 15:06:22 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_INV_L2_METADATA) {
|
|
|
|
|
tc_flags = EVENT_TC_ACTION_ENA |
|
|
|
|
|
EVENT_TC_MD_ACTION_ENA;
|
|
|
|
|
}
|
2016-10-15 16:21:20 +02:00
|
|
|
|
|
|
|
|
/* Ideally flush TC together with CB/DB. */
|
|
|
|
|
if (rctx->flags & SI_CONTEXT_INV_GLOBAL_L2) {
|
2017-08-19 00:34:12 +02:00
|
|
|
/* Writeback and invalidate everything in L2 & L1. */
|
|
|
|
|
tc_flags = EVENT_TC_ACTION_ENA |
|
|
|
|
|
EVENT_TC_WB_ACTION_ENA;
|
2016-10-15 16:21:20 +02:00
|
|
|
|
|
|
|
|
/* Clear the flags. */
|
|
|
|
|
rctx->flags &= ~(SI_CONTEXT_INV_GLOBAL_L2 |
|
|
|
|
|
SI_CONTEXT_WRITEBACK_GLOBAL_L2 |
|
|
|
|
|
SI_CONTEXT_INV_VMEM_L1);
|
2017-06-08 01:32:51 +02:00
|
|
|
sctx->b.num_L2_invalidates++;
|
2016-10-15 16:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-07 00:16:46 +02:00
|
|
|
/* Do the flush (enqueue the event and wait for it). */
|
|
|
|
|
va = sctx->wait_mem_scratch->gpu_address;
|
|
|
|
|
sctx->wait_mem_number++;
|
2016-10-15 16:21:20 +02:00
|
|
|
|
2017-09-13 02:26:26 +02:00
|
|
|
si_gfx_write_event_eop(rctx, cb_db_event, tc_flags,
|
2017-08-18 21:14:01 +02:00
|
|
|
EOP_DATA_SEL_VALUE_32BIT,
|
2017-06-07 00:16:46 +02:00
|
|
|
sctx->wait_mem_scratch, va,
|
2017-08-18 18:35:57 +02:00
|
|
|
sctx->wait_mem_number, R600_NOT_QUERY);
|
2017-09-13 02:26:26 +02:00
|
|
|
si_gfx_wait_fence(rctx, va, sctx->wait_mem_number, 0xffffffff);
|
2016-10-15 16:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-17 17:28:25 +02:00
|
|
|
/* Make sure ME is idle (it executes most packets) before continuing.
|
|
|
|
|
* This prevents read-after-write hazards between PFP and ME.
|
|
|
|
|
*/
|
2016-10-10 18:49:22 +02:00
|
|
|
if (cp_coher_cntl ||
|
|
|
|
|
(rctx->flags & (SI_CONTEXT_CS_PARTIAL_FLUSH |
|
|
|
|
|
SI_CONTEXT_INV_VMEM_L1 |
|
|
|
|
|
SI_CONTEXT_INV_GLOBAL_L2 |
|
|
|
|
|
SI_CONTEXT_WRITEBACK_GLOBAL_L2))) {
|
2016-04-17 17:28:25 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_PFP_SYNC_ME, 0, 0));
|
|
|
|
|
radeon_emit(cs, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-15 16:21:20 +02:00
|
|
|
/* SI-CI-VI only:
|
|
|
|
|
* When one of the CP_COHER_CNTL.DEST_BASE flags is set, SURFACE_SYNC
|
|
|
|
|
* waits for idle, so it should be last. SURFACE_SYNC is done in PFP.
|
2016-10-10 18:49:22 +02:00
|
|
|
*
|
|
|
|
|
* cp_coher_cntl should contain all necessary flags except TC flags
|
|
|
|
|
* at this point.
|
|
|
|
|
*
|
|
|
|
|
* SI-CIK don't support L2 write-back.
|
2014-12-30 18:41:25 +01:00
|
|
|
*/
|
2016-10-10 18:49:22 +02:00
|
|
|
if (rctx->flags & SI_CONTEXT_INV_GLOBAL_L2 ||
|
|
|
|
|
(rctx->chip_class <= CIK &&
|
|
|
|
|
(rctx->flags & SI_CONTEXT_WRITEBACK_GLOBAL_L2))) {
|
2017-01-20 01:13:39 +01:00
|
|
|
/* Invalidate L1 & L2. (L1 is always invalidated on SI)
|
2016-10-10 18:49:22 +02:00
|
|
|
* WB must be set on VI+ when TC_ACTION is set.
|
|
|
|
|
*/
|
|
|
|
|
si_emit_surface_sync(rctx, cp_coher_cntl |
|
|
|
|
|
S_0085F0_TC_ACTION_ENA(1) |
|
2017-01-20 01:13:39 +01:00
|
|
|
S_0085F0_TCL1_ACTION_ENA(1) |
|
2016-10-10 18:49:22 +02:00
|
|
|
S_0301F0_TC_WB_ACTION_ENA(rctx->chip_class >= VI));
|
|
|
|
|
cp_coher_cntl = 0;
|
2016-12-25 19:48:55 +01:00
|
|
|
sctx->b.num_L2_invalidates++;
|
2016-10-10 18:49:22 +02:00
|
|
|
} else {
|
|
|
|
|
/* L1 invalidation and L2 writeback must be done separately,
|
|
|
|
|
* because both operations can't be done together.
|
|
|
|
|
*/
|
|
|
|
|
if (rctx->flags & SI_CONTEXT_WRITEBACK_GLOBAL_L2) {
|
|
|
|
|
/* WB = write-back
|
|
|
|
|
* NC = apply to non-coherent MTYPEs
|
|
|
|
|
* (i.e. MTYPE <= 1, which is what we use everywhere)
|
|
|
|
|
*
|
|
|
|
|
* WB doesn't work without NC.
|
|
|
|
|
*/
|
|
|
|
|
si_emit_surface_sync(rctx, cp_coher_cntl |
|
|
|
|
|
S_0301F0_TC_WB_ACTION_ENA(1) |
|
|
|
|
|
S_0301F0_TC_NC_ACTION_ENA(1));
|
|
|
|
|
cp_coher_cntl = 0;
|
2016-12-25 19:48:55 +01:00
|
|
|
sctx->b.num_L2_writebacks++;
|
2016-10-10 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
if (rctx->flags & SI_CONTEXT_INV_VMEM_L1) {
|
|
|
|
|
/* Invalidate per-CU VMEM L1. */
|
|
|
|
|
si_emit_surface_sync(rctx, cp_coher_cntl |
|
|
|
|
|
S_0085F0_TCL1_ACTION_ENA(1));
|
|
|
|
|
cp_coher_cntl = 0;
|
|
|
|
|
}
|
2014-12-30 18:41:25 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-10 18:49:22 +02:00
|
|
|
/* If TC flushes haven't cleared this... */
|
|
|
|
|
if (cp_coher_cntl)
|
|
|
|
|
si_emit_surface_sync(rctx, cp_coher_cntl);
|
|
|
|
|
|
2016-08-25 14:08:24 +02:00
|
|
|
if (rctx->flags & R600_CONTEXT_START_PIPELINE_STATS) {
|
2016-04-07 02:59:09 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
|
|
|
|
|
radeon_emit(cs, EVENT_TYPE(V_028A90_PIPELINESTAT_START) |
|
|
|
|
|
EVENT_INDEX(0));
|
2016-08-25 14:08:24 +02:00
|
|
|
} else if (rctx->flags & R600_CONTEXT_STOP_PIPELINE_STATS) {
|
2016-04-07 02:59:09 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
|
|
|
|
|
radeon_emit(cs, EVENT_TYPE(V_028A90_PIPELINESTAT_STOP) |
|
|
|
|
|
EVENT_INDEX(0));
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 14:08:24 +02:00
|
|
|
rctx->flags = 0;
|
radeonsi: simplify and improve flushing
This mimics r600g. The R600_CONTEXT_xxx flags are added to rctx->b.flags
and si_emit_cache_flush emits the packets. That's it. The shared radeon code
tells us when the streamout cache should be flushed, so we have to check
the flags anyway.
There is a new atom "cache_flush", because caches must be flushed *after*
resource descriptors are changed in memory.
Functional changes:
* Write caches are flushed at the end of CS and read caches are flushed
at its beginning.
* Sampler view states are removed from si_state, they only held the flush
flags.
* Everytime a shader is changed, the I cache is flushed. Is this needed?
Due to a hw bug, this also flushes the K cache.
* The WRITE_DATA packet is changed to use TC, which fixes a rendering issue
in openarena. I'm not sure how TC interacts with CP DMA, but for now it
seems to work better than any other solution I tried. (BTW CIK allows us
to use TC for CP DMA.)
* Flush the K cache instead of the texture cache when updating resource
descriptors (due to a hw bug, this also flushes the I cache).
I think the K cache flush is correct here, but I'm not sure if the texture
cache should be flushed too (probably not considering we use TC
for WRITE_DATA, but we don't use TC for CP DMA).
* The number of resource contexts is decreased to 16. With all of these cache
changes, 4 doesn't work, but 8 works, which suggests I'm actually doing
the right thing here and the pipeline isn't drained during flushes.
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Tested-by: Tom Stellard <thomas.stellard@amd.com>
2013-08-26 17:19:39 +02:00
|
|
|
}
|
|
|
|
|
|
2014-04-24 03:03:43 +02:00
|
|
|
static void si_get_draw_start_count(struct si_context *sctx,
|
|
|
|
|
const struct pipe_draw_info *info,
|
|
|
|
|
unsigned *start, unsigned *count)
|
|
|
|
|
{
|
2017-04-02 15:24:19 +02:00
|
|
|
struct pipe_draw_indirect_info *indirect = info->indirect;
|
|
|
|
|
|
|
|
|
|
if (indirect) {
|
2017-02-20 10:46:13 +01:00
|
|
|
unsigned indirect_count;
|
|
|
|
|
struct pipe_transfer *transfer;
|
|
|
|
|
unsigned begin, end;
|
|
|
|
|
unsigned map_size;
|
|
|
|
|
unsigned *data;
|
|
|
|
|
|
2017-04-02 15:24:19 +02:00
|
|
|
if (indirect->indirect_draw_count) {
|
2017-02-20 10:46:13 +01:00
|
|
|
data = pipe_buffer_map_range(&sctx->b.b,
|
2017-04-02 15:24:19 +02:00
|
|
|
indirect->indirect_draw_count,
|
|
|
|
|
indirect->indirect_draw_count_offset,
|
2017-02-20 10:46:13 +01:00
|
|
|
sizeof(unsigned),
|
|
|
|
|
PIPE_TRANSFER_READ, &transfer);
|
|
|
|
|
|
|
|
|
|
indirect_count = *data;
|
|
|
|
|
|
|
|
|
|
pipe_buffer_unmap(&sctx->b.b, transfer);
|
|
|
|
|
} else {
|
2017-04-02 15:24:19 +02:00
|
|
|
indirect_count = indirect->draw_count;
|
2017-02-20 10:46:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!indirect_count) {
|
|
|
|
|
*start = *count = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-02 15:24:19 +02:00
|
|
|
map_size = (indirect_count - 1) * indirect->stride + 3 * sizeof(unsigned);
|
|
|
|
|
data = pipe_buffer_map_range(&sctx->b.b, indirect->buffer,
|
|
|
|
|
indirect->offset, map_size,
|
2017-02-20 10:46:13 +01:00
|
|
|
PIPE_TRANSFER_READ, &transfer);
|
|
|
|
|
|
|
|
|
|
begin = UINT_MAX;
|
|
|
|
|
end = 0;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < indirect_count; ++i) {
|
|
|
|
|
unsigned count = data[0];
|
|
|
|
|
unsigned start = data[2];
|
|
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
begin = MIN2(begin, start);
|
|
|
|
|
end = MAX2(end, start + count);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-02 15:24:19 +02:00
|
|
|
data += indirect->stride / sizeof(unsigned);
|
2017-02-20 10:46:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pipe_buffer_unmap(&sctx->b.b, transfer);
|
|
|
|
|
|
|
|
|
|
if (begin < end) {
|
|
|
|
|
*start = begin;
|
|
|
|
|
*count = end - begin;
|
|
|
|
|
} else {
|
|
|
|
|
*start = *count = 0;
|
|
|
|
|
}
|
2014-04-24 03:03:43 +02:00
|
|
|
} else {
|
|
|
|
|
*start = info->start;
|
|
|
|
|
*count = info->count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 17:38:57 +02:00
|
|
|
static void si_emit_all_states(struct si_context *sctx, const struct pipe_draw_info *info,
|
|
|
|
|
unsigned skip_atom_mask)
|
|
|
|
|
{
|
|
|
|
|
/* Emit state atoms. */
|
|
|
|
|
unsigned mask = sctx->dirty_atoms & ~skip_atom_mask;
|
|
|
|
|
while (mask) {
|
|
|
|
|
struct r600_atom *atom = sctx->atoms.array[u_bit_scan(&mask)];
|
|
|
|
|
|
|
|
|
|
atom->emit(&sctx->b, atom);
|
|
|
|
|
}
|
|
|
|
|
sctx->dirty_atoms &= skip_atom_mask;
|
|
|
|
|
|
|
|
|
|
/* Emit states. */
|
|
|
|
|
mask = sctx->dirty_states;
|
|
|
|
|
while (mask) {
|
|
|
|
|
unsigned i = u_bit_scan(&mask);
|
|
|
|
|
struct si_pm4_state *state = sctx->queued.array[i];
|
|
|
|
|
|
|
|
|
|
if (!state || sctx->emitted.array[i] == state)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
si_pm4_emit(sctx, state);
|
|
|
|
|
sctx->emitted.array[i] = state;
|
|
|
|
|
}
|
|
|
|
|
sctx->dirty_states = 0;
|
|
|
|
|
|
|
|
|
|
/* Emit draw states. */
|
|
|
|
|
unsigned num_patches = 0;
|
|
|
|
|
|
|
|
|
|
si_emit_rasterizer_prim_state(sctx);
|
|
|
|
|
if (sctx->tes_shader.cso)
|
|
|
|
|
si_emit_derived_tess_state(sctx, info, &num_patches);
|
|
|
|
|
si_emit_vs_state(sctx, info);
|
|
|
|
|
si_emit_draw_registers(sctx, info, num_patches);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-03 10:26:01 +02:00
|
|
|
void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
|
2012-07-19 15:20:45 +02:00
|
|
|
{
|
2014-01-11 16:00:50 +01:00
|
|
|
struct si_context *sctx = (struct si_context *)ctx;
|
2015-10-22 22:18:49 +02:00
|
|
|
struct si_state_rasterizer *rs = sctx->queued.named.rasterizer;
|
2017-04-02 16:24:39 +02:00
|
|
|
struct pipe_resource *indexbuf = info->index.resource;
|
2017-08-04 17:38:57 +02:00
|
|
|
unsigned dirty_tex_counter;
|
2017-04-02 20:33:04 +03:00
|
|
|
enum pipe_prim_type rast_prim;
|
2017-04-02 16:24:39 +02:00
|
|
|
unsigned index_size = info->index_size;
|
|
|
|
|
unsigned index_offset = info->indirect ? info->start * index_size : 0;
|
2012-07-19 15:20:45 +02:00
|
|
|
|
2016-09-06 00:09:17 +02:00
|
|
|
if (likely(!info->indirect)) {
|
|
|
|
|
/* SI-CI treat instance_count==0 as instance_count==1. There is
|
|
|
|
|
* no workaround for indirect draws, but we can at least skip
|
|
|
|
|
* direct draws.
|
|
|
|
|
*/
|
|
|
|
|
if (unlikely(!info->instance_count))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Handle count == 0. */
|
|
|
|
|
if (unlikely(!info->count &&
|
2017-04-02 16:24:39 +02:00
|
|
|
(index_size || !info->count_from_stream_output)))
|
2016-09-06 00:09:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2012-07-19 15:20:45 +02:00
|
|
|
|
2016-09-06 00:10:38 +02:00
|
|
|
if (unlikely(!sctx->vs_shader.cso)) {
|
2015-10-22 22:18:49 +02:00
|
|
|
assert(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-06 00:10:38 +02:00
|
|
|
if (unlikely(!sctx->ps_shader.cso && (!rs || !rs->rasterizer_discard))) {
|
2015-02-22 18:10:38 +01:00
|
|
|
assert(0);
|
2012-07-19 15:20:45 +02:00
|
|
|
return;
|
2015-02-22 18:10:38 +01:00
|
|
|
}
|
2016-09-06 00:10:38 +02:00
|
|
|
if (unlikely(!!sctx->tes_shader.cso != (info->mode == PIPE_PRIM_PATCHES))) {
|
2015-02-22 18:10:38 +01:00
|
|
|
assert(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-07-19 15:20:45 +02:00
|
|
|
|
2017-01-24 23:37:56 +01:00
|
|
|
/* Recompute and re-emit the texture resource states if needed. */
|
|
|
|
|
dirty_tex_counter = p_atomic_read(&sctx->b.screen->dirty_tex_counter);
|
|
|
|
|
if (unlikely(dirty_tex_counter != sctx->b.last_dirty_tex_counter)) {
|
|
|
|
|
sctx->b.last_dirty_tex_counter = dirty_tex_counter;
|
2016-02-24 22:04:47 +01:00
|
|
|
sctx->framebuffer.dirty_cbufs |=
|
|
|
|
|
((1 << sctx->framebuffer.state.nr_cbufs) - 1);
|
|
|
|
|
sctx->framebuffer.dirty_zsbuf = true;
|
|
|
|
|
si_mark_atom_dirty(sctx, &sctx->framebuffer.atom);
|
2016-05-17 21:45:50 +02:00
|
|
|
si_update_all_texture_descriptors(sctx);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 02:05:33 +02:00
|
|
|
si_decompress_textures(sctx, u_bit_consecutive(0, SI_NUM_GRAPHICS_SHADERS));
|
2015-02-22 19:14:42 +01:00
|
|
|
|
|
|
|
|
/* Set the rasterization primitive type.
|
|
|
|
|
*
|
|
|
|
|
* This must be done after si_decompress_textures, which can call
|
|
|
|
|
* draw_vbo recursively, and before si_update_shaders, which uses
|
|
|
|
|
* current_rast_prim for this draw_vbo call. */
|
2015-10-07 01:48:18 +02:00
|
|
|
if (sctx->gs_shader.cso)
|
2016-08-02 11:51:21 +02:00
|
|
|
rast_prim = sctx->gs_shader.cso->gs_output_prim;
|
2017-09-17 11:28:21 +02:00
|
|
|
else if (sctx->tes_shader.cso) {
|
|
|
|
|
if (sctx->tes_shader.cso->info.properties[TGSI_PROPERTY_TES_POINT_MODE])
|
|
|
|
|
rast_prim = PIPE_PRIM_POINTS;
|
|
|
|
|
else
|
|
|
|
|
rast_prim = sctx->tes_shader.cso->info.properties[TGSI_PROPERTY_TES_PRIM_MODE];
|
|
|
|
|
} else
|
2016-08-02 11:51:21 +02:00
|
|
|
rast_prim = info->mode;
|
2015-01-31 20:09:46 +01:00
|
|
|
|
2017-09-26 17:57:59 +02:00
|
|
|
if (rast_prim != sctx->current_rast_prim) {
|
|
|
|
|
bool old_is_poly = sctx->current_rast_prim >= PIPE_PRIM_TRIANGLES;
|
2017-09-17 11:26:53 +02:00
|
|
|
bool new_is_poly = rast_prim >= PIPE_PRIM_TRIANGLES;
|
|
|
|
|
if (old_is_poly != new_is_poly) {
|
2017-09-26 17:56:15 +02:00
|
|
|
sctx->scissors.dirty_mask = (1 << SI_MAX_VIEWPORTS) - 1;
|
|
|
|
|
si_mark_atom_dirty(sctx, &sctx->scissors.atom);
|
2017-09-17 11:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-26 17:57:59 +02:00
|
|
|
sctx->current_rast_prim = rast_prim;
|
2016-08-02 11:51:21 +02:00
|
|
|
sctx->do_update_shaders = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 23:11:38 +02:00
|
|
|
if (sctx->tes_shader.cso &&
|
|
|
|
|
(sctx->b.family == CHIP_VEGA10 || sctx->b.family == CHIP_RAVEN)) {
|
|
|
|
|
/* Determine whether the LS VGPR fix should be applied.
|
|
|
|
|
*
|
|
|
|
|
* It is only required when num input CPs > num output CPs,
|
|
|
|
|
* which cannot happen with the fixed function TCS. We should
|
|
|
|
|
* also update this bit when switching from TCS to fixed
|
|
|
|
|
* function TCS.
|
|
|
|
|
*/
|
|
|
|
|
struct si_shader_selector *tcs = sctx->tcs_shader.cso;
|
|
|
|
|
bool ls_vgpr_fix =
|
|
|
|
|
tcs &&
|
|
|
|
|
info->vertices_per_patch >
|
|
|
|
|
tcs->info.properties[TGSI_PROPERTY_TCS_VERTICES_OUT];
|
|
|
|
|
|
|
|
|
|
if (ls_vgpr_fix != sctx->ls_vgpr_fix) {
|
|
|
|
|
sctx->ls_vgpr_fix = ls_vgpr_fix;
|
|
|
|
|
sctx->do_update_shaders = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 12:50:09 +01:00
|
|
|
if (sctx->gs_shader.cso) {
|
|
|
|
|
/* Determine whether the GS triangle strip adjacency fix should
|
|
|
|
|
* be applied. Rotate every other triangle if
|
|
|
|
|
* - triangle strips with adjacency are fed to the GS and
|
|
|
|
|
* - primitive restart is disabled (the rotation doesn't help
|
|
|
|
|
* when the restart occurs after an odd number of triangles).
|
|
|
|
|
*/
|
|
|
|
|
bool gs_tri_strip_adj_fix =
|
|
|
|
|
!sctx->tes_shader.cso &&
|
|
|
|
|
info->mode == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY &&
|
|
|
|
|
!info->primitive_restart;
|
|
|
|
|
|
|
|
|
|
if (gs_tri_strip_adj_fix != sctx->gs_tri_strip_adj_fix) {
|
|
|
|
|
sctx->gs_tri_strip_adj_fix = gs_tri_strip_adj_fix;
|
|
|
|
|
sctx->do_update_shaders = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-02 11:51:21 +02:00
|
|
|
if (sctx->do_update_shaders && !si_update_shaders(sctx))
|
|
|
|
|
return;
|
|
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
if (index_size) {
|
2012-07-19 15:20:45 +02:00
|
|
|
/* Translate or upload, if needed. */
|
2015-04-16 20:44:54 +02:00
|
|
|
/* 8-bit indices are supported on VI. */
|
2017-04-02 16:24:39 +02:00
|
|
|
if (sctx->b.chip_class <= CIK && index_size == 1) {
|
|
|
|
|
unsigned start, count, start_offset, size, offset;
|
2014-01-22 03:05:21 +01:00
|
|
|
void *ptr;
|
|
|
|
|
|
2014-04-24 03:03:43 +02:00
|
|
|
si_get_draw_start_count(sctx, info, &start, &count);
|
2017-02-15 17:24:38 +01:00
|
|
|
start_offset = start * 2;
|
2017-02-15 18:32:34 +01:00
|
|
|
size = count * 2;
|
2014-04-24 16:13:54 +02:00
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
indexbuf = NULL;
|
2017-01-27 01:42:41 +01:00
|
|
|
u_upload_alloc(ctx->stream_uploader, start_offset,
|
2017-02-15 18:32:34 +01:00
|
|
|
size,
|
|
|
|
|
si_optimal_tcc_alignment(sctx, size),
|
2017-04-02 16:24:39 +02:00
|
|
|
&offset, &indexbuf, &ptr);
|
|
|
|
|
if (!indexbuf)
|
2015-09-10 17:42:31 +02:00
|
|
|
return;
|
2014-01-22 03:05:21 +01:00
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
util_shorten_ubyte_elts_to_userptr(&sctx->b.b, info, 0, 0,
|
|
|
|
|
index_offset + start,
|
2014-04-24 16:13:54 +02:00
|
|
|
count, ptr);
|
2014-01-22 03:05:21 +01:00
|
|
|
|
2014-04-24 16:13:54 +02:00
|
|
|
/* info->start will be added by the drawing code */
|
2017-04-02 16:24:39 +02:00
|
|
|
index_offset = offset - start_offset;
|
|
|
|
|
index_size = 2;
|
|
|
|
|
} else if (info->has_user_indices) {
|
2017-04-02 16:22:54 +02:00
|
|
|
unsigned start_offset;
|
2014-04-24 16:13:54 +02:00
|
|
|
|
2017-04-02 16:22:54 +02:00
|
|
|
assert(!info->indirect);
|
2017-04-02 16:24:39 +02:00
|
|
|
start_offset = info->start * index_size;
|
2014-04-24 16:13:54 +02:00
|
|
|
|
2017-04-02 16:24:39 +02:00
|
|
|
indexbuf = NULL;
|
2017-01-27 01:42:41 +01:00
|
|
|
u_upload_data(ctx->stream_uploader, start_offset,
|
2017-04-02 16:24:39 +02:00
|
|
|
info->count * index_size,
|
2017-02-15 18:32:34 +01:00
|
|
|
sctx->screen->b.info.tcc_cache_line_size,
|
2017-04-02 16:24:39 +02:00
|
|
|
(char*)info->index.user + start_offset,
|
|
|
|
|
&index_offset, &indexbuf);
|
|
|
|
|
if (!indexbuf)
|
2015-09-10 17:42:31 +02:00
|
|
|
return;
|
2017-03-28 22:19:29 +02:00
|
|
|
|
2014-04-24 16:13:54 +02:00
|
|
|
/* info->start will be added by the drawing code */
|
2017-04-02 16:24:39 +02:00
|
|
|
index_offset -= start_offset;
|
2017-02-15 18:36:21 +01:00
|
|
|
} else if (sctx->b.chip_class <= CIK &&
|
2017-04-02 16:24:39 +02:00
|
|
|
r600_resource(indexbuf)->TC_L2_dirty) {
|
2017-02-15 18:36:21 +01:00
|
|
|
/* VI reads index buffers through TC L2, so it doesn't
|
|
|
|
|
* need this. */
|
|
|
|
|
sctx->b.flags |= SI_CONTEXT_WRITEBACK_GLOBAL_L2;
|
2017-04-02 16:24:39 +02:00
|
|
|
r600_resource(indexbuf)->TC_L2_dirty = false;
|
2012-07-19 15:20:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-26 03:02:23 +01:00
|
|
|
if (info->indirect) {
|
2017-04-02 15:24:19 +02:00
|
|
|
struct pipe_draw_indirect_info *indirect = info->indirect;
|
|
|
|
|
|
2017-01-26 03:02:23 +01:00
|
|
|
/* Add the buffer size for memory checking in need_cs_space. */
|
2017-04-02 15:24:19 +02:00
|
|
|
r600_context_add_resource_size(ctx, indirect->buffer);
|
2016-08-08 17:06:22 +02:00
|
|
|
|
2017-06-06 12:13:40 +02:00
|
|
|
/* Indirect buffers use TC L2 on GFX9, but not older hw. */
|
|
|
|
|
if (sctx->b.chip_class <= VI) {
|
|
|
|
|
if (r600_resource(indirect->buffer)->TC_L2_dirty) {
|
|
|
|
|
sctx->b.flags |= SI_CONTEXT_WRITEBACK_GLOBAL_L2;
|
|
|
|
|
r600_resource(indirect->buffer)->TC_L2_dirty = false;
|
|
|
|
|
}
|
2016-08-08 16:00:29 +02:00
|
|
|
|
2017-06-06 12:13:40 +02:00
|
|
|
if (indirect->indirect_draw_count &&
|
|
|
|
|
r600_resource(indirect->indirect_draw_count)->TC_L2_dirty) {
|
|
|
|
|
sctx->b.flags |= SI_CONTEXT_WRITEBACK_GLOBAL_L2;
|
|
|
|
|
r600_resource(indirect->indirect_draw_count)->TC_L2_dirty = false;
|
|
|
|
|
}
|
2017-01-26 03:02:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-07-29 16:33:50 +02:00
|
|
|
|
2015-08-30 03:56:13 +02:00
|
|
|
si_need_cs_space(sctx);
|
2012-07-19 15:20:45 +02:00
|
|
|
|
2016-07-29 17:28:43 +02:00
|
|
|
/* Since we've called r600_context_add_resource_size for vertex buffers,
|
|
|
|
|
* this must be called after si_need_cs_space, because we must let
|
|
|
|
|
* need_cs_space flush before we add buffers to the buffer list.
|
|
|
|
|
*/
|
|
|
|
|
if (!si_upload_vertex_buffer_descriptors(sctx))
|
|
|
|
|
return;
|
|
|
|
|
|
2017-11-07 16:12:56 +01:00
|
|
|
/* Vega10/Raven scissor bug workaround. This must be done before VPORT
|
|
|
|
|
* scissor registers are changed. There is also a more efficient but
|
|
|
|
|
* more involved alternative workaround.
|
2017-08-10 21:50:59 +02:00
|
|
|
*/
|
2017-11-07 16:12:56 +01:00
|
|
|
if ((sctx->b.family == CHIP_VEGA10 || sctx->b.family == CHIP_RAVEN) &&
|
2017-09-26 17:56:15 +02:00
|
|
|
si_is_atom_dirty(sctx, &sctx->scissors.atom)) {
|
2017-01-09 16:32:12 +01:00
|
|
|
sctx->b.flags |= SI_CONTEXT_PS_PARTIAL_FLUSH;
|
2017-08-10 21:50:59 +02:00
|
|
|
si_emit_cache_flush(sctx);
|
|
|
|
|
}
|
2017-01-09 16:32:12 +01:00
|
|
|
|
2017-08-04 17:38:57 +02:00
|
|
|
/* Use optimal packet order based on whether we need to sync the pipeline. */
|
|
|
|
|
if (unlikely(sctx->b.flags & (SI_CONTEXT_FLUSH_AND_INV_CB |
|
|
|
|
|
SI_CONTEXT_FLUSH_AND_INV_DB |
|
|
|
|
|
SI_CONTEXT_PS_PARTIAL_FLUSH |
|
|
|
|
|
SI_CONTEXT_CS_PARTIAL_FLUSH))) {
|
|
|
|
|
/* If we have to wait for idle, set all states first, so that all
|
|
|
|
|
* SET packets are processed in parallel with previous draw calls.
|
|
|
|
|
* Then upload descriptors, set shader pointers, and draw, and
|
|
|
|
|
* prefetch at the end. This ensures that the time the CUs
|
|
|
|
|
* are idle is very short. (there are only SET_SH packets between
|
|
|
|
|
* the wait and the draw)
|
|
|
|
|
*/
|
|
|
|
|
struct r600_atom *shader_pointers = &sctx->shader_pointers.atom;
|
2017-08-25 09:04:40 +02:00
|
|
|
unsigned masked_atoms = 1u << shader_pointers->id;
|
2017-08-04 17:38:57 +02:00
|
|
|
|
2017-08-25 09:04:40 +02:00
|
|
|
if (unlikely(sctx->b.flags & R600_CONTEXT_FLUSH_FOR_RENDER_COND))
|
|
|
|
|
masked_atoms |= 1u << sctx->b.render_cond_atom.id;
|
|
|
|
|
|
|
|
|
|
/* Emit all states except shader pointers and render condition. */
|
|
|
|
|
si_emit_all_states(sctx, info, masked_atoms);
|
2016-09-08 00:59:55 +02:00
|
|
|
si_emit_cache_flush(sctx);
|
|
|
|
|
|
2017-08-04 17:38:57 +02:00
|
|
|
/* <-- CUs are idle here. */
|
|
|
|
|
if (!si_upload_graphics_shader_descriptors(sctx))
|
|
|
|
|
return;
|
2017-07-29 21:07:23 +02:00
|
|
|
|
2017-08-04 17:38:57 +02:00
|
|
|
/* Set shader pointers after descriptors are uploaded. */
|
2017-08-25 09:04:40 +02:00
|
|
|
if (si_is_atom_dirty(sctx, shader_pointers))
|
2017-08-04 17:38:57 +02:00
|
|
|
shader_pointers->emit(&sctx->b, NULL);
|
2017-08-25 09:04:40 +02:00
|
|
|
if (si_is_atom_dirty(sctx, &sctx->b.render_cond_atom))
|
|
|
|
|
sctx->b.render_cond_atom.emit(&sctx->b, NULL);
|
|
|
|
|
sctx->dirty_atoms = 0;
|
2015-08-29 00:49:40 +02:00
|
|
|
|
2017-08-04 17:38:57 +02:00
|
|
|
si_emit_draw_packets(sctx, info, indexbuf, index_size, index_offset);
|
|
|
|
|
/* <-- CUs are busy here. */
|
2013-08-06 06:42:22 +02:00
|
|
|
|
2017-08-04 17:38:57 +02:00
|
|
|
/* Start prefetches after the draw has been started. Both will run
|
|
|
|
|
* in parallel, but starting the draw first is more important.
|
|
|
|
|
*/
|
|
|
|
|
if (sctx->b.chip_class >= CIK && sctx->prefetch_L2_mask)
|
|
|
|
|
cik_emit_prefetch_L2(sctx);
|
|
|
|
|
} else {
|
|
|
|
|
/* If we don't wait for idle, start prefetches first, then set
|
|
|
|
|
* states, and draw at the end.
|
|
|
|
|
*/
|
|
|
|
|
if (sctx->b.flags)
|
|
|
|
|
si_emit_cache_flush(sctx);
|
2017-01-25 00:09:24 +01:00
|
|
|
|
2017-08-04 17:38:57 +02:00
|
|
|
if (sctx->b.chip_class >= CIK && sctx->prefetch_L2_mask)
|
|
|
|
|
cik_emit_prefetch_L2(sctx);
|
2017-01-25 00:09:24 +01:00
|
|
|
|
2017-08-04 17:38:57 +02:00
|
|
|
if (!si_upload_graphics_shader_descriptors(sctx))
|
|
|
|
|
return;
|
2017-01-25 00:09:24 +01:00
|
|
|
|
2017-08-04 17:38:57 +02:00
|
|
|
si_emit_all_states(sctx, info, 0);
|
|
|
|
|
si_emit_draw_packets(sctx, info, indexbuf, index_size, index_offset);
|
|
|
|
|
}
|
2016-03-10 21:01:39 +01:00
|
|
|
|
2017-09-23 22:34:10 +02:00
|
|
|
if (unlikely(sctx->current_saved_cs)) {
|
2014-01-11 16:00:50 +01:00
|
|
|
si_trace_emit(sctx);
|
2017-09-23 22:34:10 +02:00
|
|
|
si_log_draw_state(sctx, sctx->b.log);
|
|
|
|
|
}
|
2013-03-25 11:46:38 -04:00
|
|
|
|
2014-07-26 03:16:22 +02:00
|
|
|
/* Workaround for a VGT hang when streamout is enabled.
|
|
|
|
|
* It must be done after drawing. */
|
2015-12-04 21:24:21 +01:00
|
|
|
if ((sctx->b.family == CHIP_HAWAII ||
|
|
|
|
|
sctx->b.family == CHIP_TONGA ||
|
|
|
|
|
sctx->b.family == CHIP_FIJI) &&
|
2017-10-07 22:54:31 +02:00
|
|
|
si_get_strmout_en(sctx)) {
|
2014-12-29 14:02:46 +01:00
|
|
|
sctx->b.flags |= SI_CONTEXT_VGT_STREAMOUT_SYNC;
|
2014-07-26 03:16:22 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 15:26:55 +02:00
|
|
|
if (unlikely(sctx->decompression_enabled)) {
|
|
|
|
|
sctx->b.num_decompress_calls++;
|
|
|
|
|
} else {
|
|
|
|
|
sctx->b.num_draw_calls++;
|
|
|
|
|
if (sctx->framebuffer.state.nr_cbufs > 1)
|
|
|
|
|
sctx->b.num_mrt_draw_calls++;
|
|
|
|
|
if (info->primitive_restart)
|
|
|
|
|
sctx->b.num_prim_restart_calls++;
|
|
|
|
|
if (G_0286E8_WAVESIZE(sctx->spi_tmpring_size))
|
|
|
|
|
sctx->b.num_spill_draw_calls++;
|
|
|
|
|
}
|
2017-04-02 16:24:39 +02:00
|
|
|
if (index_size && indexbuf != info->index.resource)
|
|
|
|
|
pipe_resource_reference(&indexbuf, NULL);
|
2012-07-19 15:20:45 +02:00
|
|
|
}
|
2014-09-05 11:59:10 +02:00
|
|
|
|
2017-10-05 01:48:51 +02:00
|
|
|
void si_draw_rectangle(struct blitter_context *blitter,
|
2017-10-05 02:38:35 +02:00
|
|
|
void *vertex_elements_cso,
|
2017-10-05 04:02:05 +02:00
|
|
|
blitter_get_vs_func get_vs,
|
2017-10-05 01:48:51 +02:00
|
|
|
int x1, int y1, int x2, int y2,
|
|
|
|
|
float depth, unsigned num_instances,
|
|
|
|
|
enum blitter_attrib_type type,
|
|
|
|
|
const union blitter_attrib *attrib)
|
|
|
|
|
{
|
|
|
|
|
struct pipe_context *pipe = util_blitter_get_pipe(blitter);
|
|
|
|
|
struct si_context *sctx = (struct si_context*)pipe;
|
|
|
|
|
|
2017-10-05 20:28:29 +02:00
|
|
|
/* Pack position coordinates as signed int16. */
|
|
|
|
|
sctx->vs_blit_sh_data[0] = (uint32_t)(x1 & 0xffff) |
|
|
|
|
|
((uint32_t)(y1 & 0xffff) << 16);
|
|
|
|
|
sctx->vs_blit_sh_data[1] = (uint32_t)(x2 & 0xffff) |
|
|
|
|
|
((uint32_t)(y2 & 0xffff) << 16);
|
|
|
|
|
sctx->vs_blit_sh_data[2] = fui(depth);
|
2017-10-05 01:48:51 +02:00
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case UTIL_BLITTER_ATTRIB_COLOR:
|
2017-10-05 20:28:29 +02:00
|
|
|
memcpy(&sctx->vs_blit_sh_data[3], attrib->color,
|
|
|
|
|
sizeof(float)*4);
|
2017-10-05 01:48:51 +02:00
|
|
|
break;
|
|
|
|
|
case UTIL_BLITTER_ATTRIB_TEXCOORD_XY:
|
2017-10-05 20:28:29 +02:00
|
|
|
case UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW:
|
|
|
|
|
memcpy(&sctx->vs_blit_sh_data[3], &attrib->texcoord,
|
|
|
|
|
sizeof(attrib->texcoord));
|
2017-10-05 01:48:51 +02:00
|
|
|
break;
|
2017-10-05 20:28:29 +02:00
|
|
|
case UTIL_BLITTER_ATTRIB_NONE:;
|
2017-10-05 01:48:51 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-05 20:28:29 +02:00
|
|
|
pipe->bind_vs_state(pipe, si_get_blit_vs(sctx, type, num_instances));
|
2017-10-05 02:38:35 +02:00
|
|
|
|
2017-10-05 01:54:30 +02:00
|
|
|
struct pipe_draw_info info = {};
|
|
|
|
|
info.mode = R600_PRIM_RECTANGLE_LIST;
|
|
|
|
|
info.count = 3;
|
|
|
|
|
info.instance_count = num_instances;
|
|
|
|
|
|
2017-10-05 20:28:29 +02:00
|
|
|
/* Don't set per-stage shader pointers for VS. */
|
2017-10-07 21:53:10 +02:00
|
|
|
sctx->shader_pointers_dirty &= ~SI_DESCS_SHADER_MASK(VERTEX);
|
2017-10-05 20:28:29 +02:00
|
|
|
sctx->vertex_buffer_pointer_dirty = false;
|
|
|
|
|
|
2017-10-05 01:54:30 +02:00
|
|
|
si_draw_vbo(pipe, &info);
|
2017-10-05 01:48:51 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-05 11:59:10 +02:00
|
|
|
void si_trace_emit(struct si_context *sctx)
|
|
|
|
|
{
|
2015-11-07 14:00:30 +01:00
|
|
|
struct radeon_winsys_cs *cs = sctx->b.gfx.cs;
|
2017-08-04 18:24:33 +02:00
|
|
|
uint64_t va = sctx->current_saved_cs->trace_buf->gpu_address;
|
|
|
|
|
uint32_t trace_id = ++sctx->current_saved_cs->trace_id;
|
2017-07-31 01:34:44 +02:00
|
|
|
|
2015-08-19 11:53:25 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_WRITE_DATA, 3, 0));
|
2015-08-19 18:45:11 +02:00
|
|
|
radeon_emit(cs, S_370_DST_SEL(V_370_MEMORY_SYNC) |
|
|
|
|
|
S_370_WR_CONFIRM(1) |
|
|
|
|
|
S_370_ENGINE_SEL(V_370_ME));
|
2017-08-04 18:24:33 +02:00
|
|
|
radeon_emit(cs, va);
|
|
|
|
|
radeon_emit(cs, va >> 32);
|
|
|
|
|
radeon_emit(cs, trace_id);
|
2015-08-19 11:53:25 +02:00
|
|
|
radeon_emit(cs, PKT3(PKT3_NOP, 0, 0));
|
2017-08-04 18:24:33 +02:00
|
|
|
radeon_emit(cs, AC_ENCODE_TRACE_POINT(trace_id));
|
2017-07-31 01:34:44 +02:00
|
|
|
|
2017-08-04 18:24:33 +02:00
|
|
|
if (sctx->b.log)
|
|
|
|
|
u_log_flush(sctx->b.log);
|
2014-09-05 11:59:10 +02:00
|
|
|
}
|