17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2021 Alyssa Rosenzweig
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
207ec681f3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
217ec681f3Smrg * SOFTWARE.
227ec681f3Smrg */
237ec681f3Smrg
247ec681f3Smrg#include "agx_pack.h"
257ec681f3Smrg#include "agx_formats.h"
267ec681f3Smrg
277ec681f3Smrg#define T true
287ec681f3Smrg#define F false
297ec681f3Smrg#define AGX_FORMAT__ 0
307ec681f3Smrg
317ec681f3Smrg#define AGX_FMT(pipe, channels, type, is_renderable, internal_fmt) \
327ec681f3Smrg   [PIPE_FORMAT_ ## pipe] = { \
337ec681f3Smrg      .hw = (AGX_CHANNELS_ ## channels) | ((AGX_TEXTURE_TYPE_ ## type) << 7), \
347ec681f3Smrg      .renderable = is_renderable, \
357ec681f3Smrg      .internal = AGX_FORMAT_ ## internal_fmt,\
367ec681f3Smrg   }
377ec681f3Smrg
387ec681f3Smrgconst struct agx_pixel_format_entry agx_pixel_format[PIPE_FORMAT_COUNT] = {
397ec681f3Smrg   AGX_FMT(R8_UNORM,                R8,            UNORM,  T, U8NORM),
407ec681f3Smrg   AGX_FMT(R8G8_UNORM,              R8G8,          UNORM,  T, U8NORM),
417ec681f3Smrg   AGX_FMT(R8G8B8A8_UNORM,          R8G8B8A8,      UNORM,  T, U8NORM),
427ec681f3Smrg   AGX_FMT(A8R8G8B8_UNORM,          R8G8B8A8,      UNORM,  T, U8NORM),
437ec681f3Smrg   AGX_FMT(A8B8G8R8_UNORM,          R8G8B8A8,      UNORM,  T, U8NORM),
447ec681f3Smrg   AGX_FMT(B8G8R8A8_UNORM,          R8G8B8A8,      UNORM,  T, U8NORM),
457ec681f3Smrg
467ec681f3Smrg   AGX_FMT(R16_UNORM,               R16,           UNORM,  T, U16NORM),
477ec681f3Smrg   AGX_FMT(R16G16_UNORM,            R16G16,        UNORM,  T, U16NORM),
487ec681f3Smrg   AGX_FMT(R16G16B16A16_UNORM,      R16G16B16A16,  UNORM,  T, U16NORM),
497ec681f3Smrg
507ec681f3Smrg   AGX_FMT(R8_SRGB,                 R8,            UNORM,  T, SRGBA8),
517ec681f3Smrg   AGX_FMT(R8G8_SRGB,               R8G8,          UNORM,  T, SRGBA8),
527ec681f3Smrg   AGX_FMT(R8G8B8A8_SRGB,           R8G8B8A8,      UNORM,  T, SRGBA8),
537ec681f3Smrg   AGX_FMT(A8R8G8B8_SRGB,           R8G8B8A8,      UNORM,  T, SRGBA8),
547ec681f3Smrg   AGX_FMT(A8B8G8R8_SRGB,           R8G8B8A8,      UNORM,  T, SRGBA8),
557ec681f3Smrg   AGX_FMT(B8G8R8A8_SRGB,           R8G8B8A8,      UNORM,  T, SRGBA8),
567ec681f3Smrg
577ec681f3Smrg   AGX_FMT(R8_SNORM,                R8,            SNORM,  T, S8NORM),
587ec681f3Smrg   AGX_FMT(R8G8_SNORM,              R8G8,          SNORM,  T, S8NORM),
597ec681f3Smrg   AGX_FMT(R8G8B8A8_SNORM,          R8G8B8A8,      SNORM,  T, S8NORM),
607ec681f3Smrg   AGX_FMT(A8R8G8B8_SNORM,          R8G8B8A8,      SNORM,  T, S8NORM),
617ec681f3Smrg   AGX_FMT(A8B8G8R8_SNORM,          R8G8B8A8,      SNORM,  T, S8NORM),
627ec681f3Smrg   AGX_FMT(B8G8R8A8_SNORM,          R8G8B8A8,      SNORM,  T, S8NORM),
637ec681f3Smrg
647ec681f3Smrg   AGX_FMT(R16_FLOAT,               R16,           FLOAT,  T, F16),
657ec681f3Smrg   AGX_FMT(R16G16_FLOAT,            R16G16,        FLOAT,  T, F16),
667ec681f3Smrg   AGX_FMT(R16G16B16A16_FLOAT,      R16G16B16A16,  FLOAT,  T, F16),
677ec681f3Smrg
687ec681f3Smrg   AGX_FMT(R32_FLOAT,               R32,           FLOAT,  T, I32),
697ec681f3Smrg   AGX_FMT(R32G32_FLOAT,            R32G32,        FLOAT,  T, I32),
707ec681f3Smrg   AGX_FMT(R32G32B32A32_FLOAT,      R32G32B32A32,  FLOAT,  T, I32),
717ec681f3Smrg
727ec681f3Smrg   AGX_FMT(Z16_UNORM,               R16,           UNORM,  F, _),
737ec681f3Smrg   AGX_FMT(Z32_FLOAT,               R32,           FLOAT,  F, _),
747ec681f3Smrg   AGX_FMT(Z32_FLOAT_S8X24_UINT,    R32,           FLOAT,  F, _),
757ec681f3Smrg
767ec681f3Smrg   AGX_FMT(R10G10B10A2_UNORM,       R10G10B10A2,   UNORM,  T, RGB10A2),
777ec681f3Smrg   AGX_FMT(B10G10R10A2_UNORM,       R10G10B10A2,   UNORM,  T, RGB10A2),
787ec681f3Smrg   AGX_FMT(R11G11B10_FLOAT,         R11G11B10,     FLOAT,  T, RG11B10F),
797ec681f3Smrg   AGX_FMT(R9G9B9E5_FLOAT,          R9G9B9E5,      FLOAT,  F, RGB9E5),
807ec681f3Smrg
817ec681f3Smrg   AGX_FMT(ETC2_RGB8,               ETC2_RGB8,     UNORM,  F,_),
827ec681f3Smrg   AGX_FMT(ETC2_SRGB8,              ETC2_RGB8,     UNORM,  F,_),
837ec681f3Smrg   AGX_FMT(ETC2_RGB8A1,             ETC2_RGB8A1,   UNORM,  F,_),
847ec681f3Smrg   AGX_FMT(ETC2_SRGB8A1,            ETC2_RGB8A1,   UNORM,  F,_),
857ec681f3Smrg   AGX_FMT(ETC2_RGBA8,              ETC2_RGBA8,    UNORM,  F,_),
867ec681f3Smrg   AGX_FMT(ETC2_SRGBA8,             ETC2_RGBA8,    UNORM,  F,_),
877ec681f3Smrg   AGX_FMT(ETC2_R11_UNORM,          EAC_R11,       UNORM,  F,_),
887ec681f3Smrg   AGX_FMT(ETC2_R11_SNORM,          EAC_R11,       SNORM,  F,_),
897ec681f3Smrg   AGX_FMT(ETC2_RG11_UNORM,         EAC_RG11,      UNORM,  F,_),
907ec681f3Smrg   AGX_FMT(ETC2_RG11_SNORM,         EAC_RG11,      SNORM,  F,_),
917ec681f3Smrg};
927ec681f3Smrg
937ec681f3Smrgconst enum agx_format
947ec681f3Smrgagx_vertex_format[PIPE_FORMAT_COUNT] = {
957ec681f3Smrg   [PIPE_FORMAT_R32_FLOAT] = AGX_FORMAT_I32,
967ec681f3Smrg   [PIPE_FORMAT_R32_SINT] = AGX_FORMAT_I32,
977ec681f3Smrg   [PIPE_FORMAT_R32_UINT] = AGX_FORMAT_I32,
987ec681f3Smrg   [PIPE_FORMAT_R32G32_FLOAT] = AGX_FORMAT_I32,
997ec681f3Smrg   [PIPE_FORMAT_R32G32_SINT] = AGX_FORMAT_I32,
1007ec681f3Smrg   [PIPE_FORMAT_R32G32_UINT] = AGX_FORMAT_I32,
1017ec681f3Smrg   [PIPE_FORMAT_R32G32B32_FLOAT] = AGX_FORMAT_I32,
1027ec681f3Smrg   [PIPE_FORMAT_R32G32B32_UINT] = AGX_FORMAT_I32,
1037ec681f3Smrg   [PIPE_FORMAT_R32G32B32_SINT] = AGX_FORMAT_I32,
1047ec681f3Smrg   [PIPE_FORMAT_R32G32B32A32_FLOAT] = AGX_FORMAT_I32,
1057ec681f3Smrg   [PIPE_FORMAT_R32G32B32A32_UINT] = AGX_FORMAT_I32,
1067ec681f3Smrg   [PIPE_FORMAT_R32G32B32A32_SINT] = AGX_FORMAT_I32,
1077ec681f3Smrg
1087ec681f3Smrg   [PIPE_FORMAT_R8_UNORM] = AGX_FORMAT_U8NORM,
1097ec681f3Smrg   [PIPE_FORMAT_R8G8_UNORM] = AGX_FORMAT_U8NORM,
1107ec681f3Smrg   [PIPE_FORMAT_R8G8B8_UNORM] = AGX_FORMAT_U8NORM,
1117ec681f3Smrg   [PIPE_FORMAT_R8G8B8A8_UNORM] = AGX_FORMAT_U8NORM,
1127ec681f3Smrg
1137ec681f3Smrg   [PIPE_FORMAT_R8_SNORM] = AGX_FORMAT_S8NORM,
1147ec681f3Smrg   [PIPE_FORMAT_R8G8_SNORM] = AGX_FORMAT_S8NORM,
1157ec681f3Smrg   [PIPE_FORMAT_R8G8B8_SNORM] = AGX_FORMAT_S8NORM,
1167ec681f3Smrg   [PIPE_FORMAT_R8G8B8A8_SNORM] = AGX_FORMAT_S8NORM,
1177ec681f3Smrg
1187ec681f3Smrg   [PIPE_FORMAT_R16_UNORM] = AGX_FORMAT_U16NORM,
1197ec681f3Smrg   [PIPE_FORMAT_R16G16_UNORM] = AGX_FORMAT_U16NORM,
1207ec681f3Smrg   [PIPE_FORMAT_R16G16B16_UNORM] = AGX_FORMAT_U16NORM,
1217ec681f3Smrg   [PIPE_FORMAT_R16G16B16A16_UNORM] = AGX_FORMAT_U16NORM,
1227ec681f3Smrg
1237ec681f3Smrg   [PIPE_FORMAT_R16_SNORM] = AGX_FORMAT_S16NORM,
1247ec681f3Smrg   [PIPE_FORMAT_R16G16_SNORM] = AGX_FORMAT_S16NORM,
1257ec681f3Smrg   [PIPE_FORMAT_R16G16B16_SNORM] = AGX_FORMAT_S16NORM,
1267ec681f3Smrg   [PIPE_FORMAT_R16G16B16A16_SNORM] = AGX_FORMAT_S16NORM,
1277ec681f3Smrg
1287ec681f3Smrg   [PIPE_FORMAT_R8_UINT] = AGX_FORMAT_I8,
1297ec681f3Smrg   [PIPE_FORMAT_R8G8_UINT] = AGX_FORMAT_I8,
1307ec681f3Smrg   [PIPE_FORMAT_R8G8B8_UINT] = AGX_FORMAT_I8,
1317ec681f3Smrg   [PIPE_FORMAT_R8G8B8A8_UINT] = AGX_FORMAT_I8,
1327ec681f3Smrg
1337ec681f3Smrg   [PIPE_FORMAT_R8_SINT] = AGX_FORMAT_I8,
1347ec681f3Smrg   [PIPE_FORMAT_R8G8_SINT] = AGX_FORMAT_I8,
1357ec681f3Smrg   [PIPE_FORMAT_R8G8B8_SINT] = AGX_FORMAT_I8,
1367ec681f3Smrg   [PIPE_FORMAT_R8G8B8A8_SINT] = AGX_FORMAT_I8,
1377ec681f3Smrg
1387ec681f3Smrg   [PIPE_FORMAT_R16_UINT] = AGX_FORMAT_I16,
1397ec681f3Smrg   [PIPE_FORMAT_R16G16_UINT] = AGX_FORMAT_I16,
1407ec681f3Smrg   [PIPE_FORMAT_R16G16B16_UINT] = AGX_FORMAT_I16,
1417ec681f3Smrg   [PIPE_FORMAT_R16G16B16A16_UINT] = AGX_FORMAT_I16,
1427ec681f3Smrg
1437ec681f3Smrg   [PIPE_FORMAT_R16_SINT] = AGX_FORMAT_I16,
1447ec681f3Smrg   [PIPE_FORMAT_R16G16_SINT] = AGX_FORMAT_I16,
1457ec681f3Smrg   [PIPE_FORMAT_R16G16B16_SINT] = AGX_FORMAT_I16,
1467ec681f3Smrg   [PIPE_FORMAT_R16G16B16A16_SINT] = AGX_FORMAT_I16,
1477ec681f3Smrg
1487ec681f3Smrg   [PIPE_FORMAT_R32_UINT] = AGX_FORMAT_I32,
1497ec681f3Smrg   [PIPE_FORMAT_R32G32_UINT] = AGX_FORMAT_I32,
1507ec681f3Smrg   [PIPE_FORMAT_R32G32B32_UINT] = AGX_FORMAT_I32,
1517ec681f3Smrg   [PIPE_FORMAT_R32G32B32A32_UINT] = AGX_FORMAT_I32,
1527ec681f3Smrg
1537ec681f3Smrg   [PIPE_FORMAT_R32_SINT] = AGX_FORMAT_I32,
1547ec681f3Smrg   [PIPE_FORMAT_R32G32_SINT] = AGX_FORMAT_I32,
1557ec681f3Smrg   [PIPE_FORMAT_R32G32B32_SINT] = AGX_FORMAT_I32,
1567ec681f3Smrg   [PIPE_FORMAT_R32G32B32A32_SINT] = AGX_FORMAT_I32,
1577ec681f3Smrg};
158