1 /*
2 * Copyright © 2020 Google, Inc.
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24 #include <err.h>
25
26 #include "ir3_assembler.h"
27 #include "ir3_shader.h"
28 #include "ir3_parser.h"
29
30 /**
31 * A helper to go from ir3 assembly to assembled shader. The shader has a
32 * single variant.
33 */
34 struct ir3_shader *
ir3_parse_asm(struct ir3_compiler * c,struct ir3_kernel_info * info,FILE * in)35 ir3_parse_asm(struct ir3_compiler *c, struct ir3_kernel_info *info, FILE *in)
36 {
37 struct ir3_shader *shader = rzalloc_size(NULL, sizeof(*shader));
38 shader->compiler = c;
39 shader->type = MESA_SHADER_COMPUTE;
40 mtx_init(&shader->variants_lock, mtx_plain);
41
42 struct ir3_shader_variant *v = rzalloc_size(shader, sizeof(*v));
43 v->type = MESA_SHADER_COMPUTE;
44 v->shader = shader;
45 v->const_state = rzalloc_size(v, sizeof(*v->const_state));
46
47 shader->variants = v;
48 shader->variant_count = 1;
49
50 info->numwg = INVALID_REG;
51
52 v->ir = ir3_parse(v, info, in);
53 if (!v->ir)
54 errx(-1, "parse failed");
55
56 ir3_debug_print(v->ir, "AFTER PARSING");
57
58 v->bin = ir3_shader_assemble(v);
59 if (!v->bin)
60 errx(-1, "assembler failed");
61
62 return shader;
63 }
64