From 4ffa45689f389ff589a6a7ef63e6ce9e4dd0a201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 15 May 2023 01:28:15 -0400 Subject: [PATCH] radeonsi: implement setting a custom pitch to any multiple of 256B on gfx10.3+ Reviewed-by: Pierre-Eric Pelloux-Prayer Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/gallium/drivers/radeonsi/si_descriptors.c | 18 +++++++++++++++ src/gallium/drivers/radeonsi/si_state.c | 22 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c b/src/gallium/drivers/radeonsi/si_descriptors.c index 3987ecf6c4d..5c46796ae63 100644 --- a/src/gallium/drivers/radeonsi/si_descriptors.c +++ b/src/gallium/drivers/radeonsi/si_descriptors.c @@ -328,6 +328,24 @@ void si_set_mutable_tex_desc_fields(struct si_screen *sscreen, struct si_texture state[3] |= S_00A00C_SW_MODE(tex->surface.u.gfx9.swizzle_mode); } + /* GFX10.3+ can set a custom pitch for 1D and 2D non-array, but it must be a multiple + * of 256B. Only set it for 2D linear for multi-GPU interop. + */ + if (sscreen->info.gfx_level >= GFX10_3 && + (tex->buffer.b.b.target == PIPE_TEXTURE_2D || + tex->buffer.b.b.target == PIPE_TEXTURE_RECT) && + tex->surface.is_linear) { + assert((tex->surface.u.gfx9.surf_pitch * tex->surface.bpe) % 256 == 0); + unsigned pitch = tex->surface.u.gfx9.surf_pitch; + + /* Subsampled images have the pitch in the units of blocks. */ + if (tex->surface.blk_w == 2) + pitch *= 2; + + state[4] |= S_00A010_DEPTH(pitch - 1) | /* DEPTH contains low bits of PITCH. */ + S_00A010_PITCH_MSB((pitch - 1) >> 13); + } + if (meta_va) { struct gfx9_surf_meta_flags meta = { .rb_aligned = 1, diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index 9b2dcbd827c..62be99bb08a 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -2468,13 +2468,33 @@ static void si_initialize_color_surface(struct si_context *sctx, struct si_surfa S_028C70_ROUND_MODE(round_mode) | S_028C70_NUMBER_TYPE(ntype); + unsigned width0 = surf->width0; + + /* GFX10.3+ can set a custom pitch for 1D and 2D non-array, but it must be a multiple + * of 256B. Only set it for 2D linear for multi-GPU interop. + * + * We set the pitch in MIP0_WIDTH. + */ + if (sctx->gfx_level >= GFX10_3 && + (tex->buffer.b.b.target == PIPE_TEXTURE_2D || + tex->buffer.b.b.target == PIPE_TEXTURE_RECT) && + tex->surface.is_linear) { + assert((tex->surface.u.gfx9.surf_pitch * tex->surface.bpe) % 256 == 0); + + width0 = tex->surface.u.gfx9.surf_pitch; + + /* Subsampled images have the pitch in the units of blocks. */ + if (tex->surface.blk_w == 2) + width0 *= 2; + } + if (sctx->gfx_level >= GFX10) { /* Gfx10-11. */ surf->cb_color_view = S_028C6C_SLICE_START(surf->base.u.tex.first_layer) | S_028C6C_SLICE_MAX_GFX10(surf->base.u.tex.last_layer) | S_028C6C_MIP_LEVEL_GFX10(surf->base.u.tex.level); surf->cb_color_attrib = 0; - surf->cb_color_attrib2 = S_028C68_MIP0_WIDTH(surf->width0 - 1) | + surf->cb_color_attrib2 = S_028C68_MIP0_WIDTH(width0 - 1) | S_028C68_MIP0_HEIGHT(surf->height0 - 1) | S_028C68_MAX_MIP(tex->buffer.b.b.last_level); surf->cb_color_attrib3 = S_028EE0_MIP0_DEPTH(util_max_layer(&tex->buffer.b.b, 0)) |