anv: Add helpers to handle depth buffer layout transitions
[mesa.git] / src / intel / vulkan / genX_cmd_buffer.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25 #include <stdbool.h>
26
27 #include "anv_private.h"
28 #include "vk_format_info.h"
29
30 #include "common/gen_l3_config.h"
31 #include "genxml/gen_macros.h"
32 #include "genxml/genX_pack.h"
33
34 static void
35 emit_lrm(struct anv_batch *batch,
36 uint32_t reg, struct anv_bo *bo, uint32_t offset)
37 {
38 anv_batch_emit(batch, GENX(MI_LOAD_REGISTER_MEM), lrm) {
39 lrm.RegisterAddress = reg;
40 lrm.MemoryAddress = (struct anv_address) { bo, offset };
41 }
42 }
43
44 static void
45 emit_lri(struct anv_batch *batch, uint32_t reg, uint32_t imm)
46 {
47 anv_batch_emit(batch, GENX(MI_LOAD_REGISTER_IMM), lri) {
48 lri.RegisterOffset = reg;
49 lri.DataDWord = imm;
50 }
51 }
52
53 void
54 genX(cmd_buffer_emit_state_base_address)(struct anv_cmd_buffer *cmd_buffer)
55 {
56 struct anv_device *device = cmd_buffer->device;
57
58 /* XXX: Do we need this on more than just BDW? */
59 #if (GEN_GEN >= 8)
60 /* Emit a render target cache flush.
61 *
62 * This isn't documented anywhere in the PRM. However, it seems to be
63 * necessary prior to changing the surface state base adress. Without
64 * this, we get GPU hangs when using multi-level command buffers which
65 * clear depth, reset state base address, and then go render stuff.
66 */
67 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
68 pc.RenderTargetCacheFlushEnable = true;
69 }
70 #endif
71
72 anv_batch_emit(&cmd_buffer->batch, GENX(STATE_BASE_ADDRESS), sba) {
73 sba.GeneralStateBaseAddress = (struct anv_address) { NULL, 0 };
74 sba.GeneralStateMemoryObjectControlState = GENX(MOCS);
75 sba.GeneralStateBaseAddressModifyEnable = true;
76
77 sba.SurfaceStateBaseAddress =
78 anv_cmd_buffer_surface_base_address(cmd_buffer);
79 sba.SurfaceStateMemoryObjectControlState = GENX(MOCS);
80 sba.SurfaceStateBaseAddressModifyEnable = true;
81
82 sba.DynamicStateBaseAddress =
83 (struct anv_address) { &device->dynamic_state_block_pool.bo, 0 };
84 sba.DynamicStateMemoryObjectControlState = GENX(MOCS);
85 sba.DynamicStateBaseAddressModifyEnable = true;
86
87 sba.IndirectObjectBaseAddress = (struct anv_address) { NULL, 0 };
88 sba.IndirectObjectMemoryObjectControlState = GENX(MOCS);
89 sba.IndirectObjectBaseAddressModifyEnable = true;
90
91 sba.InstructionBaseAddress =
92 (struct anv_address) { &device->instruction_block_pool.bo, 0 };
93 sba.InstructionMemoryObjectControlState = GENX(MOCS);
94 sba.InstructionBaseAddressModifyEnable = true;
95
96 # if (GEN_GEN >= 8)
97 /* Broadwell requires that we specify a buffer size for a bunch of
98 * these fields. However, since we will be growing the BO's live, we
99 * just set them all to the maximum.
100 */
101 sba.GeneralStateBufferSize = 0xfffff;
102 sba.GeneralStateBufferSizeModifyEnable = true;
103 sba.DynamicStateBufferSize = 0xfffff;
104 sba.DynamicStateBufferSizeModifyEnable = true;
105 sba.IndirectObjectBufferSize = 0xfffff;
106 sba.IndirectObjectBufferSizeModifyEnable = true;
107 sba.InstructionBufferSize = 0xfffff;
108 sba.InstructionBuffersizeModifyEnable = true;
109 # endif
110 }
111
112 /* After re-setting the surface state base address, we have to do some
113 * cache flusing so that the sampler engine will pick up the new
114 * SURFACE_STATE objects and binding tables. From the Broadwell PRM,
115 * Shared Function > 3D Sampler > State > State Caching (page 96):
116 *
117 * Coherency with system memory in the state cache, like the texture
118 * cache is handled partially by software. It is expected that the
119 * command stream or shader will issue Cache Flush operation or
120 * Cache_Flush sampler message to ensure that the L1 cache remains
121 * coherent with system memory.
122 *
123 * [...]
124 *
125 * Whenever the value of the Dynamic_State_Base_Addr,
126 * Surface_State_Base_Addr are altered, the L1 state cache must be
127 * invalidated to ensure the new surface or sampler state is fetched
128 * from system memory.
129 *
130 * The PIPE_CONTROL command has a "State Cache Invalidation Enable" bit
131 * which, according the PIPE_CONTROL instruction documentation in the
132 * Broadwell PRM:
133 *
134 * Setting this bit is independent of any other bit in this packet.
135 * This bit controls the invalidation of the L1 and L2 state caches
136 * at the top of the pipe i.e. at the parsing time.
137 *
138 * Unfortunately, experimentation seems to indicate that state cache
139 * invalidation through a PIPE_CONTROL does nothing whatsoever in
140 * regards to surface state and binding tables. In stead, it seems that
141 * invalidating the texture cache is what is actually needed.
142 *
143 * XXX: As far as we have been able to determine through
144 * experimentation, shows that flush the texture cache appears to be
145 * sufficient. The theory here is that all of the sampling/rendering
146 * units cache the binding table in the texture cache. However, we have
147 * yet to be able to actually confirm this.
148 */
149 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
150 pc.TextureCacheInvalidationEnable = true;
151 }
152 }
153
154 static void
155 add_surface_state_reloc(struct anv_cmd_buffer *cmd_buffer,
156 struct anv_state state,
157 struct anv_bo *bo, uint32_t offset)
158 {
159 const struct isl_device *isl_dev = &cmd_buffer->device->isl_dev;
160
161 anv_reloc_list_add(&cmd_buffer->surface_relocs, &cmd_buffer->pool->alloc,
162 state.offset + isl_dev->ss.addr_offset, bo, offset);
163 }
164
165 static void
166 add_image_view_relocs(struct anv_cmd_buffer *cmd_buffer,
167 const struct anv_image_view *iview,
168 enum isl_aux_usage aux_usage,
169 struct anv_state state)
170 {
171 const struct isl_device *isl_dev = &cmd_buffer->device->isl_dev;
172
173 anv_reloc_list_add(&cmd_buffer->surface_relocs, &cmd_buffer->pool->alloc,
174 state.offset + isl_dev->ss.addr_offset,
175 iview->bo, iview->offset);
176
177 if (aux_usage != ISL_AUX_USAGE_NONE) {
178 uint32_t aux_offset = iview->offset + iview->image->aux_surface.offset;
179
180 /* On gen7 and prior, the bottom 12 bits of the MCS base address are
181 * used to store other information. This should be ok, however, because
182 * surface buffer addresses are always 4K page alinged.
183 */
184 assert((aux_offset & 0xfff) == 0);
185 uint32_t *aux_addr_dw = state.map + isl_dev->ss.aux_addr_offset;
186 aux_offset += *aux_addr_dw & 0xfff;
187
188 anv_reloc_list_add(&cmd_buffer->surface_relocs, &cmd_buffer->pool->alloc,
189 state.offset + isl_dev->ss.aux_addr_offset,
190 iview->bo, aux_offset);
191 }
192 }
193
194 static bool
195 color_is_zero_one(VkClearColorValue value, enum isl_format format)
196 {
197 if (isl_format_has_int_channel(format)) {
198 for (unsigned i = 0; i < 4; i++) {
199 if (value.int32[i] != 0 && value.int32[i] != 1)
200 return false;
201 }
202 } else {
203 for (unsigned i = 0; i < 4; i++) {
204 if (value.float32[i] != 0.0f && value.float32[i] != 1.0f)
205 return false;
206 }
207 }
208
209 return true;
210 }
211
212 static void
213 color_attachment_compute_aux_usage(struct anv_device *device,
214 struct anv_attachment_state *att_state,
215 struct anv_image_view *iview,
216 VkRect2D render_area,
217 union isl_color_value *fast_clear_color)
218 {
219 if (iview->image->aux_surface.isl.size == 0) {
220 att_state->aux_usage = ISL_AUX_USAGE_NONE;
221 att_state->input_aux_usage = ISL_AUX_USAGE_NONE;
222 att_state->fast_clear = false;
223 return;
224 }
225
226 assert(iview->image->aux_surface.isl.usage & ISL_SURF_USAGE_CCS_BIT);
227
228 att_state->clear_color_is_zero_one =
229 color_is_zero_one(att_state->clear_value.color, iview->isl.format);
230
231 if (att_state->pending_clear_aspects == VK_IMAGE_ASPECT_COLOR_BIT) {
232 /* Start off assuming fast clears are possible */
233 att_state->fast_clear = true;
234
235 /* Potentially, we could do partial fast-clears but doing so has crazy
236 * alignment restrictions. It's easier to just restrict to full size
237 * fast clears for now.
238 */
239 if (render_area.offset.x != 0 ||
240 render_area.offset.y != 0 ||
241 render_area.extent.width != iview->extent.width ||
242 render_area.extent.height != iview->extent.height)
243 att_state->fast_clear = false;
244
245 if (GEN_GEN <= 7) {
246 /* On gen7, we can't do multi-LOD or multi-layer fast-clears. We
247 * technically can, but it comes with crazy restrictions that we
248 * don't want to deal with now.
249 */
250 if (iview->isl.base_level > 0 ||
251 iview->isl.base_array_layer > 0 ||
252 iview->isl.array_len > 1)
253 att_state->fast_clear = false;
254 }
255
256 /* On Broadwell and earlier, we can only handle 0/1 clear colors */
257 if (GEN_GEN <= 8 && !att_state->clear_color_is_zero_one)
258 att_state->fast_clear = false;
259
260 if (att_state->fast_clear) {
261 memcpy(fast_clear_color->u32, att_state->clear_value.color.uint32,
262 sizeof(fast_clear_color->u32));
263 }
264 } else {
265 att_state->fast_clear = false;
266 }
267
268 if (isl_format_supports_lossless_compression(&device->info,
269 iview->isl.format)) {
270 att_state->aux_usage = ISL_AUX_USAGE_CCS_E;
271 att_state->input_aux_usage = ISL_AUX_USAGE_CCS_E;
272 } else if (att_state->fast_clear) {
273 att_state->aux_usage = ISL_AUX_USAGE_CCS_D;
274 if (GEN_GEN >= 9) {
275 /* From the Sky Lake PRM, RENDER_SURFACE_STATE::AuxiliarySurfaceMode:
276 *
277 * "If Number of Multisamples is MULTISAMPLECOUNT_1, AUX_CCS_D
278 * setting is only allowed if Surface Format supported for Fast
279 * Clear. In addition, if the surface is bound to the sampling
280 * engine, Surface Format must be supported for Render Target
281 * Compression for surfaces bound to the sampling engine."
282 *
283 * In other words, we can't sample from a fast-cleared image if it
284 * doesn't also support color compression.
285 */
286 att_state->input_aux_usage = ISL_AUX_USAGE_NONE;
287 } else if (GEN_GEN == 8) {
288 /* Broadwell can sample from fast-cleared images */
289 att_state->input_aux_usage = ISL_AUX_USAGE_CCS_D;
290 } else {
291 /* Ivy Bridge and Haswell cannot */
292 att_state->input_aux_usage = ISL_AUX_USAGE_NONE;
293 }
294 } else {
295 att_state->aux_usage = ISL_AUX_USAGE_NONE;
296 att_state->input_aux_usage = ISL_AUX_USAGE_NONE;
297 }
298 }
299
300 static bool
301 need_input_attachment_state(const struct anv_render_pass_attachment *att)
302 {
303 if (!(att->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT))
304 return false;
305
306 /* We only allocate input attachment states for color and depth surfaces.
307 * Stencil doesn't allow compression so we can just use the texture surface
308 * state from the view
309 */
310 return vk_format_is_color(att->format) || vk_format_has_depth(att->format);
311 }
312
313 static enum isl_aux_usage
314 layout_to_hiz_usage(VkImageLayout layout)
315 {
316 switch (layout) {
317 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
318 return ISL_AUX_USAGE_HIZ;
319 default:
320 return ISL_AUX_USAGE_NONE;
321 }
322 }
323
324 /* Transitions a HiZ-enabled depth buffer from one layout to another. Unless
325 * the initial layout is undefined, the HiZ buffer and depth buffer will
326 * represent the same data at the end of this operation.
327 */
328 static void
329 transition_depth_buffer(struct anv_cmd_buffer *cmd_buffer,
330 const struct anv_image *image,
331 VkImageLayout initial_layout,
332 VkImageLayout final_layout)
333 {
334 assert(image);
335
336 if (image->aux_usage != ISL_AUX_USAGE_HIZ)
337 return;
338
339 const bool hiz_enabled = layout_to_hiz_usage(initial_layout) ==
340 ISL_AUX_USAGE_HIZ;
341 const bool enable_hiz = layout_to_hiz_usage(final_layout) ==
342 ISL_AUX_USAGE_HIZ;
343
344 /* We've already initialized the aux HiZ buffer at BindImageMemory time,
345 * so there's no need to perform a HIZ resolve or clear to avoid GPU hangs.
346 * This initial layout indicates that the user doesn't care about the data
347 * that's currently in the buffer, so no resolves are necessary.
348 */
349 if (initial_layout == VK_IMAGE_LAYOUT_UNDEFINED)
350 return;
351
352 if (hiz_enabled == enable_hiz) {
353 /* The same buffer will be used, no resolves are necessary */
354 } else if (hiz_enabled && !enable_hiz) {
355 anv_gen8_hiz_op_resolve(cmd_buffer, image, BLORP_HIZ_OP_DEPTH_RESOLVE);
356 } else {
357 assert(!hiz_enabled && enable_hiz);
358 anv_gen8_hiz_op_resolve(cmd_buffer, image, BLORP_HIZ_OP_HIZ_RESOLVE);
359 }
360 }
361
362
363 /**
364 * Setup anv_cmd_state::attachments for vkCmdBeginRenderPass.
365 */
366 static void
367 genX(cmd_buffer_setup_attachments)(struct anv_cmd_buffer *cmd_buffer,
368 struct anv_render_pass *pass,
369 const VkRenderPassBeginInfo *begin)
370 {
371 const struct isl_device *isl_dev = &cmd_buffer->device->isl_dev;
372 struct anv_cmd_state *state = &cmd_buffer->state;
373
374 vk_free(&cmd_buffer->pool->alloc, state->attachments);
375
376 if (pass->attachment_count == 0) {
377 state->attachments = NULL;
378 return;
379 }
380
381 state->attachments = vk_alloc(&cmd_buffer->pool->alloc,
382 pass->attachment_count *
383 sizeof(state->attachments[0]),
384 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
385 if (state->attachments == NULL) {
386 /* FIXME: Propagate VK_ERROR_OUT_OF_HOST_MEMORY to vkEndCommandBuffer */
387 abort();
388 }
389
390 bool need_null_state = false;
391 unsigned num_states = 0;
392 for (uint32_t i = 0; i < pass->attachment_count; ++i) {
393 if (vk_format_is_color(pass->attachments[i].format)) {
394 num_states++;
395 } else {
396 /* We need a null state for any depth-stencil-only subpasses.
397 * Importantly, this includes depth/stencil clears so we create one
398 * whenever we have depth or stencil
399 */
400 need_null_state = true;
401 }
402
403 if (need_input_attachment_state(&pass->attachments[i]))
404 num_states++;
405 }
406 num_states += need_null_state;
407
408 const uint32_t ss_stride = align_u32(isl_dev->ss.size, isl_dev->ss.align);
409 state->render_pass_states =
410 anv_state_stream_alloc(&cmd_buffer->surface_state_stream,
411 num_states * ss_stride, isl_dev->ss.align);
412
413 struct anv_state next_state = state->render_pass_states;
414 next_state.alloc_size = isl_dev->ss.size;
415
416 if (need_null_state) {
417 state->null_surface_state = next_state;
418 next_state.offset += ss_stride;
419 next_state.map += ss_stride;
420 }
421
422 for (uint32_t i = 0; i < pass->attachment_count; ++i) {
423 if (vk_format_is_color(pass->attachments[i].format)) {
424 state->attachments[i].color_rt_state = next_state;
425 next_state.offset += ss_stride;
426 next_state.map += ss_stride;
427 }
428
429 if (need_input_attachment_state(&pass->attachments[i])) {
430 state->attachments[i].input_att_state = next_state;
431 next_state.offset += ss_stride;
432 next_state.map += ss_stride;
433 }
434 }
435 assert(next_state.offset == state->render_pass_states.offset +
436 state->render_pass_states.alloc_size);
437
438 if (begin) {
439 ANV_FROM_HANDLE(anv_framebuffer, framebuffer, begin->framebuffer);
440 assert(pass->attachment_count == framebuffer->attachment_count);
441
442 if (need_null_state) {
443 struct GENX(RENDER_SURFACE_STATE) null_ss = {
444 .SurfaceType = SURFTYPE_NULL,
445 .SurfaceArray = framebuffer->layers > 0,
446 .SurfaceFormat = ISL_FORMAT_R8G8B8A8_UNORM,
447 #if GEN_GEN >= 8
448 .TileMode = YMAJOR,
449 #else
450 .TiledSurface = true,
451 #endif
452 .Width = framebuffer->width - 1,
453 .Height = framebuffer->height - 1,
454 .Depth = framebuffer->layers - 1,
455 .RenderTargetViewExtent = framebuffer->layers - 1,
456 };
457 GENX(RENDER_SURFACE_STATE_pack)(NULL, state->null_surface_state.map,
458 &null_ss);
459 }
460
461 for (uint32_t i = 0; i < pass->attachment_count; ++i) {
462 struct anv_render_pass_attachment *att = &pass->attachments[i];
463 VkImageAspectFlags att_aspects = vk_format_aspects(att->format);
464 VkImageAspectFlags clear_aspects = 0;
465
466 if (att_aspects == VK_IMAGE_ASPECT_COLOR_BIT) {
467 /* color attachment */
468 if (att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
469 clear_aspects |= VK_IMAGE_ASPECT_COLOR_BIT;
470 }
471 } else {
472 /* depthstencil attachment */
473 if ((att_aspects & VK_IMAGE_ASPECT_DEPTH_BIT) &&
474 att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
475 clear_aspects |= VK_IMAGE_ASPECT_DEPTH_BIT;
476 }
477 if ((att_aspects & VK_IMAGE_ASPECT_STENCIL_BIT) &&
478 att->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
479 clear_aspects |= VK_IMAGE_ASPECT_STENCIL_BIT;
480 }
481 }
482
483 state->attachments[i].pending_clear_aspects = clear_aspects;
484 if (clear_aspects)
485 state->attachments[i].clear_value = begin->pClearValues[i];
486
487 struct anv_image_view *iview = framebuffer->attachments[i];
488 assert(iview->vk_format == att->format);
489
490 union isl_color_value clear_color = { .u32 = { 0, } };
491 if (att_aspects == VK_IMAGE_ASPECT_COLOR_BIT) {
492 color_attachment_compute_aux_usage(cmd_buffer->device,
493 &state->attachments[i],
494 iview, begin->renderArea,
495 &clear_color);
496
497 struct isl_view view = iview->isl;
498 view.usage |= ISL_SURF_USAGE_RENDER_TARGET_BIT;
499 isl_surf_fill_state(isl_dev,
500 state->attachments[i].color_rt_state.map,
501 .surf = &iview->image->color_surface.isl,
502 .view = &view,
503 .aux_surf = &iview->image->aux_surface.isl,
504 .aux_usage = state->attachments[i].aux_usage,
505 .clear_color = clear_color,
506 .mocs = cmd_buffer->device->default_mocs);
507
508 add_image_view_relocs(cmd_buffer, iview,
509 state->attachments[i].aux_usage,
510 state->attachments[i].color_rt_state);
511 } else {
512 state->attachments[i].aux_usage = iview->image->aux_usage;
513 state->attachments[i].input_aux_usage = ISL_AUX_USAGE_NONE;
514 }
515
516 if (need_input_attachment_state(&pass->attachments[i])) {
517 const struct isl_surf *surf;
518 if (att_aspects == VK_IMAGE_ASPECT_COLOR_BIT) {
519 surf = &iview->image->color_surface.isl;
520 } else {
521 surf = &iview->image->depth_surface.isl;
522 }
523
524 struct isl_view view = iview->isl;
525 view.usage |= ISL_SURF_USAGE_TEXTURE_BIT;
526 isl_surf_fill_state(isl_dev,
527 state->attachments[i].input_att_state.map,
528 .surf = surf,
529 .view = &view,
530 .aux_surf = &iview->image->aux_surface.isl,
531 .aux_usage = state->attachments[i].input_aux_usage,
532 .clear_color = clear_color,
533 .mocs = cmd_buffer->device->default_mocs);
534
535 add_image_view_relocs(cmd_buffer, iview,
536 state->attachments[i].input_aux_usage,
537 state->attachments[i].input_att_state);
538 }
539 }
540
541 if (!cmd_buffer->device->info.has_llc)
542 anv_state_clflush(state->render_pass_states);
543 }
544 }
545
546 VkResult
547 genX(BeginCommandBuffer)(
548 VkCommandBuffer commandBuffer,
549 const VkCommandBufferBeginInfo* pBeginInfo)
550 {
551 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
552
553 /* If this is the first vkBeginCommandBuffer, we must *initialize* the
554 * command buffer's state. Otherwise, we must *reset* its state. In both
555 * cases we reset it.
556 *
557 * From the Vulkan 1.0 spec:
558 *
559 * If a command buffer is in the executable state and the command buffer
560 * was allocated from a command pool with the
561 * VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, then
562 * vkBeginCommandBuffer implicitly resets the command buffer, behaving
563 * as if vkResetCommandBuffer had been called with
564 * VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT not set. It then puts
565 * the command buffer in the recording state.
566 */
567 anv_cmd_buffer_reset(cmd_buffer);
568
569 cmd_buffer->usage_flags = pBeginInfo->flags;
570
571 assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_SECONDARY ||
572 !(cmd_buffer->usage_flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT));
573
574 genX(cmd_buffer_emit_state_base_address)(cmd_buffer);
575
576 if (cmd_buffer->usage_flags &
577 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
578 cmd_buffer->state.pass =
579 anv_render_pass_from_handle(pBeginInfo->pInheritanceInfo->renderPass);
580 cmd_buffer->state.subpass =
581 &cmd_buffer->state.pass->subpasses[pBeginInfo->pInheritanceInfo->subpass];
582 cmd_buffer->state.framebuffer = NULL;
583
584 genX(cmd_buffer_setup_attachments)(cmd_buffer, cmd_buffer->state.pass,
585 NULL);
586
587 cmd_buffer->state.dirty |= ANV_CMD_DIRTY_RENDER_TARGETS;
588 }
589
590 return VK_SUCCESS;
591 }
592
593 VkResult
594 genX(EndCommandBuffer)(
595 VkCommandBuffer commandBuffer)
596 {
597 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
598
599 genX(cmd_buffer_apply_pipe_flushes)(cmd_buffer);
600
601 anv_cmd_buffer_end_batch_buffer(cmd_buffer);
602
603 return VK_SUCCESS;
604 }
605
606 void
607 genX(CmdExecuteCommands)(
608 VkCommandBuffer commandBuffer,
609 uint32_t commandBufferCount,
610 const VkCommandBuffer* pCmdBuffers)
611 {
612 ANV_FROM_HANDLE(anv_cmd_buffer, primary, commandBuffer);
613
614 assert(primary->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY);
615
616 for (uint32_t i = 0; i < commandBufferCount; i++) {
617 ANV_FROM_HANDLE(anv_cmd_buffer, secondary, pCmdBuffers[i]);
618
619 assert(secondary->level == VK_COMMAND_BUFFER_LEVEL_SECONDARY);
620
621 if (secondary->usage_flags &
622 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
623 /* If we're continuing a render pass from the primary, we need to
624 * copy the surface states for the current subpass into the storage
625 * we allocated for them in BeginCommandBuffer.
626 */
627 struct anv_bo *ss_bo = &primary->device->surface_state_block_pool.bo;
628 struct anv_state src_state = primary->state.render_pass_states;
629 struct anv_state dst_state = secondary->state.render_pass_states;
630 assert(src_state.alloc_size == dst_state.alloc_size);
631
632 genX(cmd_buffer_gpu_memcpy)(primary, ss_bo, dst_state.offset,
633 ss_bo, src_state.offset,
634 src_state.alloc_size);
635 }
636
637 anv_cmd_buffer_add_secondary(primary, secondary);
638 }
639
640 /* Each of the secondary command buffers will use its own state base
641 * address. We need to re-emit state base address for the primary after
642 * all of the secondaries are done.
643 *
644 * TODO: Maybe we want to make this a dirty bit to avoid extra state base
645 * address calls?
646 */
647 genX(cmd_buffer_emit_state_base_address)(primary);
648 }
649
650 #define IVB_L3SQCREG1_SQGHPCI_DEFAULT 0x00730000
651 #define VLV_L3SQCREG1_SQGHPCI_DEFAULT 0x00d30000
652 #define HSW_L3SQCREG1_SQGHPCI_DEFAULT 0x00610000
653
654 /**
655 * Program the hardware to use the specified L3 configuration.
656 */
657 void
658 genX(cmd_buffer_config_l3)(struct anv_cmd_buffer *cmd_buffer,
659 const struct gen_l3_config *cfg)
660 {
661 assert(cfg);
662 if (cfg == cmd_buffer->state.current_l3_config)
663 return;
664
665 if (unlikely(INTEL_DEBUG & DEBUG_L3)) {
666 fprintf(stderr, "L3 config transition: ");
667 gen_dump_l3_config(cfg, stderr);
668 }
669
670 const bool has_slm = cfg->n[GEN_L3P_SLM];
671
672 /* According to the hardware docs, the L3 partitioning can only be changed
673 * while the pipeline is completely drained and the caches are flushed,
674 * which involves a first PIPE_CONTROL flush which stalls the pipeline...
675 */
676 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
677 pc.DCFlushEnable = true;
678 pc.PostSyncOperation = NoWrite;
679 pc.CommandStreamerStallEnable = true;
680 }
681
682 /* ...followed by a second pipelined PIPE_CONTROL that initiates
683 * invalidation of the relevant caches. Note that because RO invalidation
684 * happens at the top of the pipeline (i.e. right away as the PIPE_CONTROL
685 * command is processed by the CS) we cannot combine it with the previous
686 * stalling flush as the hardware documentation suggests, because that
687 * would cause the CS to stall on previous rendering *after* RO
688 * invalidation and wouldn't prevent the RO caches from being polluted by
689 * concurrent rendering before the stall completes. This intentionally
690 * doesn't implement the SKL+ hardware workaround suggesting to enable CS
691 * stall on PIPE_CONTROLs with the texture cache invalidation bit set for
692 * GPGPU workloads because the previous and subsequent PIPE_CONTROLs
693 * already guarantee that there is no concurrent GPGPU kernel execution
694 * (see SKL HSD 2132585).
695 */
696 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
697 pc.TextureCacheInvalidationEnable = true;
698 pc.ConstantCacheInvalidationEnable = true;
699 pc.InstructionCacheInvalidateEnable = true;
700 pc.StateCacheInvalidationEnable = true;
701 pc.PostSyncOperation = NoWrite;
702 }
703
704 /* Now send a third stalling flush to make sure that invalidation is
705 * complete when the L3 configuration registers are modified.
706 */
707 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
708 pc.DCFlushEnable = true;
709 pc.PostSyncOperation = NoWrite;
710 pc.CommandStreamerStallEnable = true;
711 }
712
713 #if GEN_GEN >= 8
714
715 assert(!cfg->n[GEN_L3P_IS] && !cfg->n[GEN_L3P_C] && !cfg->n[GEN_L3P_T]);
716
717 uint32_t l3cr;
718 anv_pack_struct(&l3cr, GENX(L3CNTLREG),
719 .SLMEnable = has_slm,
720 .URBAllocation = cfg->n[GEN_L3P_URB],
721 .ROAllocation = cfg->n[GEN_L3P_RO],
722 .DCAllocation = cfg->n[GEN_L3P_DC],
723 .AllAllocation = cfg->n[GEN_L3P_ALL]);
724
725 /* Set up the L3 partitioning. */
726 emit_lri(&cmd_buffer->batch, GENX(L3CNTLREG_num), l3cr);
727
728 #else
729
730 const bool has_dc = cfg->n[GEN_L3P_DC] || cfg->n[GEN_L3P_ALL];
731 const bool has_is = cfg->n[GEN_L3P_IS] || cfg->n[GEN_L3P_RO] ||
732 cfg->n[GEN_L3P_ALL];
733 const bool has_c = cfg->n[GEN_L3P_C] || cfg->n[GEN_L3P_RO] ||
734 cfg->n[GEN_L3P_ALL];
735 const bool has_t = cfg->n[GEN_L3P_T] || cfg->n[GEN_L3P_RO] ||
736 cfg->n[GEN_L3P_ALL];
737
738 assert(!cfg->n[GEN_L3P_ALL]);
739
740 /* When enabled SLM only uses a portion of the L3 on half of the banks,
741 * the matching space on the remaining banks has to be allocated to a
742 * client (URB for all validated configurations) set to the
743 * lower-bandwidth 2-bank address hashing mode.
744 */
745 const struct gen_device_info *devinfo = &cmd_buffer->device->info;
746 const bool urb_low_bw = has_slm && !devinfo->is_baytrail;
747 assert(!urb_low_bw || cfg->n[GEN_L3P_URB] == cfg->n[GEN_L3P_SLM]);
748
749 /* Minimum number of ways that can be allocated to the URB. */
750 MAYBE_UNUSED const unsigned n0_urb = devinfo->is_baytrail ? 32 : 0;
751 assert(cfg->n[GEN_L3P_URB] >= n0_urb);
752
753 uint32_t l3sqcr1, l3cr2, l3cr3;
754 anv_pack_struct(&l3sqcr1, GENX(L3SQCREG1),
755 .ConvertDC_UC = !has_dc,
756 .ConvertIS_UC = !has_is,
757 .ConvertC_UC = !has_c,
758 .ConvertT_UC = !has_t);
759 l3sqcr1 |=
760 GEN_IS_HASWELL ? HSW_L3SQCREG1_SQGHPCI_DEFAULT :
761 devinfo->is_baytrail ? VLV_L3SQCREG1_SQGHPCI_DEFAULT :
762 IVB_L3SQCREG1_SQGHPCI_DEFAULT;
763
764 anv_pack_struct(&l3cr2, GENX(L3CNTLREG2),
765 .SLMEnable = has_slm,
766 .URBLowBandwidth = urb_low_bw,
767 .URBAllocation = cfg->n[GEN_L3P_URB],
768 #if !GEN_IS_HASWELL
769 .ALLAllocation = cfg->n[GEN_L3P_ALL],
770 #endif
771 .ROAllocation = cfg->n[GEN_L3P_RO],
772 .DCAllocation = cfg->n[GEN_L3P_DC]);
773
774 anv_pack_struct(&l3cr3, GENX(L3CNTLREG3),
775 .ISAllocation = cfg->n[GEN_L3P_IS],
776 .ISLowBandwidth = 0,
777 .CAllocation = cfg->n[GEN_L3P_C],
778 .CLowBandwidth = 0,
779 .TAllocation = cfg->n[GEN_L3P_T],
780 .TLowBandwidth = 0);
781
782 /* Set up the L3 partitioning. */
783 emit_lri(&cmd_buffer->batch, GENX(L3SQCREG1_num), l3sqcr1);
784 emit_lri(&cmd_buffer->batch, GENX(L3CNTLREG2_num), l3cr2);
785 emit_lri(&cmd_buffer->batch, GENX(L3CNTLREG3_num), l3cr3);
786
787 #if GEN_IS_HASWELL
788 if (cmd_buffer->device->instance->physicalDevice.cmd_parser_version >= 4) {
789 /* Enable L3 atomics on HSW if we have a DC partition, otherwise keep
790 * them disabled to avoid crashing the system hard.
791 */
792 uint32_t scratch1, chicken3;
793 anv_pack_struct(&scratch1, GENX(SCRATCH1),
794 .L3AtomicDisable = !has_dc);
795 anv_pack_struct(&chicken3, GENX(CHICKEN3),
796 .L3AtomicDisableMask = true,
797 .L3AtomicDisable = !has_dc);
798 emit_lri(&cmd_buffer->batch, GENX(SCRATCH1_num), scratch1);
799 emit_lri(&cmd_buffer->batch, GENX(CHICKEN3_num), chicken3);
800 }
801 #endif
802
803 #endif
804
805 cmd_buffer->state.current_l3_config = cfg;
806 }
807
808 void
809 genX(cmd_buffer_apply_pipe_flushes)(struct anv_cmd_buffer *cmd_buffer)
810 {
811 enum anv_pipe_bits bits = cmd_buffer->state.pending_pipe_bits;
812
813 /* Flushes are pipelined while invalidations are handled immediately.
814 * Therefore, if we're flushing anything then we need to schedule a stall
815 * before any invalidations can happen.
816 */
817 if (bits & ANV_PIPE_FLUSH_BITS)
818 bits |= ANV_PIPE_NEEDS_CS_STALL_BIT;
819
820 /* If we're going to do an invalidate and we have a pending CS stall that
821 * has yet to be resolved, we do the CS stall now.
822 */
823 if ((bits & ANV_PIPE_INVALIDATE_BITS) &&
824 (bits & ANV_PIPE_NEEDS_CS_STALL_BIT)) {
825 bits |= ANV_PIPE_CS_STALL_BIT;
826 bits &= ~ANV_PIPE_NEEDS_CS_STALL_BIT;
827 }
828
829 if (bits & (ANV_PIPE_FLUSH_BITS | ANV_PIPE_CS_STALL_BIT)) {
830 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pipe) {
831 pipe.DepthCacheFlushEnable = bits & ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
832 pipe.DCFlushEnable = bits & ANV_PIPE_DATA_CACHE_FLUSH_BIT;
833 pipe.RenderTargetCacheFlushEnable =
834 bits & ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
835
836 pipe.DepthStallEnable = bits & ANV_PIPE_DEPTH_STALL_BIT;
837 pipe.CommandStreamerStallEnable = bits & ANV_PIPE_CS_STALL_BIT;
838 pipe.StallAtPixelScoreboard = bits & ANV_PIPE_STALL_AT_SCOREBOARD_BIT;
839
840 /*
841 * According to the Broadwell documentation, any PIPE_CONTROL with the
842 * "Command Streamer Stall" bit set must also have another bit set,
843 * with five different options:
844 *
845 * - Render Target Cache Flush
846 * - Depth Cache Flush
847 * - Stall at Pixel Scoreboard
848 * - Post-Sync Operation
849 * - Depth Stall
850 * - DC Flush Enable
851 *
852 * I chose "Stall at Pixel Scoreboard" since that's what we use in
853 * mesa and it seems to work fine. The choice is fairly arbitrary.
854 */
855 if ((bits & ANV_PIPE_CS_STALL_BIT) &&
856 !(bits & (ANV_PIPE_FLUSH_BITS | ANV_PIPE_DEPTH_STALL_BIT |
857 ANV_PIPE_STALL_AT_SCOREBOARD_BIT)))
858 pipe.StallAtPixelScoreboard = true;
859 }
860
861 bits &= ~(ANV_PIPE_FLUSH_BITS | ANV_PIPE_CS_STALL_BIT);
862 }
863
864 if (bits & ANV_PIPE_INVALIDATE_BITS) {
865 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pipe) {
866 pipe.StateCacheInvalidationEnable =
867 bits & ANV_PIPE_STATE_CACHE_INVALIDATE_BIT;
868 pipe.ConstantCacheInvalidationEnable =
869 bits & ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT;
870 pipe.VFCacheInvalidationEnable =
871 bits & ANV_PIPE_VF_CACHE_INVALIDATE_BIT;
872 pipe.TextureCacheInvalidationEnable =
873 bits & ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
874 pipe.InstructionCacheInvalidateEnable =
875 bits & ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT;
876 }
877
878 bits &= ~ANV_PIPE_INVALIDATE_BITS;
879 }
880
881 cmd_buffer->state.pending_pipe_bits = bits;
882 }
883
884 void genX(CmdPipelineBarrier)(
885 VkCommandBuffer commandBuffer,
886 VkPipelineStageFlags srcStageMask,
887 VkPipelineStageFlags destStageMask,
888 VkBool32 byRegion,
889 uint32_t memoryBarrierCount,
890 const VkMemoryBarrier* pMemoryBarriers,
891 uint32_t bufferMemoryBarrierCount,
892 const VkBufferMemoryBarrier* pBufferMemoryBarriers,
893 uint32_t imageMemoryBarrierCount,
894 const VkImageMemoryBarrier* pImageMemoryBarriers)
895 {
896 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
897 uint32_t b;
898
899 /* XXX: Right now, we're really dumb and just flush whatever categories
900 * the app asks for. One of these days we may make this a bit better
901 * but right now that's all the hardware allows for in most areas.
902 */
903 VkAccessFlags src_flags = 0;
904 VkAccessFlags dst_flags = 0;
905
906 for (uint32_t i = 0; i < memoryBarrierCount; i++) {
907 src_flags |= pMemoryBarriers[i].srcAccessMask;
908 dst_flags |= pMemoryBarriers[i].dstAccessMask;
909 }
910
911 for (uint32_t i = 0; i < bufferMemoryBarrierCount; i++) {
912 src_flags |= pBufferMemoryBarriers[i].srcAccessMask;
913 dst_flags |= pBufferMemoryBarriers[i].dstAccessMask;
914 }
915
916 for (uint32_t i = 0; i < imageMemoryBarrierCount; i++) {
917 src_flags |= pImageMemoryBarriers[i].srcAccessMask;
918 dst_flags |= pImageMemoryBarriers[i].dstAccessMask;
919 }
920
921 enum anv_pipe_bits pipe_bits = 0;
922
923 for_each_bit(b, src_flags) {
924 switch ((VkAccessFlagBits)(1 << b)) {
925 case VK_ACCESS_SHADER_WRITE_BIT:
926 pipe_bits |= ANV_PIPE_DATA_CACHE_FLUSH_BIT;
927 break;
928 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT:
929 pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
930 break;
931 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT:
932 pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
933 break;
934 case VK_ACCESS_TRANSFER_WRITE_BIT:
935 pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
936 pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
937 break;
938 default:
939 break; /* Nothing to do */
940 }
941 }
942
943 for_each_bit(b, dst_flags) {
944 switch ((VkAccessFlagBits)(1 << b)) {
945 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT:
946 case VK_ACCESS_INDEX_READ_BIT:
947 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT:
948 pipe_bits |= ANV_PIPE_VF_CACHE_INVALIDATE_BIT;
949 break;
950 case VK_ACCESS_UNIFORM_READ_BIT:
951 pipe_bits |= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT;
952 pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
953 break;
954 case VK_ACCESS_SHADER_READ_BIT:
955 case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT:
956 case VK_ACCESS_TRANSFER_READ_BIT:
957 pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
958 break;
959 default:
960 break; /* Nothing to do */
961 }
962 }
963
964 cmd_buffer->state.pending_pipe_bits |= pipe_bits;
965 }
966
967 static void
968 cmd_buffer_alloc_push_constants(struct anv_cmd_buffer *cmd_buffer)
969 {
970 VkShaderStageFlags stages = cmd_buffer->state.pipeline->active_stages;
971
972 /* In order to avoid thrash, we assume that vertex and fragment stages
973 * always exist. In the rare case where one is missing *and* the other
974 * uses push concstants, this may be suboptimal. However, avoiding stalls
975 * seems more important.
976 */
977 stages |= VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_VERTEX_BIT;
978
979 if (stages == cmd_buffer->state.push_constant_stages)
980 return;
981
982 #if GEN_GEN >= 8
983 const unsigned push_constant_kb = 32;
984 #elif GEN_IS_HASWELL
985 const unsigned push_constant_kb = cmd_buffer->device->info.gt == 3 ? 32 : 16;
986 #else
987 const unsigned push_constant_kb = 16;
988 #endif
989
990 const unsigned num_stages =
991 _mesa_bitcount(stages & VK_SHADER_STAGE_ALL_GRAPHICS);
992 unsigned size_per_stage = push_constant_kb / num_stages;
993
994 /* Broadwell+ and Haswell gt3 require that the push constant sizes be in
995 * units of 2KB. Incidentally, these are the same platforms that have
996 * 32KB worth of push constant space.
997 */
998 if (push_constant_kb == 32)
999 size_per_stage &= ~1u;
1000
1001 uint32_t kb_used = 0;
1002 for (int i = MESA_SHADER_VERTEX; i < MESA_SHADER_FRAGMENT; i++) {
1003 unsigned push_size = (stages & (1 << i)) ? size_per_stage : 0;
1004 anv_batch_emit(&cmd_buffer->batch,
1005 GENX(3DSTATE_PUSH_CONSTANT_ALLOC_VS), alloc) {
1006 alloc._3DCommandSubOpcode = 18 + i;
1007 alloc.ConstantBufferOffset = (push_size > 0) ? kb_used : 0;
1008 alloc.ConstantBufferSize = push_size;
1009 }
1010 kb_used += push_size;
1011 }
1012
1013 anv_batch_emit(&cmd_buffer->batch,
1014 GENX(3DSTATE_PUSH_CONSTANT_ALLOC_PS), alloc) {
1015 alloc.ConstantBufferOffset = kb_used;
1016 alloc.ConstantBufferSize = push_constant_kb - kb_used;
1017 }
1018
1019 cmd_buffer->state.push_constant_stages = stages;
1020
1021 /* From the BDW PRM for 3DSTATE_PUSH_CONSTANT_ALLOC_VS:
1022 *
1023 * "The 3DSTATE_CONSTANT_VS must be reprogrammed prior to
1024 * the next 3DPRIMITIVE command after programming the
1025 * 3DSTATE_PUSH_CONSTANT_ALLOC_VS"
1026 *
1027 * Since 3DSTATE_PUSH_CONSTANT_ALLOC_VS is programmed as part of
1028 * pipeline setup, we need to dirty push constants.
1029 */
1030 cmd_buffer->state.push_constants_dirty |= VK_SHADER_STAGE_ALL_GRAPHICS;
1031 }
1032
1033 static VkResult
1034 emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
1035 gl_shader_stage stage,
1036 struct anv_state *bt_state)
1037 {
1038 struct anv_subpass *subpass = cmd_buffer->state.subpass;
1039 struct anv_pipeline *pipeline;
1040 uint32_t bias, state_offset;
1041
1042 switch (stage) {
1043 case MESA_SHADER_COMPUTE:
1044 pipeline = cmd_buffer->state.compute_pipeline;
1045 bias = 1;
1046 break;
1047 default:
1048 pipeline = cmd_buffer->state.pipeline;
1049 bias = 0;
1050 break;
1051 }
1052
1053 if (!anv_pipeline_has_stage(pipeline, stage)) {
1054 *bt_state = (struct anv_state) { 0, };
1055 return VK_SUCCESS;
1056 }
1057
1058 struct anv_pipeline_bind_map *map = &pipeline->shaders[stage]->bind_map;
1059 if (bias + map->surface_count == 0) {
1060 *bt_state = (struct anv_state) { 0, };
1061 return VK_SUCCESS;
1062 }
1063
1064 *bt_state = anv_cmd_buffer_alloc_binding_table(cmd_buffer,
1065 bias + map->surface_count,
1066 &state_offset);
1067 uint32_t *bt_map = bt_state->map;
1068
1069 if (bt_state->map == NULL)
1070 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1071
1072 if (stage == MESA_SHADER_COMPUTE &&
1073 get_cs_prog_data(cmd_buffer->state.compute_pipeline)->uses_num_work_groups) {
1074 struct anv_bo *bo = cmd_buffer->state.num_workgroups_bo;
1075 uint32_t bo_offset = cmd_buffer->state.num_workgroups_offset;
1076
1077 struct anv_state surface_state;
1078 surface_state =
1079 anv_cmd_buffer_alloc_surface_state(cmd_buffer);
1080
1081 const enum isl_format format =
1082 anv_isl_format_for_descriptor_type(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
1083 anv_fill_buffer_surface_state(cmd_buffer->device, surface_state,
1084 format, bo_offset, 12, 1);
1085
1086 bt_map[0] = surface_state.offset + state_offset;
1087 add_surface_state_reloc(cmd_buffer, surface_state, bo, bo_offset);
1088 }
1089
1090 if (map->surface_count == 0)
1091 goto out;
1092
1093 if (map->image_count > 0) {
1094 VkResult result =
1095 anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, images);
1096 if (result != VK_SUCCESS)
1097 return result;
1098
1099 cmd_buffer->state.push_constants_dirty |= 1 << stage;
1100 }
1101
1102 uint32_t image = 0;
1103 for (uint32_t s = 0; s < map->surface_count; s++) {
1104 struct anv_pipeline_binding *binding = &map->surface_to_descriptor[s];
1105
1106 struct anv_state surface_state;
1107
1108 if (binding->set == ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS) {
1109 /* Color attachment binding */
1110 assert(stage == MESA_SHADER_FRAGMENT);
1111 assert(binding->binding == 0);
1112 if (binding->index < subpass->color_count) {
1113 const unsigned att = subpass->color_attachments[binding->index];
1114 surface_state = cmd_buffer->state.attachments[att].color_rt_state;
1115 } else {
1116 surface_state = cmd_buffer->state.null_surface_state;
1117 }
1118
1119 bt_map[bias + s] = surface_state.offset + state_offset;
1120 continue;
1121 }
1122
1123 struct anv_descriptor_set *set =
1124 cmd_buffer->state.descriptors[binding->set];
1125 uint32_t offset = set->layout->binding[binding->binding].descriptor_index;
1126 struct anv_descriptor *desc = &set->descriptors[offset + binding->index];
1127
1128 switch (desc->type) {
1129 case VK_DESCRIPTOR_TYPE_SAMPLER:
1130 /* Nothing for us to do here */
1131 continue;
1132
1133 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1134 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1135 surface_state = desc->image_view->sampler_surface_state;
1136 assert(surface_state.alloc_size);
1137 add_image_view_relocs(cmd_buffer, desc->image_view,
1138 desc->image_view->image->aux_usage,
1139 surface_state);
1140 break;
1141
1142 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1143 assert(stage == MESA_SHADER_FRAGMENT);
1144 if (desc->image_view->aspect_mask == VK_IMAGE_ASPECT_STENCIL_BIT) {
1145 /* For stencil input attachments, we treat it like any old texture
1146 * that a user may have bound.
1147 */
1148 surface_state = desc->image_view->sampler_surface_state;
1149 assert(surface_state.alloc_size);
1150 add_image_view_relocs(cmd_buffer, desc->image_view,
1151 desc->image_view->image->aux_usage,
1152 surface_state);
1153 } else {
1154 /* For depth and color input attachments, we create the surface
1155 * state at vkBeginRenderPass time so that we can include aux
1156 * and clear color information.
1157 */
1158 assert(binding->input_attachment_index < subpass->input_count);
1159 const unsigned subpass_att = binding->input_attachment_index;
1160 const unsigned att = subpass->input_attachments[subpass_att];
1161 surface_state = cmd_buffer->state.attachments[att].input_att_state;
1162 }
1163 break;
1164
1165 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
1166 surface_state = desc->image_view->storage_surface_state;
1167 assert(surface_state.alloc_size);
1168 add_image_view_relocs(cmd_buffer, desc->image_view,
1169 desc->image_view->image->aux_usage,
1170 surface_state);
1171
1172 struct brw_image_param *image_param =
1173 &cmd_buffer->state.push_constants[stage]->images[image++];
1174
1175 *image_param = desc->image_view->storage_image_param;
1176 image_param->surface_idx = bias + s;
1177 break;
1178 }
1179
1180 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1181 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1182 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1183 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1184 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1185 surface_state = desc->buffer_view->surface_state;
1186 assert(surface_state.alloc_size);
1187 add_surface_state_reloc(cmd_buffer, surface_state,
1188 desc->buffer_view->bo,
1189 desc->buffer_view->offset);
1190 break;
1191
1192 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1193 surface_state = desc->buffer_view->storage_surface_state;
1194 assert(surface_state.alloc_size);
1195 add_surface_state_reloc(cmd_buffer, surface_state,
1196 desc->buffer_view->bo,
1197 desc->buffer_view->offset);
1198
1199 struct brw_image_param *image_param =
1200 &cmd_buffer->state.push_constants[stage]->images[image++];
1201
1202 *image_param = desc->buffer_view->storage_image_param;
1203 image_param->surface_idx = bias + s;
1204 break;
1205
1206 default:
1207 assert(!"Invalid descriptor type");
1208 continue;
1209 }
1210
1211 bt_map[bias + s] = surface_state.offset + state_offset;
1212 }
1213 assert(image == map->image_count);
1214
1215 out:
1216 if (!cmd_buffer->device->info.has_llc)
1217 anv_state_clflush(*bt_state);
1218
1219 return VK_SUCCESS;
1220 }
1221
1222 static VkResult
1223 emit_samplers(struct anv_cmd_buffer *cmd_buffer,
1224 gl_shader_stage stage,
1225 struct anv_state *state)
1226 {
1227 struct anv_pipeline *pipeline;
1228
1229 if (stage == MESA_SHADER_COMPUTE)
1230 pipeline = cmd_buffer->state.compute_pipeline;
1231 else
1232 pipeline = cmd_buffer->state.pipeline;
1233
1234 if (!anv_pipeline_has_stage(pipeline, stage)) {
1235 *state = (struct anv_state) { 0, };
1236 return VK_SUCCESS;
1237 }
1238
1239 struct anv_pipeline_bind_map *map = &pipeline->shaders[stage]->bind_map;
1240 if (map->sampler_count == 0) {
1241 *state = (struct anv_state) { 0, };
1242 return VK_SUCCESS;
1243 }
1244
1245 uint32_t size = map->sampler_count * 16;
1246 *state = anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, size, 32);
1247
1248 if (state->map == NULL)
1249 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1250
1251 for (uint32_t s = 0; s < map->sampler_count; s++) {
1252 struct anv_pipeline_binding *binding = &map->sampler_to_descriptor[s];
1253 struct anv_descriptor_set *set =
1254 cmd_buffer->state.descriptors[binding->set];
1255 uint32_t offset = set->layout->binding[binding->binding].descriptor_index;
1256 struct anv_descriptor *desc = &set->descriptors[offset + binding->index];
1257
1258 if (desc->type != VK_DESCRIPTOR_TYPE_SAMPLER &&
1259 desc->type != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
1260 continue;
1261
1262 struct anv_sampler *sampler = desc->sampler;
1263
1264 /* This can happen if we have an unfilled slot since TYPE_SAMPLER
1265 * happens to be zero.
1266 */
1267 if (sampler == NULL)
1268 continue;
1269
1270 memcpy(state->map + (s * 16),
1271 sampler->state, sizeof(sampler->state));
1272 }
1273
1274 if (!cmd_buffer->device->info.has_llc)
1275 anv_state_clflush(*state);
1276
1277 return VK_SUCCESS;
1278 }
1279
1280 static uint32_t
1281 flush_descriptor_sets(struct anv_cmd_buffer *cmd_buffer)
1282 {
1283 VkShaderStageFlags dirty = cmd_buffer->state.descriptors_dirty &
1284 cmd_buffer->state.pipeline->active_stages;
1285
1286 VkResult result = VK_SUCCESS;
1287 anv_foreach_stage(s, dirty) {
1288 result = emit_samplers(cmd_buffer, s, &cmd_buffer->state.samplers[s]);
1289 if (result != VK_SUCCESS)
1290 break;
1291 result = emit_binding_table(cmd_buffer, s,
1292 &cmd_buffer->state.binding_tables[s]);
1293 if (result != VK_SUCCESS)
1294 break;
1295 }
1296
1297 if (result != VK_SUCCESS) {
1298 assert(result == VK_ERROR_OUT_OF_DEVICE_MEMORY);
1299
1300 result = anv_cmd_buffer_new_binding_table_block(cmd_buffer);
1301 assert(result == VK_SUCCESS);
1302
1303 /* Re-emit state base addresses so we get the new surface state base
1304 * address before we start emitting binding tables etc.
1305 */
1306 genX(cmd_buffer_emit_state_base_address)(cmd_buffer);
1307
1308 /* Re-emit all active binding tables */
1309 dirty |= cmd_buffer->state.pipeline->active_stages;
1310 anv_foreach_stage(s, dirty) {
1311 result = emit_samplers(cmd_buffer, s, &cmd_buffer->state.samplers[s]);
1312 if (result != VK_SUCCESS)
1313 return result;
1314 result = emit_binding_table(cmd_buffer, s,
1315 &cmd_buffer->state.binding_tables[s]);
1316 if (result != VK_SUCCESS)
1317 return result;
1318 }
1319 }
1320
1321 cmd_buffer->state.descriptors_dirty &= ~dirty;
1322
1323 return dirty;
1324 }
1325
1326 static void
1327 cmd_buffer_emit_descriptor_pointers(struct anv_cmd_buffer *cmd_buffer,
1328 uint32_t stages)
1329 {
1330 static const uint32_t sampler_state_opcodes[] = {
1331 [MESA_SHADER_VERTEX] = 43,
1332 [MESA_SHADER_TESS_CTRL] = 44, /* HS */
1333 [MESA_SHADER_TESS_EVAL] = 45, /* DS */
1334 [MESA_SHADER_GEOMETRY] = 46,
1335 [MESA_SHADER_FRAGMENT] = 47,
1336 [MESA_SHADER_COMPUTE] = 0,
1337 };
1338
1339 static const uint32_t binding_table_opcodes[] = {
1340 [MESA_SHADER_VERTEX] = 38,
1341 [MESA_SHADER_TESS_CTRL] = 39,
1342 [MESA_SHADER_TESS_EVAL] = 40,
1343 [MESA_SHADER_GEOMETRY] = 41,
1344 [MESA_SHADER_FRAGMENT] = 42,
1345 [MESA_SHADER_COMPUTE] = 0,
1346 };
1347
1348 anv_foreach_stage(s, stages) {
1349 if (cmd_buffer->state.samplers[s].alloc_size > 0) {
1350 anv_batch_emit(&cmd_buffer->batch,
1351 GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS), ssp) {
1352 ssp._3DCommandSubOpcode = sampler_state_opcodes[s];
1353 ssp.PointertoVSSamplerState = cmd_buffer->state.samplers[s].offset;
1354 }
1355 }
1356
1357 /* Always emit binding table pointers if we're asked to, since on SKL
1358 * this is what flushes push constants. */
1359 anv_batch_emit(&cmd_buffer->batch,
1360 GENX(3DSTATE_BINDING_TABLE_POINTERS_VS), btp) {
1361 btp._3DCommandSubOpcode = binding_table_opcodes[s];
1362 btp.PointertoVSBindingTable = cmd_buffer->state.binding_tables[s].offset;
1363 }
1364 }
1365 }
1366
1367 static uint32_t
1368 cmd_buffer_flush_push_constants(struct anv_cmd_buffer *cmd_buffer)
1369 {
1370 static const uint32_t push_constant_opcodes[] = {
1371 [MESA_SHADER_VERTEX] = 21,
1372 [MESA_SHADER_TESS_CTRL] = 25, /* HS */
1373 [MESA_SHADER_TESS_EVAL] = 26, /* DS */
1374 [MESA_SHADER_GEOMETRY] = 22,
1375 [MESA_SHADER_FRAGMENT] = 23,
1376 [MESA_SHADER_COMPUTE] = 0,
1377 };
1378
1379 VkShaderStageFlags flushed = 0;
1380
1381 anv_foreach_stage(stage, cmd_buffer->state.push_constants_dirty) {
1382 if (stage == MESA_SHADER_COMPUTE)
1383 continue;
1384
1385 struct anv_state state = anv_cmd_buffer_push_constants(cmd_buffer, stage);
1386
1387 if (state.offset == 0) {
1388 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_CONSTANT_VS), c)
1389 c._3DCommandSubOpcode = push_constant_opcodes[stage];
1390 } else {
1391 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_CONSTANT_VS), c) {
1392 c._3DCommandSubOpcode = push_constant_opcodes[stage],
1393 c.ConstantBody = (struct GENX(3DSTATE_CONSTANT_BODY)) {
1394 #if GEN_GEN >= 9
1395 .PointerToConstantBuffer2 = { &cmd_buffer->device->dynamic_state_block_pool.bo, state.offset },
1396 .ConstantBuffer2ReadLength = DIV_ROUND_UP(state.alloc_size, 32),
1397 #else
1398 .PointerToConstantBuffer0 = { .offset = state.offset },
1399 .ConstantBuffer0ReadLength = DIV_ROUND_UP(state.alloc_size, 32),
1400 #endif
1401 };
1402 }
1403 }
1404
1405 flushed |= mesa_to_vk_shader_stage(stage);
1406 }
1407
1408 cmd_buffer->state.push_constants_dirty &= ~VK_SHADER_STAGE_ALL_GRAPHICS;
1409
1410 return flushed;
1411 }
1412
1413 void
1414 genX(cmd_buffer_flush_state)(struct anv_cmd_buffer *cmd_buffer)
1415 {
1416 struct anv_pipeline *pipeline = cmd_buffer->state.pipeline;
1417 uint32_t *p;
1418
1419 uint32_t vb_emit = cmd_buffer->state.vb_dirty & pipeline->vb_used;
1420
1421 assert((pipeline->active_stages & VK_SHADER_STAGE_COMPUTE_BIT) == 0);
1422
1423 genX(cmd_buffer_config_l3)(cmd_buffer, pipeline->urb.l3_config);
1424
1425 genX(flush_pipeline_select_3d)(cmd_buffer);
1426
1427 if (vb_emit) {
1428 const uint32_t num_buffers = __builtin_popcount(vb_emit);
1429 const uint32_t num_dwords = 1 + num_buffers * 4;
1430
1431 p = anv_batch_emitn(&cmd_buffer->batch, num_dwords,
1432 GENX(3DSTATE_VERTEX_BUFFERS));
1433 uint32_t vb, i = 0;
1434 for_each_bit(vb, vb_emit) {
1435 struct anv_buffer *buffer = cmd_buffer->state.vertex_bindings[vb].buffer;
1436 uint32_t offset = cmd_buffer->state.vertex_bindings[vb].offset;
1437
1438 struct GENX(VERTEX_BUFFER_STATE) state = {
1439 .VertexBufferIndex = vb,
1440
1441 #if GEN_GEN >= 8
1442 .MemoryObjectControlState = GENX(MOCS),
1443 #else
1444 .BufferAccessType = pipeline->instancing_enable[vb] ? INSTANCEDATA : VERTEXDATA,
1445 .InstanceDataStepRate = 1,
1446 .VertexBufferMemoryObjectControlState = GENX(MOCS),
1447 #endif
1448
1449 .AddressModifyEnable = true,
1450 .BufferPitch = pipeline->binding_stride[vb],
1451 .BufferStartingAddress = { buffer->bo, buffer->offset + offset },
1452
1453 #if GEN_GEN >= 8
1454 .BufferSize = buffer->size - offset
1455 #else
1456 .EndAddress = { buffer->bo, buffer->offset + buffer->size - 1},
1457 #endif
1458 };
1459
1460 GENX(VERTEX_BUFFER_STATE_pack)(&cmd_buffer->batch, &p[1 + i * 4], &state);
1461 i++;
1462 }
1463 }
1464
1465 cmd_buffer->state.vb_dirty &= ~vb_emit;
1466
1467 if (cmd_buffer->state.dirty & ANV_CMD_DIRTY_PIPELINE) {
1468 anv_batch_emit_batch(&cmd_buffer->batch, &pipeline->batch);
1469
1470 /* The exact descriptor layout is pulled from the pipeline, so we need
1471 * to re-emit binding tables on every pipeline change.
1472 */
1473 cmd_buffer->state.descriptors_dirty |=
1474 cmd_buffer->state.pipeline->active_stages;
1475
1476 /* If the pipeline changed, we may need to re-allocate push constant
1477 * space in the URB.
1478 */
1479 cmd_buffer_alloc_push_constants(cmd_buffer);
1480 }
1481
1482 #if GEN_GEN <= 7
1483 if (cmd_buffer->state.descriptors_dirty & VK_SHADER_STAGE_VERTEX_BIT ||
1484 cmd_buffer->state.push_constants_dirty & VK_SHADER_STAGE_VERTEX_BIT) {
1485 /* From the IVB PRM Vol. 2, Part 1, Section 3.2.1:
1486 *
1487 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth
1488 * stall needs to be sent just prior to any 3DSTATE_VS,
1489 * 3DSTATE_URB_VS, 3DSTATE_CONSTANT_VS,
1490 * 3DSTATE_BINDING_TABLE_POINTER_VS,
1491 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one
1492 * PIPE_CONTROL needs to be sent before any combination of VS
1493 * associated 3DSTATE."
1494 */
1495 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
1496 pc.DepthStallEnable = true;
1497 pc.PostSyncOperation = WriteImmediateData;
1498 pc.Address =
1499 (struct anv_address) { &cmd_buffer->device->workaround_bo, 0 };
1500 }
1501 }
1502 #endif
1503
1504 /* Render targets live in the same binding table as fragment descriptors */
1505 if (cmd_buffer->state.dirty & ANV_CMD_DIRTY_RENDER_TARGETS)
1506 cmd_buffer->state.descriptors_dirty |= VK_SHADER_STAGE_FRAGMENT_BIT;
1507
1508 /* We emit the binding tables and sampler tables first, then emit push
1509 * constants and then finally emit binding table and sampler table
1510 * pointers. It has to happen in this order, since emitting the binding
1511 * tables may change the push constants (in case of storage images). After
1512 * emitting push constants, on SKL+ we have to emit the corresponding
1513 * 3DSTATE_BINDING_TABLE_POINTER_* for the push constants to take effect.
1514 */
1515 uint32_t dirty = 0;
1516 if (cmd_buffer->state.descriptors_dirty)
1517 dirty = flush_descriptor_sets(cmd_buffer);
1518
1519 if (cmd_buffer->state.push_constants_dirty) {
1520 #if GEN_GEN >= 9
1521 /* On Sky Lake and later, the binding table pointers commands are
1522 * what actually flush the changes to push constant state so we need
1523 * to dirty them so they get re-emitted below.
1524 */
1525 dirty |= cmd_buffer_flush_push_constants(cmd_buffer);
1526 #else
1527 cmd_buffer_flush_push_constants(cmd_buffer);
1528 #endif
1529 }
1530
1531 if (dirty)
1532 cmd_buffer_emit_descriptor_pointers(cmd_buffer, dirty);
1533
1534 if (cmd_buffer->state.dirty & ANV_CMD_DIRTY_DYNAMIC_VIEWPORT)
1535 gen8_cmd_buffer_emit_viewport(cmd_buffer);
1536
1537 if (cmd_buffer->state.dirty & (ANV_CMD_DIRTY_DYNAMIC_VIEWPORT |
1538 ANV_CMD_DIRTY_PIPELINE)) {
1539 gen8_cmd_buffer_emit_depth_viewport(cmd_buffer,
1540 pipeline->depth_clamp_enable);
1541 }
1542
1543 if (cmd_buffer->state.dirty & ANV_CMD_DIRTY_DYNAMIC_SCISSOR)
1544 gen7_cmd_buffer_emit_scissor(cmd_buffer);
1545
1546 genX(cmd_buffer_flush_dynamic_state)(cmd_buffer);
1547
1548 genX(cmd_buffer_apply_pipe_flushes)(cmd_buffer);
1549 }
1550
1551 static void
1552 emit_base_vertex_instance_bo(struct anv_cmd_buffer *cmd_buffer,
1553 struct anv_bo *bo, uint32_t offset)
1554 {
1555 uint32_t *p = anv_batch_emitn(&cmd_buffer->batch, 5,
1556 GENX(3DSTATE_VERTEX_BUFFERS));
1557
1558 GENX(VERTEX_BUFFER_STATE_pack)(&cmd_buffer->batch, p + 1,
1559 &(struct GENX(VERTEX_BUFFER_STATE)) {
1560 .VertexBufferIndex = 32, /* Reserved for this */
1561 .AddressModifyEnable = true,
1562 .BufferPitch = 0,
1563 #if (GEN_GEN >= 8)
1564 .MemoryObjectControlState = GENX(MOCS),
1565 .BufferStartingAddress = { bo, offset },
1566 .BufferSize = 8
1567 #else
1568 .VertexBufferMemoryObjectControlState = GENX(MOCS),
1569 .BufferStartingAddress = { bo, offset },
1570 .EndAddress = { bo, offset + 8 },
1571 #endif
1572 });
1573 }
1574
1575 static void
1576 emit_base_vertex_instance(struct anv_cmd_buffer *cmd_buffer,
1577 uint32_t base_vertex, uint32_t base_instance)
1578 {
1579 struct anv_state id_state =
1580 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, 8, 4);
1581
1582 ((uint32_t *)id_state.map)[0] = base_vertex;
1583 ((uint32_t *)id_state.map)[1] = base_instance;
1584
1585 if (!cmd_buffer->device->info.has_llc)
1586 anv_state_clflush(id_state);
1587
1588 emit_base_vertex_instance_bo(cmd_buffer,
1589 &cmd_buffer->device->dynamic_state_block_pool.bo, id_state.offset);
1590 }
1591
1592 void genX(CmdDraw)(
1593 VkCommandBuffer commandBuffer,
1594 uint32_t vertexCount,
1595 uint32_t instanceCount,
1596 uint32_t firstVertex,
1597 uint32_t firstInstance)
1598 {
1599 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
1600 struct anv_pipeline *pipeline = cmd_buffer->state.pipeline;
1601 const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline);
1602
1603 genX(cmd_buffer_flush_state)(cmd_buffer);
1604
1605 if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
1606 emit_base_vertex_instance(cmd_buffer, firstVertex, firstInstance);
1607
1608 anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE), prim) {
1609 prim.VertexAccessType = SEQUENTIAL;
1610 prim.PrimitiveTopologyType = pipeline->topology;
1611 prim.VertexCountPerInstance = vertexCount;
1612 prim.StartVertexLocation = firstVertex;
1613 prim.InstanceCount = instanceCount;
1614 prim.StartInstanceLocation = firstInstance;
1615 prim.BaseVertexLocation = 0;
1616 }
1617 }
1618
1619 void genX(CmdDrawIndexed)(
1620 VkCommandBuffer commandBuffer,
1621 uint32_t indexCount,
1622 uint32_t instanceCount,
1623 uint32_t firstIndex,
1624 int32_t vertexOffset,
1625 uint32_t firstInstance)
1626 {
1627 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
1628 struct anv_pipeline *pipeline = cmd_buffer->state.pipeline;
1629 const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline);
1630
1631 genX(cmd_buffer_flush_state)(cmd_buffer);
1632
1633 if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
1634 emit_base_vertex_instance(cmd_buffer, vertexOffset, firstInstance);
1635
1636 anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE), prim) {
1637 prim.VertexAccessType = RANDOM;
1638 prim.PrimitiveTopologyType = pipeline->topology;
1639 prim.VertexCountPerInstance = indexCount;
1640 prim.StartVertexLocation = firstIndex;
1641 prim.InstanceCount = instanceCount;
1642 prim.StartInstanceLocation = firstInstance;
1643 prim.BaseVertexLocation = vertexOffset;
1644 }
1645 }
1646
1647 /* Auto-Draw / Indirect Registers */
1648 #define GEN7_3DPRIM_END_OFFSET 0x2420
1649 #define GEN7_3DPRIM_START_VERTEX 0x2430
1650 #define GEN7_3DPRIM_VERTEX_COUNT 0x2434
1651 #define GEN7_3DPRIM_INSTANCE_COUNT 0x2438
1652 #define GEN7_3DPRIM_START_INSTANCE 0x243C
1653 #define GEN7_3DPRIM_BASE_VERTEX 0x2440
1654
1655 void genX(CmdDrawIndirect)(
1656 VkCommandBuffer commandBuffer,
1657 VkBuffer _buffer,
1658 VkDeviceSize offset,
1659 uint32_t drawCount,
1660 uint32_t stride)
1661 {
1662 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
1663 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
1664 struct anv_pipeline *pipeline = cmd_buffer->state.pipeline;
1665 const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline);
1666 struct anv_bo *bo = buffer->bo;
1667 uint32_t bo_offset = buffer->offset + offset;
1668
1669 genX(cmd_buffer_flush_state)(cmd_buffer);
1670
1671 if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
1672 emit_base_vertex_instance_bo(cmd_buffer, bo, bo_offset + 8);
1673
1674 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_VERTEX_COUNT, bo, bo_offset);
1675 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_INSTANCE_COUNT, bo, bo_offset + 4);
1676 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_START_VERTEX, bo, bo_offset + 8);
1677 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_START_INSTANCE, bo, bo_offset + 12);
1678 emit_lri(&cmd_buffer->batch, GEN7_3DPRIM_BASE_VERTEX, 0);
1679
1680 anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE), prim) {
1681 prim.IndirectParameterEnable = true;
1682 prim.VertexAccessType = SEQUENTIAL;
1683 prim.PrimitiveTopologyType = pipeline->topology;
1684 }
1685 }
1686
1687 void genX(CmdDrawIndexedIndirect)(
1688 VkCommandBuffer commandBuffer,
1689 VkBuffer _buffer,
1690 VkDeviceSize offset,
1691 uint32_t drawCount,
1692 uint32_t stride)
1693 {
1694 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
1695 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
1696 struct anv_pipeline *pipeline = cmd_buffer->state.pipeline;
1697 const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline);
1698 struct anv_bo *bo = buffer->bo;
1699 uint32_t bo_offset = buffer->offset + offset;
1700
1701 genX(cmd_buffer_flush_state)(cmd_buffer);
1702
1703 /* TODO: We need to stomp base vertex to 0 somehow */
1704 if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
1705 emit_base_vertex_instance_bo(cmd_buffer, bo, bo_offset + 12);
1706
1707 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_VERTEX_COUNT, bo, bo_offset);
1708 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_INSTANCE_COUNT, bo, bo_offset + 4);
1709 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_START_VERTEX, bo, bo_offset + 8);
1710 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_BASE_VERTEX, bo, bo_offset + 12);
1711 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_START_INSTANCE, bo, bo_offset + 16);
1712
1713 anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE), prim) {
1714 prim.IndirectParameterEnable = true;
1715 prim.VertexAccessType = RANDOM;
1716 prim.PrimitiveTopologyType = pipeline->topology;
1717 }
1718 }
1719
1720 static VkResult
1721 flush_compute_descriptor_set(struct anv_cmd_buffer *cmd_buffer)
1722 {
1723 struct anv_pipeline *pipeline = cmd_buffer->state.compute_pipeline;
1724 struct anv_state surfaces = { 0, }, samplers = { 0, };
1725 VkResult result;
1726
1727 result = emit_binding_table(cmd_buffer, MESA_SHADER_COMPUTE, &surfaces);
1728 if (result != VK_SUCCESS) {
1729 assert(result == VK_ERROR_OUT_OF_DEVICE_MEMORY);
1730 result = anv_cmd_buffer_new_binding_table_block(cmd_buffer);
1731 assert(result == VK_SUCCESS);
1732
1733 /* Re-emit state base addresses so we get the new surface state base
1734 * address before we start emitting binding tables etc.
1735 */
1736 genX(cmd_buffer_emit_state_base_address)(cmd_buffer);
1737
1738 result = emit_binding_table(cmd_buffer, MESA_SHADER_COMPUTE, &surfaces);
1739 assert(result == VK_SUCCESS);
1740 }
1741
1742 result = emit_samplers(cmd_buffer, MESA_SHADER_COMPUTE, &samplers);
1743 assert(result == VK_SUCCESS);
1744
1745 uint32_t iface_desc_data_dw[GENX(INTERFACE_DESCRIPTOR_DATA_length)];
1746 struct GENX(INTERFACE_DESCRIPTOR_DATA) desc = {
1747 .BindingTablePointer = surfaces.offset,
1748 .SamplerStatePointer = samplers.offset,
1749 };
1750 GENX(INTERFACE_DESCRIPTOR_DATA_pack)(NULL, iface_desc_data_dw, &desc);
1751
1752 struct anv_state state =
1753 anv_cmd_buffer_merge_dynamic(cmd_buffer, iface_desc_data_dw,
1754 pipeline->interface_descriptor_data,
1755 GENX(INTERFACE_DESCRIPTOR_DATA_length),
1756 64);
1757
1758 uint32_t size = GENX(INTERFACE_DESCRIPTOR_DATA_length) * sizeof(uint32_t);
1759 anv_batch_emit(&cmd_buffer->batch,
1760 GENX(MEDIA_INTERFACE_DESCRIPTOR_LOAD), mid) {
1761 mid.InterfaceDescriptorTotalLength = size;
1762 mid.InterfaceDescriptorDataStartAddress = state.offset;
1763 }
1764
1765 return VK_SUCCESS;
1766 }
1767
1768 void
1769 genX(cmd_buffer_flush_compute_state)(struct anv_cmd_buffer *cmd_buffer)
1770 {
1771 struct anv_pipeline *pipeline = cmd_buffer->state.compute_pipeline;
1772 MAYBE_UNUSED VkResult result;
1773
1774 assert(pipeline->active_stages == VK_SHADER_STAGE_COMPUTE_BIT);
1775
1776 genX(cmd_buffer_config_l3)(cmd_buffer, pipeline->urb.l3_config);
1777
1778 genX(flush_pipeline_select_gpgpu)(cmd_buffer);
1779
1780 if (cmd_buffer->state.compute_dirty & ANV_CMD_DIRTY_PIPELINE) {
1781 /* From the Sky Lake PRM Vol 2a, MEDIA_VFE_STATE:
1782 *
1783 * "A stalling PIPE_CONTROL is required before MEDIA_VFE_STATE unless
1784 * the only bits that are changed are scoreboard related: Scoreboard
1785 * Enable, Scoreboard Type, Scoreboard Mask, Scoreboard * Delta. For
1786 * these scoreboard related states, a MEDIA_STATE_FLUSH is
1787 * sufficient."
1788 */
1789 cmd_buffer->state.pending_pipe_bits |= ANV_PIPE_CS_STALL_BIT;
1790 genX(cmd_buffer_apply_pipe_flushes)(cmd_buffer);
1791
1792 anv_batch_emit_batch(&cmd_buffer->batch, &pipeline->batch);
1793 }
1794
1795 if ((cmd_buffer->state.descriptors_dirty & VK_SHADER_STAGE_COMPUTE_BIT) ||
1796 (cmd_buffer->state.compute_dirty & ANV_CMD_DIRTY_PIPELINE)) {
1797 /* FIXME: figure out descriptors for gen7 */
1798 result = flush_compute_descriptor_set(cmd_buffer);
1799 assert(result == VK_SUCCESS);
1800 cmd_buffer->state.descriptors_dirty &= ~VK_SHADER_STAGE_COMPUTE_BIT;
1801 }
1802
1803 if (cmd_buffer->state.push_constants_dirty & VK_SHADER_STAGE_COMPUTE_BIT) {
1804 struct anv_state push_state =
1805 anv_cmd_buffer_cs_push_constants(cmd_buffer);
1806
1807 if (push_state.alloc_size) {
1808 anv_batch_emit(&cmd_buffer->batch, GENX(MEDIA_CURBE_LOAD), curbe) {
1809 curbe.CURBETotalDataLength = push_state.alloc_size;
1810 curbe.CURBEDataStartAddress = push_state.offset;
1811 }
1812 }
1813 }
1814
1815 cmd_buffer->state.compute_dirty = 0;
1816
1817 genX(cmd_buffer_apply_pipe_flushes)(cmd_buffer);
1818 }
1819
1820 #if GEN_GEN == 7
1821
1822 static bool
1823 verify_cmd_parser(const struct anv_device *device,
1824 int required_version,
1825 const char *function)
1826 {
1827 if (device->instance->physicalDevice.cmd_parser_version < required_version) {
1828 vk_errorf(VK_ERROR_FEATURE_NOT_PRESENT,
1829 "cmd parser version %d is required for %s",
1830 required_version, function);
1831 return false;
1832 } else {
1833 return true;
1834 }
1835 }
1836
1837 #endif
1838
1839 void genX(CmdDispatch)(
1840 VkCommandBuffer commandBuffer,
1841 uint32_t x,
1842 uint32_t y,
1843 uint32_t z)
1844 {
1845 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
1846 struct anv_pipeline *pipeline = cmd_buffer->state.compute_pipeline;
1847 const struct brw_cs_prog_data *prog_data = get_cs_prog_data(pipeline);
1848
1849 if (prog_data->uses_num_work_groups) {
1850 struct anv_state state =
1851 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, 12, 4);
1852 uint32_t *sizes = state.map;
1853 sizes[0] = x;
1854 sizes[1] = y;
1855 sizes[2] = z;
1856 if (!cmd_buffer->device->info.has_llc)
1857 anv_state_clflush(state);
1858 cmd_buffer->state.num_workgroups_offset = state.offset;
1859 cmd_buffer->state.num_workgroups_bo =
1860 &cmd_buffer->device->dynamic_state_block_pool.bo;
1861 }
1862
1863 genX(cmd_buffer_flush_compute_state)(cmd_buffer);
1864
1865 anv_batch_emit(&cmd_buffer->batch, GENX(GPGPU_WALKER), ggw) {
1866 ggw.SIMDSize = prog_data->simd_size / 16;
1867 ggw.ThreadDepthCounterMaximum = 0;
1868 ggw.ThreadHeightCounterMaximum = 0;
1869 ggw.ThreadWidthCounterMaximum = prog_data->threads - 1;
1870 ggw.ThreadGroupIDXDimension = x;
1871 ggw.ThreadGroupIDYDimension = y;
1872 ggw.ThreadGroupIDZDimension = z;
1873 ggw.RightExecutionMask = pipeline->cs_right_mask;
1874 ggw.BottomExecutionMask = 0xffffffff;
1875 }
1876
1877 anv_batch_emit(&cmd_buffer->batch, GENX(MEDIA_STATE_FLUSH), msf);
1878 }
1879
1880 #define GPGPU_DISPATCHDIMX 0x2500
1881 #define GPGPU_DISPATCHDIMY 0x2504
1882 #define GPGPU_DISPATCHDIMZ 0x2508
1883
1884 #define MI_PREDICATE_SRC0 0x2400
1885 #define MI_PREDICATE_SRC1 0x2408
1886
1887 void genX(CmdDispatchIndirect)(
1888 VkCommandBuffer commandBuffer,
1889 VkBuffer _buffer,
1890 VkDeviceSize offset)
1891 {
1892 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
1893 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
1894 struct anv_pipeline *pipeline = cmd_buffer->state.compute_pipeline;
1895 const struct brw_cs_prog_data *prog_data = get_cs_prog_data(pipeline);
1896 struct anv_bo *bo = buffer->bo;
1897 uint32_t bo_offset = buffer->offset + offset;
1898 struct anv_batch *batch = &cmd_buffer->batch;
1899
1900 #if GEN_GEN == 7
1901 /* Linux 4.4 added command parser version 5 which allows the GPGPU
1902 * indirect dispatch registers to be written.
1903 */
1904 if (!verify_cmd_parser(cmd_buffer->device, 5, "vkCmdDispatchIndirect"))
1905 return;
1906 #endif
1907
1908 if (prog_data->uses_num_work_groups) {
1909 cmd_buffer->state.num_workgroups_offset = bo_offset;
1910 cmd_buffer->state.num_workgroups_bo = bo;
1911 }
1912
1913 genX(cmd_buffer_flush_compute_state)(cmd_buffer);
1914
1915 emit_lrm(batch, GPGPU_DISPATCHDIMX, bo, bo_offset);
1916 emit_lrm(batch, GPGPU_DISPATCHDIMY, bo, bo_offset + 4);
1917 emit_lrm(batch, GPGPU_DISPATCHDIMZ, bo, bo_offset + 8);
1918
1919 #if GEN_GEN <= 7
1920 /* Clear upper 32-bits of SRC0 and all 64-bits of SRC1 */
1921 emit_lri(batch, MI_PREDICATE_SRC0 + 4, 0);
1922 emit_lri(batch, MI_PREDICATE_SRC1 + 0, 0);
1923 emit_lri(batch, MI_PREDICATE_SRC1 + 4, 0);
1924
1925 /* Load compute_dispatch_indirect_x_size into SRC0 */
1926 emit_lrm(batch, MI_PREDICATE_SRC0, bo, bo_offset + 0);
1927
1928 /* predicate = (compute_dispatch_indirect_x_size == 0); */
1929 anv_batch_emit(batch, GENX(MI_PREDICATE), mip) {
1930 mip.LoadOperation = LOAD_LOAD;
1931 mip.CombineOperation = COMBINE_SET;
1932 mip.CompareOperation = COMPARE_SRCS_EQUAL;
1933 }
1934
1935 /* Load compute_dispatch_indirect_y_size into SRC0 */
1936 emit_lrm(batch, MI_PREDICATE_SRC0, bo, bo_offset + 4);
1937
1938 /* predicate |= (compute_dispatch_indirect_y_size == 0); */
1939 anv_batch_emit(batch, GENX(MI_PREDICATE), mip) {
1940 mip.LoadOperation = LOAD_LOAD;
1941 mip.CombineOperation = COMBINE_OR;
1942 mip.CompareOperation = COMPARE_SRCS_EQUAL;
1943 }
1944
1945 /* Load compute_dispatch_indirect_z_size into SRC0 */
1946 emit_lrm(batch, MI_PREDICATE_SRC0, bo, bo_offset + 8);
1947
1948 /* predicate |= (compute_dispatch_indirect_z_size == 0); */
1949 anv_batch_emit(batch, GENX(MI_PREDICATE), mip) {
1950 mip.LoadOperation = LOAD_LOAD;
1951 mip.CombineOperation = COMBINE_OR;
1952 mip.CompareOperation = COMPARE_SRCS_EQUAL;
1953 }
1954
1955 /* predicate = !predicate; */
1956 #define COMPARE_FALSE 1
1957 anv_batch_emit(batch, GENX(MI_PREDICATE), mip) {
1958 mip.LoadOperation = LOAD_LOADINV;
1959 mip.CombineOperation = COMBINE_OR;
1960 mip.CompareOperation = COMPARE_FALSE;
1961 }
1962 #endif
1963
1964 anv_batch_emit(batch, GENX(GPGPU_WALKER), ggw) {
1965 ggw.IndirectParameterEnable = true;
1966 ggw.PredicateEnable = GEN_GEN <= 7;
1967 ggw.SIMDSize = prog_data->simd_size / 16;
1968 ggw.ThreadDepthCounterMaximum = 0;
1969 ggw.ThreadHeightCounterMaximum = 0;
1970 ggw.ThreadWidthCounterMaximum = prog_data->threads - 1;
1971 ggw.RightExecutionMask = pipeline->cs_right_mask;
1972 ggw.BottomExecutionMask = 0xffffffff;
1973 }
1974
1975 anv_batch_emit(batch, GENX(MEDIA_STATE_FLUSH), msf);
1976 }
1977
1978 static void
1979 flush_pipeline_before_pipeline_select(struct anv_cmd_buffer *cmd_buffer,
1980 uint32_t pipeline)
1981 {
1982 #if GEN_GEN >= 8 && GEN_GEN < 10
1983 /* From the Broadwell PRM, Volume 2a: Instructions, PIPELINE_SELECT:
1984 *
1985 * Software must clear the COLOR_CALC_STATE Valid field in
1986 * 3DSTATE_CC_STATE_POINTERS command prior to send a PIPELINE_SELECT
1987 * with Pipeline Select set to GPGPU.
1988 *
1989 * The internal hardware docs recommend the same workaround for Gen9
1990 * hardware too.
1991 */
1992 if (pipeline == GPGPU)
1993 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_CC_STATE_POINTERS), t);
1994 #elif GEN_GEN <= 7
1995 /* From "BXML » GT » MI » vol1a GPU Overview » [Instruction]
1996 * PIPELINE_SELECT [DevBWR+]":
1997 *
1998 * Project: DEVSNB+
1999 *
2000 * Software must ensure all the write caches are flushed through a
2001 * stalling PIPE_CONTROL command followed by another PIPE_CONTROL
2002 * command to invalidate read only caches prior to programming
2003 * MI_PIPELINE_SELECT command to change the Pipeline Select Mode.
2004 */
2005 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
2006 pc.RenderTargetCacheFlushEnable = true;
2007 pc.DepthCacheFlushEnable = true;
2008 pc.DCFlushEnable = true;
2009 pc.PostSyncOperation = NoWrite;
2010 pc.CommandStreamerStallEnable = true;
2011 }
2012
2013 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
2014 pc.TextureCacheInvalidationEnable = true;
2015 pc.ConstantCacheInvalidationEnable = true;
2016 pc.StateCacheInvalidationEnable = true;
2017 pc.InstructionCacheInvalidateEnable = true;
2018 pc.PostSyncOperation = NoWrite;
2019 }
2020 #endif
2021 }
2022
2023 void
2024 genX(flush_pipeline_select_3d)(struct anv_cmd_buffer *cmd_buffer)
2025 {
2026 if (cmd_buffer->state.current_pipeline != _3D) {
2027 flush_pipeline_before_pipeline_select(cmd_buffer, _3D);
2028
2029 anv_batch_emit(&cmd_buffer->batch, GENX(PIPELINE_SELECT), ps) {
2030 #if GEN_GEN >= 9
2031 ps.MaskBits = 3;
2032 #endif
2033 ps.PipelineSelection = _3D;
2034 }
2035
2036 cmd_buffer->state.current_pipeline = _3D;
2037 }
2038 }
2039
2040 void
2041 genX(flush_pipeline_select_gpgpu)(struct anv_cmd_buffer *cmd_buffer)
2042 {
2043 if (cmd_buffer->state.current_pipeline != GPGPU) {
2044 flush_pipeline_before_pipeline_select(cmd_buffer, GPGPU);
2045
2046 anv_batch_emit(&cmd_buffer->batch, GENX(PIPELINE_SELECT), ps) {
2047 #if GEN_GEN >= 9
2048 ps.MaskBits = 3;
2049 #endif
2050 ps.PipelineSelection = GPGPU;
2051 }
2052
2053 cmd_buffer->state.current_pipeline = GPGPU;
2054 }
2055 }
2056
2057 void
2058 genX(cmd_buffer_emit_gen7_depth_flush)(struct anv_cmd_buffer *cmd_buffer)
2059 {
2060 if (GEN_GEN >= 8)
2061 return;
2062
2063 /* From the Haswell PRM, documentation for 3DSTATE_DEPTH_BUFFER:
2064 *
2065 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e., any
2066 * combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
2067 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
2068 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
2069 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
2070 * Depth Flush Bit set, followed by another pipelined depth stall
2071 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
2072 * guarantee that the pipeline from WM onwards is already flushed (e.g.,
2073 * via a preceding MI_FLUSH)."
2074 */
2075 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pipe) {
2076 pipe.DepthStallEnable = true;
2077 }
2078 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pipe) {
2079 pipe.DepthCacheFlushEnable = true;
2080 }
2081 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pipe) {
2082 pipe.DepthStallEnable = true;
2083 }
2084 }
2085
2086 static uint32_t
2087 depth_stencil_surface_type(enum isl_surf_dim dim)
2088 {
2089 switch (dim) {
2090 case ISL_SURF_DIM_1D:
2091 if (GEN_GEN >= 9) {
2092 /* From the Sky Lake PRM, 3DSTATAE_DEPTH_BUFFER::SurfaceType
2093 *
2094 * Programming Notes:
2095 * The Surface Type of the depth buffer must be the same as the
2096 * Surface Type of the render target(s) (defined in
2097 * SURFACE_STATE), unless either the depth buffer or render
2098 * targets are SURFTYPE_NULL (see exception below for SKL). 1D
2099 * surface type not allowed for depth surface and stencil surface.
2100 *
2101 * Workaround:
2102 * If depth/stencil is enabled with 1D render target,
2103 * depth/stencil surface type needs to be set to 2D surface type
2104 * and height set to 1. Depth will use (legacy) TileY and stencil
2105 * will use TileW. For this case only, the Surface Type of the
2106 * depth buffer can be 2D while the Surface Type of the render
2107 * target(s) are 1D, representing an exception to a programming
2108 * note above.
2109 */
2110 return SURFTYPE_2D;
2111 } else {
2112 return SURFTYPE_1D;
2113 }
2114 case ISL_SURF_DIM_2D:
2115 return SURFTYPE_2D;
2116 case ISL_SURF_DIM_3D:
2117 if (GEN_GEN >= 9) {
2118 /* The Sky Lake docs list the value for 3D as "Reserved". However,
2119 * they have the exact same layout as 2D arrays on gen9+, so we can
2120 * just use 2D here.
2121 */
2122 return SURFTYPE_2D;
2123 } else {
2124 return SURFTYPE_3D;
2125 }
2126 default:
2127 unreachable("Invalid surface dimension");
2128 }
2129 }
2130
2131 static void
2132 cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
2133 {
2134 struct anv_device *device = cmd_buffer->device;
2135 const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
2136 const struct anv_image_view *iview =
2137 anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
2138 const struct anv_image *image = iview ? iview->image : NULL;
2139 const bool has_depth = image && (image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT);
2140 const uint32_t ds = cmd_buffer->state.subpass->depth_stencil_attachment;
2141 const bool has_hiz = image != NULL &&
2142 cmd_buffer->state.attachments[ds].aux_usage == ISL_AUX_USAGE_HIZ;
2143 const bool has_stencil =
2144 image && (image->aspects & VK_IMAGE_ASPECT_STENCIL_BIT);
2145
2146 /* FIXME: Implement the PMA stall W/A */
2147 /* FIXME: Width and Height are wrong */
2148
2149 genX(cmd_buffer_emit_gen7_depth_flush)(cmd_buffer);
2150
2151 /* Emit 3DSTATE_DEPTH_BUFFER */
2152 if (has_depth) {
2153 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DEPTH_BUFFER), db) {
2154 db.SurfaceType =
2155 depth_stencil_surface_type(image->depth_surface.isl.dim);
2156 db.DepthWriteEnable = true;
2157 db.StencilWriteEnable = has_stencil;
2158 db.HierarchicalDepthBufferEnable = has_hiz;
2159
2160 db.SurfaceFormat = isl_surf_get_depth_format(&device->isl_dev,
2161 &image->depth_surface.isl);
2162
2163 db.SurfaceBaseAddress = (struct anv_address) {
2164 .bo = image->bo,
2165 .offset = image->offset + image->depth_surface.offset,
2166 };
2167 db.DepthBufferObjectControlState = GENX(MOCS);
2168
2169 db.SurfacePitch = image->depth_surface.isl.row_pitch - 1;
2170 db.Height = image->extent.height - 1;
2171 db.Width = image->extent.width - 1;
2172 db.LOD = iview->isl.base_level;
2173 db.MinimumArrayElement = iview->isl.base_array_layer;
2174
2175 assert(image->depth_surface.isl.dim != ISL_SURF_DIM_3D);
2176 db.Depth =
2177 db.RenderTargetViewExtent =
2178 iview->isl.array_len - iview->isl.base_array_layer - 1;
2179
2180 #if GEN_GEN >= 8
2181 db.SurfaceQPitch =
2182 isl_surf_get_array_pitch_el_rows(&image->depth_surface.isl) >> 2;
2183 #endif
2184 }
2185 } else {
2186 /* Even when no depth buffer is present, the hardware requires that
2187 * 3DSTATE_DEPTH_BUFFER be programmed correctly. The Broadwell PRM says:
2188 *
2189 * If a null depth buffer is bound, the driver must instead bind depth as:
2190 * 3DSTATE_DEPTH.SurfaceType = SURFTYPE_2D
2191 * 3DSTATE_DEPTH.Width = 1
2192 * 3DSTATE_DEPTH.Height = 1
2193 * 3DSTATE_DEPTH.SuraceFormat = D16_UNORM
2194 * 3DSTATE_DEPTH.SurfaceBaseAddress = 0
2195 * 3DSTATE_DEPTH.HierarchicalDepthBufferEnable = 0
2196 * 3DSTATE_WM_DEPTH_STENCIL.DepthTestEnable = 0
2197 * 3DSTATE_WM_DEPTH_STENCIL.DepthBufferWriteEnable = 0
2198 *
2199 * The PRM is wrong, though. The width and height must be programmed to
2200 * actual framebuffer's width and height, even when neither depth buffer
2201 * nor stencil buffer is present. Also, D16_UNORM is not allowed to
2202 * be combined with a stencil buffer so we use D32_FLOAT instead.
2203 */
2204 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DEPTH_BUFFER), db) {
2205 if (has_stencil) {
2206 db.SurfaceType =
2207 depth_stencil_surface_type(image->stencil_surface.isl.dim);
2208 } else {
2209 db.SurfaceType = SURFTYPE_2D;
2210 }
2211 db.SurfaceFormat = D32_FLOAT;
2212 db.Width = MAX2(fb->width, 1) - 1;
2213 db.Height = MAX2(fb->height, 1) - 1;
2214 db.StencilWriteEnable = has_stencil;
2215 }
2216 }
2217
2218 if (has_hiz) {
2219 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_HIER_DEPTH_BUFFER), hdb) {
2220 hdb.HierarchicalDepthBufferObjectControlState = GENX(MOCS);
2221 hdb.SurfacePitch = image->aux_surface.isl.row_pitch - 1;
2222 hdb.SurfaceBaseAddress = (struct anv_address) {
2223 .bo = image->bo,
2224 .offset = image->offset + image->aux_surface.offset,
2225 };
2226 #if GEN_GEN >= 8
2227 /* From the SKL PRM Vol2a:
2228 *
2229 * The interpretation of this field is dependent on Surface Type
2230 * as follows:
2231 * - SURFTYPE_1D: distance in pixels between array slices
2232 * - SURFTYPE_2D/CUBE: distance in rows between array slices
2233 * - SURFTYPE_3D: distance in rows between R - slices
2234 *
2235 * Unfortunately, the docs aren't 100% accurate here. They fail to
2236 * mention that the 1-D rule only applies to linear 1-D images.
2237 * Since depth and HiZ buffers are always tiled, they are treated as
2238 * 2-D images. Prior to Sky Lake, this field is always in rows.
2239 */
2240 hdb.SurfaceQPitch =
2241 isl_surf_get_array_pitch_sa_rows(&image->aux_surface.isl) >> 2;
2242 #endif
2243 }
2244 } else {
2245 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_HIER_DEPTH_BUFFER), hdb);
2246 }
2247
2248 /* Emit 3DSTATE_STENCIL_BUFFER */
2249 if (has_stencil) {
2250 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_STENCIL_BUFFER), sb) {
2251 #if GEN_GEN >= 8 || GEN_IS_HASWELL
2252 sb.StencilBufferEnable = true;
2253 #endif
2254 sb.StencilBufferObjectControlState = GENX(MOCS);
2255
2256 sb.SurfacePitch = image->stencil_surface.isl.row_pitch - 1;
2257
2258 #if GEN_GEN >= 8
2259 sb.SurfaceQPitch = isl_surf_get_array_pitch_el_rows(&image->stencil_surface.isl) >> 2;
2260 #endif
2261 sb.SurfaceBaseAddress = (struct anv_address) {
2262 .bo = image->bo,
2263 .offset = image->offset + image->stencil_surface.offset,
2264 };
2265 }
2266 } else {
2267 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_STENCIL_BUFFER), sb);
2268 }
2269
2270 /* From the IVB PRM Vol2P1, 11.5.5.4 3DSTATE_CLEAR_PARAMS:
2271 *
2272 * 3DSTATE_CLEAR_PARAMS must always be programmed in the along with
2273 * the other Depth/Stencil state commands(i.e. 3DSTATE_DEPTH_BUFFER,
2274 * 3DSTATE_STENCIL_BUFFER, or 3DSTATE_HIER_DEPTH_BUFFER)
2275 *
2276 * Testing also shows that some variant of this restriction may exist HSW+.
2277 * On BDW+, it is not possible to emit 2 of these packets consecutively when
2278 * both have DepthClearValueValid set. An analysis of such state programming
2279 * on SKL showed that the GPU doesn't register the latter packet's clear
2280 * value.
2281 */
2282 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_CLEAR_PARAMS), cp) {
2283 if (has_hiz) {
2284 cp.DepthClearValueValid = true;
2285 const uint32_t ds =
2286 cmd_buffer->state.subpass->depth_stencil_attachment;
2287 cp.DepthClearValue =
2288 cmd_buffer->state.attachments[ds].clear_value.depthStencil.depth;
2289 }
2290 }
2291 }
2292
2293 static void
2294 genX(cmd_buffer_set_subpass)(struct anv_cmd_buffer *cmd_buffer,
2295 struct anv_subpass *subpass)
2296 {
2297 cmd_buffer->state.subpass = subpass;
2298
2299 cmd_buffer->state.dirty |= ANV_CMD_DIRTY_RENDER_TARGETS;
2300
2301 const struct anv_image_view *iview =
2302 anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
2303
2304 if (iview) {
2305 anv_gen8_hiz_op_resolve(cmd_buffer, iview->image,
2306 BLORP_HIZ_OP_HIZ_RESOLVE);
2307 }
2308
2309 cmd_buffer_emit_depth_stencil(cmd_buffer);
2310
2311 anv_cmd_buffer_clear_subpass(cmd_buffer);
2312 }
2313
2314 void genX(CmdBeginRenderPass)(
2315 VkCommandBuffer commandBuffer,
2316 const VkRenderPassBeginInfo* pRenderPassBegin,
2317 VkSubpassContents contents)
2318 {
2319 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
2320 ANV_FROM_HANDLE(anv_render_pass, pass, pRenderPassBegin->renderPass);
2321 ANV_FROM_HANDLE(anv_framebuffer, framebuffer, pRenderPassBegin->framebuffer);
2322
2323 cmd_buffer->state.framebuffer = framebuffer;
2324 cmd_buffer->state.pass = pass;
2325 cmd_buffer->state.render_area = pRenderPassBegin->renderArea;
2326 genX(cmd_buffer_setup_attachments)(cmd_buffer, pass, pRenderPassBegin);
2327
2328 genX(flush_pipeline_select_3d)(cmd_buffer);
2329
2330 genX(cmd_buffer_set_subpass)(cmd_buffer, pass->subpasses);
2331 }
2332
2333 void genX(CmdNextSubpass)(
2334 VkCommandBuffer commandBuffer,
2335 VkSubpassContents contents)
2336 {
2337 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
2338
2339 assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2340
2341 const struct anv_image_view *iview =
2342 anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
2343
2344 if (iview) {
2345 anv_gen8_hiz_op_resolve(cmd_buffer, iview->image,
2346 BLORP_HIZ_OP_DEPTH_RESOLVE);
2347 }
2348
2349 anv_cmd_buffer_resolve_subpass(cmd_buffer);
2350 genX(cmd_buffer_set_subpass)(cmd_buffer, cmd_buffer->state.subpass + 1);
2351 }
2352
2353 void genX(CmdEndRenderPass)(
2354 VkCommandBuffer commandBuffer)
2355 {
2356 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
2357
2358 const struct anv_image_view *iview =
2359 anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
2360
2361 if (iview) {
2362 anv_gen8_hiz_op_resolve(cmd_buffer, iview->image,
2363 BLORP_HIZ_OP_DEPTH_RESOLVE);
2364 }
2365
2366 anv_cmd_buffer_resolve_subpass(cmd_buffer);
2367
2368 #ifndef NDEBUG
2369 anv_dump_add_framebuffer(cmd_buffer, cmd_buffer->state.framebuffer);
2370 #endif
2371 }
2372
2373 static void
2374 emit_ps_depth_count(struct anv_cmd_buffer *cmd_buffer,
2375 struct anv_bo *bo, uint32_t offset)
2376 {
2377 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
2378 pc.DestinationAddressType = DAT_PPGTT;
2379 pc.PostSyncOperation = WritePSDepthCount;
2380 pc.DepthStallEnable = true;
2381 pc.Address = (struct anv_address) { bo, offset };
2382
2383 if (GEN_GEN == 9 && cmd_buffer->device->info.gt == 4)
2384 pc.CommandStreamerStallEnable = true;
2385 }
2386 }
2387
2388 static void
2389 emit_query_availability(struct anv_cmd_buffer *cmd_buffer,
2390 struct anv_bo *bo, uint32_t offset)
2391 {
2392 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
2393 pc.DestinationAddressType = DAT_PPGTT;
2394 pc.PostSyncOperation = WriteImmediateData;
2395 pc.Address = (struct anv_address) { bo, offset };
2396 pc.ImmediateData = 1;
2397 }
2398 }
2399
2400 void genX(CmdBeginQuery)(
2401 VkCommandBuffer commandBuffer,
2402 VkQueryPool queryPool,
2403 uint32_t query,
2404 VkQueryControlFlags flags)
2405 {
2406 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
2407 ANV_FROM_HANDLE(anv_query_pool, pool, queryPool);
2408
2409 /* Workaround: When meta uses the pipeline with the VS disabled, it seems
2410 * that the pipelining of the depth write breaks. What we see is that
2411 * samples from the render pass clear leaks into the first query
2412 * immediately after the clear. Doing a pipecontrol with a post-sync
2413 * operation and DepthStallEnable seems to work around the issue.
2414 */
2415 if (cmd_buffer->state.need_query_wa) {
2416 cmd_buffer->state.need_query_wa = false;
2417 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
2418 pc.DepthCacheFlushEnable = true;
2419 pc.DepthStallEnable = true;
2420 }
2421 }
2422
2423 switch (pool->type) {
2424 case VK_QUERY_TYPE_OCCLUSION:
2425 emit_ps_depth_count(cmd_buffer, &pool->bo,
2426 query * sizeof(struct anv_query_pool_slot));
2427 break;
2428
2429 case VK_QUERY_TYPE_PIPELINE_STATISTICS:
2430 default:
2431 unreachable("");
2432 }
2433 }
2434
2435 void genX(CmdEndQuery)(
2436 VkCommandBuffer commandBuffer,
2437 VkQueryPool queryPool,
2438 uint32_t query)
2439 {
2440 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
2441 ANV_FROM_HANDLE(anv_query_pool, pool, queryPool);
2442
2443 switch (pool->type) {
2444 case VK_QUERY_TYPE_OCCLUSION:
2445 emit_ps_depth_count(cmd_buffer, &pool->bo,
2446 query * sizeof(struct anv_query_pool_slot) + 8);
2447
2448 emit_query_availability(cmd_buffer, &pool->bo,
2449 query * sizeof(struct anv_query_pool_slot) + 16);
2450 break;
2451
2452 case VK_QUERY_TYPE_PIPELINE_STATISTICS:
2453 default:
2454 unreachable("");
2455 }
2456 }
2457
2458 #define TIMESTAMP 0x2358
2459
2460 void genX(CmdWriteTimestamp)(
2461 VkCommandBuffer commandBuffer,
2462 VkPipelineStageFlagBits pipelineStage,
2463 VkQueryPool queryPool,
2464 uint32_t query)
2465 {
2466 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
2467 ANV_FROM_HANDLE(anv_query_pool, pool, queryPool);
2468 uint32_t offset = query * sizeof(struct anv_query_pool_slot);
2469
2470 assert(pool->type == VK_QUERY_TYPE_TIMESTAMP);
2471
2472 switch (pipelineStage) {
2473 case VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT:
2474 anv_batch_emit(&cmd_buffer->batch, GENX(MI_STORE_REGISTER_MEM), srm) {
2475 srm.RegisterAddress = TIMESTAMP;
2476 srm.MemoryAddress = (struct anv_address) { &pool->bo, offset };
2477 }
2478 anv_batch_emit(&cmd_buffer->batch, GENX(MI_STORE_REGISTER_MEM), srm) {
2479 srm.RegisterAddress = TIMESTAMP + 4;
2480 srm.MemoryAddress = (struct anv_address) { &pool->bo, offset + 4 };
2481 }
2482 break;
2483
2484 default:
2485 /* Everything else is bottom-of-pipe */
2486 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
2487 pc.DestinationAddressType = DAT_PPGTT;
2488 pc.PostSyncOperation = WriteTimestamp;
2489 pc.Address = (struct anv_address) { &pool->bo, offset };
2490
2491 if (GEN_GEN == 9 && cmd_buffer->device->info.gt == 4)
2492 pc.CommandStreamerStallEnable = true;
2493 }
2494 break;
2495 }
2496
2497 emit_query_availability(cmd_buffer, &pool->bo, query + 16);
2498 }
2499
2500 #if GEN_GEN > 7 || GEN_IS_HASWELL
2501
2502 #define alu_opcode(v) __gen_uint((v), 20, 31)
2503 #define alu_operand1(v) __gen_uint((v), 10, 19)
2504 #define alu_operand2(v) __gen_uint((v), 0, 9)
2505 #define alu(opcode, operand1, operand2) \
2506 alu_opcode(opcode) | alu_operand1(operand1) | alu_operand2(operand2)
2507
2508 #define OPCODE_NOOP 0x000
2509 #define OPCODE_LOAD 0x080
2510 #define OPCODE_LOADINV 0x480
2511 #define OPCODE_LOAD0 0x081
2512 #define OPCODE_LOAD1 0x481
2513 #define OPCODE_ADD 0x100
2514 #define OPCODE_SUB 0x101
2515 #define OPCODE_AND 0x102
2516 #define OPCODE_OR 0x103
2517 #define OPCODE_XOR 0x104
2518 #define OPCODE_STORE 0x180
2519 #define OPCODE_STOREINV 0x580
2520
2521 #define OPERAND_R0 0x00
2522 #define OPERAND_R1 0x01
2523 #define OPERAND_R2 0x02
2524 #define OPERAND_R3 0x03
2525 #define OPERAND_R4 0x04
2526 #define OPERAND_SRCA 0x20
2527 #define OPERAND_SRCB 0x21
2528 #define OPERAND_ACCU 0x31
2529 #define OPERAND_ZF 0x32
2530 #define OPERAND_CF 0x33
2531
2532 #define CS_GPR(n) (0x2600 + (n) * 8)
2533
2534 static void
2535 emit_load_alu_reg_u64(struct anv_batch *batch, uint32_t reg,
2536 struct anv_bo *bo, uint32_t offset)
2537 {
2538 anv_batch_emit(batch, GENX(MI_LOAD_REGISTER_MEM), lrm) {
2539 lrm.RegisterAddress = reg,
2540 lrm.MemoryAddress = (struct anv_address) { bo, offset };
2541 }
2542 anv_batch_emit(batch, GENX(MI_LOAD_REGISTER_MEM), lrm) {
2543 lrm.RegisterAddress = reg + 4;
2544 lrm.MemoryAddress = (struct anv_address) { bo, offset + 4 };
2545 }
2546 }
2547
2548 static void
2549 store_query_result(struct anv_batch *batch, uint32_t reg,
2550 struct anv_bo *bo, uint32_t offset, VkQueryResultFlags flags)
2551 {
2552 anv_batch_emit(batch, GENX(MI_STORE_REGISTER_MEM), srm) {
2553 srm.RegisterAddress = reg;
2554 srm.MemoryAddress = (struct anv_address) { bo, offset };
2555 }
2556
2557 if (flags & VK_QUERY_RESULT_64_BIT) {
2558 anv_batch_emit(batch, GENX(MI_STORE_REGISTER_MEM), srm) {
2559 srm.RegisterAddress = reg + 4;
2560 srm.MemoryAddress = (struct anv_address) { bo, offset + 4 };
2561 }
2562 }
2563 }
2564
2565 void genX(CmdCopyQueryPoolResults)(
2566 VkCommandBuffer commandBuffer,
2567 VkQueryPool queryPool,
2568 uint32_t firstQuery,
2569 uint32_t queryCount,
2570 VkBuffer destBuffer,
2571 VkDeviceSize destOffset,
2572 VkDeviceSize destStride,
2573 VkQueryResultFlags flags)
2574 {
2575 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
2576 ANV_FROM_HANDLE(anv_query_pool, pool, queryPool);
2577 ANV_FROM_HANDLE(anv_buffer, buffer, destBuffer);
2578 uint32_t slot_offset, dst_offset;
2579
2580 if (flags & VK_QUERY_RESULT_WAIT_BIT) {
2581 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
2582 pc.CommandStreamerStallEnable = true;
2583 pc.StallAtPixelScoreboard = true;
2584 }
2585 }
2586
2587 dst_offset = buffer->offset + destOffset;
2588 for (uint32_t i = 0; i < queryCount; i++) {
2589
2590 slot_offset = (firstQuery + i) * sizeof(struct anv_query_pool_slot);
2591 switch (pool->type) {
2592 case VK_QUERY_TYPE_OCCLUSION:
2593 emit_load_alu_reg_u64(&cmd_buffer->batch,
2594 CS_GPR(0), &pool->bo, slot_offset);
2595 emit_load_alu_reg_u64(&cmd_buffer->batch,
2596 CS_GPR(1), &pool->bo, slot_offset + 8);
2597
2598 /* FIXME: We need to clamp the result for 32 bit. */
2599
2600 uint32_t *dw = anv_batch_emitn(&cmd_buffer->batch, 5, GENX(MI_MATH));
2601 dw[1] = alu(OPCODE_LOAD, OPERAND_SRCA, OPERAND_R1);
2602 dw[2] = alu(OPCODE_LOAD, OPERAND_SRCB, OPERAND_R0);
2603 dw[3] = alu(OPCODE_SUB, 0, 0);
2604 dw[4] = alu(OPCODE_STORE, OPERAND_R2, OPERAND_ACCU);
2605 break;
2606
2607 case VK_QUERY_TYPE_TIMESTAMP:
2608 emit_load_alu_reg_u64(&cmd_buffer->batch,
2609 CS_GPR(2), &pool->bo, slot_offset);
2610 break;
2611
2612 default:
2613 unreachable("unhandled query type");
2614 }
2615
2616 store_query_result(&cmd_buffer->batch,
2617 CS_GPR(2), buffer->bo, dst_offset, flags);
2618
2619 if (flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) {
2620 emit_load_alu_reg_u64(&cmd_buffer->batch, CS_GPR(0),
2621 &pool->bo, slot_offset + 16);
2622 if (flags & VK_QUERY_RESULT_64_BIT)
2623 store_query_result(&cmd_buffer->batch,
2624 CS_GPR(0), buffer->bo, dst_offset + 8, flags);
2625 else
2626 store_query_result(&cmd_buffer->batch,
2627 CS_GPR(0), buffer->bo, dst_offset + 4, flags);
2628 }
2629
2630 dst_offset += destStride;
2631 }
2632 }
2633
2634 #else
2635 void genX(CmdCopyQueryPoolResults)(
2636 VkCommandBuffer commandBuffer,
2637 VkQueryPool queryPool,
2638 uint32_t firstQuery,
2639 uint32_t queryCount,
2640 VkBuffer destBuffer,
2641 VkDeviceSize destOffset,
2642 VkDeviceSize destStride,
2643 VkQueryResultFlags flags)
2644 {
2645 anv_finishme("Queries not yet supported on Ivy Bridge");
2646 }
2647 #endif