From 24031700a7f6f38826d3a2ff4c5aa4b7c773c919 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 14 Jul 2021 13:17:03 -0500 Subject: [PATCH] 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 Part-of: --- 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 f5f0ec0..dbe11e4 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); -- 2.7.4