1 /********************************************************** 2 * Copyright 2011 VMware, Inc. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 * 24 **********************************************************/ 25 26 27 #include "pipe/p_format.h" 28 #include "util/u_debug.h" 29 #include "util/u_memory.h" 30 31 #include "svga_winsys.h" 32 #include "svga_screen.h" 33 #include "svga_format.h" 34 35 36 /* 37 * Translate from gallium format to SVGA3D format. 38 */ 39 SVGA3dSurfaceFormat 40 svga_translate_format(struct svga_screen *ss, 41 enum pipe_format format, 42 unsigned bind) 43 { 44 switch(format) { 45 46 case PIPE_FORMAT_B8G8R8A8_UNORM: 47 return SVGA3D_A8R8G8B8; 48 case PIPE_FORMAT_B8G8R8X8_UNORM: 49 return SVGA3D_X8R8G8B8; 50 51 /* sRGB required for GL2.1 */ 52 case PIPE_FORMAT_B8G8R8A8_SRGB: 53 return SVGA3D_A8R8G8B8; 54 case PIPE_FORMAT_DXT1_SRGB: 55 case PIPE_FORMAT_DXT1_SRGBA: 56 return SVGA3D_DXT1; 57 case PIPE_FORMAT_DXT3_SRGBA: 58 return SVGA3D_DXT3; 59 case PIPE_FORMAT_DXT5_SRGBA: 60 return SVGA3D_DXT5; 61 62 case PIPE_FORMAT_B5G6R5_UNORM: 63 return SVGA3D_R5G6B5; 64 case PIPE_FORMAT_B5G5R5A1_UNORM: 65 return SVGA3D_A1R5G5B5; 66 case PIPE_FORMAT_B4G4R4A4_UNORM: 67 return SVGA3D_A4R4G4B4; 68 69 case PIPE_FORMAT_Z16_UNORM: 70 return bind & PIPE_BIND_SAMPLER_VIEW ? ss->depth.z16 : SVGA3D_Z_D16; 71 case PIPE_FORMAT_S8_UINT_Z24_UNORM: 72 return bind & PIPE_BIND_SAMPLER_VIEW ? ss->depth.s8z24 : SVGA3D_Z_D24S8; 73 case PIPE_FORMAT_X8Z24_UNORM: 74 return bind & PIPE_BIND_SAMPLER_VIEW ? ss->depth.x8z24 : SVGA3D_Z_D24X8; 75 76 case PIPE_FORMAT_A8_UNORM: 77 return SVGA3D_ALPHA8; 78 case PIPE_FORMAT_L8_UNORM: 79 return SVGA3D_LUMINANCE8; 80 81 case PIPE_FORMAT_DXT1_RGB: 82 case PIPE_FORMAT_DXT1_RGBA: 83 return SVGA3D_DXT1; 84 case PIPE_FORMAT_DXT3_RGBA: 85 return SVGA3D_DXT3; 86 case PIPE_FORMAT_DXT5_RGBA: 87 return SVGA3D_DXT5; 88 89 /* Float formats (only 1, 2 and 4-component formats supported) */ 90 case PIPE_FORMAT_R32_FLOAT: 91 return SVGA3D_R_S23E8; 92 case PIPE_FORMAT_R32G32_FLOAT: 93 return SVGA3D_RG_S23E8; 94 case PIPE_FORMAT_R32G32B32A32_FLOAT: 95 return SVGA3D_ARGB_S23E8; 96 case PIPE_FORMAT_R16_FLOAT: 97 return SVGA3D_R_S10E5; 98 case PIPE_FORMAT_R16G16_FLOAT: 99 return SVGA3D_RG_S10E5; 100 case PIPE_FORMAT_R16G16B16A16_FLOAT: 101 return SVGA3D_ARGB_S10E5; 102 103 case PIPE_FORMAT_Z32_UNORM: 104 /* SVGA3D_Z_D32 is not yet unsupported */ 105 /* fall-through */ 106 default: 107 return SVGA3D_FORMAT_INVALID; 108 } 109 } 110 111 112 /* 113 * Format capability description entry. 114 */ 115 struct format_cap { 116 SVGA3dSurfaceFormat format; 117 118 /* 119 * Capability index corresponding to the format. 120 */ 121 SVGA3dDevCapIndex index; 122 123 /* 124 * Mask of supported SVGA3dFormatOp operations, to be inferred when the 125 * capability is not explicitly present. 126 */ 127 uint32 defaultOperations; 128 }; 129 130 131 /* 132 * Format capability description table. 133 * 134 * Ordererd by increasing SVGA3dSurfaceFormat value, but with gaps. 135 */ 136 static const struct format_cap format_cap_table[] = { 137 { 138 SVGA3D_X8R8G8B8, 139 SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8, 140 SVGA3DFORMAT_OP_TEXTURE | 141 SVGA3DFORMAT_OP_CUBETEXTURE | 142 SVGA3DFORMAT_OP_VOLUMETEXTURE | 143 SVGA3DFORMAT_OP_DISPLAYMODE | 144 SVGA3DFORMAT_OP_3DACCELERATION | 145 SVGA3DFORMAT_OP_CONVERT_TO_ARGB | 146 SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | 147 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 148 SVGA3DFORMAT_OP_SRGBREAD | 149 SVGA3DFORMAT_OP_SRGBWRITE | 150 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 151 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 152 }, 153 { 154 SVGA3D_A8R8G8B8, 155 SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8, 156 SVGA3DFORMAT_OP_TEXTURE | 157 SVGA3DFORMAT_OP_CUBETEXTURE | 158 SVGA3DFORMAT_OP_VOLUMETEXTURE | 159 SVGA3DFORMAT_OP_CONVERT_TO_ARGB | 160 SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | 161 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 162 SVGA3DFORMAT_OP_SRGBREAD | 163 SVGA3DFORMAT_OP_SRGBWRITE | 164 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 165 SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET | 166 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 167 }, 168 { 169 SVGA3D_R5G6B5, 170 SVGA3D_DEVCAP_SURFACEFMT_R5G6B5, 171 SVGA3DFORMAT_OP_TEXTURE | 172 SVGA3DFORMAT_OP_CUBETEXTURE | 173 SVGA3DFORMAT_OP_VOLUMETEXTURE | 174 SVGA3DFORMAT_OP_DISPLAYMODE | 175 SVGA3DFORMAT_OP_3DACCELERATION | 176 SVGA3DFORMAT_OP_CONVERT_TO_ARGB | 177 SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | 178 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 179 SVGA3DFORMAT_OP_SRGBREAD | 180 SVGA3DFORMAT_OP_SRGBWRITE | 181 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 182 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 183 }, 184 { 185 SVGA3D_X1R5G5B5, 186 SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5, 187 SVGA3DFORMAT_OP_TEXTURE | 188 SVGA3DFORMAT_OP_CUBETEXTURE | 189 SVGA3DFORMAT_OP_VOLUMETEXTURE | 190 SVGA3DFORMAT_OP_CONVERT_TO_ARGB | 191 SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | 192 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 193 SVGA3DFORMAT_OP_SRGBREAD | 194 SVGA3DFORMAT_OP_SRGBWRITE | 195 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 196 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 197 }, 198 { 199 SVGA3D_A1R5G5B5, 200 SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5, 201 SVGA3DFORMAT_OP_TEXTURE | 202 SVGA3DFORMAT_OP_CUBETEXTURE | 203 SVGA3DFORMAT_OP_VOLUMETEXTURE | 204 SVGA3DFORMAT_OP_CONVERT_TO_ARGB | 205 SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | 206 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 207 SVGA3DFORMAT_OP_SRGBREAD | 208 SVGA3DFORMAT_OP_SRGBWRITE | 209 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 210 SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET | 211 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 212 }, 213 { 214 SVGA3D_A4R4G4B4, 215 SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4, 216 SVGA3DFORMAT_OP_TEXTURE | 217 SVGA3DFORMAT_OP_CUBETEXTURE | 218 SVGA3DFORMAT_OP_VOLUMETEXTURE | 219 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 220 SVGA3DFORMAT_OP_SRGBREAD | 221 SVGA3DFORMAT_OP_SRGBWRITE | 222 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 223 SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET | 224 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 225 }, 226 /* 227 * SVGA3D_Z_D32 is not yet supported, and has no corresponding 228 * SVGA3D_DEVCAP_xxx. 229 */ 230 { 231 SVGA3D_Z_D16, 232 SVGA3D_DEVCAP_SURFACEFMT_Z_D16, 233 SVGA3DFORMAT_OP_ZSTENCIL | 234 SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH 235 }, 236 { 237 SVGA3D_Z_D24S8, 238 SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8, 239 SVGA3DFORMAT_OP_ZSTENCIL | 240 SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH 241 }, 242 { 243 SVGA3D_Z_D15S1, 244 SVGA3D_DEVCAP_MAX, 245 SVGA3DFORMAT_OP_ZSTENCIL | 246 SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH 247 }, 248 { 249 SVGA3D_LUMINANCE8, 250 SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8, 251 SVGA3DFORMAT_OP_TEXTURE | 252 SVGA3DFORMAT_OP_CUBETEXTURE | 253 SVGA3DFORMAT_OP_VOLUMETEXTURE | 254 SVGA3DFORMAT_OP_OFFSCREENPLAIN 255 }, 256 { 257 SVGA3D_LUMINANCE8_ALPHA8, 258 SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8, 259 SVGA3DFORMAT_OP_TEXTURE | 260 SVGA3DFORMAT_OP_CUBETEXTURE | 261 SVGA3DFORMAT_OP_VOLUMETEXTURE | 262 SVGA3DFORMAT_OP_OFFSCREENPLAIN 263 }, 264 /* 265 * SVGA3D_LUMINANCE4_ALPHA4 is not supported, and has no corresponding 266 * SVGA3D_DEVCAP_xxx. 267 */ 268 { 269 SVGA3D_LUMINANCE16, 270 SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16, 271 SVGA3DFORMAT_OP_TEXTURE | 272 SVGA3DFORMAT_OP_CUBETEXTURE | 273 SVGA3DFORMAT_OP_VOLUMETEXTURE | 274 SVGA3DFORMAT_OP_OFFSCREENPLAIN 275 }, 276 { 277 SVGA3D_DXT1, 278 SVGA3D_DEVCAP_SURFACEFMT_DXT1, 279 SVGA3DFORMAT_OP_TEXTURE | 280 SVGA3DFORMAT_OP_SRGBREAD | 281 SVGA3DFORMAT_OP_CUBETEXTURE | 282 SVGA3DFORMAT_OP_OFFSCREENPLAIN 283 }, 284 { 285 SVGA3D_DXT2, 286 SVGA3D_DEVCAP_SURFACEFMT_DXT2, 287 SVGA3DFORMAT_OP_TEXTURE | 288 SVGA3DFORMAT_OP_SRGBREAD | 289 SVGA3DFORMAT_OP_CUBETEXTURE | 290 SVGA3DFORMAT_OP_OFFSCREENPLAIN 291 }, 292 { 293 SVGA3D_DXT3, 294 SVGA3D_DEVCAP_SURFACEFMT_DXT3, 295 SVGA3DFORMAT_OP_TEXTURE | 296 SVGA3DFORMAT_OP_SRGBREAD | 297 SVGA3DFORMAT_OP_CUBETEXTURE | 298 SVGA3DFORMAT_OP_OFFSCREENPLAIN 299 }, 300 { 301 SVGA3D_DXT4, 302 SVGA3D_DEVCAP_SURFACEFMT_DXT4, 303 SVGA3DFORMAT_OP_TEXTURE | 304 SVGA3DFORMAT_OP_SRGBREAD | 305 SVGA3DFORMAT_OP_CUBETEXTURE | 306 SVGA3DFORMAT_OP_OFFSCREENPLAIN 307 }, 308 { 309 SVGA3D_DXT5, 310 SVGA3D_DEVCAP_SURFACEFMT_DXT5, 311 SVGA3DFORMAT_OP_TEXTURE | 312 SVGA3DFORMAT_OP_SRGBREAD | 313 SVGA3DFORMAT_OP_CUBETEXTURE | 314 SVGA3DFORMAT_OP_OFFSCREENPLAIN 315 }, 316 { 317 SVGA3D_BUMPU8V8, 318 SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8, 319 SVGA3DFORMAT_OP_TEXTURE | 320 SVGA3DFORMAT_OP_CUBETEXTURE | 321 SVGA3DFORMAT_OP_VOLUMETEXTURE | 322 SVGA3DFORMAT_OP_BUMPMAP | 323 SVGA3DFORMAT_OP_OFFSCREENPLAIN 324 }, 325 /* 326 * SVGA3D_BUMPL6V5U5 is unsupported; it has no corresponding 327 * SVGA3D_DEVCAP_xxx. 328 */ 329 { 330 SVGA3D_BUMPX8L8V8U8, 331 SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8, 332 SVGA3DFORMAT_OP_TEXTURE | 333 SVGA3DFORMAT_OP_CUBETEXTURE | 334 SVGA3DFORMAT_OP_BUMPMAP | 335 SVGA3DFORMAT_OP_OFFSCREENPLAIN 336 }, 337 /* 338 * SVGA3D_BUMPL8V8U8 is unsupported; it has no corresponding 339 * SVGA3D_DEVCAP_xxx. SVGA3D_BUMPX8L8V8U8 should be used instead. 340 */ 341 { 342 SVGA3D_ARGB_S10E5, 343 SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5, 344 SVGA3DFORMAT_OP_TEXTURE | 345 SVGA3DFORMAT_OP_CUBETEXTURE | 346 SVGA3DFORMAT_OP_VOLUMETEXTURE | 347 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 348 SVGA3DFORMAT_OP_SRGBREAD | 349 SVGA3DFORMAT_OP_SRGBWRITE | 350 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 351 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 352 }, 353 { 354 SVGA3D_ARGB_S23E8, 355 SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8, 356 SVGA3DFORMAT_OP_TEXTURE | 357 SVGA3DFORMAT_OP_CUBETEXTURE | 358 SVGA3DFORMAT_OP_VOLUMETEXTURE | 359 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 360 SVGA3DFORMAT_OP_SRGBREAD | 361 SVGA3DFORMAT_OP_SRGBWRITE | 362 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 363 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 364 }, 365 { 366 SVGA3D_A2R10G10B10, 367 SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10, 368 SVGA3DFORMAT_OP_TEXTURE | 369 SVGA3DFORMAT_OP_CUBETEXTURE | 370 SVGA3DFORMAT_OP_VOLUMETEXTURE | 371 SVGA3DFORMAT_OP_CONVERT_TO_ARGB | 372 SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB | 373 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 374 SVGA3DFORMAT_OP_SRGBREAD | 375 SVGA3DFORMAT_OP_SRGBWRITE | 376 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 377 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 378 }, 379 /* 380 * SVGA3D_V8U8 is unsupported; it has no corresponding 381 * SVGA3D_DEVCAP_xxx. SVGA3D_BUMPU8V8 should be used instead. 382 */ 383 { 384 SVGA3D_Q8W8V8U8, 385 SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8, 386 SVGA3DFORMAT_OP_TEXTURE | 387 SVGA3DFORMAT_OP_CUBETEXTURE | 388 SVGA3DFORMAT_OP_BUMPMAP | 389 SVGA3DFORMAT_OP_OFFSCREENPLAIN 390 }, 391 { 392 SVGA3D_CxV8U8, 393 SVGA3D_DEVCAP_SURFACEFMT_CxV8U8, 394 SVGA3DFORMAT_OP_TEXTURE | 395 SVGA3DFORMAT_OP_BUMPMAP | 396 SVGA3DFORMAT_OP_OFFSCREENPLAIN 397 }, 398 /* 399 * SVGA3D_X8L8V8U8 is unsupported; it has no corresponding 400 * SVGA3D_DEVCAP_xxx. SVGA3D_BUMPX8L8V8U8 should be used instead. 401 */ 402 { 403 SVGA3D_A2W10V10U10, 404 SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10, 405 SVGA3DFORMAT_OP_TEXTURE | 406 SVGA3DFORMAT_OP_BUMPMAP | 407 SVGA3DFORMAT_OP_OFFSCREENPLAIN 408 }, 409 { 410 SVGA3D_ALPHA8, 411 SVGA3D_DEVCAP_SURFACEFMT_ALPHA8, 412 SVGA3DFORMAT_OP_TEXTURE | 413 SVGA3DFORMAT_OP_CUBETEXTURE | 414 SVGA3DFORMAT_OP_VOLUMETEXTURE | 415 SVGA3DFORMAT_OP_OFFSCREENPLAIN 416 }, 417 { 418 SVGA3D_R_S10E5, 419 SVGA3D_DEVCAP_SURFACEFMT_R_S10E5, 420 SVGA3DFORMAT_OP_TEXTURE | 421 SVGA3DFORMAT_OP_VOLUMETEXTURE | 422 SVGA3DFORMAT_OP_CUBETEXTURE | 423 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 424 SVGA3DFORMAT_OP_SRGBREAD | 425 SVGA3DFORMAT_OP_SRGBWRITE | 426 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 427 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 428 }, 429 { 430 SVGA3D_R_S23E8, 431 SVGA3D_DEVCAP_SURFACEFMT_R_S23E8, 432 SVGA3DFORMAT_OP_TEXTURE | 433 SVGA3DFORMAT_OP_VOLUMETEXTURE | 434 SVGA3DFORMAT_OP_CUBETEXTURE | 435 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 436 SVGA3DFORMAT_OP_SRGBREAD | 437 SVGA3DFORMAT_OP_SRGBWRITE | 438 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 439 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 440 }, 441 { 442 SVGA3D_RG_S10E5, 443 SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5, 444 SVGA3DFORMAT_OP_TEXTURE | 445 SVGA3DFORMAT_OP_VOLUMETEXTURE | 446 SVGA3DFORMAT_OP_CUBETEXTURE | 447 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 448 SVGA3DFORMAT_OP_SRGBREAD | 449 SVGA3DFORMAT_OP_SRGBWRITE | 450 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 451 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 452 }, 453 { 454 SVGA3D_RG_S23E8, 455 SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8, 456 SVGA3DFORMAT_OP_TEXTURE | 457 SVGA3DFORMAT_OP_VOLUMETEXTURE | 458 SVGA3DFORMAT_OP_CUBETEXTURE | 459 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 460 SVGA3DFORMAT_OP_SRGBREAD | 461 SVGA3DFORMAT_OP_SRGBWRITE | 462 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 463 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 464 }, 465 /* 466 * SVGA3D_BUFFER is a placeholder format for index/vertex buffers. 467 */ 468 { 469 SVGA3D_Z_D24X8, 470 SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8, 471 SVGA3DFORMAT_OP_ZSTENCIL | 472 SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH 473 }, 474 { 475 SVGA3D_V16U16, 476 SVGA3D_DEVCAP_SURFACEFMT_V16U16, 477 SVGA3DFORMAT_OP_TEXTURE | 478 SVGA3DFORMAT_OP_CUBETEXTURE | 479 SVGA3DFORMAT_OP_VOLUMETEXTURE | 480 SVGA3DFORMAT_OP_BUMPMAP | 481 SVGA3DFORMAT_OP_OFFSCREENPLAIN 482 }, 483 { 484 SVGA3D_G16R16, 485 SVGA3D_DEVCAP_SURFACEFMT_G16R16, 486 SVGA3DFORMAT_OP_TEXTURE | 487 SVGA3DFORMAT_OP_CUBETEXTURE | 488 SVGA3DFORMAT_OP_VOLUMETEXTURE | 489 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 490 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 491 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 492 }, 493 { 494 SVGA3D_A16B16G16R16, 495 SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16, 496 SVGA3DFORMAT_OP_TEXTURE | 497 SVGA3DFORMAT_OP_CUBETEXTURE | 498 SVGA3DFORMAT_OP_VOLUMETEXTURE | 499 SVGA3DFORMAT_OP_OFFSCREENPLAIN | 500 SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET | 501 SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET 502 }, 503 { 504 SVGA3D_UYVY, 505 SVGA3D_DEVCAP_SURFACEFMT_UYVY, 506 0 507 }, 508 { 509 SVGA3D_YUY2, 510 SVGA3D_DEVCAP_SURFACEFMT_YUY2, 511 0 512 }, 513 { 514 SVGA3D_NV12, 515 SVGA3D_DEVCAP_SURFACEFMT_NV12, 516 0 517 }, 518 { 519 SVGA3D_AYUV, 520 SVGA3D_DEVCAP_SURFACEFMT_AYUV, 521 0 522 }, 523 { 524 SVGA3D_BC4_UNORM, 525 SVGA3D_DEVCAP_SURFACEFMT_BC4_UNORM, 526 0 527 }, 528 { 529 SVGA3D_BC5_UNORM, 530 SVGA3D_DEVCAP_SURFACEFMT_BC5_UNORM, 531 0 532 }, 533 { 534 SVGA3D_Z_DF16, 535 SVGA3D_DEVCAP_SURFACEFMT_Z_DF16, 536 0 537 }, 538 { 539 SVGA3D_Z_DF24, 540 SVGA3D_DEVCAP_SURFACEFMT_Z_DF24, 541 0 542 }, 543 { 544 SVGA3D_Z_D24S8_INT, 545 SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT, 546 0 547 }, 548 }; 549 550 551 /* 552 * Get format capabilities from the host. It takes in consideration 553 * deprecated/unsupported formats, and formats which are implicitely assumed to 554 * be supported when the host does not provide an explicit capability entry. 555 */ 556 void 557 svga_get_format_cap(struct svga_screen *ss, 558 SVGA3dSurfaceFormat format, 559 SVGA3dSurfaceFormatCaps *caps) 560 { 561 const struct format_cap *entry; 562 563 for (entry = format_cap_table; entry < format_cap_table + Elements(format_cap_table); ++entry) { 564 if (entry->format == format) { 565 struct svga_winsys_screen *sws = ss->sws; 566 SVGA3dDevCapResult result; 567 568 if (sws->get_cap(sws, entry->index, &result)) { 569 /* Explicitly advertised format */ 570 caps->value = result.u; 571 } else { 572 /* Implicitly advertised format -- use default caps */ 573 caps->value = entry->defaultOperations; 574 } 575 576 return; 577 } 578 } 579 580 /* Unsupported format */ 581 caps->value = 0; 582 } 583 584 585 /** 586 * Return block size and bytes per block for the given SVGA3D format. 587 * block_width and block_height are one for uncompressed formats and 588 * greater than one for compressed formats. 589 * Note: we don't handle formats that are unsupported, according to 590 * the format_cap_table above. 591 */ 592 void 593 svga_format_size(SVGA3dSurfaceFormat format, 594 unsigned *block_width, 595 unsigned *block_height, 596 unsigned *bytes_per_block) 597 { 598 *block_width = *block_height = 1; 599 600 switch (format) { 601 case SVGA3D_X8R8G8B8: 602 case SVGA3D_A8R8G8B8: 603 *bytes_per_block = 4; 604 return; 605 606 case SVGA3D_R5G6B5: 607 case SVGA3D_X1R5G5B5: 608 case SVGA3D_A1R5G5B5: 609 case SVGA3D_A4R4G4B4: 610 *bytes_per_block = 2; 611 return; 612 613 case SVGA3D_Z_D32: 614 *bytes_per_block = 4; 615 return; 616 617 case SVGA3D_Z_D16: 618 *bytes_per_block = 2; 619 return; 620 621 case SVGA3D_Z_D24S8: 622 *bytes_per_block = 4; 623 return; 624 625 case SVGA3D_Z_D15S1: 626 *bytes_per_block = 2; 627 return; 628 629 case SVGA3D_LUMINANCE8: 630 case SVGA3D_LUMINANCE4_ALPHA4: 631 *bytes_per_block = 1; 632 return; 633 634 case SVGA3D_LUMINANCE16: 635 case SVGA3D_LUMINANCE8_ALPHA8: 636 *bytes_per_block = 2; 637 return; 638 639 case SVGA3D_DXT1: 640 case SVGA3D_DXT2: 641 *block_width = *block_height = 4; 642 *bytes_per_block = 8; 643 return; 644 645 case SVGA3D_DXT3: 646 case SVGA3D_DXT4: 647 case SVGA3D_DXT5: 648 *block_width = *block_height = 4; 649 *bytes_per_block = 16; 650 return; 651 652 case SVGA3D_BUMPU8V8: 653 case SVGA3D_BUMPL6V5U5: 654 *bytes_per_block = 2; 655 return; 656 657 case SVGA3D_BUMPX8L8V8U8: 658 *bytes_per_block = 4; 659 return; 660 661 case SVGA3D_ARGB_S10E5: 662 *bytes_per_block = 8; 663 return; 664 665 case SVGA3D_ARGB_S23E8: 666 *bytes_per_block = 16; 667 return; 668 669 case SVGA3D_A2R10G10B10: 670 *bytes_per_block = 4; 671 return; 672 673 case SVGA3D_Q8W8V8U8: 674 *bytes_per_block = 4; 675 return; 676 677 case SVGA3D_CxV8U8: 678 *bytes_per_block = 2; 679 return; 680 681 case SVGA3D_X8L8V8U8: 682 case SVGA3D_A2W10V10U10: 683 *bytes_per_block = 4; 684 return; 685 686 case SVGA3D_ALPHA8: 687 *bytes_per_block = 1; 688 return; 689 690 case SVGA3D_R_S10E5: 691 *bytes_per_block = 2; 692 return; 693 case SVGA3D_R_S23E8: 694 *bytes_per_block = 4; 695 return; 696 case SVGA3D_RG_S10E5: 697 *bytes_per_block = 4; 698 return; 699 case SVGA3D_RG_S23E8: 700 *bytes_per_block = 8; 701 return; 702 703 case SVGA3D_BUFFER: 704 *bytes_per_block = 1; 705 return; 706 707 case SVGA3D_Z_D24X8: 708 *bytes_per_block = 4; 709 return; 710 711 case SVGA3D_V16U16: 712 *bytes_per_block = 4; 713 return; 714 715 case SVGA3D_G16R16: 716 *bytes_per_block = 4; 717 return; 718 719 case SVGA3D_A16B16G16R16: 720 *bytes_per_block = 8; 721 return; 722 723 case SVGA3D_Z_DF16: 724 *bytes_per_block = 2; 725 return; 726 case SVGA3D_Z_DF24: 727 *bytes_per_block = 4; 728 return; 729 case SVGA3D_Z_D24S8_INT: 730 *bytes_per_block = 4; 731 return; 732 733 default: 734 debug_printf("format %u\n", (unsigned) format); 735 assert(!"unexpected format in svga_format_size()"); 736 *bytes_per_block = 4; 737 } 738 } 739