zink: fix luminance/luminance-alpha emulation

We need to check the pipe_resource's format, not the texture-view
format. We're trying to overcome differences in the physical memory
layout, not the interpretation of the view.

But since we're now looking at the resource-format, we also need to take
the view-swizzle into account, because the state tracker likes to do
blits between LA and RA formats.

This had little effect in practice for luminance formats, but for
luminance-alpha formats things went kinda sideways. But luckily,
we don't actually use those formats yet, triggering state-tracker
emulation instead.

Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18596>
This commit is contained in:
Erik Faye-Lund
2022-09-14 11:31:32 +02:00
committed by Marge Bot
parent 09afab4c29
commit e7f192030c
+25 -6
View File
@@ -999,12 +999,31 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres,
} else if (util_format_is_alpha(state->format)) {
for (int i = 0; i < 4; ++i)
swizzle[i] = clamp_alpha_swizzle(swizzle[i]);
} else if (util_format_is_luminance(state->format)) {
for (int i = 0; i < 4; ++i)
swizzle[i] = clamp_luminance_swizzle(swizzle[i]);
} else if (util_format_is_luminance_alpha(state->format)) {
for (int i = 0; i < 4; ++i)
swizzle[i] = clamp_luminance_alpha_swizzle(swizzle[i]);
} else if (util_format_is_luminance(pres->format) ||
util_format_is_luminance_alpha(pres->format)) {
if (util_format_is_luminance(pres->format)) {
for (int i = 0; i < 4; ++i)
swizzle[i] = clamp_luminance_swizzle(swizzle[i]);
} else {
for (int i = 0; i < 4; ++i)
swizzle[i] = clamp_luminance_alpha_swizzle(swizzle[i]);
}
if (state->format != pres->format) {
/* luminance / luminance-alpha formats can be reinterpreted
* as red / red-alpha formats by the state-tracker, and we
* need to whack the green/blue channels here to the
* correct values for that to work.
*/
enum pipe_format linear = util_format_linear(pres->format);
if (state->format == util_format_luminance_to_red(linear)) {
assert(swizzle[1] == PIPE_SWIZZLE_X ||
swizzle[1] == PIPE_SWIZZLE_0);
assert(swizzle[2] == PIPE_SWIZZLE_X ||
swizzle[2] == PIPE_SWIZZLE_0);
swizzle[1] = swizzle[2] = PIPE_SWIZZLE_0;
} else
assert(state->format == linear);
}
}
ivci.components.r = zink_component_mapping(swizzle[0]);