anv_formats.c revision 01e04c3f
1/* 2 * Copyright © 2015 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24#include "anv_private.h" 25#include "drm_fourcc.h" 26#include "vk_enum_to_str.h" 27#include "vk_format_info.h" 28#include "vk_util.h" 29 30/* 31 * gcc-4 and earlier don't allow compound literals where a constant 32 * is required in -std=c99/gnu99 mode, so we can't use ISL_SWIZZLE() 33 * here. -std=c89/gnu89 would allow it, but we depend on c99 features 34 * so using -std=c89/gnu89 is not an option. Starting from gcc-5 35 * compound literals can also be considered constant in -std=c99/gnu99 36 * mode. 37 */ 38#define _ISL_SWIZZLE(r, g, b, a) { \ 39 ISL_CHANNEL_SELECT_##r, \ 40 ISL_CHANNEL_SELECT_##g, \ 41 ISL_CHANNEL_SELECT_##b, \ 42 ISL_CHANNEL_SELECT_##a, \ 43} 44 45#define RGBA _ISL_SWIZZLE(RED, GREEN, BLUE, ALPHA) 46#define BGRA _ISL_SWIZZLE(BLUE, GREEN, RED, ALPHA) 47#define RGB1 _ISL_SWIZZLE(RED, GREEN, BLUE, ONE) 48 49#define swiz_fmt1(__vk_fmt, __hw_fmt, __swizzle) \ 50 [VK_ENUM_OFFSET(__vk_fmt)] = { \ 51 .planes = { \ 52 { .isl_format = __hw_fmt, .swizzle = __swizzle, \ 53 .denominator_scales = { 1, 1, }, \ 54 }, \ 55 }, \ 56 .n_planes = 1, \ 57 } 58 59#define fmt1(__vk_fmt, __hw_fmt) \ 60 swiz_fmt1(__vk_fmt, __hw_fmt, RGBA) 61 62#define fmt2(__vk_fmt, __fmt1, __fmt2) \ 63 [VK_ENUM_OFFSET(__vk_fmt)] = { \ 64 .planes = { \ 65 { .isl_format = __fmt1, \ 66 .swizzle = RGBA, \ 67 .denominator_scales = { 1, 1, }, \ 68 }, \ 69 { .isl_format = __fmt2, \ 70 .swizzle = RGBA, \ 71 .denominator_scales = { 1, 1, }, \ 72 }, \ 73 }, \ 74 .n_planes = 2, \ 75 } 76 77#define fmt_unsupported(__vk_fmt) \ 78 [VK_ENUM_OFFSET(__vk_fmt)] = { \ 79 .planes = { \ 80 { .isl_format = ISL_FORMAT_UNSUPPORTED, }, \ 81 }, \ 82 } 83 84#define y_plane(__hw_fmt, __swizzle, __ycbcr_swizzle, dhs, dvs) \ 85 { .isl_format = __hw_fmt, \ 86 .swizzle = __swizzle, \ 87 .ycbcr_swizzle = __ycbcr_swizzle, \ 88 .denominator_scales = { dhs, dvs, }, \ 89 .has_chroma = false, \ 90 } 91 92#define chroma_plane(__hw_fmt, __swizzle, __ycbcr_swizzle, dhs, dvs) \ 93 { .isl_format = __hw_fmt, \ 94 .swizzle = __swizzle, \ 95 .ycbcr_swizzle = __ycbcr_swizzle, \ 96 .denominator_scales = { dhs, dvs, }, \ 97 .has_chroma = true, \ 98 } 99 100#define ycbcr_fmt(__vk_fmt, __n_planes, ...) \ 101 [VK_ENUM_OFFSET(__vk_fmt)] = { \ 102 .planes = { \ 103 __VA_ARGS__, \ 104 }, \ 105 .n_planes = __n_planes, \ 106 .can_ycbcr = true, \ 107 } 108 109/* HINT: For array formats, the ISL name should match the VK name. For 110 * packed formats, they should have the channels in reverse order from each 111 * other. The reason for this is that, for packed formats, the ISL (and 112 * bspec) names are in LSB -> MSB order while VK formats are MSB -> LSB. 113 */ 114static const struct anv_format main_formats[] = { 115 fmt_unsupported(VK_FORMAT_UNDEFINED), 116 fmt_unsupported(VK_FORMAT_R4G4_UNORM_PACK8), 117 fmt1(VK_FORMAT_R4G4B4A4_UNORM_PACK16, ISL_FORMAT_A4B4G4R4_UNORM), 118 swiz_fmt1(VK_FORMAT_B4G4R4A4_UNORM_PACK16, ISL_FORMAT_A4B4G4R4_UNORM, BGRA), 119 fmt1(VK_FORMAT_R5G6B5_UNORM_PACK16, ISL_FORMAT_B5G6R5_UNORM), 120 swiz_fmt1(VK_FORMAT_B5G6R5_UNORM_PACK16, ISL_FORMAT_B5G6R5_UNORM, BGRA), 121 fmt1(VK_FORMAT_R5G5B5A1_UNORM_PACK16, ISL_FORMAT_A1B5G5R5_UNORM), 122 fmt_unsupported(VK_FORMAT_B5G5R5A1_UNORM_PACK16), 123 fmt1(VK_FORMAT_A1R5G5B5_UNORM_PACK16, ISL_FORMAT_B5G5R5A1_UNORM), 124 fmt1(VK_FORMAT_R8_UNORM, ISL_FORMAT_R8_UNORM), 125 fmt1(VK_FORMAT_R8_SNORM, ISL_FORMAT_R8_SNORM), 126 fmt1(VK_FORMAT_R8_USCALED, ISL_FORMAT_R8_USCALED), 127 fmt1(VK_FORMAT_R8_SSCALED, ISL_FORMAT_R8_SSCALED), 128 fmt1(VK_FORMAT_R8_UINT, ISL_FORMAT_R8_UINT), 129 fmt1(VK_FORMAT_R8_SINT, ISL_FORMAT_R8_SINT), 130 swiz_fmt1(VK_FORMAT_R8_SRGB, ISL_FORMAT_L8_UNORM_SRGB, 131 _ISL_SWIZZLE(RED, ZERO, ZERO, ONE)), 132 fmt1(VK_FORMAT_R8G8_UNORM, ISL_FORMAT_R8G8_UNORM), 133 fmt1(VK_FORMAT_R8G8_SNORM, ISL_FORMAT_R8G8_SNORM), 134 fmt1(VK_FORMAT_R8G8_USCALED, ISL_FORMAT_R8G8_USCALED), 135 fmt1(VK_FORMAT_R8G8_SSCALED, ISL_FORMAT_R8G8_SSCALED), 136 fmt1(VK_FORMAT_R8G8_UINT, ISL_FORMAT_R8G8_UINT), 137 fmt1(VK_FORMAT_R8G8_SINT, ISL_FORMAT_R8G8_SINT), 138 fmt_unsupported(VK_FORMAT_R8G8_SRGB), /* L8A8_UNORM_SRGB */ 139 fmt1(VK_FORMAT_R8G8B8_UNORM, ISL_FORMAT_R8G8B8_UNORM), 140 fmt1(VK_FORMAT_R8G8B8_SNORM, ISL_FORMAT_R8G8B8_SNORM), 141 fmt1(VK_FORMAT_R8G8B8_USCALED, ISL_FORMAT_R8G8B8_USCALED), 142 fmt1(VK_FORMAT_R8G8B8_SSCALED, ISL_FORMAT_R8G8B8_SSCALED), 143 fmt1(VK_FORMAT_R8G8B8_UINT, ISL_FORMAT_R8G8B8_UINT), 144 fmt1(VK_FORMAT_R8G8B8_SINT, ISL_FORMAT_R8G8B8_SINT), 145 fmt1(VK_FORMAT_R8G8B8_SRGB, ISL_FORMAT_R8G8B8_UNORM_SRGB), 146 fmt1(VK_FORMAT_R8G8B8A8_UNORM, ISL_FORMAT_R8G8B8A8_UNORM), 147 fmt1(VK_FORMAT_R8G8B8A8_SNORM, ISL_FORMAT_R8G8B8A8_SNORM), 148 fmt1(VK_FORMAT_R8G8B8A8_USCALED, ISL_FORMAT_R8G8B8A8_USCALED), 149 fmt1(VK_FORMAT_R8G8B8A8_SSCALED, ISL_FORMAT_R8G8B8A8_SSCALED), 150 fmt1(VK_FORMAT_R8G8B8A8_UINT, ISL_FORMAT_R8G8B8A8_UINT), 151 fmt1(VK_FORMAT_R8G8B8A8_SINT, ISL_FORMAT_R8G8B8A8_SINT), 152 fmt1(VK_FORMAT_R8G8B8A8_SRGB, ISL_FORMAT_R8G8B8A8_UNORM_SRGB), 153 fmt1(VK_FORMAT_A8B8G8R8_UNORM_PACK32, ISL_FORMAT_R8G8B8A8_UNORM), 154 fmt1(VK_FORMAT_A8B8G8R8_SNORM_PACK32, ISL_FORMAT_R8G8B8A8_SNORM), 155 fmt1(VK_FORMAT_A8B8G8R8_USCALED_PACK32, ISL_FORMAT_R8G8B8A8_USCALED), 156 fmt1(VK_FORMAT_A8B8G8R8_SSCALED_PACK32, ISL_FORMAT_R8G8B8A8_SSCALED), 157 fmt1(VK_FORMAT_A8B8G8R8_UINT_PACK32, ISL_FORMAT_R8G8B8A8_UINT), 158 fmt1(VK_FORMAT_A8B8G8R8_SINT_PACK32, ISL_FORMAT_R8G8B8A8_SINT), 159 fmt1(VK_FORMAT_A8B8G8R8_SRGB_PACK32, ISL_FORMAT_R8G8B8A8_UNORM_SRGB), 160 fmt1(VK_FORMAT_A2R10G10B10_UNORM_PACK32, ISL_FORMAT_B10G10R10A2_UNORM), 161 fmt1(VK_FORMAT_A2R10G10B10_SNORM_PACK32, ISL_FORMAT_B10G10R10A2_SNORM), 162 fmt1(VK_FORMAT_A2R10G10B10_USCALED_PACK32, ISL_FORMAT_B10G10R10A2_USCALED), 163 fmt1(VK_FORMAT_A2R10G10B10_SSCALED_PACK32, ISL_FORMAT_B10G10R10A2_SSCALED), 164 fmt1(VK_FORMAT_A2R10G10B10_UINT_PACK32, ISL_FORMAT_B10G10R10A2_UINT), 165 fmt1(VK_FORMAT_A2R10G10B10_SINT_PACK32, ISL_FORMAT_B10G10R10A2_SINT), 166 fmt1(VK_FORMAT_A2B10G10R10_UNORM_PACK32, ISL_FORMAT_R10G10B10A2_UNORM), 167 fmt1(VK_FORMAT_A2B10G10R10_SNORM_PACK32, ISL_FORMAT_R10G10B10A2_SNORM), 168 fmt1(VK_FORMAT_A2B10G10R10_USCALED_PACK32, ISL_FORMAT_R10G10B10A2_USCALED), 169 fmt1(VK_FORMAT_A2B10G10R10_SSCALED_PACK32, ISL_FORMAT_R10G10B10A2_SSCALED), 170 fmt1(VK_FORMAT_A2B10G10R10_UINT_PACK32, ISL_FORMAT_R10G10B10A2_UINT), 171 fmt1(VK_FORMAT_A2B10G10R10_SINT_PACK32, ISL_FORMAT_R10G10B10A2_SINT), 172 fmt1(VK_FORMAT_R16_UNORM, ISL_FORMAT_R16_UNORM), 173 fmt1(VK_FORMAT_R16_SNORM, ISL_FORMAT_R16_SNORM), 174 fmt1(VK_FORMAT_R16_USCALED, ISL_FORMAT_R16_USCALED), 175 fmt1(VK_FORMAT_R16_SSCALED, ISL_FORMAT_R16_SSCALED), 176 fmt1(VK_FORMAT_R16_UINT, ISL_FORMAT_R16_UINT), 177 fmt1(VK_FORMAT_R16_SINT, ISL_FORMAT_R16_SINT), 178 fmt1(VK_FORMAT_R16_SFLOAT, ISL_FORMAT_R16_FLOAT), 179 fmt1(VK_FORMAT_R16G16_UNORM, ISL_FORMAT_R16G16_UNORM), 180 fmt1(VK_FORMAT_R16G16_SNORM, ISL_FORMAT_R16G16_SNORM), 181 fmt1(VK_FORMAT_R16G16_USCALED, ISL_FORMAT_R16G16_USCALED), 182 fmt1(VK_FORMAT_R16G16_SSCALED, ISL_FORMAT_R16G16_SSCALED), 183 fmt1(VK_FORMAT_R16G16_UINT, ISL_FORMAT_R16G16_UINT), 184 fmt1(VK_FORMAT_R16G16_SINT, ISL_FORMAT_R16G16_SINT), 185 fmt1(VK_FORMAT_R16G16_SFLOAT, ISL_FORMAT_R16G16_FLOAT), 186 fmt1(VK_FORMAT_R16G16B16_UNORM, ISL_FORMAT_R16G16B16_UNORM), 187 fmt1(VK_FORMAT_R16G16B16_SNORM, ISL_FORMAT_R16G16B16_SNORM), 188 fmt1(VK_FORMAT_R16G16B16_USCALED, ISL_FORMAT_R16G16B16_USCALED), 189 fmt1(VK_FORMAT_R16G16B16_SSCALED, ISL_FORMAT_R16G16B16_SSCALED), 190 fmt1(VK_FORMAT_R16G16B16_UINT, ISL_FORMAT_R16G16B16_UINT), 191 fmt1(VK_FORMAT_R16G16B16_SINT, ISL_FORMAT_R16G16B16_SINT), 192 fmt1(VK_FORMAT_R16G16B16_SFLOAT, ISL_FORMAT_R16G16B16_FLOAT), 193 fmt1(VK_FORMAT_R16G16B16A16_UNORM, ISL_FORMAT_R16G16B16A16_UNORM), 194 fmt1(VK_FORMAT_R16G16B16A16_SNORM, ISL_FORMAT_R16G16B16A16_SNORM), 195 fmt1(VK_FORMAT_R16G16B16A16_USCALED, ISL_FORMAT_R16G16B16A16_USCALED), 196 fmt1(VK_FORMAT_R16G16B16A16_SSCALED, ISL_FORMAT_R16G16B16A16_SSCALED), 197 fmt1(VK_FORMAT_R16G16B16A16_UINT, ISL_FORMAT_R16G16B16A16_UINT), 198 fmt1(VK_FORMAT_R16G16B16A16_SINT, ISL_FORMAT_R16G16B16A16_SINT), 199 fmt1(VK_FORMAT_R16G16B16A16_SFLOAT, ISL_FORMAT_R16G16B16A16_FLOAT), 200 fmt1(VK_FORMAT_R32_UINT, ISL_FORMAT_R32_UINT), 201 fmt1(VK_FORMAT_R32_SINT, ISL_FORMAT_R32_SINT), 202 fmt1(VK_FORMAT_R32_SFLOAT, ISL_FORMAT_R32_FLOAT), 203 fmt1(VK_FORMAT_R32G32_UINT, ISL_FORMAT_R32G32_UINT), 204 fmt1(VK_FORMAT_R32G32_SINT, ISL_FORMAT_R32G32_SINT), 205 fmt1(VK_FORMAT_R32G32_SFLOAT, ISL_FORMAT_R32G32_FLOAT), 206 fmt1(VK_FORMAT_R32G32B32_UINT, ISL_FORMAT_R32G32B32_UINT), 207 fmt1(VK_FORMAT_R32G32B32_SINT, ISL_FORMAT_R32G32B32_SINT), 208 fmt1(VK_FORMAT_R32G32B32_SFLOAT, ISL_FORMAT_R32G32B32_FLOAT), 209 fmt1(VK_FORMAT_R32G32B32A32_UINT, ISL_FORMAT_R32G32B32A32_UINT), 210 fmt1(VK_FORMAT_R32G32B32A32_SINT, ISL_FORMAT_R32G32B32A32_SINT), 211 fmt1(VK_FORMAT_R32G32B32A32_SFLOAT, ISL_FORMAT_R32G32B32A32_FLOAT), 212 fmt1(VK_FORMAT_R64_UINT, ISL_FORMAT_R64_PASSTHRU), 213 fmt1(VK_FORMAT_R64_SINT, ISL_FORMAT_R64_PASSTHRU), 214 fmt1(VK_FORMAT_R64_SFLOAT, ISL_FORMAT_R64_PASSTHRU), 215 fmt1(VK_FORMAT_R64G64_UINT, ISL_FORMAT_R64G64_PASSTHRU), 216 fmt1(VK_FORMAT_R64G64_SINT, ISL_FORMAT_R64G64_PASSTHRU), 217 fmt1(VK_FORMAT_R64G64_SFLOAT, ISL_FORMAT_R64G64_PASSTHRU), 218 fmt1(VK_FORMAT_R64G64B64_UINT, ISL_FORMAT_R64G64B64_PASSTHRU), 219 fmt1(VK_FORMAT_R64G64B64_SINT, ISL_FORMAT_R64G64B64_PASSTHRU), 220 fmt1(VK_FORMAT_R64G64B64_SFLOAT, ISL_FORMAT_R64G64B64_PASSTHRU), 221 fmt1(VK_FORMAT_R64G64B64A64_UINT, ISL_FORMAT_R64G64B64A64_PASSTHRU), 222 fmt1(VK_FORMAT_R64G64B64A64_SINT, ISL_FORMAT_R64G64B64A64_PASSTHRU), 223 fmt1(VK_FORMAT_R64G64B64A64_SFLOAT, ISL_FORMAT_R64G64B64A64_PASSTHRU), 224 fmt1(VK_FORMAT_B10G11R11_UFLOAT_PACK32, ISL_FORMAT_R11G11B10_FLOAT), 225 fmt1(VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, ISL_FORMAT_R9G9B9E5_SHAREDEXP), 226 227 fmt1(VK_FORMAT_D16_UNORM, ISL_FORMAT_R16_UNORM), 228 fmt1(VK_FORMAT_X8_D24_UNORM_PACK32, ISL_FORMAT_R24_UNORM_X8_TYPELESS), 229 fmt1(VK_FORMAT_D32_SFLOAT, ISL_FORMAT_R32_FLOAT), 230 fmt1(VK_FORMAT_S8_UINT, ISL_FORMAT_R8_UINT), 231 fmt_unsupported(VK_FORMAT_D16_UNORM_S8_UINT), 232 fmt2(VK_FORMAT_D24_UNORM_S8_UINT, ISL_FORMAT_R24_UNORM_X8_TYPELESS, ISL_FORMAT_R8_UINT), 233 fmt2(VK_FORMAT_D32_SFLOAT_S8_UINT, ISL_FORMAT_R32_FLOAT, ISL_FORMAT_R8_UINT), 234 235 swiz_fmt1(VK_FORMAT_BC1_RGB_UNORM_BLOCK, ISL_FORMAT_BC1_UNORM, RGB1), 236 swiz_fmt1(VK_FORMAT_BC1_RGB_SRGB_BLOCK, ISL_FORMAT_BC1_UNORM_SRGB, RGB1), 237 fmt1(VK_FORMAT_BC1_RGBA_UNORM_BLOCK, ISL_FORMAT_BC1_UNORM), 238 fmt1(VK_FORMAT_BC1_RGBA_SRGB_BLOCK, ISL_FORMAT_BC1_UNORM_SRGB), 239 fmt1(VK_FORMAT_BC2_UNORM_BLOCK, ISL_FORMAT_BC2_UNORM), 240 fmt1(VK_FORMAT_BC2_SRGB_BLOCK, ISL_FORMAT_BC2_UNORM_SRGB), 241 fmt1(VK_FORMAT_BC3_UNORM_BLOCK, ISL_FORMAT_BC3_UNORM), 242 fmt1(VK_FORMAT_BC3_SRGB_BLOCK, ISL_FORMAT_BC3_UNORM_SRGB), 243 fmt1(VK_FORMAT_BC4_UNORM_BLOCK, ISL_FORMAT_BC4_UNORM), 244 fmt1(VK_FORMAT_BC4_SNORM_BLOCK, ISL_FORMAT_BC4_SNORM), 245 fmt1(VK_FORMAT_BC5_UNORM_BLOCK, ISL_FORMAT_BC5_UNORM), 246 fmt1(VK_FORMAT_BC5_SNORM_BLOCK, ISL_FORMAT_BC5_SNORM), 247 fmt1(VK_FORMAT_BC6H_UFLOAT_BLOCK, ISL_FORMAT_BC6H_UF16), 248 fmt1(VK_FORMAT_BC6H_SFLOAT_BLOCK, ISL_FORMAT_BC6H_SF16), 249 fmt1(VK_FORMAT_BC7_UNORM_BLOCK, ISL_FORMAT_BC7_UNORM), 250 fmt1(VK_FORMAT_BC7_SRGB_BLOCK, ISL_FORMAT_BC7_UNORM_SRGB), 251 fmt1(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, ISL_FORMAT_ETC2_RGB8), 252 fmt1(VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, ISL_FORMAT_ETC2_SRGB8), 253 fmt1(VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, ISL_FORMAT_ETC2_RGB8_PTA), 254 fmt1(VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, ISL_FORMAT_ETC2_SRGB8_PTA), 255 fmt1(VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, ISL_FORMAT_ETC2_EAC_RGBA8), 256 fmt1(VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, ISL_FORMAT_ETC2_EAC_SRGB8_A8), 257 fmt1(VK_FORMAT_EAC_R11_UNORM_BLOCK, ISL_FORMAT_EAC_R11), 258 fmt1(VK_FORMAT_EAC_R11_SNORM_BLOCK, ISL_FORMAT_EAC_SIGNED_R11), 259 fmt1(VK_FORMAT_EAC_R11G11_UNORM_BLOCK, ISL_FORMAT_EAC_RG11), 260 fmt1(VK_FORMAT_EAC_R11G11_SNORM_BLOCK, ISL_FORMAT_EAC_SIGNED_RG11), 261 fmt1(VK_FORMAT_ASTC_4x4_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_4X4_U8SRGB), 262 fmt1(VK_FORMAT_ASTC_5x4_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_5X4_U8SRGB), 263 fmt1(VK_FORMAT_ASTC_5x5_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_5X5_U8SRGB), 264 fmt1(VK_FORMAT_ASTC_6x5_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_6X5_U8SRGB), 265 fmt1(VK_FORMAT_ASTC_6x6_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_6X6_U8SRGB), 266 fmt1(VK_FORMAT_ASTC_8x5_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_8X5_U8SRGB), 267 fmt1(VK_FORMAT_ASTC_8x6_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_8X6_U8SRGB), 268 fmt1(VK_FORMAT_ASTC_8x8_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_8X8_U8SRGB), 269 fmt1(VK_FORMAT_ASTC_10x5_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_10X5_U8SRGB), 270 fmt1(VK_FORMAT_ASTC_10x6_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_10X6_U8SRGB), 271 fmt1(VK_FORMAT_ASTC_10x8_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_10X8_U8SRGB), 272 fmt1(VK_FORMAT_ASTC_10x10_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_10X10_U8SRGB), 273 fmt1(VK_FORMAT_ASTC_12x10_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_12X10_U8SRGB), 274 fmt1(VK_FORMAT_ASTC_12x12_SRGB_BLOCK, ISL_FORMAT_ASTC_LDR_2D_12X12_U8SRGB), 275 fmt1(VK_FORMAT_ASTC_4x4_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_4X4_FLT16), 276 fmt1(VK_FORMAT_ASTC_5x4_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_5X4_FLT16), 277 fmt1(VK_FORMAT_ASTC_5x5_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_5X5_FLT16), 278 fmt1(VK_FORMAT_ASTC_6x5_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_6X5_FLT16), 279 fmt1(VK_FORMAT_ASTC_6x6_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_6X6_FLT16), 280 fmt1(VK_FORMAT_ASTC_8x5_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_8X5_FLT16), 281 fmt1(VK_FORMAT_ASTC_8x6_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_8X6_FLT16), 282 fmt1(VK_FORMAT_ASTC_8x8_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_8X8_FLT16), 283 fmt1(VK_FORMAT_ASTC_10x5_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_10X5_FLT16), 284 fmt1(VK_FORMAT_ASTC_10x6_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_10X6_FLT16), 285 fmt1(VK_FORMAT_ASTC_10x8_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_10X8_FLT16), 286 fmt1(VK_FORMAT_ASTC_10x10_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_10X10_FLT16), 287 fmt1(VK_FORMAT_ASTC_12x10_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_12X10_FLT16), 288 fmt1(VK_FORMAT_ASTC_12x12_UNORM_BLOCK, ISL_FORMAT_ASTC_LDR_2D_12X12_FLT16), 289 fmt_unsupported(VK_FORMAT_B8G8R8_UNORM), 290 fmt_unsupported(VK_FORMAT_B8G8R8_SNORM), 291 fmt_unsupported(VK_FORMAT_B8G8R8_USCALED), 292 fmt_unsupported(VK_FORMAT_B8G8R8_SSCALED), 293 fmt_unsupported(VK_FORMAT_B8G8R8_UINT), 294 fmt_unsupported(VK_FORMAT_B8G8R8_SINT), 295 fmt_unsupported(VK_FORMAT_B8G8R8_SRGB), 296 fmt1(VK_FORMAT_B8G8R8A8_UNORM, ISL_FORMAT_B8G8R8A8_UNORM), 297 fmt_unsupported(VK_FORMAT_B8G8R8A8_SNORM), 298 fmt_unsupported(VK_FORMAT_B8G8R8A8_USCALED), 299 fmt_unsupported(VK_FORMAT_B8G8R8A8_SSCALED), 300 fmt_unsupported(VK_FORMAT_B8G8R8A8_UINT), 301 fmt_unsupported(VK_FORMAT_B8G8R8A8_SINT), 302 fmt1(VK_FORMAT_B8G8R8A8_SRGB, ISL_FORMAT_B8G8R8A8_UNORM_SRGB), 303}; 304 305static const struct anv_format ycbcr_formats[] = { 306 ycbcr_fmt(VK_FORMAT_G8B8G8R8_422_UNORM, 1, 307 y_plane(ISL_FORMAT_YCRCB_SWAPUV, RGBA, _ISL_SWIZZLE(BLUE, GREEN, RED, ZERO), 1, 1)), 308 ycbcr_fmt(VK_FORMAT_B8G8R8G8_422_UNORM, 1, 309 y_plane(ISL_FORMAT_YCRCB_SWAPUVY, RGBA, _ISL_SWIZZLE(BLUE, GREEN, RED, ZERO), 1, 1)), 310 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, 3, 311 y_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 312 chroma_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(BLUE, ZERO, ZERO, ZERO), 2, 2), 313 chroma_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(RED, ZERO, ZERO, ZERO), 2, 2)), 314 ycbcr_fmt(VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, 2, 315 y_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 316 chroma_plane(ISL_FORMAT_R8G8_UNORM, RGBA, _ISL_SWIZZLE(BLUE, RED, ZERO, ZERO), 2, 2)), 317 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM, 3, 318 y_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 319 chroma_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(BLUE, ZERO, ZERO, ZERO), 2, 1), 320 chroma_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(RED, ZERO, ZERO, ZERO), 2, 1)), 321 ycbcr_fmt(VK_FORMAT_G8_B8R8_2PLANE_422_UNORM, 2, 322 y_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 323 chroma_plane(ISL_FORMAT_R8G8_UNORM, RGBA, _ISL_SWIZZLE(BLUE, RED, ZERO, ZERO), 2, 1)), 324 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM, 3, 325 y_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 326 chroma_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(BLUE, ZERO, ZERO, ZERO), 1, 1), 327 chroma_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(RED, ZERO, ZERO, ZERO), 1, 1)), 328 329 fmt_unsupported(VK_FORMAT_R10X6_UNORM_PACK16), 330 fmt_unsupported(VK_FORMAT_R10X6G10X6_UNORM_2PACK16), 331 fmt_unsupported(VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16), 332 fmt_unsupported(VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16), 333 fmt_unsupported(VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16), 334 fmt_unsupported(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16), 335 fmt_unsupported(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16), 336 fmt_unsupported(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16), 337 fmt_unsupported(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16), 338 fmt_unsupported(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16), 339 fmt_unsupported(VK_FORMAT_R12X4_UNORM_PACK16), 340 fmt_unsupported(VK_FORMAT_R12X4G12X4_UNORM_2PACK16), 341 fmt_unsupported(VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16), 342 fmt_unsupported(VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16), 343 fmt_unsupported(VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16), 344 fmt_unsupported(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16), 345 fmt_unsupported(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16), 346 fmt_unsupported(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16), 347 fmt_unsupported(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16), 348 fmt_unsupported(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16), 349 /* TODO: it is possible to enable the following 2 formats, but that 350 * requires further refactoring of how we handle multiplanar formats. 351 */ 352 fmt_unsupported(VK_FORMAT_G16B16G16R16_422_UNORM), 353 fmt_unsupported(VK_FORMAT_B16G16R16G16_422_UNORM), 354 355 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM, 3, 356 y_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 357 chroma_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(BLUE, ZERO, ZERO, ZERO), 2, 2), 358 chroma_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(RED, ZERO, ZERO, ZERO), 2, 2)), 359 ycbcr_fmt(VK_FORMAT_G16_B16R16_2PLANE_420_UNORM, 2, 360 y_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 361 chroma_plane(ISL_FORMAT_R16G16_UNORM, RGBA, _ISL_SWIZZLE(BLUE, RED, ZERO, ZERO), 2, 2)), 362 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM, 3, 363 y_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 364 chroma_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(BLUE, ZERO, ZERO, ZERO), 2, 1), 365 chroma_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(RED, ZERO, ZERO, ZERO), 2, 1)), 366 ycbcr_fmt(VK_FORMAT_G16_B16R16_2PLANE_422_UNORM, 2, 367 y_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 368 chroma_plane(ISL_FORMAT_R16G16_UNORM, RGBA, _ISL_SWIZZLE(BLUE, RED, ZERO, ZERO), 2, 1)), 369 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM, 3, 370 y_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1), 371 chroma_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(BLUE, ZERO, ZERO, ZERO), 1, 1), 372 chroma_plane(ISL_FORMAT_R16_UNORM, RGBA, _ISL_SWIZZLE(RED, ZERO, ZERO, ZERO), 1, 1)), 373}; 374 375#undef _fmt 376#undef swiz_fmt1 377#undef fmt1 378#undef fmt 379 380static const struct { 381 const struct anv_format *formats; 382 uint32_t n_formats; 383} anv_formats[] = { 384 [0] = { .formats = main_formats, 385 .n_formats = ARRAY_SIZE(main_formats), }, 386 [_VK_KHR_sampler_ycbcr_conversion_number] = { .formats = ycbcr_formats, 387 .n_formats = ARRAY_SIZE(ycbcr_formats), }, 388}; 389 390const struct anv_format * 391anv_get_format(VkFormat vk_format) 392{ 393 uint32_t enum_offset = VK_ENUM_OFFSET(vk_format); 394 uint32_t ext_number = VK_ENUM_EXTENSION(vk_format); 395 396 if (ext_number >= ARRAY_SIZE(anv_formats) || 397 enum_offset >= anv_formats[ext_number].n_formats) 398 return NULL; 399 400 const struct anv_format *format = 401 &anv_formats[ext_number].formats[enum_offset]; 402 if (format->planes[0].isl_format == ISL_FORMAT_UNSUPPORTED) 403 return NULL; 404 405 return format; 406} 407 408/** 409 * Exactly one bit must be set in \a aspect. 410 */ 411struct anv_format_plane 412anv_get_format_plane(const struct gen_device_info *devinfo, VkFormat vk_format, 413 VkImageAspectFlagBits aspect, VkImageTiling tiling) 414{ 415 const struct anv_format *format = anv_get_format(vk_format); 416 const struct anv_format_plane unsupported = { 417 .isl_format = ISL_FORMAT_UNSUPPORTED, 418 }; 419 420 if (format == NULL) 421 return unsupported; 422 423 uint32_t plane = anv_image_aspect_to_plane(vk_format_aspects(vk_format), aspect); 424 struct anv_format_plane plane_format = format->planes[plane]; 425 if (plane_format.isl_format == ISL_FORMAT_UNSUPPORTED) 426 return unsupported; 427 428 if (aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { 429 assert(vk_format_aspects(vk_format) & 430 (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); 431 return plane_format; 432 } 433 434 assert((aspect & ~VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) == 0); 435 436 const struct isl_format_layout *isl_layout = 437 isl_format_get_layout(plane_format.isl_format); 438 439 if (tiling == VK_IMAGE_TILING_OPTIMAL && 440 !util_is_power_of_two_or_zero(isl_layout->bpb)) { 441 /* Tiled formats *must* be power-of-two because we need up upload 442 * them with the render pipeline. For 3-channel formats, we fix 443 * this by switching them over to RGBX or RGBA formats under the 444 * hood. 445 */ 446 enum isl_format rgbx = isl_format_rgb_to_rgbx(plane_format.isl_format); 447 if (rgbx != ISL_FORMAT_UNSUPPORTED && 448 isl_format_supports_rendering(devinfo, rgbx)) { 449 plane_format.isl_format = rgbx; 450 } else { 451 plane_format.isl_format = 452 isl_format_rgb_to_rgba(plane_format.isl_format); 453 plane_format.swizzle = ISL_SWIZZLE(RED, GREEN, BLUE, ONE); 454 } 455 } 456 457 /* The B4G4R4A4 format isn't available prior to Broadwell so we have to fall 458 * back to a format with a more complex swizzle. 459 */ 460 if (vk_format == VK_FORMAT_B4G4R4A4_UNORM_PACK16 && devinfo->gen < 8) { 461 plane_format.isl_format = ISL_FORMAT_B4G4R4A4_UNORM; 462 plane_format.swizzle = ISL_SWIZZLE(GREEN, RED, ALPHA, BLUE); 463 } 464 465 return plane_format; 466} 467 468// Format capabilities 469 470static VkFormatFeatureFlags 471get_image_format_features(const struct gen_device_info *devinfo, 472 VkFormat vk_format, 473 const struct anv_format *anv_format, 474 VkImageTiling vk_tiling) 475{ 476 VkFormatFeatureFlags flags = 0; 477 478 if (anv_format == NULL) 479 return 0; 480 481 const VkImageAspectFlags aspects = vk_format_aspects(vk_format); 482 483 if (aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { 484 if (vk_tiling == VK_IMAGE_TILING_LINEAR) 485 return 0; 486 487 flags |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT; 488 489 if (aspects == VK_IMAGE_ASPECT_DEPTH_BIT || devinfo->gen >= 8) 490 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; 491 492 if ((aspects & VK_IMAGE_ASPECT_DEPTH_BIT) && devinfo->gen >= 9) 493 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT; 494 495 flags |= VK_FORMAT_FEATURE_BLIT_SRC_BIT | 496 VK_FORMAT_FEATURE_BLIT_DST_BIT | 497 VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR | 498 VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR; 499 500 return flags; 501 } 502 503 const struct anv_format_plane plane_format = 504 anv_get_format_plane(devinfo, vk_format, VK_IMAGE_ASPECT_COLOR_BIT, 505 vk_tiling); 506 507 if (plane_format.isl_format == ISL_FORMAT_UNSUPPORTED) 508 return 0; 509 510 struct anv_format_plane base_plane_format = plane_format; 511 if (vk_tiling == VK_IMAGE_TILING_OPTIMAL) { 512 base_plane_format = anv_get_format_plane(devinfo, vk_format, 513 VK_IMAGE_ASPECT_COLOR_BIT, 514 VK_IMAGE_TILING_LINEAR); 515 } 516 517 enum isl_format base_isl_format = base_plane_format.isl_format; 518 519 /* ASTC textures must be in Y-tiled memory */ 520 if (vk_tiling == VK_IMAGE_TILING_LINEAR && 521 isl_format_get_layout(plane_format.isl_format)->txc == ISL_TXC_ASTC) 522 return 0; 523 524 /* ASTC requires nasty workarounds on BSW so we just disable it for now. 525 * 526 * TODO: Figure out the ASTC workarounds and re-enable on BSW. 527 */ 528 if (devinfo->gen < 9 && 529 isl_format_get_layout(plane_format.isl_format)->txc == ISL_TXC_ASTC) 530 return 0; 531 532 if (isl_format_supports_sampling(devinfo, plane_format.isl_format)) { 533 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; 534 535 if (devinfo->gen >= 9) 536 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT; 537 538 if (isl_format_supports_filtering(devinfo, plane_format.isl_format)) 539 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT; 540 } 541 542 /* We can render to swizzled formats. However, if the alpha channel is 543 * moved, then blending won't work correctly. The PRM tells us 544 * straight-up not to render to such a surface. 545 */ 546 if (isl_format_supports_rendering(devinfo, plane_format.isl_format) && 547 plane_format.swizzle.a == ISL_CHANNEL_SELECT_ALPHA) { 548 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT; 549 550 if (isl_format_supports_alpha_blending(devinfo, plane_format.isl_format)) 551 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT; 552 } 553 554 /* Load/store is determined based on base format. This prevents RGB 555 * formats from showing up as load/store capable. 556 */ 557 if (isl_is_storage_image_format(base_isl_format)) 558 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; 559 560 if (base_isl_format == ISL_FORMAT_R32_SINT || 561 base_isl_format == ISL_FORMAT_R32_UINT) 562 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT; 563 564 if (flags) { 565 flags |= VK_FORMAT_FEATURE_BLIT_SRC_BIT | 566 VK_FORMAT_FEATURE_BLIT_DST_BIT | 567 VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | 568 VK_FORMAT_FEATURE_TRANSFER_DST_BIT; 569 } 570 571 /* XXX: We handle 3-channel formats by switching them out for RGBX or 572 * RGBA formats behind-the-scenes. This works fine for textures 573 * because the upload process will fill in the extra channel. 574 * We could also support it for render targets, but it will take 575 * substantially more work and we have enough RGBX formats to handle 576 * what most clients will want. 577 */ 578 if (vk_tiling == VK_IMAGE_TILING_OPTIMAL && 579 base_isl_format != ISL_FORMAT_UNSUPPORTED && 580 !util_is_power_of_two_or_zero(isl_format_layouts[base_isl_format].bpb) && 581 isl_format_rgb_to_rgbx(base_isl_format) == ISL_FORMAT_UNSUPPORTED) { 582 flags &= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT; 583 flags &= ~VK_FORMAT_FEATURE_BLIT_DST_BIT; 584 } 585 586 if (anv_format->can_ycbcr) { 587 /* The sampler doesn't have support for mid point when it handles YUV on 588 * its own. 589 */ 590 if (isl_format_is_yuv(anv_format->planes[0].isl_format)) { 591 /* TODO: We've disabled linear implicit reconstruction with the 592 * sampler. The failures show a slightly out of range values on the 593 * bottom left of the sampled image. 594 */ 595 flags |= VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT; 596 } else { 597 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT | 598 VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT | 599 VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT; 600 } 601 602 /* We can support cosited chroma locations when handle planes with our 603 * own shader snippets. 604 */ 605 for (unsigned p = 0; p < anv_format->n_planes; p++) { 606 if (anv_format->planes[p].denominator_scales[0] > 1 || 607 anv_format->planes[p].denominator_scales[1] > 1) { 608 flags |= VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT; 609 break; 610 } 611 } 612 613 if (anv_format->n_planes > 1) 614 flags |= VK_FORMAT_FEATURE_DISJOINT_BIT; 615 616 const VkFormatFeatureFlags disallowed_ycbcr_image_features = 617 VK_FORMAT_FEATURE_BLIT_SRC_BIT | 618 VK_FORMAT_FEATURE_BLIT_DST_BIT | 619 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | 620 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT | 621 VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; 622 623 flags &= ~disallowed_ycbcr_image_features; 624 } 625 626 return flags; 627} 628 629static VkFormatFeatureFlags 630get_buffer_format_features(const struct gen_device_info *devinfo, 631 VkFormat vk_format, 632 const struct anv_format *anv_format) 633{ 634 VkFormatFeatureFlags flags = 0; 635 636 if (anv_format == NULL) 637 return 0; 638 639 const enum isl_format isl_format = anv_format->planes[0].isl_format; 640 641 if (isl_format == ISL_FORMAT_UNSUPPORTED) 642 return 0; 643 644 if (anv_format->n_planes > 1) 645 return 0; 646 647 if (anv_format->can_ycbcr) 648 return 0; 649 650 if (vk_format_is_depth_or_stencil(vk_format)) 651 return 0; 652 653 if (isl_format_supports_sampling(devinfo, isl_format) && 654 !isl_format_is_compressed(isl_format)) 655 flags |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT; 656 657 if (isl_format_supports_vertex_fetch(devinfo, isl_format)) 658 flags |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT; 659 660 if (isl_is_storage_image_format(isl_format)) 661 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT; 662 663 if (isl_format == ISL_FORMAT_R32_SINT || isl_format == ISL_FORMAT_R32_UINT) 664 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT; 665 666 return flags; 667} 668 669static void 670get_wsi_format_modifier_properties_list(const struct anv_physical_device *physical_device, 671 VkFormat vk_format, 672 struct wsi_format_modifier_properties_list *list) 673{ 674 const struct anv_format *anv_format = anv_get_format(vk_format); 675 676 VK_OUTARRAY_MAKE(out, list->modifier_properties, &list->modifier_count); 677 678 /* This is a simplified list where all the modifiers are available */ 679 assert(vk_format == VK_FORMAT_B8G8R8_SRGB || 680 vk_format == VK_FORMAT_B8G8R8_UNORM || 681 vk_format == VK_FORMAT_B8G8R8A8_SRGB || 682 vk_format == VK_FORMAT_B8G8R8A8_UNORM); 683 684 uint64_t modifiers[] = { 685 DRM_FORMAT_MOD_LINEAR, 686 I915_FORMAT_MOD_X_TILED, 687 I915_FORMAT_MOD_Y_TILED, 688 I915_FORMAT_MOD_Y_TILED_CCS, 689 }; 690 691 for (uint32_t i = 0; i < ARRAY_SIZE(modifiers); i++) { 692 const struct isl_drm_modifier_info *mod_info = 693 isl_drm_modifier_get_info(modifiers[i]); 694 695 if (mod_info->aux_usage == ISL_AUX_USAGE_CCS_E && 696 !isl_format_supports_ccs_e(&physical_device->info, 697 anv_format->planes[0].isl_format)) 698 continue; 699 700 vk_outarray_append(&out, mod_props) { 701 mod_props->modifier = modifiers[i]; 702 if (isl_drm_modifier_has_aux(modifiers[i])) 703 mod_props->modifier_plane_count = 2; 704 else 705 mod_props->modifier_plane_count = anv_format->n_planes; 706 } 707 } 708} 709 710void anv_GetPhysicalDeviceFormatProperties( 711 VkPhysicalDevice physicalDevice, 712 VkFormat vk_format, 713 VkFormatProperties* pFormatProperties) 714{ 715 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); 716 const struct gen_device_info *devinfo = &physical_device->info; 717 const struct anv_format *anv_format = anv_get_format(vk_format); 718 719 *pFormatProperties = (VkFormatProperties) { 720 .linearTilingFeatures = 721 get_image_format_features(devinfo, vk_format, anv_format, 722 VK_IMAGE_TILING_LINEAR), 723 .optimalTilingFeatures = 724 get_image_format_features(devinfo, vk_format, anv_format, 725 VK_IMAGE_TILING_OPTIMAL), 726 .bufferFeatures = 727 get_buffer_format_features(devinfo, vk_format, anv_format), 728 }; 729} 730 731void anv_GetPhysicalDeviceFormatProperties2( 732 VkPhysicalDevice physicalDevice, 733 VkFormat format, 734 VkFormatProperties2* pFormatProperties) 735{ 736 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); 737 anv_GetPhysicalDeviceFormatProperties(physicalDevice, format, 738 &pFormatProperties->formatProperties); 739 740 vk_foreach_struct(ext, pFormatProperties->pNext) { 741 /* Use unsigned since some cases are not in the VkStructureType enum. */ 742 switch ((unsigned)ext->sType) { 743 case VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA: 744 get_wsi_format_modifier_properties_list(physical_device, format, 745 (void *)ext); 746 break; 747 default: 748 anv_debug_ignored_stype(ext->sType); 749 break; 750 } 751 } 752} 753 754static VkResult 755anv_get_image_format_properties( 756 struct anv_physical_device *physical_device, 757 const VkPhysicalDeviceImageFormatInfo2 *info, 758 VkImageFormatProperties *pImageFormatProperties, 759 VkSamplerYcbcrConversionImageFormatPropertiesKHR *pYcbcrImageFormatProperties) 760{ 761 VkFormatFeatureFlags format_feature_flags; 762 VkExtent3D maxExtent; 763 uint32_t maxMipLevels; 764 uint32_t maxArraySize; 765 VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT; 766 const struct gen_device_info *devinfo = &physical_device->info; 767 const struct anv_format *format = anv_get_format(info->format); 768 769 if (format == NULL) 770 goto unsupported; 771 772 format_feature_flags = get_image_format_features(devinfo, info->format, 773 format, info->tiling); 774 775 switch (info->type) { 776 default: 777 unreachable("bad VkImageType"); 778 case VK_IMAGE_TYPE_1D: 779 maxExtent.width = 16384; 780 maxExtent.height = 1; 781 maxExtent.depth = 1; 782 maxMipLevels = 15; /* log2(maxWidth) + 1 */ 783 maxArraySize = 2048; 784 sampleCounts = VK_SAMPLE_COUNT_1_BIT; 785 break; 786 case VK_IMAGE_TYPE_2D: 787 /* FINISHME: Does this really differ for cube maps? The documentation 788 * for RENDER_SURFACE_STATE suggests so. 789 */ 790 maxExtent.width = 16384; 791 maxExtent.height = 16384; 792 maxExtent.depth = 1; 793 maxMipLevels = 15; /* log2(maxWidth) + 1 */ 794 maxArraySize = 2048; 795 break; 796 case VK_IMAGE_TYPE_3D: 797 maxExtent.width = 2048; 798 maxExtent.height = 2048; 799 maxExtent.depth = 2048; 800 maxMipLevels = 12; /* log2(maxWidth) + 1 */ 801 maxArraySize = 1; 802 break; 803 } 804 805 /* Our hardware doesn't support 1D compressed textures. 806 * From the SKL PRM, RENDER_SURFACE_STATE::SurfaceFormat: 807 * * This field cannot be a compressed (BC*, DXT*, FXT*, ETC*, EAC*) format 808 * if the Surface Type is SURFTYPE_1D. 809 * * This field cannot be ASTC format if the Surface Type is SURFTYPE_1D. 810 */ 811 if (info->type == VK_IMAGE_TYPE_1D && 812 isl_format_is_compressed(format->planes[0].isl_format)) { 813 goto unsupported; 814 } 815 816 if (info->tiling == VK_IMAGE_TILING_OPTIMAL && 817 info->type == VK_IMAGE_TYPE_2D && 818 (format_feature_flags & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | 819 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) && 820 !(info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && 821 !(info->usage & VK_IMAGE_USAGE_STORAGE_BIT)) { 822 sampleCounts = isl_device_get_sample_counts(&physical_device->isl_dev); 823 } 824 825 if (info->usage & (VK_IMAGE_USAGE_TRANSFER_SRC_BIT | 826 VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { 827 /* Accept transfers on anything we can sample from or renderer to. */ 828 if (!(format_feature_flags & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | 829 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT | 830 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))) { 831 goto unsupported; 832 } 833 } 834 835 if (info->usage & VK_IMAGE_USAGE_SAMPLED_BIT) { 836 if (!(format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) { 837 goto unsupported; 838 } 839 } 840 841 if (info->usage & VK_IMAGE_USAGE_STORAGE_BIT) { 842 if (!(format_feature_flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) { 843 goto unsupported; 844 } 845 } 846 847 if (info->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { 848 if (!(format_feature_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) { 849 goto unsupported; 850 } 851 } 852 853 if (info->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { 854 if (!(format_feature_flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) { 855 goto unsupported; 856 } 857 } 858 859 if (info->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) { 860 /* Nothing to check. */ 861 } 862 863 if (info->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) { 864 /* Ignore this flag because it was removed from the 865 * provisional_I_20150910 header. 866 */ 867 } 868 869 /* From the bspec section entitled "Surface Layout and Tiling", 870 * pre-gen9 has a 2 GB limitation of the size in bytes, 871 * gen9 and gen10 have a 256 GB limitation and gen11+ 872 * has a 16 TB limitation. 873 */ 874 uint64_t maxResourceSize = 0; 875 if (devinfo->gen < 9) 876 maxResourceSize = (uint64_t) 1 << 31; 877 else if (devinfo->gen < 11) 878 maxResourceSize = (uint64_t) 1 << 38; 879 else 880 maxResourceSize = (uint64_t) 1 << 44; 881 882 *pImageFormatProperties = (VkImageFormatProperties) { 883 .maxExtent = maxExtent, 884 .maxMipLevels = maxMipLevels, 885 .maxArrayLayers = maxArraySize, 886 .sampleCounts = sampleCounts, 887 888 /* FINISHME: Accurately calculate 889 * VkImageFormatProperties::maxResourceSize. 890 */ 891 .maxResourceSize = maxResourceSize, 892 }; 893 894 if (pYcbcrImageFormatProperties) { 895 pYcbcrImageFormatProperties->combinedImageSamplerDescriptorCount = 896 format->n_planes; 897 } 898 899 return VK_SUCCESS; 900 901unsupported: 902 *pImageFormatProperties = (VkImageFormatProperties) { 903 .maxExtent = { 0, 0, 0 }, 904 .maxMipLevels = 0, 905 .maxArrayLayers = 0, 906 .sampleCounts = 0, 907 .maxResourceSize = 0, 908 }; 909 910 return VK_ERROR_FORMAT_NOT_SUPPORTED; 911} 912 913VkResult anv_GetPhysicalDeviceImageFormatProperties( 914 VkPhysicalDevice physicalDevice, 915 VkFormat format, 916 VkImageType type, 917 VkImageTiling tiling, 918 VkImageUsageFlags usage, 919 VkImageCreateFlags createFlags, 920 VkImageFormatProperties* pImageFormatProperties) 921{ 922 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); 923 924 const VkPhysicalDeviceImageFormatInfo2 info = { 925 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, 926 .pNext = NULL, 927 .format = format, 928 .type = type, 929 .tiling = tiling, 930 .usage = usage, 931 .flags = createFlags, 932 }; 933 934 return anv_get_image_format_properties(physical_device, &info, 935 pImageFormatProperties, NULL); 936} 937 938static const VkExternalMemoryProperties prime_fd_props = { 939 /* If we can handle external, then we can both import and export it. */ 940 .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | 941 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT, 942 /* For the moment, let's not support mixing and matching */ 943 .exportFromImportedHandleTypes = 944 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT | 945 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, 946 .compatibleHandleTypes = 947 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT | 948 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, 949}; 950 951VkResult anv_GetPhysicalDeviceImageFormatProperties2( 952 VkPhysicalDevice physicalDevice, 953 const VkPhysicalDeviceImageFormatInfo2* base_info, 954 VkImageFormatProperties2* base_props) 955{ 956 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); 957 const VkPhysicalDeviceExternalImageFormatInfo *external_info = NULL; 958 VkExternalImageFormatPropertiesKHR *external_props = NULL; 959 VkSamplerYcbcrConversionImageFormatProperties *ycbcr_props = NULL; 960 VkResult result; 961 962 /* Extract input structs */ 963 vk_foreach_struct_const(s, base_info->pNext) { 964 switch (s->sType) { 965 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO: 966 external_info = (const void *) s; 967 break; 968 default: 969 anv_debug_ignored_stype(s->sType); 970 break; 971 } 972 } 973 974 /* Extract output structs */ 975 vk_foreach_struct(s, base_props->pNext) { 976 switch (s->sType) { 977 case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES: 978 external_props = (void *) s; 979 break; 980 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES: 981 ycbcr_props = (void *) s; 982 break; 983 default: 984 anv_debug_ignored_stype(s->sType); 985 break; 986 } 987 } 988 989 result = anv_get_image_format_properties(physical_device, base_info, 990 &base_props->imageFormatProperties, ycbcr_props); 991 if (result != VK_SUCCESS) 992 goto fail; 993 994 /* From the Vulkan 1.0.42 spec: 995 * 996 * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will 997 * behave as if VkPhysicalDeviceExternalImageFormatInfo was not 998 * present and VkExternalImageFormatProperties will be ignored. 999 */ 1000 if (external_info && external_info->handleType != 0) { 1001 switch (external_info->handleType) { 1002 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT: 1003 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT: 1004 if (external_props) 1005 external_props->externalMemoryProperties = prime_fd_props; 1006 break; 1007 default: 1008 /* From the Vulkan 1.0.42 spec: 1009 * 1010 * If handleType is not compatible with the [parameters] specified 1011 * in VkPhysicalDeviceImageFormatInfo2, then 1012 * vkGetPhysicalDeviceImageFormatProperties2 returns 1013 * VK_ERROR_FORMAT_NOT_SUPPORTED. 1014 */ 1015 result = vk_errorf(physical_device->instance, physical_device, 1016 VK_ERROR_FORMAT_NOT_SUPPORTED, 1017 "unsupported VkExternalMemoryTypeFlagBits 0x%x", 1018 external_info->handleType); 1019 goto fail; 1020 } 1021 } 1022 1023 return VK_SUCCESS; 1024 1025 fail: 1026 if (result == VK_ERROR_FORMAT_NOT_SUPPORTED) { 1027 /* From the Vulkan 1.0.42 spec: 1028 * 1029 * If the combination of parameters to 1030 * vkGetPhysicalDeviceImageFormatProperties2 is not supported by 1031 * the implementation for use in vkCreateImage, then all members of 1032 * imageFormatProperties will be filled with zero. 1033 */ 1034 base_props->imageFormatProperties = (VkImageFormatProperties) {}; 1035 } 1036 1037 return result; 1038} 1039 1040void anv_GetPhysicalDeviceSparseImageFormatProperties( 1041 VkPhysicalDevice physicalDevice, 1042 VkFormat format, 1043 VkImageType type, 1044 uint32_t samples, 1045 VkImageUsageFlags usage, 1046 VkImageTiling tiling, 1047 uint32_t* pNumProperties, 1048 VkSparseImageFormatProperties* pProperties) 1049{ 1050 /* Sparse images are not yet supported. */ 1051 *pNumProperties = 0; 1052} 1053 1054void anv_GetPhysicalDeviceSparseImageFormatProperties2( 1055 VkPhysicalDevice physicalDevice, 1056 const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, 1057 uint32_t* pPropertyCount, 1058 VkSparseImageFormatProperties2* pProperties) 1059{ 1060 /* Sparse images are not yet supported. */ 1061 *pPropertyCount = 0; 1062} 1063 1064void anv_GetPhysicalDeviceExternalBufferProperties( 1065 VkPhysicalDevice physicalDevice, 1066 const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, 1067 VkExternalBufferProperties* pExternalBufferProperties) 1068{ 1069 /* The Vulkan 1.0.42 spec says "handleType must be a valid 1070 * VkExternalMemoryHandleTypeFlagBits value" in 1071 * VkPhysicalDeviceExternalBufferInfo. This differs from 1072 * VkPhysicalDeviceExternalImageFormatInfo, which surprisingly permits 1073 * handleType == 0. 1074 */ 1075 assert(pExternalBufferInfo->handleType != 0); 1076 1077 /* All of the current flags are for sparse which we don't support yet. 1078 * Even when we do support it, doing sparse on external memory sounds 1079 * sketchy. Also, just disallowing flags is the safe option. 1080 */ 1081 if (pExternalBufferInfo->flags) 1082 goto unsupported; 1083 1084 switch (pExternalBufferInfo->handleType) { 1085 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT: 1086 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT: 1087 pExternalBufferProperties->externalMemoryProperties = prime_fd_props; 1088 return; 1089 default: 1090 goto unsupported; 1091 } 1092 1093 unsupported: 1094 pExternalBufferProperties->externalMemoryProperties = 1095 (VkExternalMemoryProperties) {0}; 1096} 1097 1098VkResult anv_CreateSamplerYcbcrConversion( 1099 VkDevice _device, 1100 const VkSamplerYcbcrConversionCreateInfo* pCreateInfo, 1101 const VkAllocationCallbacks* pAllocator, 1102 VkSamplerYcbcrConversion* pYcbcrConversion) 1103{ 1104 ANV_FROM_HANDLE(anv_device, device, _device); 1105 struct anv_ycbcr_conversion *conversion; 1106 1107 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO); 1108 1109 conversion = vk_alloc2(&device->alloc, pAllocator, sizeof(*conversion), 8, 1110 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); 1111 if (!conversion) 1112 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 1113 1114 memset(conversion, 0, sizeof(*conversion)); 1115 1116 conversion->format = anv_get_format(pCreateInfo->format); 1117 conversion->ycbcr_model = pCreateInfo->ycbcrModel; 1118 conversion->ycbcr_range = pCreateInfo->ycbcrRange; 1119 conversion->mapping[0] = pCreateInfo->components.r; 1120 conversion->mapping[1] = pCreateInfo->components.g; 1121 conversion->mapping[2] = pCreateInfo->components.b; 1122 conversion->mapping[3] = pCreateInfo->components.a; 1123 conversion->chroma_offsets[0] = pCreateInfo->xChromaOffset; 1124 conversion->chroma_offsets[1] = pCreateInfo->yChromaOffset; 1125 conversion->chroma_filter = pCreateInfo->chromaFilter; 1126 1127 bool has_chroma_subsampled = false; 1128 for (uint32_t p = 0; p < conversion->format->n_planes; p++) { 1129 if (conversion->format->planes[p].has_chroma && 1130 (conversion->format->planes[p].denominator_scales[0] > 1 || 1131 conversion->format->planes[p].denominator_scales[1] > 1)) 1132 has_chroma_subsampled = true; 1133 } 1134 conversion->chroma_reconstruction = has_chroma_subsampled && 1135 (conversion->chroma_offsets[0] == VK_CHROMA_LOCATION_COSITED_EVEN || 1136 conversion->chroma_offsets[1] == VK_CHROMA_LOCATION_COSITED_EVEN); 1137 1138 *pYcbcrConversion = anv_ycbcr_conversion_to_handle(conversion); 1139 1140 return VK_SUCCESS; 1141} 1142 1143void anv_DestroySamplerYcbcrConversion( 1144 VkDevice _device, 1145 VkSamplerYcbcrConversion YcbcrConversion, 1146 const VkAllocationCallbacks* pAllocator) 1147{ 1148 ANV_FROM_HANDLE(anv_device, device, _device); 1149 ANV_FROM_HANDLE(anv_ycbcr_conversion, conversion, YcbcrConversion); 1150 1151 if (!conversion) 1152 return; 1153 1154 vk_free2(&device->alloc, pAllocator, conversion); 1155} 1156