util: Add new helpers for pipe resources

They will be handy for drivers supporting multi-planar formats.

Cc: mesa-stable
Reviewed-by: Italo Nicola <italonicola@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26109>
This commit is contained in:
Robert Mader 2023-11-08 15:23:48 +01:00 committed by Marge Bot
parent 94e867e4a6
commit d679154dc0
2 changed files with 38 additions and 0 deletions

View file

@ -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;
}

View file

@ -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.
*