mesa/st: Add st_texture_image_resource_level
authorNanley Chery <nanley.g.chery@intel.com>
Mon, 24 Oct 2022 23:44:03 +0000 (16:44 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 10 Feb 2023 01:40:47 +0000 (01:40 +0000)
Returns the level of the gl_texture_image with respect to the resource
it's allocated within. Example: returns 0 for non-finalized texture.

Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19827>

src/mesa/state_tracker/st_texture.c
src/mesa/state_tracker/st_texture.h

index 3f295bf..e16bc7c 100644 (file)
@@ -259,6 +259,21 @@ st_texture_image_insert_transfer(struct gl_texture_image *stImage,
    stImage->transfer[index].transfer = transfer;
 }
 
+/* See st_texture.h for more information. */
+GLuint
+st_texture_image_resource_level(struct gl_texture_image *stImage)
+{
+   /* An image for a non-finalized texture object only has a single level. */
+   if (stImage->pt != stImage->TexObject->pt)
+      return 0;
+
+   /* An immutable texture object may have views with an LOD offset. */
+   if (stImage->TexObject->Immutable)
+      return stImage->Level + stImage->TexObject->Attrib.MinLevel;
+
+   return stImage->Level;
+}
+
 /**
  * Map a texture image and return the address for a particular 2D face/slice/
  * layer.  The stImage indicates the cube face and mipmap level.  The slice
index 064200d..1e5c782 100644 (file)
@@ -186,6 +186,13 @@ st_texture_image_insert_transfer(struct gl_texture_image *stImage,
                                  unsigned index,
                                  struct pipe_transfer *transfer);
 
+/**
+ * Returns the level of the gl_texture_image with respect to the resource it
+ * is allocated within. Example: returns 0 for non-finalized texture.
+ */
+GLuint
+st_texture_image_resource_level(struct gl_texture_image *stImage);
+
 /* Return a pointer to an image within a texture.  Return image stride as
  * well.
  */