ir3_assembler.c revision 7ec681f3
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 "ir3_assembler.h"
25#include "ir3_parser.h"
26#include "ir3_shader.h"
27
28/**
29 * A helper to go from ir3 assembly to assembled shader.  The shader has a
30 * single variant.
31 */
32struct ir3_shader *
33ir3_parse_asm(struct ir3_compiler *c, struct ir3_kernel_info *info, FILE *in)
34{
35   struct ir3_shader *shader = rzalloc_size(NULL, sizeof(*shader));
36   shader->compiler = c;
37   shader->type = MESA_SHADER_COMPUTE;
38   mtx_init(&shader->variants_lock, mtx_plain);
39
40   struct ir3_shader_variant *v = rzalloc_size(shader, sizeof(*v));
41   v->type = MESA_SHADER_COMPUTE;
42   v->shader = shader;
43   v->const_state = rzalloc_size(v, sizeof(*v->const_state));
44
45   shader->variants = v;
46   shader->variant_count = 1;
47
48   info->numwg = INVALID_REG;
49
50   for (int i = 0; i < MAX_BUFS; i++) {
51      info->buf_addr_regs[i] = INVALID_REG;
52   }
53
54   /* Provide a default local_size in case the shader doesn't set it, so that
55    * we don't crash at least.
56    */
57   v->local_size[0] = v->local_size[1] = v->local_size[2] = 1;
58
59   v->ir = ir3_parse(v, info, in);
60   if (!v->ir)
61      goto error;
62
63   ir3_debug_print(v->ir, "AFTER PARSING");
64
65   v->bin = ir3_shader_assemble(v);
66   if (!v->bin)
67      goto error;
68
69   return shader;
70
71error:
72   ralloc_free(shader);
73   return NULL;
74}
75