From 2e084c2cb3699e846753b31bd63ed6cd18cd73f8 Mon Sep 17 00:00:00 2001 From: Jonathan Marek Date: Fri, 13 Mar 2020 11:57:23 -0400 Subject: turnip: new clear/blit implementation with shader path fallback The shader path is used to implement the following cases: * stencil aspect mask on D24S8 (for image_to_buffer,buffer_to_image) * clear/copy msaa destination (2D engine can't have msaa dest) Signed-off-by: Jonathan Marek Part-of: --- src/freedreno/vulkan/tu_formats.c | 387 +------------------------------------- 1 file changed, 7 insertions(+), 380 deletions(-) (limited to 'src/freedreno/vulkan/tu_formats.c') diff --git a/src/freedreno/vulkan/tu_formats.c b/src/freedreno/vulkan/tu_formats.c index 6a8f3d022a2..528a4176f4a 100644 --- a/src/freedreno/vulkan/tu_formats.c +++ b/src/freedreno/vulkan/tu_formats.c @@ -28,10 +28,6 @@ #include "registers/adreno_common.xml.h" #include "registers/a6xx.xml.h" -#include "util/format_r11g11b10f.h" -#include "util/format_rgb9e5.h" -#include "util/format_srgb.h" -#include "util/u_half.h" #include "vk_format.h" #include "vk_util.h" #include "drm-uapi/drm_fourcc.h" @@ -222,13 +218,13 @@ static const struct tu_native_format tu6_format_table[] = { TU6_xTx(E5B9G9R9_UFLOAT_PACK32, 9_9_9_E5_FLOAT, WZYX), /* 123 */ /* depth/stencil */ - TU6_xTC(D16_UNORM, 16_UNORM, WZYX), /* 124 */ - TU6_xTC(X8_D24_UNORM_PACK32, Z24_UNORM_S8_UINT, WZYX), /* 125 */ - TU6_xTC(D32_SFLOAT, 32_FLOAT, WZYX), /* 126 */ - TU6_xTC(S8_UINT, 8_UINT, WZYX), /* 127 */ - TU6_xxx(D16_UNORM_S8_UINT, X8Z16_UNORM, WZYX), /* 128 */ - TU6_xTC(D24_UNORM_S8_UINT, Z24_UNORM_S8_UINT, WZYX), /* 129 */ - TU6_xxx(D32_SFLOAT_S8_UINT, x, WZYX), /* 130 */ + TU6_xTC(D16_UNORM, 16_UNORM, WZYX), /* 124 */ + TU6_xTC(X8_D24_UNORM_PACK32, Z24_UNORM_S8_UINT_AS_R8G8B8A8, WZYX), /* 125 */ + TU6_xTC(D32_SFLOAT, 32_FLOAT, WZYX), /* 126 */ + TU6_xTC(S8_UINT, 8_UINT, WZYX), /* 127 */ + TU6_xxx(D16_UNORM_S8_UINT, X8Z16_UNORM, WZYX), /* 128 */ + TU6_xTC(D24_UNORM_S8_UINT, Z24_UNORM_S8_UINT_AS_R8G8B8A8, WZYX), /* 129 */ + TU6_xxx(D32_SFLOAT_S8_UINT, x, WZYX), /* 130 */ /* compressed */ TU6_xTx(BC1_RGB_UNORM_BLOCK, DXT1, WZYX), /* 131 */ @@ -348,75 +344,6 @@ tu6_format_texture(VkFormat format, enum a6xx_tile_mode tile_mode) return fmt; } -enum a6xx_2d_ifmt -tu6_fmt_to_ifmt(enum a6xx_format fmt) -{ - switch (fmt) { - case FMT6_A8_UNORM: - case FMT6_8_UNORM: - case FMT6_8_SNORM: - case FMT6_8_8_UNORM: - case FMT6_8_8_SNORM: - case FMT6_8_8_8_8_UNORM: - case FMT6_8_8_8_X8_UNORM: - case FMT6_8_8_8_8_SNORM: - case FMT6_4_4_4_4_UNORM: - case FMT6_5_5_5_1_UNORM: - case FMT6_5_6_5_UNORM: - case FMT6_Z24_UNORM_S8_UINT: - case FMT6_Z24_UNORM_S8_UINT_AS_R8G8B8A8: - return R2D_UNORM8; - - case FMT6_32_UINT: - case FMT6_32_SINT: - case FMT6_32_32_UINT: - case FMT6_32_32_SINT: - case FMT6_32_32_32_32_UINT: - case FMT6_32_32_32_32_SINT: - return R2D_INT32; - - case FMT6_16_UINT: - case FMT6_16_SINT: - case FMT6_16_16_UINT: - case FMT6_16_16_SINT: - case FMT6_16_16_16_16_UINT: - case FMT6_16_16_16_16_SINT: - case FMT6_10_10_10_2_UINT: - return R2D_INT16; - - case FMT6_8_UINT: - case FMT6_8_SINT: - case FMT6_8_8_UINT: - case FMT6_8_8_SINT: - case FMT6_8_8_8_8_UINT: - case FMT6_8_8_8_8_SINT: - return R2D_INT8; - - case FMT6_16_UNORM: - case FMT6_16_SNORM: - case FMT6_16_16_UNORM: - case FMT6_16_16_SNORM: - case FMT6_16_16_16_16_UNORM: - case FMT6_16_16_16_16_SNORM: - case FMT6_32_FLOAT: - case FMT6_32_32_FLOAT: - case FMT6_32_32_32_32_FLOAT: - return R2D_FLOAT32; - - case FMT6_16_FLOAT: - case FMT6_16_16_FLOAT: - case FMT6_16_16_16_16_FLOAT: - case FMT6_11_11_10_FLOAT: - case FMT6_10_10_10_2_UNORM: - case FMT6_10_10_10_2_UNORM_DEST: - return R2D_FLOAT16; - - default: - unreachable("bad format"); - return 0; - } -} - enum a6xx_depth_format tu6_pipe2depth(VkFormat format) { @@ -433,306 +360,6 @@ tu6_pipe2depth(VkFormat format) } } -static uint32_t -tu_pack_mask(int bits) -{ - assert(bits <= 32); - return (1ull << bits) - 1; -} - -static uint32_t -tu_pack_float32_for_unorm(float val, int bits) -{ - const uint32_t max = tu_pack_mask(bits); - if (val < 0.0f) - return 0; - else if (val > 1.0f) - return max; - else - return _mesa_lroundevenf(val * (float) max); -} - -static uint32_t -tu_pack_float32_for_snorm(float val, int bits) -{ - const int32_t max = tu_pack_mask(bits - 1); - int32_t tmp; - if (val < -1.0f) - tmp = -max; - else if (val > 1.0f) - tmp = max; - else - tmp = _mesa_lroundevenf(val * (float) max); - - return tmp & tu_pack_mask(bits); -} - -static uint32_t -tu_pack_float32_for_uscaled(float val, int bits) -{ - const uint32_t max = tu_pack_mask(bits); - if (val < 0.0f) - return 0; - else if (val > (float) max) - return max; - else - return (uint32_t) val; -} - -static uint32_t -tu_pack_float32_for_sscaled(float val, int bits) -{ - const int32_t max = tu_pack_mask(bits - 1); - const int32_t min = -max - 1; - int32_t tmp; - if (val < (float) min) - tmp = min; - else if (val > (float) max) - tmp = max; - else - tmp = (int32_t) val; - - return tmp & tu_pack_mask(bits); -} - -static uint32_t -tu_pack_uint32_for_uint(uint32_t val, int bits) -{ - return val & tu_pack_mask(bits); -} - -static uint32_t -tu_pack_int32_for_sint(int32_t val, int bits) -{ - return val & tu_pack_mask(bits); -} - -static uint32_t -tu_pack_float32_for_sfloat(float val, int bits) -{ - assert(bits == 16 || bits == 32); - return bits == 16 ? util_float_to_half(val) : fui(val); -} - -union tu_clear_component_value { - float float32; - int32_t int32; - uint32_t uint32; -}; - -static uint32_t -tu_pack_clear_component_value(union tu_clear_component_value val, - const struct util_format_channel_description *ch) -{ - uint32_t packed; - - switch (ch->type) { - case UTIL_FORMAT_TYPE_UNSIGNED: - /* normalized, scaled, or pure integer */ - if (ch->normalized) - packed = tu_pack_float32_for_unorm(val.float32, ch->size); - else if (ch->pure_integer) - packed = tu_pack_uint32_for_uint(val.uint32, ch->size); - else - packed = tu_pack_float32_for_uscaled(val.float32, ch->size); - break; - case UTIL_FORMAT_TYPE_SIGNED: - /* normalized, scaled, or pure integer */ - if (ch->normalized) - packed = tu_pack_float32_for_snorm(val.float32, ch->size); - else if (ch->pure_integer) - packed = tu_pack_int32_for_sint(val.int32, ch->size); - else - packed = tu_pack_float32_for_sscaled(val.float32, ch->size); - break; - case UTIL_FORMAT_TYPE_FLOAT: - packed = tu_pack_float32_for_sfloat(val.float32, ch->size); - break; - default: - unreachable("unexpected channel type"); - packed = 0; - break; - } - - assert((packed & tu_pack_mask(ch->size)) == packed); - return packed; -} - -static const struct util_format_channel_description * -tu_get_format_channel_description(const struct util_format_description *desc, - int comp) -{ - switch (desc->swizzle[comp]) { - case PIPE_SWIZZLE_X: - return &desc->channel[0]; - case PIPE_SWIZZLE_Y: - return &desc->channel[1]; - case PIPE_SWIZZLE_Z: - return &desc->channel[2]; - case PIPE_SWIZZLE_W: - return &desc->channel[3]; - default: - return NULL; - } -} - -static union tu_clear_component_value -tu_get_clear_component_value(const VkClearValue *val, int comp, - enum util_format_colorspace colorspace) -{ - assert(comp < 4); - - union tu_clear_component_value tmp; - switch (colorspace) { - case UTIL_FORMAT_COLORSPACE_ZS: - assert(comp < 2); - if (comp == 0) - tmp.float32 = val->depthStencil.depth; - else - tmp.uint32 = val->depthStencil.stencil; - break; - case UTIL_FORMAT_COLORSPACE_SRGB: - if (comp < 3) { - tmp.float32 = util_format_linear_to_srgb_float(val->color.float32[comp]); - break; - } - default: - assert(comp < 4); - tmp.uint32 = val->color.uint32[comp]; - break; - } - - return tmp; -} - -/** - * Pack a VkClearValue into a 128-bit buffer. \a format is respected except - * for the component order. The components are always packed in WZYX order - * (i.e., msb is white and lsb is red). - * - * Return the number of uint32_t's used. - */ -void -tu_pack_clear_value(const VkClearValue *val, VkFormat format, uint32_t buf[4]) -{ - const struct util_format_description *desc = vk_format_description(format); - - switch (format) { - case VK_FORMAT_B10G11R11_UFLOAT_PACK32: - buf[0] = float3_to_r11g11b10f(val->color.float32); - return; - case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32: - buf[0] = float3_to_rgb9e5(val->color.float32); - return; - default: - break; - } - - assert(desc && desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); - - /* S8_UINT is special and has no depth */ - const int max_components = - format == VK_FORMAT_S8_UINT ? 2 : desc->nr_channels; - - int buf_offset = 0; - int bit_shift = 0; - for (int comp = 0; comp < max_components; comp++) { - const struct util_format_channel_description *ch = - tu_get_format_channel_description(desc, comp); - if (!ch) { - assert((format == VK_FORMAT_S8_UINT && comp == 0) || - (format == VK_FORMAT_X8_D24_UNORM_PACK32 && comp == 1)); - continue; - } - - union tu_clear_component_value v = tu_get_clear_component_value( - val, comp, desc->colorspace); - - /* move to the next uint32_t when there is not enough space */ - assert(ch->size <= 32); - if (bit_shift + ch->size > 32) { - buf_offset++; - bit_shift = 0; - } - - if (bit_shift == 0) - buf[buf_offset] = 0; - - buf[buf_offset] |= tu_pack_clear_component_value(v, ch) << bit_shift; - bit_shift += ch->size; - } -} - -void -tu_2d_clear_color(const VkClearColorValue *val, VkFormat format, uint32_t buf[4]) -{ - const struct util_format_description *desc = vk_format_description(format); - - /* not supported by 2D engine, cleared as U32 */ - if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) { - buf[0] = float3_to_rgb9e5(val->float32); - return; - } - - enum a6xx_2d_ifmt ifmt = tu6_fmt_to_ifmt(tu6_get_native_format(format).fmt); - - assert(desc && (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN || - format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)); - - for (unsigned i = 0; i < desc->nr_channels; i++) { - const struct util_format_channel_description *ch = &desc->channel[i]; - - switch (ifmt) { - case R2D_INT32: - case R2D_INT16: - case R2D_INT8: - case R2D_FLOAT32: - buf[i] = val->uint32[i]; - break; - case R2D_FLOAT16: - buf[i] = util_float_to_half(val->float32[i]); - break; - case R2D_UNORM8: { - float linear = val->float32[i]; - if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB && i < 3) - linear = util_format_linear_to_srgb_float(val->float32[i]); - - if (ch->type == UTIL_FORMAT_TYPE_SIGNED) - buf[i] = tu_pack_float32_for_snorm(linear, 8); - else - buf[i] = tu_pack_float32_for_unorm(linear, 8); - } break; - default: - unreachable("unexpected ifmt"); - break; - } - } -} - -void -tu_2d_clear_zs(const VkClearDepthStencilValue *val, VkFormat format, uint32_t buf[4]) -{ - switch (format) { - case VK_FORMAT_X8_D24_UNORM_PACK32: - case VK_FORMAT_D24_UNORM_S8_UINT: - buf[0] = tu_pack_float32_for_unorm(val->depth, 24); - buf[1] = buf[0] >> 8; - buf[2] = buf[0] >> 16; - buf[3] = val->stencil; - return; - case VK_FORMAT_D16_UNORM: - case VK_FORMAT_D32_SFLOAT: - buf[0] = fui(val->depth); - return; - case VK_FORMAT_S8_UINT: - buf[0] = val->stencil; - return; - default: - unreachable("unexpected zs format"); - break; - } -} - static void tu_physical_device_get_format_properties( struct tu_physical_device *physical_device, -- cgit v1.2.3