2 * Copyright (c) 2015 Etnaviv Project
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Rob Clark <robclark@freedesktop.org>
25 * Christian Gmeiner <christian.gmeiner@gmail.com>
34 #include "tgsi/tgsi_dump.h"
35 #include "tgsi/tgsi_parse.h"
36 #include "tgsi/tgsi_text.h"
38 #include "etnaviv_compiler.h"
39 #include "etnaviv_debug.h"
40 #include "etnaviv_internal.h"
42 static const struct etna_specs specs_gc2000
= {
44 .has_sin_cos_sqrt
= 1,
45 .has_sign_floor_ceil
= 1,
46 .vertex_sampler_offset
= 8,
47 .vertex_output_buffer_size
= 512,
48 .vertex_cache_size
= 16,
49 .shader_core_count
= 4,
50 .max_instructions
= 512,
53 .max_vs_uniforms
= 168,
54 .max_ps_uniforms
= 128,
59 read_file(const char *filename
, void **ptr
, size_t *size
)
66 fd
= open(filename
, O_RDONLY
);
68 warnx("couldn't open `%s'", filename
);
74 errx(1, "couldn't stat `%s'", filename
);
77 *ptr
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_SHARED
, fd
, 0);
78 if (*ptr
== MAP_FAILED
)
79 errx(1, "couldn't map `%s'", filename
);
89 printf("Usage: etnaviv_compiler [OPTIONS]... FILE\n");
90 printf(" --verbose - verbose compiler/debug messages\n");
91 printf(" --help - show this message\n");
95 main(int argc
, char **argv
)
99 struct tgsi_token toks
[65536];
100 struct tgsi_parse_context parse
;
101 struct etna_shader_variant
*shader_obj
;
105 etna_mesa_debug
= ETNA_DBG_MSGS
;
108 if (!strcmp(argv
[n
], "--verbose")) {
109 etna_mesa_debug
|= ETNA_DBG_COMPILER_MSGS
;
114 if (!strcmp(argv
[n
], "--help")) {
124 ret
= read_file(filename
, &ptr
, &size
);
130 debug_printf("%s\n", (char *)ptr
);
132 if (!tgsi_text_translate(ptr
, toks
, ARRAY_SIZE(toks
)))
133 errx(1, "could not parse `%s'", filename
);
135 tgsi_parse_init(&parse
, toks
);
137 shader_obj
= etna_compile_shader(&specs_gc2000
, toks
);
139 if (shader_obj
== NULL
) {
140 fprintf(stderr
, "compiler failed!\n");
144 etna_dump_shader(shader_obj
);
145 etna_destroy_shader(shader_obj
);