xref: /aosp_15_r20/external/mesa3d/src/panfrost/tools/panfrost_texfeatures.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2022 Collabora, Ltd.
3  * Copyright 2022 Amazon.com, Inc. or its affiliates.
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #include <assert.h>
8 #include <stdbool.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <xf86drm.h>
14 
15 #include <lib/kmod/pan_kmod.h>
16 #include <lib/pan_props.h>
17 
18 /*
19  * Mapping of texture feature bits to compressed formats on Mali-G57, other
20  * Malis should be similar.
21  */
22 struct format {
23    unsigned bit;
24    const char *name;
25 };
26 
27 #define FMT(bit, name)                                                         \
28    {                                                                           \
29       bit, name ":"                                                            \
30    }
31 
32 static struct format formats[] = {
33    FMT(1, "ETC2"),
34    FMT(3, "ETC2 EAC"),
35    FMT(19, "ETC2 PTA"),
36    FMT(2, "EAC 1"),
37    FMT(4, "EAC 2"),
38    FMT(17, "EAC snorm 1"),
39    FMT(18, "EAC snorm 2"),
40    {0, NULL},
41    FMT(20, "ASTC 3D LDR"),
42    FMT(21, "ASTC 3D HDR"),
43    FMT(22, "ASTC 2D LDR"),
44    FMT(23, "ASTC 3D HDR"),
45    {0, NULL},
46    FMT(7, "BC1"),
47    FMT(8, "BC2"),
48    FMT(9, "BC3"),
49    FMT(10, "BC4 unorm"),
50    FMT(11, "BC4 snorm"),
51    FMT(12, "BC5 unorm"),
52    FMT(13, "BC5 snorm"),
53    FMT(14, "BC6H UF16"),
54    FMT(15, "BC6H SF16"),
55    FMT(16, "BC7"),
56 };
57 
58 /* ANSI escape code */
59 #define RESET    "\033[0m"
60 #define RED(x)   "\033[31m" x RESET
61 #define GREEN(x) "\033[32m" x RESET
62 
63 int
main(void)64 main(void)
65 {
66    int fd = drmOpenWithType("panfrost", NULL, DRM_NODE_RENDER);
67    if (fd < 0) {
68       fprintf(stderr, "No panfrost device\n");
69       exit(1);
70    }
71 
72    struct pan_kmod_dev *dev =
73       pan_kmod_dev_create(fd, PAN_KMOD_DEV_FLAG_OWNS_FD, NULL);
74    struct pan_kmod_dev_props props;
75 
76    pan_kmod_dev_query_props(dev, &props);
77 
78    uint32_t supported = panfrost_query_compressed_formats(&props);
79    bool all_ok = true;
80 
81    printf("System-on-chip compressed texture support:"
82           "\n\n");
83 
84    for (unsigned i = 0; i < ARRAY_SIZE(formats); ++i) {
85       if (formats[i].name == NULL) {
86          printf("\n");
87          continue;
88       }
89 
90       /* Maximum length for justification */
91       assert(strlen(formats[i].name) <= 12);
92 
93       bool ok = (supported & BITFIELD_BIT(formats[i].bit));
94       all_ok &= ok;
95 
96       printf("%-14s %s\n", formats[i].name, ok ? GREEN("YES") : RED(" NO"));
97    }
98 
99    if (!all_ok) {
100       printf(
101          "\n"
102          "This system-on-chip lacks support for some formats. This is not a driver bug.\n"
103          "Unsupported formats will be emulated at a performance and memory cost.\n");
104    }
105 
106    pan_kmod_dev_destroy(dev);
107 }
108