• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_core_info * info)34 etna_compiler_create(const char *renderer, const struct etna_core_info *info)
35 {
36    struct etna_compiler *compiler = rzalloc(NULL, struct etna_compiler);
37    bool has_sign_floor_ceil = etna_core_has_feature(info, ETNA_FEATURE_HAS_SIGN_FLOOR_CEIL);
38    bool has_sin_cos_sqrt = etna_core_has_feature(info, ETNA_FEATURE_HAS_SQRT_TRIG);
39 
40    compiler->options = (nir_shader_compiler_options) {
41       .has_texture_scaling = true,
42       .lower_fpow = true,
43       .lower_fround_even = true,
44       .lower_ftrunc = true,
45       .fuse_ffma16 = true,
46       .fuse_ffma32 = true,
47       .fuse_ffma64 = true,
48       .lower_uadd_carry = true,
49       .lower_usub_borrow = true,
50       .lower_ldexp = true,
51       .lower_mul_high = true,
52       .lower_bitops = true,
53       .lower_all_io_to_temps = true,
54       .lower_flrp32 = true,
55       .lower_fmod = true,
56       .lower_vector_cmp = true,
57       .lower_fdph = true,
58       .lower_insert_byte = true,
59       .lower_insert_word = true,
60       .lower_fdiv = true, /* !specs->has_new_transcendentals */
61       .lower_extract_byte = true,
62       .lower_extract_word = true,
63       .lower_fsign = !has_sign_floor_ceil,
64       .lower_ffloor = !has_sign_floor_ceil,
65       .lower_fceil = !has_sign_floor_ceil,
66       .lower_fsqrt = !has_sin_cos_sqrt,
67       .lower_sincos = !has_sin_cos_sqrt,
68       .lower_uniforms_to_ubo = info->halti >= 2,
69       .force_indirect_unrolling = nir_var_all,
70       .max_unroll_iterations = 32,
71       .vectorize_io = true,
72       .lower_pack_32_2x16_split = true,
73       .lower_pack_64_2x32_split = true,
74       .lower_unpack_32_2x16_split = true,
75       .lower_unpack_64_2x32_split = true,
76       .lower_find_lsb = true,
77       .lower_ifind_msb = true,
78       .lower_ufind_msb = true,
79       .has_uclz = true,
80       .no_integers = info->halti < 2,
81       .support_indirect_inputs = (uint8_t)BITFIELD_MASK(PIPE_SHADER_TYPES),
82       .support_indirect_outputs = (uint8_t)BITFIELD_MASK(PIPE_SHADER_TYPES),
83    };
84 
85    compiler->regs = etna_ra_setup(compiler);
86    if (!compiler->regs) {
87       ralloc_free((void *)compiler);
88       compiler = NULL;
89    }
90 
91    etna_disk_cache_init(compiler, renderer);
92 
93    return compiler;
94 }
95 
96 void
etna_compiler_destroy(const struct etna_compiler * compiler)97 etna_compiler_destroy(const struct etna_compiler *compiler)
98 {
99    disk_cache_destroy(compiler->disk_cache);
100    ralloc_free((void *)compiler);
101 }
102 
103 const nir_shader_compiler_options *
etna_compiler_get_options(struct etna_compiler * compiler)104 etna_compiler_get_options(struct etna_compiler *compiler)
105 {
106    return &compiler->options;
107 }
108