Debian Codegraph @

src/panfrost/compiler/bifrost/bifrost_compile.h

raw
1 /*
2 * Copyright (C) 2018-2019 Alyssa Rosenzweig
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef __BIFROST_PUBLIC_H_
7 #define __BIFROST_PUBLIC_H_
8
9 #include <stdint.h>
10 #include <string.h>
11 #include "compiler/nir/nir.h"
12 #include "panfrost/compiler/pan_compiler.h"
13 #include "util/u_dynarray.h"
14
15 struct bifrost_precompiled_kernel_sysvals {
16 struct {
17 unsigned x, y, z;
18 } num_workgroups;
19 uint64_t printf_buffer_address;
20 } __attribute__((aligned(8)));
21
22 #define BIFROST_PRECOMPILED_KERNEL_SYSVALS_SIZE \
23 sizeof(struct bifrost_precompiled_kernel_sysvals)
24 #define BIFROST_PRECOMPILED_KERNEL_SYSVALS_OFFSET (0)
25 #define BIFROST_PRECOMPILED_KERNEL_ARGS_OFFSET \
26 (BIFROST_PRECOMPILED_KERNEL_SYSVALS_OFFSET + \
27 BIFROST_PRECOMPILED_KERNEL_SYSVALS_SIZE)
28 #define BIFROST_PRECOMPILED_KERNEL_ARGS_SIZE \
29 (512 - BIFROST_PRECOMPILED_KERNEL_ARGS_OFFSET)
30
31 struct bifrost_precompiled_kernel_info {
32 struct pan_shader_info info;
33 unsigned local_size_x;
34 unsigned local_size_y;
35 unsigned local_size_z;
36 unsigned binary_size;
37 };
38
39 static inline struct bifrost_precompiled_kernel_info
40 bifrost_precompiled_pack_kernel_info(nir_shader *nir,
41 struct pan_shader_info *info,
42 struct util_dynarray *binary)
43 {
44 return (struct bifrost_precompiled_kernel_info){
45 .info = *info,
46 .local_size_x = nir->info.workgroup_size[0],
47 .local_size_y = nir->info.workgroup_size[1],
48 .local_size_z = nir->info.workgroup_size[2],
49 .binary_size = binary->size,
50 };
51 }
52
53 static inline void
54 bifrost_precompiled_kernel_prepare_push_uniforms(
55 void *dst, const void *user_data, size_t user_data_size,
56 const struct bifrost_precompiled_kernel_sysvals *sysvals)
57 {
58 assert(user_data_size <= BIFROST_PRECOMPILED_KERNEL_ARGS_SIZE);
59
60 memcpy(dst, sysvals, sizeof(*sysvals));
61 memcpy(((uint8_t *)dst + BIFROST_PRECOMPILED_KERNEL_ARGS_OFFSET), user_data,
62 user_data_size);
63 }
64
65 void bifrost_preprocess_nir(nir_shader *nir, uint64_t gpu_id);
66 void bifrost_optimize_nir(nir_shader *nir, uint64_t gpu_id);
67 void bifrost_postprocess_nir(nir_shader *nir, uint64_t gpu_id);
68
69 void bifrost_compile_shader_nir(nir_shader *nir,
70 const struct pan_compile_inputs *inputs,
71 struct util_dynarray *binary,
72 struct pan_shader_info *info);
73
74 bool valhall_can_merge_workgroups(nir_shader *nir);
75
76 #define VALHAL_EX_FIFO_VARYING_BITS \
77 (VARYING_BIT_PSIZ | VARYING_BIT_LAYER | VARYING_BIT_PRIMITIVE_ID)
78
79 #define DEFINE_OPTIONS(name, arch, merge_workgroups) \
80 static const nir_shader_compiler_options name = { \
81 .lower_scmp = true, \
82 .lower_flrp16 = true, \
83 .lower_flrp32 = true, \
84 .lower_flrp64 = true, \
85 .lower_ffract = arch < 11, \
86 .lower_fmod = true, \
87 .lower_fdiv = true, \
88 .lower_isign = true, \
89 .lower_find_lsb = true, \
90 .lower_ifind_msb = true, \
91 .lower_fdph = true, \
92 .lower_fsqrt = true, \
93 \
94 .lower_fsign = true, \
95 \
96 .lower_bitfield_insert = true, \
97 .lower_bitfield_extract = true, \
98 .lower_bitfield_extract8 = true, \
99 .lower_bitfield_extract16 = true, \
100 .lower_insert_byte = true, \
101 \
102 .lower_pack_64_4x16 = true, \
103 .lower_pack_half_2x16 = true, \
104 .lower_pack_unorm_2x16 = true, \
105 .lower_pack_snorm_2x16 = true, \
106 .lower_pack_unorm_4x8 = true, \
107 .lower_pack_snorm_4x8 = true, \
108 .lower_unpack_half_2x16 = true, \
109 .lower_unpack_unorm_2x16 = true, \
110 .lower_unpack_snorm_2x16 = true, \
111 .lower_unpack_unorm_4x8 = true, \
112 .lower_unpack_snorm_4x8 = true, \
113 .has_pack_32_4x8 = true, \
114 \
115 .lower_doubles_options = \
116 nir_lower_dmod, /* TODO: Don't lower supported 64-bit operations */ \
117 .lower_int64_options = arch >= 9 ? ~(nir_lower_iadd64) : ~0, \
118 .lower_mul_high = true, \
119 .lower_fisnormal = true, \
120 .lower_uadd_carry = true, \
121 .lower_usub_borrow = true, \
122 \
123 .has_ldexp = true, \
124 .has_isub = true, \
125 .vectorize_vec2_16bit = true, \
126 .fuse_ffma16 = true, \
127 .fuse_ffma32 = true, \
128 .fuse_ffma64 = true, \
129 \
130 .lower_uniforms_to_ubo = true, \
131 \
132 .has_cs_global_id = true, \
133 .lower_cs_local_index_to_id = true, \
134 .lower_device_index_to_zero = true, \
135 .max_unroll_iterations = 32, \
136 .max_samples = 16, \
137 .force_indirect_unrolling = \
138 (nir_var_shader_in | nir_var_shader_out | nir_var_function_temp), \
139 .force_indirect_unrolling_sampler = true, \
140 .scalarize_ddx = true, \
141 .support_indirect_inputs = BITFIELD_BIT(MESA_SHADER_TESS_CTRL) | \
142 BITFIELD_BIT(MESA_SHADER_TESS_EVAL) | \
143 BITFIELD_BIT(MESA_SHADER_FRAGMENT), \
144 .lower_hadd = arch >= 11, \
145 .discard_is_demote = true, \
146 .has_udot_4x8 = arch >= 9, \
147 .has_udot_4x8_sat = arch >= 9, \
148 .has_sdot_4x8 = arch >= 9, \
149 .has_sdot_4x8_sat = arch >= 9, \
150 \
151 .divergence_analysis_options = merge_workgroups ? \
152 (nir_divergence_across_subgroups | \
153 nir_divergence_multiple_workgroup_per_compute_subgroup) \
154 : 0, \
155 };
156
157 DEFINE_OPTIONS(bifrost_nir_options_v6, 6, false);
158 DEFINE_OPTIONS(bifrost_nir_options_v9, 9, false);
159 DEFINE_OPTIONS(bifrost_nir_options_v9_merge_wg, 9, true);
160 DEFINE_OPTIONS(bifrost_nir_options_v11, 11, false);
161 DEFINE_OPTIONS(bifrost_nir_options_v11_merge_wg, 11, true);
162
163 #endif