1 /*
2 * Copyright (c) 2020 Etnaviv Project
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, sub license,
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
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the 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 NON-INFRINGEMENT. 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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Christian Gmeiner <christian.gmeiner@gmail.com>
25 */
26
27 #include "etnaviv_compiler.h"
28 #include "etnaviv_compiler_nir.h"
29 #include "etnaviv_debug.h"
30 #include "etnaviv_disk_cache.h"
31 #include "util/ralloc.h"
32
33 struct etna_compiler *
etna_compiler_create(const char * renderer,const struct etna_specs * specs)34 etna_compiler_create(const char *renderer, const struct etna_specs *specs)
35 {
36 struct etna_compiler *compiler = rzalloc(NULL, struct etna_compiler);
37
38 compiler->options = (nir_shader_compiler_options) {
39 .has_texture_scaling = true,
40 .lower_fpow = true,
41 .lower_fround_even = true,
42 .lower_ftrunc = true,
43 .fuse_ffma16 = true,
44 .fuse_ffma32 = true,
45 .fuse_ffma64 = true,
46 .lower_uadd_carry = true,
47 .lower_usub_borrow = true,
48 .lower_ldexp = true,
49 .lower_mul_high = true,
50 .lower_bitops = true,
51 .lower_all_io_to_temps = true,
52 .vertex_id_zero_based = true,
53 .lower_flrp32 = true,
54 .lower_fmod = true,
55 .lower_vector_cmp = true,
56 .lower_fdph = true,
57 .lower_insert_byte = true,
58 .lower_insert_word = true,
59 .lower_fdiv = true, /* !specs->has_new_transcendentals */
60 .lower_extract_byte = true,
61 .lower_extract_word = true,
62 .lower_fsign = !specs->has_sign_floor_ceil,
63 .lower_ffloor = !specs->has_sign_floor_ceil,
64 .lower_fceil = !specs->has_sign_floor_ceil,
65 .lower_fsqrt = !specs->has_sin_cos_sqrt,
66 .lower_sincos = !specs->has_sin_cos_sqrt,
67 .lower_uniforms_to_ubo = specs->halti >= 2,
68 .force_indirect_unrolling = nir_var_all,
69 .max_unroll_iterations = 32,
70 .vectorize_io = true,
71 .lower_pack_32_2x16_split = true,
72 .lower_pack_64_2x32_split = true,
73 .lower_unpack_32_2x16_split = true,
74 .lower_unpack_64_2x32_split = true,
75 .lower_find_lsb = true,
76 .lower_ifind_msb = true,
77 .lower_ufind_msb = true,
78 .has_uclz = true,
79 };
80
81 compiler->regs = etna_ra_setup(compiler);
82 if (!compiler->regs) {
83 ralloc_free((void *)compiler);
84 compiler = NULL;
85 }
86
87 etna_disk_cache_init(compiler, renderer);
88
89 return compiler;
90 }
91
92 void
etna_compiler_destroy(const struct etna_compiler * compiler)93 etna_compiler_destroy(const struct etna_compiler *compiler)
94 {
95 disk_cache_destroy(compiler->disk_cache);
96 ralloc_free((void *)compiler);
97 }
98
99 const nir_shader_compiler_options *
etna_compiler_get_options(struct etna_compiler * compiler)100 etna_compiler_get_options(struct etna_compiler *compiler)
101 {
102 return &compiler->options;
103 }
104