1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker * Copyright © 2016 Red Hat.
3*61046927SAndroid Build Coastguard Worker * Copyright © 2016 Bas Nieuwenhuizen
4*61046927SAndroid Build Coastguard Worker * SPDX-License-Identifier: MIT
5*61046927SAndroid Build Coastguard Worker *
6*61046927SAndroid Build Coastguard Worker * based in part on anv driver which is:
7*61046927SAndroid Build Coastguard Worker * Copyright © 2015 Intel Corporation
8*61046927SAndroid Build Coastguard Worker */
9*61046927SAndroid Build Coastguard Worker
10*61046927SAndroid Build Coastguard Worker #ifndef TU_PIPELINE_H
11*61046927SAndroid Build Coastguard Worker #define TU_PIPELINE_H
12*61046927SAndroid Build Coastguard Worker
13*61046927SAndroid Build Coastguard Worker #include "tu_common.h"
14*61046927SAndroid Build Coastguard Worker
15*61046927SAndroid Build Coastguard Worker #include "tu_cs.h"
16*61046927SAndroid Build Coastguard Worker #include "tu_descriptor_set.h"
17*61046927SAndroid Build Coastguard Worker #include "tu_shader.h"
18*61046927SAndroid Build Coastguard Worker #include "tu_suballoc.h"
19*61046927SAndroid Build Coastguard Worker
20*61046927SAndroid Build Coastguard Worker enum tu_dynamic_state
21*61046927SAndroid Build Coastguard Worker {
22*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_VIEWPORT,
23*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_SCISSOR,
24*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_RAST,
25*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_DEPTH_BIAS,
26*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_BLEND_CONSTANTS,
27*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_DS,
28*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_RB_DEPTH_CNTL,
29*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_SAMPLE_LOCATIONS,
30*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_VB_STRIDE,
31*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_BLEND,
32*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_VERTEX_INPUT,
33*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_PATCH_CONTROL_POINTS,
34*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_PRIM_MODE_SYSMEM,
35*61046927SAndroid Build Coastguard Worker TU_DYNAMIC_STATE_COUNT,
36*61046927SAndroid Build Coastguard Worker };
37*61046927SAndroid Build Coastguard Worker
38*61046927SAndroid Build Coastguard Worker struct cache_entry;
39*61046927SAndroid Build Coastguard Worker
40*61046927SAndroid Build Coastguard Worker struct tu_lrz_blend
41*61046927SAndroid Build Coastguard Worker {
42*61046927SAndroid Build Coastguard Worker bool valid;
43*61046927SAndroid Build Coastguard Worker bool reads_dest;
44*61046927SAndroid Build Coastguard Worker };
45*61046927SAndroid Build Coastguard Worker
46*61046927SAndroid Build Coastguard Worker struct tu_bandwidth
47*61046927SAndroid Build Coastguard Worker {
48*61046927SAndroid Build Coastguard Worker uint32_t color_bandwidth_per_sample;
49*61046927SAndroid Build Coastguard Worker uint32_t depth_cpp_per_sample;
50*61046927SAndroid Build Coastguard Worker uint32_t stencil_cpp_per_sample;
51*61046927SAndroid Build Coastguard Worker bool valid;
52*61046927SAndroid Build Coastguard Worker };
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard Worker struct tu_nir_shaders
55*61046927SAndroid Build Coastguard Worker {
56*61046927SAndroid Build Coastguard Worker struct vk_pipeline_cache_object base;
57*61046927SAndroid Build Coastguard Worker
58*61046927SAndroid Build Coastguard Worker /* This is optional, and is only filled out when a library pipeline is
59*61046927SAndroid Build Coastguard Worker * compiled with RETAIN_LINK_TIME_OPTIMIZATION_INFO.
60*61046927SAndroid Build Coastguard Worker */
61*61046927SAndroid Build Coastguard Worker nir_shader *nir[MESA_SHADER_STAGES];
62*61046927SAndroid Build Coastguard Worker };
63*61046927SAndroid Build Coastguard Worker
64*61046927SAndroid Build Coastguard Worker extern const struct vk_pipeline_cache_object_ops tu_nir_shaders_ops;
65*61046927SAndroid Build Coastguard Worker
66*61046927SAndroid Build Coastguard Worker static bool inline
tu6_shared_constants_enable(const struct tu_pipeline_layout * layout,const struct ir3_compiler * compiler)67*61046927SAndroid Build Coastguard Worker tu6_shared_constants_enable(const struct tu_pipeline_layout *layout,
68*61046927SAndroid Build Coastguard Worker const struct ir3_compiler *compiler)
69*61046927SAndroid Build Coastguard Worker {
70*61046927SAndroid Build Coastguard Worker return layout->push_constant_size > 0 &&
71*61046927SAndroid Build Coastguard Worker layout->push_constant_size <= (compiler->shared_consts_size * 16);
72*61046927SAndroid Build Coastguard Worker }
73*61046927SAndroid Build Coastguard Worker
74*61046927SAndroid Build Coastguard Worker enum ir3_push_consts_type
75*61046927SAndroid Build Coastguard Worker tu_push_consts_type(const struct tu_pipeline_layout *layout,
76*61046927SAndroid Build Coastguard Worker const struct ir3_compiler *compiler);
77*61046927SAndroid Build Coastguard Worker
78*61046927SAndroid Build Coastguard Worker struct tu_program_descriptor_linkage
79*61046927SAndroid Build Coastguard Worker {
80*61046927SAndroid Build Coastguard Worker struct ir3_const_state const_state;
81*61046927SAndroid Build Coastguard Worker
82*61046927SAndroid Build Coastguard Worker uint32_t constlen;
83*61046927SAndroid Build Coastguard Worker
84*61046927SAndroid Build Coastguard Worker struct tu_const_state tu_const_state;
85*61046927SAndroid Build Coastguard Worker };
86*61046927SAndroid Build Coastguard Worker
87*61046927SAndroid Build Coastguard Worker struct tu_program_state
88*61046927SAndroid Build Coastguard Worker {
89*61046927SAndroid Build Coastguard Worker struct tu_draw_state config_state;
90*61046927SAndroid Build Coastguard Worker struct tu_draw_state vs_state, vs_binning_state;
91*61046927SAndroid Build Coastguard Worker struct tu_draw_state hs_state;
92*61046927SAndroid Build Coastguard Worker struct tu_draw_state ds_state;
93*61046927SAndroid Build Coastguard Worker struct tu_draw_state gs_state, gs_binning_state;
94*61046927SAndroid Build Coastguard Worker struct tu_draw_state vpc_state;
95*61046927SAndroid Build Coastguard Worker struct tu_draw_state fs_state;
96*61046927SAndroid Build Coastguard Worker
97*61046927SAndroid Build Coastguard Worker struct tu_push_constant_range shared_consts;
98*61046927SAndroid Build Coastguard Worker
99*61046927SAndroid Build Coastguard Worker struct tu_program_descriptor_linkage link[MESA_SHADER_STAGES];
100*61046927SAndroid Build Coastguard Worker
101*61046927SAndroid Build Coastguard Worker unsigned dynamic_descriptor_offsets[MAX_SETS];
102*61046927SAndroid Build Coastguard Worker
103*61046927SAndroid Build Coastguard Worker bool per_view_viewport;
104*61046927SAndroid Build Coastguard Worker };
105*61046927SAndroid Build Coastguard Worker
106*61046927SAndroid Build Coastguard Worker struct tu_pipeline_executable {
107*61046927SAndroid Build Coastguard Worker gl_shader_stage stage;
108*61046927SAndroid Build Coastguard Worker
109*61046927SAndroid Build Coastguard Worker struct ir3_info stats;
110*61046927SAndroid Build Coastguard Worker bool is_binning;
111*61046927SAndroid Build Coastguard Worker
112*61046927SAndroid Build Coastguard Worker char *nir_from_spirv;
113*61046927SAndroid Build Coastguard Worker char *nir_final;
114*61046927SAndroid Build Coastguard Worker char *disasm;
115*61046927SAndroid Build Coastguard Worker };
116*61046927SAndroid Build Coastguard Worker
117*61046927SAndroid Build Coastguard Worker enum tu_pipeline_type {
118*61046927SAndroid Build Coastguard Worker TU_PIPELINE_GRAPHICS,
119*61046927SAndroid Build Coastguard Worker TU_PIPELINE_GRAPHICS_LIB,
120*61046927SAndroid Build Coastguard Worker TU_PIPELINE_COMPUTE,
121*61046927SAndroid Build Coastguard Worker };
122*61046927SAndroid Build Coastguard Worker
123*61046927SAndroid Build Coastguard Worker struct tu_pipeline
124*61046927SAndroid Build Coastguard Worker {
125*61046927SAndroid Build Coastguard Worker struct vk_object_base base;
126*61046927SAndroid Build Coastguard Worker enum tu_pipeline_type type;
127*61046927SAndroid Build Coastguard Worker
128*61046927SAndroid Build Coastguard Worker struct tu_cs cs;
129*61046927SAndroid Build Coastguard Worker struct tu_suballoc_bo bo;
130*61046927SAndroid Build Coastguard Worker
131*61046927SAndroid Build Coastguard Worker VkShaderStageFlags active_stages;
132*61046927SAndroid Build Coastguard Worker uint32_t active_desc_sets;
133*61046927SAndroid Build Coastguard Worker
134*61046927SAndroid Build Coastguard Worker /* mask of enabled dynamic states
135*61046927SAndroid Build Coastguard Worker * if BIT(i) is set, pipeline->dynamic_state[i] is used
136*61046927SAndroid Build Coastguard Worker */
137*61046927SAndroid Build Coastguard Worker uint32_t set_state_mask;
138*61046927SAndroid Build Coastguard Worker struct tu_draw_state dynamic_state[TU_DYNAMIC_STATE_COUNT];
139*61046927SAndroid Build Coastguard Worker
140*61046927SAndroid Build Coastguard Worker BITSET_DECLARE(static_state_mask, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
141*61046927SAndroid Build Coastguard Worker
142*61046927SAndroid Build Coastguard Worker struct {
143*61046927SAndroid Build Coastguard Worker bool raster_order_attachment_access;
144*61046927SAndroid Build Coastguard Worker } ds;
145*61046927SAndroid Build Coastguard Worker
146*61046927SAndroid Build Coastguard Worker /* Misc. info from the fragment output interface state that is used
147*61046927SAndroid Build Coastguard Worker * elsewhere.
148*61046927SAndroid Build Coastguard Worker */
149*61046927SAndroid Build Coastguard Worker struct {
150*61046927SAndroid Build Coastguard Worker bool raster_order_attachment_access;
151*61046927SAndroid Build Coastguard Worker } output;
152*61046927SAndroid Build Coastguard Worker
153*61046927SAndroid Build Coastguard Worker /* In other words - framebuffer fetch support */
154*61046927SAndroid Build Coastguard Worker struct {
155*61046927SAndroid Build Coastguard Worker /* If the pipeline sets SINGLE_PRIM_MODE for sysmem. */
156*61046927SAndroid Build Coastguard Worker bool sysmem_single_prim_mode;
157*61046927SAndroid Build Coastguard Worker struct tu_draw_state state_gmem;
158*61046927SAndroid Build Coastguard Worker } prim_order;
159*61046927SAndroid Build Coastguard Worker
160*61046927SAndroid Build Coastguard Worker /* draw states for the pipeline */
161*61046927SAndroid Build Coastguard Worker struct tu_draw_state load_state;
162*61046927SAndroid Build Coastguard Worker
163*61046927SAndroid Build Coastguard Worker struct tu_shader *shaders[MESA_SHADER_STAGES];
164*61046927SAndroid Build Coastguard Worker
165*61046927SAndroid Build Coastguard Worker struct tu_program_state program;
166*61046927SAndroid Build Coastguard Worker
167*61046927SAndroid Build Coastguard Worker struct tu_lrz_blend lrz_blend;
168*61046927SAndroid Build Coastguard Worker struct tu_bandwidth bandwidth;
169*61046927SAndroid Build Coastguard Worker
170*61046927SAndroid Build Coastguard Worker void *executables_mem_ctx;
171*61046927SAndroid Build Coastguard Worker /* tu_pipeline_executable */
172*61046927SAndroid Build Coastguard Worker struct util_dynarray executables;
173*61046927SAndroid Build Coastguard Worker };
174*61046927SAndroid Build Coastguard Worker
175*61046927SAndroid Build Coastguard Worker struct tu_graphics_lib_pipeline {
176*61046927SAndroid Build Coastguard Worker struct tu_pipeline base;
177*61046927SAndroid Build Coastguard Worker
178*61046927SAndroid Build Coastguard Worker VkGraphicsPipelineLibraryFlagsEXT state;
179*61046927SAndroid Build Coastguard Worker
180*61046927SAndroid Build Coastguard Worker struct vk_graphics_pipeline_state graphics_state;
181*61046927SAndroid Build Coastguard Worker
182*61046927SAndroid Build Coastguard Worker /* For vk_graphics_pipeline_state */
183*61046927SAndroid Build Coastguard Worker void *state_data;
184*61046927SAndroid Build Coastguard Worker
185*61046927SAndroid Build Coastguard Worker struct tu_nir_shaders *nir_shaders;
186*61046927SAndroid Build Coastguard Worker struct {
187*61046927SAndroid Build Coastguard Worker nir_shader *nir;
188*61046927SAndroid Build Coastguard Worker struct tu_shader_key key;
189*61046927SAndroid Build Coastguard Worker } shaders[MESA_SHADER_FRAGMENT + 1];
190*61046927SAndroid Build Coastguard Worker
191*61046927SAndroid Build Coastguard Worker /* Used to stitch together an overall layout for the final pipeline. */
192*61046927SAndroid Build Coastguard Worker struct tu_descriptor_set_layout *layouts[MAX_SETS];
193*61046927SAndroid Build Coastguard Worker unsigned num_sets;
194*61046927SAndroid Build Coastguard Worker unsigned push_constant_size;
195*61046927SAndroid Build Coastguard Worker bool independent_sets;
196*61046927SAndroid Build Coastguard Worker };
197*61046927SAndroid Build Coastguard Worker
198*61046927SAndroid Build Coastguard Worker struct tu_graphics_pipeline {
199*61046927SAndroid Build Coastguard Worker struct tu_pipeline base;
200*61046927SAndroid Build Coastguard Worker
201*61046927SAndroid Build Coastguard Worker struct vk_dynamic_graphics_state dynamic_state;
202*61046927SAndroid Build Coastguard Worker
203*61046927SAndroid Build Coastguard Worker /* Only used if the sample locations are static but the enable is dynamic.
204*61046927SAndroid Build Coastguard Worker * Otherwise we should be able to precompile the draw state.
205*61046927SAndroid Build Coastguard Worker */
206*61046927SAndroid Build Coastguard Worker struct vk_sample_locations_state sample_locations;
207*61046927SAndroid Build Coastguard Worker
208*61046927SAndroid Build Coastguard Worker VkImageAspectFlags feedback_loops;
209*61046927SAndroid Build Coastguard Worker bool feedback_loop_may_involve_textures;
210*61046927SAndroid Build Coastguard Worker };
211*61046927SAndroid Build Coastguard Worker
212*61046927SAndroid Build Coastguard Worker struct tu_compute_pipeline {
213*61046927SAndroid Build Coastguard Worker struct tu_pipeline base;
214*61046927SAndroid Build Coastguard Worker
215*61046927SAndroid Build Coastguard Worker uint32_t local_size[3];
216*61046927SAndroid Build Coastguard Worker uint32_t instrlen;
217*61046927SAndroid Build Coastguard Worker };
218*61046927SAndroid Build Coastguard Worker
219*61046927SAndroid Build Coastguard Worker VK_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline, base, VkPipeline,
220*61046927SAndroid Build Coastguard Worker VK_OBJECT_TYPE_PIPELINE)
221*61046927SAndroid Build Coastguard Worker
222*61046927SAndroid Build Coastguard Worker #define TU_DECL_PIPELINE_DOWNCAST(pipe_type, pipe_enum) \
223*61046927SAndroid Build Coastguard Worker static inline struct tu_##pipe_type##_pipeline * \
224*61046927SAndroid Build Coastguard Worker tu_pipeline_to_##pipe_type(struct tu_pipeline *pipeline) \
225*61046927SAndroid Build Coastguard Worker { \
226*61046927SAndroid Build Coastguard Worker assert(pipeline->type == pipe_enum); \
227*61046927SAndroid Build Coastguard Worker return (struct tu_##pipe_type##_pipeline *) pipeline; \
228*61046927SAndroid Build Coastguard Worker }
229*61046927SAndroid Build Coastguard Worker
230*61046927SAndroid Build Coastguard Worker TU_DECL_PIPELINE_DOWNCAST(graphics, TU_PIPELINE_GRAPHICS)
231*61046927SAndroid Build Coastguard Worker TU_DECL_PIPELINE_DOWNCAST(graphics_lib, TU_PIPELINE_GRAPHICS_LIB)
232*61046927SAndroid Build Coastguard Worker TU_DECL_PIPELINE_DOWNCAST(compute, TU_PIPELINE_COMPUTE)
233*61046927SAndroid Build Coastguard Worker
234*61046927SAndroid Build Coastguard Worker VkOffset2D tu_fdm_per_bin_offset(VkExtent2D frag_area, VkRect2D bin);
235*61046927SAndroid Build Coastguard Worker
236*61046927SAndroid Build Coastguard Worker template <chip CHIP>
237*61046927SAndroid Build Coastguard Worker uint32_t tu_emit_draw_state(struct tu_cmd_buffer *cmd);
238*61046927SAndroid Build Coastguard Worker
239*61046927SAndroid Build Coastguard Worker struct tu_pvtmem_config {
240*61046927SAndroid Build Coastguard Worker uint64_t iova;
241*61046927SAndroid Build Coastguard Worker uint32_t per_fiber_size;
242*61046927SAndroid Build Coastguard Worker uint32_t per_sp_size;
243*61046927SAndroid Build Coastguard Worker bool per_wave;
244*61046927SAndroid Build Coastguard Worker };
245*61046927SAndroid Build Coastguard Worker
246*61046927SAndroid Build Coastguard Worker template <chip CHIP>
247*61046927SAndroid Build Coastguard Worker void
248*61046927SAndroid Build Coastguard Worker tu6_emit_xs_config(struct tu_cs *cs,
249*61046927SAndroid Build Coastguard Worker gl_shader_stage stage,
250*61046927SAndroid Build Coastguard Worker const struct ir3_shader_variant *xs);
251*61046927SAndroid Build Coastguard Worker
252*61046927SAndroid Build Coastguard Worker template <chip CHIP>
253*61046927SAndroid Build Coastguard Worker void
254*61046927SAndroid Build Coastguard Worker tu6_emit_shared_consts_enable(struct tu_cs *cs, bool shared_consts_enable);
255*61046927SAndroid Build Coastguard Worker
256*61046927SAndroid Build Coastguard Worker template <chip CHIP>
257*61046927SAndroid Build Coastguard Worker void
258*61046927SAndroid Build Coastguard Worker tu6_emit_vpc(struct tu_cs *cs,
259*61046927SAndroid Build Coastguard Worker const struct ir3_shader_variant *vs,
260*61046927SAndroid Build Coastguard Worker const struct ir3_shader_variant *hs,
261*61046927SAndroid Build Coastguard Worker const struct ir3_shader_variant *ds,
262*61046927SAndroid Build Coastguard Worker const struct ir3_shader_variant *gs,
263*61046927SAndroid Build Coastguard Worker const struct ir3_shader_variant *fs);
264*61046927SAndroid Build Coastguard Worker
265*61046927SAndroid Build Coastguard Worker void
266*61046927SAndroid Build Coastguard Worker tu_fill_render_pass_state(struct vk_render_pass_state *rp,
267*61046927SAndroid Build Coastguard Worker const struct tu_render_pass *pass,
268*61046927SAndroid Build Coastguard Worker const struct tu_subpass *subpass);
269*61046927SAndroid Build Coastguard Worker
270*61046927SAndroid Build Coastguard Worker #endif /* TU_PIPELINE_H */
271