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"
41 #include "etnaviv_shader.h"
43 #include "util/u_memory.h"
45 static const struct etna_specs specs_gc2000
= {
47 .has_sin_cos_sqrt
= 1,
48 .has_sign_floor_ceil
= 1,
49 .vertex_sampler_offset
= 8,
50 .vertex_output_buffer_size
= 512,
51 .vertex_cache_size
= 16,
52 .shader_core_count
= 4,
53 .max_instructions
= 512,
56 .max_vs_uniforms
= 168,
57 .max_ps_uniforms
= 128,
62 read_file(const char *filename
, void **ptr
, size_t *size
)
69 fd
= open(filename
, O_RDONLY
);
71 warnx("couldn't open `%s'", filename
);
77 errx(1, "couldn't stat `%s'", filename
);
80 *ptr
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_SHARED
, fd
, 0);
81 if (*ptr
== MAP_FAILED
)
82 errx(1, "couldn't map `%s'", filename
);
92 printf("Usage: etnaviv_compiler [OPTIONS]... FILE\n");
93 printf(" --verbose - verbose compiler/debug messages\n");
94 printf(" --frag-rb-swap - swap rb in color output (FRAG)\n");
95 printf(" --help - show this message\n");
99 main(int argc
, char **argv
)
102 const char *filename
;
103 struct tgsi_token toks
[65536];
104 struct tgsi_parse_context parse
;
105 struct etna_shader s
= {};
106 struct etna_shader_key key
= {};
110 struct etna_shader_variant
*v
= CALLOC_STRUCT(etna_shader_variant
);
112 fprintf(stderr
, "malloc failed!\n");
116 etna_mesa_debug
= ETNA_DBG_MSGS
;
119 if (!strcmp(argv
[n
], "--verbose")) {
120 etna_mesa_debug
|= ETNA_DBG_COMPILER_MSGS
;
125 if (!strcmp(argv
[n
], "--frag-rb-swap")) {
126 debug_printf(" %s", argv
[n
]);
127 key
.frag_rb_swap
= true;
132 if (!strcmp(argv
[n
], "--help")) {
142 ret
= read_file(filename
, &ptr
, &size
);
148 debug_printf("%s\n", (char *)ptr
);
150 if (!tgsi_text_translate(ptr
, toks
, ARRAY_SIZE(toks
)))
151 errx(1, "could not parse `%s'", filename
);
153 tgsi_parse_init(&parse
, toks
);
155 s
.specs
= &specs_gc2000
;
161 if (!etna_compile_shader(v
)) {
162 fprintf(stderr
, "compiler failed!\n");
167 etna_destroy_shader(v
);