Skip to contentSkip to conversation

drm/radeon/evergreen_cs: implement cond_exec and cond_write

PATCH In review Patrick Lerda 2 participants 6 messages Jun 10, 2025 – Jun 30, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/radeon/evergreen_cs: implement cond_exec and cond_write

This change implements the support of PACKET3_COND_EXEC and PACKET3_COND_WRITE which are required to implement ARB_indirect_parameters. ARB_indirect_parameters is part of OpenGL 4.6.

---
 drivers/gpu/drm/radeon/evergreen_cs.c | 96 ++++++++++++++++++++++++++-
 1 file changed, 95 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/evergreen_cs.c +95 -1
index a46613283393..7d00096fc915 100644
@@ -2661,6 +2661,95 @@ static int evergreen_packet3_check(struct radeon_cs_parser *p,
 		}
 		break;
 	}
+	case PACKET3_COND_EXEC:
+	{
+		u64 offset;
+
+		if (pkt->count != 2) {
+			DRM_ERROR("bad COND_EXEC (invalid count)\n");
+			return -EINVAL;
+		}
+		r = radeon_cs_packet_next_reloc(p, &reloc, 0);
+		if (r) {
+			DRM_ERROR("bad COND_EXEC (missing reloc)\n");
+			return -EINVAL;
+		}
+		offset = radeon_get_ib_value(p, idx + 0);
+		offset += ((u64)(radeon_get_ib_value(p, idx + 1) & 0xff)) << 32UL;
+		if (offset & 0x7) {
+			DRM_ERROR("bad COND_EXEC (address not qwords aligned)\n");
+			return -EINVAL;
+		}
+		if ((offset + 8) > radeon_bo_size(reloc->robj)) {
+			DRM_ERROR("bad COND_EXEC bo too small: 0x%llx, 0x%lx\n",
+				  offset + 8, radeon_bo_size(reloc->robj));
+			return -EINVAL;
+		}
+		offset += reloc->gpu_offset;
+		ib[idx + 0] = offset;
+		ib[idx + 1] = upper_32_bits(offset) & 0xff;
+		break;
+	}
+	case PACKET3_COND_WRITE:
+		if (pkt->count != 7) {
+			DRM_ERROR("bad COND_WRITE (invalid count)\n");
+			return -EINVAL;
+		}
+		if (idx_value & 0x10) {
+			u64 offset;
+			/* POLL is memory. */
+			r = radeon_cs_packet_next_reloc(p, &reloc, 0);
+			if (r) {
+				DRM_ERROR("bad COND_WRITE (missing src reloc)\n");
+				return -EINVAL;
+			}
+			offset = radeon_get_ib_value(p, idx + 1);
+			offset += ((u64)(radeon_get_ib_value(p, idx + 2) & 0xff)) << 32;
+			if ((offset + 8) > radeon_bo_size(reloc->robj)) {
+				DRM_ERROR("bad COND_WRITE src bo too small: 0x%llx, 0x%lx\n",
+					  offset + 8, radeon_bo_size(reloc->robj));
+				return -EINVAL;
+			}
+			offset += reloc->gpu_offset;
+			ib[idx + 1] = offset;
+			ib[idx + 2] = upper_32_bits(offset) & 0xff;
+		} else {
+			/* POLL is a reg. */
+			reg = radeon_get_ib_value(p, idx + 1) << 2;
+			if (!evergreen_is_safe_reg(p, reg)) {
+				dev_warn(p->dev, "forbidden register 0x%08x at %d\n",
+					 reg, idx + 1);
+				return -EINVAL;
+			}
+		}
+		if (idx_value & 0x100) {
+			u64 offset;
+			/* WRITE is memory. */
+			r = radeon_cs_packet_next_reloc(p, &reloc, 0);
+			if (r) {
+				DRM_ERROR("bad COND_WRITE (missing dst reloc)\n");
+				return -EINVAL;
+			}
+			offset = radeon_get_ib_value(p, idx + 5);
+			offset += ((u64)(radeon_get_ib_value(p, idx + 6) & 0xff)) << 32;
+			if ((offset + 8) > radeon_bo_size(reloc->robj)) {
+				DRM_ERROR("bad COND_WRITE dst bo too small: 0x%llx, 0x%lx\n",
+					  offset + 8, radeon_bo_size(reloc->robj));
+				return -EINVAL;
+			}
+			offset += reloc->gpu_offset;
+			ib[idx + 5] = offset;
+			ib[idx + 6] = upper_32_bits(offset) & 0xff;
+		} else {
+			/* WRITE is a reg. */
+			reg = radeon_get_ib_value(p, idx + 5) << 2;
+			if (!evergreen_is_safe_reg(p, reg)) {
+				dev_warn(p->dev, "forbidden register 0x%08x at %d\n",
+					 reg, idx + 5);
+				return -EINVAL;
+			}
+		}
+		break;
 	case PACKET3_NOP:
 		break;
 	default:
@@ -3406,7 +3495,12 @@ static int evergreen_vm_packet3_check(struct radeon_device *rdev,
 	case CAYMAN_PACKET3_DEALLOC_STATE:
 		break;
 	case PACKET3_COND_WRITE:
-		if (idx_value & 0x100) {
+		if (!(idx_value & 0x10)) {
+			reg = ib[idx + 1] * 4;
+			if (!evergreen_vm_reg_valid(reg))
+				return -EINVAL;
+		}
+		if (!(idx_value & 0x100)) {
 			reg = ib[idx + 5] * 4;
 			if (!evergreen_vm_reg_valid(reg))
 				return -EINVAL;
Signature · 1 line
2.49.0
#1 lore raw

PATCH 2/2 drm/radeon/evergreen_cs: lower evergreen_surface_check_linear_aligned restriction

This change removes the restriction when palign=64 and nbx=32. This makes two piglit tests working. This is discussed on the thread linked below.

---
 drivers/gpu/drm/radeon/evergreen_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/radeon/evergreen_cs.c +1 -1
index 7d00096fc915..266c57733136 100644
@@ -211,7 +211,7 @@ static int evergreen_surface_check_linear_aligned(struct radeon_cs_parser *p,
 	surf->base_align = track->group_size;
 	surf->palign = palign;
 	surf->halign = 1;
-	if (surf->nbx & (palign - 1)) {
+	if ((surf->nbx & (palign - 1)) && !(palign == 64 && surf->nbx == 32)) {
 		if (prefix) {
 			dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d\n",
 				 __func__, __LINE__, prefix, surf->nbx, palign);
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH 2/2] drm/radeon/evergreen_cs: lower evergreen_surface_check_linear_aligned restriction

Applied the series.

Thanks!

Quoted 27 lines · Patrick Lerda

This change removes the restriction when palign=64 and nbx=32. This makes two piglit tests working. This is discussed on the thread linked below.

---
 drivers/gpu/drm/radeon/evergreen_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/radeon/evergreen_cs.c +1 -2
index 7d00096fc915..266c57733136 100644
@@ -211,7 +211,7 @@ static int evergreen_surface_check_linear_aligned(struct radeon_cs_parser *p,
        surf->base_align = track->group_size;
        surf->palign = palign;
        surf->halign = 1;
-       if (surf->nbx & (palign - 1)) {
+       if ((surf->nbx & (palign - 1)) && !(palign == 64 && surf->nbx == 32)) {
                if (prefix) {
                        dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d\n",
                                 __func__, __LINE__, prefix, surf->nbx, palign);
--

2.49.0

#3 lore raw

Re: [PATCH 2/2] drm/radeon/evergreen_cs: lower evergreen_surface_check_linear_aligned restriction

BTW, do you want to send a patch to bump the driver version so that mesa can check for this and determine whether or not to enable this functionality? See KMS_DRIVER_MINOR in radeon_drv.c.

Alex

Quoted 33 lines · Alex Deucher

Applied the series.

Thanks!

Quoted 27 lines · Patrick Lerda

This change removes the restriction when palign=64 and nbx=32. This makes two piglit tests working. This is discussed on the thread linked below.

---
 drivers/gpu/drm/radeon/evergreen_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/radeon/evergreen_cs.c +1 -2
index 7d00096fc915..266c57733136 100644
@@ -211,7 +211,7 @@ static int evergreen_surface_check_linear_aligned(struct radeon_cs_parser *p,
        surf->base_align = track->group_size;
        surf->palign = palign;
        surf->halign = 1;
-       if (surf->nbx & (palign - 1)) {
+       if ((surf->nbx & (palign - 1)) && !(palign == 64 && surf->nbx == 32)) {
                if (prefix) {
                        dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d\n",
                                 __func__, __LINE__, prefix, surf->nbx, palign);
--

2.49.0

#4 lore raw

PATCH 1/1 drm/radeon: bump version to 2.51.0

The version 2.51.0 adds OpenGL 4.6 compatibility to evergreen and cayman.

---
 drivers/gpu/drm/radeon/radeon_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_drv.c +2 -1
index 267f082bc430..88e821d67af7 100644
@@ -110,9 +110,10 @@
  *   2.48.0 - TA_CS_BC_BASE_ADDR allowed on SI
  *   2.49.0 - DRM_RADEON_GEM_INFO ioctl returns correct vram_size/visible values
  *   2.50.0 - Allows unaligned shader loads on CIK. (needed by OpenGL)
+ *   2.51.0 - Add evergreen/cayman OpenGL 4.6 compatibility
  */
 #define KMS_DRIVER_MAJOR	2
-#define KMS_DRIVER_MINOR	50
+#define KMS_DRIVER_MINOR	51
 #define KMS_DRIVER_PATCHLEVEL	0
 
 int radeon_no_wb;
Signature · 1 line
2.50.0
Applied
#5 lore raw

Re: [PATCH] drm/radeon: bump version to 2.51.0

Applied. Thanks!

Alex

Quoted 28 lines · Patrick Lerda

The version 2.51.0 adds OpenGL 4.6 compatibility to evergreen and cayman.

---
 drivers/gpu/drm/radeon/radeon_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_drv.c +2 -2
index 267f082bc430..88e821d67af7 100644
@@ -110,9 +110,10 @@
  *   2.48.0 - TA_CS_BC_BASE_ADDR allowed on SI
  *   2.49.0 - DRM_RADEON_GEM_INFO ioctl returns correct vram_size/visible values
  *   2.50.0 - Allows unaligned shader loads on CIK. (needed by OpenGL)
+ *   2.51.0 - Add evergreen/cayman OpenGL 4.6 compatibility
  */
 #define KMS_DRIVER_MAJOR       2
-#define KMS_DRIVER_MINOR       50
+#define KMS_DRIVER_MINOR       51
 #define KMS_DRIVER_PATCHLEVEL  0
 
 int radeon_no_wb;
--

2.50.0