Module: Mesa Branch: staging/23.0 Commit: 4f53644c003c64e8cd8135c536f9c7243a4b64c4 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=4f53644c003c64e8cd8135c536f9c7243a4b64c4
Author: Nanley Chery <[email protected]> Date: Mon Apr 10 14:18:56 2023 -0700 iris/bufmgr: Add and use zero_bo This simplifies the next patch. Cc: mesa-stable Reviewed-by: José Roberto de Souza <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22487> (cherry picked from commit 215fbbb6049bf6dd2f1b6fda4ab7b111b6c81436) --- .pick_status.json | 2 +- src/gallium/drivers/iris/iris_bufmgr.c | 37 +++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 9d82f91a1a6..6416dfb8ac4 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3014,7 +3014,7 @@ "description": "iris/bufmgr: Add and use zero_bo", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 4f843bffbca..9ca2d64d85d 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -778,6 +778,21 @@ flags_to_heap(struct iris_bufmgr *bufmgr, unsigned flags) } } +static bool +zero_bo(struct iris_bufmgr *bufmgr, + unsigned flags, + struct iris_bo *bo) +{ + assert(flags & BO_ALLOC_ZEROED); + + void *map = iris_bo_map(NULL, bo, MAP_WRITE | MAP_RAW); + if (!map) + return false; + + memset(map, 0, bo->size); + return true; +} + static struct iris_bo * alloc_bo_from_slabs(struct iris_bufmgr *bufmgr, const char *name, @@ -854,14 +869,9 @@ alloc_bo_from_slabs(struct iris_bufmgr *bufmgr, /* Zero the contents if necessary. If this fails, fall back to * allocating a fresh BO, which will always be zeroed by the kernel. */ - if (flags & BO_ALLOC_ZEROED) { - void *map = iris_bo_map(NULL, bo, MAP_WRITE | MAP_RAW); - if (map) { - memset(map, 0, bo->size); - } else { - pb_slab_free(slabs, &bo->slab.entry); - return NULL; - } + if ((flags & BO_ALLOC_ZEROED) && !zero_bo(bufmgr, flags, bo)) { + pb_slab_free(slabs, &bo->slab.entry); + return NULL; } return bo; @@ -944,14 +954,9 @@ alloc_bo_from_cache(struct iris_bufmgr *bufmgr, /* Zero the contents if necessary. If this fails, fall back to * allocating a fresh BO, which will always be zeroed by the kernel. */ - if (flags & BO_ALLOC_ZEROED) { - void *map = iris_bo_map(NULL, bo, MAP_WRITE | MAP_RAW); - if (map) { - memset(map, 0, bo->size); - } else { - bo_free(bo); - return NULL; - } + if ((flags & BO_ALLOC_ZEROED) && !zero_bo(bufmgr, flags, bo)) { + bo_free(bo); + return NULL; } return bo;
