Mesa (main): pan/bi: Use getopt for bifrost_compiler
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jul 29 23:09:19 UTC 2021
Module: Mesa
Branch: main
Commit: c6be4f85e3c443f4ec46e60e25054601e8af979a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c6be4f85e3c443f4ec46e60e25054601e8af979a
Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date: Mon Jul 19 15:52:19 2021 -0400
pan/bi: Use getopt for bifrost_compiler
Specify gpu id with --gpu-id or marketing name with --gpu. Still have
compile/disasm as commands, but allow -v for verbose printing.
Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12134>
---
src/panfrost/bifrost/bi_quirks.h | 7 ++++
src/panfrost/bifrost/cmdline.c | 91 +++++++++++++++++++++++++++++++++++-----
2 files changed, 88 insertions(+), 10 deletions(-)
diff --git a/src/panfrost/bifrost/bi_quirks.h b/src/panfrost/bifrost/bi_quirks.h
index aec92918071..995dc18661b 100644
--- a/src/panfrost/bifrost/bi_quirks.h
+++ b/src/panfrost/bifrost/bi_quirks.h
@@ -48,10 +48,17 @@ bifrost_get_quirks(unsigned product_id)
case 0x62:
return BIFROST_NO_PRELOAD;
case 0x70:
+ case 0x71:
case 0x72:
+ case 0x73:
case 0x74:
return 0;
+ case 0x90:
+ case 0x91:
case 0x92:
+ case 0x93:
+ case 0x94:
+ case 0x95:
return BIFROST_NO_PRELOAD;
default:
unreachable("Unknown Bifrost/Valhall GPU ID");
diff --git a/src/panfrost/bifrost/cmdline.c b/src/panfrost/bifrost/cmdline.c
index 75e3b31fd28..7aa98715d55 100644
--- a/src/panfrost/bifrost/cmdline.c
+++ b/src/panfrost/bifrost/cmdline.c
@@ -24,6 +24,7 @@
* SOFTWARE.
*/
+#include <getopt.h>
#include <string.h>
#include "disassemble.h"
#include "compiler.h"
@@ -36,6 +37,9 @@
#include "util/u_dynarray.h"
#include "bifrost_compile.h"
+unsigned gpu_id = 0x7212;
+int verbose = 0;
+
static gl_shader_stage
filename_to_stage(const char *stage)
{
@@ -187,7 +191,7 @@ compile_shader(int stages, char **files)
NIR_PASS_V(nir[i], nir_opt_constant_folding);
struct panfrost_compile_inputs inputs = {
- .gpu_id = 0x7212, /* Mali G52 */
+ .gpu_id = gpu_id,
};
struct pan_shader_info info = { 0 };
@@ -211,7 +215,7 @@ compile_shader(int stages, char **files)
(uint32_t)(ch2) << 16 | (uint32_t)(ch3) << 24)
static void
-disassemble(const char *filename, bool verbose)
+disassemble(const char *filename)
{
FILE *fp = fopen(filename, "rb");
assert(fp);
@@ -225,6 +229,7 @@ disassemble(const char *filename, bool verbose)
if (res != filesize) {
printf("Couldn't read full file\n");
}
+
fclose(fp);
if (filesize && code[0] == BI_FOURCC('M', 'B', 'S', '2')) {
@@ -247,19 +252,85 @@ disassemble(const char *filename, bool verbose)
int
main(int argc, char **argv)
{
+ char c;
+
if (argc < 2) {
printf("Pass a command\n");
exit(1);
}
- if (strcmp(argv[1], "compile") == 0)
- compile_shader(argc - 2, &argv[2]);
- else if (strcmp(argv[1], "disasm") == 0)
- disassemble(argv[2], false);
- else if (strcmp(argv[1], "disasm-verbose") == 0)
- disassemble(argv[2], true);
- else
- unreachable("Unknown command. Valid: compile/disasm");
+ static struct option longopts[] = {
+ { "id", optional_argument, NULL, 'i' },
+ { "gpu", optional_argument, NULL, 'g' },
+ { "verbose", no_argument, &verbose, 'v' },
+ { NULL, 0, NULL, 0 }
+ };
+
+ static struct {
+ const char *name;
+ unsigned major, minor;
+ } gpus[] = {
+ { "G71", 6, 0 },
+ { "G72", 6, 2 },
+ { "G51", 7, 0 },
+ { "G76", 7, 1 },
+ { "G52", 7, 2 },
+ { "G31", 7, 3 },
+ { "G77", 9, 0 },
+ { "G57", 9, 1 },
+ { "G78", 9, 2 },
+ { "G57", 9, 3 },
+ { "G68", 9, 4 },
+ { "G78AE", 9, 5 },
+ };
+
+ while ((c = getopt_long(argc, argv, "v:", longopts, NULL)) != -1) {
+
+ switch (c) {
+ case 'i':
+ gpu_id = atoi(optarg);
+
+ if (!gpu_id) {
+ fprintf(stderr, "Expected GPU ID, got %s\n", optarg);
+ return 1;
+ }
+
+ break;
+ case 'g':
+ gpu_id = 0;
+
+ /* Compatibility with the Arm compiler */
+ if (strncmp(optarg, "Mali-", 5) == 0) optarg += 5;
+
+ for (unsigned i = 0; i < ARRAY_SIZE(gpus); ++i) {
+ if (strcmp(gpus[i].name, optarg)) continue;
+
+ unsigned major = gpus[i].major;
+ unsigned minor = gpus[i].minor;
+
+ gpu_id = (major << 12) | (minor << 8);
+ break;
+ }
+
+ if (!gpu_id) {
+ fprintf(stderr, "Unknown GPU %s\n", optarg);
+ return 1;
+ }
+
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (strcmp(argv[optind], "compile") == 0)
+ compile_shader(argc - optind - 1, &argv[optind + 1]);
+ else if (strcmp(argv[optind], "disasm") == 0)
+ disassemble(argv[optind + 1]);
+ else {
+ fprintf(stderr, "Unknown command. Valid: compile/disasm\n");
+ return 1;
+ }
return 0;
}
More information about the mesa-commit
mailing list