From 5542b17f7241e5ef581251e84dc6299741a85f4f Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Wed, 8 Nov 2023 15:23:48 +0100 Subject: [PATCH] util: Add new helpers for pipe resources They will be handy for drivers supporting multi-planar formats. Cc: mesa-stable Reviewed-by: Italo Nicola Part-of: (cherry picked from commit d679154dc021feb1333bf7207d8a26d9db75b921) --- .pick_status.json | 2 +- src/gallium/auxiliary/util/u_resource.c | 32 +++++++++++++++++++++++++ src/gallium/auxiliary/util/u_resource.h | 6 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index 2f736f26fd3..aa884ec0b6a 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1284,7 +1284,7 @@ "description": "util: Add new helpers for pipe resources", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/auxiliary/util/u_resource.c b/src/gallium/auxiliary/util/u_resource.c index b27c3f3c80b..728a662f09b 100644 --- a/src/gallium/auxiliary/util/u_resource.c +++ b/src/gallium/auxiliary/util/u_resource.c @@ -64,3 +64,35 @@ util_resource_size(const struct pipe_resource *res) return size; } + +/** + * Return the number of the resources. + */ +unsigned +util_resource_num(const struct pipe_resource *res) +{ + const struct pipe_resource *cur; + unsigned count; + + for (count = 0, cur = res; cur; cur = cur->next) + count++; + + return count; +} + +/** + * Return the resource at the given index. + */ +struct pipe_resource * +util_resource_at_index(const struct pipe_resource *res, unsigned index) +{ + const struct pipe_resource *cur; + unsigned count; + + for (count = 0, cur = res; cur; cur = cur->next) { + if (count++ == index) + return (struct pipe_resource *)cur; + } + + return NULL; +} diff --git a/src/gallium/auxiliary/util/u_resource.h b/src/gallium/auxiliary/util/u_resource.h index fe9c1c4d7f0..32e9d158ad0 100644 --- a/src/gallium/auxiliary/util/u_resource.h +++ b/src/gallium/auxiliary/util/u_resource.h @@ -31,6 +31,12 @@ unsigned util_resource_size(const struct pipe_resource *res); +unsigned +util_resource_num(const struct pipe_resource *res); + +struct pipe_resource * +util_resource_at_index(const struct pipe_resource *res, unsigned index); + /** * Return true if the texture target is an array type. *