1 /* 2 * Copyright (C) 2021 Alyssa Rosenzweig 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 FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 */ 23 24 #include "agx_pack.h" 25 #include "agx_formats.h" 26 27 #define T true 28 #define F false 29 #define AGX_FORMAT__ 0 30 31 #define AGX_FMT(pipe, channels, type, is_renderable, internal_fmt) \ 32 [PIPE_FORMAT_ ## pipe] = { \ 33 .hw = (AGX_CHANNELS_ ## channels) | ((AGX_TEXTURE_TYPE_ ## type) << 7), \ 34 .renderable = is_renderable, \ 35 .internal = AGX_FORMAT_ ## internal_fmt,\ 36 } 37 38 const struct agx_pixel_format_entry agx_pixel_format[PIPE_FORMAT_COUNT] = { 39 AGX_FMT(R8_UNORM, R8, UNORM, T, U8NORM), 40 AGX_FMT(R8G8_UNORM, R8G8, UNORM, T, U8NORM), 41 AGX_FMT(R8G8B8A8_UNORM, R8G8B8A8, UNORM, T, U8NORM), 42 AGX_FMT(A8R8G8B8_UNORM, R8G8B8A8, UNORM, T, U8NORM), 43 AGX_FMT(A8B8G8R8_UNORM, R8G8B8A8, UNORM, T, U8NORM), 44 AGX_FMT(B8G8R8A8_UNORM, R8G8B8A8, UNORM, T, U8NORM), 45 46 AGX_FMT(R16_UNORM, R16, UNORM, T, U16NORM), 47 AGX_FMT(R16G16_UNORM, R16G16, UNORM, T, U16NORM), 48 AGX_FMT(R16G16B16A16_UNORM, R16G16B16A16, UNORM, T, U16NORM), 49 50 AGX_FMT(R8_SRGB, R8, UNORM, T, SRGBA8), 51 AGX_FMT(R8G8_SRGB, R8G8, UNORM, T, SRGBA8), 52 AGX_FMT(R8G8B8A8_SRGB, R8G8B8A8, UNORM, T, SRGBA8), 53 AGX_FMT(A8R8G8B8_SRGB, R8G8B8A8, UNORM, T, SRGBA8), 54 AGX_FMT(A8B8G8R8_SRGB, R8G8B8A8, UNORM, T, SRGBA8), 55 AGX_FMT(B8G8R8A8_SRGB, R8G8B8A8, UNORM, T, SRGBA8), 56 57 AGX_FMT(R8_SNORM, R8, SNORM, T, S8NORM), 58 AGX_FMT(R8G8_SNORM, R8G8, SNORM, T, S8NORM), 59 AGX_FMT(R8G8B8A8_SNORM, R8G8B8A8, SNORM, T, S8NORM), 60 AGX_FMT(A8R8G8B8_SNORM, R8G8B8A8, SNORM, T, S8NORM), 61 AGX_FMT(A8B8G8R8_SNORM, R8G8B8A8, SNORM, T, S8NORM), 62 AGX_FMT(B8G8R8A8_SNORM, R8G8B8A8, SNORM, T, S8NORM), 63 64 AGX_FMT(R16_FLOAT, R16, FLOAT, T, F16), 65 AGX_FMT(R16G16_FLOAT, R16G16, FLOAT, T, F16), 66 AGX_FMT(R16G16B16A16_FLOAT, R16G16B16A16, FLOAT, T, F16), 67 68 AGX_FMT(R32_FLOAT, R32, FLOAT, T, I32), 69 AGX_FMT(R32G32_FLOAT, R32G32, FLOAT, T, I32), 70 AGX_FMT(R32G32B32A32_FLOAT, R32G32B32A32, FLOAT, T, I32), 71 72 AGX_FMT(R8_UINT, R8, UINT, T, I8), 73 AGX_FMT(R8G8_UINT, R8G8, UINT, T, I8), 74 AGX_FMT(R8G8B8A8_UINT, R8G8B8A8, UINT, T, I8), 75 76 AGX_FMT(R16_UINT, R16, UINT, T, I16), 77 AGX_FMT(R16G16_UINT, R16G16, UINT, T, I16), 78 AGX_FMT(R16G16B16A16_UINT, R16G16B16A16, UINT, T, I16), 79 80 AGX_FMT(R32_UINT, R32, UINT, T, I32), 81 AGX_FMT(R32G32_UINT, R32G32, UINT, T, I32), 82 AGX_FMT(R32G32B32A32_UINT, R32G32B32A32, UINT, T, I32), 83 84 AGX_FMT(R8_SINT, R8, SINT, T, I8), 85 AGX_FMT(R8G8_SINT, R8G8, SINT, T, I8), 86 AGX_FMT(R8G8B8A8_SINT, R8G8B8A8, SINT, T, I8), 87 88 AGX_FMT(R16_SINT, R16, SINT, T, I16), 89 AGX_FMT(R16G16_SINT, R16G16, SINT, T, I16), 90 AGX_FMT(R16G16B16A16_SINT, R16G16B16A16, SINT, T, I16), 91 92 AGX_FMT(R32_SINT, R32, SINT, T, I32), 93 AGX_FMT(R32G32_SINT, R32G32, SINT, T, I32), 94 AGX_FMT(R32G32B32A32_SINT, R32G32B32A32, SINT, T, I32), 95 96 AGX_FMT(Z16_UNORM, R16, UNORM, F, _), 97 AGX_FMT(Z32_FLOAT, R32, FLOAT, F, _), 98 AGX_FMT(Z32_FLOAT_S8X24_UINT, R32, FLOAT, F, _), 99 100 /* These must be lowered by u_transfer_helper to Z32F */ 101 AGX_FMT(Z24X8_UNORM, R32, FLOAT, F, _), 102 AGX_FMT(Z24_UNORM_S8_UINT, R32, FLOAT, F, _), 103 104 AGX_FMT(R10G10B10A2_UNORM, R10G10B10A2, UNORM, T, RGB10A2), 105 AGX_FMT(B10G10R10A2_UNORM, R10G10B10A2, UNORM, T, RGB10A2), 106 107 AGX_FMT(R10G10B10A2_UINT, R10G10B10A2, UINT, T, _), 108 AGX_FMT(B10G10R10A2_UINT, R10G10B10A2, UINT, T, _), 109 110 AGX_FMT(R10G10B10A2_SINT, R10G10B10A2, SINT, T, _), 111 AGX_FMT(B10G10R10A2_SINT, R10G10B10A2, SINT, T, _), 112 113 AGX_FMT(R11G11B10_FLOAT, R11G11B10, FLOAT, T, RG11B10F), 114 AGX_FMT(R9G9B9E5_FLOAT, R9G9B9E5, FLOAT, F, RGB9E5), 115 116 AGX_FMT(ETC2_RGB8, ETC2_RGB8, UNORM, F,_), 117 AGX_FMT(ETC2_SRGB8, ETC2_RGB8, UNORM, F,_), 118 AGX_FMT(ETC2_RGB8A1, ETC2_RGB8A1, UNORM, F,_), 119 AGX_FMT(ETC2_SRGB8A1, ETC2_RGB8A1, UNORM, F,_), 120 AGX_FMT(ETC2_RGBA8, ETC2_RGBA8, UNORM, F,_), 121 AGX_FMT(ETC2_SRGBA8, ETC2_RGBA8, UNORM, F,_), 122 AGX_FMT(ETC2_R11_UNORM, EAC_R11, UNORM, F,_), 123 AGX_FMT(ETC2_R11_SNORM, EAC_R11, SNORM, F,_), 124 AGX_FMT(ETC2_RG11_UNORM, EAC_RG11, UNORM, F,_), 125 AGX_FMT(ETC2_RG11_SNORM, EAC_RG11, SNORM, F,_), 126 }; 127 128 const enum agx_format 129 agx_vertex_format[PIPE_FORMAT_COUNT] = { 130 [PIPE_FORMAT_R32_FLOAT] = AGX_FORMAT_I32, 131 [PIPE_FORMAT_R32_SINT] = AGX_FORMAT_I32, 132 [PIPE_FORMAT_R32_UINT] = AGX_FORMAT_I32, 133 [PIPE_FORMAT_R32G32_FLOAT] = AGX_FORMAT_I32, 134 [PIPE_FORMAT_R32G32_SINT] = AGX_FORMAT_I32, 135 [PIPE_FORMAT_R32G32_UINT] = AGX_FORMAT_I32, 136 [PIPE_FORMAT_R32G32B32_FLOAT] = AGX_FORMAT_I32, 137 [PIPE_FORMAT_R32G32B32_UINT] = AGX_FORMAT_I32, 138 [PIPE_FORMAT_R32G32B32_SINT] = AGX_FORMAT_I32, 139 [PIPE_FORMAT_R32G32B32A32_FLOAT] = AGX_FORMAT_I32, 140 [PIPE_FORMAT_R32G32B32A32_UINT] = AGX_FORMAT_I32, 141 [PIPE_FORMAT_R32G32B32A32_SINT] = AGX_FORMAT_I32, 142 143 [PIPE_FORMAT_R8_UNORM] = AGX_FORMAT_U8NORM, 144 [PIPE_FORMAT_R8G8_UNORM] = AGX_FORMAT_U8NORM, 145 [PIPE_FORMAT_R8G8B8_UNORM] = AGX_FORMAT_U8NORM, 146 [PIPE_FORMAT_R8G8B8A8_UNORM] = AGX_FORMAT_U8NORM, 147 148 [PIPE_FORMAT_R8_SNORM] = AGX_FORMAT_S8NORM, 149 [PIPE_FORMAT_R8G8_SNORM] = AGX_FORMAT_S8NORM, 150 [PIPE_FORMAT_R8G8B8_SNORM] = AGX_FORMAT_S8NORM, 151 [PIPE_FORMAT_R8G8B8A8_SNORM] = AGX_FORMAT_S8NORM, 152 153 [PIPE_FORMAT_R16_UNORM] = AGX_FORMAT_U16NORM, 154 [PIPE_FORMAT_R16G16_UNORM] = AGX_FORMAT_U16NORM, 155 [PIPE_FORMAT_R16G16B16_UNORM] = AGX_FORMAT_U16NORM, 156 [PIPE_FORMAT_R16G16B16A16_UNORM] = AGX_FORMAT_U16NORM, 157 158 [PIPE_FORMAT_R16_SNORM] = AGX_FORMAT_S16NORM, 159 [PIPE_FORMAT_R16G16_SNORM] = AGX_FORMAT_S16NORM, 160 [PIPE_FORMAT_R16G16B16_SNORM] = AGX_FORMAT_S16NORM, 161 [PIPE_FORMAT_R16G16B16A16_SNORM] = AGX_FORMAT_S16NORM, 162 163 [PIPE_FORMAT_R8_UINT] = AGX_FORMAT_I8, 164 [PIPE_FORMAT_R8G8_UINT] = AGX_FORMAT_I8, 165 [PIPE_FORMAT_R8G8B8_UINT] = AGX_FORMAT_I8, 166 [PIPE_FORMAT_R8G8B8A8_UINT] = AGX_FORMAT_I8, 167 168 [PIPE_FORMAT_R8_SINT] = AGX_FORMAT_I8, 169 [PIPE_FORMAT_R8G8_SINT] = AGX_FORMAT_I8, 170 [PIPE_FORMAT_R8G8B8_SINT] = AGX_FORMAT_I8, 171 [PIPE_FORMAT_R8G8B8A8_SINT] = AGX_FORMAT_I8, 172 173 [PIPE_FORMAT_R16_UINT] = AGX_FORMAT_I16, 174 [PIPE_FORMAT_R16G16_UINT] = AGX_FORMAT_I16, 175 [PIPE_FORMAT_R16G16B16_UINT] = AGX_FORMAT_I16, 176 [PIPE_FORMAT_R16G16B16A16_UINT] = AGX_FORMAT_I16, 177 178 [PIPE_FORMAT_R16_SINT] = AGX_FORMAT_I16, 179 [PIPE_FORMAT_R16G16_SINT] = AGX_FORMAT_I16, 180 [PIPE_FORMAT_R16G16B16_SINT] = AGX_FORMAT_I16, 181 [PIPE_FORMAT_R16G16B16A16_SINT] = AGX_FORMAT_I16, 182 183 [PIPE_FORMAT_R32_UINT] = AGX_FORMAT_I32, 184 [PIPE_FORMAT_R32G32_UINT] = AGX_FORMAT_I32, 185 [PIPE_FORMAT_R32G32B32_UINT] = AGX_FORMAT_I32, 186 [PIPE_FORMAT_R32G32B32A32_UINT] = AGX_FORMAT_I32, 187 188 [PIPE_FORMAT_R32_SINT] = AGX_FORMAT_I32, 189 [PIPE_FORMAT_R32G32_SINT] = AGX_FORMAT_I32, 190 [PIPE_FORMAT_R32G32B32_SINT] = AGX_FORMAT_I32, 191 [PIPE_FORMAT_R32G32B32A32_SINT] = AGX_FORMAT_I32, 192 }; 193