Mesa (main): iris: Use a tiny table to map mmap modes to offsets

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 12 20:00:55 UTC 2021


Module: Mesa
Branch: main
Commit: 24031700a7f6f38826d3a2ff4c5aa4b7c773c919
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=24031700a7f6f38826d3a2ff4c5aa4b7c773c919

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Wed Jul 14 13:17:03 2021 -0500

iris: Use a tiny table to map mmap modes to offsets

This is a little more obvious than the if-ladder.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11888>

---

 src/gallium/drivers/iris/iris_bufmgr.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c
index f5f0ec0e9d3..dbe11e454bc 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.c
+++ b/src/gallium/drivers/iris/iris_bufmgr.c
@@ -1043,12 +1043,13 @@ iris_bo_gem_mmap_offset(struct pipe_debug_callback *dbg, struct iris_bo *bo)
       .handle = bo->gem_handle,
    };
 
-   if (bo->mmap_mode == IRIS_MMAP_WB)
-      mmap_arg.flags = I915_MMAP_OFFSET_WB;
-   else if (bo->mmap_mode == IRIS_MMAP_WC)
-      mmap_arg.flags = I915_MMAP_OFFSET_WC;
-   else
-      mmap_arg.flags = I915_MMAP_OFFSET_UC;
+   static const uint32_t mmap_offset_for_mode[] = {
+      [IRIS_MMAP_UC]    = I915_MMAP_OFFSET_UC,
+      [IRIS_MMAP_WC]    = I915_MMAP_OFFSET_WC,
+      [IRIS_MMAP_WB]    = I915_MMAP_OFFSET_WB,
+   };
+   assert(bo->mmap_mode < ARRAY_SIZE(mmap_offset_for_mode));
+   mmap_arg.flags = mmap_offset_for_mode[bo->mmap_mode];
 
    /* Get the fake offset back */
    int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP_OFFSET, &mmap_arg);



More information about the mesa-commit mailing list