freedreno/ir3: support glsl linking for cmdline compiler

For .vert/.frag, now multiple can be specified on the cmdline for
purposes of linking, and the last one specified is the one that is
fed into the ir3 backend (and dumped along the way if --verbose is
specified)

Without this, varyings in frag shaders would appear as undefined.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
This commit is contained in:
Rob Clark 2016-06-24 15:17:27 -04:00 committed by Rob Clark
parent 07cfe4e6aa
commit 202710d110
1 changed files with 47 additions and 24 deletions

View File

@ -60,7 +60,7 @@ static void dump_info(struct ir3_shader_variant *so, const char *str)
int st_glsl_type_size(const struct glsl_type *type);
static nir_shader *
load_glsl(const char *filename, gl_shader_stage stage)
load_glsl(unsigned num_files, char* const* files, gl_shader_stage stage)
{
static const struct standalone_options options = {
.glsl_version = 140,
@ -68,9 +68,9 @@ load_glsl(const char *filename, gl_shader_stage stage)
};
struct gl_shader_program *prog;
prog = standalone_compile_shader(&options, 1, (char * const*)&filename);
prog = standalone_compile_shader(&options, num_files, files);
if (!prog)
errx(1, "couldn't parse `%s'", filename);
errx(1, "couldn't parse `%s'", files[0]);
nir_shader *nir = glsl_to_nir(prog, stage, ir3_get_compiler_options());
@ -129,7 +129,7 @@ read_file(const char *filename, void **ptr, size_t *size)
static void print_usage(void)
{
printf("Usage: ir3_compiler [OPTIONS]... <file.tgsi | file.vert | file.frag>\n");
printf("Usage: ir3_compiler [OPTIONS]... <file.tgsi | (file.vert | file.frag)*>\n");
printf(" --verbose - verbose compiler/debug messages\n");
printf(" --binning-pass - generate binning pass shader (VERT)\n");
printf(" --color-two-side - emulate two-sided color (FRAG)\n");
@ -147,7 +147,9 @@ static void print_usage(void)
int main(int argc, char **argv)
{
int ret = 0, n = 1;
const char *filename;
char *filenames[2];
int num_files = 0;
unsigned stage = 0;
struct ir3_shader_variant v;
struct ir3_shader s;
struct ir3_shader_key key = {};
@ -264,38 +266,59 @@ int main(int argc, char **argv)
}
debug_printf("\n");
filename = argv[n];
while (n < argc) {
char *filename = argv[n];
char *ext = rindex(filename, '.');
ret = read_file(filename, &ptr, &size);
if (ret) {
print_usage();
return ret;
if (strcmp(ext, ".tgsi") == 0) {
if (num_files != 0)
errx(1, "in TGSI mode, only a single file may be specified");
s.from_tgsi = true;
} else if (strcmp(ext, ".frag") == 0) {
if (s.from_tgsi)
errx(1, "cannot mix GLSL and TGSI");
if (num_files >= ARRAY_SIZE(filenames))
errx(1, "too many GLSL files");
stage = MESA_SHADER_FRAGMENT;
} else if (strcmp(ext, ".vert") == 0) {
if (s.from_tgsi)
errx(1, "cannot mix GLSL and TGSI");
if (num_files >= ARRAY_SIZE(filenames))
errx(1, "too many GLSL files");
stage = MESA_SHADER_VERTEX;
} else {
print_usage();
return -1;
}
filenames[num_files++] = filename;
n++;
}
if (fd_mesa_debug & FD_DBG_OPTMSGS)
debug_printf("%s\n", (char *)ptr);
nir_shader *nir;
char *ext = rindex(filename, '.');
if (strcmp(ext, ".tgsi") == 0) {
if (s.from_tgsi) {
struct tgsi_token toks[65536];
ret = read_file(filenames[0], &ptr, &size);
if (ret) {
print_usage();
return ret;
}
if (fd_mesa_debug & FD_DBG_OPTMSGS)
debug_printf("%s\n", (char *)ptr);
if (!tgsi_text_translate(ptr, toks, ARRAY_SIZE(toks)))
errx(1, "could not parse `%s'", filename);
errx(1, "could not parse `%s'", filenames[0]);
if (fd_mesa_debug & FD_DBG_OPTMSGS)
tgsi_dump(toks, 0);
nir = ir3_tgsi_to_nir(toks);
s.from_tgsi = true;
} else if (strcmp(ext, ".frag") == 0) {
nir = load_glsl(filename, MESA_SHADER_FRAGMENT);
s.from_tgsi = false;
} else if (strcmp(ext, ".vert") == 0) {
nir = load_glsl(filename, MESA_SHADER_FRAGMENT);
s.from_tgsi = false;
} else if (num_files > 0) {
nir = load_glsl(num_files, filenames, stage);
} else {
print_usage();
return -1;