diff --git a/src/amd/common/ac_formats.c b/src/amd/common/ac_formats.c index 74c0e4e9af2..6f708f199f2 100644 --- a/src/amd/common/ac_formats.c +++ b/src/amd/common/ac_formats.c @@ -451,3 +451,39 @@ ac_is_zs_format_supported(enum pipe_format format) { return ac_translate_dbformat(format) != V_028040_Z_INVALID; } + +uint32_t +ac_border_color_swizzle(const struct util_format_description *desc) +{ + unsigned bc_swizzle = V_008F20_BC_SWIZZLE_XYZW; + + if (desc->format == PIPE_FORMAT_S8_UINT) { + /* Swizzle of 8-bit stencil format is defined as _x__ but the hw expects XYZW. */ + assert(desc->swizzle[1] == PIPE_SWIZZLE_X); + return bc_swizzle; + } + + if (desc->swizzle[3] == PIPE_SWIZZLE_X) { + /* For the pre-defined border color values (white, opaque + * black, transparent black), the only thing that matters is + * that the alpha channel winds up in the correct place + * (because the RGB channels are all the same) so either of + * these enumerations will work. + */ + if (desc->swizzle[2] == PIPE_SWIZZLE_Y) + bc_swizzle = V_008F20_BC_SWIZZLE_WZYX; + else + bc_swizzle = V_008F20_BC_SWIZZLE_WXYZ; + } else if (desc->swizzle[0] == PIPE_SWIZZLE_X) { + if (desc->swizzle[1] == PIPE_SWIZZLE_Y) + bc_swizzle = V_008F20_BC_SWIZZLE_XYZW; + else + bc_swizzle = V_008F20_BC_SWIZZLE_XWYZ; + } else if (desc->swizzle[1] == PIPE_SWIZZLE_X) { + bc_swizzle = V_008F20_BC_SWIZZLE_YXWZ; + } else if (desc->swizzle[2] == PIPE_SWIZZLE_X) { + bc_swizzle = V_008F20_BC_SWIZZLE_ZYXW; + } + + return bc_swizzle; +} diff --git a/src/amd/common/ac_formats.h b/src/amd/common/ac_formats.h index 761e052c624..76af48e1a8f 100644 --- a/src/amd/common/ac_formats.h +++ b/src/amd/common/ac_formats.h @@ -52,6 +52,9 @@ ac_translate_dbformat(enum pipe_format format); bool ac_is_zs_format_supported(enum pipe_format format); +uint32_t +ac_border_color_swizzle(const struct util_format_description *desc); + #ifdef __cplusplus } #endif diff --git a/src/amd/vulkan/radv_image_view.c b/src/amd/vulkan/radv_image_view.c index 4fb0480e7c9..dd204478805 100644 --- a/src/amd/vulkan/radv_image_view.c +++ b/src/amd/vulkan/radv_image_view.c @@ -17,44 +17,9 @@ #include "radv_image.h" #include "ac_descriptors.h" +#include "ac_formats.h" #include "gfx10_format_table.h" -static unsigned -gfx9_border_color_swizzle(const struct util_format_description *desc) -{ - unsigned bc_swizzle = V_008F20_BC_SWIZZLE_XYZW; - - if (desc->format == PIPE_FORMAT_S8_UINT) { - /* Swizzle of 8-bit stencil format is defined as _x__ but the hw expects XYZW. */ - assert(desc->swizzle[1] == PIPE_SWIZZLE_X); - return bc_swizzle; - } - - if (desc->swizzle[3] == PIPE_SWIZZLE_X) { - /* For the pre-defined border color values (white, opaque - * black, transparent black), the only thing that matters is - * that the alpha channel winds up in the correct place - * (because the RGB channels are all the same) so either of - * these enumerations will work. - */ - if (desc->swizzle[2] == PIPE_SWIZZLE_Y) - bc_swizzle = V_008F20_BC_SWIZZLE_WZYX; - else - bc_swizzle = V_008F20_BC_SWIZZLE_WXYZ; - } else if (desc->swizzle[0] == PIPE_SWIZZLE_X) { - if (desc->swizzle[1] == PIPE_SWIZZLE_Y) - bc_swizzle = V_008F20_BC_SWIZZLE_XYZW; - else - bc_swizzle = V_008F20_BC_SWIZZLE_XWYZ; - } else if (desc->swizzle[1] == PIPE_SWIZZLE_X) { - bc_swizzle = V_008F20_BC_SWIZZLE_YXWZ; - } else if (desc->swizzle[2] == PIPE_SWIZZLE_X) { - bc_swizzle = V_008F20_BC_SWIZZLE_ZYXW; - } - - return bc_swizzle; -} - static unsigned radv_tex_dim(VkImageType image_type, VkImageViewType view_type, unsigned nr_layers, unsigned nr_samples, bool is_storage_image, bool gfx9) @@ -200,7 +165,7 @@ gfx10_make_texture_descriptor(struct radv_device *device, struct radv_image *ima S_00A00C_DST_SEL_Z(radv_map_swizzle(swizzle[2])) | S_00A00C_DST_SEL_W(radv_map_swizzle(swizzle[3])) | S_00A00C_BASE_LEVEL(image->vk.samples > 1 ? 0 : first_level) | S_00A00C_LAST_LEVEL_GFX10(image->vk.samples > 1 ? util_logbase2(image->vk.samples) : last_level) | - S_00A00C_BC_SWIZZLE(gfx9_border_color_swizzle(desc)) | S_00A00C_TYPE(type); + S_00A00C_BC_SWIZZLE(ac_border_color_swizzle(desc)) | S_00A00C_TYPE(type); /* Depth is the the last accessible layer on gfx9+. The hw doesn't need * to know the total number of layers. */ @@ -343,7 +308,7 @@ gfx6_make_texture_descriptor(struct radv_device *device, struct radv_image *imag state[7] = 0; if (pdev->info.gfx_level == GFX9) { - unsigned bc_swizzle = gfx9_border_color_swizzle(desc); + unsigned bc_swizzle = ac_border_color_swizzle(desc); /* Depth is the last accessible layer on Gfx9. * The hw doesn't need to know the total number of layers. diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index d9af5f0d681..7db9b161352 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -4487,35 +4487,6 @@ void si_make_buffer_descriptor(struct si_screen *screen, struct si_resource *buf } } -static unsigned gfx9_border_color_swizzle(const unsigned char swizzle[4]) -{ - unsigned bc_swizzle = V_008F20_BC_SWIZZLE_XYZW; - - if (swizzle[3] == PIPE_SWIZZLE_X) { - /* For the pre-defined border color values (white, opaque - * black, transparent black), the only thing that matters is - * that the alpha channel winds up in the correct place - * (because the RGB channels are all the same) so either of - * these enumerations will work. - */ - if (swizzle[2] == PIPE_SWIZZLE_Y) - bc_swizzle = V_008F20_BC_SWIZZLE_WZYX; - else - bc_swizzle = V_008F20_BC_SWIZZLE_WXYZ; - } else if (swizzle[0] == PIPE_SWIZZLE_X) { - if (swizzle[1] == PIPE_SWIZZLE_Y) - bc_swizzle = V_008F20_BC_SWIZZLE_XYZW; - else - bc_swizzle = V_008F20_BC_SWIZZLE_XWYZ; - } else if (swizzle[1] == PIPE_SWIZZLE_X) { - bc_swizzle = V_008F20_BC_SWIZZLE_YXWZ; - } else if (swizzle[2] == PIPE_SWIZZLE_X) { - bc_swizzle = V_008F20_BC_SWIZZLE_ZYXW; - } - - return bc_swizzle; -} - /** * Translate the parameters to an image descriptor for CDNA image emulation. * In this function, we choose our own image descriptor format because we emulate image opcodes @@ -4716,7 +4687,7 @@ static void gfx10_make_texture_descriptor( util_format_is_compressed(res->format) && !util_format_is_compressed(pipe_format)) | S_00A00C_LAST_LEVEL_GFX12(field_last_level) | - S_00A00C_BC_SWIZZLE(gfx9_border_color_swizzle(desc->swizzle)) | + S_00A00C_BC_SWIZZLE(ac_border_color_swizzle(desc)) | S_00A00C_TYPE(type); /* Depth is the the last accessible layer on gfx9+. The hw doesn't need * to know the total number of layers. @@ -4741,7 +4712,7 @@ static void gfx10_make_texture_descriptor( S_00A00C_DST_SEL_W(si_map_swizzle(swizzle[3])) | S_00A00C_BASE_LEVEL(res->nr_samples > 1 ? 0 : first_level) | S_00A00C_LAST_LEVEL_GFX10(res->nr_samples > 1 ? util_logbase2(res->nr_samples) : last_level) | - S_00A00C_BC_SWIZZLE(gfx9_border_color_swizzle(desc->swizzle)) | S_00A00C_TYPE(type); + S_00A00C_BC_SWIZZLE(ac_border_color_swizzle(desc)) | S_00A00C_TYPE(type); /* Depth is the the last accessible layer on gfx9+. The hw doesn't need * to know the total number of layers. */ @@ -4899,7 +4870,7 @@ static void si_make_texture_descriptor(struct si_screen *screen, struct si_textu state[7] = 0; if (screen->info.gfx_level == GFX9) { - unsigned bc_swizzle = gfx9_border_color_swizzle(desc->swizzle); + unsigned bc_swizzle = ac_border_color_swizzle(desc); /* Depth is the the last accessible layer on Gfx9. * The hw doesn't need to know the total number of layers.