2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 #include "anv_private.h"
28 #include "vk_format_info.h"
31 #include "common/gen_l3_config.h"
32 #include "genxml/gen_macros.h"
33 #include "genxml/genX_pack.h"
36 emit_lrm(struct anv_batch
*batch
,
37 uint32_t reg
, struct anv_bo
*bo
, uint32_t offset
)
39 anv_batch_emit(batch
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
40 lrm
.RegisterAddress
= reg
;
41 lrm
.MemoryAddress
= (struct anv_address
) { bo
, offset
};
46 emit_lri(struct anv_batch
*batch
, uint32_t reg
, uint32_t imm
)
48 anv_batch_emit(batch
, GENX(MI_LOAD_REGISTER_IMM
), lri
) {
49 lri
.RegisterOffset
= reg
;
54 #if GEN_IS_HASWELL || GEN_GEN >= 8
56 emit_lrr(struct anv_batch
*batch
, uint32_t dst
, uint32_t src
)
58 anv_batch_emit(batch
, GENX(MI_LOAD_REGISTER_REG
), lrr
) {
59 lrr
.SourceRegisterAddress
= src
;
60 lrr
.DestinationRegisterAddress
= dst
;
66 genX(cmd_buffer_emit_state_base_address
)(struct anv_cmd_buffer
*cmd_buffer
)
68 struct anv_device
*device
= cmd_buffer
->device
;
70 /* Emit a render target cache flush.
72 * This isn't documented anywhere in the PRM. However, it seems to be
73 * necessary prior to changing the surface state base adress. Without
74 * this, we get GPU hangs when using multi-level command buffers which
75 * clear depth, reset state base address, and then go render stuff.
77 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pc
) {
78 pc
.DCFlushEnable
= true;
79 pc
.RenderTargetCacheFlushEnable
= true;
80 pc
.CommandStreamerStallEnable
= true;
83 anv_batch_emit(&cmd_buffer
->batch
, GENX(STATE_BASE_ADDRESS
), sba
) {
84 sba
.GeneralStateBaseAddress
= (struct anv_address
) { NULL
, 0 };
85 sba
.GeneralStateMemoryObjectControlState
= GENX(MOCS
);
86 sba
.GeneralStateBaseAddressModifyEnable
= true;
88 sba
.SurfaceStateBaseAddress
=
89 anv_cmd_buffer_surface_base_address(cmd_buffer
);
90 sba
.SurfaceStateMemoryObjectControlState
= GENX(MOCS
);
91 sba
.SurfaceStateBaseAddressModifyEnable
= true;
93 sba
.DynamicStateBaseAddress
=
94 (struct anv_address
) { &device
->dynamic_state_pool
.block_pool
.bo
, 0 };
95 sba
.DynamicStateMemoryObjectControlState
= GENX(MOCS
);
96 sba
.DynamicStateBaseAddressModifyEnable
= true;
98 sba
.IndirectObjectBaseAddress
= (struct anv_address
) { NULL
, 0 };
99 sba
.IndirectObjectMemoryObjectControlState
= GENX(MOCS
);
100 sba
.IndirectObjectBaseAddressModifyEnable
= true;
102 sba
.InstructionBaseAddress
=
103 (struct anv_address
) { &device
->instruction_state_pool
.block_pool
.bo
, 0 };
104 sba
.InstructionMemoryObjectControlState
= GENX(MOCS
);
105 sba
.InstructionBaseAddressModifyEnable
= true;
108 /* Broadwell requires that we specify a buffer size for a bunch of
109 * these fields. However, since we will be growing the BO's live, we
110 * just set them all to the maximum.
112 sba
.GeneralStateBufferSize
= 0xfffff;
113 sba
.GeneralStateBufferSizeModifyEnable
= true;
114 sba
.DynamicStateBufferSize
= 0xfffff;
115 sba
.DynamicStateBufferSizeModifyEnable
= true;
116 sba
.IndirectObjectBufferSize
= 0xfffff;
117 sba
.IndirectObjectBufferSizeModifyEnable
= true;
118 sba
.InstructionBufferSize
= 0xfffff;
119 sba
.InstructionBuffersizeModifyEnable
= true;
123 /* After re-setting the surface state base address, we have to do some
124 * cache flusing so that the sampler engine will pick up the new
125 * SURFACE_STATE objects and binding tables. From the Broadwell PRM,
126 * Shared Function > 3D Sampler > State > State Caching (page 96):
128 * Coherency with system memory in the state cache, like the texture
129 * cache is handled partially by software. It is expected that the
130 * command stream or shader will issue Cache Flush operation or
131 * Cache_Flush sampler message to ensure that the L1 cache remains
132 * coherent with system memory.
136 * Whenever the value of the Dynamic_State_Base_Addr,
137 * Surface_State_Base_Addr are altered, the L1 state cache must be
138 * invalidated to ensure the new surface or sampler state is fetched
139 * from system memory.
141 * The PIPE_CONTROL command has a "State Cache Invalidation Enable" bit
142 * which, according the PIPE_CONTROL instruction documentation in the
145 * Setting this bit is independent of any other bit in this packet.
146 * This bit controls the invalidation of the L1 and L2 state caches
147 * at the top of the pipe i.e. at the parsing time.
149 * Unfortunately, experimentation seems to indicate that state cache
150 * invalidation through a PIPE_CONTROL does nothing whatsoever in
151 * regards to surface state and binding tables. In stead, it seems that
152 * invalidating the texture cache is what is actually needed.
154 * XXX: As far as we have been able to determine through
155 * experimentation, shows that flush the texture cache appears to be
156 * sufficient. The theory here is that all of the sampling/rendering
157 * units cache the binding table in the texture cache. However, we have
158 * yet to be able to actually confirm this.
160 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pc
) {
161 pc
.TextureCacheInvalidationEnable
= true;
162 pc
.ConstantCacheInvalidationEnable
= true;
163 pc
.StateCacheInvalidationEnable
= true;
168 add_surface_state_reloc(struct anv_cmd_buffer
*cmd_buffer
,
169 struct anv_state state
,
170 struct anv_bo
*bo
, uint32_t offset
)
172 const struct isl_device
*isl_dev
= &cmd_buffer
->device
->isl_dev
;
175 anv_reloc_list_add(&cmd_buffer
->surface_relocs
, &cmd_buffer
->pool
->alloc
,
176 state
.offset
+ isl_dev
->ss
.addr_offset
, bo
, offset
);
177 if (result
!= VK_SUCCESS
)
178 anv_batch_set_error(&cmd_buffer
->batch
, result
);
182 add_image_relocs(struct anv_cmd_buffer
* const cmd_buffer
,
183 const struct anv_image
* const image
,
184 const VkImageAspectFlags aspect_mask
,
185 const enum isl_aux_usage aux_usage
,
186 const struct anv_state state
)
188 const struct isl_device
*isl_dev
= &cmd_buffer
->device
->isl_dev
;
189 const uint32_t surf_offset
= image
->offset
+
190 anv_image_get_surface_for_aspect_mask(image
, aspect_mask
)->offset
;
192 add_surface_state_reloc(cmd_buffer
, state
, image
->bo
, surf_offset
);
194 if (aux_usage
!= ISL_AUX_USAGE_NONE
) {
195 uint32_t aux_offset
= image
->offset
+ image
->aux_surface
.offset
;
197 /* On gen7 and prior, the bottom 12 bits of the MCS base address are
198 * used to store other information. This should be ok, however, because
199 * surface buffer addresses are always 4K page alinged.
201 assert((aux_offset
& 0xfff) == 0);
202 uint32_t *aux_addr_dw
= state
.map
+ isl_dev
->ss
.aux_addr_offset
;
203 aux_offset
+= *aux_addr_dw
& 0xfff;
206 anv_reloc_list_add(&cmd_buffer
->surface_relocs
,
207 &cmd_buffer
->pool
->alloc
,
208 state
.offset
+ isl_dev
->ss
.aux_addr_offset
,
209 image
->bo
, aux_offset
);
210 if (result
!= VK_SUCCESS
)
211 anv_batch_set_error(&cmd_buffer
->batch
, result
);
216 color_is_zero_one(VkClearColorValue value
, enum isl_format format
)
218 if (isl_format_has_int_channel(format
)) {
219 for (unsigned i
= 0; i
< 4; i
++) {
220 if (value
.int32
[i
] != 0 && value
.int32
[i
] != 1)
224 for (unsigned i
= 0; i
< 4; i
++) {
225 if (value
.float32
[i
] != 0.0f
&& value
.float32
[i
] != 1.0f
)
234 color_attachment_compute_aux_usage(struct anv_device
* device
,
235 struct anv_cmd_state
* cmd_state
,
236 uint32_t att
, VkRect2D render_area
,
237 union isl_color_value
*fast_clear_color
)
239 struct anv_attachment_state
*att_state
= &cmd_state
->attachments
[att
];
240 struct anv_image_view
*iview
= cmd_state
->framebuffer
->attachments
[att
];
242 if (iview
->isl
.base_array_layer
>=
243 anv_image_aux_layers(iview
->image
, iview
->isl
.base_level
)) {
244 /* There is no aux buffer which corresponds to the level and layer(s)
247 att_state
->aux_usage
= ISL_AUX_USAGE_NONE
;
248 att_state
->input_aux_usage
= ISL_AUX_USAGE_NONE
;
249 att_state
->fast_clear
= false;
251 } else if (iview
->image
->aux_usage
== ISL_AUX_USAGE_MCS
) {
252 att_state
->aux_usage
= ISL_AUX_USAGE_MCS
;
253 att_state
->input_aux_usage
= ISL_AUX_USAGE_MCS
;
254 att_state
->fast_clear
= false;
258 assert(iview
->image
->aux_surface
.isl
.usage
& ISL_SURF_USAGE_CCS_BIT
);
260 att_state
->clear_color_is_zero_one
=
261 color_is_zero_one(att_state
->clear_value
.color
, iview
->isl
.format
);
262 att_state
->clear_color_is_zero
=
263 att_state
->clear_value
.color
.uint32
[0] == 0 &&
264 att_state
->clear_value
.color
.uint32
[1] == 0 &&
265 att_state
->clear_value
.color
.uint32
[2] == 0 &&
266 att_state
->clear_value
.color
.uint32
[3] == 0;
268 if (att_state
->pending_clear_aspects
== VK_IMAGE_ASPECT_COLOR_BIT
) {
269 /* Start off assuming fast clears are possible */
270 att_state
->fast_clear
= true;
272 /* Potentially, we could do partial fast-clears but doing so has crazy
273 * alignment restrictions. It's easier to just restrict to full size
274 * fast clears for now.
276 if (render_area
.offset
.x
!= 0 ||
277 render_area
.offset
.y
!= 0 ||
278 render_area
.extent
.width
!= iview
->extent
.width
||
279 render_area
.extent
.height
!= iview
->extent
.height
)
280 att_state
->fast_clear
= false;
282 /* On Broadwell and earlier, we can only handle 0/1 clear colors */
283 if (GEN_GEN
<= 8 && !att_state
->clear_color_is_zero_one
)
284 att_state
->fast_clear
= false;
286 /* We allow fast clears when all aux layers of the miplevel are targeted.
287 * See add_fast_clear_state_buffer() for more information. Also, because
288 * we only either do a fast clear or a normal clear and not both, this
289 * complies with the gen7 restriction of not fast-clearing multiple
292 if (cmd_state
->framebuffer
->layers
!=
293 anv_image_aux_layers(iview
->image
, iview
->isl
.base_level
)) {
294 att_state
->fast_clear
= false;
296 anv_perf_warn("Not fast-clearing the first layer in "
297 "a multi-layer fast clear.");
301 /* We only allow fast clears in the GENERAL layout if the auxiliary
302 * buffer is always enabled and the fast-clear value is all 0's. See
303 * add_fast_clear_state_buffer() for more information.
305 if (cmd_state
->pass
->attachments
[att
].first_subpass_layout
==
306 VK_IMAGE_LAYOUT_GENERAL
&&
307 (!att_state
->clear_color_is_zero
||
308 iview
->image
->aux_usage
== ISL_AUX_USAGE_NONE
)) {
309 att_state
->fast_clear
= false;
312 if (att_state
->fast_clear
) {
313 memcpy(fast_clear_color
->u32
, att_state
->clear_value
.color
.uint32
,
314 sizeof(fast_clear_color
->u32
));
317 att_state
->fast_clear
= false;
321 * TODO: Consider using a heuristic to determine if temporarily enabling
322 * CCS_E for this image view would be beneficial.
324 * While fast-clear resolves and partial resolves are fairly cheap in the
325 * case where you render to most of the pixels, full resolves are not
326 * because they potentially involve reading and writing the entire
327 * framebuffer. If we can't texture with CCS_E, we should leave it off and
328 * limit ourselves to fast clears.
330 if (iview
->image
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
331 att_state
->aux_usage
= ISL_AUX_USAGE_CCS_E
;
332 att_state
->input_aux_usage
= ISL_AUX_USAGE_CCS_E
;
334 att_state
->aux_usage
= ISL_AUX_USAGE_CCS_D
;
335 /* From the Sky Lake PRM, RENDER_SURFACE_STATE::AuxiliarySurfaceMode:
337 * "If Number of Multisamples is MULTISAMPLECOUNT_1, AUX_CCS_D
338 * setting is only allowed if Surface Format supported for Fast
339 * Clear. In addition, if the surface is bound to the sampling
340 * engine, Surface Format must be supported for Render Target
341 * Compression for surfaces bound to the sampling engine."
343 * In other words, we can only sample from a fast-cleared image if it
344 * also supports color compression.
346 if (isl_format_supports_ccs_e(&device
->info
, iview
->isl
.format
))
347 att_state
->input_aux_usage
= ISL_AUX_USAGE_CCS_D
;
349 att_state
->input_aux_usage
= ISL_AUX_USAGE_NONE
;
354 need_input_attachment_state(const struct anv_render_pass_attachment
*att
)
356 if (!(att
->usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
))
359 /* We only allocate input attachment states for color surfaces. Compression
360 * is not yet enabled for depth textures and stencil doesn't allow
361 * compression so we can just use the texture surface state from the view.
363 return vk_format_is_color(att
->format
);
366 /* Transitions a HiZ-enabled depth buffer from one layout to another. Unless
367 * the initial layout is undefined, the HiZ buffer and depth buffer will
368 * represent the same data at the end of this operation.
371 transition_depth_buffer(struct anv_cmd_buffer
*cmd_buffer
,
372 const struct anv_image
*image
,
373 VkImageLayout initial_layout
,
374 VkImageLayout final_layout
)
378 /* A transition is a no-op if HiZ is not enabled, or if the initial and
379 * final layouts are equal.
381 * The undefined layout indicates that the user doesn't care about the data
382 * that's currently in the buffer. Therefore, a data-preserving resolve
383 * operation is not needed.
385 if (image
->aux_usage
!= ISL_AUX_USAGE_HIZ
|| initial_layout
== final_layout
)
388 const bool hiz_enabled
= ISL_AUX_USAGE_HIZ
==
389 anv_layout_to_aux_usage(&cmd_buffer
->device
->info
, image
, image
->aspects
,
391 const bool enable_hiz
= ISL_AUX_USAGE_HIZ
==
392 anv_layout_to_aux_usage(&cmd_buffer
->device
->info
, image
, image
->aspects
,
395 enum blorp_hiz_op hiz_op
;
396 if (hiz_enabled
&& !enable_hiz
) {
397 hiz_op
= BLORP_HIZ_OP_DEPTH_RESOLVE
;
398 } else if (!hiz_enabled
&& enable_hiz
) {
399 hiz_op
= BLORP_HIZ_OP_HIZ_RESOLVE
;
401 assert(hiz_enabled
== enable_hiz
);
402 /* If the same buffer will be used, no resolves are necessary. */
403 hiz_op
= BLORP_HIZ_OP_NONE
;
406 if (hiz_op
!= BLORP_HIZ_OP_NONE
)
407 anv_gen8_hiz_op_resolve(cmd_buffer
, image
, hiz_op
);
410 static inline uint32_t
411 get_fast_clear_state_entry_offset(const struct anv_device
*device
,
412 const struct anv_image
*image
,
415 assert(device
&& image
);
416 assert(image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
);
417 assert(level
< anv_image_aux_levels(image
));
418 const uint32_t offset
= image
->offset
+ image
->aux_surface
.offset
+
419 image
->aux_surface
.isl
.size
+
420 anv_fast_clear_state_entry_size(device
) * level
;
421 assert(offset
< image
->offset
+ image
->size
);
426 init_fast_clear_state_entry(struct anv_cmd_buffer
*cmd_buffer
,
427 const struct anv_image
*image
,
430 assert(cmd_buffer
&& image
);
431 assert(image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
);
432 assert(level
< anv_image_aux_levels(image
));
434 /* The fast clear value dword(s) will be copied into a surface state object.
435 * Ensure that the restrictions of the fields in the dword(s) are followed.
437 * CCS buffers on SKL+ can have any value set for the clear colors.
439 if (image
->samples
== 1 && GEN_GEN
>= 9)
442 /* Other combinations of auxiliary buffers and platforms require specific
443 * values in the clear value dword(s).
446 for (; i
< cmd_buffer
->device
->isl_dev
.ss
.clear_value_size
; i
+= 4) {
447 anv_batch_emit(&cmd_buffer
->batch
, GENX(MI_STORE_DATA_IMM
), sdi
) {
448 const uint32_t entry_offset
=
449 get_fast_clear_state_entry_offset(cmd_buffer
->device
, image
, level
);
450 sdi
.Address
= (struct anv_address
) { image
->bo
, entry_offset
+ i
};
453 /* MCS buffers on SKL+ can only have 1/0 clear colors. */
454 assert(image
->aux_usage
== ISL_AUX_USAGE_MCS
);
455 sdi
.ImmediateData
= 0;
456 } else if (GEN_VERSIONx10
>= 75) {
457 /* Pre-SKL, the dword containing the clear values also contains
458 * other fields, so we need to initialize those fields to match the
459 * values that would be in a color attachment.
462 sdi
.ImmediateData
= ISL_CHANNEL_SELECT_RED
<< 25 |
463 ISL_CHANNEL_SELECT_GREEN
<< 22 |
464 ISL_CHANNEL_SELECT_BLUE
<< 19 |
465 ISL_CHANNEL_SELECT_ALPHA
<< 16;
466 } else if (GEN_VERSIONx10
== 70) {
467 /* On IVB, the dword containing the clear values also contains
468 * other fields that must be zero or can be zero.
471 sdi
.ImmediateData
= 0;
477 /* Copy the fast-clear value dword(s) between a surface state object and an
478 * image's fast clear state buffer.
481 genX(copy_fast_clear_dwords
)(struct anv_cmd_buffer
*cmd_buffer
,
482 struct anv_state surface_state
,
483 const struct anv_image
*image
,
485 bool copy_from_surface_state
)
487 assert(cmd_buffer
&& image
);
488 assert(image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
);
489 assert(level
< anv_image_aux_levels(image
));
491 struct anv_bo
*ss_bo
=
492 &cmd_buffer
->device
->surface_state_pool
.block_pool
.bo
;
493 uint32_t ss_clear_offset
= surface_state
.offset
+
494 cmd_buffer
->device
->isl_dev
.ss
.clear_value_offset
;
495 uint32_t entry_offset
=
496 get_fast_clear_state_entry_offset(cmd_buffer
->device
, image
, level
);
497 unsigned copy_size
= cmd_buffer
->device
->isl_dev
.ss
.clear_value_size
;
499 if (copy_from_surface_state
) {
500 genX(cmd_buffer_mi_memcpy
)(cmd_buffer
, image
->bo
, entry_offset
,
501 ss_bo
, ss_clear_offset
, copy_size
);
503 genX(cmd_buffer_mi_memcpy
)(cmd_buffer
, ss_bo
, ss_clear_offset
,
504 image
->bo
, entry_offset
, copy_size
);
506 /* Updating a surface state object may require that the state cache be
507 * invalidated. From the SKL PRM, Shared Functions -> State -> State
510 * Whenever the RENDER_SURFACE_STATE object in memory pointed to by
511 * the Binding Table Pointer (BTP) and Binding Table Index (BTI) is
512 * modified [...], the L1 state cache must be invalidated to ensure
513 * the new surface or sampler state is fetched from system memory.
515 * In testing, SKL doesn't actually seem to need this, but HSW does.
517 cmd_buffer
->state
.pending_pipe_bits
|=
518 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
;
523 transition_color_buffer(struct anv_cmd_buffer
*cmd_buffer
,
524 const struct anv_image
*image
,
525 const uint32_t base_level
, uint32_t level_count
,
526 uint32_t base_layer
, uint32_t layer_count
,
527 VkImageLayout initial_layout
,
528 VkImageLayout final_layout
)
530 assert(image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
);
532 if (image
->aux_surface
.isl
.size
== 0 ||
533 base_level
>= anv_image_aux_levels(image
))
536 if (initial_layout
!= VK_IMAGE_LAYOUT_UNDEFINED
&&
537 initial_layout
!= VK_IMAGE_LAYOUT_PREINITIALIZED
)
540 /* A transition of a 3D subresource works on all slices at a time. */
541 if (image
->type
== VK_IMAGE_TYPE_3D
) {
543 layer_count
= anv_minify(image
->extent
.depth
, base_level
);
546 /* We're interested in the subresource range subset that has aux data. */
547 level_count
= MIN2(level_count
, anv_image_aux_levels(image
) - base_level
);
549 /* We're transitioning from an undefined layout. We must ensure that the
550 * clear values buffer is filled with valid data.
552 for (unsigned l
= 0; l
< level_count
; l
++)
553 init_fast_clear_state_entry(cmd_buffer
, image
, base_level
+ l
);
555 if (image
->aux_usage
== ISL_AUX_USAGE_CCS_E
||
556 image
->aux_usage
== ISL_AUX_USAGE_MCS
) {
557 /* We're transitioning from an undefined layout so it doesn't really
558 * matter what data ends up in the color buffer. We do, however, need to
559 * ensure that the auxiliary surface is not in an undefined state. This
560 * state is possible for CCS buffers SKL+ and MCS buffers with certain
561 * sample counts that require certain bits to be reserved (2x and 8x).
562 * One easy way to get to a valid state is to fast-clear the specified
565 * Even for MCS buffers that have sample counts that don't require
566 * certain bits to be reserved (4x and 8x), we're unsure if the hardware
567 * will be okay with the sample mappings given by the undefined buffer.
568 * We don't have any data to show that this is a problem, but we want to
569 * avoid causing difficult-to-debug problems.
571 if (image
->samples
== 4 || image
->samples
== 16) {
572 anv_perf_warn("Doing a potentially unnecessary fast-clear to define "
576 anv_image_fast_clear(cmd_buffer
, image
, base_level
, level_count
,
577 base_layer
, layer_count
);
582 * Setup anv_cmd_state::attachments for vkCmdBeginRenderPass.
585 genX(cmd_buffer_setup_attachments
)(struct anv_cmd_buffer
*cmd_buffer
,
586 struct anv_render_pass
*pass
,
587 const VkRenderPassBeginInfo
*begin
)
589 const struct isl_device
*isl_dev
= &cmd_buffer
->device
->isl_dev
;
590 struct anv_cmd_state
*state
= &cmd_buffer
->state
;
592 vk_free(&cmd_buffer
->pool
->alloc
, state
->attachments
);
594 if (pass
->attachment_count
> 0) {
595 state
->attachments
= vk_alloc(&cmd_buffer
->pool
->alloc
,
596 pass
->attachment_count
*
597 sizeof(state
->attachments
[0]),
598 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
599 if (state
->attachments
== NULL
) {
600 /* Propagate VK_ERROR_OUT_OF_HOST_MEMORY to vkEndCommandBuffer */
601 return anv_batch_set_error(&cmd_buffer
->batch
,
602 VK_ERROR_OUT_OF_HOST_MEMORY
);
605 state
->attachments
= NULL
;
608 /* Reserve one for the NULL state. */
609 unsigned num_states
= 1;
610 for (uint32_t i
= 0; i
< pass
->attachment_count
; ++i
) {
611 if (vk_format_is_color(pass
->attachments
[i
].format
))
614 if (need_input_attachment_state(&pass
->attachments
[i
]))
618 const uint32_t ss_stride
= align_u32(isl_dev
->ss
.size
, isl_dev
->ss
.align
);
619 state
->render_pass_states
=
620 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
,
621 num_states
* ss_stride
, isl_dev
->ss
.align
);
623 struct anv_state next_state
= state
->render_pass_states
;
624 next_state
.alloc_size
= isl_dev
->ss
.size
;
626 state
->null_surface_state
= next_state
;
627 next_state
.offset
+= ss_stride
;
628 next_state
.map
+= ss_stride
;
630 for (uint32_t i
= 0; i
< pass
->attachment_count
; ++i
) {
631 if (vk_format_is_color(pass
->attachments
[i
].format
)) {
632 state
->attachments
[i
].color_rt_state
= next_state
;
633 next_state
.offset
+= ss_stride
;
634 next_state
.map
+= ss_stride
;
637 if (need_input_attachment_state(&pass
->attachments
[i
])) {
638 state
->attachments
[i
].input_att_state
= next_state
;
639 next_state
.offset
+= ss_stride
;
640 next_state
.map
+= ss_stride
;
643 assert(next_state
.offset
== state
->render_pass_states
.offset
+
644 state
->render_pass_states
.alloc_size
);
647 ANV_FROM_HANDLE(anv_framebuffer
, framebuffer
, begin
->framebuffer
);
648 assert(pass
->attachment_count
== framebuffer
->attachment_count
);
650 struct GENX(RENDER_SURFACE_STATE
) null_ss
= {
651 .SurfaceType
= SURFTYPE_NULL
,
652 .SurfaceArray
= framebuffer
->layers
> 0,
653 .SurfaceFormat
= ISL_FORMAT_R8G8B8A8_UNORM
,
657 .TiledSurface
= true,
659 .Width
= framebuffer
->width
- 1,
660 .Height
= framebuffer
->height
- 1,
661 .Depth
= framebuffer
->layers
- 1,
662 .RenderTargetViewExtent
= framebuffer
->layers
- 1,
664 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, state
->null_surface_state
.map
,
667 for (uint32_t i
= 0; i
< pass
->attachment_count
; ++i
) {
668 struct anv_render_pass_attachment
*att
= &pass
->attachments
[i
];
669 VkImageAspectFlags att_aspects
= vk_format_aspects(att
->format
);
670 VkImageAspectFlags clear_aspects
= 0;
672 if (att_aspects
== VK_IMAGE_ASPECT_COLOR_BIT
) {
673 /* color attachment */
674 if (att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
675 clear_aspects
|= VK_IMAGE_ASPECT_COLOR_BIT
;
678 /* depthstencil attachment */
679 if ((att_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) &&
680 att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
681 clear_aspects
|= VK_IMAGE_ASPECT_DEPTH_BIT
;
683 if ((att_aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) &&
684 att
->stencil_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
685 clear_aspects
|= VK_IMAGE_ASPECT_STENCIL_BIT
;
689 state
->attachments
[i
].current_layout
= att
->initial_layout
;
690 state
->attachments
[i
].pending_clear_aspects
= clear_aspects
;
692 state
->attachments
[i
].clear_value
= begin
->pClearValues
[i
];
694 struct anv_image_view
*iview
= framebuffer
->attachments
[i
];
695 anv_assert(iview
->vk_format
== att
->format
);
697 union isl_color_value clear_color
= { .u32
= { 0, } };
698 if (att_aspects
== VK_IMAGE_ASPECT_COLOR_BIT
) {
699 color_attachment_compute_aux_usage(cmd_buffer
->device
,
700 state
, i
, begin
->renderArea
,
703 struct isl_view view
= iview
->isl
;
704 view
.usage
|= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
705 view
.swizzle
= anv_swizzle_for_render(view
.swizzle
);
706 isl_surf_fill_state(isl_dev
,
707 state
->attachments
[i
].color_rt_state
.map
,
708 .surf
= &iview
->image
->color_surface
.isl
,
710 .aux_surf
= &iview
->image
->aux_surface
.isl
,
711 .aux_usage
= state
->attachments
[i
].aux_usage
,
712 .clear_color
= clear_color
,
713 .mocs
= cmd_buffer
->device
->default_mocs
);
715 add_image_relocs(cmd_buffer
, iview
->image
, iview
->aspect_mask
,
716 state
->attachments
[i
].aux_usage
,
717 state
->attachments
[i
].color_rt_state
);
719 /* This field will be initialized after the first subpass
722 state
->attachments
[i
].aux_usage
= ISL_AUX_USAGE_NONE
;
724 state
->attachments
[i
].input_aux_usage
= ISL_AUX_USAGE_NONE
;
727 if (need_input_attachment_state(&pass
->attachments
[i
])) {
728 struct isl_view view
= iview
->isl
;
729 view
.usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
730 isl_surf_fill_state(isl_dev
,
731 state
->attachments
[i
].input_att_state
.map
,
732 .surf
= &iview
->image
->color_surface
.isl
,
734 .aux_surf
= &iview
->image
->aux_surface
.isl
,
735 .aux_usage
= state
->attachments
[i
].input_aux_usage
,
736 .clear_color
= clear_color
,
737 .mocs
= cmd_buffer
->device
->default_mocs
);
739 add_image_relocs(cmd_buffer
, iview
->image
, iview
->aspect_mask
,
740 state
->attachments
[i
].input_aux_usage
,
741 state
->attachments
[i
].input_att_state
);
745 anv_state_flush(cmd_buffer
->device
, state
->render_pass_states
);
752 genX(BeginCommandBuffer
)(
753 VkCommandBuffer commandBuffer
,
754 const VkCommandBufferBeginInfo
* pBeginInfo
)
756 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
758 /* If this is the first vkBeginCommandBuffer, we must *initialize* the
759 * command buffer's state. Otherwise, we must *reset* its state. In both
762 * From the Vulkan 1.0 spec:
764 * If a command buffer is in the executable state and the command buffer
765 * was allocated from a command pool with the
766 * VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, then
767 * vkBeginCommandBuffer implicitly resets the command buffer, behaving
768 * as if vkResetCommandBuffer had been called with
769 * VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT not set. It then puts
770 * the command buffer in the recording state.
772 anv_cmd_buffer_reset(cmd_buffer
);
774 cmd_buffer
->usage_flags
= pBeginInfo
->flags
;
776 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_SECONDARY
||
777 !(cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
));
779 genX(cmd_buffer_emit_state_base_address
)(cmd_buffer
);
781 /* We sometimes store vertex data in the dynamic state buffer for blorp
782 * operations and our dynamic state stream may re-use data from previous
783 * command buffers. In order to prevent stale cache data, we flush the VF
784 * cache. We could do this on every blorp call but that's not really
785 * needed as all of the data will get written by the CPU prior to the GPU
786 * executing anything. The chances are fairly high that they will use
787 * blorp at least once per primary command buffer so it shouldn't be
790 if (cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
)
791 cmd_buffer
->state
.pending_pipe_bits
|= ANV_PIPE_VF_CACHE_INVALIDATE_BIT
;
793 VkResult result
= VK_SUCCESS
;
794 if (cmd_buffer
->usage_flags
&
795 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
) {
796 cmd_buffer
->state
.pass
=
797 anv_render_pass_from_handle(pBeginInfo
->pInheritanceInfo
->renderPass
);
798 cmd_buffer
->state
.subpass
=
799 &cmd_buffer
->state
.pass
->subpasses
[pBeginInfo
->pInheritanceInfo
->subpass
];
800 cmd_buffer
->state
.framebuffer
= NULL
;
802 result
= genX(cmd_buffer_setup_attachments
)(cmd_buffer
,
803 cmd_buffer
->state
.pass
, NULL
);
805 cmd_buffer
->state
.dirty
|= ANV_CMD_DIRTY_RENDER_TARGETS
;
812 genX(EndCommandBuffer
)(
813 VkCommandBuffer commandBuffer
)
815 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
817 if (anv_batch_has_error(&cmd_buffer
->batch
))
818 return cmd_buffer
->batch
.status
;
820 /* We want every command buffer to start with the PMA fix in a known state,
821 * so we disable it at the end of the command buffer.
823 genX(cmd_buffer_enable_pma_fix
)(cmd_buffer
, false);
825 genX(cmd_buffer_apply_pipe_flushes
)(cmd_buffer
);
827 anv_cmd_buffer_end_batch_buffer(cmd_buffer
);
833 genX(CmdExecuteCommands
)(
834 VkCommandBuffer commandBuffer
,
835 uint32_t commandBufferCount
,
836 const VkCommandBuffer
* pCmdBuffers
)
838 ANV_FROM_HANDLE(anv_cmd_buffer
, primary
, commandBuffer
);
840 assert(primary
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
842 if (anv_batch_has_error(&primary
->batch
))
845 /* The secondary command buffers will assume that the PMA fix is disabled
846 * when they begin executing. Make sure this is true.
848 genX(cmd_buffer_enable_pma_fix
)(primary
, false);
850 /* The secondary command buffer doesn't know which textures etc. have been
851 * flushed prior to their execution. Apply those flushes now.
853 genX(cmd_buffer_apply_pipe_flushes
)(primary
);
855 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
856 ANV_FROM_HANDLE(anv_cmd_buffer
, secondary
, pCmdBuffers
[i
]);
858 assert(secondary
->level
== VK_COMMAND_BUFFER_LEVEL_SECONDARY
);
859 assert(!anv_batch_has_error(&secondary
->batch
));
861 if (secondary
->usage_flags
&
862 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
) {
863 /* If we're continuing a render pass from the primary, we need to
864 * copy the surface states for the current subpass into the storage
865 * we allocated for them in BeginCommandBuffer.
867 struct anv_bo
*ss_bo
=
868 &primary
->device
->surface_state_pool
.block_pool
.bo
;
869 struct anv_state src_state
= primary
->state
.render_pass_states
;
870 struct anv_state dst_state
= secondary
->state
.render_pass_states
;
871 assert(src_state
.alloc_size
== dst_state
.alloc_size
);
873 genX(cmd_buffer_so_memcpy
)(primary
, ss_bo
, dst_state
.offset
,
874 ss_bo
, src_state
.offset
,
875 src_state
.alloc_size
);
878 anv_cmd_buffer_add_secondary(primary
, secondary
);
881 /* Each of the secondary command buffers will use its own state base
882 * address. We need to re-emit state base address for the primary after
883 * all of the secondaries are done.
885 * TODO: Maybe we want to make this a dirty bit to avoid extra state base
888 genX(cmd_buffer_emit_state_base_address
)(primary
);
891 #define IVB_L3SQCREG1_SQGHPCI_DEFAULT 0x00730000
892 #define VLV_L3SQCREG1_SQGHPCI_DEFAULT 0x00d30000
893 #define HSW_L3SQCREG1_SQGHPCI_DEFAULT 0x00610000
896 * Program the hardware to use the specified L3 configuration.
899 genX(cmd_buffer_config_l3
)(struct anv_cmd_buffer
*cmd_buffer
,
900 const struct gen_l3_config
*cfg
)
903 if (cfg
== cmd_buffer
->state
.current_l3_config
)
906 if (unlikely(INTEL_DEBUG
& DEBUG_L3
)) {
907 fprintf(stderr
, "L3 config transition: ");
908 gen_dump_l3_config(cfg
, stderr
);
911 const bool has_slm
= cfg
->n
[GEN_L3P_SLM
];
913 /* According to the hardware docs, the L3 partitioning can only be changed
914 * while the pipeline is completely drained and the caches are flushed,
915 * which involves a first PIPE_CONTROL flush which stalls the pipeline...
917 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pc
) {
918 pc
.DCFlushEnable
= true;
919 pc
.PostSyncOperation
= NoWrite
;
920 pc
.CommandStreamerStallEnable
= true;
923 /* ...followed by a second pipelined PIPE_CONTROL that initiates
924 * invalidation of the relevant caches. Note that because RO invalidation
925 * happens at the top of the pipeline (i.e. right away as the PIPE_CONTROL
926 * command is processed by the CS) we cannot combine it with the previous
927 * stalling flush as the hardware documentation suggests, because that
928 * would cause the CS to stall on previous rendering *after* RO
929 * invalidation and wouldn't prevent the RO caches from being polluted by
930 * concurrent rendering before the stall completes. This intentionally
931 * doesn't implement the SKL+ hardware workaround suggesting to enable CS
932 * stall on PIPE_CONTROLs with the texture cache invalidation bit set for
933 * GPGPU workloads because the previous and subsequent PIPE_CONTROLs
934 * already guarantee that there is no concurrent GPGPU kernel execution
935 * (see SKL HSD 2132585).
937 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pc
) {
938 pc
.TextureCacheInvalidationEnable
= true;
939 pc
.ConstantCacheInvalidationEnable
= true;
940 pc
.InstructionCacheInvalidateEnable
= true;
941 pc
.StateCacheInvalidationEnable
= true;
942 pc
.PostSyncOperation
= NoWrite
;
945 /* Now send a third stalling flush to make sure that invalidation is
946 * complete when the L3 configuration registers are modified.
948 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pc
) {
949 pc
.DCFlushEnable
= true;
950 pc
.PostSyncOperation
= NoWrite
;
951 pc
.CommandStreamerStallEnable
= true;
956 assert(!cfg
->n
[GEN_L3P_IS
] && !cfg
->n
[GEN_L3P_C
] && !cfg
->n
[GEN_L3P_T
]);
959 anv_pack_struct(&l3cr
, GENX(L3CNTLREG
),
960 .SLMEnable
= has_slm
,
961 .URBAllocation
= cfg
->n
[GEN_L3P_URB
],
962 .ROAllocation
= cfg
->n
[GEN_L3P_RO
],
963 .DCAllocation
= cfg
->n
[GEN_L3P_DC
],
964 .AllAllocation
= cfg
->n
[GEN_L3P_ALL
]);
966 /* Set up the L3 partitioning. */
967 emit_lri(&cmd_buffer
->batch
, GENX(L3CNTLREG_num
), l3cr
);
971 const bool has_dc
= cfg
->n
[GEN_L3P_DC
] || cfg
->n
[GEN_L3P_ALL
];
972 const bool has_is
= cfg
->n
[GEN_L3P_IS
] || cfg
->n
[GEN_L3P_RO
] ||
974 const bool has_c
= cfg
->n
[GEN_L3P_C
] || cfg
->n
[GEN_L3P_RO
] ||
976 const bool has_t
= cfg
->n
[GEN_L3P_T
] || cfg
->n
[GEN_L3P_RO
] ||
979 assert(!cfg
->n
[GEN_L3P_ALL
]);
981 /* When enabled SLM only uses a portion of the L3 on half of the banks,
982 * the matching space on the remaining banks has to be allocated to a
983 * client (URB for all validated configurations) set to the
984 * lower-bandwidth 2-bank address hashing mode.
986 const struct gen_device_info
*devinfo
= &cmd_buffer
->device
->info
;
987 const bool urb_low_bw
= has_slm
&& !devinfo
->is_baytrail
;
988 assert(!urb_low_bw
|| cfg
->n
[GEN_L3P_URB
] == cfg
->n
[GEN_L3P_SLM
]);
990 /* Minimum number of ways that can be allocated to the URB. */
991 MAYBE_UNUSED
const unsigned n0_urb
= devinfo
->is_baytrail
? 32 : 0;
992 assert(cfg
->n
[GEN_L3P_URB
] >= n0_urb
);
994 uint32_t l3sqcr1
, l3cr2
, l3cr3
;
995 anv_pack_struct(&l3sqcr1
, GENX(L3SQCREG1
),
996 .ConvertDC_UC
= !has_dc
,
997 .ConvertIS_UC
= !has_is
,
998 .ConvertC_UC
= !has_c
,
999 .ConvertT_UC
= !has_t
);
1001 GEN_IS_HASWELL
? HSW_L3SQCREG1_SQGHPCI_DEFAULT
:
1002 devinfo
->is_baytrail
? VLV_L3SQCREG1_SQGHPCI_DEFAULT
:
1003 IVB_L3SQCREG1_SQGHPCI_DEFAULT
;
1005 anv_pack_struct(&l3cr2
, GENX(L3CNTLREG2
),
1006 .SLMEnable
= has_slm
,
1007 .URBLowBandwidth
= urb_low_bw
,
1008 .URBAllocation
= cfg
->n
[GEN_L3P_URB
] - n0_urb
,
1010 .ALLAllocation
= cfg
->n
[GEN_L3P_ALL
],
1012 .ROAllocation
= cfg
->n
[GEN_L3P_RO
],
1013 .DCAllocation
= cfg
->n
[GEN_L3P_DC
]);
1015 anv_pack_struct(&l3cr3
, GENX(L3CNTLREG3
),
1016 .ISAllocation
= cfg
->n
[GEN_L3P_IS
],
1017 .ISLowBandwidth
= 0,
1018 .CAllocation
= cfg
->n
[GEN_L3P_C
],
1020 .TAllocation
= cfg
->n
[GEN_L3P_T
],
1021 .TLowBandwidth
= 0);
1023 /* Set up the L3 partitioning. */
1024 emit_lri(&cmd_buffer
->batch
, GENX(L3SQCREG1_num
), l3sqcr1
);
1025 emit_lri(&cmd_buffer
->batch
, GENX(L3CNTLREG2_num
), l3cr2
);
1026 emit_lri(&cmd_buffer
->batch
, GENX(L3CNTLREG3_num
), l3cr3
);
1029 if (cmd_buffer
->device
->instance
->physicalDevice
.cmd_parser_version
>= 4) {
1030 /* Enable L3 atomics on HSW if we have a DC partition, otherwise keep
1031 * them disabled to avoid crashing the system hard.
1033 uint32_t scratch1
, chicken3
;
1034 anv_pack_struct(&scratch1
, GENX(SCRATCH1
),
1035 .L3AtomicDisable
= !has_dc
);
1036 anv_pack_struct(&chicken3
, GENX(CHICKEN3
),
1037 .L3AtomicDisableMask
= true,
1038 .L3AtomicDisable
= !has_dc
);
1039 emit_lri(&cmd_buffer
->batch
, GENX(SCRATCH1_num
), scratch1
);
1040 emit_lri(&cmd_buffer
->batch
, GENX(CHICKEN3_num
), chicken3
);
1046 cmd_buffer
->state
.current_l3_config
= cfg
;
1050 genX(cmd_buffer_apply_pipe_flushes
)(struct anv_cmd_buffer
*cmd_buffer
)
1052 enum anv_pipe_bits bits
= cmd_buffer
->state
.pending_pipe_bits
;
1054 /* Flushes are pipelined while invalidations are handled immediately.
1055 * Therefore, if we're flushing anything then we need to schedule a stall
1056 * before any invalidations can happen.
1058 if (bits
& ANV_PIPE_FLUSH_BITS
)
1059 bits
|= ANV_PIPE_NEEDS_CS_STALL_BIT
;
1061 /* If we're going to do an invalidate and we have a pending CS stall that
1062 * has yet to be resolved, we do the CS stall now.
1064 if ((bits
& ANV_PIPE_INVALIDATE_BITS
) &&
1065 (bits
& ANV_PIPE_NEEDS_CS_STALL_BIT
)) {
1066 bits
|= ANV_PIPE_CS_STALL_BIT
;
1067 bits
&= ~ANV_PIPE_NEEDS_CS_STALL_BIT
;
1070 if (bits
& (ANV_PIPE_FLUSH_BITS
| ANV_PIPE_CS_STALL_BIT
)) {
1071 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pipe
) {
1072 pipe
.DepthCacheFlushEnable
= bits
& ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
1073 pipe
.DCFlushEnable
= bits
& ANV_PIPE_DATA_CACHE_FLUSH_BIT
;
1074 pipe
.RenderTargetCacheFlushEnable
=
1075 bits
& ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1077 pipe
.DepthStallEnable
= bits
& ANV_PIPE_DEPTH_STALL_BIT
;
1078 pipe
.CommandStreamerStallEnable
= bits
& ANV_PIPE_CS_STALL_BIT
;
1079 pipe
.StallAtPixelScoreboard
= bits
& ANV_PIPE_STALL_AT_SCOREBOARD_BIT
;
1082 * According to the Broadwell documentation, any PIPE_CONTROL with the
1083 * "Command Streamer Stall" bit set must also have another bit set,
1084 * with five different options:
1086 * - Render Target Cache Flush
1087 * - Depth Cache Flush
1088 * - Stall at Pixel Scoreboard
1089 * - Post-Sync Operation
1093 * I chose "Stall at Pixel Scoreboard" since that's what we use in
1094 * mesa and it seems to work fine. The choice is fairly arbitrary.
1096 if ((bits
& ANV_PIPE_CS_STALL_BIT
) &&
1097 !(bits
& (ANV_PIPE_FLUSH_BITS
| ANV_PIPE_DEPTH_STALL_BIT
|
1098 ANV_PIPE_STALL_AT_SCOREBOARD_BIT
)))
1099 pipe
.StallAtPixelScoreboard
= true;
1102 bits
&= ~(ANV_PIPE_FLUSH_BITS
| ANV_PIPE_CS_STALL_BIT
);
1105 if (bits
& ANV_PIPE_INVALIDATE_BITS
) {
1106 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pipe
) {
1107 pipe
.StateCacheInvalidationEnable
=
1108 bits
& ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
;
1109 pipe
.ConstantCacheInvalidationEnable
=
1110 bits
& ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
;
1111 pipe
.VFCacheInvalidationEnable
=
1112 bits
& ANV_PIPE_VF_CACHE_INVALIDATE_BIT
;
1113 pipe
.TextureCacheInvalidationEnable
=
1114 bits
& ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
1115 pipe
.InstructionCacheInvalidateEnable
=
1116 bits
& ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT
;
1119 bits
&= ~ANV_PIPE_INVALIDATE_BITS
;
1122 cmd_buffer
->state
.pending_pipe_bits
= bits
;
1125 void genX(CmdPipelineBarrier
)(
1126 VkCommandBuffer commandBuffer
,
1127 VkPipelineStageFlags srcStageMask
,
1128 VkPipelineStageFlags destStageMask
,
1130 uint32_t memoryBarrierCount
,
1131 const VkMemoryBarrier
* pMemoryBarriers
,
1132 uint32_t bufferMemoryBarrierCount
,
1133 const VkBufferMemoryBarrier
* pBufferMemoryBarriers
,
1134 uint32_t imageMemoryBarrierCount
,
1135 const VkImageMemoryBarrier
* pImageMemoryBarriers
)
1137 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1139 /* XXX: Right now, we're really dumb and just flush whatever categories
1140 * the app asks for. One of these days we may make this a bit better
1141 * but right now that's all the hardware allows for in most areas.
1143 VkAccessFlags src_flags
= 0;
1144 VkAccessFlags dst_flags
= 0;
1146 for (uint32_t i
= 0; i
< memoryBarrierCount
; i
++) {
1147 src_flags
|= pMemoryBarriers
[i
].srcAccessMask
;
1148 dst_flags
|= pMemoryBarriers
[i
].dstAccessMask
;
1151 for (uint32_t i
= 0; i
< bufferMemoryBarrierCount
; i
++) {
1152 src_flags
|= pBufferMemoryBarriers
[i
].srcAccessMask
;
1153 dst_flags
|= pBufferMemoryBarriers
[i
].dstAccessMask
;
1156 for (uint32_t i
= 0; i
< imageMemoryBarrierCount
; i
++) {
1157 src_flags
|= pImageMemoryBarriers
[i
].srcAccessMask
;
1158 dst_flags
|= pImageMemoryBarriers
[i
].dstAccessMask
;
1159 ANV_FROM_HANDLE(anv_image
, image
, pImageMemoryBarriers
[i
].image
);
1160 const VkImageSubresourceRange
*range
=
1161 &pImageMemoryBarriers
[i
].subresourceRange
;
1163 if (range
->aspectMask
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
1164 transition_depth_buffer(cmd_buffer
, image
,
1165 pImageMemoryBarriers
[i
].oldLayout
,
1166 pImageMemoryBarriers
[i
].newLayout
);
1167 } else if (range
->aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
) {
1168 transition_color_buffer(cmd_buffer
, image
,
1169 range
->baseMipLevel
,
1170 anv_get_levelCount(image
, range
),
1171 range
->baseArrayLayer
,
1172 anv_get_layerCount(image
, range
),
1173 pImageMemoryBarriers
[i
].oldLayout
,
1174 pImageMemoryBarriers
[i
].newLayout
);
1178 cmd_buffer
->state
.pending_pipe_bits
|=
1179 anv_pipe_flush_bits_for_access_flags(src_flags
) |
1180 anv_pipe_invalidate_bits_for_access_flags(dst_flags
);
1184 cmd_buffer_alloc_push_constants(struct anv_cmd_buffer
*cmd_buffer
)
1186 VkShaderStageFlags stages
= cmd_buffer
->state
.pipeline
->active_stages
;
1188 /* In order to avoid thrash, we assume that vertex and fragment stages
1189 * always exist. In the rare case where one is missing *and* the other
1190 * uses push concstants, this may be suboptimal. However, avoiding stalls
1191 * seems more important.
1193 stages
|= VK_SHADER_STAGE_FRAGMENT_BIT
| VK_SHADER_STAGE_VERTEX_BIT
;
1195 if (stages
== cmd_buffer
->state
.push_constant_stages
)
1199 const unsigned push_constant_kb
= 32;
1200 #elif GEN_IS_HASWELL
1201 const unsigned push_constant_kb
= cmd_buffer
->device
->info
.gt
== 3 ? 32 : 16;
1203 const unsigned push_constant_kb
= 16;
1206 const unsigned num_stages
=
1207 _mesa_bitcount(stages
& VK_SHADER_STAGE_ALL_GRAPHICS
);
1208 unsigned size_per_stage
= push_constant_kb
/ num_stages
;
1210 /* Broadwell+ and Haswell gt3 require that the push constant sizes be in
1211 * units of 2KB. Incidentally, these are the same platforms that have
1212 * 32KB worth of push constant space.
1214 if (push_constant_kb
== 32)
1215 size_per_stage
&= ~1u;
1217 uint32_t kb_used
= 0;
1218 for (int i
= MESA_SHADER_VERTEX
; i
< MESA_SHADER_FRAGMENT
; i
++) {
1219 unsigned push_size
= (stages
& (1 << i
)) ? size_per_stage
: 0;
1220 anv_batch_emit(&cmd_buffer
->batch
,
1221 GENX(3DSTATE_PUSH_CONSTANT_ALLOC_VS
), alloc
) {
1222 alloc
._3DCommandSubOpcode
= 18 + i
;
1223 alloc
.ConstantBufferOffset
= (push_size
> 0) ? kb_used
: 0;
1224 alloc
.ConstantBufferSize
= push_size
;
1226 kb_used
+= push_size
;
1229 anv_batch_emit(&cmd_buffer
->batch
,
1230 GENX(3DSTATE_PUSH_CONSTANT_ALLOC_PS
), alloc
) {
1231 alloc
.ConstantBufferOffset
= kb_used
;
1232 alloc
.ConstantBufferSize
= push_constant_kb
- kb_used
;
1235 cmd_buffer
->state
.push_constant_stages
= stages
;
1237 /* From the BDW PRM for 3DSTATE_PUSH_CONSTANT_ALLOC_VS:
1239 * "The 3DSTATE_CONSTANT_VS must be reprogrammed prior to
1240 * the next 3DPRIMITIVE command after programming the
1241 * 3DSTATE_PUSH_CONSTANT_ALLOC_VS"
1243 * Since 3DSTATE_PUSH_CONSTANT_ALLOC_VS is programmed as part of
1244 * pipeline setup, we need to dirty push constants.
1246 cmd_buffer
->state
.push_constants_dirty
|= VK_SHADER_STAGE_ALL_GRAPHICS
;
1250 emit_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1251 gl_shader_stage stage
,
1252 struct anv_state
*bt_state
)
1254 struct anv_subpass
*subpass
= cmd_buffer
->state
.subpass
;
1255 struct anv_pipeline
*pipeline
;
1256 uint32_t bias
, state_offset
;
1259 case MESA_SHADER_COMPUTE
:
1260 pipeline
= cmd_buffer
->state
.compute_pipeline
;
1264 pipeline
= cmd_buffer
->state
.pipeline
;
1269 if (!anv_pipeline_has_stage(pipeline
, stage
)) {
1270 *bt_state
= (struct anv_state
) { 0, };
1274 struct anv_pipeline_bind_map
*map
= &pipeline
->shaders
[stage
]->bind_map
;
1275 if (bias
+ map
->surface_count
== 0) {
1276 *bt_state
= (struct anv_state
) { 0, };
1280 *bt_state
= anv_cmd_buffer_alloc_binding_table(cmd_buffer
,
1281 bias
+ map
->surface_count
,
1283 uint32_t *bt_map
= bt_state
->map
;
1285 if (bt_state
->map
== NULL
)
1286 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1288 if (stage
== MESA_SHADER_COMPUTE
&&
1289 get_cs_prog_data(cmd_buffer
->state
.compute_pipeline
)->uses_num_work_groups
) {
1290 struct anv_bo
*bo
= cmd_buffer
->state
.num_workgroups_bo
;
1291 uint32_t bo_offset
= cmd_buffer
->state
.num_workgroups_offset
;
1293 struct anv_state surface_state
;
1295 anv_cmd_buffer_alloc_surface_state(cmd_buffer
);
1297 const enum isl_format format
=
1298 anv_isl_format_for_descriptor_type(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
);
1299 anv_fill_buffer_surface_state(cmd_buffer
->device
, surface_state
,
1300 format
, bo_offset
, 12, 1);
1302 bt_map
[0] = surface_state
.offset
+ state_offset
;
1303 add_surface_state_reloc(cmd_buffer
, surface_state
, bo
, bo_offset
);
1306 if (map
->surface_count
== 0)
1309 if (map
->image_count
> 0) {
1311 anv_cmd_buffer_ensure_push_constant_field(cmd_buffer
, stage
, images
);
1312 if (result
!= VK_SUCCESS
)
1315 cmd_buffer
->state
.push_constants_dirty
|= 1 << stage
;
1319 for (uint32_t s
= 0; s
< map
->surface_count
; s
++) {
1320 struct anv_pipeline_binding
*binding
= &map
->surface_to_descriptor
[s
];
1322 struct anv_state surface_state
;
1324 if (binding
->set
== ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS
) {
1325 /* Color attachment binding */
1326 assert(stage
== MESA_SHADER_FRAGMENT
);
1327 assert(binding
->binding
== 0);
1328 if (binding
->index
< subpass
->color_count
) {
1329 const unsigned att
=
1330 subpass
->color_attachments
[binding
->index
].attachment
;
1332 /* From the Vulkan 1.0.46 spec:
1334 * "If any color or depth/stencil attachments are
1335 * VK_ATTACHMENT_UNUSED, then no writes occur for those
1338 if (att
== VK_ATTACHMENT_UNUSED
) {
1339 surface_state
= cmd_buffer
->state
.null_surface_state
;
1341 surface_state
= cmd_buffer
->state
.attachments
[att
].color_rt_state
;
1344 surface_state
= cmd_buffer
->state
.null_surface_state
;
1347 bt_map
[bias
+ s
] = surface_state
.offset
+ state_offset
;
1351 struct anv_descriptor_set
*set
=
1352 cmd_buffer
->state
.descriptors
[binding
->set
];
1353 uint32_t offset
= set
->layout
->binding
[binding
->binding
].descriptor_index
;
1354 struct anv_descriptor
*desc
= &set
->descriptors
[offset
+ binding
->index
];
1356 switch (desc
->type
) {
1357 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1358 /* Nothing for us to do here */
1361 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1362 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1363 surface_state
= desc
->aux_usage
== ISL_AUX_USAGE_NONE
?
1364 desc
->image_view
->no_aux_sampler_surface_state
:
1365 desc
->image_view
->sampler_surface_state
;
1366 assert(surface_state
.alloc_size
);
1367 add_image_relocs(cmd_buffer
, desc
->image_view
->image
,
1368 desc
->image_view
->aspect_mask
,
1369 desc
->aux_usage
, surface_state
);
1371 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
1372 assert(stage
== MESA_SHADER_FRAGMENT
);
1373 if (desc
->image_view
->aspect_mask
!= VK_IMAGE_ASPECT_COLOR_BIT
) {
1374 /* For depth and stencil input attachments, we treat it like any
1375 * old texture that a user may have bound.
1377 surface_state
= desc
->aux_usage
== ISL_AUX_USAGE_NONE
?
1378 desc
->image_view
->no_aux_sampler_surface_state
:
1379 desc
->image_view
->sampler_surface_state
;
1380 assert(surface_state
.alloc_size
);
1381 add_image_relocs(cmd_buffer
, desc
->image_view
->image
,
1382 desc
->image_view
->aspect_mask
,
1383 desc
->aux_usage
, surface_state
);
1385 /* For color input attachments, we create the surface state at
1386 * vkBeginRenderPass time so that we can include aux and clear
1387 * color information.
1389 assert(binding
->input_attachment_index
< subpass
->input_count
);
1390 const unsigned subpass_att
= binding
->input_attachment_index
;
1391 const unsigned att
= subpass
->input_attachments
[subpass_att
].attachment
;
1392 surface_state
= cmd_buffer
->state
.attachments
[att
].input_att_state
;
1396 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
: {
1397 surface_state
= (binding
->write_only
)
1398 ? desc
->image_view
->writeonly_storage_surface_state
1399 : desc
->image_view
->storage_surface_state
;
1400 assert(surface_state
.alloc_size
);
1401 add_image_relocs(cmd_buffer
, desc
->image_view
->image
,
1402 desc
->image_view
->aspect_mask
,
1403 desc
->image_view
->image
->aux_usage
, surface_state
);
1405 struct brw_image_param
*image_param
=
1406 &cmd_buffer
->state
.push_constants
[stage
]->images
[image
++];
1408 *image_param
= desc
->image_view
->storage_image_param
;
1409 image_param
->surface_idx
= bias
+ s
;
1413 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1414 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1415 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1416 surface_state
= desc
->buffer_view
->surface_state
;
1417 assert(surface_state
.alloc_size
);
1418 add_surface_state_reloc(cmd_buffer
, surface_state
,
1419 desc
->buffer_view
->bo
,
1420 desc
->buffer_view
->offset
);
1423 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1424 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
1425 uint32_t dynamic_offset_idx
=
1426 pipeline
->layout
->set
[binding
->set
].dynamic_offset_start
+
1427 set
->layout
->binding
[binding
->binding
].dynamic_offset_index
+
1430 /* Compute the offset within the buffer */
1431 uint64_t offset
= desc
->offset
+
1432 cmd_buffer
->state
.dynamic_offsets
[dynamic_offset_idx
];
1433 /* Clamp to the buffer size */
1434 offset
= MIN2(offset
, desc
->buffer
->size
);
1435 /* Clamp the range to the buffer size */
1436 uint32_t range
= MIN2(desc
->range
, desc
->buffer
->size
- offset
);
1439 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, 64, 64);
1440 enum isl_format format
=
1441 anv_isl_format_for_descriptor_type(desc
->type
);
1443 anv_fill_buffer_surface_state(cmd_buffer
->device
, surface_state
,
1444 format
, offset
, range
, 1);
1445 add_surface_state_reloc(cmd_buffer
, surface_state
,
1447 desc
->buffer
->offset
+ offset
);
1451 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1452 surface_state
= (binding
->write_only
)
1453 ? desc
->buffer_view
->writeonly_storage_surface_state
1454 : desc
->buffer_view
->storage_surface_state
;
1455 assert(surface_state
.alloc_size
);
1456 add_surface_state_reloc(cmd_buffer
, surface_state
,
1457 desc
->buffer_view
->bo
,
1458 desc
->buffer_view
->offset
);
1460 struct brw_image_param
*image_param
=
1461 &cmd_buffer
->state
.push_constants
[stage
]->images
[image
++];
1463 *image_param
= desc
->buffer_view
->storage_image_param
;
1464 image_param
->surface_idx
= bias
+ s
;
1468 assert(!"Invalid descriptor type");
1472 bt_map
[bias
+ s
] = surface_state
.offset
+ state_offset
;
1474 assert(image
== map
->image_count
);
1477 anv_state_flush(cmd_buffer
->device
, *bt_state
);
1483 emit_samplers(struct anv_cmd_buffer
*cmd_buffer
,
1484 gl_shader_stage stage
,
1485 struct anv_state
*state
)
1487 struct anv_pipeline
*pipeline
;
1489 if (stage
== MESA_SHADER_COMPUTE
)
1490 pipeline
= cmd_buffer
->state
.compute_pipeline
;
1492 pipeline
= cmd_buffer
->state
.pipeline
;
1494 if (!anv_pipeline_has_stage(pipeline
, stage
)) {
1495 *state
= (struct anv_state
) { 0, };
1499 struct anv_pipeline_bind_map
*map
= &pipeline
->shaders
[stage
]->bind_map
;
1500 if (map
->sampler_count
== 0) {
1501 *state
= (struct anv_state
) { 0, };
1505 uint32_t size
= map
->sampler_count
* 16;
1506 *state
= anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, size
, 32);
1508 if (state
->map
== NULL
)
1509 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1511 for (uint32_t s
= 0; s
< map
->sampler_count
; s
++) {
1512 struct anv_pipeline_binding
*binding
= &map
->sampler_to_descriptor
[s
];
1513 struct anv_descriptor_set
*set
=
1514 cmd_buffer
->state
.descriptors
[binding
->set
];
1515 uint32_t offset
= set
->layout
->binding
[binding
->binding
].descriptor_index
;
1516 struct anv_descriptor
*desc
= &set
->descriptors
[offset
+ binding
->index
];
1518 if (desc
->type
!= VK_DESCRIPTOR_TYPE_SAMPLER
&&
1519 desc
->type
!= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
)
1522 struct anv_sampler
*sampler
= desc
->sampler
;
1524 /* This can happen if we have an unfilled slot since TYPE_SAMPLER
1525 * happens to be zero.
1527 if (sampler
== NULL
)
1530 memcpy(state
->map
+ (s
* 16),
1531 sampler
->state
, sizeof(sampler
->state
));
1534 anv_state_flush(cmd_buffer
->device
, *state
);
1540 flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
)
1542 VkShaderStageFlags dirty
= cmd_buffer
->state
.descriptors_dirty
&
1543 cmd_buffer
->state
.pipeline
->active_stages
;
1545 VkResult result
= VK_SUCCESS
;
1546 anv_foreach_stage(s
, dirty
) {
1547 result
= emit_samplers(cmd_buffer
, s
, &cmd_buffer
->state
.samplers
[s
]);
1548 if (result
!= VK_SUCCESS
)
1550 result
= emit_binding_table(cmd_buffer
, s
,
1551 &cmd_buffer
->state
.binding_tables
[s
]);
1552 if (result
!= VK_SUCCESS
)
1556 if (result
!= VK_SUCCESS
) {
1557 assert(result
== VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1559 result
= anv_cmd_buffer_new_binding_table_block(cmd_buffer
);
1560 if (result
!= VK_SUCCESS
)
1563 /* Re-emit state base addresses so we get the new surface state base
1564 * address before we start emitting binding tables etc.
1566 genX(cmd_buffer_emit_state_base_address
)(cmd_buffer
);
1568 /* Re-emit all active binding tables */
1569 dirty
|= cmd_buffer
->state
.pipeline
->active_stages
;
1570 anv_foreach_stage(s
, dirty
) {
1571 result
= emit_samplers(cmd_buffer
, s
, &cmd_buffer
->state
.samplers
[s
]);
1572 if (result
!= VK_SUCCESS
) {
1573 anv_batch_set_error(&cmd_buffer
->batch
, result
);
1576 result
= emit_binding_table(cmd_buffer
, s
,
1577 &cmd_buffer
->state
.binding_tables
[s
]);
1578 if (result
!= VK_SUCCESS
) {
1579 anv_batch_set_error(&cmd_buffer
->batch
, result
);
1585 cmd_buffer
->state
.descriptors_dirty
&= ~dirty
;
1591 cmd_buffer_emit_descriptor_pointers(struct anv_cmd_buffer
*cmd_buffer
,
1594 static const uint32_t sampler_state_opcodes
[] = {
1595 [MESA_SHADER_VERTEX
] = 43,
1596 [MESA_SHADER_TESS_CTRL
] = 44, /* HS */
1597 [MESA_SHADER_TESS_EVAL
] = 45, /* DS */
1598 [MESA_SHADER_GEOMETRY
] = 46,
1599 [MESA_SHADER_FRAGMENT
] = 47,
1600 [MESA_SHADER_COMPUTE
] = 0,
1603 static const uint32_t binding_table_opcodes
[] = {
1604 [MESA_SHADER_VERTEX
] = 38,
1605 [MESA_SHADER_TESS_CTRL
] = 39,
1606 [MESA_SHADER_TESS_EVAL
] = 40,
1607 [MESA_SHADER_GEOMETRY
] = 41,
1608 [MESA_SHADER_FRAGMENT
] = 42,
1609 [MESA_SHADER_COMPUTE
] = 0,
1612 anv_foreach_stage(s
, stages
) {
1613 if (cmd_buffer
->state
.samplers
[s
].alloc_size
> 0) {
1614 anv_batch_emit(&cmd_buffer
->batch
,
1615 GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS
), ssp
) {
1616 ssp
._3DCommandSubOpcode
= sampler_state_opcodes
[s
];
1617 ssp
.PointertoVSSamplerState
= cmd_buffer
->state
.samplers
[s
].offset
;
1621 /* Always emit binding table pointers if we're asked to, since on SKL
1622 * this is what flushes push constants. */
1623 anv_batch_emit(&cmd_buffer
->batch
,
1624 GENX(3DSTATE_BINDING_TABLE_POINTERS_VS
), btp
) {
1625 btp
._3DCommandSubOpcode
= binding_table_opcodes
[s
];
1626 btp
.PointertoVSBindingTable
= cmd_buffer
->state
.binding_tables
[s
].offset
;
1632 cmd_buffer_flush_push_constants(struct anv_cmd_buffer
*cmd_buffer
)
1634 static const uint32_t push_constant_opcodes
[] = {
1635 [MESA_SHADER_VERTEX
] = 21,
1636 [MESA_SHADER_TESS_CTRL
] = 25, /* HS */
1637 [MESA_SHADER_TESS_EVAL
] = 26, /* DS */
1638 [MESA_SHADER_GEOMETRY
] = 22,
1639 [MESA_SHADER_FRAGMENT
] = 23,
1640 [MESA_SHADER_COMPUTE
] = 0,
1643 VkShaderStageFlags flushed
= 0;
1645 anv_foreach_stage(stage
, cmd_buffer
->state
.push_constants_dirty
) {
1646 if (stage
== MESA_SHADER_COMPUTE
)
1649 struct anv_state state
= anv_cmd_buffer_push_constants(cmd_buffer
, stage
);
1651 if (state
.offset
== 0) {
1652 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_CONSTANT_VS
), c
)
1653 c
._3DCommandSubOpcode
= push_constant_opcodes
[stage
];
1655 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_CONSTANT_VS
), c
) {
1656 c
._3DCommandSubOpcode
= push_constant_opcodes
[stage
],
1657 c
.ConstantBody
= (struct GENX(3DSTATE_CONSTANT_BODY
)) {
1659 .Buffer
[2] = { &cmd_buffer
->device
->dynamic_state_pool
.block_pool
.bo
, state
.offset
},
1660 .ReadLength
[2] = DIV_ROUND_UP(state
.alloc_size
, 32),
1662 .Buffer
[0] = { .offset
= state
.offset
},
1663 .ReadLength
[0] = DIV_ROUND_UP(state
.alloc_size
, 32),
1669 flushed
|= mesa_to_vk_shader_stage(stage
);
1672 cmd_buffer
->state
.push_constants_dirty
&= ~VK_SHADER_STAGE_ALL_GRAPHICS
;
1678 genX(cmd_buffer_flush_state
)(struct anv_cmd_buffer
*cmd_buffer
)
1680 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
1683 uint32_t vb_emit
= cmd_buffer
->state
.vb_dirty
& pipeline
->vb_used
;
1685 assert((pipeline
->active_stages
& VK_SHADER_STAGE_COMPUTE_BIT
) == 0);
1687 genX(cmd_buffer_config_l3
)(cmd_buffer
, pipeline
->urb
.l3_config
);
1689 genX(flush_pipeline_select_3d
)(cmd_buffer
);
1692 const uint32_t num_buffers
= __builtin_popcount(vb_emit
);
1693 const uint32_t num_dwords
= 1 + num_buffers
* 4;
1695 p
= anv_batch_emitn(&cmd_buffer
->batch
, num_dwords
,
1696 GENX(3DSTATE_VERTEX_BUFFERS
));
1698 for_each_bit(vb
, vb_emit
) {
1699 struct anv_buffer
*buffer
= cmd_buffer
->state
.vertex_bindings
[vb
].buffer
;
1700 uint32_t offset
= cmd_buffer
->state
.vertex_bindings
[vb
].offset
;
1702 struct GENX(VERTEX_BUFFER_STATE
) state
= {
1703 .VertexBufferIndex
= vb
,
1706 .MemoryObjectControlState
= GENX(MOCS
),
1708 .BufferAccessType
= pipeline
->instancing_enable
[vb
] ? INSTANCEDATA
: VERTEXDATA
,
1709 /* Our implementation of VK_KHR_multiview uses instancing to draw
1710 * the different views. If the client asks for instancing, we
1711 * need to use the Instance Data Step Rate to ensure that we
1712 * repeat the client's per-instance data once for each view.
1714 .InstanceDataStepRate
= anv_subpass_view_count(pipeline
->subpass
),
1715 .VertexBufferMemoryObjectControlState
= GENX(MOCS
),
1718 .AddressModifyEnable
= true,
1719 .BufferPitch
= pipeline
->binding_stride
[vb
],
1720 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
1723 .BufferSize
= buffer
->size
- offset
1725 .EndAddress
= { buffer
->bo
, buffer
->offset
+ buffer
->size
- 1},
1729 GENX(VERTEX_BUFFER_STATE_pack
)(&cmd_buffer
->batch
, &p
[1 + i
* 4], &state
);
1734 cmd_buffer
->state
.vb_dirty
&= ~vb_emit
;
1736 if (cmd_buffer
->state
.dirty
& ANV_CMD_DIRTY_PIPELINE
) {
1737 anv_batch_emit_batch(&cmd_buffer
->batch
, &pipeline
->batch
);
1739 /* The exact descriptor layout is pulled from the pipeline, so we need
1740 * to re-emit binding tables on every pipeline change.
1742 cmd_buffer
->state
.descriptors_dirty
|=
1743 cmd_buffer
->state
.pipeline
->active_stages
;
1745 /* If the pipeline changed, we may need to re-allocate push constant
1748 cmd_buffer_alloc_push_constants(cmd_buffer
);
1752 if (cmd_buffer
->state
.descriptors_dirty
& VK_SHADER_STAGE_VERTEX_BIT
||
1753 cmd_buffer
->state
.push_constants_dirty
& VK_SHADER_STAGE_VERTEX_BIT
) {
1754 /* From the IVB PRM Vol. 2, Part 1, Section 3.2.1:
1756 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth
1757 * stall needs to be sent just prior to any 3DSTATE_VS,
1758 * 3DSTATE_URB_VS, 3DSTATE_CONSTANT_VS,
1759 * 3DSTATE_BINDING_TABLE_POINTER_VS,
1760 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one
1761 * PIPE_CONTROL needs to be sent before any combination of VS
1762 * associated 3DSTATE."
1764 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pc
) {
1765 pc
.DepthStallEnable
= true;
1766 pc
.PostSyncOperation
= WriteImmediateData
;
1768 (struct anv_address
) { &cmd_buffer
->device
->workaround_bo
, 0 };
1773 /* Render targets live in the same binding table as fragment descriptors */
1774 if (cmd_buffer
->state
.dirty
& ANV_CMD_DIRTY_RENDER_TARGETS
)
1775 cmd_buffer
->state
.descriptors_dirty
|= VK_SHADER_STAGE_FRAGMENT_BIT
;
1777 /* We emit the binding tables and sampler tables first, then emit push
1778 * constants and then finally emit binding table and sampler table
1779 * pointers. It has to happen in this order, since emitting the binding
1780 * tables may change the push constants (in case of storage images). After
1781 * emitting push constants, on SKL+ we have to emit the corresponding
1782 * 3DSTATE_BINDING_TABLE_POINTER_* for the push constants to take effect.
1785 if (cmd_buffer
->state
.descriptors_dirty
)
1786 dirty
= flush_descriptor_sets(cmd_buffer
);
1788 if (cmd_buffer
->state
.push_constants_dirty
) {
1790 /* On Sky Lake and later, the binding table pointers commands are
1791 * what actually flush the changes to push constant state so we need
1792 * to dirty them so they get re-emitted below.
1794 dirty
|= cmd_buffer_flush_push_constants(cmd_buffer
);
1796 cmd_buffer_flush_push_constants(cmd_buffer
);
1801 cmd_buffer_emit_descriptor_pointers(cmd_buffer
, dirty
);
1803 if (cmd_buffer
->state
.dirty
& ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
)
1804 gen8_cmd_buffer_emit_viewport(cmd_buffer
);
1806 if (cmd_buffer
->state
.dirty
& (ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
|
1807 ANV_CMD_DIRTY_PIPELINE
)) {
1808 gen8_cmd_buffer_emit_depth_viewport(cmd_buffer
,
1809 pipeline
->depth_clamp_enable
);
1812 if (cmd_buffer
->state
.dirty
& ANV_CMD_DIRTY_DYNAMIC_SCISSOR
)
1813 gen7_cmd_buffer_emit_scissor(cmd_buffer
);
1815 genX(cmd_buffer_flush_dynamic_state
)(cmd_buffer
);
1817 genX(cmd_buffer_apply_pipe_flushes
)(cmd_buffer
);
1821 emit_vertex_bo(struct anv_cmd_buffer
*cmd_buffer
,
1822 struct anv_bo
*bo
, uint32_t offset
,
1823 uint32_t size
, uint32_t index
)
1825 uint32_t *p
= anv_batch_emitn(&cmd_buffer
->batch
, 5,
1826 GENX(3DSTATE_VERTEX_BUFFERS
));
1828 GENX(VERTEX_BUFFER_STATE_pack
)(&cmd_buffer
->batch
, p
+ 1,
1829 &(struct GENX(VERTEX_BUFFER_STATE
)) {
1830 .VertexBufferIndex
= index
,
1831 .AddressModifyEnable
= true,
1834 .MemoryObjectControlState
= GENX(MOCS
),
1835 .BufferStartingAddress
= { bo
, offset
},
1838 .VertexBufferMemoryObjectControlState
= GENX(MOCS
),
1839 .BufferStartingAddress
= { bo
, offset
},
1840 .EndAddress
= { bo
, offset
+ size
},
1846 emit_base_vertex_instance_bo(struct anv_cmd_buffer
*cmd_buffer
,
1847 struct anv_bo
*bo
, uint32_t offset
)
1849 emit_vertex_bo(cmd_buffer
, bo
, offset
, 8, ANV_SVGS_VB_INDEX
);
1853 emit_base_vertex_instance(struct anv_cmd_buffer
*cmd_buffer
,
1854 uint32_t base_vertex
, uint32_t base_instance
)
1856 struct anv_state id_state
=
1857 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, 8, 4);
1859 ((uint32_t *)id_state
.map
)[0] = base_vertex
;
1860 ((uint32_t *)id_state
.map
)[1] = base_instance
;
1862 anv_state_flush(cmd_buffer
->device
, id_state
);
1864 emit_base_vertex_instance_bo(cmd_buffer
,
1865 &cmd_buffer
->device
->dynamic_state_pool
.block_pool
.bo
, id_state
.offset
);
1869 emit_draw_index(struct anv_cmd_buffer
*cmd_buffer
, uint32_t draw_index
)
1871 struct anv_state state
=
1872 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, 4, 4);
1874 ((uint32_t *)state
.map
)[0] = draw_index
;
1876 anv_state_flush(cmd_buffer
->device
, state
);
1878 emit_vertex_bo(cmd_buffer
,
1879 &cmd_buffer
->device
->dynamic_state_pool
.block_pool
.bo
,
1880 state
.offset
, 4, ANV_DRAWID_VB_INDEX
);
1884 VkCommandBuffer commandBuffer
,
1885 uint32_t vertexCount
,
1886 uint32_t instanceCount
,
1887 uint32_t firstVertex
,
1888 uint32_t firstInstance
)
1890 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1891 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
1892 const struct brw_vs_prog_data
*vs_prog_data
= get_vs_prog_data(pipeline
);
1894 if (anv_batch_has_error(&cmd_buffer
->batch
))
1897 genX(cmd_buffer_flush_state
)(cmd_buffer
);
1899 if (vs_prog_data
->uses_basevertex
|| vs_prog_data
->uses_baseinstance
)
1900 emit_base_vertex_instance(cmd_buffer
, firstVertex
, firstInstance
);
1901 if (vs_prog_data
->uses_drawid
)
1902 emit_draw_index(cmd_buffer
, 0);
1904 /* Our implementation of VK_KHR_multiview uses instancing to draw the
1905 * different views. We need to multiply instanceCount by the view count.
1907 instanceCount
*= anv_subpass_view_count(cmd_buffer
->state
.subpass
);
1909 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DPRIMITIVE
), prim
) {
1910 prim
.VertexAccessType
= SEQUENTIAL
;
1911 prim
.PrimitiveTopologyType
= pipeline
->topology
;
1912 prim
.VertexCountPerInstance
= vertexCount
;
1913 prim
.StartVertexLocation
= firstVertex
;
1914 prim
.InstanceCount
= instanceCount
;
1915 prim
.StartInstanceLocation
= firstInstance
;
1916 prim
.BaseVertexLocation
= 0;
1920 void genX(CmdDrawIndexed
)(
1921 VkCommandBuffer commandBuffer
,
1922 uint32_t indexCount
,
1923 uint32_t instanceCount
,
1924 uint32_t firstIndex
,
1925 int32_t vertexOffset
,
1926 uint32_t firstInstance
)
1928 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1929 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
1930 const struct brw_vs_prog_data
*vs_prog_data
= get_vs_prog_data(pipeline
);
1932 if (anv_batch_has_error(&cmd_buffer
->batch
))
1935 genX(cmd_buffer_flush_state
)(cmd_buffer
);
1937 if (vs_prog_data
->uses_basevertex
|| vs_prog_data
->uses_baseinstance
)
1938 emit_base_vertex_instance(cmd_buffer
, vertexOffset
, firstInstance
);
1939 if (vs_prog_data
->uses_drawid
)
1940 emit_draw_index(cmd_buffer
, 0);
1942 /* Our implementation of VK_KHR_multiview uses instancing to draw the
1943 * different views. We need to multiply instanceCount by the view count.
1945 instanceCount
*= anv_subpass_view_count(cmd_buffer
->state
.subpass
);
1947 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DPRIMITIVE
), prim
) {
1948 prim
.VertexAccessType
= RANDOM
;
1949 prim
.PrimitiveTopologyType
= pipeline
->topology
;
1950 prim
.VertexCountPerInstance
= indexCount
;
1951 prim
.StartVertexLocation
= firstIndex
;
1952 prim
.InstanceCount
= instanceCount
;
1953 prim
.StartInstanceLocation
= firstInstance
;
1954 prim
.BaseVertexLocation
= vertexOffset
;
1958 /* Auto-Draw / Indirect Registers */
1959 #define GEN7_3DPRIM_END_OFFSET 0x2420
1960 #define GEN7_3DPRIM_START_VERTEX 0x2430
1961 #define GEN7_3DPRIM_VERTEX_COUNT 0x2434
1962 #define GEN7_3DPRIM_INSTANCE_COUNT 0x2438
1963 #define GEN7_3DPRIM_START_INSTANCE 0x243C
1964 #define GEN7_3DPRIM_BASE_VERTEX 0x2440
1966 /* MI_MATH only exists on Haswell+ */
1967 #if GEN_IS_HASWELL || GEN_GEN >= 8
1970 mi_alu(uint32_t opcode
, uint32_t op1
, uint32_t op2
)
1972 struct GENX(MI_MATH_ALU_INSTRUCTION
) instr
= {
1973 .ALUOpcode
= opcode
,
1979 GENX(MI_MATH_ALU_INSTRUCTION_pack
)(NULL
, &dw
, &instr
);
1984 #define CS_GPR(n) (0x2600 + (n) * 8)
1986 /* Emit dwords to multiply GPR0 by N */
1988 build_alu_multiply_gpr0(uint32_t *dw
, unsigned *dw_count
, uint32_t N
)
1990 VK_OUTARRAY_MAKE(out
, dw
, dw_count
);
1992 #define append_alu(opcode, operand1, operand2) \
1993 vk_outarray_append(&out, alu_dw) *alu_dw = mi_alu(opcode, operand1, operand2)
1996 unsigned top_bit
= 31 - __builtin_clz(N
);
1997 for (int i
= top_bit
- 1; i
>= 0; i
--) {
1998 /* We get our initial data in GPR0 and we write the final data out to
1999 * GPR0 but we use GPR1 as our scratch register.
2001 unsigned src_reg
= i
== top_bit
- 1 ? MI_ALU_REG0
: MI_ALU_REG1
;
2002 unsigned dst_reg
= i
== 0 ? MI_ALU_REG0
: MI_ALU_REG1
;
2004 /* Shift the current value left by 1 */
2005 append_alu(MI_ALU_LOAD
, MI_ALU_SRCA
, src_reg
);
2006 append_alu(MI_ALU_LOAD
, MI_ALU_SRCB
, src_reg
);
2007 append_alu(MI_ALU_ADD
, 0, 0);
2010 /* Store ACCU to R1 and add R0 to R1 */
2011 append_alu(MI_ALU_STORE
, MI_ALU_REG1
, MI_ALU_ACCU
);
2012 append_alu(MI_ALU_LOAD
, MI_ALU_SRCA
, MI_ALU_REG0
);
2013 append_alu(MI_ALU_LOAD
, MI_ALU_SRCB
, MI_ALU_REG1
);
2014 append_alu(MI_ALU_ADD
, 0, 0);
2017 append_alu(MI_ALU_STORE
, dst_reg
, MI_ALU_ACCU
);
2024 emit_mul_gpr0(struct anv_batch
*batch
, uint32_t N
)
2026 uint32_t num_dwords
;
2027 build_alu_multiply_gpr0(NULL
, &num_dwords
, N
);
2029 uint32_t *dw
= anv_batch_emitn(batch
, 1 + num_dwords
, GENX(MI_MATH
));
2030 build_alu_multiply_gpr0(dw
+ 1, &num_dwords
, N
);
2033 #endif /* GEN_IS_HASWELL || GEN_GEN >= 8 */
2036 load_indirect_parameters(struct anv_cmd_buffer
*cmd_buffer
,
2037 struct anv_buffer
*buffer
, uint64_t offset
,
2040 struct anv_batch
*batch
= &cmd_buffer
->batch
;
2041 struct anv_bo
*bo
= buffer
->bo
;
2042 uint32_t bo_offset
= buffer
->offset
+ offset
;
2044 emit_lrm(batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
2046 unsigned view_count
= anv_subpass_view_count(cmd_buffer
->state
.subpass
);
2047 if (view_count
> 1) {
2048 #if GEN_IS_HASWELL || GEN_GEN >= 8
2049 emit_lrm(batch
, CS_GPR(0), bo
, bo_offset
+ 4);
2050 emit_mul_gpr0(batch
, view_count
);
2051 emit_lrr(batch
, GEN7_3DPRIM_INSTANCE_COUNT
, CS_GPR(0));
2053 anv_finishme("Multiview + indirect draw requires MI_MATH\n"
2054 "MI_MATH is not supported on Ivy Bridge");
2055 emit_lrm(batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
2058 emit_lrm(batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
2061 emit_lrm(batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
2064 emit_lrm(batch
, GEN7_3DPRIM_BASE_VERTEX
, bo
, bo_offset
+ 12);
2065 emit_lrm(batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 16);
2067 emit_lrm(batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 12);
2068 emit_lri(batch
, GEN7_3DPRIM_BASE_VERTEX
, 0);
2072 void genX(CmdDrawIndirect
)(
2073 VkCommandBuffer commandBuffer
,
2075 VkDeviceSize offset
,
2079 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
2080 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2081 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
2082 const struct brw_vs_prog_data
*vs_prog_data
= get_vs_prog_data(pipeline
);
2084 if (anv_batch_has_error(&cmd_buffer
->batch
))
2087 genX(cmd_buffer_flush_state
)(cmd_buffer
);
2089 for (uint32_t i
= 0; i
< drawCount
; i
++) {
2090 struct anv_bo
*bo
= buffer
->bo
;
2091 uint32_t bo_offset
= buffer
->offset
+ offset
;
2093 if (vs_prog_data
->uses_basevertex
|| vs_prog_data
->uses_baseinstance
)
2094 emit_base_vertex_instance_bo(cmd_buffer
, bo
, bo_offset
+ 8);
2095 if (vs_prog_data
->uses_drawid
)
2096 emit_draw_index(cmd_buffer
, i
);
2098 load_indirect_parameters(cmd_buffer
, buffer
, offset
, false);
2100 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DPRIMITIVE
), prim
) {
2101 prim
.IndirectParameterEnable
= true;
2102 prim
.VertexAccessType
= SEQUENTIAL
;
2103 prim
.PrimitiveTopologyType
= pipeline
->topology
;
2110 void genX(CmdDrawIndexedIndirect
)(
2111 VkCommandBuffer commandBuffer
,
2113 VkDeviceSize offset
,
2117 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
2118 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2119 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
2120 const struct brw_vs_prog_data
*vs_prog_data
= get_vs_prog_data(pipeline
);
2122 if (anv_batch_has_error(&cmd_buffer
->batch
))
2125 genX(cmd_buffer_flush_state
)(cmd_buffer
);
2127 for (uint32_t i
= 0; i
< drawCount
; i
++) {
2128 struct anv_bo
*bo
= buffer
->bo
;
2129 uint32_t bo_offset
= buffer
->offset
+ offset
;
2131 /* TODO: We need to stomp base vertex to 0 somehow */
2132 if (vs_prog_data
->uses_basevertex
|| vs_prog_data
->uses_baseinstance
)
2133 emit_base_vertex_instance_bo(cmd_buffer
, bo
, bo_offset
+ 12);
2134 if (vs_prog_data
->uses_drawid
)
2135 emit_draw_index(cmd_buffer
, i
);
2137 load_indirect_parameters(cmd_buffer
, buffer
, offset
, true);
2139 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DPRIMITIVE
), prim
) {
2140 prim
.IndirectParameterEnable
= true;
2141 prim
.VertexAccessType
= RANDOM
;
2142 prim
.PrimitiveTopologyType
= pipeline
->topology
;
2150 flush_compute_descriptor_set(struct anv_cmd_buffer
*cmd_buffer
)
2152 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.compute_pipeline
;
2153 struct anv_state surfaces
= { 0, }, samplers
= { 0, };
2156 result
= emit_binding_table(cmd_buffer
, MESA_SHADER_COMPUTE
, &surfaces
);
2157 if (result
!= VK_SUCCESS
) {
2158 assert(result
== VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2160 result
= anv_cmd_buffer_new_binding_table_block(cmd_buffer
);
2161 if (result
!= VK_SUCCESS
)
2164 /* Re-emit state base addresses so we get the new surface state base
2165 * address before we start emitting binding tables etc.
2167 genX(cmd_buffer_emit_state_base_address
)(cmd_buffer
);
2169 result
= emit_binding_table(cmd_buffer
, MESA_SHADER_COMPUTE
, &surfaces
);
2170 if (result
!= VK_SUCCESS
) {
2171 anv_batch_set_error(&cmd_buffer
->batch
, result
);
2176 result
= emit_samplers(cmd_buffer
, MESA_SHADER_COMPUTE
, &samplers
);
2177 if (result
!= VK_SUCCESS
) {
2178 anv_batch_set_error(&cmd_buffer
->batch
, result
);
2182 uint32_t iface_desc_data_dw
[GENX(INTERFACE_DESCRIPTOR_DATA_length
)];
2183 struct GENX(INTERFACE_DESCRIPTOR_DATA
) desc
= {
2184 .BindingTablePointer
= surfaces
.offset
,
2185 .SamplerStatePointer
= samplers
.offset
,
2187 GENX(INTERFACE_DESCRIPTOR_DATA_pack
)(NULL
, iface_desc_data_dw
, &desc
);
2189 struct anv_state state
=
2190 anv_cmd_buffer_merge_dynamic(cmd_buffer
, iface_desc_data_dw
,
2191 pipeline
->interface_descriptor_data
,
2192 GENX(INTERFACE_DESCRIPTOR_DATA_length
),
2195 uint32_t size
= GENX(INTERFACE_DESCRIPTOR_DATA_length
) * sizeof(uint32_t);
2196 anv_batch_emit(&cmd_buffer
->batch
,
2197 GENX(MEDIA_INTERFACE_DESCRIPTOR_LOAD
), mid
) {
2198 mid
.InterfaceDescriptorTotalLength
= size
;
2199 mid
.InterfaceDescriptorDataStartAddress
= state
.offset
;
2206 genX(cmd_buffer_flush_compute_state
)(struct anv_cmd_buffer
*cmd_buffer
)
2208 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.compute_pipeline
;
2209 MAYBE_UNUSED VkResult result
;
2211 assert(pipeline
->active_stages
== VK_SHADER_STAGE_COMPUTE_BIT
);
2213 genX(cmd_buffer_config_l3
)(cmd_buffer
, pipeline
->urb
.l3_config
);
2215 genX(flush_pipeline_select_gpgpu
)(cmd_buffer
);
2217 if (cmd_buffer
->state
.compute_dirty
& ANV_CMD_DIRTY_PIPELINE
) {
2218 /* From the Sky Lake PRM Vol 2a, MEDIA_VFE_STATE:
2220 * "A stalling PIPE_CONTROL is required before MEDIA_VFE_STATE unless
2221 * the only bits that are changed are scoreboard related: Scoreboard
2222 * Enable, Scoreboard Type, Scoreboard Mask, Scoreboard * Delta. For
2223 * these scoreboard related states, a MEDIA_STATE_FLUSH is
2226 cmd_buffer
->state
.pending_pipe_bits
|= ANV_PIPE_CS_STALL_BIT
;
2227 genX(cmd_buffer_apply_pipe_flushes
)(cmd_buffer
);
2229 anv_batch_emit_batch(&cmd_buffer
->batch
, &pipeline
->batch
);
2232 if ((cmd_buffer
->state
.descriptors_dirty
& VK_SHADER_STAGE_COMPUTE_BIT
) ||
2233 (cmd_buffer
->state
.compute_dirty
& ANV_CMD_DIRTY_PIPELINE
)) {
2234 /* FIXME: figure out descriptors for gen7 */
2235 result
= flush_compute_descriptor_set(cmd_buffer
);
2236 if (result
!= VK_SUCCESS
)
2239 cmd_buffer
->state
.descriptors_dirty
&= ~VK_SHADER_STAGE_COMPUTE_BIT
;
2242 if (cmd_buffer
->state
.push_constants_dirty
& VK_SHADER_STAGE_COMPUTE_BIT
) {
2243 struct anv_state push_state
=
2244 anv_cmd_buffer_cs_push_constants(cmd_buffer
);
2246 if (push_state
.alloc_size
) {
2247 anv_batch_emit(&cmd_buffer
->batch
, GENX(MEDIA_CURBE_LOAD
), curbe
) {
2248 curbe
.CURBETotalDataLength
= push_state
.alloc_size
;
2249 curbe
.CURBEDataStartAddress
= push_state
.offset
;
2254 cmd_buffer
->state
.compute_dirty
= 0;
2256 genX(cmd_buffer_apply_pipe_flushes
)(cmd_buffer
);
2262 verify_cmd_parser(const struct anv_device
*device
,
2263 int required_version
,
2264 const char *function
)
2266 if (device
->instance
->physicalDevice
.cmd_parser_version
< required_version
) {
2267 return vk_errorf(VK_ERROR_FEATURE_NOT_PRESENT
,
2268 "cmd parser version %d is required for %s",
2269 required_version
, function
);
2277 void genX(CmdDispatch
)(
2278 VkCommandBuffer commandBuffer
,
2283 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
2284 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.compute_pipeline
;
2285 const struct brw_cs_prog_data
*prog_data
= get_cs_prog_data(pipeline
);
2287 if (anv_batch_has_error(&cmd_buffer
->batch
))
2290 if (prog_data
->uses_num_work_groups
) {
2291 struct anv_state state
=
2292 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, 12, 4);
2293 uint32_t *sizes
= state
.map
;
2297 anv_state_flush(cmd_buffer
->device
, state
);
2298 cmd_buffer
->state
.num_workgroups_offset
= state
.offset
;
2299 cmd_buffer
->state
.num_workgroups_bo
=
2300 &cmd_buffer
->device
->dynamic_state_pool
.block_pool
.bo
;
2303 genX(cmd_buffer_flush_compute_state
)(cmd_buffer
);
2305 anv_batch_emit(&cmd_buffer
->batch
, GENX(GPGPU_WALKER
), ggw
) {
2306 ggw
.SIMDSize
= prog_data
->simd_size
/ 16;
2307 ggw
.ThreadDepthCounterMaximum
= 0;
2308 ggw
.ThreadHeightCounterMaximum
= 0;
2309 ggw
.ThreadWidthCounterMaximum
= prog_data
->threads
- 1;
2310 ggw
.ThreadGroupIDXDimension
= x
;
2311 ggw
.ThreadGroupIDYDimension
= y
;
2312 ggw
.ThreadGroupIDZDimension
= z
;
2313 ggw
.RightExecutionMask
= pipeline
->cs_right_mask
;
2314 ggw
.BottomExecutionMask
= 0xffffffff;
2317 anv_batch_emit(&cmd_buffer
->batch
, GENX(MEDIA_STATE_FLUSH
), msf
);
2320 #define GPGPU_DISPATCHDIMX 0x2500
2321 #define GPGPU_DISPATCHDIMY 0x2504
2322 #define GPGPU_DISPATCHDIMZ 0x2508
2324 #define MI_PREDICATE_SRC0 0x2400
2325 #define MI_PREDICATE_SRC1 0x2408
2327 void genX(CmdDispatchIndirect
)(
2328 VkCommandBuffer commandBuffer
,
2330 VkDeviceSize offset
)
2332 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
2333 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2334 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.compute_pipeline
;
2335 const struct brw_cs_prog_data
*prog_data
= get_cs_prog_data(pipeline
);
2336 struct anv_bo
*bo
= buffer
->bo
;
2337 uint32_t bo_offset
= buffer
->offset
+ offset
;
2338 struct anv_batch
*batch
= &cmd_buffer
->batch
;
2341 /* Linux 4.4 added command parser version 5 which allows the GPGPU
2342 * indirect dispatch registers to be written.
2344 if (verify_cmd_parser(cmd_buffer
->device
, 5,
2345 "vkCmdDispatchIndirect") != VK_SUCCESS
)
2349 if (prog_data
->uses_num_work_groups
) {
2350 cmd_buffer
->state
.num_workgroups_offset
= bo_offset
;
2351 cmd_buffer
->state
.num_workgroups_bo
= bo
;
2354 genX(cmd_buffer_flush_compute_state
)(cmd_buffer
);
2356 emit_lrm(batch
, GPGPU_DISPATCHDIMX
, bo
, bo_offset
);
2357 emit_lrm(batch
, GPGPU_DISPATCHDIMY
, bo
, bo_offset
+ 4);
2358 emit_lrm(batch
, GPGPU_DISPATCHDIMZ
, bo
, bo_offset
+ 8);
2361 /* Clear upper 32-bits of SRC0 and all 64-bits of SRC1 */
2362 emit_lri(batch
, MI_PREDICATE_SRC0
+ 4, 0);
2363 emit_lri(batch
, MI_PREDICATE_SRC1
+ 0, 0);
2364 emit_lri(batch
, MI_PREDICATE_SRC1
+ 4, 0);
2366 /* Load compute_dispatch_indirect_x_size into SRC0 */
2367 emit_lrm(batch
, MI_PREDICATE_SRC0
, bo
, bo_offset
+ 0);
2369 /* predicate = (compute_dispatch_indirect_x_size == 0); */
2370 anv_batch_emit(batch
, GENX(MI_PREDICATE
), mip
) {
2371 mip
.LoadOperation
= LOAD_LOAD
;
2372 mip
.CombineOperation
= COMBINE_SET
;
2373 mip
.CompareOperation
= COMPARE_SRCS_EQUAL
;
2376 /* Load compute_dispatch_indirect_y_size into SRC0 */
2377 emit_lrm(batch
, MI_PREDICATE_SRC0
, bo
, bo_offset
+ 4);
2379 /* predicate |= (compute_dispatch_indirect_y_size == 0); */
2380 anv_batch_emit(batch
, GENX(MI_PREDICATE
), mip
) {
2381 mip
.LoadOperation
= LOAD_LOAD
;
2382 mip
.CombineOperation
= COMBINE_OR
;
2383 mip
.CompareOperation
= COMPARE_SRCS_EQUAL
;
2386 /* Load compute_dispatch_indirect_z_size into SRC0 */
2387 emit_lrm(batch
, MI_PREDICATE_SRC0
, bo
, bo_offset
+ 8);
2389 /* predicate |= (compute_dispatch_indirect_z_size == 0); */
2390 anv_batch_emit(batch
, GENX(MI_PREDICATE
), mip
) {
2391 mip
.LoadOperation
= LOAD_LOAD
;
2392 mip
.CombineOperation
= COMBINE_OR
;
2393 mip
.CompareOperation
= COMPARE_SRCS_EQUAL
;
2396 /* predicate = !predicate; */
2397 #define COMPARE_FALSE 1
2398 anv_batch_emit(batch
, GENX(MI_PREDICATE
), mip
) {
2399 mip
.LoadOperation
= LOAD_LOADINV
;
2400 mip
.CombineOperation
= COMBINE_OR
;
2401 mip
.CompareOperation
= COMPARE_FALSE
;
2405 anv_batch_emit(batch
, GENX(GPGPU_WALKER
), ggw
) {
2406 ggw
.IndirectParameterEnable
= true;
2407 ggw
.PredicateEnable
= GEN_GEN
<= 7;
2408 ggw
.SIMDSize
= prog_data
->simd_size
/ 16;
2409 ggw
.ThreadDepthCounterMaximum
= 0;
2410 ggw
.ThreadHeightCounterMaximum
= 0;
2411 ggw
.ThreadWidthCounterMaximum
= prog_data
->threads
- 1;
2412 ggw
.RightExecutionMask
= pipeline
->cs_right_mask
;
2413 ggw
.BottomExecutionMask
= 0xffffffff;
2416 anv_batch_emit(batch
, GENX(MEDIA_STATE_FLUSH
), msf
);
2420 genX(flush_pipeline_select
)(struct anv_cmd_buffer
*cmd_buffer
,
2423 if (cmd_buffer
->state
.current_pipeline
== pipeline
)
2426 #if GEN_GEN >= 8 && GEN_GEN < 10
2427 /* From the Broadwell PRM, Volume 2a: Instructions, PIPELINE_SELECT:
2429 * Software must clear the COLOR_CALC_STATE Valid field in
2430 * 3DSTATE_CC_STATE_POINTERS command prior to send a PIPELINE_SELECT
2431 * with Pipeline Select set to GPGPU.
2433 * The internal hardware docs recommend the same workaround for Gen9
2436 if (pipeline
== GPGPU
)
2437 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_CC_STATE_POINTERS
), t
);
2440 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
2441 * PIPELINE_SELECT [DevBWR+]":
2445 * Software must ensure all the write caches are flushed through a
2446 * stalling PIPE_CONTROL command followed by another PIPE_CONTROL
2447 * command to invalidate read only caches prior to programming
2448 * MI_PIPELINE_SELECT command to change the Pipeline Select Mode.
2450 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pc
) {
2451 pc
.RenderTargetCacheFlushEnable
= true;
2452 pc
.DepthCacheFlushEnable
= true;
2453 pc
.DCFlushEnable
= true;
2454 pc
.PostSyncOperation
= NoWrite
;
2455 pc
.CommandStreamerStallEnable
= true;
2458 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pc
) {
2459 pc
.TextureCacheInvalidationEnable
= true;
2460 pc
.ConstantCacheInvalidationEnable
= true;
2461 pc
.StateCacheInvalidationEnable
= true;
2462 pc
.InstructionCacheInvalidateEnable
= true;
2463 pc
.PostSyncOperation
= NoWrite
;
2466 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPELINE_SELECT
), ps
) {
2470 ps
.PipelineSelection
= pipeline
;
2473 cmd_buffer
->state
.current_pipeline
= pipeline
;
2477 genX(flush_pipeline_select_3d
)(struct anv_cmd_buffer
*cmd_buffer
)
2479 genX(flush_pipeline_select
)(cmd_buffer
, _3D
);
2483 genX(flush_pipeline_select_gpgpu
)(struct anv_cmd_buffer
*cmd_buffer
)
2485 genX(flush_pipeline_select
)(cmd_buffer
, GPGPU
);
2489 genX(cmd_buffer_emit_gen7_depth_flush
)(struct anv_cmd_buffer
*cmd_buffer
)
2494 /* From the Haswell PRM, documentation for 3DSTATE_DEPTH_BUFFER:
2496 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e., any
2497 * combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
2498 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
2499 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
2500 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
2501 * Depth Flush Bit set, followed by another pipelined depth stall
2502 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
2503 * guarantee that the pipeline from WM onwards is already flushed (e.g.,
2504 * via a preceding MI_FLUSH)."
2506 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pipe
) {
2507 pipe
.DepthStallEnable
= true;
2509 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pipe
) {
2510 pipe
.DepthCacheFlushEnable
= true;
2512 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
), pipe
) {
2513 pipe
.DepthStallEnable
= true;
2518 cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer
*cmd_buffer
)
2520 struct anv_device
*device
= cmd_buffer
->device
;
2521 const struct anv_image_view
*iview
=
2522 anv_cmd_buffer_get_depth_stencil_view(cmd_buffer
);
2523 const struct anv_image
*image
= iview
? iview
->image
: NULL
;
2525 /* FIXME: Width and Height are wrong */
2527 genX(cmd_buffer_emit_gen7_depth_flush
)(cmd_buffer
);
2529 uint32_t *dw
= anv_batch_emit_dwords(&cmd_buffer
->batch
,
2530 device
->isl_dev
.ds
.size
/ 4);
2534 struct isl_depth_stencil_hiz_emit_info info
= {
2535 .mocs
= device
->default_mocs
,
2539 info
.view
= &iview
->isl
;
2541 if (image
&& (image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
)) {
2542 info
.depth_surf
= &image
->depth_surface
.isl
;
2544 info
.depth_address
=
2545 anv_batch_emit_reloc(&cmd_buffer
->batch
,
2546 dw
+ device
->isl_dev
.ds
.depth_offset
/ 4,
2548 image
->offset
+ image
->depth_surface
.offset
);
2551 cmd_buffer
->state
.subpass
->depth_stencil_attachment
.attachment
;
2552 info
.hiz_usage
= cmd_buffer
->state
.attachments
[ds
].aux_usage
;
2553 if (info
.hiz_usage
== ISL_AUX_USAGE_HIZ
) {
2554 info
.hiz_surf
= &image
->aux_surface
.isl
;
2557 anv_batch_emit_reloc(&cmd_buffer
->batch
,
2558 dw
+ device
->isl_dev
.ds
.hiz_offset
/ 4,
2560 image
->offset
+ image
->aux_surface
.offset
);
2562 info
.depth_clear_value
= ANV_HZ_FC_VAL
;
2566 if (image
&& (image
->aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
)) {
2567 info
.stencil_surf
= &image
->stencil_surface
.isl
;
2569 info
.stencil_address
=
2570 anv_batch_emit_reloc(&cmd_buffer
->batch
,
2571 dw
+ device
->isl_dev
.ds
.stencil_offset
/ 4,
2573 image
->offset
+ image
->stencil_surface
.offset
);
2576 isl_emit_depth_stencil_hiz_s(&device
->isl_dev
, dw
, &info
);
2578 cmd_buffer
->state
.hiz_enabled
= info
.hiz_usage
== ISL_AUX_USAGE_HIZ
;
2583 * @brief Perform any layout transitions required at the beginning and/or end
2584 * of the current subpass for depth buffers.
2586 * TODO: Consider preprocessing the attachment reference array at render pass
2587 * create time to determine if no layout transition is needed at the
2588 * beginning and/or end of each subpass.
2590 * @param cmd_buffer The command buffer the transition is happening within.
2591 * @param subpass_end If true, marks that the transition is happening at the
2592 * end of the subpass.
2595 cmd_buffer_subpass_transition_layouts(struct anv_cmd_buffer
* const cmd_buffer
,
2596 const bool subpass_end
)
2598 /* We need a non-NULL command buffer. */
2601 const struct anv_cmd_state
* const cmd_state
= &cmd_buffer
->state
;
2602 const struct anv_subpass
* const subpass
= cmd_state
->subpass
;
2604 /* This function must be called within a subpass. */
2607 /* If there are attachment references, the array shouldn't be NULL.
2609 if (subpass
->attachment_count
> 0)
2610 assert(subpass
->attachments
);
2612 /* Iterate over the array of attachment references. */
2613 for (const VkAttachmentReference
*att_ref
= subpass
->attachments
;
2614 att_ref
< subpass
->attachments
+ subpass
->attachment_count
; att_ref
++) {
2616 /* If the attachment is unused, we can't perform a layout transition. */
2617 if (att_ref
->attachment
== VK_ATTACHMENT_UNUSED
)
2620 /* This attachment index shouldn't go out of bounds. */
2621 assert(att_ref
->attachment
< cmd_state
->pass
->attachment_count
);
2623 const struct anv_render_pass_attachment
* const att_desc
=
2624 &cmd_state
->pass
->attachments
[att_ref
->attachment
];
2625 struct anv_attachment_state
* const att_state
=
2626 &cmd_buffer
->state
.attachments
[att_ref
->attachment
];
2628 /* The attachment should not be used in a subpass after its last. */
2629 assert(att_desc
->last_subpass_idx
>= anv_get_subpass_id(cmd_state
));
2631 if (subpass_end
&& anv_get_subpass_id(cmd_state
) <
2632 att_desc
->last_subpass_idx
) {
2633 /* We're calling this function on a buffer twice in one subpass and
2634 * this is not the last use of the buffer. The layout should not have
2635 * changed from the first call and no transition is necessary.
2637 assert(att_ref
->layout
== att_state
->current_layout
);
2641 /* Get the appropriate target layout for this attachment. */
2642 const VkImageLayout target_layout
= subpass_end
?
2643 att_desc
->final_layout
: att_ref
->layout
;
2645 /* The attachment index must be less than the number of attachments
2646 * within the framebuffer.
2648 assert(att_ref
->attachment
< cmd_state
->framebuffer
->attachment_count
);
2650 const struct anv_image_view
* const iview
=
2651 cmd_state
->framebuffer
->attachments
[att_ref
->attachment
];
2652 const struct anv_image
* const image
= iview
->image
;
2654 /* Perform the layout transition. */
2655 if (image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
2656 transition_depth_buffer(cmd_buffer
, image
,
2657 att_state
->current_layout
, target_layout
);
2658 att_state
->aux_usage
=
2659 anv_layout_to_aux_usage(&cmd_buffer
->device
->info
, image
,
2660 image
->aspects
, target_layout
);
2661 } else if (image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
) {
2662 transition_color_buffer(cmd_buffer
, image
,
2663 iview
->isl
.base_level
, 1,
2664 iview
->isl
.base_array_layer
,
2665 iview
->isl
.array_len
,
2666 att_state
->current_layout
, target_layout
);
2669 att_state
->current_layout
= target_layout
;
2673 /* Update the clear value dword(s) in surface state objects or the fast clear
2674 * state buffer entry for the color attachments used in this subpass.
2677 cmd_buffer_subpass_sync_fast_clear_values(struct anv_cmd_buffer
*cmd_buffer
)
2679 assert(cmd_buffer
&& cmd_buffer
->state
.subpass
);
2681 const struct anv_cmd_state
*state
= &cmd_buffer
->state
;
2683 /* Iterate through every color attachment used in this subpass. */
2684 for (uint32_t i
= 0; i
< state
->subpass
->color_count
; ++i
) {
2686 /* The attachment should be one of the attachments described in the
2687 * render pass and used in the subpass.
2689 const uint32_t a
= state
->subpass
->color_attachments
[i
].attachment
;
2690 assert(a
< state
->pass
->attachment_count
);
2691 if (a
== VK_ATTACHMENT_UNUSED
)
2694 /* Store some information regarding this attachment. */
2695 const struct anv_attachment_state
*att_state
= &state
->attachments
[a
];
2696 const struct anv_image_view
*iview
= state
->framebuffer
->attachments
[a
];
2697 const struct anv_render_pass_attachment
*rp_att
=
2698 &state
->pass
->attachments
[a
];
2700 if (att_state
->aux_usage
== ISL_AUX_USAGE_NONE
)
2703 /* The fast clear state entry must be updated if a fast clear is going to
2704 * happen. The surface state must be updated if the clear value from a
2705 * prior fast clear may be needed.
2707 if (att_state
->pending_clear_aspects
&& att_state
->fast_clear
) {
2708 /* Update the fast clear state entry. */
2709 genX(copy_fast_clear_dwords
)(cmd_buffer
, att_state
->color_rt_state
,
2710 iview
->image
, iview
->isl
.base_level
,
2711 true /* copy from ss */);
2712 } else if (rp_att
->load_op
== VK_ATTACHMENT_LOAD_OP_LOAD
) {
2713 /* The attachment may have been fast-cleared in a previous render
2714 * pass and the value is needed now. Update the surface state(s).
2716 * TODO: Do this only once per render pass instead of every subpass.
2718 genX(copy_fast_clear_dwords
)(cmd_buffer
, att_state
->color_rt_state
,
2719 iview
->image
, iview
->isl
.base_level
,
2720 false /* copy to ss */);
2722 if (need_input_attachment_state(rp_att
) &&
2723 att_state
->input_aux_usage
!= ISL_AUX_USAGE_NONE
) {
2724 genX(copy_fast_clear_dwords
)(cmd_buffer
, att_state
->input_att_state
,
2725 iview
->image
, iview
->isl
.base_level
,
2726 false /* copy to ss */);
2734 genX(cmd_buffer_set_subpass
)(struct anv_cmd_buffer
*cmd_buffer
,
2735 struct anv_subpass
*subpass
)
2737 cmd_buffer
->state
.subpass
= subpass
;
2739 cmd_buffer
->state
.dirty
|= ANV_CMD_DIRTY_RENDER_TARGETS
;
2741 /* Our implementation of VK_KHR_multiview uses instancing to draw the
2742 * different views. If the client asks for instancing, we need to use the
2743 * Instance Data Step Rate to ensure that we repeat the client's
2744 * per-instance data once for each view. Since this bit is in
2745 * VERTEX_BUFFER_STATE on gen7, we need to dirty vertex buffers at the top
2749 cmd_buffer
->state
.vb_dirty
|= ~0;
2751 /* Perform transitions to the subpass layout before any writes have
2754 cmd_buffer_subpass_transition_layouts(cmd_buffer
, false);
2756 /* Update clear values *after* performing automatic layout transitions.
2757 * This ensures that transitions from the UNDEFINED layout have had a chance
2758 * to populate the clear value buffer with the correct values for the
2759 * LOAD_OP_LOAD loadOp and that the fast-clears will update the buffer
2760 * without the aforementioned layout transition overwriting the fast-clear
2763 cmd_buffer_subpass_sync_fast_clear_values(cmd_buffer
);
2765 cmd_buffer_emit_depth_stencil(cmd_buffer
);
2767 anv_cmd_buffer_clear_subpass(cmd_buffer
);
2770 void genX(CmdBeginRenderPass
)(
2771 VkCommandBuffer commandBuffer
,
2772 const VkRenderPassBeginInfo
* pRenderPassBegin
,
2773 VkSubpassContents contents
)
2775 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
2776 ANV_FROM_HANDLE(anv_render_pass
, pass
, pRenderPassBegin
->renderPass
);
2777 ANV_FROM_HANDLE(anv_framebuffer
, framebuffer
, pRenderPassBegin
->framebuffer
);
2779 cmd_buffer
->state
.framebuffer
= framebuffer
;
2780 cmd_buffer
->state
.pass
= pass
;
2781 cmd_buffer
->state
.render_area
= pRenderPassBegin
->renderArea
;
2783 genX(cmd_buffer_setup_attachments
)(cmd_buffer
, pass
, pRenderPassBegin
);
2785 /* If we failed to setup the attachments we should not try to go further */
2786 if (result
!= VK_SUCCESS
) {
2787 assert(anv_batch_has_error(&cmd_buffer
->batch
));
2791 genX(flush_pipeline_select_3d
)(cmd_buffer
);
2793 genX(cmd_buffer_set_subpass
)(cmd_buffer
, pass
->subpasses
);
2795 cmd_buffer
->state
.pending_pipe_bits
|=
2796 cmd_buffer
->state
.pass
->subpass_flushes
[0];
2799 void genX(CmdNextSubpass
)(
2800 VkCommandBuffer commandBuffer
,
2801 VkSubpassContents contents
)
2803 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
2805 if (anv_batch_has_error(&cmd_buffer
->batch
))
2808 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2810 anv_cmd_buffer_resolve_subpass(cmd_buffer
);
2812 /* Perform transitions to the final layout after all writes have occurred.
2814 cmd_buffer_subpass_transition_layouts(cmd_buffer
, true);
2816 genX(cmd_buffer_set_subpass
)(cmd_buffer
, cmd_buffer
->state
.subpass
+ 1);
2818 uint32_t subpass_id
= anv_get_subpass_id(&cmd_buffer
->state
);
2819 cmd_buffer
->state
.pending_pipe_bits
|=
2820 cmd_buffer
->state
.pass
->subpass_flushes
[subpass_id
];
2823 void genX(CmdEndRenderPass
)(
2824 VkCommandBuffer commandBuffer
)
2826 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
2828 if (anv_batch_has_error(&cmd_buffer
->batch
))
2831 anv_cmd_buffer_resolve_subpass(cmd_buffer
);
2833 /* Perform transitions to the final layout after all writes have occurred.
2835 cmd_buffer_subpass_transition_layouts(cmd_buffer
, true);
2837 cmd_buffer
->state
.pending_pipe_bits
|=
2838 cmd_buffer
->state
.pass
->subpass_flushes
[cmd_buffer
->state
.pass
->subpass_count
];
2840 cmd_buffer
->state
.hiz_enabled
= false;
2843 anv_dump_add_framebuffer(cmd_buffer
, cmd_buffer
->state
.framebuffer
);
2846 /* Remove references to render pass specific state. This enables us to
2847 * detect whether or not we're in a renderpass.
2849 cmd_buffer
->state
.framebuffer
= NULL
;
2850 cmd_buffer
->state
.pass
= NULL
;
2851 cmd_buffer
->state
.subpass
= NULL
;