Debian Codegraph @

src/kosmickrisp/compiler/nir_to_msl.h

raw symbols SCIP
1 /*
2 * Copyright 2025 LunarG, Inc.
3 * Copyright 2025 Google LLC
4 * SPDX-License-Identifier: MIT
5 */
6
7 #pragma once
8
9 #include "nir.h"
10
11 enum pipe_format;
12
13 struct nir_to_msl_options {
14 void *mem_ctx;
15 uint64_t disabled_workarounds;
16
17 /* Required to correctly declare fragment outputs. Shader may contain
18 * shrinked writes which can lead to writting less components than the ones
19 * the render target has. This leads to an incorrect calculation of the
20 * component count for the render target formats. */
21 uint8_t rts_component_count[MAX_DRAW_BUFFERS];
22 };
23
24 /* Assumes nir_shader_gather_info has been called beforehand. */
25 char *nir_to_msl(nir_shader *shader, struct nir_to_msl_options *options);
26
27 /* Call this after all API-specific lowerings. It will bring the NIR out of SSA
28 * at the end */
29 bool msl_optimize_nir(struct nir_shader *nir);
30
31 /* Call this before all API-speicific lowerings, it will */
32 void msl_preprocess_nir(struct nir_shader *nir);
33
34 enum msl_tex_access_flag {
35 MSL_ACCESS_SAMPLE = 0,
36 MSL_ACCESS_READ,
37 MSL_ACCESS_WRITE,
38 MSL_ACCESS_READ_WRITE,
39 };
40
41 static inline enum msl_tex_access_flag
42 msl_convert_access_flag(enum gl_access_qualifier qual)
43 {
44 enum gl_access_qualifier readwrite =
45 (ACCESS_NON_WRITEABLE | ACCESS_NON_READABLE);
46 if ((qual & readwrite) == readwrite)
47 return MSL_ACCESS_READ_WRITE;
48 if (qual & ACCESS_NON_WRITEABLE)
49 return MSL_ACCESS_READ;
50 if (qual & ACCESS_NON_READABLE)
51 return MSL_ACCESS_WRITE;
52 return MSL_ACCESS_READ_WRITE;
53 }
54
55 bool msl_nir_fs_force_output_signedness(
56 nir_shader *nir, enum pipe_format render_target_formats[MAX_DRAW_BUFFERS]);
57
58 bool msl_nir_vs_remove_point_size_write(nir_builder *b,
59 nir_intrinsic_instr *intrin,
60 void *data);
61
62 bool msl_nir_fs_remove_depth_write(nir_builder *b, nir_intrinsic_instr *intrin,
63 void *data);
64
65 bool msl_lower_textures(nir_shader *s);
66
67 bool msl_lower_static_sample_mask(nir_shader *nir, uint32_t sample_mask);
68 bool msl_ensure_depth_write(nir_shader *nir);
69 bool msl_ensure_vertex_position_output(nir_shader *nir);
70 bool msl_nir_fs_io_types(nir_shader *nir);
71 bool msl_nir_vs_io_types(nir_shader *nir);
72 bool msl_nir_fake_guard_for_discards(struct nir_shader *nir);
73 bool msl_nir_lower_sample_shading(nir_shader *nir);
74 void msl_lower_nir_late(nir_shader *nir);
75
76 static const nir_shader_compiler_options kk_nir_options = {
77 .lower_fdph = true,
78 .has_fsub = true,
79 .has_isub = true,
80 .lower_extract_word = true,
81 .lower_extract_byte = true,
82 .lower_insert_word = true,
83 .lower_insert_byte = true,
84 .lower_fmod = true,
85 .discard_is_demote = true,
86 .instance_id_includes_base_index = true,
87 .lower_device_index_to_zero = true,
88 .lower_pack_64_2x32_split = true,
89 .lower_unpack_64_2x32_split = true,
90 .lower_pack_64_2x32 = true,
91 .lower_pack_half_2x16 = true,
92 .lower_pack_split = true,
93 .lower_unpack_half_2x16 = true,
94 .has_cs_global_id = true,
95 .lower_fquantize2f16 = true,
96 .lower_scmp = true,
97 .lower_ifind_msb = true,
98 .lower_ufind_msb = true,
99 .lower_find_lsb = true,
100 .has_uclz = true,
101 .lower_mul_2x32_64 = true,
102 .lower_uadd_carry = true,
103 .lower_usub_borrow = true,
104 /* Metal does not support double. */
105 .lower_doubles_options = (nir_lower_doubles_options)(~0),
106 .lower_int64_options = nir_lower_ufind_msb64 | nir_lower_subgroup_shuffle64,
107 .io_options = nir_io_mediump_is_32bit,
108 };