kk: Fix emulated format's swizzle

Signed-off-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38831>
This commit is contained in:
Aitor Camacho
2025-12-05 20:49:24 +09:00
committed by Marge Bot
parent dd4a1a50f5
commit 4a58046caa
7 changed files with 25 additions and 24 deletions
+4 -4
View File
@@ -89,10 +89,10 @@ kk_CreateBufferView(VkDevice _device, const VkBufferViewCreateInfo *pCreateInfo,
.format = {.pipe = p_format, .mtl = supported_format->mtl_pixel_format},
.swizzle =
{
.red = supported_format->swizzle.red,
.green = supported_format->swizzle.green,
.blue = supported_format->swizzle.blue,
.alpha = supported_format->swizzle.alpha,
.red = supported_format->unswizzle.red,
.green = supported_format->unswizzle.green,
.blue = supported_format->unswizzle.blue,
.alpha = supported_format->unswizzle.alpha,
},
.linear_stride_B = view->vk.range,
};
+2 -2
View File
@@ -155,8 +155,8 @@ vk_clear_color_value_to_mtl_clear_color(union VkClearColorValue color,
const struct kk_va_format *supported_format = kk_get_va_format(format);
struct mtl_clear_color swizzled_color;
for (uint32_t i = 0u; i < 4; ++i)
swizzled_color.channel[i] =
value.channel[supported_format->swizzle.channels[i]];
swizzled_color.channel[supported_format->unswizzle.channels[i]] =
value.channel[i];
return swizzled_color;
}
+4 -4
View File
@@ -105,7 +105,7 @@
}
#define MTL_SWIZZLE_IDENTITY \
.swizzle = { \
.unswizzle = { \
.red = PIPE_SWIZZLE_X, \
.green = PIPE_SWIZZLE_Y, \
.blue = PIPE_SWIZZLE_Z, \
@@ -113,7 +113,7 @@
}
#define MTL_SWIZZLE_ABGR \
.swizzle = { \
.unswizzle = { \
.red = PIPE_SWIZZLE_W, \
.green = PIPE_SWIZZLE_Z, \
.blue = PIPE_SWIZZLE_Y, \
@@ -121,7 +121,7 @@
}
#define MTL_SWIZZLE_BGRA \
.swizzle = { \
.unswizzle = { \
.red = PIPE_SWIZZLE_Z, \
.green = PIPE_SWIZZLE_Y, \
.blue = PIPE_SWIZZLE_X, \
@@ -129,7 +129,7 @@
}
#define MTL_SWIZZLE_RGB1 \
.swizzle = { \
.unswizzle = { \
.red = PIPE_SWIZZLE_X, \
.green = PIPE_SWIZZLE_Y, \
.blue = PIPE_SWIZZLE_Z, \
+3 -2
View File
@@ -17,7 +17,8 @@ enum pipe_format;
enum mtl_pixel_format;
struct kk_va_format {
/* Would love to use enum pipe_swizzle, but it's bigger than the required
/* Transforms from the native format to the emulated format.
* Would love to use enum pipe_swizzle, but it's bigger than the required
* type for util_format_compose_swizzles... */
struct {
union {
@@ -29,7 +30,7 @@ struct kk_va_format {
};
uint8_t channels[4];
};
} swizzle;
} unswizzle;
uint32_t mtl_pixel_format;
uint8_t bit_widths;
uint8_t filter : 1;
+4 -4
View File
@@ -94,10 +94,10 @@ kk_image_layout_init(const struct kk_device *dev,
create_info->usage, create_info->flags, supported_format->atomic);
layout->format.pipe = format;
layout->format.mtl = supported_format->mtl_pixel_format;
layout->swizzle.red = supported_format->swizzle.red;
layout->swizzle.green = supported_format->swizzle.green;
layout->swizzle.blue = supported_format->swizzle.blue;
layout->swizzle.alpha = supported_format->swizzle.alpha;
layout->swizzle.red = supported_format->unswizzle.red;
layout->swizzle.green = supported_format->unswizzle.green;
layout->swizzle.blue = supported_format->unswizzle.blue;
layout->swizzle.alpha = supported_format->unswizzle.alpha;
layout->sample_count_sa = create_info->samples;
mtl_heap_texture_size_and_align_with_descriptor(dev->mtl_handle, layout);
+1 -1
View File
@@ -119,7 +119,7 @@ kk_image_view_init(struct kk_device *dev, struct kk_image_view *view,
vk_swizzle_to_pipe(view->vk.swizzle.g),
vk_swizzle_to_pipe(view->vk.swizzle.b),
vk_swizzle_to_pipe(view->vk.swizzle.a)};
util_format_compose_swizzles(supported_format->swizzle.channels,
util_format_compose_swizzles(supported_format->unswizzle.channels,
view_swizzle, view_layout.swizzle.channels);
/* When sampling a depth/stencil texture Metal returns (d, d, d, 1), but
+7 -7
View File
@@ -252,21 +252,21 @@ kk_nir_swizzle_fragment_output(nir_builder *b, nir_intrinsic_instr *intrin,
/* Check if we have to apply any swizzle */
if (!supported_format->is_native) {
unsigned channel_swizzle[] = {
supported_format->swizzle.red, supported_format->swizzle.green,
supported_format->swizzle.blue, supported_format->swizzle.alpha};
unsigned channel_unswizzle[] = {
supported_format->unswizzle.red, supported_format->unswizzle.green,
supported_format->unswizzle.blue, supported_format->unswizzle.alpha};
if (intrin->intrinsic == nir_intrinsic_store_output) {
unsigned channel_swizzle[4] = {0u};
for (uint32_t i = 0u; i < 4; ++i)
channel_swizzle[channel_unswizzle[i]] = i;
b->cursor = nir_before_instr(&intrin->instr);
nir_def *to_replace = intrin->src[0].ssa;
nir_def *swizzled = nir_swizzle(b, to_replace, channel_swizzle,
to_replace->num_components);
nir_src_rewrite(&intrin->src[0], swizzled);
} else {
unsigned channel_unswizzle[4] = {0u};
for (uint32_t i = 0u; i < 4; ++i)
channel_unswizzle[channel_swizzle[i]] = i;
b->cursor = nir_after_instr(&intrin->instr);
nir_def *to_replace = &intrin->def;
nir_def *swizzled = nir_swizzle(b, to_replace, channel_unswizzle,