2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #include "tu_private.h"
30 #include "ir3/ir3_nir.h"
31 #include "main/menums.h"
33 #include "nir/nir_builder.h"
34 #include "spirv/nir_spirv.h"
35 #include "util/debug.h"
36 #include "util/mesa-sha1.h"
37 #include "util/u_atomic.h"
38 #include "vk_format.h"
43 /* Emit IB that preloads the descriptors that the shader uses */
46 emit_load_state(struct tu_cs
*cs
, unsigned opcode
, enum a6xx_state_type st
,
47 enum a6xx_state_block sb
, unsigned base
, unsigned offset
,
50 /* Note: just emit one packet, even if count overflows NUM_UNIT. It's not
51 * clear if emitting more packets will even help anything. Presumably the
52 * descriptor cache is relatively small, and these packets stop doing
53 * anything when there are too many descriptors.
55 tu_cs_emit_pkt7(cs
, opcode
, 3);
57 CP_LOAD_STATE6_0_STATE_TYPE(st
) |
58 CP_LOAD_STATE6_0_STATE_SRC(SS6_BINDLESS
) |
59 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
60 CP_LOAD_STATE6_0_NUM_UNIT(MIN2(count
, 1024-1)));
61 tu_cs_emit_qw(cs
, offset
| (base
<< 28));
65 tu6_load_state_size(struct tu_pipeline_layout
*layout
, bool compute
)
67 const unsigned load_state_size
= 4;
69 for (unsigned i
= 0; i
< layout
->num_sets
; i
++) {
70 struct tu_descriptor_set_layout
*set_layout
= layout
->set
[i
].layout
;
71 for (unsigned j
= 0; j
< set_layout
->binding_count
; j
++) {
72 struct tu_descriptor_set_binding_layout
*binding
= &set_layout
->binding
[j
];
74 /* Note: some users, like amber for example, pass in
75 * VK_SHADER_STAGE_ALL which includes a bunch of extra bits, so
76 * filter these out by using VK_SHADER_STAGE_ALL_GRAPHICS explicitly.
78 VkShaderStageFlags stages
= compute
?
79 binding
->shader_stages
& VK_SHADER_STAGE_COMPUTE_BIT
:
80 binding
->shader_stages
& VK_SHADER_STAGE_ALL_GRAPHICS
;
81 unsigned stage_count
= util_bitcount(stages
);
82 switch (binding
->type
) {
83 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
84 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
85 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
86 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
87 /* IBO-backed resources only need one packet for all graphics stages */
88 if (stages
& ~VK_SHADER_STAGE_COMPUTE_BIT
)
90 if (stages
& VK_SHADER_STAGE_COMPUTE_BIT
)
93 case VK_DESCRIPTOR_TYPE_SAMPLER
:
94 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
95 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
96 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
97 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
98 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
99 /* Textures and UBO's needs a packet for each stage */
102 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
103 /* Because of how we pack combined images and samplers, we
104 * currently can't use one packet for the whole array.
106 count
= stage_count
* binding
->array_size
* 2;
109 unreachable("bad descriptor type");
111 size
+= count
* load_state_size
;
118 tu6_emit_load_state(struct tu_pipeline
*pipeline
, bool compute
)
120 unsigned size
= tu6_load_state_size(pipeline
->layout
, compute
);
125 tu_cs_begin_sub_stream(&pipeline
->cs
, size
, &cs
);
127 struct tu_pipeline_layout
*layout
= pipeline
->layout
;
128 for (unsigned i
= 0; i
< layout
->num_sets
; i
++) {
129 /* From 13.2.7. Descriptor Set Binding:
131 * A compatible descriptor set must be bound for all set numbers that
132 * any shaders in a pipeline access, at the time that a draw or
133 * dispatch command is recorded to execute using that pipeline.
134 * However, if none of the shaders in a pipeline statically use any
135 * bindings with a particular set number, then no descriptor set need
136 * be bound for that set number, even if the pipeline layout includes
137 * a non-trivial descriptor set layout for that set number.
139 * This means that descriptor sets unused by the pipeline may have a
140 * garbage or 0 BINDLESS_BASE register, which will cause context faults
141 * when prefetching descriptors from these sets. Skip prefetching for
142 * descriptors from them to avoid this. This is also an optimization,
143 * since these prefetches would be useless.
145 if (!(pipeline
->active_desc_sets
& (1u << i
)))
148 struct tu_descriptor_set_layout
*set_layout
= layout
->set
[i
].layout
;
149 for (unsigned j
= 0; j
< set_layout
->binding_count
; j
++) {
150 struct tu_descriptor_set_binding_layout
*binding
= &set_layout
->binding
[j
];
152 unsigned offset
= binding
->offset
/ 4;
153 /* Note: some users, like amber for example, pass in
154 * VK_SHADER_STAGE_ALL which includes a bunch of extra bits, so
155 * filter these out by using VK_SHADER_STAGE_ALL_GRAPHICS explicitly.
157 VkShaderStageFlags stages
= compute
?
158 binding
->shader_stages
& VK_SHADER_STAGE_COMPUTE_BIT
:
159 binding
->shader_stages
& VK_SHADER_STAGE_ALL_GRAPHICS
;
160 unsigned count
= binding
->array_size
;
161 if (count
== 0 || stages
== 0)
163 switch (binding
->type
) {
164 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
166 offset
= (layout
->set
[i
].dynamic_offset_start
+
167 binding
->dynamic_offset_offset
) * A6XX_TEX_CONST_DWORDS
;
169 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
170 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
171 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
172 /* IBO-backed resources only need one packet for all graphics stages */
173 if (stages
& ~VK_SHADER_STAGE_COMPUTE_BIT
) {
174 emit_load_state(&cs
, CP_LOAD_STATE6
, ST6_SHADER
, SB6_IBO
,
175 base
, offset
, count
);
177 if (stages
& VK_SHADER_STAGE_COMPUTE_BIT
) {
178 emit_load_state(&cs
, CP_LOAD_STATE6_FRAG
, ST6_IBO
, SB6_CS_SHADER
,
179 base
, offset
, count
);
182 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
183 /* nothing - input attachment doesn't use bindless */
185 case VK_DESCRIPTOR_TYPE_SAMPLER
:
186 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
187 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
: {
188 tu_foreach_stage(stage
, stages
) {
189 emit_load_state(&cs
, tu6_stage2opcode(stage
),
190 binding
->type
== VK_DESCRIPTOR_TYPE_SAMPLER
?
191 ST6_SHADER
: ST6_CONSTANTS
,
192 tu6_stage2texsb(stage
), base
, offset
, count
);
196 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
198 offset
= (layout
->set
[i
].dynamic_offset_start
+
199 binding
->dynamic_offset_offset
) * A6XX_TEX_CONST_DWORDS
;
201 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
: {
202 tu_foreach_stage(stage
, stages
) {
203 emit_load_state(&cs
, tu6_stage2opcode(stage
), ST6_UBO
,
204 tu6_stage2shadersb(stage
), base
, offset
, count
);
208 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
: {
209 tu_foreach_stage(stage
, stages
) {
210 /* TODO: We could emit less CP_LOAD_STATE6 if we used
211 * struct-of-arrays instead of array-of-structs.
213 for (unsigned i
= 0; i
< count
; i
++) {
214 unsigned tex_offset
= offset
+ 2 * i
* A6XX_TEX_CONST_DWORDS
;
215 unsigned sam_offset
= offset
+ (2 * i
+ 1) * A6XX_TEX_CONST_DWORDS
;
216 emit_load_state(&cs
, tu6_stage2opcode(stage
),
217 ST6_CONSTANTS
, tu6_stage2texsb(stage
),
218 base
, tex_offset
, 1);
219 emit_load_state(&cs
, tu6_stage2opcode(stage
),
220 ST6_SHADER
, tu6_stage2texsb(stage
),
221 base
, sam_offset
, 1);
227 unreachable("bad descriptor type");
232 pipeline
->load_state
.state_ib
= tu_cs_end_sub_stream(&pipeline
->cs
, &cs
);
235 struct tu_pipeline_builder
237 struct tu_device
*device
;
238 struct tu_pipeline_cache
*cache
;
239 struct tu_pipeline_layout
*layout
;
240 const VkAllocationCallbacks
*alloc
;
241 const VkGraphicsPipelineCreateInfo
*create_info
;
243 struct tu_shader
*shaders
[MESA_SHADER_STAGES
];
244 struct ir3_shader_variant
*variants
[MESA_SHADER_STAGES
];
245 struct ir3_shader_variant
*binning_variant
;
246 uint64_t shader_iova
[MESA_SHADER_STAGES
];
247 uint64_t binning_vs_iova
;
249 bool rasterizer_discard
;
250 /* these states are affectd by rasterizer_discard */
251 VkSampleCountFlagBits samples
;
252 bool use_color_attachments
;
253 bool use_dual_src_blend
;
254 uint32_t color_attachment_count
;
255 VkFormat color_attachment_formats
[MAX_RTS
];
256 VkFormat depth_attachment_format
;
257 uint32_t render_components
;
261 tu_logic_op_reads_dst(VkLogicOp op
)
264 case VK_LOGIC_OP_CLEAR
:
265 case VK_LOGIC_OP_COPY
:
266 case VK_LOGIC_OP_COPY_INVERTED
:
267 case VK_LOGIC_OP_SET
:
275 tu_blend_factor_no_dst_alpha(VkBlendFactor factor
)
277 /* treat dst alpha as 1.0 and avoid reading it */
279 case VK_BLEND_FACTOR_DST_ALPHA
:
280 return VK_BLEND_FACTOR_ONE
;
281 case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA
:
282 return VK_BLEND_FACTOR_ZERO
;
288 static bool tu_blend_factor_is_dual_src(VkBlendFactor factor
)
291 case VK_BLEND_FACTOR_SRC1_COLOR
:
292 case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR
:
293 case VK_BLEND_FACTOR_SRC1_ALPHA
:
294 case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA
:
302 tu_blend_state_is_dual_src(const VkPipelineColorBlendStateCreateInfo
*info
)
307 for (unsigned i
= 0; i
< info
->attachmentCount
; i
++) {
308 const VkPipelineColorBlendAttachmentState
*blend
= &info
->pAttachments
[i
];
309 if (tu_blend_factor_is_dual_src(blend
->srcColorBlendFactor
) ||
310 tu_blend_factor_is_dual_src(blend
->dstColorBlendFactor
) ||
311 tu_blend_factor_is_dual_src(blend
->srcAlphaBlendFactor
) ||
312 tu_blend_factor_is_dual_src(blend
->dstAlphaBlendFactor
))
320 tu6_emit_xs_config(struct tu_cs
*cs
,
321 gl_shader_stage stage
, /* xs->type, but xs may be NULL */
322 const struct ir3_shader_variant
*xs
,
323 uint64_t binary_iova
)
325 static const struct xs_config
{
326 uint16_t reg_sp_xs_ctrl
;
327 uint16_t reg_sp_xs_config
;
328 uint16_t reg_hlsq_xs_ctrl
;
329 uint16_t reg_sp_vs_obj_start
;
331 [MESA_SHADER_VERTEX
] = {
332 REG_A6XX_SP_VS_CTRL_REG0
,
333 REG_A6XX_SP_VS_CONFIG
,
334 REG_A6XX_HLSQ_VS_CNTL
,
335 REG_A6XX_SP_VS_OBJ_START_LO
,
337 [MESA_SHADER_TESS_CTRL
] = {
338 REG_A6XX_SP_HS_CTRL_REG0
,
339 REG_A6XX_SP_HS_CONFIG
,
340 REG_A6XX_HLSQ_HS_CNTL
,
341 REG_A6XX_SP_HS_OBJ_START_LO
,
343 [MESA_SHADER_TESS_EVAL
] = {
344 REG_A6XX_SP_DS_CTRL_REG0
,
345 REG_A6XX_SP_DS_CONFIG
,
346 REG_A6XX_HLSQ_DS_CNTL
,
347 REG_A6XX_SP_DS_OBJ_START_LO
,
349 [MESA_SHADER_GEOMETRY
] = {
350 REG_A6XX_SP_GS_CTRL_REG0
,
351 REG_A6XX_SP_GS_CONFIG
,
352 REG_A6XX_HLSQ_GS_CNTL
,
353 REG_A6XX_SP_GS_OBJ_START_LO
,
355 [MESA_SHADER_FRAGMENT
] = {
356 REG_A6XX_SP_FS_CTRL_REG0
,
357 REG_A6XX_SP_FS_CONFIG
,
358 REG_A6XX_HLSQ_FS_CNTL
,
359 REG_A6XX_SP_FS_OBJ_START_LO
,
361 [MESA_SHADER_COMPUTE
] = {
362 REG_A6XX_SP_CS_CTRL_REG0
,
363 REG_A6XX_SP_CS_CONFIG
,
364 REG_A6XX_HLSQ_CS_CNTL
,
365 REG_A6XX_SP_CS_OBJ_START_LO
,
368 const struct xs_config
*cfg
= &xs_config
[stage
];
371 /* shader stage disabled */
372 tu_cs_emit_pkt4(cs
, cfg
->reg_sp_xs_config
, 1);
375 tu_cs_emit_pkt4(cs
, cfg
->reg_hlsq_xs_ctrl
, 1);
380 bool is_fs
= xs
->type
== MESA_SHADER_FRAGMENT
;
381 enum a3xx_threadsize threadsize
= FOUR_QUADS
;
384 * the "threadsize" field may have nothing to do with threadsize,
385 * use a value that matches the blob until it is figured out
387 if (xs
->type
== MESA_SHADER_GEOMETRY
)
388 threadsize
= TWO_QUADS
;
390 tu_cs_emit_pkt4(cs
, cfg
->reg_sp_xs_ctrl
, 1);
392 A6XX_SP_VS_CTRL_REG0_THREADSIZE(threadsize
) |
393 A6XX_SP_VS_CTRL_REG0_FULLREGFOOTPRINT(xs
->info
.max_reg
+ 1) |
394 A6XX_SP_VS_CTRL_REG0_HALFREGFOOTPRINT(xs
->info
.max_half_reg
+ 1) |
395 COND(xs
->mergedregs
, A6XX_SP_VS_CTRL_REG0_MERGEDREGS
) |
396 A6XX_SP_VS_CTRL_REG0_BRANCHSTACK(xs
->branchstack
) |
397 COND(xs
->need_pixlod
, A6XX_SP_VS_CTRL_REG0_PIXLODENABLE
) |
398 COND(xs
->need_fine_derivatives
, A6XX_SP_VS_CTRL_REG0_DIFF_FINE
) |
399 /* only fragment shader sets VARYING bit */
400 COND(xs
->total_in
&& is_fs
, A6XX_SP_FS_CTRL_REG0_VARYING
) |
401 /* unknown bit, seems unnecessary */
402 COND(is_fs
, 0x1000000));
404 tu_cs_emit_pkt4(cs
, cfg
->reg_sp_xs_config
, 2);
405 tu_cs_emit(cs
, A6XX_SP_VS_CONFIG_ENABLED
|
406 COND(xs
->bindless_tex
, A6XX_SP_VS_CONFIG_BINDLESS_TEX
) |
407 COND(xs
->bindless_samp
, A6XX_SP_VS_CONFIG_BINDLESS_SAMP
) |
408 COND(xs
->bindless_ibo
, A6XX_SP_VS_CONFIG_BINDLESS_IBO
) |
409 COND(xs
->bindless_ubo
, A6XX_SP_VS_CONFIG_BINDLESS_UBO
) |
410 A6XX_SP_VS_CONFIG_NTEX(xs
->num_samp
) |
411 A6XX_SP_VS_CONFIG_NSAMP(xs
->num_samp
));
412 tu_cs_emit(cs
, xs
->instrlen
);
414 tu_cs_emit_pkt4(cs
, cfg
->reg_hlsq_xs_ctrl
, 1);
415 tu_cs_emit(cs
, A6XX_HLSQ_VS_CNTL_CONSTLEN(xs
->constlen
) |
416 A6XX_HLSQ_VS_CNTL_ENABLED
);
418 /* emit program binary
419 * binary_iova should be aligned to 1 instrlen unit (128 bytes)
422 assert((binary_iova
& 0x7f) == 0);
424 tu_cs_emit_pkt4(cs
, cfg
->reg_sp_vs_obj_start
, 2);
425 tu_cs_emit_qw(cs
, binary_iova
);
427 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(stage
), 3);
428 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(0) |
429 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
430 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
431 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(stage
)) |
432 CP_LOAD_STATE6_0_NUM_UNIT(xs
->instrlen
));
433 tu_cs_emit_qw(cs
, binary_iova
);
435 /* emit immediates */
437 const struct ir3_const_state
*const_state
= ir3_const_state(xs
);
438 uint32_t base
= const_state
->offsets
.immediate
;
439 int size
= const_state
->immediates_count
;
441 /* truncate size to avoid writing constants that shader
444 size
= MIN2(size
+ base
, xs
->constlen
) - base
;
449 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(stage
), 3 + size
* 4);
450 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(base
) |
451 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
452 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
453 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(stage
)) |
454 CP_LOAD_STATE6_0_NUM_UNIT(size
));
455 tu_cs_emit(cs
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
456 tu_cs_emit(cs
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
458 for (unsigned i
= 0; i
< size
; i
++) {
459 tu_cs_emit(cs
, const_state
->immediates
[i
].val
[0]);
460 tu_cs_emit(cs
, const_state
->immediates
[i
].val
[1]);
461 tu_cs_emit(cs
, const_state
->immediates
[i
].val
[2]);
462 tu_cs_emit(cs
, const_state
->immediates
[i
].val
[3]);
467 tu6_emit_cs_config(struct tu_cs
*cs
, const struct tu_shader
*shader
,
468 const struct ir3_shader_variant
*v
,
469 uint32_t binary_iova
)
471 tu_cs_emit_pkt4(cs
, REG_A6XX_HLSQ_UPDATE_CNTL
, 1);
472 tu_cs_emit(cs
, 0xff);
474 tu6_emit_xs_config(cs
, MESA_SHADER_COMPUTE
, v
, binary_iova
);
476 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_CS_UNKNOWN_A9B1
, 1);
477 tu_cs_emit(cs
, 0x41);
479 uint32_t local_invocation_id
=
480 ir3_find_sysval_regid(v
, SYSTEM_VALUE_LOCAL_INVOCATION_ID
);
481 uint32_t work_group_id
=
482 ir3_find_sysval_regid(v
, SYSTEM_VALUE_WORK_GROUP_ID
);
484 tu_cs_emit_pkt4(cs
, REG_A6XX_HLSQ_CS_CNTL_0
, 2);
486 A6XX_HLSQ_CS_CNTL_0_WGIDCONSTID(work_group_id
) |
487 A6XX_HLSQ_CS_CNTL_0_UNK0(regid(63, 0)) |
488 A6XX_HLSQ_CS_CNTL_0_UNK1(regid(63, 0)) |
489 A6XX_HLSQ_CS_CNTL_0_LOCALIDREGID(local_invocation_id
));
490 tu_cs_emit(cs
, 0x2fc); /* HLSQ_CS_UNKNOWN_B998 */
494 tu6_emit_vs_system_values(struct tu_cs
*cs
,
495 const struct ir3_shader_variant
*vs
,
496 const struct ir3_shader_variant
*hs
,
497 const struct ir3_shader_variant
*ds
,
498 const struct ir3_shader_variant
*gs
,
499 bool primid_passthru
)
501 const uint32_t vertexid_regid
=
502 ir3_find_sysval_regid(vs
, SYSTEM_VALUE_VERTEX_ID
);
503 const uint32_t instanceid_regid
=
504 ir3_find_sysval_regid(vs
, SYSTEM_VALUE_INSTANCE_ID
);
505 const uint32_t tess_coord_x_regid
= hs
?
506 ir3_find_sysval_regid(ds
, SYSTEM_VALUE_TESS_COORD
) :
508 const uint32_t tess_coord_y_regid
= VALIDREG(tess_coord_x_regid
) ?
509 tess_coord_x_regid
+ 1 :
511 const uint32_t hs_patch_regid
= hs
?
512 ir3_find_sysval_regid(hs
, SYSTEM_VALUE_PRIMITIVE_ID
) :
514 const uint32_t ds_patch_regid
= hs
?
515 ir3_find_sysval_regid(ds
, SYSTEM_VALUE_PRIMITIVE_ID
) :
517 const uint32_t hs_invocation_regid
= hs
?
518 ir3_find_sysval_regid(hs
, SYSTEM_VALUE_TCS_HEADER_IR3
) :
520 const uint32_t primitiveid_regid
= gs
?
521 ir3_find_sysval_regid(gs
, SYSTEM_VALUE_PRIMITIVE_ID
) :
523 const uint32_t gsheader_regid
= gs
?
524 ir3_find_sysval_regid(gs
, SYSTEM_VALUE_GS_HEADER_IR3
) :
527 tu_cs_emit_pkt4(cs
, REG_A6XX_VFD_CONTROL_1
, 6);
528 tu_cs_emit(cs
, A6XX_VFD_CONTROL_1_REGID4VTX(vertexid_regid
) |
529 A6XX_VFD_CONTROL_1_REGID4INST(instanceid_regid
) |
530 A6XX_VFD_CONTROL_1_REGID4PRIMID(primitiveid_regid
) |
532 tu_cs_emit(cs
, A6XX_VFD_CONTROL_2_REGID_HSPATCHID(hs_patch_regid
) |
533 A6XX_VFD_CONTROL_2_REGID_INVOCATIONID(hs_invocation_regid
));
534 tu_cs_emit(cs
, A6XX_VFD_CONTROL_3_REGID_DSPATCHID(ds_patch_regid
) |
535 A6XX_VFD_CONTROL_3_REGID_TESSX(tess_coord_x_regid
) |
536 A6XX_VFD_CONTROL_3_REGID_TESSY(tess_coord_y_regid
) |
538 tu_cs_emit(cs
, 0x000000fc); /* VFD_CONTROL_4 */
539 tu_cs_emit(cs
, A6XX_VFD_CONTROL_5_REGID_GSHEADER(gsheader_regid
) |
540 0xfc00); /* VFD_CONTROL_5 */
541 tu_cs_emit(cs
, COND(primid_passthru
, A6XX_VFD_CONTROL_6_PRIMID_PASSTHRU
)); /* VFD_CONTROL_6 */
544 /* Add any missing varyings needed for stream-out. Otherwise varyings not
545 * used by fragment shader will be stripped out.
548 tu6_link_streamout(struct ir3_shader_linkage
*l
,
549 const struct ir3_shader_variant
*v
)
551 const struct ir3_stream_output_info
*info
= &v
->shader
->stream_output
;
554 * First, any stream-out varyings not already in linkage map (ie. also
555 * consumed by frag shader) need to be added:
557 for (unsigned i
= 0; i
< info
->num_outputs
; i
++) {
558 const struct ir3_stream_output
*out
= &info
->output
[i
];
560 (1 << (out
->num_components
+ out
->start_component
)) - 1;
561 unsigned k
= out
->register_index
;
562 unsigned idx
, nextloc
= 0;
564 /* psize/pos need to be the last entries in linkage map, and will
565 * get added link_stream_out, so skip over them:
567 if (v
->outputs
[k
].slot
== VARYING_SLOT_PSIZ
||
568 v
->outputs
[k
].slot
== VARYING_SLOT_POS
)
571 for (idx
= 0; idx
< l
->cnt
; idx
++) {
572 if (l
->var
[idx
].regid
== v
->outputs
[k
].regid
)
574 nextloc
= MAX2(nextloc
, l
->var
[idx
].loc
+ 4);
577 /* add if not already in linkage map: */
579 ir3_link_add(l
, v
->outputs
[k
].regid
, compmask
, nextloc
);
581 /* expand component-mask if needed, ie streaming out all components
582 * but frag shader doesn't consume all components:
584 if (compmask
& ~l
->var
[idx
].compmask
) {
585 l
->var
[idx
].compmask
|= compmask
;
586 l
->max_loc
= MAX2(l
->max_loc
, l
->var
[idx
].loc
+
587 util_last_bit(l
->var
[idx
].compmask
));
593 tu6_setup_streamout(struct tu_cs
*cs
,
594 const struct ir3_shader_variant
*v
,
595 struct ir3_shader_linkage
*l
)
597 const struct ir3_stream_output_info
*info
= &v
->shader
->stream_output
;
598 uint32_t prog
[IR3_MAX_SO_OUTPUTS
* 2] = {};
599 uint32_t ncomp
[IR3_MAX_SO_BUFFERS
] = {};
600 uint32_t prog_count
= align(l
->max_loc
, 2) / 2;
602 /* TODO: streamout state should be in a non-GMEM draw state */
605 if (info
->num_outputs
== 0) {
606 tu_cs_emit_pkt7(cs
, CP_CONTEXT_REG_BUNCH
, 4);
607 tu_cs_emit(cs
, REG_A6XX_VPC_SO_CNTL
);
609 tu_cs_emit(cs
, REG_A6XX_VPC_SO_BUF_CNTL
);
614 /* is there something to do with info->stride[i]? */
616 for (unsigned i
= 0; i
< info
->num_outputs
; i
++) {
617 const struct ir3_stream_output
*out
= &info
->output
[i
];
618 unsigned k
= out
->register_index
;
621 /* Skip it, if there's an unused reg in the middle of outputs. */
622 if (v
->outputs
[k
].regid
== INVALID_REG
)
625 ncomp
[out
->output_buffer
] += out
->num_components
;
627 /* linkage map sorted by order frag shader wants things, so
628 * a bit less ideal here..
630 for (idx
= 0; idx
< l
->cnt
; idx
++)
631 if (l
->var
[idx
].regid
== v
->outputs
[k
].regid
)
634 debug_assert(idx
< l
->cnt
);
636 for (unsigned j
= 0; j
< out
->num_components
; j
++) {
637 unsigned c
= j
+ out
->start_component
;
638 unsigned loc
= l
->var
[idx
].loc
+ c
;
639 unsigned off
= j
+ out
->dst_offset
; /* in dwords */
642 prog
[loc
/2] |= A6XX_VPC_SO_PROG_B_EN
|
643 A6XX_VPC_SO_PROG_B_BUF(out
->output_buffer
) |
644 A6XX_VPC_SO_PROG_B_OFF(off
* 4);
646 prog
[loc
/2] |= A6XX_VPC_SO_PROG_A_EN
|
647 A6XX_VPC_SO_PROG_A_BUF(out
->output_buffer
) |
648 A6XX_VPC_SO_PROG_A_OFF(off
* 4);
653 tu_cs_emit_pkt7(cs
, CP_CONTEXT_REG_BUNCH
, 12 + 2 * prog_count
);
654 tu_cs_emit(cs
, REG_A6XX_VPC_SO_BUF_CNTL
);
655 tu_cs_emit(cs
, A6XX_VPC_SO_BUF_CNTL_ENABLE
|
656 COND(ncomp
[0] > 0, A6XX_VPC_SO_BUF_CNTL_BUF0
) |
657 COND(ncomp
[1] > 0, A6XX_VPC_SO_BUF_CNTL_BUF1
) |
658 COND(ncomp
[2] > 0, A6XX_VPC_SO_BUF_CNTL_BUF2
) |
659 COND(ncomp
[3] > 0, A6XX_VPC_SO_BUF_CNTL_BUF3
));
660 for (uint32_t i
= 0; i
< 4; i
++) {
661 tu_cs_emit(cs
, REG_A6XX_VPC_SO_NCOMP(i
));
662 tu_cs_emit(cs
, ncomp
[i
]);
664 /* note: "VPC_SO_CNTL" write seems to be responsible for resetting the SO_PROG */
665 tu_cs_emit(cs
, REG_A6XX_VPC_SO_CNTL
);
666 tu_cs_emit(cs
, A6XX_VPC_SO_CNTL_ENABLE
);
667 for (uint32_t i
= 0; i
< prog_count
; i
++) {
668 tu_cs_emit(cs
, REG_A6XX_VPC_SO_PROG
);
669 tu_cs_emit(cs
, prog
[i
]);
674 tu6_emit_const(struct tu_cs
*cs
, uint32_t opcode
, uint32_t base
,
675 enum a6xx_state_block block
, uint32_t offset
,
676 uint32_t size
, uint32_t *dwords
) {
677 assert(size
% 4 == 0);
679 tu_cs_emit_pkt7(cs
, opcode
, 3 + size
);
680 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(base
) |
681 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
682 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
683 CP_LOAD_STATE6_0_STATE_BLOCK(block
) |
684 CP_LOAD_STATE6_0_NUM_UNIT(size
/ 4));
686 tu_cs_emit(cs
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
687 tu_cs_emit(cs
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
688 dwords
= (uint32_t *)&((uint8_t *)dwords
)[offset
];
690 tu_cs_emit_array(cs
, dwords
, size
);
694 tu6_emit_link_map(struct tu_cs
*cs
,
695 const struct ir3_shader_variant
*producer
,
696 const struct ir3_shader_variant
*consumer
,
697 enum a6xx_state_block sb
)
699 const struct ir3_const_state
*const_state
= ir3_const_state(consumer
);
700 uint32_t base
= const_state
->offsets
.primitive_map
;
701 uint32_t patch_locs
[MAX_VARYING
] = { }, num_loc
;
702 num_loc
= ir3_link_geometry_stages(producer
, consumer
, patch_locs
);
703 int size
= DIV_ROUND_UP(num_loc
, 4);
705 size
= (MIN2(size
+ base
, consumer
->constlen
) - base
) * 4;
709 tu6_emit_const(cs
, CP_LOAD_STATE6_GEOM
, base
, sb
, 0, size
,
714 gl_primitive_to_tess(uint16_t primitive
) {
720 case GL_TRIANGLE_STRIP
:
728 tu6_emit_vpc(struct tu_cs
*cs
,
729 const struct ir3_shader_variant
*vs
,
730 const struct ir3_shader_variant
*hs
,
731 const struct ir3_shader_variant
*ds
,
732 const struct ir3_shader_variant
*gs
,
733 const struct ir3_shader_variant
*fs
)
735 const struct ir3_shader_variant
*last_shader
;
743 struct ir3_shader_linkage linkage
= { .primid_loc
= 0xff };
745 ir3_link_shaders(&linkage
, last_shader
, fs
, true);
747 if (last_shader
->shader
->stream_output
.num_outputs
)
748 tu6_link_streamout(&linkage
, last_shader
);
750 /* We do this after linking shaders in order to know whether PrimID
751 * passthrough needs to be enabled.
753 bool primid_passthru
= linkage
.primid_loc
!= 0xff;
754 tu6_emit_vs_system_values(cs
, vs
, hs
, ds
, gs
, primid_passthru
);
756 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_VAR_DISABLE(0), 4);
757 tu_cs_emit(cs
, ~linkage
.varmask
[0]);
758 tu_cs_emit(cs
, ~linkage
.varmask
[1]);
759 tu_cs_emit(cs
, ~linkage
.varmask
[2]);
760 tu_cs_emit(cs
, ~linkage
.varmask
[3]);
762 /* a6xx finds position/pointsize at the end */
763 const uint32_t position_regid
=
764 ir3_find_output_regid(last_shader
, VARYING_SLOT_POS
);
765 const uint32_t pointsize_regid
=
766 ir3_find_output_regid(last_shader
, VARYING_SLOT_PSIZ
);
767 const uint32_t layer_regid
= gs
?
768 ir3_find_output_regid(gs
, VARYING_SLOT_LAYER
) : regid(63, 0);
770 uint32_t pointsize_loc
= 0xff, position_loc
= 0xff, layer_loc
= 0xff;
771 if (layer_regid
!= regid(63, 0)) {
772 layer_loc
= linkage
.max_loc
;
773 ir3_link_add(&linkage
, layer_regid
, 0x1, linkage
.max_loc
);
775 if (position_regid
!= regid(63, 0)) {
776 position_loc
= linkage
.max_loc
;
777 ir3_link_add(&linkage
, position_regid
, 0xf, linkage
.max_loc
);
779 if (pointsize_regid
!= regid(63, 0)) {
780 pointsize_loc
= linkage
.max_loc
;
781 ir3_link_add(&linkage
, pointsize_regid
, 0x1, linkage
.max_loc
);
784 tu6_setup_streamout(cs
, last_shader
, &linkage
);
786 /* map outputs of the last shader to VPC */
787 assert(linkage
.cnt
<= 32);
788 const uint32_t sp_out_count
= DIV_ROUND_UP(linkage
.cnt
, 2);
789 const uint32_t sp_vpc_dst_count
= DIV_ROUND_UP(linkage
.cnt
, 4);
791 uint32_t sp_vpc_dst
[8];
792 for (uint32_t i
= 0; i
< linkage
.cnt
; i
++) {
793 ((uint16_t *) sp_out
)[i
] =
794 A6XX_SP_VS_OUT_REG_A_REGID(linkage
.var
[i
].regid
) |
795 A6XX_SP_VS_OUT_REG_A_COMPMASK(linkage
.var
[i
].compmask
);
796 ((uint8_t *) sp_vpc_dst
)[i
] =
797 A6XX_SP_VS_VPC_DST_REG_OUTLOC0(linkage
.var
[i
].loc
);
801 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_GS_OUT_REG(0), sp_out_count
);
803 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_DS_OUT_REG(0), sp_out_count
);
805 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_VS_OUT_REG(0), sp_out_count
);
806 tu_cs_emit_array(cs
, sp_out
, sp_out_count
);
809 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_GS_VPC_DST_REG(0), sp_vpc_dst_count
);
811 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_DS_VPC_DST_REG(0), sp_vpc_dst_count
);
813 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_VS_VPC_DST_REG(0), sp_vpc_dst_count
);
814 tu_cs_emit_array(cs
, sp_vpc_dst
, sp_vpc_dst_count
);
816 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_PRIMID_CNTL
, 1);
817 tu_cs_emit(cs
, COND(primid_passthru
, A6XX_PC_PRIMID_CNTL_PRIMID_PASSTHRU
));
819 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_CNTL_0
, 1);
820 tu_cs_emit(cs
, A6XX_VPC_CNTL_0_NUMNONPOSVAR(fs
? fs
->total_in
: 0) |
821 COND(fs
&& fs
->total_in
, A6XX_VPC_CNTL_0_VARYING
) |
822 A6XX_VPC_CNTL_0_PRIMIDLOC(linkage
.primid_loc
) |
823 A6XX_VPC_CNTL_0_UNKLOC(0xff));
825 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_PACK
, 1);
826 tu_cs_emit(cs
, A6XX_VPC_PACK_POSITIONLOC(position_loc
) |
827 A6XX_VPC_PACK_PSIZELOC(pointsize_loc
) |
828 A6XX_VPC_PACK_STRIDE_IN_VPC(linkage
.max_loc
));
831 shader_info
*hs_info
= &hs
->shader
->nir
->info
;
832 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_TESS_NUM_VERTEX
, 1);
833 tu_cs_emit(cs
, hs_info
->tess
.tcs_vertices_out
);
835 /* Total attribute slots in HS incoming patch. */
836 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_UNKNOWN_9801
, 1);
838 hs_info
->tess
.tcs_vertices_out
* vs
->output_size
/ 4);
840 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_HS_UNKNOWN_A831
, 1);
841 tu_cs_emit(cs
, vs
->output_size
);
842 /* In SPIR-V generated from GLSL, the tessellation primitive params are
843 * are specified in the tess eval shader, but in SPIR-V generated from
844 * HLSL, they are specified in the tess control shader. */
845 shader_info
*tess_info
=
846 ds
->shader
->nir
->info
.tess
.spacing
== TESS_SPACING_UNSPECIFIED
?
847 &hs
->shader
->nir
->info
: &ds
->shader
->nir
->info
;
848 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_TESS_CNTL
, 1);
850 if (tess_info
->tess
.point_mode
)
851 output
= TESS_POINTS
;
852 else if (tess_info
->tess
.primitive_mode
== GL_ISOLINES
)
854 else if (tess_info
->tess
.ccw
)
855 output
= TESS_CCW_TRIS
;
857 output
= TESS_CW_TRIS
;
859 enum a6xx_tess_spacing spacing
;
860 switch (tess_info
->tess
.spacing
) {
861 case TESS_SPACING_EQUAL
:
862 spacing
= TESS_EQUAL
;
864 case TESS_SPACING_FRACTIONAL_ODD
:
865 spacing
= TESS_FRACTIONAL_ODD
;
867 case TESS_SPACING_FRACTIONAL_EVEN
:
868 spacing
= TESS_FRACTIONAL_EVEN
;
870 case TESS_SPACING_UNSPECIFIED
:
872 unreachable("invalid tess spacing");
874 tu_cs_emit(cs
, A6XX_PC_TESS_CNTL_SPACING(spacing
) |
875 A6XX_PC_TESS_CNTL_OUTPUT(output
));
877 /* xxx: Misc tess unknowns: */
878 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_UNKNOWN_9103
, 1);
879 tu_cs_emit(cs
, 0x00ffff00);
881 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_UNKNOWN_9106
, 1);
882 tu_cs_emit(cs
, 0x0000ffff);
884 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_UNKNOWN_809D
, 1);
887 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_UNKNOWN_8002
, 1);
890 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_PACK
, 1);
891 tu_cs_emit(cs
, A6XX_VPC_PACK_POSITIONLOC(position_loc
) |
892 A6XX_VPC_PACK_PSIZELOC(255) |
893 A6XX_VPC_PACK_STRIDE_IN_VPC(linkage
.max_loc
));
895 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_PACK_3
, 1);
896 tu_cs_emit(cs
, A6XX_VPC_PACK_3_POSITIONLOC(position_loc
) |
897 A6XX_VPC_PACK_3_PSIZELOC(pointsize_loc
) |
898 A6XX_VPC_PACK_3_STRIDE_IN_VPC(linkage
.max_loc
));
900 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_DS_PRIMITIVE_CNTL
, 1);
901 tu_cs_emit(cs
, A6XX_SP_DS_PRIMITIVE_CNTL_DSOUT(linkage
.cnt
));
903 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_4
, 1);
904 tu_cs_emit(cs
, A6XX_PC_PRIMITIVE_CNTL_4_STRIDE_IN_VPC(linkage
.max_loc
) |
905 CONDREG(pointsize_regid
, 0x100));
907 tu6_emit_link_map(cs
, vs
, hs
, SB6_HS_SHADER
);
908 tu6_emit_link_map(cs
, hs
, ds
, SB6_DS_SHADER
);
913 uint32_t vertices_out
, invocations
, output
, vec4_size
;
914 /* this detects the tu_clear_blit path, which doesn't set ->nir */
915 if (gs
->shader
->nir
) {
917 tu6_emit_link_map(cs
, ds
, gs
, SB6_GS_SHADER
);
919 tu6_emit_link_map(cs
, vs
, gs
, SB6_GS_SHADER
);
921 vertices_out
= gs
->shader
->nir
->info
.gs
.vertices_out
- 1;
922 output
= gl_primitive_to_tess(gs
->shader
->nir
->info
.gs
.output_primitive
);
923 invocations
= gs
->shader
->nir
->info
.gs
.invocations
- 1;
924 /* Size of per-primitive alloction in ldlw memory in vec4s. */
925 vec4_size
= gs
->shader
->nir
->info
.gs
.vertices_in
*
926 DIV_ROUND_UP(vs
->output_size
, 4);
929 output
= TESS_CW_TRIS
;
934 uint32_t primitive_regid
=
935 ir3_find_sysval_regid(gs
, SYSTEM_VALUE_PRIMITIVE_ID
);
936 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_PACK_GS
, 1);
937 tu_cs_emit(cs
, A6XX_VPC_PACK_GS_POSITIONLOC(position_loc
) |
938 A6XX_VPC_PACK_GS_PSIZELOC(pointsize_loc
) |
939 A6XX_VPC_PACK_GS_STRIDE_IN_VPC(linkage
.max_loc
));
941 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_UNKNOWN_9105
, 1);
942 tu_cs_emit(cs
, A6XX_VPC_UNKNOWN_9105_LAYERLOC(layer_loc
) | 0xff00);
944 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_UNKNOWN_809C
, 1);
945 tu_cs_emit(cs
, CONDREG(layer_regid
,
946 A6XX_GRAS_UNKNOWN_809C_GS_WRITES_LAYER
));
948 uint32_t flags_regid
= ir3_find_output_regid(gs
,
949 VARYING_SLOT_GS_VERTEX_FLAGS_IR3
);
951 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_PRIMITIVE_CNTL_GS
, 1);
952 tu_cs_emit(cs
, A6XX_SP_PRIMITIVE_CNTL_GS_GSOUT(linkage
.cnt
) |
953 A6XX_SP_PRIMITIVE_CNTL_GS_FLAGS_REGID(flags_regid
));
955 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_2
, 1);
956 tu_cs_emit(cs
, A6XX_PC_PRIMITIVE_CNTL_2_STRIDE_IN_VPC(linkage
.max_loc
) |
957 CONDREG(pointsize_regid
, A6XX_PC_PRIMITIVE_CNTL_2_PSIZE
) |
958 CONDREG(layer_regid
, A6XX_PC_PRIMITIVE_CNTL_2_LAYER
) |
959 CONDREG(primitive_regid
, A6XX_PC_PRIMITIVE_CNTL_2_PRIMITIVE_ID
));
961 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_5
, 1);
963 A6XX_PC_PRIMITIVE_CNTL_5_GS_VERTICES_OUT(vertices_out
) |
964 A6XX_PC_PRIMITIVE_CNTL_5_GS_OUTPUT(output
) |
965 A6XX_PC_PRIMITIVE_CNTL_5_GS_INVOCATIONS(invocations
));
967 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_3
, 1);
970 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_UNKNOWN_8003
, 1);
973 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_UNKNOWN_9100
, 1);
974 tu_cs_emit(cs
, 0xff);
976 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_UNKNOWN_9102
, 1);
977 tu_cs_emit(cs
, 0xffff00);
979 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_6
, 1);
980 tu_cs_emit(cs
, A6XX_PC_PRIMITIVE_CNTL_6_STRIDE_IN_VPC(vec4_size
));
982 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_UNKNOWN_9B07
, 1);
985 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_GS_PRIM_SIZE
, 1);
986 tu_cs_emit(cs
, vs
->output_size
);
989 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_PRIMITIVE_CNTL
, 1);
990 tu_cs_emit(cs
, A6XX_SP_PRIMITIVE_CNTL_VSOUT(linkage
.cnt
));
992 tu_cs_emit_pkt4(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_1
, 1);
993 tu_cs_emit(cs
, A6XX_PC_PRIMITIVE_CNTL_1_STRIDE_IN_VPC(linkage
.max_loc
) |
994 (last_shader
->writes_psize
? A6XX_PC_PRIMITIVE_CNTL_1_PSIZE
: 0));
998 tu6_vpc_varying_mode(const struct ir3_shader_variant
*fs
,
1000 uint8_t *interp_mode
,
1001 uint8_t *ps_repl_mode
)
1015 PS_REPL_ONE_MINUS_T
= 3,
1018 const uint32_t compmask
= fs
->inputs
[index
].compmask
;
1020 /* NOTE: varyings are packed, so if compmask is 0xb then first, second, and
1021 * fourth component occupy three consecutive varying slots
1026 if (fs
->inputs
[index
].slot
== VARYING_SLOT_PNTC
) {
1027 if (compmask
& 0x1) {
1028 *ps_repl_mode
|= PS_REPL_S
<< shift
;
1031 if (compmask
& 0x2) {
1032 *ps_repl_mode
|= PS_REPL_T
<< shift
;
1035 if (compmask
& 0x4) {
1036 *interp_mode
|= INTERP_ZERO
<< shift
;
1039 if (compmask
& 0x8) {
1040 *interp_mode
|= INTERP_ONE
<< 6;
1043 } else if ((fs
->inputs
[index
].interpolate
== INTERP_MODE_FLAT
) ||
1044 fs
->inputs
[index
].rasterflat
) {
1045 for (int i
= 0; i
< 4; i
++) {
1046 if (compmask
& (1 << i
)) {
1047 *interp_mode
|= INTERP_FLAT
<< shift
;
1057 tu6_emit_vpc_varying_modes(struct tu_cs
*cs
,
1058 const struct ir3_shader_variant
*fs
)
1060 uint32_t interp_modes
[8] = { 0 };
1061 uint32_t ps_repl_modes
[8] = { 0 };
1065 (i
= ir3_next_varying(fs
, i
)) < (int) fs
->inputs_count
;) {
1067 /* get the mode for input i */
1068 uint8_t interp_mode
;
1069 uint8_t ps_repl_mode
;
1071 tu6_vpc_varying_mode(fs
, i
, &interp_mode
, &ps_repl_mode
);
1073 /* OR the mode into the array */
1074 const uint32_t inloc
= fs
->inputs
[i
].inloc
* 2;
1075 uint32_t n
= inloc
/ 32;
1076 uint32_t shift
= inloc
% 32;
1077 interp_modes
[n
] |= interp_mode
<< shift
;
1078 ps_repl_modes
[n
] |= ps_repl_mode
<< shift
;
1079 if (shift
+ bits
> 32) {
1083 interp_modes
[n
] |= interp_mode
>> shift
;
1084 ps_repl_modes
[n
] |= ps_repl_mode
>> shift
;
1089 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_VARYING_INTERP_MODE(0), 8);
1090 tu_cs_emit_array(cs
, interp_modes
, 8);
1092 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_VARYING_PS_REPL_MODE(0), 8);
1093 tu_cs_emit_array(cs
, ps_repl_modes
, 8);
1097 tu6_emit_fs_inputs(struct tu_cs
*cs
, const struct ir3_shader_variant
*fs
)
1099 uint32_t face_regid
, coord_regid
, zwcoord_regid
, samp_id_regid
;
1100 uint32_t ij_regid
[IJ_COUNT
];
1101 uint32_t smask_in_regid
;
1103 bool sample_shading
= fs
->per_samp
| fs
->key
.sample_shading
;
1104 bool enable_varyings
= fs
->total_in
> 0;
1106 samp_id_regid
= ir3_find_sysval_regid(fs
, SYSTEM_VALUE_SAMPLE_ID
);
1107 smask_in_regid
= ir3_find_sysval_regid(fs
, SYSTEM_VALUE_SAMPLE_MASK_IN
);
1108 face_regid
= ir3_find_sysval_regid(fs
, SYSTEM_VALUE_FRONT_FACE
);
1109 coord_regid
= ir3_find_sysval_regid(fs
, SYSTEM_VALUE_FRAG_COORD
);
1110 zwcoord_regid
= VALIDREG(coord_regid
) ? coord_regid
+ 2 : regid(63, 0);
1111 for (unsigned i
= 0; i
< ARRAY_SIZE(ij_regid
); i
++)
1112 ij_regid
[i
] = ir3_find_sysval_regid(fs
, SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL
+ i
);
1114 if (VALIDREG(ij_regid
[IJ_LINEAR_SAMPLE
]))
1115 tu_finishme("linear sample varying");
1117 if (VALIDREG(ij_regid
[IJ_LINEAR_CENTROID
]))
1118 tu_finishme("linear centroid varying");
1120 if (fs
->num_sampler_prefetch
> 0) {
1121 assert(VALIDREG(ij_regid
[IJ_PERSP_PIXEL
]));
1122 /* also, it seems like ij_pix is *required* to be r0.x */
1123 assert(ij_regid
[IJ_PERSP_PIXEL
] == regid(0, 0));
1126 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_FS_PREFETCH_CNTL
, 1 + fs
->num_sampler_prefetch
);
1127 tu_cs_emit(cs
, A6XX_SP_FS_PREFETCH_CNTL_COUNT(fs
->num_sampler_prefetch
) |
1128 A6XX_SP_FS_PREFETCH_CNTL_UNK4(regid(63, 0)) |
1130 for (int i
= 0; i
< fs
->num_sampler_prefetch
; i
++) {
1131 const struct ir3_sampler_prefetch
*prefetch
= &fs
->sampler_prefetch
[i
];
1132 tu_cs_emit(cs
, A6XX_SP_FS_PREFETCH_CMD_SRC(prefetch
->src
) |
1133 A6XX_SP_FS_PREFETCH_CMD_SAMP_ID(prefetch
->samp_id
) |
1134 A6XX_SP_FS_PREFETCH_CMD_TEX_ID(prefetch
->tex_id
) |
1135 A6XX_SP_FS_PREFETCH_CMD_DST(prefetch
->dst
) |
1136 A6XX_SP_FS_PREFETCH_CMD_WRMASK(prefetch
->wrmask
) |
1137 COND(prefetch
->half_precision
, A6XX_SP_FS_PREFETCH_CMD_HALF
) |
1138 A6XX_SP_FS_PREFETCH_CMD_CMD(prefetch
->cmd
));
1141 if (fs
->num_sampler_prefetch
> 0) {
1142 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_FS_BINDLESS_PREFETCH_CMD(0), fs
->num_sampler_prefetch
);
1143 for (int i
= 0; i
< fs
->num_sampler_prefetch
; i
++) {
1144 const struct ir3_sampler_prefetch
*prefetch
= &fs
->sampler_prefetch
[i
];
1146 A6XX_SP_FS_BINDLESS_PREFETCH_CMD_SAMP_ID(prefetch
->samp_bindless_id
) |
1147 A6XX_SP_FS_BINDLESS_PREFETCH_CMD_TEX_ID(prefetch
->tex_bindless_id
));
1151 tu_cs_emit_pkt4(cs
, REG_A6XX_HLSQ_CONTROL_1_REG
, 5);
1152 tu_cs_emit(cs
, 0x7);
1153 tu_cs_emit(cs
, A6XX_HLSQ_CONTROL_2_REG_FACEREGID(face_regid
) |
1154 A6XX_HLSQ_CONTROL_2_REG_SAMPLEID(samp_id_regid
) |
1155 A6XX_HLSQ_CONTROL_2_REG_SAMPLEMASK(smask_in_regid
) |
1156 A6XX_HLSQ_CONTROL_2_REG_SIZE(ij_regid
[IJ_PERSP_SIZE
]));
1157 tu_cs_emit(cs
, A6XX_HLSQ_CONTROL_3_REG_IJ_PERSP_PIXEL(ij_regid
[IJ_PERSP_PIXEL
]) |
1158 A6XX_HLSQ_CONTROL_3_REG_IJ_LINEAR_PIXEL(ij_regid
[IJ_LINEAR_PIXEL
]) |
1159 A6XX_HLSQ_CONTROL_3_REG_IJ_PERSP_CENTROID(ij_regid
[IJ_PERSP_CENTROID
]) |
1160 A6XX_HLSQ_CONTROL_3_REG_IJ_LINEAR_CENTROID(ij_regid
[IJ_LINEAR_CENTROID
]));
1161 tu_cs_emit(cs
, A6XX_HLSQ_CONTROL_4_REG_XYCOORDREGID(coord_regid
) |
1162 A6XX_HLSQ_CONTROL_4_REG_ZWCOORDREGID(zwcoord_regid
) |
1163 A6XX_HLSQ_CONTROL_4_REG_IJ_PERSP_SAMPLE(ij_regid
[IJ_PERSP_SAMPLE
]) |
1164 A6XX_HLSQ_CONTROL_4_REG_IJ_LINEAR_SAMPLE(ij_regid
[IJ_LINEAR_SAMPLE
]));
1165 tu_cs_emit(cs
, 0xfc);
1167 tu_cs_emit_pkt4(cs
, REG_A6XX_HLSQ_UNKNOWN_B980
, 1);
1168 tu_cs_emit(cs
, enable_varyings
? 3 : 1);
1170 bool need_size
= fs
->frag_face
|| fs
->fragcoord_compmask
!= 0;
1171 bool need_size_persamp
= false;
1172 if (VALIDREG(ij_regid
[IJ_PERSP_SIZE
])) {
1174 need_size_persamp
= true;
1178 if (VALIDREG(ij_regid
[IJ_LINEAR_PIXEL
]))
1181 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_CNTL
, 1);
1183 CONDREG(ij_regid
[IJ_PERSP_PIXEL
], A6XX_GRAS_CNTL_IJ_PERSP_PIXEL
) |
1184 CONDREG(ij_regid
[IJ_PERSP_CENTROID
], A6XX_GRAS_CNTL_IJ_PERSP_CENTROID
) |
1185 CONDREG(ij_regid
[IJ_PERSP_SAMPLE
], A6XX_GRAS_CNTL_IJ_PERSP_SAMPLE
) |
1186 COND(need_size
, A6XX_GRAS_CNTL_SIZE
) |
1187 COND(need_size_persamp
, A6XX_GRAS_CNTL_SIZE_PERSAMP
) |
1188 COND(fs
->fragcoord_compmask
!= 0, A6XX_GRAS_CNTL_COORD_MASK(fs
->fragcoord_compmask
)));
1190 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_RENDER_CONTROL0
, 2);
1192 CONDREG(ij_regid
[IJ_PERSP_PIXEL
], A6XX_RB_RENDER_CONTROL0_IJ_PERSP_PIXEL
) |
1193 CONDREG(ij_regid
[IJ_PERSP_CENTROID
], A6XX_RB_RENDER_CONTROL0_IJ_PERSP_CENTROID
) |
1194 CONDREG(ij_regid
[IJ_PERSP_SAMPLE
], A6XX_RB_RENDER_CONTROL0_IJ_PERSP_SAMPLE
) |
1195 COND(need_size
, A6XX_RB_RENDER_CONTROL0_SIZE
) |
1196 COND(enable_varyings
, A6XX_RB_RENDER_CONTROL0_UNK10
) |
1197 COND(need_size_persamp
, A6XX_RB_RENDER_CONTROL0_SIZE_PERSAMP
) |
1198 COND(fs
->fragcoord_compmask
!= 0,
1199 A6XX_RB_RENDER_CONTROL0_COORD_MASK(fs
->fragcoord_compmask
)));
1201 /* these two bits (UNK4/UNK5) relate to fragcoord
1202 * without them, fragcoord is the same for all samples
1204 COND(sample_shading
, A6XX_RB_RENDER_CONTROL1_UNK4
) |
1205 COND(sample_shading
, A6XX_RB_RENDER_CONTROL1_UNK5
) |
1206 CONDREG(smask_in_regid
, A6XX_RB_RENDER_CONTROL1_SAMPLEMASK
) |
1207 CONDREG(samp_id_regid
, A6XX_RB_RENDER_CONTROL1_SAMPLEID
) |
1208 CONDREG(ij_regid
[IJ_PERSP_SIZE
], A6XX_RB_RENDER_CONTROL1_SIZE
) |
1209 COND(fs
->frag_face
, A6XX_RB_RENDER_CONTROL1_FACENESS
));
1211 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_SAMPLE_CNTL
, 1);
1212 tu_cs_emit(cs
, COND(sample_shading
, A6XX_RB_SAMPLE_CNTL_PER_SAMP_MODE
));
1214 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_UNKNOWN_8101
, 1);
1215 tu_cs_emit(cs
, COND(sample_shading
, 0x6)); // XXX
1217 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_SAMPLE_CNTL
, 1);
1218 tu_cs_emit(cs
, COND(sample_shading
, A6XX_GRAS_SAMPLE_CNTL_PER_SAMP_MODE
));
1222 tu6_emit_fs_outputs(struct tu_cs
*cs
,
1223 const struct ir3_shader_variant
*fs
,
1224 uint32_t mrt_count
, bool dual_src_blend
,
1225 uint32_t render_components
,
1228 uint32_t smask_regid
, posz_regid
;
1230 posz_regid
= ir3_find_output_regid(fs
, FRAG_RESULT_DEPTH
);
1231 smask_regid
= ir3_find_output_regid(fs
, FRAG_RESULT_SAMPLE_MASK
);
1233 uint32_t fragdata_regid
[8];
1234 if (fs
->color0_mrt
) {
1235 fragdata_regid
[0] = ir3_find_output_regid(fs
, FRAG_RESULT_COLOR
);
1236 for (uint32_t i
= 1; i
< ARRAY_SIZE(fragdata_regid
); i
++)
1237 fragdata_regid
[i
] = fragdata_regid
[0];
1239 for (uint32_t i
= 0; i
< ARRAY_SIZE(fragdata_regid
); i
++)
1240 fragdata_regid
[i
] = ir3_find_output_regid(fs
, FRAG_RESULT_DATA0
+ i
);
1243 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_FS_OUTPUT_CNTL0
, 2);
1244 tu_cs_emit(cs
, A6XX_SP_FS_OUTPUT_CNTL0_DEPTH_REGID(posz_regid
) |
1245 A6XX_SP_FS_OUTPUT_CNTL0_SAMPMASK_REGID(smask_regid
) |
1246 COND(dual_src_blend
, A6XX_SP_FS_OUTPUT_CNTL0_DUAL_COLOR_IN_ENABLE
) |
1248 tu_cs_emit(cs
, A6XX_SP_FS_OUTPUT_CNTL1_MRT(mrt_count
));
1250 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_FS_OUTPUT_REG(0), 8);
1251 for (uint32_t i
= 0; i
< ARRAY_SIZE(fragdata_regid
); i
++) {
1252 // TODO we could have a mix of half and full precision outputs,
1253 // we really need to figure out half-precision from IR3_REG_HALF
1254 tu_cs_emit(cs
, A6XX_SP_FS_OUTPUT_REG_REGID(fragdata_regid
[i
]) |
1255 (false ? A6XX_SP_FS_OUTPUT_REG_HALF_PRECISION
: 0));
1259 A6XX_SP_FS_RENDER_COMPONENTS(.dword
= render_components
));
1261 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 2);
1262 tu_cs_emit(cs
, COND(fs
->writes_pos
, A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_Z
) |
1263 COND(fs
->writes_smask
, A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_SAMPMASK
) |
1264 COND(dual_src_blend
, A6XX_RB_FS_OUTPUT_CNTL0_DUAL_COLOR_IN_ENABLE
));
1265 tu_cs_emit(cs
, A6XX_RB_FS_OUTPUT_CNTL1_MRT(mrt_count
));
1268 A6XX_RB_RENDER_COMPONENTS(.dword
= render_components
));
1270 enum a6xx_ztest_mode zmode
;
1272 if (fs
->no_earlyz
|| fs
->has_kill
|| fs
->writes_pos
|| is_s8_uint
) {
1273 zmode
= A6XX_LATE_Z
;
1275 zmode
= A6XX_EARLY_Z
;
1278 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_SU_DEPTH_PLANE_CNTL
, 1);
1279 tu_cs_emit(cs
, A6XX_GRAS_SU_DEPTH_PLANE_CNTL_Z_MODE(zmode
));
1281 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_DEPTH_PLANE_CNTL
, 1);
1282 tu_cs_emit(cs
, A6XX_RB_DEPTH_PLANE_CNTL_Z_MODE(zmode
));
1286 tu6_emit_geom_tess_consts(struct tu_cs
*cs
,
1287 const struct ir3_shader_variant
*vs
,
1288 const struct ir3_shader_variant
*hs
,
1289 const struct ir3_shader_variant
*ds
,
1290 const struct ir3_shader_variant
*gs
,
1291 uint32_t cps_per_patch
)
1293 uint32_t num_vertices
=
1294 hs
? cps_per_patch
: gs
->shader
->nir
->info
.gs
.vertices_in
;
1296 uint32_t vs_params
[4] = {
1297 vs
->output_size
* num_vertices
* 4, /* vs primitive stride */
1298 vs
->output_size
* 4, /* vs vertex stride */
1302 uint32_t vs_base
= ir3_const_state(vs
)->offsets
.primitive_param
;
1303 tu6_emit_const(cs
, CP_LOAD_STATE6_GEOM
, vs_base
, SB6_VS_SHADER
, 0,
1304 ARRAY_SIZE(vs_params
), vs_params
);
1307 assert(ds
->type
!= MESA_SHADER_NONE
);
1308 uint32_t hs_params
[4] = {
1309 vs
->output_size
* num_vertices
* 4, /* hs primitive stride */
1310 vs
->output_size
* 4, /* hs vertex stride */
1315 uint32_t hs_base
= hs
->const_state
->offsets
.primitive_param
;
1316 tu6_emit_const(cs
, CP_LOAD_STATE6_GEOM
, hs_base
, SB6_HS_SHADER
, 0,
1317 ARRAY_SIZE(hs_params
), hs_params
);
1319 num_vertices
= gs
->shader
->nir
->info
.gs
.vertices_in
;
1321 uint32_t ds_params
[4] = {
1322 ds
->output_size
* num_vertices
* 4, /* ds primitive stride */
1323 ds
->output_size
* 4, /* ds vertex stride */
1324 hs
->output_size
, /* hs vertex stride (dwords) */
1325 hs
->shader
->nir
->info
.tess
.tcs_vertices_out
1328 uint32_t ds_base
= ds
->const_state
->offsets
.primitive_param
;
1329 tu6_emit_const(cs
, CP_LOAD_STATE6_GEOM
, ds_base
, SB6_DS_SHADER
, 0,
1330 ARRAY_SIZE(ds_params
), ds_params
);
1334 const struct ir3_shader_variant
*prev
= ds
? ds
: vs
;
1335 uint32_t gs_params
[4] = {
1336 prev
->output_size
* num_vertices
* 4, /* gs primitive stride */
1337 prev
->output_size
* 4, /* gs vertex stride */
1341 uint32_t gs_base
= gs
->const_state
->offsets
.primitive_param
;
1342 tu6_emit_const(cs
, CP_LOAD_STATE6_GEOM
, gs_base
, SB6_GS_SHADER
, 0,
1343 ARRAY_SIZE(gs_params
), gs_params
);
1348 tu6_emit_program(struct tu_cs
*cs
,
1349 struct tu_pipeline_builder
*builder
,
1352 const struct ir3_shader_variant
*vs
= builder
->variants
[MESA_SHADER_VERTEX
];
1353 const struct ir3_shader_variant
*bs
= builder
->binning_variant
;
1354 const struct ir3_shader_variant
*hs
= builder
->variants
[MESA_SHADER_TESS_CTRL
];
1355 const struct ir3_shader_variant
*ds
= builder
->variants
[MESA_SHADER_TESS_EVAL
];
1356 const struct ir3_shader_variant
*gs
= builder
->variants
[MESA_SHADER_GEOMETRY
];
1357 const struct ir3_shader_variant
*fs
= builder
->variants
[MESA_SHADER_FRAGMENT
];
1358 gl_shader_stage stage
= MESA_SHADER_VERTEX
;
1360 STATIC_ASSERT(MESA_SHADER_VERTEX
== 0);
1362 tu_cs_emit_pkt4(cs
, REG_A6XX_HLSQ_UPDATE_CNTL
, 1);
1363 tu_cs_emit(cs
, 0xff); /* XXX */
1365 /* Don't use the binning pass variant when GS is present because we don't
1366 * support compiling correct binning pass variants with GS.
1368 if (binning_pass
&& !gs
) {
1370 tu6_emit_xs_config(cs
, stage
, bs
, builder
->binning_vs_iova
);
1374 for (; stage
< ARRAY_SIZE(builder
->shaders
); stage
++) {
1375 const struct ir3_shader_variant
*xs
= builder
->variants
[stage
];
1377 if (stage
== MESA_SHADER_FRAGMENT
&& binning_pass
)
1380 tu6_emit_xs_config(cs
, stage
, xs
, builder
->shader_iova
[stage
]);
1383 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_HS_UNKNOWN_A831
, 1);
1386 tu6_emit_vpc(cs
, vs
, hs
, ds
, gs
, fs
);
1387 tu6_emit_vpc_varying_modes(cs
, fs
);
1390 tu6_emit_fs_inputs(cs
, fs
);
1391 tu6_emit_fs_outputs(cs
, fs
, builder
->color_attachment_count
,
1392 builder
->use_dual_src_blend
,
1393 builder
->render_components
,
1394 builder
->depth_attachment_format
== VK_FORMAT_S8_UINT
);
1396 /* TODO: check if these can be skipped if fs is disabled */
1397 struct ir3_shader_variant dummy_variant
= {};
1398 tu6_emit_fs_inputs(cs
, &dummy_variant
);
1399 tu6_emit_fs_outputs(cs
, &dummy_variant
, builder
->color_attachment_count
,
1400 builder
->use_dual_src_blend
,
1401 builder
->render_components
,
1402 builder
->depth_attachment_format
== VK_FORMAT_S8_UINT
);
1406 uint32_t cps_per_patch
= builder
->create_info
->pTessellationState
?
1407 builder
->create_info
->pTessellationState
->patchControlPoints
: 0;
1408 tu6_emit_geom_tess_consts(cs
, vs
, hs
, ds
, gs
, cps_per_patch
);
1413 tu6_emit_vertex_input(struct tu_cs
*cs
,
1414 const struct ir3_shader_variant
*vs
,
1415 const VkPipelineVertexInputStateCreateInfo
*info
,
1416 uint32_t *bindings_used
)
1418 uint32_t vfd_decode_idx
= 0;
1419 uint32_t binding_instanced
= 0; /* bitmask of instanced bindings */
1420 uint32_t step_rate
[MAX_VBS
];
1422 for (uint32_t i
= 0; i
< info
->vertexBindingDescriptionCount
; i
++) {
1423 const VkVertexInputBindingDescription
*binding
=
1424 &info
->pVertexBindingDescriptions
[i
];
1427 A6XX_VFD_FETCH_STRIDE(binding
->binding
, binding
->stride
));
1429 if (binding
->inputRate
== VK_VERTEX_INPUT_RATE_INSTANCE
)
1430 binding_instanced
|= 1 << binding
->binding
;
1432 *bindings_used
|= 1 << binding
->binding
;
1433 step_rate
[binding
->binding
] = 1;
1436 const VkPipelineVertexInputDivisorStateCreateInfoEXT
*div_state
=
1437 vk_find_struct_const(info
->pNext
, PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT
);
1439 for (uint32_t i
= 0; i
< div_state
->vertexBindingDivisorCount
; i
++) {
1440 const VkVertexInputBindingDivisorDescriptionEXT
*desc
=
1441 &div_state
->pVertexBindingDivisors
[i
];
1442 step_rate
[desc
->binding
] = desc
->divisor
;
1446 /* TODO: emit all VFD_DECODE/VFD_DEST_CNTL in same (two) pkt4 */
1448 for (uint32_t i
= 0; i
< info
->vertexAttributeDescriptionCount
; i
++) {
1449 const VkVertexInputAttributeDescription
*attr
=
1450 &info
->pVertexAttributeDescriptions
[i
];
1453 assert(*bindings_used
& BIT(attr
->binding
));
1455 for (input_idx
= 0; input_idx
< vs
->inputs_count
; input_idx
++) {
1456 if ((vs
->inputs
[input_idx
].slot
- VERT_ATTRIB_GENERIC0
) == attr
->location
)
1460 /* attribute not used, skip it */
1461 if (input_idx
== vs
->inputs_count
)
1464 const struct tu_native_format format
= tu6_format_vtx(attr
->format
);
1466 A6XX_VFD_DECODE_INSTR(vfd_decode_idx
,
1467 .idx
= attr
->binding
,
1468 .offset
= attr
->offset
,
1469 .instanced
= binding_instanced
& (1 << attr
->binding
),
1470 .format
= format
.fmt
,
1471 .swap
= format
.swap
,
1473 ._float
= !vk_format_is_int(attr
->format
)),
1474 A6XX_VFD_DECODE_STEP_RATE(vfd_decode_idx
, step_rate
[attr
->binding
]));
1477 A6XX_VFD_DEST_CNTL_INSTR(vfd_decode_idx
,
1478 .writemask
= vs
->inputs
[input_idx
].compmask
,
1479 .regid
= vs
->inputs
[input_idx
].regid
));
1486 .fetch_cnt
= vfd_decode_idx
, /* decode_cnt for binning pass ? */
1487 .decode_cnt
= vfd_decode_idx
));
1491 tu6_guardband_adj(uint32_t v
)
1494 return (uint32_t)(511.0 - 65.0 * (log2(v
) - 8.0));
1500 tu6_emit_viewport(struct tu_cs
*cs
, const VkViewport
*viewport
)
1504 scales
[0] = viewport
->width
/ 2.0f
;
1505 scales
[1] = viewport
->height
/ 2.0f
;
1506 scales
[2] = viewport
->maxDepth
- viewport
->minDepth
;
1507 offsets
[0] = viewport
->x
+ scales
[0];
1508 offsets
[1] = viewport
->y
+ scales
[1];
1509 offsets
[2] = viewport
->minDepth
;
1513 min
.x
= (int32_t) viewport
->x
;
1514 max
.x
= (int32_t) ceilf(viewport
->x
+ viewport
->width
);
1515 if (viewport
->height
>= 0.0f
) {
1516 min
.y
= (int32_t) viewport
->y
;
1517 max
.y
= (int32_t) ceilf(viewport
->y
+ viewport
->height
);
1519 min
.y
= (int32_t)(viewport
->y
+ viewport
->height
);
1520 max
.y
= (int32_t) ceilf(viewport
->y
);
1522 /* the spec allows viewport->height to be 0.0f */
1525 assert(min
.x
>= 0 && min
.x
< max
.x
);
1526 assert(min
.y
>= 0 && min
.y
< max
.y
);
1528 VkExtent2D guardband_adj
;
1529 guardband_adj
.width
= tu6_guardband_adj(max
.x
- min
.x
);
1530 guardband_adj
.height
= tu6_guardband_adj(max
.y
- min
.y
);
1532 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_CL_VPORT_XOFFSET_0
, 6);
1533 tu_cs_emit(cs
, A6XX_GRAS_CL_VPORT_XOFFSET_0(offsets
[0]).value
);
1534 tu_cs_emit(cs
, A6XX_GRAS_CL_VPORT_XSCALE_0(scales
[0]).value
);
1535 tu_cs_emit(cs
, A6XX_GRAS_CL_VPORT_YOFFSET_0(offsets
[1]).value
);
1536 tu_cs_emit(cs
, A6XX_GRAS_CL_VPORT_YSCALE_0(scales
[1]).value
);
1537 tu_cs_emit(cs
, A6XX_GRAS_CL_VPORT_ZOFFSET_0(offsets
[2]).value
);
1538 tu_cs_emit(cs
, A6XX_GRAS_CL_VPORT_ZSCALE_0(scales
[2]).value
);
1540 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0
, 2);
1541 tu_cs_emit(cs
, A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_X(min
.x
) |
1542 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_Y(min
.y
));
1543 tu_cs_emit(cs
, A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_X(max
.x
- 1) |
1544 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_Y(max
.y
- 1));
1546 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ
, 1);
1548 A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ_HORZ(guardband_adj
.width
) |
1549 A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ_VERT(guardband_adj
.height
));
1551 float z_clamp_min
= MIN2(viewport
->minDepth
, viewport
->maxDepth
);
1552 float z_clamp_max
= MAX2(viewport
->minDepth
, viewport
->maxDepth
);
1555 A6XX_GRAS_CL_Z_CLAMP_MIN(z_clamp_min
),
1556 A6XX_GRAS_CL_Z_CLAMP_MAX(z_clamp_max
));
1559 A6XX_RB_Z_CLAMP_MIN(z_clamp_min
),
1560 A6XX_RB_Z_CLAMP_MAX(z_clamp_max
));
1564 tu6_emit_scissor(struct tu_cs
*cs
, const VkRect2D
*scissor
)
1566 VkOffset2D min
= scissor
->offset
;
1568 scissor
->offset
.x
+ scissor
->extent
.width
,
1569 scissor
->offset
.y
+ scissor
->extent
.height
,
1572 /* special case for empty scissor with max == 0 to avoid overflow */
1578 /* avoid overflow with large scissor
1579 * note the max will be limited to min - 1, so that empty scissor works
1581 uint32_t scissor_max
= BITFIELD_MASK(15);
1582 min
.x
= MIN2(scissor_max
, min
.x
);
1583 min
.y
= MIN2(scissor_max
, min
.y
);
1584 max
.x
= MIN2(scissor_max
, max
.x
);
1585 max
.y
= MIN2(scissor_max
, max
.y
);
1588 A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0(.x
= min
.x
, .y
= min
.y
),
1589 A6XX_GRAS_SC_SCREEN_SCISSOR_BR_0(.x
= max
.x
- 1, .y
= max
.y
- 1));
1593 tu6_emit_sample_locations(struct tu_cs
*cs
, const VkSampleLocationsInfoEXT
*samp_loc
)
1596 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_SAMPLE_CONFIG
, 1);
1599 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_SAMPLE_CONFIG
, 1);
1602 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_TP_SAMPLE_CONFIG
, 1);
1607 assert(samp_loc
->sampleLocationsPerPixel
== samp_loc
->sampleLocationsCount
);
1608 assert(samp_loc
->sampleLocationGridSize
.width
== 1);
1609 assert(samp_loc
->sampleLocationGridSize
.height
== 1);
1611 uint32_t sample_config
=
1612 A6XX_RB_SAMPLE_CONFIG_LOCATION_ENABLE
;
1613 uint32_t sample_locations
= 0;
1614 for (uint32_t i
= 0; i
< samp_loc
->sampleLocationsCount
; i
++) {
1616 (A6XX_RB_SAMPLE_LOCATION_0_SAMPLE_0_X(samp_loc
->pSampleLocations
[i
].x
) |
1617 A6XX_RB_SAMPLE_LOCATION_0_SAMPLE_0_Y(samp_loc
->pSampleLocations
[i
].y
)) << i
*8;
1620 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_SAMPLE_CONFIG
, 2);
1621 tu_cs_emit(cs
, sample_config
);
1622 tu_cs_emit(cs
, sample_locations
);
1624 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_SAMPLE_CONFIG
, 2);
1625 tu_cs_emit(cs
, sample_config
);
1626 tu_cs_emit(cs
, sample_locations
);
1628 tu_cs_emit_pkt4(cs
, REG_A6XX_SP_TP_SAMPLE_CONFIG
, 2);
1629 tu_cs_emit(cs
, sample_config
);
1630 tu_cs_emit(cs
, sample_locations
);
1634 tu6_gras_su_cntl(const VkPipelineRasterizationStateCreateInfo
*rast_info
,
1635 VkSampleCountFlagBits samples
)
1637 uint32_t gras_su_cntl
= 0;
1639 if (rast_info
->cullMode
& VK_CULL_MODE_FRONT_BIT
)
1640 gras_su_cntl
|= A6XX_GRAS_SU_CNTL_CULL_FRONT
;
1641 if (rast_info
->cullMode
& VK_CULL_MODE_BACK_BIT
)
1642 gras_su_cntl
|= A6XX_GRAS_SU_CNTL_CULL_BACK
;
1644 if (rast_info
->frontFace
== VK_FRONT_FACE_CLOCKWISE
)
1645 gras_su_cntl
|= A6XX_GRAS_SU_CNTL_FRONT_CW
;
1647 /* don't set A6XX_GRAS_SU_CNTL_LINEHALFWIDTH */
1649 if (rast_info
->depthBiasEnable
)
1650 gras_su_cntl
|= A6XX_GRAS_SU_CNTL_POLY_OFFSET
;
1652 if (samples
> VK_SAMPLE_COUNT_1_BIT
)
1653 gras_su_cntl
|= A6XX_GRAS_SU_CNTL_MSAA_ENABLE
;
1655 return gras_su_cntl
;
1659 tu6_emit_depth_bias(struct tu_cs
*cs
,
1660 float constant_factor
,
1664 tu_cs_emit_pkt4(cs
, REG_A6XX_GRAS_SU_POLY_OFFSET_SCALE
, 3);
1665 tu_cs_emit(cs
, A6XX_GRAS_SU_POLY_OFFSET_SCALE(slope_factor
).value
);
1666 tu_cs_emit(cs
, A6XX_GRAS_SU_POLY_OFFSET_OFFSET(constant_factor
).value
);
1667 tu_cs_emit(cs
, A6XX_GRAS_SU_POLY_OFFSET_OFFSET_CLAMP(clamp
).value
);
1671 tu6_emit_depth_control(struct tu_cs
*cs
,
1672 const VkPipelineDepthStencilStateCreateInfo
*ds_info
,
1673 const VkPipelineRasterizationStateCreateInfo
*rast_info
)
1675 uint32_t rb_depth_cntl
= 0;
1676 if (ds_info
->depthTestEnable
) {
1678 A6XX_RB_DEPTH_CNTL_Z_ENABLE
|
1679 A6XX_RB_DEPTH_CNTL_ZFUNC(tu6_compare_func(ds_info
->depthCompareOp
)) |
1680 A6XX_RB_DEPTH_CNTL_Z_TEST_ENABLE
; /* TODO: don't set for ALWAYS/NEVER */
1682 if (rast_info
->depthClampEnable
)
1683 rb_depth_cntl
|= A6XX_RB_DEPTH_CNTL_Z_CLAMP_ENABLE
;
1685 if (ds_info
->depthWriteEnable
)
1686 rb_depth_cntl
|= A6XX_RB_DEPTH_CNTL_Z_WRITE_ENABLE
;
1689 if (ds_info
->depthBoundsTestEnable
)
1690 rb_depth_cntl
|= A6XX_RB_DEPTH_CNTL_Z_BOUNDS_ENABLE
| A6XX_RB_DEPTH_CNTL_Z_TEST_ENABLE
;
1692 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_DEPTH_CNTL
, 1);
1693 tu_cs_emit(cs
, rb_depth_cntl
);
1697 tu6_emit_stencil_control(struct tu_cs
*cs
,
1698 const VkPipelineDepthStencilStateCreateInfo
*ds_info
)
1700 uint32_t rb_stencil_control
= 0;
1701 if (ds_info
->stencilTestEnable
) {
1702 const VkStencilOpState
*front
= &ds_info
->front
;
1703 const VkStencilOpState
*back
= &ds_info
->back
;
1704 rb_stencil_control
|=
1705 A6XX_RB_STENCIL_CONTROL_STENCIL_ENABLE
|
1706 A6XX_RB_STENCIL_CONTROL_STENCIL_ENABLE_BF
|
1707 A6XX_RB_STENCIL_CONTROL_STENCIL_READ
|
1708 A6XX_RB_STENCIL_CONTROL_FUNC(tu6_compare_func(front
->compareOp
)) |
1709 A6XX_RB_STENCIL_CONTROL_FAIL(tu6_stencil_op(front
->failOp
)) |
1710 A6XX_RB_STENCIL_CONTROL_ZPASS(tu6_stencil_op(front
->passOp
)) |
1711 A6XX_RB_STENCIL_CONTROL_ZFAIL(tu6_stencil_op(front
->depthFailOp
)) |
1712 A6XX_RB_STENCIL_CONTROL_FUNC_BF(tu6_compare_func(back
->compareOp
)) |
1713 A6XX_RB_STENCIL_CONTROL_FAIL_BF(tu6_stencil_op(back
->failOp
)) |
1714 A6XX_RB_STENCIL_CONTROL_ZPASS_BF(tu6_stencil_op(back
->passOp
)) |
1715 A6XX_RB_STENCIL_CONTROL_ZFAIL_BF(tu6_stencil_op(back
->depthFailOp
));
1718 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_STENCIL_CONTROL
, 1);
1719 tu_cs_emit(cs
, rb_stencil_control
);
1723 tu6_rb_mrt_blend_control(const VkPipelineColorBlendAttachmentState
*att
,
1726 const enum a3xx_rb_blend_opcode color_op
= tu6_blend_op(att
->colorBlendOp
);
1727 const enum adreno_rb_blend_factor src_color_factor
= tu6_blend_factor(
1728 has_alpha
? att
->srcColorBlendFactor
1729 : tu_blend_factor_no_dst_alpha(att
->srcColorBlendFactor
));
1730 const enum adreno_rb_blend_factor dst_color_factor
= tu6_blend_factor(
1731 has_alpha
? att
->dstColorBlendFactor
1732 : tu_blend_factor_no_dst_alpha(att
->dstColorBlendFactor
));
1733 const enum a3xx_rb_blend_opcode alpha_op
= tu6_blend_op(att
->alphaBlendOp
);
1734 const enum adreno_rb_blend_factor src_alpha_factor
=
1735 tu6_blend_factor(att
->srcAlphaBlendFactor
);
1736 const enum adreno_rb_blend_factor dst_alpha_factor
=
1737 tu6_blend_factor(att
->dstAlphaBlendFactor
);
1739 return A6XX_RB_MRT_BLEND_CONTROL_RGB_SRC_FACTOR(src_color_factor
) |
1740 A6XX_RB_MRT_BLEND_CONTROL_RGB_BLEND_OPCODE(color_op
) |
1741 A6XX_RB_MRT_BLEND_CONTROL_RGB_DEST_FACTOR(dst_color_factor
) |
1742 A6XX_RB_MRT_BLEND_CONTROL_ALPHA_SRC_FACTOR(src_alpha_factor
) |
1743 A6XX_RB_MRT_BLEND_CONTROL_ALPHA_BLEND_OPCODE(alpha_op
) |
1744 A6XX_RB_MRT_BLEND_CONTROL_ALPHA_DEST_FACTOR(dst_alpha_factor
);
1748 tu6_rb_mrt_control(const VkPipelineColorBlendAttachmentState
*att
,
1749 uint32_t rb_mrt_control_rop
,
1753 uint32_t rb_mrt_control
=
1754 A6XX_RB_MRT_CONTROL_COMPONENT_ENABLE(att
->colorWriteMask
);
1756 /* ignore blending and logic op for integer attachments */
1758 rb_mrt_control
|= A6XX_RB_MRT_CONTROL_ROP_CODE(ROP_COPY
);
1759 return rb_mrt_control
;
1762 rb_mrt_control
|= rb_mrt_control_rop
;
1764 if (att
->blendEnable
) {
1765 rb_mrt_control
|= A6XX_RB_MRT_CONTROL_BLEND
;
1768 rb_mrt_control
|= A6XX_RB_MRT_CONTROL_BLEND2
;
1771 return rb_mrt_control
;
1775 tu6_emit_rb_mrt_controls(struct tu_cs
*cs
,
1776 const VkPipelineColorBlendStateCreateInfo
*blend_info
,
1777 const VkFormat attachment_formats
[MAX_RTS
],
1778 uint32_t *blend_enable_mask
)
1780 *blend_enable_mask
= 0;
1782 bool rop_reads_dst
= false;
1783 uint32_t rb_mrt_control_rop
= 0;
1784 if (blend_info
->logicOpEnable
) {
1785 rop_reads_dst
= tu_logic_op_reads_dst(blend_info
->logicOp
);
1786 rb_mrt_control_rop
=
1787 A6XX_RB_MRT_CONTROL_ROP_ENABLE
|
1788 A6XX_RB_MRT_CONTROL_ROP_CODE(tu6_rop(blend_info
->logicOp
));
1791 for (uint32_t i
= 0; i
< blend_info
->attachmentCount
; i
++) {
1792 const VkPipelineColorBlendAttachmentState
*att
=
1793 &blend_info
->pAttachments
[i
];
1794 const VkFormat format
= attachment_formats
[i
];
1796 uint32_t rb_mrt_control
= 0;
1797 uint32_t rb_mrt_blend_control
= 0;
1798 if (format
!= VK_FORMAT_UNDEFINED
) {
1799 const bool is_int
= vk_format_is_int(format
);
1800 const bool has_alpha
= vk_format_has_alpha(format
);
1803 tu6_rb_mrt_control(att
, rb_mrt_control_rop
, is_int
, has_alpha
);
1804 rb_mrt_blend_control
= tu6_rb_mrt_blend_control(att
, has_alpha
);
1806 if (att
->blendEnable
|| rop_reads_dst
)
1807 *blend_enable_mask
|= 1 << i
;
1810 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_MRT_CONTROL(i
), 2);
1811 tu_cs_emit(cs
, rb_mrt_control
);
1812 tu_cs_emit(cs
, rb_mrt_blend_control
);
1817 tu6_emit_blend_control(struct tu_cs
*cs
,
1818 uint32_t blend_enable_mask
,
1819 bool dual_src_blend
,
1820 const VkPipelineMultisampleStateCreateInfo
*msaa_info
)
1822 const uint32_t sample_mask
=
1823 msaa_info
->pSampleMask
? (*msaa_info
->pSampleMask
& 0xffff)
1824 : ((1 << msaa_info
->rasterizationSamples
) - 1);
1827 A6XX_SP_BLEND_CNTL(.enabled
= blend_enable_mask
,
1828 .dual_color_in_enable
= dual_src_blend
,
1829 .alpha_to_coverage
= msaa_info
->alphaToCoverageEnable
,
1832 /* set A6XX_RB_BLEND_CNTL_INDEPENDENT_BLEND only when enabled? */
1834 A6XX_RB_BLEND_CNTL(.enable_blend
= blend_enable_mask
,
1835 .independent_blend
= true,
1836 .sample_mask
= sample_mask
,
1837 .dual_color_in_enable
= dual_src_blend
,
1838 .alpha_to_coverage
= msaa_info
->alphaToCoverageEnable
,
1839 .alpha_to_one
= msaa_info
->alphaToOneEnable
));
1843 tu_pipeline_allocate_cs(struct tu_device
*dev
,
1844 struct tu_pipeline
*pipeline
,
1845 struct tu_pipeline_builder
*builder
,
1846 struct ir3_shader_variant
*compute
)
1848 uint32_t size
= 2048 + tu6_load_state_size(pipeline
->layout
, compute
);
1850 /* graphics case: */
1852 for (uint32_t i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
1853 if (builder
->variants
[i
])
1854 size
+= builder
->variants
[i
]->info
.sizedwords
;
1857 size
+= builder
->binning_variant
->info
.sizedwords
;
1859 size
+= compute
->info
.sizedwords
;
1862 tu_cs_init(&pipeline
->cs
, dev
, TU_CS_MODE_SUB_STREAM
, size
);
1864 /* Reserve the space now such that tu_cs_begin_sub_stream never fails. Note
1865 * that LOAD_STATE can potentially take up a large amount of space so we
1866 * calculate its size explicitly.
1868 return tu_cs_reserve_space(&pipeline
->cs
, size
);
1872 tu_pipeline_shader_key_init(struct ir3_shader_key
*key
,
1873 const VkGraphicsPipelineCreateInfo
*pipeline_info
)
1875 for (uint32_t i
= 0; i
< pipeline_info
->stageCount
; i
++) {
1876 if (pipeline_info
->pStages
[i
].stage
== VK_SHADER_STAGE_GEOMETRY_BIT
) {
1882 if (pipeline_info
->pRasterizationState
->rasterizerDiscardEnable
)
1885 const VkPipelineMultisampleStateCreateInfo
*msaa_info
= pipeline_info
->pMultisampleState
;
1886 const struct VkPipelineSampleLocationsStateCreateInfoEXT
*sample_locations
=
1887 vk_find_struct_const(msaa_info
->pNext
, PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT
);
1888 if (msaa_info
->rasterizationSamples
> 1 ||
1889 /* also set msaa key when sample location is not the default
1890 * since this affects varying interpolation */
1891 (sample_locations
&& sample_locations
->sampleLocationsEnable
)) {
1895 /* note: not actually used by ir3, just checked in tu6_emit_fs_inputs */
1896 if (msaa_info
->sampleShadingEnable
)
1897 key
->sample_shading
= true;
1899 /* We set this after we compile to NIR because we need the prim mode */
1900 key
->tessellation
= IR3_TESS_NONE
;
1904 tu6_get_tessmode(struct tu_shader
* shader
)
1906 uint32_t primitive_mode
= shader
->ir3_shader
->nir
->info
.tess
.primitive_mode
;
1907 switch (primitive_mode
) {
1909 return IR3_TESS_ISOLINES
;
1911 return IR3_TESS_TRIANGLES
;
1913 return IR3_TESS_QUADS
;
1915 return IR3_TESS_NONE
;
1917 unreachable("bad tessmode");
1922 tu_upload_variant(struct tu_pipeline
*pipeline
,
1923 const struct ir3_shader_variant
*variant
)
1925 struct tu_cs_memory memory
;
1930 /* this expects to get enough alignment because shaders are allocated first
1931 * and sizedwords is always aligned correctly
1932 * note: an assert in tu6_emit_xs_config validates the alignment
1934 tu_cs_alloc(&pipeline
->cs
, variant
->info
.sizedwords
, 1, &memory
);
1936 memcpy(memory
.map
, variant
->bin
, sizeof(uint32_t) * variant
->info
.sizedwords
);
1941 tu_pipeline_builder_compile_shaders(struct tu_pipeline_builder
*builder
,
1942 struct tu_pipeline
*pipeline
)
1944 const struct ir3_compiler
*compiler
= builder
->device
->compiler
;
1945 const VkPipelineShaderStageCreateInfo
*stage_infos
[MESA_SHADER_STAGES
] = {
1948 for (uint32_t i
= 0; i
< builder
->create_info
->stageCount
; i
++) {
1949 gl_shader_stage stage
=
1950 vk_to_mesa_shader_stage(builder
->create_info
->pStages
[i
].stage
);
1951 stage_infos
[stage
] = &builder
->create_info
->pStages
[i
];
1954 struct ir3_shader_key key
= {};
1955 tu_pipeline_shader_key_init(&key
, builder
->create_info
);
1957 for (gl_shader_stage stage
= MESA_SHADER_VERTEX
;
1958 stage
< MESA_SHADER_STAGES
; stage
++) {
1959 const VkPipelineShaderStageCreateInfo
*stage_info
= stage_infos
[stage
];
1960 if (!stage_info
&& stage
!= MESA_SHADER_FRAGMENT
)
1963 struct tu_shader
*shader
=
1964 tu_shader_create(builder
->device
, stage
, stage_info
, builder
->layout
,
1967 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1969 /* In SPIR-V generated from GLSL, the primitive mode is specified in the
1970 * tessellation evaluation shader, but in SPIR-V generated from HLSL,
1971 * the mode is specified in the tessellation control shader. */
1972 if ((stage
== MESA_SHADER_TESS_EVAL
|| stage
== MESA_SHADER_TESS_CTRL
) &&
1973 key
.tessellation
== IR3_TESS_NONE
) {
1974 key
.tessellation
= tu6_get_tessmode(shader
);
1977 builder
->shaders
[stage
] = shader
;
1980 pipeline
->tess
.patch_type
= key
.tessellation
;
1982 for (gl_shader_stage stage
= MESA_SHADER_VERTEX
;
1983 stage
< MESA_SHADER_STAGES
; stage
++) {
1984 if (!builder
->shaders
[stage
])
1988 builder
->variants
[stage
] =
1989 ir3_shader_get_variant(builder
->shaders
[stage
]->ir3_shader
,
1990 &key
, false, &created
);
1991 if (!builder
->variants
[stage
])
1992 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1995 uint32_t safe_constlens
= ir3_trim_constlen(builder
->variants
, compiler
);
1997 key
.safe_constlen
= true;
1999 for (gl_shader_stage stage
= MESA_SHADER_VERTEX
;
2000 stage
< MESA_SHADER_STAGES
; stage
++) {
2001 if (!builder
->shaders
[stage
])
2004 if (safe_constlens
& (1 << stage
)) {
2006 builder
->variants
[stage
] =
2007 ir3_shader_get_variant(builder
->shaders
[stage
]->ir3_shader
,
2008 &key
, false, &created
);
2009 if (!builder
->variants
[stage
])
2010 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2014 const struct tu_shader
*vs
= builder
->shaders
[MESA_SHADER_VERTEX
];
2015 struct ir3_shader_variant
*variant
;
2017 if (vs
->ir3_shader
->stream_output
.num_outputs
||
2018 !ir3_has_binning_vs(&key
)) {
2019 variant
= builder
->variants
[MESA_SHADER_VERTEX
];
2022 key
.safe_constlen
= !!(safe_constlens
& (1 << MESA_SHADER_VERTEX
));
2023 variant
= ir3_shader_get_variant(vs
->ir3_shader
, &key
,
2026 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2029 builder
->binning_variant
= variant
;
2031 if (builder
->shaders
[MESA_SHADER_TESS_CTRL
]) {
2032 struct ir3_shader
*hs
=
2033 builder
->shaders
[MESA_SHADER_TESS_CTRL
]->ir3_shader
;
2034 assert(hs
->type
!= MESA_SHADER_NONE
);
2036 /* Calculate and store the per-vertex and per-patch HS-output sizes. */
2037 uint32_t per_vertex_output_size
= 0;
2038 uint32_t per_patch_output_size
= 0;
2039 nir_foreach_variable (output
, &hs
->nir
->outputs
) {
2040 switch (output
->data
.location
) {
2041 case VARYING_SLOT_TESS_LEVEL_OUTER
:
2042 case VARYING_SLOT_TESS_LEVEL_INNER
:
2045 uint32_t size
= glsl_count_attribute_slots(output
->type
, false) * 4;
2046 if (output
->data
.patch
)
2047 per_patch_output_size
+= size
;
2049 per_vertex_output_size
+= size
;
2051 pipeline
->tess
.per_vertex_output_size
= per_vertex_output_size
;
2052 pipeline
->tess
.per_patch_output_size
= per_patch_output_size
;
2059 tu_pipeline_builder_parse_dynamic(struct tu_pipeline_builder
*builder
,
2060 struct tu_pipeline
*pipeline
)
2062 const VkPipelineDynamicStateCreateInfo
*dynamic_info
=
2063 builder
->create_info
->pDynamicState
;
2068 for (uint32_t i
= 0; i
< dynamic_info
->dynamicStateCount
; i
++) {
2069 VkDynamicState state
= dynamic_info
->pDynamicStates
[i
];
2071 case VK_DYNAMIC_STATE_VIEWPORT
... VK_DYNAMIC_STATE_STENCIL_REFERENCE
:
2072 pipeline
->dynamic_state_mask
|= BIT(state
);
2074 case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT
:
2075 pipeline
->dynamic_state_mask
|= BIT(TU_DYNAMIC_STATE_SAMPLE_LOCATIONS
);
2078 assert(!"unsupported dynamic state");
2085 tu_pipeline_set_linkage(struct tu_program_descriptor_linkage
*link
,
2086 struct tu_shader
*shader
,
2087 struct ir3_shader_variant
*v
)
2089 link
->const_state
= *ir3_const_state(v
);
2090 link
->constlen
= v
->constlen
;
2091 link
->push_consts
= shader
->push_consts
;
2095 tu_pipeline_builder_parse_shader_stages(struct tu_pipeline_builder
*builder
,
2096 struct tu_pipeline
*pipeline
)
2098 struct tu_cs prog_cs
;
2099 tu_cs_begin_sub_stream(&pipeline
->cs
, 512, &prog_cs
);
2100 tu6_emit_program(&prog_cs
, builder
, false);
2101 pipeline
->program
.state_ib
= tu_cs_end_sub_stream(&pipeline
->cs
, &prog_cs
);
2103 tu_cs_begin_sub_stream(&pipeline
->cs
, 512, &prog_cs
);
2104 tu6_emit_program(&prog_cs
, builder
, true);
2105 pipeline
->program
.binning_state_ib
= tu_cs_end_sub_stream(&pipeline
->cs
, &prog_cs
);
2107 VkShaderStageFlags stages
= 0;
2108 for (unsigned i
= 0; i
< builder
->create_info
->stageCount
; i
++) {
2109 stages
|= builder
->create_info
->pStages
[i
].stage
;
2111 pipeline
->active_stages
= stages
;
2113 uint32_t desc_sets
= 0;
2114 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
2115 if (!builder
->shaders
[i
])
2118 tu_pipeline_set_linkage(&pipeline
->program
.link
[i
],
2119 builder
->shaders
[i
],
2120 builder
->variants
[i
]);
2121 desc_sets
|= builder
->shaders
[i
]->active_desc_sets
;
2123 pipeline
->active_desc_sets
= desc_sets
;
2127 tu_pipeline_builder_parse_vertex_input(struct tu_pipeline_builder
*builder
,
2128 struct tu_pipeline
*pipeline
)
2130 const VkPipelineVertexInputStateCreateInfo
*vi_info
=
2131 builder
->create_info
->pVertexInputState
;
2132 const struct ir3_shader_variant
*vs
= builder
->variants
[MESA_SHADER_VERTEX
];
2133 const struct ir3_shader_variant
*bs
= builder
->binning_variant
;
2136 tu_cs_begin_sub_stream(&pipeline
->cs
,
2137 MAX_VERTEX_ATTRIBS
* 7 + 2, &vi_cs
);
2138 tu6_emit_vertex_input(&vi_cs
, vs
, vi_info
,
2139 &pipeline
->vi
.bindings_used
);
2140 pipeline
->vi
.state_ib
= tu_cs_end_sub_stream(&pipeline
->cs
, &vi_cs
);
2143 tu_cs_begin_sub_stream(&pipeline
->cs
,
2144 MAX_VERTEX_ATTRIBS
* 7 + 2, &vi_cs
);
2145 tu6_emit_vertex_input(
2146 &vi_cs
, bs
, vi_info
, &pipeline
->vi
.bindings_used
);
2147 pipeline
->vi
.binning_state_ib
=
2148 tu_cs_end_sub_stream(&pipeline
->cs
, &vi_cs
);
2153 tu_pipeline_builder_parse_input_assembly(struct tu_pipeline_builder
*builder
,
2154 struct tu_pipeline
*pipeline
)
2156 const VkPipelineInputAssemblyStateCreateInfo
*ia_info
=
2157 builder
->create_info
->pInputAssemblyState
;
2159 pipeline
->ia
.primtype
= tu6_primtype(ia_info
->topology
);
2160 pipeline
->ia
.primitive_restart
= ia_info
->primitiveRestartEnable
;
2164 tu_pipeline_static_state(struct tu_pipeline
*pipeline
, struct tu_cs
*cs
,
2165 uint32_t id
, uint32_t size
)
2167 struct tu_cs_memory memory
;
2169 if (pipeline
->dynamic_state_mask
& BIT(id
))
2172 /* TODO: share this logc with tu_cmd_dynamic_state */
2173 tu_cs_alloc(&pipeline
->cs
, size
, 1, &memory
);
2174 tu_cs_init_external(cs
, memory
.map
, memory
.map
+ size
);
2176 tu_cs_reserve_space(cs
, size
);
2178 assert(id
< ARRAY_SIZE(pipeline
->dynamic_state
));
2179 pipeline
->dynamic_state
[id
].iova
= memory
.iova
;
2180 pipeline
->dynamic_state
[id
].size
= size
;
2185 tu_pipeline_builder_parse_tessellation(struct tu_pipeline_builder
*builder
,
2186 struct tu_pipeline
*pipeline
)
2188 const VkPipelineTessellationStateCreateInfo
*tess_info
=
2189 builder
->create_info
->pTessellationState
;
2194 assert(pipeline
->ia
.primtype
== DI_PT_PATCHES0
);
2195 assert(tess_info
->patchControlPoints
<= 32);
2196 pipeline
->ia
.primtype
+= tess_info
->patchControlPoints
;
2197 const VkPipelineTessellationDomainOriginStateCreateInfo
*domain_info
=
2198 vk_find_struct_const(tess_info
->pNext
, PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO
);
2199 pipeline
->tess
.upper_left_domain_origin
= !domain_info
||
2200 domain_info
->domainOrigin
== VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT
;
2201 const struct ir3_shader_variant
*hs
= builder
->variants
[MESA_SHADER_TESS_CTRL
];
2202 const struct ir3_shader_variant
*ds
= builder
->variants
[MESA_SHADER_TESS_EVAL
];
2203 pipeline
->tess
.hs_bo_regid
= hs
->const_state
->offsets
.primitive_param
+ 1;
2204 pipeline
->tess
.ds_bo_regid
= ds
->const_state
->offsets
.primitive_param
+ 1;
2208 tu_pipeline_builder_parse_viewport(struct tu_pipeline_builder
*builder
,
2209 struct tu_pipeline
*pipeline
)
2213 * pViewportState is a pointer to an instance of the
2214 * VkPipelineViewportStateCreateInfo structure, and is ignored if the
2215 * pipeline has rasterization disabled."
2217 * We leave the relevant registers stale in that case.
2219 if (builder
->rasterizer_discard
)
2222 const VkPipelineViewportStateCreateInfo
*vp_info
=
2223 builder
->create_info
->pViewportState
;
2227 if (tu_pipeline_static_state(pipeline
, &cs
, VK_DYNAMIC_STATE_VIEWPORT
, 18))
2228 tu6_emit_viewport(&cs
, vp_info
->pViewports
);
2230 if (tu_pipeline_static_state(pipeline
, &cs
, VK_DYNAMIC_STATE_SCISSOR
, 3))
2231 tu6_emit_scissor(&cs
, vp_info
->pScissors
);
2235 tu_pipeline_builder_parse_rasterization(struct tu_pipeline_builder
*builder
,
2236 struct tu_pipeline
*pipeline
)
2238 const VkPipelineRasterizationStateCreateInfo
*rast_info
=
2239 builder
->create_info
->pRasterizationState
;
2241 enum a6xx_polygon_mode mode
= tu6_polygon_mode(rast_info
->polygonMode
);
2244 tu_cs_begin_sub_stream(&pipeline
->cs
, 11, &cs
);
2246 tu_cs_emit_regs(&cs
,
2248 .znear_clip_disable
= rast_info
->depthClampEnable
,
2249 .zfar_clip_disable
= rast_info
->depthClampEnable
,
2250 .unk5
= rast_info
->depthClampEnable
,
2251 .zero_gb_scale_z
= 1,
2252 .vp_clip_code_ignore
= 1));
2254 tu_cs_emit_regs(&cs
,
2255 A6XX_VPC_POLYGON_MODE(.mode
= mode
));
2257 tu_cs_emit_regs(&cs
,
2258 A6XX_PC_POLYGON_MODE(.mode
= mode
));
2260 /* move to hw ctx init? */
2261 tu_cs_emit_regs(&cs
, A6XX_GRAS_UNKNOWN_8001());
2262 tu_cs_emit_regs(&cs
,
2263 A6XX_GRAS_SU_POINT_MINMAX(.min
= 1.0f
/ 16.0f
, .max
= 4092.0f
),
2264 A6XX_GRAS_SU_POINT_SIZE(1.0f
));
2266 pipeline
->rast
.state_ib
= tu_cs_end_sub_stream(&pipeline
->cs
, &cs
);
2268 pipeline
->gras_su_cntl
=
2269 tu6_gras_su_cntl(rast_info
, builder
->samples
);
2271 if (tu_pipeline_static_state(pipeline
, &cs
, VK_DYNAMIC_STATE_LINE_WIDTH
, 2)) {
2272 pipeline
->gras_su_cntl
|=
2273 A6XX_GRAS_SU_CNTL_LINEHALFWIDTH(rast_info
->lineWidth
/ 2.0f
);
2274 tu_cs_emit_regs(&cs
, A6XX_GRAS_SU_CNTL(.dword
= pipeline
->gras_su_cntl
));
2277 if (tu_pipeline_static_state(pipeline
, &cs
, VK_DYNAMIC_STATE_DEPTH_BIAS
, 4)) {
2278 tu6_emit_depth_bias(&cs
, rast_info
->depthBiasConstantFactor
,
2279 rast_info
->depthBiasClamp
,
2280 rast_info
->depthBiasSlopeFactor
);
2286 tu_pipeline_builder_parse_depth_stencil(struct tu_pipeline_builder
*builder
,
2287 struct tu_pipeline
*pipeline
)
2291 * pDepthStencilState is a pointer to an instance of the
2292 * VkPipelineDepthStencilStateCreateInfo structure, and is ignored if
2293 * the pipeline has rasterization disabled or if the subpass of the
2294 * render pass the pipeline is created against does not use a
2295 * depth/stencil attachment.
2297 * Disable both depth and stencil tests if there is no ds attachment,
2298 * Disable depth test if ds attachment is S8_UINT, since S8_UINT defines
2299 * only the separate stencil attachment
2301 static const VkPipelineDepthStencilStateCreateInfo dummy_ds_info
;
2302 const VkPipelineDepthStencilStateCreateInfo
*ds_info
=
2303 builder
->depth_attachment_format
!= VK_FORMAT_UNDEFINED
2304 ? builder
->create_info
->pDepthStencilState
2306 const VkPipelineDepthStencilStateCreateInfo
*ds_info_depth
=
2307 builder
->depth_attachment_format
!= VK_FORMAT_S8_UINT
2308 ? ds_info
: &dummy_ds_info
;
2311 tu_cs_begin_sub_stream(&pipeline
->cs
, 6, &cs
);
2313 /* move to hw ctx init? */
2314 tu_cs_emit_regs(&cs
, A6XX_RB_ALPHA_CONTROL());
2315 tu6_emit_depth_control(&cs
, ds_info_depth
,
2316 builder
->create_info
->pRasterizationState
);
2317 tu6_emit_stencil_control(&cs
, ds_info
);
2319 pipeline
->ds
.state_ib
= tu_cs_end_sub_stream(&pipeline
->cs
, &cs
);
2321 if (tu_pipeline_static_state(pipeline
, &cs
, VK_DYNAMIC_STATE_DEPTH_BOUNDS
, 3)) {
2322 tu_cs_emit_regs(&cs
,
2323 A6XX_RB_Z_BOUNDS_MIN(ds_info
->minDepthBounds
),
2324 A6XX_RB_Z_BOUNDS_MAX(ds_info
->maxDepthBounds
));
2327 if (tu_pipeline_static_state(pipeline
, &cs
, VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
, 2)) {
2328 tu_cs_emit_regs(&cs
, A6XX_RB_STENCILMASK(.mask
= ds_info
->front
.compareMask
& 0xff,
2329 .bfmask
= ds_info
->back
.compareMask
& 0xff));
2332 if (tu_pipeline_static_state(pipeline
, &cs
, VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
, 2)) {
2333 tu_cs_emit_regs(&cs
, A6XX_RB_STENCILWRMASK(.wrmask
= ds_info
->front
.writeMask
& 0xff,
2334 .bfwrmask
= ds_info
->back
.writeMask
& 0xff));
2337 if (tu_pipeline_static_state(pipeline
, &cs
, VK_DYNAMIC_STATE_STENCIL_REFERENCE
, 2)) {
2338 tu_cs_emit_regs(&cs
, A6XX_RB_STENCILREF(.ref
= ds_info
->front
.reference
& 0xff,
2339 .bfref
= ds_info
->back
.reference
& 0xff));
2344 tu_pipeline_builder_parse_multisample_and_color_blend(
2345 struct tu_pipeline_builder
*builder
, struct tu_pipeline
*pipeline
)
2349 * pMultisampleState is a pointer to an instance of the
2350 * VkPipelineMultisampleStateCreateInfo, and is ignored if the pipeline
2351 * has rasterization disabled.
2355 * pColorBlendState is a pointer to an instance of the
2356 * VkPipelineColorBlendStateCreateInfo structure, and is ignored if the
2357 * pipeline has rasterization disabled or if the subpass of the render
2358 * pass the pipeline is created against does not use any color
2361 * We leave the relevant registers stale when rasterization is disabled.
2363 if (builder
->rasterizer_discard
)
2366 static const VkPipelineColorBlendStateCreateInfo dummy_blend_info
;
2367 const VkPipelineMultisampleStateCreateInfo
*msaa_info
=
2368 builder
->create_info
->pMultisampleState
;
2369 const VkPipelineColorBlendStateCreateInfo
*blend_info
=
2370 builder
->use_color_attachments
? builder
->create_info
->pColorBlendState
2371 : &dummy_blend_info
;
2374 tu_cs_begin_sub_stream(&pipeline
->cs
, MAX_RTS
* 3 + 4, &cs
);
2376 uint32_t blend_enable_mask
;
2377 tu6_emit_rb_mrt_controls(&cs
, blend_info
,
2378 builder
->color_attachment_formats
,
2379 &blend_enable_mask
);
2381 tu6_emit_blend_control(&cs
, blend_enable_mask
,
2382 builder
->use_dual_src_blend
, msaa_info
);
2384 pipeline
->blend
.state_ib
= tu_cs_end_sub_stream(&pipeline
->cs
, &cs
);
2386 if (tu_pipeline_static_state(pipeline
, &cs
, VK_DYNAMIC_STATE_BLEND_CONSTANTS
, 5)) {
2387 tu_cs_emit_pkt4(&cs
, REG_A6XX_RB_BLEND_RED_F32
, 4);
2388 tu_cs_emit_array(&cs
, (const uint32_t *) blend_info
->blendConstants
, 4);
2391 const struct VkPipelineSampleLocationsStateCreateInfoEXT
*sample_locations
=
2392 vk_find_struct_const(msaa_info
->pNext
, PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT
);
2393 const VkSampleLocationsInfoEXT
*samp_loc
= NULL
;
2395 if (sample_locations
&& sample_locations
->sampleLocationsEnable
)
2396 samp_loc
= &sample_locations
->sampleLocationsInfo
;
2398 if (tu_pipeline_static_state(pipeline
, &cs
, TU_DYNAMIC_STATE_SAMPLE_LOCATIONS
,
2399 samp_loc
? 9 : 6)) {
2400 tu6_emit_sample_locations(&cs
, samp_loc
);
2405 tu_pipeline_finish(struct tu_pipeline
*pipeline
,
2406 struct tu_device
*dev
,
2407 const VkAllocationCallbacks
*alloc
)
2409 tu_cs_finish(&pipeline
->cs
);
2413 tu_pipeline_builder_build(struct tu_pipeline_builder
*builder
,
2414 struct tu_pipeline
**pipeline
)
2419 vk_zalloc2(&builder
->device
->alloc
, builder
->alloc
, sizeof(**pipeline
),
2420 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2422 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2424 (*pipeline
)->layout
= builder
->layout
;
2426 /* compile and upload shaders */
2427 result
= tu_pipeline_builder_compile_shaders(builder
, *pipeline
);
2428 if (result
!= VK_SUCCESS
) {
2429 vk_free2(&builder
->device
->alloc
, builder
->alloc
, *pipeline
);
2433 result
= tu_pipeline_allocate_cs(builder
->device
, *pipeline
, builder
, NULL
);
2434 if (result
!= VK_SUCCESS
) {
2435 vk_free2(&builder
->device
->alloc
, builder
->alloc
, *pipeline
);
2439 for (uint32_t i
= 0; i
< MESA_SHADER_STAGES
; i
++)
2440 builder
->shader_iova
[i
] = tu_upload_variant(*pipeline
, builder
->variants
[i
]);
2442 builder
->binning_vs_iova
=
2443 tu_upload_variant(*pipeline
, builder
->binning_variant
);
2445 tu_pipeline_builder_parse_dynamic(builder
, *pipeline
);
2446 tu_pipeline_builder_parse_shader_stages(builder
, *pipeline
);
2447 tu_pipeline_builder_parse_vertex_input(builder
, *pipeline
);
2448 tu_pipeline_builder_parse_input_assembly(builder
, *pipeline
);
2449 tu_pipeline_builder_parse_tessellation(builder
, *pipeline
);
2450 tu_pipeline_builder_parse_viewport(builder
, *pipeline
);
2451 tu_pipeline_builder_parse_rasterization(builder
, *pipeline
);
2452 tu_pipeline_builder_parse_depth_stencil(builder
, *pipeline
);
2453 tu_pipeline_builder_parse_multisample_and_color_blend(builder
, *pipeline
);
2454 tu6_emit_load_state(*pipeline
, false);
2456 /* we should have reserved enough space upfront such that the CS never
2459 assert((*pipeline
)->cs
.bo_count
== 1);
2465 tu_pipeline_builder_finish(struct tu_pipeline_builder
*builder
)
2467 for (uint32_t i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
2468 if (!builder
->shaders
[i
])
2470 tu_shader_destroy(builder
->device
, builder
->shaders
[i
], builder
->alloc
);
2475 tu_pipeline_builder_init_graphics(
2476 struct tu_pipeline_builder
*builder
,
2477 struct tu_device
*dev
,
2478 struct tu_pipeline_cache
*cache
,
2479 const VkGraphicsPipelineCreateInfo
*create_info
,
2480 const VkAllocationCallbacks
*alloc
)
2482 TU_FROM_HANDLE(tu_pipeline_layout
, layout
, create_info
->layout
);
2484 *builder
= (struct tu_pipeline_builder
) {
2487 .create_info
= create_info
,
2492 builder
->rasterizer_discard
=
2493 create_info
->pRasterizationState
->rasterizerDiscardEnable
;
2495 if (builder
->rasterizer_discard
) {
2496 builder
->samples
= VK_SAMPLE_COUNT_1_BIT
;
2498 builder
->samples
= create_info
->pMultisampleState
->rasterizationSamples
;
2500 const struct tu_render_pass
*pass
=
2501 tu_render_pass_from_handle(create_info
->renderPass
);
2502 const struct tu_subpass
*subpass
=
2503 &pass
->subpasses
[create_info
->subpass
];
2505 const uint32_t a
= subpass
->depth_stencil_attachment
.attachment
;
2506 builder
->depth_attachment_format
= (a
!= VK_ATTACHMENT_UNUSED
) ?
2507 pass
->attachments
[a
].format
: VK_FORMAT_UNDEFINED
;
2509 assert(subpass
->color_count
== 0 ||
2510 !create_info
->pColorBlendState
||
2511 subpass
->color_count
== create_info
->pColorBlendState
->attachmentCount
);
2512 builder
->color_attachment_count
= subpass
->color_count
;
2513 for (uint32_t i
= 0; i
< subpass
->color_count
; i
++) {
2514 const uint32_t a
= subpass
->color_attachments
[i
].attachment
;
2515 if (a
== VK_ATTACHMENT_UNUSED
)
2518 builder
->color_attachment_formats
[i
] = pass
->attachments
[a
].format
;
2519 builder
->use_color_attachments
= true;
2520 builder
->render_components
|= 0xf << (i
* 4);
2523 if (tu_blend_state_is_dual_src(create_info
->pColorBlendState
)) {
2524 builder
->color_attachment_count
++;
2525 builder
->use_dual_src_blend
= true;
2526 /* dual source blending has an extra fs output in the 2nd slot */
2527 if (subpass
->color_attachments
[0].attachment
!= VK_ATTACHMENT_UNUSED
)
2528 builder
->render_components
|= 0xf << 4;
2534 tu_graphics_pipeline_create(VkDevice device
,
2535 VkPipelineCache pipelineCache
,
2536 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
2537 const VkAllocationCallbacks
*pAllocator
,
2538 VkPipeline
*pPipeline
)
2540 TU_FROM_HANDLE(tu_device
, dev
, device
);
2541 TU_FROM_HANDLE(tu_pipeline_cache
, cache
, pipelineCache
);
2543 struct tu_pipeline_builder builder
;
2544 tu_pipeline_builder_init_graphics(&builder
, dev
, cache
,
2545 pCreateInfo
, pAllocator
);
2547 struct tu_pipeline
*pipeline
= NULL
;
2548 VkResult result
= tu_pipeline_builder_build(&builder
, &pipeline
);
2549 tu_pipeline_builder_finish(&builder
);
2551 if (result
== VK_SUCCESS
)
2552 *pPipeline
= tu_pipeline_to_handle(pipeline
);
2554 *pPipeline
= VK_NULL_HANDLE
;
2560 tu_CreateGraphicsPipelines(VkDevice device
,
2561 VkPipelineCache pipelineCache
,
2563 const VkGraphicsPipelineCreateInfo
*pCreateInfos
,
2564 const VkAllocationCallbacks
*pAllocator
,
2565 VkPipeline
*pPipelines
)
2567 VkResult final_result
= VK_SUCCESS
;
2569 for (uint32_t i
= 0; i
< count
; i
++) {
2570 VkResult result
= tu_graphics_pipeline_create(device
, pipelineCache
,
2571 &pCreateInfos
[i
], pAllocator
,
2574 if (result
!= VK_SUCCESS
)
2575 final_result
= result
;
2578 return final_result
;
2582 tu_compute_pipeline_create(VkDevice device
,
2583 VkPipelineCache _cache
,
2584 const VkComputePipelineCreateInfo
*pCreateInfo
,
2585 const VkAllocationCallbacks
*pAllocator
,
2586 VkPipeline
*pPipeline
)
2588 TU_FROM_HANDLE(tu_device
, dev
, device
);
2589 TU_FROM_HANDLE(tu_pipeline_layout
, layout
, pCreateInfo
->layout
);
2590 const VkPipelineShaderStageCreateInfo
*stage_info
= &pCreateInfo
->stage
;
2593 struct tu_pipeline
*pipeline
;
2595 *pPipeline
= VK_NULL_HANDLE
;
2598 vk_zalloc2(&dev
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
2599 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2601 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2603 pipeline
->layout
= layout
;
2605 struct ir3_shader_key key
= {};
2607 struct tu_shader
*shader
=
2608 tu_shader_create(dev
, MESA_SHADER_COMPUTE
, stage_info
, layout
, pAllocator
);
2610 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
2615 struct ir3_shader_variant
*v
=
2616 ir3_shader_get_variant(shader
->ir3_shader
, &key
, false, &created
);
2618 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
2622 tu_pipeline_set_linkage(&pipeline
->program
.link
[MESA_SHADER_COMPUTE
],
2625 result
= tu_pipeline_allocate_cs(dev
, pipeline
, NULL
, v
);
2626 if (result
!= VK_SUCCESS
)
2629 uint64_t shader_iova
= tu_upload_variant(pipeline
, v
);
2631 for (int i
= 0; i
< 3; i
++)
2632 pipeline
->compute
.local_size
[i
] = v
->shader
->nir
->info
.cs
.local_size
[i
];
2634 struct tu_cs prog_cs
;
2635 tu_cs_begin_sub_stream(&pipeline
->cs
, 512, &prog_cs
);
2636 tu6_emit_cs_config(&prog_cs
, shader
, v
, shader_iova
);
2637 pipeline
->program
.state_ib
= tu_cs_end_sub_stream(&pipeline
->cs
, &prog_cs
);
2639 tu6_emit_load_state(pipeline
, true);
2641 *pPipeline
= tu_pipeline_to_handle(pipeline
);
2646 tu_shader_destroy(dev
, shader
, pAllocator
);
2648 vk_free2(&dev
->alloc
, pAllocator
, pipeline
);
2654 tu_CreateComputePipelines(VkDevice device
,
2655 VkPipelineCache pipelineCache
,
2657 const VkComputePipelineCreateInfo
*pCreateInfos
,
2658 const VkAllocationCallbacks
*pAllocator
,
2659 VkPipeline
*pPipelines
)
2661 VkResult final_result
= VK_SUCCESS
;
2663 for (uint32_t i
= 0; i
< count
; i
++) {
2664 VkResult result
= tu_compute_pipeline_create(device
, pipelineCache
,
2666 pAllocator
, &pPipelines
[i
]);
2667 if (result
!= VK_SUCCESS
)
2668 final_result
= result
;
2671 return final_result
;
2675 tu_DestroyPipeline(VkDevice _device
,
2676 VkPipeline _pipeline
,
2677 const VkAllocationCallbacks
*pAllocator
)
2679 TU_FROM_HANDLE(tu_device
, dev
, _device
);
2680 TU_FROM_HANDLE(tu_pipeline
, pipeline
, _pipeline
);
2685 tu_pipeline_finish(pipeline
, dev
, pAllocator
);
2686 vk_free2(&dev
->alloc
, pAllocator
, pipeline
);