• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2016 Red Hat.
3  * Copyright © 2016 Bas Nieuwenhuizen
4  * SPDX-License-Identifier: MIT
5  *
6  * based in part on anv driver which is:
7  * Copyright © 2015 Intel Corporation
8  */
9 
10 #ifndef TU_SHADER_H
11 #define TU_SHADER_H
12 
13 #include "tu_common.h"
14 #include "tu_cs.h"
15 #include "tu_suballoc.h"
16 #include "tu_descriptor_set.h"
17 
18 struct tu_inline_ubo
19 {
20    /* Push the data at BINDLESS_BASE[base] + offset */
21    unsigned base;
22    unsigned offset;
23 
24    /* If true, push the base address instead */
25    bool push_address;
26 
27    /* Push it to this location in the const file, in vec4s */
28    unsigned const_offset_vec4;
29 
30    /* How much to push */
31    unsigned size_vec4;
32 };
33 
34 /* The meaning of the range depends on "type". If it's
35  * IR3_PUSH_CONSTS_PER_STAGE, then it's the range used by this shader. If
36  * it's IR3_PUSH_CONSTS_SHARED then it's the overall range as provided by
37  * the pipeline layout and must match between shaders where it's non-zero.
38  */
39 struct tu_push_constant_range
40 {
41    uint32_t lo_dwords;
42    uint32_t dwords;
43    enum ir3_push_consts_type type;
44 };
45 
46 struct tu_const_state
47 {
48    struct tu_push_constant_range push_consts;
49    uint32_t dynamic_offset_loc;
50    unsigned num_inline_ubos;
51    struct tu_inline_ubo ubos[MAX_INLINE_UBOS];
52 
53    struct ir3_driver_ubo fdm_ubo;
54    struct ir3_driver_ubo dynamic_offsets_ubo;
55    struct ir3_driver_ubo inline_uniforms_ubo;
56 };
57 
58 struct tu_shader
59 {
60    struct vk_pipeline_cache_object base;
61 
62    const struct ir3_shader_variant *variant;
63    const struct ir3_shader_variant *safe_const_variant;
64 
65    struct tu_suballoc_bo bo;
66    struct tu_cs cs;
67    struct tu_bo *pvtmem_bo;
68 
69    struct tu_draw_state state;
70    struct tu_draw_state safe_const_state;
71    struct tu_draw_state binning_state;
72 
73    struct tu_const_state const_state;
74    uint32_t view_mask;
75    uint8_t active_desc_sets;
76 
77    /* The dynamic buffer descriptor size for descriptor sets that we know
78     * about. This is used when linking to piece together the sizes and from
79     * there calculate the offsets. It's -1 if we don't know because the
80     * descriptor set layout is NULL.
81     */
82    int dynamic_descriptor_sizes[MAX_SETS];
83 
84    union {
85       struct {
86          unsigned patch_type;
87          enum a6xx_tess_output tess_output_upper_left, tess_output_lower_left;
88          enum a6xx_tess_spacing tess_spacing;
89       } tes;
90 
91       struct {
92          bool per_samp;
93          bool has_fdm;
94 
95          uint16_t dynamic_input_attachments_used;
96 
97          struct {
98             uint32_t status;
99             bool force_late_z;
100          } lrz;
101       } fs;
102    };
103 };
104 
105 struct tu_shader_key {
106    unsigned multiview_mask;
107    uint16_t read_only_input_attachments;
108    bool force_sample_interp;
109    bool fragment_density_map;
110    bool dynamic_renderpass;
111    uint8_t unscaled_input_fragcoord;
112    bool robust_storage_access2;
113    bool robust_uniform_access2;
114    bool lower_view_index_to_device_index;
115    enum ir3_wavesize_option api_wavesize, real_wavesize;
116 };
117 
118 extern const struct vk_pipeline_cache_object_ops tu_shader_ops;
119 bool
120 tu_nir_lower_multiview(nir_shader *nir, uint32_t mask, struct tu_device *dev);
121 
122 nir_shader *
123 tu_spirv_to_nir(struct tu_device *dev,
124                 void *mem_ctx,
125                 VkPipelineCreateFlags2KHR pipeline_flags,
126                 const VkPipelineShaderStageCreateInfo *stage_info,
127                 const struct tu_shader_key *key,
128                 gl_shader_stage stage);
129 
130 void
131 tu6_emit_xs(struct tu_cs *cs,
132             gl_shader_stage stage,
133             const struct ir3_shader_variant *xs,
134             const struct tu_pvtmem_config *pvtmem,
135             uint64_t binary_iova);
136 
137 template <chip CHIP>
138 void
139 tu6_emit_vs(struct tu_cs *cs, const struct ir3_shader_variant *vs,
140             uint32_t view_mask);
141 
142 template <chip CHIP>
143 void
144 tu6_emit_hs(struct tu_cs *cs, const struct ir3_shader_variant *hs);
145 
146 template <chip CHIP>
147 void
148 tu6_emit_ds(struct tu_cs *cs, const struct ir3_shader_variant *hs);
149 
150 template <chip CHIP>
151 void
152 tu6_emit_gs(struct tu_cs *cs, const struct ir3_shader_variant *hs);
153 
154 template <chip CHIP>
155 void
156 tu6_emit_fs(struct tu_cs *cs, const struct ir3_shader_variant *fs);
157 
158 VkResult
159 tu_shader_create(struct tu_device *dev,
160                  struct tu_shader **shader_out,
161                  nir_shader *nir,
162                  const struct tu_shader_key *key,
163                  const struct ir3_shader_key *ir3_key,
164                  const void *key_data,
165                  size_t key_size,
166                  struct tu_pipeline_layout *layout,
167                  bool executable_info);
168 
169 void
170 tu_shader_key_subgroup_size(struct tu_shader_key *key,
171                             bool allow_varying_subgroup_size,
172                             bool require_full_subgroups,
173                             const VkPipelineShaderStageRequiredSubgroupSizeCreateInfo *subgroup_info,
174                             struct tu_device *dev);
175 
176 void
177 tu_shader_key_robustness(struct tu_shader_key *key,
178                          const struct vk_pipeline_robustness_state *rs);
179 
180 VkResult
181 tu_compile_shaders(struct tu_device *device,
182                    VkPipelineCreateFlags2KHR pipeline_flags,
183                    const VkPipelineShaderStageCreateInfo **stage_infos,
184                    nir_shader **nir,
185                    const struct tu_shader_key *keys,
186                    struct tu_pipeline_layout *layout,
187                    const unsigned char *pipeline_sha1,
188                    struct tu_shader **shaders,
189                    char **nir_initial_disasm,
190                    void *nir_initial_disasm_mem_ctx,
191                    nir_shader **nir_out,
192                    VkPipelineCreationFeedback *stage_feedbacks);
193 
194 VkResult
195 tu_init_empty_shaders(struct tu_device *device);
196 
197 void
198 tu_destroy_empty_shaders(struct tu_device *device);
199 
200 void
201 tu_shader_destroy(struct tu_device *dev,
202                   struct tu_shader *shader);
203 
204 #endif /* TU_SHADER_H */
205