2 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
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, sublicense,
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 next
12 * paragraph) shall be included in all copies or substantial portions of the
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 NONINFRINGEMENT. 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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Rob Clark <robclark@freedesktop.org>
27 #include <sys/types.h>
35 #include "tgsi/tgsi_parse.h"
36 #include "tgsi/tgsi_text.h"
37 #include "tgsi/tgsi_dump.h"
39 #include "freedreno_util.h"
40 #include "freedreno_lowering.h"
42 #include "ir3_compiler.h"
43 #include "instr-a3xx.h"
46 static void dump_info(struct ir3_shader_variant
*so
)
50 const char *type
= (so
->type
== SHADER_VERTEX
) ? "VERT" : "FRAG";
52 // for debug, dump some before/after info:
53 bin
= ir3_assemble(so
->ir
, &info
);
54 if (fd_mesa_debug
& FD_DBG_DISASM
) {
57 debug_printf("%s: disasm:\n", type
);
58 disasm_a3xx(bin
, info
.sizedwords
, 0, so
->type
);
60 debug_printf("%s: outputs:", type
);
61 for (i
= 0; i
< so
->outputs_count
; i
++) {
62 uint8_t regid
= so
->outputs
[i
].regid
;
63 ir3_semantic sem
= so
->outputs
[i
].semantic
;
64 debug_printf(" r%d.%c (%u:%u)",
65 (regid
>> 2), "xyzw"[regid
& 0x3],
66 sem2name(sem
), sem2idx(sem
));
69 debug_printf("%s: inputs:", type
);
70 for (i
= 0; i
< so
->inputs_count
; i
++) {
71 uint8_t regid
= so
->inputs
[i
].regid
;
72 ir3_semantic sem
= so
->inputs
[i
].semantic
;
73 debug_printf(" r%d.%c (%u:%u,cm=%x,il=%u,b=%u)",
74 (regid
>> 2), "xyzw"[regid
& 0x3],
75 sem2name(sem
), sem2idx(sem
),
76 so
->inputs
[i
].compmask
,
82 debug_printf("%s: %u instructions, %d half, %d full\n\n",
83 type
, info
.instrs_count
, info
.max_half_reg
+ 1, info
.max_reg
+ 1);
89 read_file(const char *filename
, void **ptr
, size_t *size
)
96 fd
= open(filename
, O_RDONLY
);
98 errx(1, "couldn't open `%s'", filename
);
100 ret
= fstat(fd
, &st
);
102 errx(1, "couldn't stat `%s'", filename
);
105 *ptr
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_SHARED
, fd
, 0);
106 if (*ptr
== MAP_FAILED
)
107 errx(1, "couldn't map `%s'", filename
);
112 static void reset_variant(struct ir3_shader_variant
*v
, const char *msg
)
116 v
->outputs_count
= 0;
119 v
->immediates_count
= 0;
122 int main(int argc
, char **argv
)
125 const char *filename
= argv
[1];
126 struct tgsi_token toks
[65536];
127 struct tgsi_parse_context parse
;
128 struct ir3_shader_variant v
;
129 struct ir3_shader_key key
= {
130 .color_two_side
= true,
135 fd_mesa_debug
|= FD_DBG_DISASM
| FD_DBG_OPTDUMP
| FD_DBG_MSGS
| FD_DBG_OPTMSGS
;
138 memset(&v
, 0, sizeof(v
));
141 read_file(filename
, &ptr
, &size
);
143 if (!tgsi_text_translate(ptr
, toks
, Elements(toks
)))
144 errx(1, "could not parse `%s'", filename
);
146 tgsi_parse_init(&parse
, toks
);
147 switch (parse
.FullHeader
.Processor
.Processor
) {
148 case TGSI_PROCESSOR_FRAGMENT
:
149 v
.type
= SHADER_FRAGMENT
;
151 case TGSI_PROCESSOR_VERTEX
:
152 v
.type
= SHADER_VERTEX
;
154 case TGSI_PROCESSOR_COMPUTE
:
155 v
.type
= SHADER_COMPUTE
;
159 if (!(fd_mesa_debug
& FD_DBG_NOOPT
)) {
160 /* with new compiler: */
161 ret
= ir3_compile_shader(&v
, toks
, key
, true);
164 reset_variant(&v
, "new compiler failed, trying without copy propagation!");
165 ret
= ir3_compile_shader(&v
, toks
, key
, false);
167 reset_variant(&v
, "new compiler failed, trying fallback!\n");
172 ret
= ir3_compile_shader_old(&v
, toks
, key
);
175 fprintf(stderr
, "old compiler failed!\n");