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(Z16_UNORM, R16, UNORM, F, _), 73 AGX_FMT(Z32_FLOAT, R32, FLOAT, F, _), 74 AGX_FMT(Z32_FLOAT_S8X24_UINT, R32, FLOAT, F, _), 75 76 AGX_FMT(R10G10B10A2_UNORM, R10G10B10A2, UNORM, T, RGB10A2), 77 AGX_FMT(B10G10R10A2_UNORM, R10G10B10A2, UNORM, T, RGB10A2), 78 AGX_FMT(R11G11B10_FLOAT, R11G11B10, FLOAT, T, RG11B10F), 79 AGX_FMT(R9G9B9E5_FLOAT, R9G9B9E5, FLOAT, F, RGB9E5), 80 81 AGX_FMT(ETC2_RGB8, ETC2_RGB8, UNORM, F,_), 82 AGX_FMT(ETC2_SRGB8, ETC2_RGB8, UNORM, F,_), 83 AGX_FMT(ETC2_RGB8A1, ETC2_RGB8A1, UNORM, F,_), 84 AGX_FMT(ETC2_SRGB8A1, ETC2_RGB8A1, UNORM, F,_), 85 AGX_FMT(ETC2_RGBA8, ETC2_RGBA8, UNORM, F,_), 86 AGX_FMT(ETC2_SRGBA8, ETC2_RGBA8, UNORM, F,_), 87 AGX_FMT(ETC2_R11_UNORM, EAC_R11, UNORM, F,_), 88 AGX_FMT(ETC2_R11_SNORM, EAC_R11, SNORM, F,_), 89 AGX_FMT(ETC2_RG11_UNORM, EAC_RG11, UNORM, F,_), 90 AGX_FMT(ETC2_RG11_SNORM, EAC_RG11, SNORM, F,_), 91 }; 92 93 const enum agx_format 94 agx_vertex_format[PIPE_FORMAT_COUNT] = { 95 [PIPE_FORMAT_R32_FLOAT] = AGX_FORMAT_I32, 96 [PIPE_FORMAT_R32_SINT] = AGX_FORMAT_I32, 97 [PIPE_FORMAT_R32_UINT] = AGX_FORMAT_I32, 98 [PIPE_FORMAT_R32G32_FLOAT] = AGX_FORMAT_I32, 99 [PIPE_FORMAT_R32G32_SINT] = AGX_FORMAT_I32, 100 [PIPE_FORMAT_R32G32_UINT] = AGX_FORMAT_I32, 101 [PIPE_FORMAT_R32G32B32_FLOAT] = AGX_FORMAT_I32, 102 [PIPE_FORMAT_R32G32B32_UINT] = AGX_FORMAT_I32, 103 [PIPE_FORMAT_R32G32B32_SINT] = AGX_FORMAT_I32, 104 [PIPE_FORMAT_R32G32B32A32_FLOAT] = AGX_FORMAT_I32, 105 [PIPE_FORMAT_R32G32B32A32_UINT] = AGX_FORMAT_I32, 106 [PIPE_FORMAT_R32G32B32A32_SINT] = AGX_FORMAT_I32, 107 108 [PIPE_FORMAT_R8_UNORM] = AGX_FORMAT_U8NORM, 109 [PIPE_FORMAT_R8G8_UNORM] = AGX_FORMAT_U8NORM, 110 [PIPE_FORMAT_R8G8B8_UNORM] = AGX_FORMAT_U8NORM, 111 [PIPE_FORMAT_R8G8B8A8_UNORM] = AGX_FORMAT_U8NORM, 112 113 [PIPE_FORMAT_R8_SNORM] = AGX_FORMAT_S8NORM, 114 [PIPE_FORMAT_R8G8_SNORM] = AGX_FORMAT_S8NORM, 115 [PIPE_FORMAT_R8G8B8_SNORM] = AGX_FORMAT_S8NORM, 116 [PIPE_FORMAT_R8G8B8A8_SNORM] = AGX_FORMAT_S8NORM, 117 118 [PIPE_FORMAT_R16_UNORM] = AGX_FORMAT_U16NORM, 119 [PIPE_FORMAT_R16G16_UNORM] = AGX_FORMAT_U16NORM, 120 [PIPE_FORMAT_R16G16B16_UNORM] = AGX_FORMAT_U16NORM, 121 [PIPE_FORMAT_R16G16B16A16_UNORM] = AGX_FORMAT_U16NORM, 122 123 [PIPE_FORMAT_R16_SNORM] = AGX_FORMAT_S16NORM, 124 [PIPE_FORMAT_R16G16_SNORM] = AGX_FORMAT_S16NORM, 125 [PIPE_FORMAT_R16G16B16_SNORM] = AGX_FORMAT_S16NORM, 126 [PIPE_FORMAT_R16G16B16A16_SNORM] = AGX_FORMAT_S16NORM, 127 128 [PIPE_FORMAT_R8_UINT] = AGX_FORMAT_I8, 129 [PIPE_FORMAT_R8G8_UINT] = AGX_FORMAT_I8, 130 [PIPE_FORMAT_R8G8B8_UINT] = AGX_FORMAT_I8, 131 [PIPE_FORMAT_R8G8B8A8_UINT] = AGX_FORMAT_I8, 132 133 [PIPE_FORMAT_R8_SINT] = AGX_FORMAT_I8, 134 [PIPE_FORMAT_R8G8_SINT] = AGX_FORMAT_I8, 135 [PIPE_FORMAT_R8G8B8_SINT] = AGX_FORMAT_I8, 136 [PIPE_FORMAT_R8G8B8A8_SINT] = AGX_FORMAT_I8, 137 138 [PIPE_FORMAT_R16_UINT] = AGX_FORMAT_I16, 139 [PIPE_FORMAT_R16G16_UINT] = AGX_FORMAT_I16, 140 [PIPE_FORMAT_R16G16B16_UINT] = AGX_FORMAT_I16, 141 [PIPE_FORMAT_R16G16B16A16_UINT] = AGX_FORMAT_I16, 142 143 [PIPE_FORMAT_R16_SINT] = AGX_FORMAT_I16, 144 [PIPE_FORMAT_R16G16_SINT] = AGX_FORMAT_I16, 145 [PIPE_FORMAT_R16G16B16_SINT] = AGX_FORMAT_I16, 146 [PIPE_FORMAT_R16G16B16A16_SINT] = AGX_FORMAT_I16, 147 148 [PIPE_FORMAT_R32_UINT] = AGX_FORMAT_I32, 149 [PIPE_FORMAT_R32G32_UINT] = AGX_FORMAT_I32, 150 [PIPE_FORMAT_R32G32B32_UINT] = AGX_FORMAT_I32, 151 [PIPE_FORMAT_R32G32B32A32_UINT] = AGX_FORMAT_I32, 152 153 [PIPE_FORMAT_R32_SINT] = AGX_FORMAT_I32, 154 [PIPE_FORMAT_R32G32_SINT] = AGX_FORMAT_I32, 155 [PIPE_FORMAT_R32G32B32_SINT] = AGX_FORMAT_I32, 156 [PIPE_FORMAT_R32G32B32A32_SINT] = AGX_FORMAT_I32, 157 }; 158