1 /*
2  * Copyright (C) 2018-2019 Alyssa Rosenzweig <alyssa@rosenzweig.io>
3  * Copyright (C) 2019-2020 Collabora, Ltd.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #ifndef __MIDGARD_H_
26 #define __MIDGARD_H_
27 
28 #include "compiler/nir/nir.h"
29 #include "util/u_dynarray.h"
30 #include "panfrost/util/pan_ir.h"
31 
32 void
33 midgard_compile_shader_nir(nir_shader *nir,
34                            const struct panfrost_compile_inputs *inputs,
35                            struct util_dynarray *binary,
36                            struct pan_shader_info *info);
37 
38 /* NIR options are shared between the standalone compiler and the online
39  * compiler. Defining it here is the simplest, though maybe not the Right
40  * solution. */
41 
42 static const nir_shader_compiler_options midgard_nir_options = {
43         .lower_ffma16 = true,
44         .lower_ffma32 = true,
45         .lower_ffma64 = true,
46         .lower_scmp = true,
47         .lower_flrp16 = true,
48         .lower_flrp32 = true,
49         .lower_flrp64 = true,
50         .lower_ffract = true,
51         .lower_fmod = true,
52         .lower_fdiv = true,
53         .lower_isign = true,
54         .lower_fpow = true,
55         .lower_find_lsb = true,
56         .lower_ifind_msb = true,
57         .lower_fdph = true,
58 
59         .lower_wpos_pntc = true,
60 
61         /* TODO: We have native ops to help here, which we'll want to look into
62          * eventually */
63         .lower_fsign = true,
64 
65         .lower_bit_count = true,
66         .lower_bitfield_reverse = true,
67         .lower_bitfield_insert_to_shifts = true,
68         .lower_bitfield_extract_to_shifts = true,
69         .lower_extract_byte = true,
70         .lower_extract_word = true,
71         .lower_insert_byte = true,
72         .lower_insert_word = true,
73         .lower_rotate = true,
74 
75         .lower_pack_half_2x16 = true,
76         .lower_pack_unorm_2x16 = true,
77         .lower_pack_snorm_2x16 = true,
78         .lower_pack_unorm_4x8 = true,
79         .lower_pack_snorm_4x8 = true,
80         .lower_unpack_half_2x16 = true,
81         .lower_unpack_unorm_2x16 = true,
82         .lower_unpack_snorm_2x16 = true,
83         .lower_unpack_unorm_4x8 = true,
84         .lower_unpack_snorm_4x8 = true,
85         .lower_pack_split = true,
86 
87         .lower_doubles_options = nir_lower_dmod,
88 
89         .lower_bitfield_extract_to_shifts = true,
90         .lower_uniforms_to_ubo = true,
91         .has_fsub = true,
92         .has_isub = true,
93         .vectorize_io = true,
94         .use_interpolated_input_intrinsics = true,
95 
96         .vertex_id_zero_based = true,
97         .has_cs_global_id = true,
98         .lower_cs_local_index_from_id = true,
99         .max_unroll_iterations = 32,
100         .force_indirect_unrolling = (nir_var_shader_in | nir_var_shader_out | nir_var_function_temp),
101 };
102 
103 #endif
104