#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"
-#define FMT6_x -1
-
#define TU6_FMT(vkfmt, hwfmt, swapfmt, valid) \
[VK_FORMAT_##vkfmt] = { \
.fmt = FMT6_##hwfmt, \
#define TU6_xTC(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_TEXTURE | FMT_COLOR)
#define TU6_Vxx(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_VERTEX)
#define TU6_xTx(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_TEXTURE)
-#define TU6_xxx(vk, fmt, swap) TU6_FMT(vk, x, WZYX, false)
+#define TU6_xxx(vk, fmt, swap) TU6_FMT(vk, NONE, WZYX, 0)
static const struct tu_native_format tu6_format_table[] = {
TU6_xxx(UNDEFINED, x, x), /* 0 */
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 */
TU6_xTx(ASTC_12x12_SRGB_BLOCK, ASTC_12x12, WZYX), /* 184 */
};
+#define FMT_EXT_BASE VK_FORMAT_G8B8G8R8_422_UNORM
+#undef TU6_FMT
+#define TU6_FMT(vkfmt, hwfmt, swapfmt, valid) \
+ [VK_FORMAT_##vkfmt - FMT_EXT_BASE] = { \
+ .fmt = FMT6_##hwfmt, \
+ .swap = swapfmt, \
+ .supported = valid, \
+ }
+
+static const struct tu_native_format tu6_format_table_ext[] = {
+ TU6_xTx(G8B8G8R8_422_UNORM, R8G8R8B8_422_UNORM, WZYX), /* 0 */
+ TU6_xTx(B8G8R8G8_422_UNORM, G8R8B8R8_422_UNORM, WZYX), /* 1 */
+};
+
static struct tu_native_format
tu6_get_native_format(VkFormat format)
{
struct tu_native_format fmt = {};
- if (format >= ARRAY_SIZE(tu6_format_table))
- return fmt;
-
- if (!tu6_format_table[format].supported)
- return fmt;
+ if (format < ARRAY_SIZE(tu6_format_table)) {
+ fmt = tu6_format_table[format];
+ } else if (format >= FMT_EXT_BASE) {
+ unsigned idx = format - FMT_EXT_BASE;
+ if (idx < ARRAY_SIZE(tu6_format_table_ext))
+ fmt = tu6_format_table_ext[idx];
+ }
- if (vk_format_to_pipe_format(format) == PIPE_FORMAT_NONE) {
+ if (fmt.supported && vk_format_to_pipe_format(format) == PIPE_FORMAT_NONE) {
tu_finishme("vk_format %d missing matching pipe format.\n", format);
- return fmt;
+ fmt.supported = false;
}
- return tu6_format_table[format];
+ return fmt;
}
struct tu_native_format
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)
-{
- switch (format) {
- case VK_FORMAT_D16_UNORM:
- return DEPTH6_16;
- case VK_FORMAT_X8_D24_UNORM_PACK32:
- case VK_FORMAT_D24_UNORM_S8_UINT:
- return DEPTH6_24_8;
- case VK_FORMAT_D32_SFLOAT:
- return DEPTH6_32;
- default:
- return ~0;
- }
-}
-
-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,
buffer |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
if (native_fmt.supported & FMT_TEXTURE) {
- optimal |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
+ optimal |= VK_FORMAT_FEATURE_BLIT_SRC_BIT |
+ VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
VK_FORMAT_FEATURE_TRANSFER_DST_BIT |
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
- VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
+ VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
+ VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT |
+ VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT |
+ VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT;
+
buffer |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
+
+ if (desc->layout != UTIL_FORMAT_LAYOUT_SUBSAMPLED)
+ optimal |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT;
+
+ if (physical_device->supported_extensions.EXT_filter_cubic)
+ optimal |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_EXT;
}
if (native_fmt.supported & FMT_COLOR) {
assert(native_fmt.supported & FMT_TEXTURE);
optimal |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
- VK_FORMAT_FEATURE_BLIT_SRC_BIT |
VK_FORMAT_FEATURE_BLIT_DST_BIT;
+
+ /* IBO's don't have a swap field at all, so swapped formats can't be
+ * supported, even with linear images.
+ *
+ * TODO: See if setting the swap field from the tex descriptor works,
+ * after we enable shaderStorageImageReadWithoutFormat and there are
+ * tests for these formats.
+ */
+ if (native_fmt.swap == WZYX) {
+ optimal |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
+ buffer |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
+ }
+
+ /* TODO: The blob also exposes these for R16G16_UINT/R16G16_SINT, but we
+ * don't have any tests for those.
+ */
+ if (format == VK_FORMAT_R32_UINT || format == VK_FORMAT_R32_SINT) {
+ optimal |= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
+ buffer |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
+ }
+
+ if (vk_format_is_float(format) ||
+ vk_format_is_unorm(format) ||
+ vk_format_is_snorm(format) ||
+ vk_format_is_srgb(format)) {
+ optimal |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
+ }
}
/* For the most part, we can do anything with a linear image that we could
tu_get_image_format_properties(
struct tu_physical_device *physical_device,
const VkPhysicalDeviceImageFormatInfo2 *info,
- VkImageFormatProperties *pImageFormatProperties)
-
+ VkImageFormatProperties *pImageFormatProperties,
+ VkFormatFeatureFlags *p_feature_flags)
{
VkFormatProperties format_props;
VkFormatFeatureFlags format_feature_flags;
.maxResourceSize = UINT32_MAX,
};
+ if (p_feature_flags)
+ *p_feature_flags = format_feature_flags;
+
return VK_SUCCESS;
unsupported:
*pImageFormatProperties = (VkImageFormatProperties) {
};
return tu_get_image_format_properties(physical_device, &info,
- pImageFormatProperties);
+ pImageFormatProperties, NULL);
}
static VkResult
{
TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice);
const VkPhysicalDeviceExternalImageFormatInfo *external_info = NULL;
+ const VkPhysicalDeviceImageViewImageFormatInfoEXT *image_view_info = NULL;
VkExternalImageFormatProperties *external_props = NULL;
+ VkFilterCubicImageViewImageFormatPropertiesEXT *cubic_props = NULL;
+ VkFormatFeatureFlags format_feature_flags;
+ VkSamplerYcbcrConversionImageFormatProperties *ycbcr_props = NULL;
VkResult result;
- result = tu_get_image_format_properties(
- physical_device, base_info, &base_props->imageFormatProperties);
+ result = tu_get_image_format_properties(physical_device,
+ base_info, &base_props->imageFormatProperties, &format_feature_flags);
if (result != VK_SUCCESS)
return result;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO:
external_info = (const void *) s;
break;
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_IMAGE_FORMAT_INFO_EXT:
+ image_view_info = (const void *) s;
+ break;
default:
break;
}
case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES:
external_props = (void *) s;
break;
+ case VK_STRUCTURE_TYPE_FILTER_CUBIC_IMAGE_VIEW_IMAGE_FORMAT_PROPERTIES_EXT:
+ cubic_props = (void *) s;
+ break;
+ case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES:
+ ycbcr_props = (void *) s;
+ break;
default:
break;
}
goto fail;
}
+ if (cubic_props) {
+ /* note: blob only allows cubic filtering for 2D and 2D array views
+ * its likely we can enable it for 1D and CUBE, needs testing however
+ */
+ if ((image_view_info->imageViewType == VK_IMAGE_VIEW_TYPE_2D ||
+ image_view_info->imageViewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY) &&
+ (format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_EXT)) {
+ cubic_props->filterCubic = true;
+ cubic_props->filterCubicMinmax = true;
+ } else {
+ cubic_props->filterCubic = false;
+ cubic_props->filterCubicMinmax = false;
+ }
+ }
+
+ if (ycbcr_props)
+ ycbcr_props->combinedImageSamplerDescriptorCount = 1;
+
return VK_SUCCESS;
fail:
* the implementation for use in vkCreateImage, then all members of
* imageFormatProperties will be filled with zero.
*/
- base_props->imageFormatProperties = (VkImageFormatProperties) { 0 };
+ base_props->imageFormatProperties = (VkImageFormatProperties) {};
}
return result;