| 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 |
| 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 = dev->props; |
| 75 |
uint32_t supported = pan_query_compressed_formats(&props); |
| 76 |
bool all_ok = true; |
| 77 |
|
| 78 |
printf("System-on-chip compressed texture support:" |
| 79 |
"\n\n"); |
| 80 |
|
| 81 |
for (unsigned i = 0; i < ARRAY_SIZE(formats); ++i) { |
| 82 |
if (formats[i].name == NULL) { |
| 83 |
printf("\n"); |
| 84 |
continue; |
| 85 |
} |
| 86 |
|
| 87 |
/* Maximum length for justification */ |
| 88 |
assert(strlen(formats[i].name) <= 12); |
| 89 |
|
| 90 |
bool ok = (supported & BITFIELD_BIT(formats[i].bit)); |
| 91 |
all_ok &= ok; |
| 92 |
|
| 93 |
printf("%-14s %s\n", formats[i].name, ok ? GREEN("YES") : RED(" NO")); |
| 94 |
} |
| 95 |
|
| 96 |
if (!all_ok) { |
| 97 |
printf( |
| 98 |
"\n" |
| 99 |
"This system-on-chip lacks support for some formats. This is not a driver bug.\n" |
| 100 |
"Unsupported formats will be emulated at a performance and memory cost.\n"); |
| 101 |
} |
| 102 |
|
| 103 |
pan_kmod_dev_destroy(dev); |
| 104 |
} |