int main(int argc, char * const* argv) { int status = EXIT_SUCCESS; int c; int idx = 0; while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1) { switch (c) { case 'v': options.glsl_version = strtol(optarg, NULL, 10); break; default: break; } } if (argc <= optind) usage_fail(argv[0]); struct gl_shader_program *whole_program; whole_program = standalone_compile_shader(&options, argc - optind, &argv[optind]); if (!whole_program) usage_fail(argv[0]); standalone_compiler_cleanup(whole_program); return status; }
static nir_shader * load_glsl(unsigned num_files, char* const* files, gl_shader_stage stage) { static const struct standalone_options options = { .glsl_version = 140, .do_link = true, }; struct gl_shader_program *prog; prog = standalone_compile_shader(&options, num_files, files); if (!prog) errx(1, "couldn't parse `%s'", files[0]); nir_shader *nir = glsl_to_nir(prog, stage, ir3_get_compiler_options()); standalone_compiler_cleanup(prog); /* required NIR passes: */ /* TODO cmdline args for some of the conditional lowering passes? */ NIR_PASS_V(nir, nir_lower_io_to_temporaries, nir_shader_get_entrypoint(nir), true, true); NIR_PASS_V(nir, nir_lower_global_vars_to_local); NIR_PASS_V(nir, nir_split_var_copies); NIR_PASS_V(nir, nir_lower_var_copies); NIR_PASS_V(nir, nir_split_var_copies); NIR_PASS_V(nir, nir_lower_var_copies); NIR_PASS_V(nir, nir_lower_io_types); // TODO nir_assign_var_locations?? NIR_PASS_V(nir, nir_lower_system_values); NIR_PASS_V(nir, nir_lower_io, nir_var_all, st_glsl_type_size); NIR_PASS_V(nir, nir_lower_samplers, prog); return nir; } static int read_file(const char *filename, void **ptr, size_t *size) { int fd, ret; struct stat st; *ptr = MAP_FAILED; fd = open(filename, O_RDONLY); if (fd == -1) { warnx("couldn't open `%s'", filename); return 1; } ret = fstat(fd, &st); if (ret) errx(1, "couldn't stat `%s'", filename); *size = st.st_size; *ptr = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (*ptr == MAP_FAILED) errx(1, "couldn't map `%s'", filename); close(fd); return 0; }