1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (c) 2016 Etnaviv Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 12bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 13bf215546Sopenharmony_ci * of the Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Christian Gmeiner <christian.gmeiner@gmail.com> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "etnaviv_format.h" 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "hw/common_3d.xml.h" 30bf215546Sopenharmony_ci#include "hw/state.xml.h" 31bf215546Sopenharmony_ci#include "hw/state_3d.xml.h" 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#include "pipe/p_defines.h" 34bf215546Sopenharmony_ci#include "util/compiler.h" 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci/* Specifies the table of all the formats and their features. Also supplies 37bf215546Sopenharmony_ci * the helpers that look up various data in those tables. 38bf215546Sopenharmony_ci */ 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_cistruct etna_format { 41bf215546Sopenharmony_ci unsigned vtx; 42bf215546Sopenharmony_ci unsigned tex; 43bf215546Sopenharmony_ci unsigned pe; 44bf215546Sopenharmony_ci bool present; 45bf215546Sopenharmony_ci}; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci#define PE_FORMAT_NONE ~0 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci#define PE_FORMAT_MASK 0x7f 50bf215546Sopenharmony_ci#define PE_FORMAT(x) ((x) & PE_FORMAT_MASK) 51bf215546Sopenharmony_ci#define PE_FORMAT_RB_SWAP 0x80 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci#define PE_FORMAT_X8B8G8R8 (PE_FORMAT_X8R8G8B8 | PE_FORMAT_RB_SWAP) 54bf215546Sopenharmony_ci#define PE_FORMAT_A8B8G8R8 (PE_FORMAT_A8R8G8B8 | PE_FORMAT_RB_SWAP) 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci#define TS_SAMPLER_FORMAT_NONE ETNA_NO_MATCH 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci/* vertex + texture */ 59bf215546Sopenharmony_ci#define VT(pipe, vtxfmt, texfmt, rsfmt) \ 60bf215546Sopenharmony_ci [PIPE_FORMAT_##pipe] = { \ 61bf215546Sopenharmony_ci .vtx = FE_DATA_TYPE_##vtxfmt, \ 62bf215546Sopenharmony_ci .tex = TEXTURE_FORMAT_##texfmt, \ 63bf215546Sopenharmony_ci .pe = PE_FORMAT_##rsfmt, \ 64bf215546Sopenharmony_ci .present = 1, \ 65bf215546Sopenharmony_ci } 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci/* texture-only */ 68bf215546Sopenharmony_ci#define _T(pipe, fmt, rsfmt) \ 69bf215546Sopenharmony_ci [PIPE_FORMAT_##pipe] = { \ 70bf215546Sopenharmony_ci .vtx = ETNA_NO_MATCH, \ 71bf215546Sopenharmony_ci .tex = TEXTURE_FORMAT_##fmt, \ 72bf215546Sopenharmony_ci .pe = PE_FORMAT_##rsfmt, \ 73bf215546Sopenharmony_ci .present = 1, \ 74bf215546Sopenharmony_ci } 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci/* vertex-only */ 77bf215546Sopenharmony_ci#define V_(pipe, fmt, rsfmt) \ 78bf215546Sopenharmony_ci [PIPE_FORMAT_##pipe] = { \ 79bf215546Sopenharmony_ci .vtx = FE_DATA_TYPE_##fmt, \ 80bf215546Sopenharmony_ci .tex = ETNA_NO_MATCH, \ 81bf215546Sopenharmony_ci .pe = PE_FORMAT_##rsfmt, \ 82bf215546Sopenharmony_ci .present = 1, \ 83bf215546Sopenharmony_ci } 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_cistatic struct etna_format formats[PIPE_FORMAT_COUNT] = { 86bf215546Sopenharmony_ci /* 8-bit */ 87bf215546Sopenharmony_ci VT(R8_UNORM, UNSIGNED_BYTE, L8, R8), 88bf215546Sopenharmony_ci VT(R8_SNORM, BYTE, EXT_R8_SNORM | EXT_FORMAT, NONE), 89bf215546Sopenharmony_ci VT(R8_UINT, BYTE_I, EXT_R8I | EXT_FORMAT, R8I), 90bf215546Sopenharmony_ci VT(R8_SINT, BYTE_I, EXT_R8I | EXT_FORMAT, R8I), 91bf215546Sopenharmony_ci V_(R8_USCALED, UNSIGNED_BYTE, NONE), 92bf215546Sopenharmony_ci V_(R8_SSCALED, BYTE, NONE), 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci _T(A8_UNORM, A8, NONE), 95bf215546Sopenharmony_ci _T(L8_UNORM, L8, NONE), 96bf215546Sopenharmony_ci _T(I8_UNORM, I8, NONE), 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci /* 16-bit */ 99bf215546Sopenharmony_ci V_(R16_UNORM, UNSIGNED_SHORT, NONE), 100bf215546Sopenharmony_ci V_(R16_SNORM, SHORT, NONE), 101bf215546Sopenharmony_ci VT(R16_UINT, SHORT_I, EXT_R16I | EXT_FORMAT, R16I), 102bf215546Sopenharmony_ci VT(R16_SINT, SHORT_I, EXT_R16I | EXT_FORMAT, R16I), 103bf215546Sopenharmony_ci V_(R16_USCALED, UNSIGNED_SHORT, NONE), 104bf215546Sopenharmony_ci V_(R16_SSCALED, SHORT, NONE), 105bf215546Sopenharmony_ci VT(R16_FLOAT, HALF_FLOAT, EXT_R16F | EXT_FORMAT, R16F), 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci _T(B4G4R4A4_UNORM, A4R4G4B4, A4R4G4B4), 108bf215546Sopenharmony_ci _T(B4G4R4X4_UNORM, X4R4G4B4, X4R4G4B4), 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci _T(L8A8_UNORM, A8L8, NONE), 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci _T(Z16_UNORM, D16, NONE), 113bf215546Sopenharmony_ci _T(B5G6R5_UNORM, R5G6B5, R5G6B5), 114bf215546Sopenharmony_ci _T(B5G5R5A1_UNORM, A1R5G5B5, A1R5G5B5), 115bf215546Sopenharmony_ci _T(B5G5R5X1_UNORM, X1R5G5B5, X1R5G5B5), 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_ci VT(R8G8_UNORM, UNSIGNED_BYTE, EXT_G8R8 | EXT_FORMAT, G8R8), 118bf215546Sopenharmony_ci VT(R8G8_SNORM, BYTE, EXT_G8R8_SNORM | EXT_FORMAT, NONE), 119bf215546Sopenharmony_ci VT(R8G8_UINT, BYTE_I, EXT_G8R8I | EXT_FORMAT, G8R8I), 120bf215546Sopenharmony_ci VT(R8G8_SINT, BYTE_I, EXT_G8R8I | EXT_FORMAT, G8R8I), 121bf215546Sopenharmony_ci V_(R8G8_USCALED, UNSIGNED_BYTE, NONE), 122bf215546Sopenharmony_ci V_(R8G8_SSCALED, BYTE, NONE), 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci /* 24-bit */ 125bf215546Sopenharmony_ci V_(R8G8B8_UNORM, UNSIGNED_BYTE, NONE), 126bf215546Sopenharmony_ci V_(R8G8B8_SNORM, BYTE, NONE), 127bf215546Sopenharmony_ci V_(R8G8B8_UINT, BYTE_I, NONE), 128bf215546Sopenharmony_ci V_(R8G8B8_SINT, BYTE_I, NONE), 129bf215546Sopenharmony_ci V_(R8G8B8_USCALED, UNSIGNED_BYTE, NONE), 130bf215546Sopenharmony_ci V_(R8G8B8_SSCALED, BYTE, NONE), 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci /* 32-bit */ 133bf215546Sopenharmony_ci V_(R32_UNORM, UNSIGNED_INT, NONE), 134bf215546Sopenharmony_ci V_(R32_SNORM, INT, NONE), 135bf215546Sopenharmony_ci VT(R32_SINT, FLOAT, EXT_R32F | EXT_FORMAT, R32F), 136bf215546Sopenharmony_ci VT(R32_UINT, FLOAT, EXT_R32F | EXT_FORMAT, R32F), 137bf215546Sopenharmony_ci V_(R32_USCALED, UNSIGNED_INT, NONE), 138bf215546Sopenharmony_ci V_(R32_SSCALED, INT, NONE), 139bf215546Sopenharmony_ci VT(R32_FLOAT, FLOAT, EXT_R32F | EXT_FORMAT, R32F), 140bf215546Sopenharmony_ci V_(R32_FIXED, FIXED, NONE), 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci V_(R16G16_UNORM, UNSIGNED_SHORT, NONE), 143bf215546Sopenharmony_ci V_(R16G16_SNORM, SHORT, NONE), 144bf215546Sopenharmony_ci VT(R16G16_UINT, SHORT_I, EXT_G16R16I | EXT_FORMAT, G16R16I), 145bf215546Sopenharmony_ci VT(R16G16_SINT, SHORT_I, EXT_G16R16I | EXT_FORMAT, G16R16I), 146bf215546Sopenharmony_ci V_(R16G16_USCALED, UNSIGNED_SHORT, NONE), 147bf215546Sopenharmony_ci V_(R16G16_SSCALED, SHORT, NONE), 148bf215546Sopenharmony_ci VT(R16G16_FLOAT, HALF_FLOAT, EXT_G16R16F | EXT_FORMAT, G16R16F), 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci V_(A8B8G8R8_UNORM, UNSIGNED_BYTE, NONE), 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci VT(R8G8B8A8_UNORM, UNSIGNED_BYTE, A8B8G8R8, A8B8G8R8), 153bf215546Sopenharmony_ci VT(R8G8B8A8_SNORM, BYTE, EXT_A8B8G8R8_SNORM | EXT_FORMAT, NONE), 154bf215546Sopenharmony_ci _T(R8G8B8X8_UNORM, X8B8G8R8, X8B8G8R8), 155bf215546Sopenharmony_ci _T(R8G8B8X8_SNORM, EXT_X8B8G8R8_SNORM | EXT_FORMAT, NONE), 156bf215546Sopenharmony_ci VT(R8G8B8A8_UINT, BYTE_I, EXT_A8B8G8R8I | EXT_FORMAT, A8B8G8R8I), 157bf215546Sopenharmony_ci VT(R8G8B8A8_SINT, BYTE_I, EXT_A8B8G8R8I | EXT_FORMAT, A8B8G8R8I), 158bf215546Sopenharmony_ci V_(R8G8B8A8_USCALED, UNSIGNED_BYTE, A8B8G8R8), 159bf215546Sopenharmony_ci V_(R8G8B8A8_SSCALED, BYTE, A8B8G8R8), 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ci _T(B8G8R8A8_UNORM, A8R8G8B8, A8R8G8B8), 162bf215546Sopenharmony_ci _T(B8G8R8X8_UNORM, X8R8G8B8, X8R8G8B8), 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci VT(R10G10B10A2_UNORM, UNSIGNED_INT_2_10_10_10_REV, EXT_A2B10G10R10 | EXT_FORMAT, A2B10G10R10), 165bf215546Sopenharmony_ci _T(R10G10B10X2_UNORM, EXT_A2B10G10R10 | EXT_FORMAT, A2B10G10R10), 166bf215546Sopenharmony_ci V_(R10G10B10A2_SNORM, INT_2_10_10_10_REV, NONE), 167bf215546Sopenharmony_ci _T(R10G10B10A2_UINT, EXT_A2B10G10R10UI | EXT_FORMAT, A2B10G10R10UI), 168bf215546Sopenharmony_ci V_(R10G10B10A2_USCALED, UNSIGNED_INT_2_10_10_10_REV, NONE), 169bf215546Sopenharmony_ci V_(R10G10B10A2_SSCALED, INT_2_10_10_10_REV, NONE), 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci _T(X8Z24_UNORM, D24X8, NONE), 172bf215546Sopenharmony_ci _T(S8_UINT_Z24_UNORM, D24X8, NONE), 173bf215546Sopenharmony_ci 174bf215546Sopenharmony_ci _T(R9G9B9E5_FLOAT, E5B9G9R9, NONE), 175bf215546Sopenharmony_ci _T(R11G11B10_FLOAT, EXT_B10G11R11F | EXT_FORMAT, B10G11R11F), 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_ci /* 48-bit */ 178bf215546Sopenharmony_ci V_(R16G16B16_UNORM, UNSIGNED_SHORT, NONE), 179bf215546Sopenharmony_ci V_(R16G16B16_SNORM, SHORT, NONE), 180bf215546Sopenharmony_ci V_(R16G16B16_UINT, SHORT_I, NONE), 181bf215546Sopenharmony_ci V_(R16G16B16_SINT, SHORT_I, NONE), 182bf215546Sopenharmony_ci V_(R16G16B16_USCALED, UNSIGNED_SHORT, NONE), 183bf215546Sopenharmony_ci V_(R16G16B16_SSCALED, SHORT, NONE), 184bf215546Sopenharmony_ci V_(R16G16B16_FLOAT, HALF_FLOAT, NONE), 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci /* 64-bit */ 187bf215546Sopenharmony_ci V_(R16G16B16A16_UNORM, UNSIGNED_SHORT, NONE), 188bf215546Sopenharmony_ci V_(R16G16B16A16_SNORM, SHORT, NONE), 189bf215546Sopenharmony_ci VT(R16G16B16A16_UINT, SHORT_I, EXT_A16B16G16R16I | EXT_FORMAT, A16B16G16R16I), 190bf215546Sopenharmony_ci VT(R16G16B16A16_SINT, SHORT_I, EXT_A16B16G16R16I | EXT_FORMAT, A16B16G16R16I), 191bf215546Sopenharmony_ci V_(R16G16B16A16_USCALED, UNSIGNED_SHORT, NONE), 192bf215546Sopenharmony_ci V_(R16G16B16A16_SSCALED, SHORT, NONE), 193bf215546Sopenharmony_ci VT(R16G16B16A16_FLOAT, HALF_FLOAT, EXT_A16B16G16R16F | EXT_FORMAT, A16B16G16R16F), 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci V_(R32G32_UNORM, UNSIGNED_INT, NONE), 196bf215546Sopenharmony_ci V_(R32G32_SNORM, INT, NONE), 197bf215546Sopenharmony_ci VT(R32G32_UINT, FLOAT, EXT_G32R32F | EXT_FORMAT, G32R32F), 198bf215546Sopenharmony_ci VT(R32G32_SINT, FLOAT, EXT_G32R32F | EXT_FORMAT, G32R32F), 199bf215546Sopenharmony_ci V_(R32G32_USCALED, UNSIGNED_INT, NONE), 200bf215546Sopenharmony_ci V_(R32G32_SSCALED, INT, NONE), 201bf215546Sopenharmony_ci VT(R32G32_FLOAT, FLOAT, EXT_G32R32F | EXT_FORMAT, G32R32F), 202bf215546Sopenharmony_ci V_(R32G32_FIXED, FIXED, NONE), 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_ci /* 96-bit */ 205bf215546Sopenharmony_ci V_(R32G32B32_UNORM, UNSIGNED_INT, NONE), 206bf215546Sopenharmony_ci V_(R32G32B32_SNORM, INT, NONE), 207bf215546Sopenharmony_ci V_(R32G32B32_UINT, FLOAT, NONE), 208bf215546Sopenharmony_ci V_(R32G32B32_SINT, FLOAT, NONE), 209bf215546Sopenharmony_ci V_(R32G32B32_USCALED, UNSIGNED_INT, NONE), 210bf215546Sopenharmony_ci V_(R32G32B32_SSCALED, INT, NONE), 211bf215546Sopenharmony_ci V_(R32G32B32_FLOAT, FLOAT, NONE), 212bf215546Sopenharmony_ci V_(R32G32B32_FIXED, FIXED, NONE), 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_ci /* 128-bit */ 215bf215546Sopenharmony_ci V_(R32G32B32A32_UNORM, UNSIGNED_INT, NONE), 216bf215546Sopenharmony_ci V_(R32G32B32A32_SNORM, INT, NONE), 217bf215546Sopenharmony_ci V_(R32G32B32A32_UINT, FLOAT, NONE), 218bf215546Sopenharmony_ci V_(R32G32B32A32_SINT, FLOAT, NONE), 219bf215546Sopenharmony_ci V_(R32G32B32A32_USCALED, UNSIGNED_INT, NONE), 220bf215546Sopenharmony_ci V_(R32G32B32A32_SSCALED, INT, NONE), 221bf215546Sopenharmony_ci V_(R32G32B32A32_FLOAT, FLOAT, NONE), 222bf215546Sopenharmony_ci V_(R32G32B32A32_FIXED, FIXED, NONE), 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_ci /* compressed */ 225bf215546Sopenharmony_ci _T(ETC1_RGB8, ETC1, NONE), 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_ci _T(DXT1_RGB, DXT1, NONE), 228bf215546Sopenharmony_ci _T(DXT1_RGBA, DXT1, NONE), 229bf215546Sopenharmony_ci _T(DXT3_RGBA, DXT2_DXT3, NONE), 230bf215546Sopenharmony_ci _T(DXT5_RGBA, DXT4_DXT5, NONE), 231bf215546Sopenharmony_ci 232bf215546Sopenharmony_ci _T(ETC2_RGB8, EXT_NONE | EXT_FORMAT, NONE), /* Extd. format NONE doubles as ETC2_RGB8 */ 233bf215546Sopenharmony_ci _T(ETC2_RGB8A1, EXT_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 | EXT_FORMAT, NONE), 234bf215546Sopenharmony_ci _T(ETC2_RGBA8, EXT_RGBA8_ETC2_EAC | EXT_FORMAT, NONE), 235bf215546Sopenharmony_ci _T(ETC2_R11_UNORM, EXT_R11_EAC | EXT_FORMAT, NONE), 236bf215546Sopenharmony_ci _T(ETC2_R11_SNORM, EXT_SIGNED_R11_EAC | EXT_FORMAT, NONE), 237bf215546Sopenharmony_ci _T(ETC2_RG11_UNORM, EXT_RG11_EAC | EXT_FORMAT, NONE), 238bf215546Sopenharmony_ci _T(ETC2_RG11_SNORM, EXT_SIGNED_RG11_EAC | EXT_FORMAT, NONE), 239bf215546Sopenharmony_ci 240bf215546Sopenharmony_ci _T(ASTC_4x4, ASTC_RGBA_4x4 | ASTC_FORMAT, NONE), 241bf215546Sopenharmony_ci _T(ASTC_5x4, ASTC_RGBA_5x4 | ASTC_FORMAT, NONE), 242bf215546Sopenharmony_ci _T(ASTC_5x5, ASTC_RGBA_5x5 | ASTC_FORMAT, NONE), 243bf215546Sopenharmony_ci _T(ASTC_6x5, ASTC_RGBA_6x5 | ASTC_FORMAT, NONE), 244bf215546Sopenharmony_ci _T(ASTC_6x6, ASTC_RGBA_6x6 | ASTC_FORMAT, NONE), 245bf215546Sopenharmony_ci _T(ASTC_8x5, ASTC_RGBA_8x5 | ASTC_FORMAT, NONE), 246bf215546Sopenharmony_ci _T(ASTC_8x6, ASTC_RGBA_8x6 | ASTC_FORMAT, NONE), 247bf215546Sopenharmony_ci _T(ASTC_8x8, ASTC_RGBA_8x8 | ASTC_FORMAT, NONE), 248bf215546Sopenharmony_ci _T(ASTC_10x5, ASTC_RGBA_10x5 | ASTC_FORMAT, NONE), 249bf215546Sopenharmony_ci _T(ASTC_10x6, ASTC_RGBA_10x6 | ASTC_FORMAT, NONE), 250bf215546Sopenharmony_ci _T(ASTC_10x8, ASTC_RGBA_10x8 | ASTC_FORMAT, NONE), 251bf215546Sopenharmony_ci _T(ASTC_10x10, ASTC_RGBA_10x10 | ASTC_FORMAT, NONE), 252bf215546Sopenharmony_ci _T(ASTC_12x10, ASTC_RGBA_12x10 | ASTC_FORMAT, NONE), 253bf215546Sopenharmony_ci _T(ASTC_12x12, ASTC_RGBA_12x12 | ASTC_FORMAT, NONE), 254bf215546Sopenharmony_ci 255bf215546Sopenharmony_ci /* YUV */ 256bf215546Sopenharmony_ci _T(YUYV, YUY2, YUY2), 257bf215546Sopenharmony_ci _T(UYVY, UYVY, NONE), 258bf215546Sopenharmony_ci}; 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_ciuint32_t 261bf215546Sopenharmony_citranslate_texture_format(enum pipe_format fmt) 262bf215546Sopenharmony_ci{ 263bf215546Sopenharmony_ci fmt = util_format_linear(fmt); 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ci if (!formats[fmt].present) 266bf215546Sopenharmony_ci return ETNA_NO_MATCH; 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_ci return formats[fmt].tex; 269bf215546Sopenharmony_ci} 270bf215546Sopenharmony_ci 271bf215546Sopenharmony_cibool 272bf215546Sopenharmony_citexture_use_int_filter(const struct pipe_sampler_view *sv, 273bf215546Sopenharmony_ci const struct pipe_sampler_state *ss, 274bf215546Sopenharmony_ci bool tex_desc) 275bf215546Sopenharmony_ci{ 276bf215546Sopenharmony_ci switch (sv->target) { 277bf215546Sopenharmony_ci case PIPE_TEXTURE_1D_ARRAY: 278bf215546Sopenharmony_ci case PIPE_TEXTURE_2D_ARRAY: 279bf215546Sopenharmony_ci if (tex_desc) 280bf215546Sopenharmony_ci break; 281bf215546Sopenharmony_ci FALLTHROUGH; 282bf215546Sopenharmony_ci case PIPE_TEXTURE_3D: 283bf215546Sopenharmony_ci return false; 284bf215546Sopenharmony_ci default: 285bf215546Sopenharmony_ci break; 286bf215546Sopenharmony_ci } 287bf215546Sopenharmony_ci 288bf215546Sopenharmony_ci /* only unorm formats can use int filter */ 289bf215546Sopenharmony_ci if (!util_format_is_unorm(sv->format)) 290bf215546Sopenharmony_ci return false; 291bf215546Sopenharmony_ci 292bf215546Sopenharmony_ci if (util_format_is_srgb(sv->format)) 293bf215546Sopenharmony_ci return false; 294bf215546Sopenharmony_ci 295bf215546Sopenharmony_ci if (util_format_description(sv->format)->layout == UTIL_FORMAT_LAYOUT_ASTC) 296bf215546Sopenharmony_ci return false; 297bf215546Sopenharmony_ci 298bf215546Sopenharmony_ci if (ss->max_anisotropy > 1) 299bf215546Sopenharmony_ci return false; 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_ci switch (sv->format) { 302bf215546Sopenharmony_ci /* apparently D16 can't use int filter but D24 can */ 303bf215546Sopenharmony_ci case PIPE_FORMAT_Z16_UNORM: 304bf215546Sopenharmony_ci case PIPE_FORMAT_R10G10B10A2_UNORM: 305bf215546Sopenharmony_ci case PIPE_FORMAT_R10G10B10X2_UNORM: 306bf215546Sopenharmony_ci case PIPE_FORMAT_ETC2_R11_UNORM: 307bf215546Sopenharmony_ci case PIPE_FORMAT_ETC2_RG11_UNORM: 308bf215546Sopenharmony_ci return false; 309bf215546Sopenharmony_ci default: 310bf215546Sopenharmony_ci return true; 311bf215546Sopenharmony_ci } 312bf215546Sopenharmony_ci} 313bf215546Sopenharmony_ci 314bf215546Sopenharmony_cibool 315bf215546Sopenharmony_citexture_format_needs_swiz(enum pipe_format fmt) 316bf215546Sopenharmony_ci{ 317bf215546Sopenharmony_ci return util_format_linear(fmt) == PIPE_FORMAT_R8_UNORM; 318bf215546Sopenharmony_ci} 319bf215546Sopenharmony_ci 320bf215546Sopenharmony_ciuint32_t 321bf215546Sopenharmony_ciget_texture_swiz(enum pipe_format fmt, unsigned swizzle_r, 322bf215546Sopenharmony_ci unsigned swizzle_g, unsigned swizzle_b, unsigned swizzle_a) 323bf215546Sopenharmony_ci{ 324bf215546Sopenharmony_ci unsigned char swiz[4] = { 325bf215546Sopenharmony_ci swizzle_r, swizzle_g, swizzle_b, swizzle_a, 326bf215546Sopenharmony_ci }; 327bf215546Sopenharmony_ci 328bf215546Sopenharmony_ci if (util_format_linear(fmt) == PIPE_FORMAT_R8_UNORM) { 329bf215546Sopenharmony_ci /* R8 is emulated with L8, needs yz channels set to zero */ 330bf215546Sopenharmony_ci for (unsigned i = 0; i < 4; i++) { 331bf215546Sopenharmony_ci if (swiz[i] == PIPE_SWIZZLE_Y || swiz[i] == PIPE_SWIZZLE_Z) 332bf215546Sopenharmony_ci swiz[i] = PIPE_SWIZZLE_0; 333bf215546Sopenharmony_ci } 334bf215546Sopenharmony_ci } 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ci /* PIPE_SWIZZLE_ maps 1:1 to TEXTURE_SWIZZLE_ */ 337bf215546Sopenharmony_ci STATIC_ASSERT(PIPE_SWIZZLE_X == TEXTURE_SWIZZLE_RED); 338bf215546Sopenharmony_ci STATIC_ASSERT(PIPE_SWIZZLE_Y == TEXTURE_SWIZZLE_GREEN); 339bf215546Sopenharmony_ci STATIC_ASSERT(PIPE_SWIZZLE_Z == TEXTURE_SWIZZLE_BLUE); 340bf215546Sopenharmony_ci STATIC_ASSERT(PIPE_SWIZZLE_W == TEXTURE_SWIZZLE_ALPHA); 341bf215546Sopenharmony_ci STATIC_ASSERT(PIPE_SWIZZLE_0 == TEXTURE_SWIZZLE_ZERO); 342bf215546Sopenharmony_ci STATIC_ASSERT(PIPE_SWIZZLE_1 == TEXTURE_SWIZZLE_ONE); 343bf215546Sopenharmony_ci 344bf215546Sopenharmony_ci return VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_R(swiz[0]) | 345bf215546Sopenharmony_ci VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_G(swiz[1]) | 346bf215546Sopenharmony_ci VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_B(swiz[2]) | 347bf215546Sopenharmony_ci VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_A(swiz[3]); 348bf215546Sopenharmony_ci} 349bf215546Sopenharmony_ci 350bf215546Sopenharmony_ciuint32_t 351bf215546Sopenharmony_citranslate_pe_format(enum pipe_format fmt) 352bf215546Sopenharmony_ci{ 353bf215546Sopenharmony_ci fmt = util_format_linear(fmt); 354bf215546Sopenharmony_ci 355bf215546Sopenharmony_ci if (!formats[fmt].present) 356bf215546Sopenharmony_ci return ETNA_NO_MATCH; 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_ci if (formats[fmt].pe == ETNA_NO_MATCH) 359bf215546Sopenharmony_ci return ETNA_NO_MATCH; 360bf215546Sopenharmony_ci 361bf215546Sopenharmony_ci return PE_FORMAT(formats[fmt].pe); 362bf215546Sopenharmony_ci} 363bf215546Sopenharmony_ci 364bf215546Sopenharmony_ciint 365bf215546Sopenharmony_citranslate_pe_format_rb_swap(enum pipe_format fmt) 366bf215546Sopenharmony_ci{ 367bf215546Sopenharmony_ci fmt = util_format_linear(fmt); 368bf215546Sopenharmony_ci assert(formats[fmt].present); 369bf215546Sopenharmony_ci 370bf215546Sopenharmony_ci return formats[fmt].pe & PE_FORMAT_RB_SWAP; 371bf215546Sopenharmony_ci} 372bf215546Sopenharmony_ci 373bf215546Sopenharmony_ci/* Return type flags for vertex element format */ 374bf215546Sopenharmony_ciuint32_t 375bf215546Sopenharmony_citranslate_vertex_format_type(enum pipe_format fmt) 376bf215546Sopenharmony_ci{ 377bf215546Sopenharmony_ci if (!formats[fmt].present) 378bf215546Sopenharmony_ci return ETNA_NO_MATCH; 379bf215546Sopenharmony_ci 380bf215546Sopenharmony_ci return formats[fmt].vtx; 381bf215546Sopenharmony_ci} 382