Module: Mesa Branch: main Commit: 567bdf2e8f2713039e0f551450ee59839768f5e4 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=567bdf2e8f2713039e0f551450ee59839768f5e4
Author: Mike Blumenkrantz <[email protected]> Date: Wed May 5 09:40:51 2021 -0400 zink: clamp zs samplers to XXXX swizzle for all non-zero/one swizzles Reviewed-by: Erik Faye-Lund <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10649> --- src/gallium/drivers/zink/zink_context.c | 51 ++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index db9e8790100..cadaaaa147a 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -509,6 +509,21 @@ clamp_void_swizzle(const struct util_format_description *desc, enum pipe_swizzle return swizzle; } +ALWAYS_INLINE static enum pipe_swizzle +clamp_zs_swizzle(enum pipe_swizzle swizzle) +{ + switch (swizzle) { + case PIPE_SWIZZLE_X: + case PIPE_SWIZZLE_Y: + case PIPE_SWIZZLE_Z: + case PIPE_SWIZZLE_W: + return PIPE_SWIZZLE_X; + default: + break; + } + return swizzle; +} + static struct pipe_sampler_view * zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres, const struct pipe_sampler_view *state) @@ -530,33 +545,29 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres, ivci.image = res->obj->image; ivci.viewType = image_view_type(state->target); - ivci.components.r = component_mapping(sampler_view->base.swizzle_r); - ivci.components.g = component_mapping(sampler_view->base.swizzle_g); - ivci.components.b = component_mapping(sampler_view->base.swizzle_b); - ivci.components.a = component_mapping(sampler_view->base.swizzle_a); - ivci.subresourceRange.aspectMask = sampler_aspect_from_format(state->format); ivci.format = zink_get_format(screen, state->format); /* samplers for stencil aspects of packed formats need to always use stencil swizzle */ - if (ivci.subresourceRange.aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT) { - ivci.components.g = VK_COMPONENT_SWIZZLE_R; + if (ivci.subresourceRange.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { + ivci.components.r = component_mapping(clamp_zs_swizzle(sampler_view->base.swizzle_r)); + ivci.components.g = component_mapping(clamp_zs_swizzle(sampler_view->base.swizzle_g)); + ivci.components.b = component_mapping(clamp_zs_swizzle(sampler_view->base.swizzle_b)); + ivci.components.a = component_mapping(clamp_zs_swizzle(sampler_view->base.swizzle_a)); } else { /* if we have e.g., R8G8B8X8, then we have to ignore alpha since we're just emulating * these formats */ - if (ivci.subresourceRange.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) { - const struct util_format_description *desc = util_format_description(state->format); - if (util_format_is_rgba8_variant(desc)) { - sampler_view->base.swizzle_r = clamp_void_swizzle(desc, sampler_view->base.swizzle_r); - sampler_view->base.swizzle_g = clamp_void_swizzle(desc, sampler_view->base.swizzle_g); - sampler_view->base.swizzle_b = clamp_void_swizzle(desc, sampler_view->base.swizzle_b); - sampler_view->base.swizzle_a = clamp_void_swizzle(desc, sampler_view->base.swizzle_a); - ivci.components.r = component_mapping(sampler_view->base.swizzle_r); - ivci.components.g = component_mapping(sampler_view->base.swizzle_g); - ivci.components.b = component_mapping(sampler_view->base.swizzle_b); - ivci.components.a = component_mapping(sampler_view->base.swizzle_a); - } - } + const struct util_format_description *desc = util_format_description(state->format); + if (util_format_is_rgba8_variant(desc)) { + sampler_view->base.swizzle_r = clamp_void_swizzle(desc, sampler_view->base.swizzle_r); + sampler_view->base.swizzle_g = clamp_void_swizzle(desc, sampler_view->base.swizzle_g); + sampler_view->base.swizzle_b = clamp_void_swizzle(desc, sampler_view->base.swizzle_b); + sampler_view->base.swizzle_a = clamp_void_swizzle(desc, sampler_view->base.swizzle_a); + } + ivci.components.r = component_mapping(sampler_view->base.swizzle_r); + ivci.components.g = component_mapping(sampler_view->base.swizzle_g); + ivci.components.b = component_mapping(sampler_view->base.swizzle_b); + ivci.components.a = component_mapping(sampler_view->base.swizzle_a); } assert(ivci.format); _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
