summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/virgl/virgl_resource.c
diff options
context:
space:
mode:
authorGurchetan Singh <[email protected]>2018-11-09 16:40:03 -0800
committerBas Nieuwenhuizen <[email protected]>2018-12-19 13:29:16 +0100
commit2a44acc83b9cefe98c35927b85411cac3108fc65 (patch)
tree9307a0a89b6302c2760fe9020c7b3e2eafdb09c1 /src/gallium/drivers/virgl/virgl_resource.c
parentf749229a8e16df4e88e2a1d30895f7741b91f1fd (diff)
virgl: move vrend_get_tex_image_offset to common code
Will be reused. Reviewed-by: Elie Tournier <[email protected]>
Diffstat (limited to 'src/gallium/drivers/virgl/virgl_resource.c')
-rw-r--r--src/gallium/drivers/virgl/virgl_resource.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/gallium/drivers/virgl/virgl_resource.c b/src/gallium/drivers/virgl/virgl_resource.c
index 4608ad0361c..b252be1ba33 100644
--- a/src/gallium/drivers/virgl/virgl_resource.c
+++ b/src/gallium/drivers/virgl/virgl_resource.c
@@ -147,3 +147,27 @@ void virgl_resource_layout(struct pipe_resource *pt,
else /* don't create guest backing store for MSAA */
metadata->total_size = 0;
}
+
+unsigned virgl_resource_offset(struct pipe_resource *pres,
+ struct virgl_resource_metadata *metadata,
+ unsigned level, unsigned layer)
+{
+ const unsigned hgt = u_minify(pres->height0, level);
+ const unsigned nblocksy = util_format_get_nblocksy(pres->format, hgt);
+ unsigned offset = metadata->level_offset[level];
+
+ if (pres->target == PIPE_TEXTURE_CUBE ||
+ pres->target == PIPE_TEXTURE_CUBE_ARRAY ||
+ pres->target == PIPE_TEXTURE_3D ||
+ pres->target == PIPE_TEXTURE_2D_ARRAY) {
+ offset += layer * nblocksy * metadata->stride[level];
+ }
+ else if (pres->target == PIPE_TEXTURE_1D_ARRAY) {
+ offset += layer * metadata->stride[level];
+ }
+ else {
+ assert(layer == 0);
+ }
+
+ return offset;
+}