[PATCH i-g-t 08/23] lib/rendercopy: Extract gen4_surface_format()

Ville Syrjala ville.syrjala at linux.intel.com
Mon Sep 2 14:37:43 UTC 2024


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

All the rendercopy implementation can use the same code to
determine the surface format. Extract said code to a helper.

v2: Drop stray newline

Reviewed-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 lib/rendercopy_gen4.c |  9 +--------
 lib/rendercopy_gen6.c | 10 +---------
 lib/rendercopy_gen7.c | 12 ++----------
 lib/rendercopy_gen8.c |  8 +-------
 lib/rendercopy_gen9.c |  8 +-------
 lib/surfaceformat.h   | 16 ++++++++++++++++
 6 files changed, 22 insertions(+), 41 deletions(-)

diff --git a/lib/rendercopy_gen4.c b/lib/rendercopy_gen4.c
index 8582e0efb886..b8b7e5ad7e2c 100644
--- a/lib/rendercopy_gen4.c
+++ b/lib/rendercopy_gen4.c
@@ -137,14 +137,7 @@ gen4_bind_buf(struct intel_bb *ibb, const struct intel_buf *buf, int is_dst)
 	ss = intel_bb_ptr_align(ibb, 32);
 
 	ss->ss0.surface_type = SURFACE_2D;
-	switch (buf->bpp) {
-		case 8: ss->ss0.surface_format = SURFACEFORMAT_R8_UNORM; break;
-		case 16: ss->ss0.surface_format = SURFACEFORMAT_R8G8_UNORM; break;
-		case 32: ss->ss0.surface_format = SURFACEFORMAT_B8G8R8A8_UNORM; break;
-		case 64: ss->ss0.surface_format = SURFACEFORMAT_R16G16B16A16_FLOAT; break;
-		default: igt_assert(0);
-	}
-
+	ss->ss0.surface_format = gen4_surface_format(buf->bpp);
 	ss->ss0.data_return_format = SURFACERETURNFORMAT_FLOAT32;
 	ss->ss0.color_blend = 1;
 
diff --git a/lib/rendercopy_gen6.c b/lib/rendercopy_gen6.c
index ec197661702f..0c71bd9cbf19 100644
--- a/lib/rendercopy_gen6.c
+++ b/lib/rendercopy_gen6.c
@@ -79,15 +79,7 @@ gen6_bind_buf(struct intel_bb *ibb, const struct intel_buf *buf, int is_dst)
 
 	ss = intel_bb_ptr_align(ibb, 32);
 	ss->ss0.surface_type = SURFACE_2D;
-
-	switch (buf->bpp) {
-		case 8: ss->ss0.surface_format = SURFACEFORMAT_R8_UNORM; break;
-		case 16: ss->ss0.surface_format = SURFACEFORMAT_R8G8_UNORM; break;
-		case 32: ss->ss0.surface_format = SURFACEFORMAT_B8G8R8A8_UNORM; break;
-		case 64: ss->ss0.surface_format = SURFACEFORMAT_R16G16B16A16_FLOAT; break;
-		default: igt_assert(0);
-	}
-
+	ss->ss0.surface_format = gen4_surface_format(buf->bpp);
 	ss->ss0.data_return_format = SURFACERETURNFORMAT_FLOAT32;
 	ss->ss0.color_blend = 1;
 
diff --git a/lib/rendercopy_gen7.c b/lib/rendercopy_gen7.c
index e3657b5d1035..8fcbbc21cdd8 100644
--- a/lib/rendercopy_gen7.c
+++ b/lib/rendercopy_gen7.c
@@ -57,7 +57,7 @@ gen7_bind_buf(struct intel_bb *ibb,
 	      const struct intel_buf *buf,
 	      int is_dst)
 {
-	uint32_t format, *ss;
+	uint32_t *ss;
 	uint32_t write_domain, read_domain;
 	uint64_t address;
 
@@ -65,14 +65,6 @@ gen7_bind_buf(struct intel_bb *ibb,
 	igt_assert_lte(intel_buf_width(buf), 16384);
 	igt_assert_lte(intel_buf_height(buf), 16384);
 
-	switch (buf->bpp) {
-		case 8: format = SURFACEFORMAT_R8_UNORM; break;
-		case 16: format = SURFACEFORMAT_R8G8_UNORM; break;
-		case 32: format = SURFACEFORMAT_B8G8R8A8_UNORM; break;
-		case 64: format = SURFACEFORMAT_R16G16B16A16_FLOAT; break;
-		default: igt_assert(0);
-	}
-
 	if (is_dst) {
 		write_domain = read_domain = I915_GEM_DOMAIN_RENDER;
 	} else {
@@ -84,7 +76,7 @@ gen7_bind_buf(struct intel_bb *ibb,
 
 	ss[0] = (SURFACE_2D << GEN7_SURFACE_TYPE_SHIFT |
 		 gen7_tiling_bits(buf->tiling) |
-		format << GEN7_SURFACE_FORMAT_SHIFT);
+		 gen4_surface_format(buf->bpp) << GEN7_SURFACE_FORMAT_SHIFT);
 
 	address = intel_bb_offset_reloc_with_delta(ibb, buf->handle,
 						   read_domain, write_domain,
diff --git a/lib/rendercopy_gen8.c b/lib/rendercopy_gen8.c
index 23bea56ad1ba..28c703fca393 100644
--- a/lib/rendercopy_gen8.c
+++ b/lib/rendercopy_gen8.c
@@ -88,13 +88,7 @@ gen8_bind_buf(struct intel_bb *ibb,
 	ss = intel_bb_ptr_align(ibb, 64);
 
 	ss->ss0.surface_type = SURFACE_2D;
-	switch (buf->bpp) {
-		case 8: ss->ss0.surface_format = SURFACEFORMAT_R8_UNORM; break;
-		case 16: ss->ss0.surface_format = SURFACEFORMAT_R8G8_UNORM; break;
-		case 32: ss->ss0.surface_format = SURFACEFORMAT_B8G8R8A8_UNORM; break;
-		case 64: ss->ss0.surface_format = SURFACEFORMAT_R16G16B16A16_FLOAT; break;
-		default: igt_assert(0);
-	}
+	ss->ss0.surface_format = gen4_surface_format(buf->bpp);
 	ss->ss0.render_cache_read_write = 1;
 	ss->ss0.vertical_alignment = 1; /* align 4 */
 	ss->ss0.horizontal_alignment = 1; /* align 4 */
diff --git a/lib/rendercopy_gen9.c b/lib/rendercopy_gen9.c
index 42a227916f15..11f456a70d2f 100644
--- a/lib/rendercopy_gen9.c
+++ b/lib/rendercopy_gen9.c
@@ -168,13 +168,7 @@ gen9_bind_buf(struct intel_bb *ibb, const struct intel_buf *buf, int is_dst,
 	ss = intel_bb_ptr_align(ibb, 64);
 
 	ss->ss0.surface_type = SURFACE_2D;
-	switch (buf->bpp) {
-		case 8: ss->ss0.surface_format = SURFACEFORMAT_R8_UNORM; break;
-		case 16: ss->ss0.surface_format = SURFACEFORMAT_R8G8_UNORM; break;
-		case 32: ss->ss0.surface_format = SURFACEFORMAT_B8G8R8A8_UNORM; break;
-		case 64: ss->ss0.surface_format = SURFACEFORMAT_R16G16B16A16_FLOAT; break;
-		default: igt_assert(0);
-	}
+	ss->ss0.surface_format = gen4_surface_format(buf->bpp);
 	ss->ss0.vertical_alignment = 1; /* align 4 */
 	ss->ss0.horizontal_alignment = 1; /* align 4 or HALIGN_32 on display ver >= 13*/
 
diff --git a/lib/surfaceformat.h b/lib/surfaceformat.h
index 32ea373262ca..58ef41e6d3cd 100644
--- a/lib/surfaceformat.h
+++ b/lib/surfaceformat.h
@@ -186,4 +186,20 @@
 #define SURFACE_MIPMAPLAYOUT_BELOW	0
 #define SURFACE_MIPMAPLAYOUT_RIGHT	1
 
+static inline uint32_t gen4_surface_format(int bpp)
+{
+	switch (bpp) {
+	case 8:
+		return SURFACEFORMAT_R8_UNORM;
+	case 16:
+		return SURFACEFORMAT_R8G8_UNORM;
+	case 32:
+		return SURFACEFORMAT_B8G8R8A8_UNORM;
+	case 64:
+		return SURFACEFORMAT_R16G16B16A16_FLOAT;
+	default:
+		return 0;
+	}
+}
+
 #endif
-- 
2.44.2



More information about the igt-dev mailing list