From 0c283ca15627954239913de43e386aaf2a4b7675 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 15 Jun 2022 12:58:03 -0400 Subject: [PATCH] zink: add a function for getting the minimum framebuffer layers this clamps the layer count to the smallest number of layers rather than the largest cc: mesa-stable Reviewed-by: Adam Jackson Part-of: (cherry picked from commit f74df6205d245491a8a54ffa6e737f22b9b00fb4) Conflicts: src/gallium/drivers/zink/zink_framebuffer.h --- .pick_status.json | 2 +- src/gallium/drivers/zink/zink_framebuffer.c | 23 +++++++++++++++++++++ src/gallium/drivers/zink/zink_framebuffer.h | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index fe8b2b4058b..cd8a0908a05 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -895,7 +895,7 @@ "description": "zink: add a function for getting the minimum framebuffer layers", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/gallium/drivers/zink/zink_framebuffer.c b/src/gallium/drivers/zink/zink_framebuffer.c index fd21a695c95..99aead406ae 100644 --- a/src/gallium/drivers/zink/zink_framebuffer.c +++ b/src/gallium/drivers/zink/zink_framebuffer.c @@ -378,3 +378,26 @@ zink_get_framebuffer(struct zink_context *ctx) return fb; } + +/* same as u_framebuffer_get_num_layers, but clamp to lowest layer count */ +unsigned +zink_framebuffer_get_num_layers(const struct pipe_framebuffer_state *fb) +{ + unsigned i, num_layers = UINT32_MAX; + if (!(fb->nr_cbufs || fb->zsbuf)) + return MAX2(fb->layers, 1); + + for (i = 0; i < fb->nr_cbufs; i++) { + if (fb->cbufs[i]) { + unsigned num = fb->cbufs[i]->u.tex.last_layer - + fb->cbufs[i]->u.tex.first_layer + 1; + num_layers = MIN2(num_layers, num); + } + } + if (fb->zsbuf) { + unsigned num = fb->zsbuf->u.tex.last_layer - + fb->zsbuf->u.tex.first_layer + 1; + num_layers = MIN2(num_layers, num); + } + return MAX2(num_layers, 1); +} diff --git a/src/gallium/drivers/zink/zink_framebuffer.h b/src/gallium/drivers/zink/zink_framebuffer.h index 4fb8bf67b90..d157be96ee5 100644 --- a/src/gallium/drivers/zink/zink_framebuffer.h +++ b/src/gallium/drivers/zink/zink_framebuffer.h @@ -95,4 +95,8 @@ zink_get_framebuffer_imageless(struct zink_context *ctx); struct zink_framebuffer * zink_get_framebuffer(struct zink_context *ctx); + +unsigned +zink_framebuffer_get_num_layers(const struct pipe_framebuffer_state *fb); + #endif