From 59b0105e658b757b152a55dc6f062b16b7324ef4 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 18 Feb 2022 09:43:24 -0500 Subject: [PATCH] zink: clamp 3d/array shader images to lower dimensionality using layer counts this creates the view type expected by the shader instead of doing weird stuff like trying to create a 3D imageview with layers > 1 Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_context.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index c5cfd025215..44254946877 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -1327,11 +1327,29 @@ create_image_surface(struct zink_context *ctx, const struct pipe_image_view *vie { struct zink_resource *res = zink_resource(view->resource); struct pipe_surface tmpl = {0}; - enum pipe_texture_target target = res->base.b.target == PIPE_TEXTURE_3D ? PIPE_TEXTURE_2D : res->base.b.target; + enum pipe_texture_target target = res->base.b.target; tmpl.format = view->format; tmpl.u.tex.level = view->u.tex.level; tmpl.u.tex.first_layer = view->u.tex.first_layer; tmpl.u.tex.last_layer = view->u.tex.last_layer; + unsigned depth = 1 + tmpl.u.tex.last_layer - tmpl.u.tex.first_layer; + switch (target) { + case PIPE_TEXTURE_3D: + if (depth < res->base.b.depth0) { + assert(depth == 1); + target = PIPE_TEXTURE_2D; + } else { + assert(tmpl.u.tex.first_layer == 0); + tmpl.u.tex.last_layer = 0; + } + break; + case PIPE_TEXTURE_2D_ARRAY: + case PIPE_TEXTURE_1D_ARRAY: + if (depth < res->base.b.array_size && depth == 1) + target = target == PIPE_TEXTURE_2D_ARRAY ? PIPE_TEXTURE_2D : PIPE_TEXTURE_1D; + break; + default: break; + } VkImageViewCreateInfo ivci = create_ivci(zink_screen(ctx->base.screen), res, &tmpl, target); struct pipe_surface *psurf = zink_get_surface(ctx, view->resource, &tmpl, &ivci); if (!psurf)