[PATCH i-g-t 6/7] lib/intel_bufops: Add png dump helper without detiling

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Wed Feb 28 14:54:06 UTC 2024


Sometimes we need to visualy inspect tiled surface. Add appropriate
function which doesn't detile surface before writing to png.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Cc: Matthew Auld <matthew.auld at intel.com>
---
 lib/intel_bufops.c | 34 ++++++++++++++++++++++++++++++++++
 lib/intel_bufops.h |  1 +
 2 files changed, 35 insertions(+)

diff --git a/lib/intel_bufops.c b/lib/intel_bufops.c
index 67254ec107..5e2701a7dc 100644
--- a/lib/intel_bufops.c
+++ b/lib/intel_bufops.c
@@ -1337,6 +1337,40 @@ void intel_buf_write_aux_to_png(struct intel_buf *buf, const char *filename)
 
 	__intel_buf_write_to_png(buf->bops, buf, filename, true);
 }
+static void __intel_buf_raw_write_to_png(struct buf_ops *bops,
+					 struct intel_buf *buf,
+					 const char *filename)
+{
+	cairo_surface_t *surface;
+	cairo_status_t ret;
+	uint8_t *linear;
+	int format, width, height, stride;
+
+	format = CAIRO_FORMAT_RGB24;
+	width = buf->surface[0].stride / 4;
+	height = __get_aligned_height(intel_buf_height(buf),
+				      buf->bpp, buf->tiling);
+	stride = buf->surface[0].stride;
+
+	if (is_xe_device(bops->fd))
+		linear = xe_bo_map(bops->fd, buf->handle, buf->bo_size);
+	else
+		linear = gem_mmap__device_coherent(bops->fd, buf->handle,
+						   0, buf->bo_size, PROT_READ);
+	surface = cairo_image_surface_create_for_data(linear,
+						      format, width, height,
+						      stride);
+	ret = cairo_surface_write_to_png(surface, filename);
+	igt_assert(ret == CAIRO_STATUS_SUCCESS);
+	cairo_surface_destroy(surface);
+
+	munmap(linear, buf->bo_size);
+}
+
+void intel_buf_raw_write_to_png(struct intel_buf *buf, const char *filename)
+{
+	__intel_buf_raw_write_to_png(buf->bops, buf, filename);
+}
 
 static void *alloc_aligned(uint64_t size)
 {
diff --git a/lib/intel_bufops.h b/lib/intel_bufops.h
index 75e0ec2c44..363f7abaad 100644
--- a/lib/intel_bufops.h
+++ b/lib/intel_bufops.h
@@ -221,6 +221,7 @@ const char *intel_buf_set_name(struct intel_buf *buf, const char *name);
 
 void intel_buf_write_to_png(struct intel_buf *buf, const char *filename);
 void intel_buf_write_aux_to_png(struct intel_buf *buf, const char *filename);
+void intel_buf_raw_write_to_png(struct intel_buf *buf, const char *filename);
 void intel_buf_draw_pattern(struct buf_ops *bops, struct intel_buf *buf,
 			    int x, int y, int w, int h,
 			    int cx, int cy, int cw, int ch,
-- 
2.34.1



More information about the igt-dev mailing list