diff options
author | Rob Clark <robclark@freedesktop.org> | 2016-06-24 15:17:27 -0400 |
---|---|---|
committer | Rob Clark <robdclark@gmail.com> | 2016-07-02 09:00:19 -0400 |
commit | 202710d11057dfe4416770752cf5fd5b3f766999 (patch) | |
tree | e34ec5958b92f1f1b647c1289d5c5e78f0e8a386 /src/gallium/drivers/freedreno/ir3 | |
parent | 07cfe4e6aa2af646445c3e0f6be5eea60c721094 (diff) |
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>
Diffstat (limited to 'src/gallium/drivers/freedreno/ir3')
-rw-r--r-- | src/gallium/drivers/freedreno/ir3/ir3_cmdline.c | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c b/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c index 3e97ca5d63..41532fc4fb 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c +++ b/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c @@ -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, '.'); + + 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; + } - ret = read_file(filename, &ptr, &size); - if (ret) { - print_usage(); - return ret; - } + filenames[num_files++] = filename; - if (fd_mesa_debug & FD_DBG_OPTMSGS) - debug_printf("%s\n", (char *)ptr); + n++; + } 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; |