• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
32 struct ir3_shader *
ir3_parse_asm(struct ir3_compiler * c,struct ir3_kernel_info * info,FILE * in)33 ir3_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->compiler = c;
43    v->const_state = rzalloc_size(v, sizeof(*v->const_state));
44 
45    if (c->gen >= 6)
46       v->mergedregs = true;
47 
48    shader->variants = v;
49    shader->variant_count = 1;
50 
51    info->numwg = INVALID_REG;
52 
53    for (int i = 0; i < MAX_BUFS; i++) {
54       info->buf_addr_regs[i] = INVALID_REG;
55    }
56 
57    /* Provide a default local_size in case the shader doesn't set it, so that
58     * we don't crash at least.
59     */
60    v->local_size[0] = v->local_size[1] = v->local_size[2] = 1;
61 
62    v->ir = ir3_parse(v, info, in);
63    if (!v->ir)
64       goto error;
65 
66    ir3_debug_print(v->ir, "AFTER PARSING");
67 
68    v->bin = ir3_shader_assemble(v);
69    if (!v->bin)
70       goto error;
71 
72    return shader;
73 
74 error:
75    ralloc_free(shader);
76    return NULL;
77 }
78