Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_compiler_cmdline.c
4570 views
/*1* Copyright (c) 2015 Etnaviv Project2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sub license,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the11* next paragraph) shall be included in all copies or substantial portions12* of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*22* Authors:23* Rob Clark <[email protected]>24* Christian Gmeiner <[email protected]>25*/2627#include <err.h>28#include <fcntl.h>29#include <sys/mman.h>30#include <sys/stat.h>31#include <unistd.h>3233#include "tgsi/tgsi_dump.h"34#include "tgsi/tgsi_parse.h"35#include "tgsi/tgsi_text.h"3637#include "etnaviv_compiler.h"38#include "etnaviv_debug.h"39#include "etnaviv_internal.h"40#include "etnaviv_shader.h"4142#include "util/u_memory.h"4344static const struct etna_specs specs_gc2000 = {45.vs_need_z_div = 0,46.has_sin_cos_sqrt = 1,47.has_sign_floor_ceil = 1,48.vertex_sampler_offset = 8,49.vertex_output_buffer_size = 512,50.vertex_cache_size = 16,51.shader_core_count = 4,52.max_instructions = 512,53.max_varyings = 12,54.max_registers = 64,55.max_vs_uniforms = 168,56.max_ps_uniforms = 128,57.num_constants = 168,58};5960static int61read_file(const char *filename, void **ptr, size_t *size)62{63int fd, ret;64struct stat st;6566*ptr = MAP_FAILED;6768fd = open(filename, O_RDONLY);69if (fd == -1) {70warnx("couldn't open `%s'", filename);71return 1;72}7374ret = fstat(fd, &st);75if (ret)76errx(1, "couldn't stat `%s'", filename);7778*size = st.st_size;79*ptr = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);80if (*ptr == MAP_FAILED)81errx(1, "couldn't map `%s'", filename);8283close(fd);8485return 0;86}8788static void89print_usage(void)90{91printf("Usage: etnaviv_compiler [OPTIONS]... FILE\n");92printf(" --verbose - verbose compiler/debug messages\n");93printf(" --frag-rb-swap - swap rb in color output (FRAG)\n");94printf(" --help - show this message\n");95}9697int98main(int argc, char **argv)99{100int ret = 0, n = 1;101const char *filename;102struct tgsi_token toks[65536];103struct tgsi_parse_context parse;104struct etna_shader s = {};105struct etna_shader_key key = {};106void *ptr;107size_t size;108109struct etna_shader_variant *v = CALLOC_STRUCT(etna_shader_variant);110if (!v) {111fprintf(stderr, "malloc failed!\n");112return 1;113}114115etna_mesa_debug = ETNA_DBG_MSGS;116117while (n < argc) {118if (!strcmp(argv[n], "--verbose")) {119etna_mesa_debug |= ETNA_DBG_COMPILER_MSGS;120n++;121continue;122}123124if (!strcmp(argv[n], "--frag-rb-swap")) {125debug_printf(" %s", argv[n]);126key.frag_rb_swap = true;127n++;128continue;129}130131if (!strcmp(argv[n], "--help")) {132print_usage();133return 0;134}135136break;137}138139filename = argv[n];140141ret = read_file(filename, &ptr, &size);142if (ret) {143print_usage();144return ret;145}146147debug_printf("%s\n", (char *)ptr);148149if (!tgsi_text_translate(ptr, toks, ARRAY_SIZE(toks)))150errx(1, "could not parse `%s'", filename);151152tgsi_parse_init(&parse, toks);153154s.specs = &specs_gc2000;155s.tokens = toks;156157v->shader = &s;158v->key = key;159160if (!etna_compile_shader(v)) {161fprintf(stderr, "compiler failed!\n");162return 1;163}164165etna_dump_shader(v);166etna_destroy_shader(v);167}168169170