Skip to content

Commit 88f50c8

Browse files
Jerome Glisseairlied
authored andcommitted
drm/radeon/kms: add htile support to the cs checker v3
For 6xx+. Required for mesa to use htile support for HiZ/HiS. Userspace will check radeon version 2.14 with is bumped either by tiling patch or stream out patch. This patch only add support for htile relocation which should be enough for any userspace to implement the hyperz (using htile buffer) feature. v2: Jerome: Fix size checking for htile buffer. v3: Jerome: Adapt on top of r600/evergreen cs checker changes, also check htile surface in case only stencil is present. Signed-off-by: Pierre-Eric Pelloux-Prayer <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Signed-off-by: Jerome Glisse <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
1 parent 017d213 commit 88f50c8

File tree

7 files changed

+385
-123
lines changed

7 files changed

+385
-123
lines changed

drivers/gpu/drm/radeon/evergreen_cs.c

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ struct evergreen_cs_track {
8080
bool cb_dirty;
8181
bool db_dirty;
8282
bool streamout_dirty;
83+
u32 htile_offset;
84+
u32 htile_surface;
85+
struct radeon_bo *htile_bo;
8386
};
8487

8588
static u32 evergreen_cs_get_aray_mode(u32 tiling_flags)
@@ -144,6 +147,9 @@ static void evergreen_cs_track_init(struct evergreen_cs_track *track)
144147
track->db_s_read_bo = NULL;
145148
track->db_s_write_bo = NULL;
146149
track->db_dirty = true;
150+
track->htile_bo = NULL;
151+
track->htile_offset = 0xFFFFFFFF;
152+
track->htile_surface = 0;
147153

148154
for (i = 0; i < 4; i++) {
149155
track->vgt_strmout_size[i] = 0;
@@ -444,6 +450,62 @@ static int evergreen_cs_track_validate_cb(struct radeon_cs_parser *p, unsigned i
444450
return 0;
445451
}
446452

453+
static int evergreen_cs_track_validate_htile(struct radeon_cs_parser *p,
454+
unsigned nbx, unsigned nby)
455+
{
456+
struct evergreen_cs_track *track = p->track;
457+
unsigned long size;
458+
459+
if (track->htile_bo == NULL) {
460+
dev_warn(p->dev, "%s:%d htile enabled without htile surface 0x%08x\n",
461+
__func__, __LINE__, track->db_z_info);
462+
return -EINVAL;
463+
}
464+
465+
if (G_028ABC_LINEAR(track->htile_surface)) {
466+
/* pitch must be 16 htiles aligned == 16 * 8 pixel aligned */
467+
nbx = round_up(nbx, 16 * 8);
468+
/* height is npipes htiles aligned == npipes * 8 pixel aligned */
469+
nby = round_up(nby, track->npipes * 8);
470+
} else {
471+
switch (track->npipes) {
472+
case 8:
473+
nbx = round_up(nbx, 64 * 8);
474+
nby = round_up(nby, 64 * 8);
475+
break;
476+
case 4:
477+
nbx = round_up(nbx, 64 * 8);
478+
nby = round_up(nby, 32 * 8);
479+
break;
480+
case 2:
481+
nbx = round_up(nbx, 32 * 8);
482+
nby = round_up(nby, 32 * 8);
483+
break;
484+
case 1:
485+
nbx = round_up(nbx, 32 * 8);
486+
nby = round_up(nby, 16 * 8);
487+
break;
488+
default:
489+
dev_warn(p->dev, "%s:%d invalid num pipes %d\n",
490+
__func__, __LINE__, track->npipes);
491+
return -EINVAL;
492+
}
493+
}
494+
/* compute number of htile */
495+
nbx = nbx / 8;
496+
nby = nby / 8;
497+
size = nbx * nby * 4;
498+
size += track->htile_offset;
499+
500+
if (size > radeon_bo_size(track->htile_bo)) {
501+
dev_warn(p->dev, "%s:%d htile surface too small %ld for %ld (%d %d)\n",
502+
__func__, __LINE__, radeon_bo_size(track->htile_bo),
503+
size, nbx, nby);
504+
return -EINVAL;
505+
}
506+
return 0;
507+
}
508+
447509
static int evergreen_cs_track_validate_stencil(struct radeon_cs_parser *p)
448510
{
449511
struct evergreen_cs_track *track = p->track;
@@ -530,6 +592,14 @@ static int evergreen_cs_track_validate_stencil(struct radeon_cs_parser *p)
530592
return -EINVAL;
531593
}
532594

595+
/* hyperz */
596+
if (G_028040_TILE_SURFACE_ENABLE(track->db_z_info)) {
597+
r = evergreen_cs_track_validate_htile(p, surf.nbx, surf.nby);
598+
if (r) {
599+
return r;
600+
}
601+
}
602+
533603
return 0;
534604
}
535605

@@ -617,6 +687,14 @@ static int evergreen_cs_track_validate_depth(struct radeon_cs_parser *p)
617687
return -EINVAL;
618688
}
619689

690+
/* hyperz */
691+
if (G_028040_TILE_SURFACE_ENABLE(track->db_z_info)) {
692+
r = evergreen_cs_track_validate_htile(p, surf.nbx, surf.nby);
693+
if (r) {
694+
return r;
695+
}
696+
}
697+
620698
return 0;
621699
}
622700

@@ -850,7 +928,7 @@ static int evergreen_cs_track_check(struct radeon_cs_parser *p)
850928
return r;
851929
}
852930
/* Check depth buffer */
853-
if (G_028800_Z_WRITE_ENABLE(track->db_depth_control)) {
931+
if (G_028800_Z_ENABLE(track->db_depth_control)) {
854932
r = evergreen_cs_track_validate_depth(p);
855933
if (r)
856934
return r;
@@ -1616,6 +1694,23 @@ static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
16161694
track->cb_color_bo[tmp] = reloc->robj;
16171695
track->cb_dirty = true;
16181696
break;
1697+
case DB_HTILE_DATA_BASE:
1698+
r = evergreen_cs_packet_next_reloc(p, &reloc);
1699+
if (r) {
1700+
dev_warn(p->dev, "bad SET_CONTEXT_REG "
1701+
"0x%04X\n", reg);
1702+
return -EINVAL;
1703+
}
1704+
track->htile_offset = radeon_get_ib_value(p, idx);
1705+
ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1706+
track->htile_bo = reloc->robj;
1707+
track->db_dirty = true;
1708+
break;
1709+
case DB_HTILE_SURFACE:
1710+
/* 8x8 only */
1711+
track->htile_surface = radeon_get_ib_value(p, idx);
1712+
track->db_dirty = true;
1713+
break;
16191714
case CB_IMMED0_BASE:
16201715
case CB_IMMED1_BASE:
16211716
case CB_IMMED2_BASE:
@@ -1628,7 +1723,6 @@ static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
16281723
case CB_IMMED9_BASE:
16291724
case CB_IMMED10_BASE:
16301725
case CB_IMMED11_BASE:
1631-
case DB_HTILE_DATA_BASE:
16321726
case SQ_PGM_START_FS:
16331727
case SQ_PGM_START_ES:
16341728
case SQ_PGM_START_VS:

drivers/gpu/drm/radeon/evergreend.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,14 @@
991991
#define G_028008_SLICE_MAX(x) (((x) >> 13) & 0x7FF)
992992
#define C_028008_SLICE_MAX 0xFF001FFF
993993
#define DB_HTILE_DATA_BASE 0x28014
994+
#define DB_HTILE_SURFACE 0x28abc
995+
#define S_028ABC_HTILE_WIDTH(x) (((x) & 0x1) << 0)
996+
#define G_028ABC_HTILE_WIDTH(x) (((x) >> 0) & 0x1)
997+
#define C_028ABC_HTILE_WIDTH 0xFFFFFFFE
998+
#define S_028ABC_HTILE_HEIGHT(x) (((x) & 0x1) << 1)
999+
#define G_028ABC_HTILE_HEIGHT(x) (((x) >> 1) & 0x1)
1000+
#define C_028ABC_HTILE_HEIGHT 0xFFFFFFFD
1001+
#define G_028ABC_LINEAR(x) (((x) >> 2) & 0x1)
9941002
#define DB_Z_INFO 0x28040
9951003
# define Z_ARRAY_MODE(x) ((x) << 4)
9961004
# define DB_TILE_SPLIT(x) (((x) & 0x7) << 8)

0 commit comments

Comments
 (0)