[igt-dev] [PATCH i-g-t v32 33/39] lib/intel_bufops: address review comments (alignment, unmap/flush)
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Fri Aug 28 13:13:48 UTC 2020
1. relax alignment to handle 8bpp surfaces
2. add intel_buf_flush_and_unmap() to avoid unnecessary GEM_SW_FINISH
ioctl() when buffer is not framebuffer
3. add protecting asserts
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
lib/intel_bufops.c | 20 ++++++++++++++++----
lib/intel_bufops.h | 1 +
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/lib/intel_bufops.c b/lib/intel_bufops.c
index 871a28da..714e1aaa 100644
--- a/lib/intel_bufops.c
+++ b/lib/intel_bufops.c
@@ -717,7 +717,7 @@ static void __intel_buf_init(struct buf_ops *bops,
igt_assert(buf);
igt_assert(width > 0 && height > 0);
igt_assert(bpp == 8 || bpp == 16 || bpp == 32 || bpp == 64);
- igt_assert(alignment % 2 == 0);
+ igt_assert(alignment >= 0);
memset(buf, 0, sizeof(*buf));
@@ -762,7 +762,7 @@ static void __intel_buf_init(struct buf_ops *bops,
tile_width = get_stride(devid, tiling);
buf->surface[0].stride = ALIGN(width * (bpp / 8), tile_width);
} else {
- buf->surface[0].stride = ALIGN(width * (bpp / 8), alignment ?: 2);
+ buf->surface[0].stride = ALIGN(width * (bpp / 8), alignment ?: 1);
}
buf->surface[0].size = buf->surface[0].stride * height;
@@ -870,6 +870,7 @@ struct intel_buf *intel_buf_create(struct buf_ops *bops,
void intel_buf_destroy(struct intel_buf *buf)
{
igt_assert(buf);
+ igt_assert(buf->ptr == NULL);
intel_buf_close(buf->bops, buf);
free(buf);
@@ -879,6 +880,7 @@ void *intel_buf_cpu_map(struct intel_buf *buf, bool write)
{
int i915 = buf_ops_get_fd(buf->bops);
+ igt_assert(buf);
igt_assert(buf->ptr == NULL); /* already mapped */
buf->cpu_write = write;
@@ -897,6 +899,7 @@ void *intel_buf_device_map(struct intel_buf *buf, bool write)
{
int i915 = buf_ops_get_fd(buf->bops);
+ igt_assert(buf);
igt_assert(buf->ptr == NULL); /* already mapped */
buf->ptr = gem_mmap__device_coherent(i915, buf->handle, 0,
@@ -912,13 +915,22 @@ void *intel_buf_device_map(struct intel_buf *buf, bool write)
void intel_buf_unmap(struct intel_buf *buf)
{
+ igt_assert(buf);
+ igt_assert(buf->ptr);
+
+ munmap(buf->ptr, buf->surface[0].size);
+ buf->ptr = NULL;
+}
+
+void intel_buf_flush_and_unmap(struct intel_buf *buf)
+{
+ igt_assert(buf);
igt_assert(buf->ptr);
if (buf->cpu_write)
gem_sw_finish(buf_ops_get_fd(buf->bops), buf->handle);
- munmap(buf->ptr, buf->surface[0].size);
- buf->ptr = NULL;
+ intel_buf_unmap(buf);
}
void intel_buf_print(const struct intel_buf *buf)
diff --git a/lib/intel_bufops.h b/lib/intel_bufops.h
index 75b5f5f6..0a8536ba 100644
--- a/lib/intel_bufops.h
+++ b/lib/intel_bufops.h
@@ -127,6 +127,7 @@ void intel_buf_destroy(struct intel_buf *buf);
void *intel_buf_cpu_map(struct intel_buf *buf, bool write);
void *intel_buf_device_map(struct intel_buf *buf, bool write);
void intel_buf_unmap(struct intel_buf *buf);
+void intel_buf_flush_and_unmap(struct intel_buf *buf);
void intel_buf_print(const struct intel_buf *buf);
void intel_buf_dump(const struct intel_buf *buf, const char *filename);
--
2.26.0
More information about the igt-dev
mailing list