1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* Copyright (c) 2015 Etnaviv Project
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sub license,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Authors:
* Rob Clark <robclark@freedesktop.org>
* Christian Gmeiner <christian.gmeiner@gmail.com>
*/
#include <err.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include "tgsi/tgsi_dump.h"
#include "tgsi/tgsi_parse.h"
#include "tgsi/tgsi_text.h"
#include "etnaviv_compiler.h"
#include "etnaviv_debug.h"
#include "etnaviv_internal.h"
#include "etnaviv_shader.h"
#include "util/u_memory.h"
static const struct etna_specs specs_gc2000 = {
.vs_need_z_div = 0,
.has_sin_cos_sqrt = 1,
.has_sign_floor_ceil = 1,
.vertex_sampler_offset = 8,
.vertex_output_buffer_size = 512,
.vertex_cache_size = 16,
.shader_core_count = 4,
.max_instructions = 512,
.max_varyings = 12,
.max_registers = 64,
.max_vs_uniforms = 168,
.max_ps_uniforms = 128,
.num_constants = 168,
};
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;
}
static void
print_usage(void)
{
printf("Usage: etnaviv_compiler [OPTIONS]... FILE\n");
printf(" --verbose - verbose compiler/debug messages\n");
printf(" --frag-rb-swap - swap rb in color output (FRAG)\n");
printf(" --help - show this message\n");
}
int
main(int argc, char **argv)
{
int ret = 0, n = 1;
const char *filename;
struct tgsi_token toks[65536];
struct tgsi_parse_context parse;
struct etna_shader s = {};
struct etna_shader_key key = {};
void *ptr;
size_t size;
struct etna_shader_variant *v = CALLOC_STRUCT(etna_shader_variant);
if (!v) {
fprintf(stderr, "malloc failed!\n");
return 1;
}
etna_mesa_debug = ETNA_DBG_MSGS;
while (n < argc) {
if (!strcmp(argv[n], "--verbose")) {
etna_mesa_debug |= ETNA_DBG_COMPILER_MSGS;
n++;
continue;
}
if (!strcmp(argv[n], "--frag-rb-swap")) {
debug_printf(" %s", argv[n]);
key.frag_rb_swap = true;
n++;
continue;
}
if (!strcmp(argv[n], "--help")) {
print_usage();
return 0;
}
break;
}
filename = argv[n];
ret = read_file(filename, &ptr, &size);
if (ret) {
print_usage();
return ret;
}
debug_printf("%s\n", (char *)ptr);
if (!tgsi_text_translate(ptr, toks, ARRAY_SIZE(toks)))
errx(1, "could not parse `%s'", filename);
tgsi_parse_init(&parse, toks);
s.specs = &specs_gc2000;
s.tokens = toks;
v->shader = &s;
v->key = key;
if (!etna_compile_shader(v)) {
fprintf(stderr, "compiler failed!\n");
return 1;
}
etna_dump_shader(v);
etna_destroy_shader(v);
}
|