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@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12134>
This commit is contained in:
committed by
Marge Bot
parent
4c5f1ef3ca
commit
c6be4f85e3
@@ -48,10 +48,17 @@ bifrost_get_quirks(unsigned product_id)
|
|||||||
case 0x62:
|
case 0x62:
|
||||||
return BIFROST_NO_PRELOAD;
|
return BIFROST_NO_PRELOAD;
|
||||||
case 0x70:
|
case 0x70:
|
||||||
|
case 0x71:
|
||||||
case 0x72:
|
case 0x72:
|
||||||
|
case 0x73:
|
||||||
case 0x74:
|
case 0x74:
|
||||||
return 0;
|
return 0;
|
||||||
|
case 0x90:
|
||||||
|
case 0x91:
|
||||||
case 0x92:
|
case 0x92:
|
||||||
|
case 0x93:
|
||||||
|
case 0x94:
|
||||||
|
case 0x95:
|
||||||
return BIFROST_NO_PRELOAD;
|
return BIFROST_NO_PRELOAD;
|
||||||
default:
|
default:
|
||||||
unreachable("Unknown Bifrost/Valhall GPU ID");
|
unreachable("Unknown Bifrost/Valhall GPU ID");
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <getopt.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "disassemble.h"
|
#include "disassemble.h"
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
@@ -36,6 +37,9 @@
|
|||||||
#include "util/u_dynarray.h"
|
#include "util/u_dynarray.h"
|
||||||
#include "bifrost_compile.h"
|
#include "bifrost_compile.h"
|
||||||
|
|
||||||
|
unsigned gpu_id = 0x7212;
|
||||||
|
int verbose = 0;
|
||||||
|
|
||||||
static gl_shader_stage
|
static gl_shader_stage
|
||||||
filename_to_stage(const char *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);
|
NIR_PASS_V(nir[i], nir_opt_constant_folding);
|
||||||
|
|
||||||
struct panfrost_compile_inputs inputs = {
|
struct panfrost_compile_inputs inputs = {
|
||||||
.gpu_id = 0x7212, /* Mali G52 */
|
.gpu_id = gpu_id,
|
||||||
};
|
};
|
||||||
struct pan_shader_info info = { 0 };
|
struct pan_shader_info info = { 0 };
|
||||||
|
|
||||||
@@ -211,7 +215,7 @@ compile_shader(int stages, char **files)
|
|||||||
(uint32_t)(ch2) << 16 | (uint32_t)(ch3) << 24)
|
(uint32_t)(ch2) << 16 | (uint32_t)(ch3) << 24)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disassemble(const char *filename, bool verbose)
|
disassemble(const char *filename)
|
||||||
{
|
{
|
||||||
FILE *fp = fopen(filename, "rb");
|
FILE *fp = fopen(filename, "rb");
|
||||||
assert(fp);
|
assert(fp);
|
||||||
@@ -225,6 +229,7 @@ disassemble(const char *filename, bool verbose)
|
|||||||
if (res != filesize) {
|
if (res != filesize) {
|
||||||
printf("Couldn't read full file\n");
|
printf("Couldn't read full file\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if (filesize && code[0] == BI_FOURCC('M', 'B', 'S', '2')) {
|
if (filesize && code[0] == BI_FOURCC('M', 'B', 'S', '2')) {
|
||||||
@@ -247,19 +252,85 @@ disassemble(const char *filename, bool verbose)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("Pass a command\n");
|
printf("Pass a command\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(argv[1], "compile") == 0)
|
static struct option longopts[] = {
|
||||||
compile_shader(argc - 2, &argv[2]);
|
{ "id", optional_argument, NULL, 'i' },
|
||||||
else if (strcmp(argv[1], "disasm") == 0)
|
{ "gpu", optional_argument, NULL, 'g' },
|
||||||
disassemble(argv[2], false);
|
{ "verbose", no_argument, &verbose, 'v' },
|
||||||
else if (strcmp(argv[1], "disasm-verbose") == 0)
|
{ NULL, 0, NULL, 0 }
|
||||||
disassemble(argv[2], true);
|
};
|
||||||
else
|
|
||||||
unreachable("Unknown command. Valid: compile/disasm");
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user