anv: Add initial support for cube maps
[mesa.git] / src / vulkan / gen8_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 #include <string.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29
30 #include "anv_private.h"
31
32 #include "gen8_pack.h"
33 #include "gen9_pack.h"
34
35 static void
36 cmd_buffer_flush_push_constants(struct anv_cmd_buffer *cmd_buffer)
37 {
38 static const uint32_t push_constant_opcodes[] = {
39 [MESA_SHADER_VERTEX] = 21,
40 [MESA_SHADER_TESS_CTRL] = 25, /* HS */
41 [MESA_SHADER_TESS_EVAL] = 26, /* DS */
42 [MESA_SHADER_GEOMETRY] = 22,
43 [MESA_SHADER_FRAGMENT] = 23,
44 [MESA_SHADER_COMPUTE] = 0,
45 };
46
47 VkShaderStageFlags flushed = 0;
48
49 anv_foreach_stage(stage, cmd_buffer->state.push_constants_dirty) {
50 if (stage == MESA_SHADER_COMPUTE)
51 continue;
52
53 struct anv_state state = anv_cmd_buffer_push_constants(cmd_buffer, stage);
54
55 if (state.offset == 0)
56 continue;
57
58 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_CONSTANT_VS),
59 ._3DCommandSubOpcode = push_constant_opcodes[stage],
60 .ConstantBody = {
61 .PointerToConstantBuffer0 = { .offset = state.offset },
62 .ConstantBuffer0ReadLength = DIV_ROUND_UP(state.alloc_size, 32),
63 });
64
65 flushed |= mesa_to_vk_shader_stage(stage);
66 }
67
68 cmd_buffer->state.push_constants_dirty &= ~flushed;
69 }
70
71 #if ANV_GEN == 8
72 static void
73 emit_viewport_state(struct anv_cmd_buffer *cmd_buffer,
74 uint32_t count, const VkViewport *viewports)
75 {
76 struct anv_state sf_clip_state =
77 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, count * 64, 64);
78 struct anv_state cc_state =
79 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, count * 8, 32);
80
81 for (uint32_t i = 0; i < count; i++) {
82 const VkViewport *vp = &viewports[i];
83
84 /* The gen7 state struct has just the matrix and guardband fields, the
85 * gen8 struct adds the min/max viewport fields. */
86 struct GENX(SF_CLIP_VIEWPORT) sf_clip_viewport = {
87 .ViewportMatrixElementm00 = vp->width / 2,
88 .ViewportMatrixElementm11 = vp->height / 2,
89 .ViewportMatrixElementm22 = (vp->maxDepth - vp->minDepth) / 2,
90 .ViewportMatrixElementm30 = vp->x + vp->width / 2,
91 .ViewportMatrixElementm31 = vp->y + vp->height / 2,
92 .ViewportMatrixElementm32 = (vp->maxDepth + vp->minDepth) / 2,
93 .XMinClipGuardband = -1.0f,
94 .XMaxClipGuardband = 1.0f,
95 .YMinClipGuardband = -1.0f,
96 .YMaxClipGuardband = 1.0f,
97 .XMinViewPort = vp->x,
98 .XMaxViewPort = vp->x + vp->width - 1,
99 .YMinViewPort = vp->y,
100 .YMaxViewPort = vp->y + vp->height - 1,
101 };
102
103 struct GENX(CC_VIEWPORT) cc_viewport = {
104 .MinimumDepth = vp->minDepth,
105 .MaximumDepth = vp->maxDepth
106 };
107
108 GENX(SF_CLIP_VIEWPORT_pack)(NULL, sf_clip_state.map + i * 64,
109 &sf_clip_viewport);
110 GENX(CC_VIEWPORT_pack)(NULL, cc_state.map + i * 32, &cc_viewport);
111 }
112
113 if (!cmd_buffer->device->info.has_llc) {
114 anv_state_clflush(sf_clip_state);
115 anv_state_clflush(cc_state);
116 }
117
118 anv_batch_emit(&cmd_buffer->batch,
119 GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC),
120 .CCViewportPointer = cc_state.offset);
121 anv_batch_emit(&cmd_buffer->batch,
122 GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP),
123 .SFClipViewportPointer = sf_clip_state.offset);
124 }
125
126 void
127 gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer)
128 {
129 if (cmd_buffer->state.dynamic.viewport.count > 0) {
130 emit_viewport_state(cmd_buffer, cmd_buffer->state.dynamic.viewport.count,
131 cmd_buffer->state.dynamic.viewport.viewports);
132 } else {
133 /* If viewport count is 0, this is taken to mean "use the default" */
134 emit_viewport_state(cmd_buffer, 1,
135 &(VkViewport) {
136 .x = 0.0f,
137 .y = 0.0f,
138 .width = cmd_buffer->state.framebuffer->width,
139 .height = cmd_buffer->state.framebuffer->height,
140 .minDepth = 0.0f,
141 .maxDepth = 1.0f,
142 });
143 }
144 }
145 #endif
146
147 static void
148 cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer)
149 {
150 struct anv_pipeline *pipeline = cmd_buffer->state.pipeline;
151 uint32_t *p;
152
153 uint32_t vb_emit = cmd_buffer->state.vb_dirty & pipeline->vb_used;
154
155 assert((pipeline->active_stages & VK_SHADER_STAGE_COMPUTE_BIT) == 0);
156
157 if (cmd_buffer->state.current_pipeline != _3D) {
158 anv_batch_emit(&cmd_buffer->batch, GENX(PIPELINE_SELECT),
159 #if ANV_GEN >= 9
160 .MaskBits = 3,
161 #endif
162 .PipelineSelection = _3D);
163 cmd_buffer->state.current_pipeline = _3D;
164 }
165
166 if (vb_emit) {
167 const uint32_t num_buffers = __builtin_popcount(vb_emit);
168 const uint32_t num_dwords = 1 + num_buffers * 4;
169
170 p = anv_batch_emitn(&cmd_buffer->batch, num_dwords,
171 GENX(3DSTATE_VERTEX_BUFFERS));
172 uint32_t vb, i = 0;
173 for_each_bit(vb, vb_emit) {
174 struct anv_buffer *buffer = cmd_buffer->state.vertex_bindings[vb].buffer;
175 uint32_t offset = cmd_buffer->state.vertex_bindings[vb].offset;
176
177 struct GENX(VERTEX_BUFFER_STATE) state = {
178 .VertexBufferIndex = vb,
179 .MemoryObjectControlState = GENX(MOCS),
180 .AddressModifyEnable = true,
181 .BufferPitch = pipeline->binding_stride[vb],
182 .BufferStartingAddress = { buffer->bo, buffer->offset + offset },
183 .BufferSize = buffer->size - offset
184 };
185
186 GENX(VERTEX_BUFFER_STATE_pack)(&cmd_buffer->batch, &p[1 + i * 4], &state);
187 i++;
188 }
189 }
190
191 if (cmd_buffer->state.dirty & ANV_CMD_DIRTY_PIPELINE) {
192 /* If somebody compiled a pipeline after starting a command buffer the
193 * scratch bo may have grown since we started this cmd buffer (and
194 * emitted STATE_BASE_ADDRESS). If we're binding that pipeline now,
195 * reemit STATE_BASE_ADDRESS so that we use the bigger scratch bo. */
196 if (cmd_buffer->state.scratch_size < pipeline->total_scratch)
197 anv_cmd_buffer_emit_state_base_address(cmd_buffer);
198
199 anv_batch_emit_batch(&cmd_buffer->batch, &pipeline->batch);
200 }
201
202 #if ANV_GEN >= 9
203 /* On SKL+ the new constants don't take effect until the next corresponding
204 * 3DSTATE_BINDING_TABLE_POINTER_* command is parsed so we need to ensure
205 * that is sent. As it is, we re-emit binding tables but we could hold on
206 * to the offset of the most recent binding table and only re-emit the
207 * 3DSTATE_BINDING_TABLE_POINTER_* command.
208 */
209 cmd_buffer->state.descriptors_dirty |=
210 cmd_buffer->state.push_constants_dirty &
211 cmd_buffer->state.pipeline->active_stages;
212 #endif
213
214 if (cmd_buffer->state.descriptors_dirty)
215 gen7_cmd_buffer_flush_descriptor_sets(cmd_buffer);
216
217 if (cmd_buffer->state.push_constants_dirty)
218 cmd_buffer_flush_push_constants(cmd_buffer);
219
220 if (cmd_buffer->state.dirty & ANV_CMD_DIRTY_DYNAMIC_VIEWPORT)
221 gen8_cmd_buffer_emit_viewport(cmd_buffer);
222
223 if (cmd_buffer->state.dirty & ANV_CMD_DIRTY_DYNAMIC_SCISSOR)
224 gen7_cmd_buffer_emit_scissor(cmd_buffer);
225
226 if (cmd_buffer->state.dirty & (ANV_CMD_DIRTY_PIPELINE |
227 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH)) {
228 uint32_t sf_dw[GENX(3DSTATE_SF_length)];
229 struct GENX(3DSTATE_SF) sf = {
230 GENX(3DSTATE_SF_header),
231 .LineWidth = cmd_buffer->state.dynamic.line_width,
232 };
233 GENX(3DSTATE_SF_pack)(NULL, sf_dw, &sf);
234 /* FIXME: gen9.fs */
235 anv_batch_emit_merge(&cmd_buffer->batch, sf_dw, pipeline->gen8.sf);
236 }
237
238 if (cmd_buffer->state.dirty & (ANV_CMD_DIRTY_PIPELINE |
239 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS)){
240 bool enable_bias = cmd_buffer->state.dynamic.depth_bias.bias != 0.0f ||
241 cmd_buffer->state.dynamic.depth_bias.slope != 0.0f;
242
243 uint32_t raster_dw[GENX(3DSTATE_RASTER_length)];
244 struct GENX(3DSTATE_RASTER) raster = {
245 GENX(3DSTATE_RASTER_header),
246 .GlobalDepthOffsetEnableSolid = enable_bias,
247 .GlobalDepthOffsetEnableWireframe = enable_bias,
248 .GlobalDepthOffsetEnablePoint = enable_bias,
249 .GlobalDepthOffsetConstant = cmd_buffer->state.dynamic.depth_bias.bias,
250 .GlobalDepthOffsetScale = cmd_buffer->state.dynamic.depth_bias.slope,
251 .GlobalDepthOffsetClamp = cmd_buffer->state.dynamic.depth_bias.clamp
252 };
253 GENX(3DSTATE_RASTER_pack)(NULL, raster_dw, &raster);
254 anv_batch_emit_merge(&cmd_buffer->batch, raster_dw,
255 pipeline->gen8.raster);
256 }
257
258 /* Stencil reference values moved from COLOR_CALC_STATE in gen8 to
259 * 3DSTATE_WM_DEPTH_STENCIL in gen9. That means the dirty bits gets split
260 * across different state packets for gen8 and gen9. We handle that by
261 * using a big old #if switch here.
262 */
263 #if ANV_GEN == 8
264 if (cmd_buffer->state.dirty & (ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS |
265 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE)) {
266 struct anv_state cc_state =
267 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer,
268 GEN8_COLOR_CALC_STATE_length, 64);
269 struct GEN8_COLOR_CALC_STATE cc = {
270 .BlendConstantColorRed = cmd_buffer->state.dynamic.blend_constants[0],
271 .BlendConstantColorGreen = cmd_buffer->state.dynamic.blend_constants[1],
272 .BlendConstantColorBlue = cmd_buffer->state.dynamic.blend_constants[2],
273 .BlendConstantColorAlpha = cmd_buffer->state.dynamic.blend_constants[3],
274 .StencilReferenceValue =
275 cmd_buffer->state.dynamic.stencil_reference.front,
276 .BackFaceStencilReferenceValue =
277 cmd_buffer->state.dynamic.stencil_reference.back,
278 };
279 GEN8_COLOR_CALC_STATE_pack(NULL, cc_state.map, &cc);
280
281 if (!cmd_buffer->device->info.has_llc)
282 anv_state_clflush(cc_state);
283
284 anv_batch_emit(&cmd_buffer->batch,
285 GEN8_3DSTATE_CC_STATE_POINTERS,
286 .ColorCalcStatePointer = cc_state.offset,
287 .ColorCalcStatePointerValid = true);
288 }
289
290 if (cmd_buffer->state.dirty & (ANV_CMD_DIRTY_PIPELINE |
291 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK |
292 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK)) {
293 uint32_t wm_depth_stencil_dw[GEN8_3DSTATE_WM_DEPTH_STENCIL_length];
294
295 struct GEN8_3DSTATE_WM_DEPTH_STENCIL wm_depth_stencil = {
296 GEN8_3DSTATE_WM_DEPTH_STENCIL_header,
297
298 /* Is this what we need to do? */
299 .StencilBufferWriteEnable =
300 cmd_buffer->state.dynamic.stencil_write_mask.front != 0,
301
302 .StencilTestMask =
303 cmd_buffer->state.dynamic.stencil_compare_mask.front & 0xff,
304 .StencilWriteMask =
305 cmd_buffer->state.dynamic.stencil_write_mask.front & 0xff,
306
307 .BackfaceStencilTestMask =
308 cmd_buffer->state.dynamic.stencil_compare_mask.back & 0xff,
309 .BackfaceStencilWriteMask =
310 cmd_buffer->state.dynamic.stencil_write_mask.back & 0xff,
311 };
312 GEN8_3DSTATE_WM_DEPTH_STENCIL_pack(NULL, wm_depth_stencil_dw,
313 &wm_depth_stencil);
314
315 anv_batch_emit_merge(&cmd_buffer->batch, wm_depth_stencil_dw,
316 pipeline->gen8.wm_depth_stencil);
317 }
318 #else
319 if (cmd_buffer->state.dirty & ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS) {
320 struct anv_state cc_state =
321 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer,
322 GEN9_COLOR_CALC_STATE_length, 64);
323 struct GEN9_COLOR_CALC_STATE cc = {
324 .BlendConstantColorRed = cmd_buffer->state.dynamic.blend_constants[0],
325 .BlendConstantColorGreen = cmd_buffer->state.dynamic.blend_constants[1],
326 .BlendConstantColorBlue = cmd_buffer->state.dynamic.blend_constants[2],
327 .BlendConstantColorAlpha = cmd_buffer->state.dynamic.blend_constants[3],
328 };
329 GEN9_COLOR_CALC_STATE_pack(NULL, cc_state.map, &cc);
330
331 if (!cmd_buffer->device->info.has_llc)
332 anv_state_clflush(cc_state);
333
334 anv_batch_emit(&cmd_buffer->batch,
335 GEN9_3DSTATE_CC_STATE_POINTERS,
336 .ColorCalcStatePointer = cc_state.offset,
337 .ColorCalcStatePointerValid = true);
338 }
339
340 if (cmd_buffer->state.dirty & (ANV_CMD_DIRTY_PIPELINE |
341 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK |
342 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK |
343 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE)) {
344 uint32_t dwords[GEN9_3DSTATE_WM_DEPTH_STENCIL_length];
345 struct anv_dynamic_state *d = &cmd_buffer->state.dynamic;
346 struct GEN9_3DSTATE_WM_DEPTH_STENCIL wm_depth_stencil = {
347 GEN9_3DSTATE_WM_DEPTH_STENCIL_header,
348
349 .StencilBufferWriteEnable = d->stencil_write_mask.front != 0,
350
351 .StencilTestMask = d->stencil_compare_mask.front & 0xff,
352 .StencilWriteMask = d->stencil_write_mask.front & 0xff,
353
354 .BackfaceStencilTestMask = d->stencil_compare_mask.back & 0xff,
355 .BackfaceStencilWriteMask = d->stencil_write_mask.back & 0xff,
356
357 .StencilReferenceValue = d->stencil_reference.front,
358 .BackfaceStencilReferenceValue = d->stencil_reference.back
359 };
360 GEN9_3DSTATE_WM_DEPTH_STENCIL_pack(NULL, dwords, &wm_depth_stencil);
361
362 anv_batch_emit_merge(&cmd_buffer->batch, dwords,
363 pipeline->gen9.wm_depth_stencil);
364 }
365 #endif
366
367 if (cmd_buffer->state.dirty & (ANV_CMD_DIRTY_PIPELINE |
368 ANV_CMD_DIRTY_INDEX_BUFFER)) {
369 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_VF),
370 .IndexedDrawCutIndexEnable = pipeline->primitive_restart,
371 .CutIndex = cmd_buffer->state.restart_index,
372 );
373 }
374
375 cmd_buffer->state.vb_dirty &= ~vb_emit;
376 cmd_buffer->state.dirty = 0;
377 }
378
379 void genX(CmdDraw)(
380 VkCommandBuffer commandBuffer,
381 uint32_t vertexCount,
382 uint32_t instanceCount,
383 uint32_t firstVertex,
384 uint32_t firstInstance)
385 {
386 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
387
388 cmd_buffer_flush_state(cmd_buffer);
389
390 anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE),
391 .VertexAccessType = SEQUENTIAL,
392 .VertexCountPerInstance = vertexCount,
393 .StartVertexLocation = firstVertex,
394 .InstanceCount = instanceCount,
395 .StartInstanceLocation = firstInstance,
396 .BaseVertexLocation = 0);
397 }
398
399 void genX(CmdDrawIndexed)(
400 VkCommandBuffer commandBuffer,
401 uint32_t indexCount,
402 uint32_t instanceCount,
403 uint32_t firstIndex,
404 int32_t vertexOffset,
405 uint32_t firstInstance)
406 {
407 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
408
409 cmd_buffer_flush_state(cmd_buffer);
410
411 anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE),
412 .VertexAccessType = RANDOM,
413 .VertexCountPerInstance = indexCount,
414 .StartVertexLocation = firstIndex,
415 .InstanceCount = instanceCount,
416 .StartInstanceLocation = firstInstance,
417 .BaseVertexLocation = vertexOffset);
418 }
419
420 static void
421 emit_lrm(struct anv_batch *batch,
422 uint32_t reg, struct anv_bo *bo, uint32_t offset)
423 {
424 anv_batch_emit(batch, GENX(MI_LOAD_REGISTER_MEM),
425 .RegisterAddress = reg,
426 .MemoryAddress = { bo, offset });
427 }
428
429 static void
430 emit_lri(struct anv_batch *batch, uint32_t reg, uint32_t imm)
431 {
432 anv_batch_emit(batch, GENX(MI_LOAD_REGISTER_IMM),
433 .RegisterOffset = reg,
434 .DataDWord = imm);
435 }
436
437 /* Auto-Draw / Indirect Registers */
438 #define GEN7_3DPRIM_END_OFFSET 0x2420
439 #define GEN7_3DPRIM_START_VERTEX 0x2430
440 #define GEN7_3DPRIM_VERTEX_COUNT 0x2434
441 #define GEN7_3DPRIM_INSTANCE_COUNT 0x2438
442 #define GEN7_3DPRIM_START_INSTANCE 0x243C
443 #define GEN7_3DPRIM_BASE_VERTEX 0x2440
444
445 void genX(CmdDrawIndirect)(
446 VkCommandBuffer commandBuffer,
447 VkBuffer _buffer,
448 VkDeviceSize offset,
449 uint32_t drawCount,
450 uint32_t stride)
451 {
452 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
453 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
454 struct anv_bo *bo = buffer->bo;
455 uint32_t bo_offset = buffer->offset + offset;
456
457 cmd_buffer_flush_state(cmd_buffer);
458
459 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_VERTEX_COUNT, bo, bo_offset);
460 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_INSTANCE_COUNT, bo, bo_offset + 4);
461 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_START_VERTEX, bo, bo_offset + 8);
462 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_START_INSTANCE, bo, bo_offset + 12);
463 emit_lri(&cmd_buffer->batch, GEN7_3DPRIM_BASE_VERTEX, 0);
464
465 anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE),
466 .IndirectParameterEnable = true,
467 .VertexAccessType = SEQUENTIAL);
468 }
469
470 void genX(CmdBindIndexBuffer)(
471 VkCommandBuffer commandBuffer,
472 VkBuffer _buffer,
473 VkDeviceSize offset,
474 VkIndexType indexType)
475 {
476 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
477 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
478
479 static const uint32_t vk_to_gen_index_type[] = {
480 [VK_INDEX_TYPE_UINT16] = INDEX_WORD,
481 [VK_INDEX_TYPE_UINT32] = INDEX_DWORD,
482 };
483
484 static const uint32_t restart_index_for_type[] = {
485 [VK_INDEX_TYPE_UINT16] = UINT16_MAX,
486 [VK_INDEX_TYPE_UINT32] = UINT32_MAX,
487 };
488
489 cmd_buffer->state.restart_index = restart_index_for_type[indexType];
490
491 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_INDEX_BUFFER),
492 .IndexFormat = vk_to_gen_index_type[indexType],
493 .MemoryObjectControlState = GENX(MOCS),
494 .BufferStartingAddress = { buffer->bo, buffer->offset + offset },
495 .BufferSize = buffer->size - offset);
496
497 cmd_buffer->state.dirty |= ANV_CMD_DIRTY_INDEX_BUFFER;
498 }
499
500 static VkResult
501 flush_compute_descriptor_set(struct anv_cmd_buffer *cmd_buffer)
502 {
503 struct anv_device *device = cmd_buffer->device;
504 struct anv_pipeline *pipeline = cmd_buffer->state.compute_pipeline;
505 struct anv_state surfaces = { 0, }, samplers = { 0, };
506 VkResult result;
507
508 result = anv_cmd_buffer_emit_samplers(cmd_buffer,
509 MESA_SHADER_COMPUTE, &samplers);
510 if (result != VK_SUCCESS)
511 return result;
512 result = anv_cmd_buffer_emit_binding_table(cmd_buffer,
513 MESA_SHADER_COMPUTE, &surfaces);
514 if (result != VK_SUCCESS)
515 return result;
516
517 struct anv_state push_state = anv_cmd_buffer_cs_push_constants(cmd_buffer);
518
519 const struct brw_cs_prog_data *cs_prog_data = &pipeline->cs_prog_data;
520 const struct brw_stage_prog_data *prog_data = &cs_prog_data->base;
521
522 unsigned local_id_dwords = cs_prog_data->local_invocation_id_regs * 8;
523 unsigned push_constant_data_size =
524 (prog_data->nr_params + local_id_dwords) * 4;
525 unsigned reg_aligned_constant_size = ALIGN(push_constant_data_size, 32);
526 unsigned push_constant_regs = reg_aligned_constant_size / 32;
527
528 if (push_state.alloc_size) {
529 anv_batch_emit(&cmd_buffer->batch, GENX(MEDIA_CURBE_LOAD),
530 .CURBETotalDataLength = push_state.alloc_size,
531 .CURBEDataStartAddress = push_state.offset);
532 }
533
534 struct anv_state state =
535 anv_state_pool_emit(&device->dynamic_state_pool,
536 GENX(INTERFACE_DESCRIPTOR_DATA), 64,
537 .KernelStartPointer = pipeline->cs_simd,
538 .KernelStartPointerHigh = 0,
539 .BindingTablePointer = surfaces.offset,
540 .BindingTableEntryCount = 0,
541 .SamplerStatePointer = samplers.offset,
542 .SamplerCount = 0,
543 .ConstantIndirectURBEntryReadLength = push_constant_regs,
544 .ConstantURBEntryReadOffset = 0,
545 .NumberofThreadsinGPGPUThreadGroup = 0);
546
547 uint32_t size = GENX(INTERFACE_DESCRIPTOR_DATA_length) * sizeof(uint32_t);
548 anv_batch_emit(&cmd_buffer->batch, GENX(MEDIA_INTERFACE_DESCRIPTOR_LOAD),
549 .InterfaceDescriptorTotalLength = size,
550 .InterfaceDescriptorDataStartAddress = state.offset);
551
552 return VK_SUCCESS;
553 }
554
555 static void
556 cmd_buffer_flush_compute_state(struct anv_cmd_buffer *cmd_buffer)
557 {
558 struct anv_pipeline *pipeline = cmd_buffer->state.compute_pipeline;
559 VkResult result;
560
561 assert(pipeline->active_stages == VK_SHADER_STAGE_COMPUTE_BIT);
562
563 if (cmd_buffer->state.current_pipeline != GPGPU) {
564 anv_batch_emit(&cmd_buffer->batch, GENX(PIPELINE_SELECT),
565 #if ANV_GEN >= 9
566 .MaskBits = 3,
567 #endif
568 .PipelineSelection = GPGPU);
569 cmd_buffer->state.current_pipeline = GPGPU;
570 }
571
572 if (cmd_buffer->state.compute_dirty & ANV_CMD_DIRTY_PIPELINE)
573 anv_batch_emit_batch(&cmd_buffer->batch, &pipeline->batch);
574
575 if ((cmd_buffer->state.descriptors_dirty & VK_SHADER_STAGE_COMPUTE_BIT) ||
576 (cmd_buffer->state.compute_dirty & ANV_CMD_DIRTY_PIPELINE)) {
577 result = flush_compute_descriptor_set(cmd_buffer);
578 assert(result == VK_SUCCESS);
579 cmd_buffer->state.descriptors_dirty &= ~VK_SHADER_STAGE_COMPUTE_BIT;
580 }
581
582 cmd_buffer->state.compute_dirty = 0;
583 }
584
585 void genX(CmdDrawIndexedIndirect)(
586 VkCommandBuffer commandBuffer,
587 VkBuffer _buffer,
588 VkDeviceSize offset,
589 uint32_t drawCount,
590 uint32_t stride)
591 {
592 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
593 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
594 struct anv_bo *bo = buffer->bo;
595 uint32_t bo_offset = buffer->offset + offset;
596
597 cmd_buffer_flush_state(cmd_buffer);
598
599 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_VERTEX_COUNT, bo, bo_offset);
600 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_INSTANCE_COUNT, bo, bo_offset + 4);
601 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_START_VERTEX, bo, bo_offset + 8);
602 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_BASE_VERTEX, bo, bo_offset + 12);
603 emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_START_INSTANCE, bo, bo_offset + 16);
604
605 anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE),
606 .IndirectParameterEnable = true,
607 .VertexAccessType = RANDOM);
608 }
609
610 void genX(CmdDispatch)(
611 VkCommandBuffer commandBuffer,
612 uint32_t x,
613 uint32_t y,
614 uint32_t z)
615 {
616 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
617 struct anv_pipeline *pipeline = cmd_buffer->state.compute_pipeline;
618 struct brw_cs_prog_data *prog_data = &pipeline->cs_prog_data;
619
620 cmd_buffer_flush_compute_state(cmd_buffer);
621
622 anv_batch_emit(&cmd_buffer->batch, GENX(GPGPU_WALKER),
623 .SIMDSize = prog_data->simd_size / 16,
624 .ThreadDepthCounterMaximum = 0,
625 .ThreadHeightCounterMaximum = 0,
626 .ThreadWidthCounterMaximum = pipeline->cs_thread_width_max - 1,
627 .ThreadGroupIDXDimension = x,
628 .ThreadGroupIDYDimension = y,
629 .ThreadGroupIDZDimension = z,
630 .RightExecutionMask = pipeline->cs_right_mask,
631 .BottomExecutionMask = 0xffffffff);
632
633 anv_batch_emit(&cmd_buffer->batch, GENX(MEDIA_STATE_FLUSH));
634 }
635
636 #define GPGPU_DISPATCHDIMX 0x2500
637 #define GPGPU_DISPATCHDIMY 0x2504
638 #define GPGPU_DISPATCHDIMZ 0x2508
639
640 void genX(CmdDispatchIndirect)(
641 VkCommandBuffer commandBuffer,
642 VkBuffer _buffer,
643 VkDeviceSize offset)
644 {
645 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
646 ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
647 struct anv_pipeline *pipeline = cmd_buffer->state.compute_pipeline;
648 struct brw_cs_prog_data *prog_data = &pipeline->cs_prog_data;
649 struct anv_bo *bo = buffer->bo;
650 uint32_t bo_offset = buffer->offset + offset;
651
652 cmd_buffer_flush_compute_state(cmd_buffer);
653
654 emit_lrm(&cmd_buffer->batch, GPGPU_DISPATCHDIMX, bo, bo_offset);
655 emit_lrm(&cmd_buffer->batch, GPGPU_DISPATCHDIMY, bo, bo_offset + 4);
656 emit_lrm(&cmd_buffer->batch, GPGPU_DISPATCHDIMZ, bo, bo_offset + 8);
657
658 anv_batch_emit(&cmd_buffer->batch, GENX(GPGPU_WALKER),
659 .IndirectParameterEnable = true,
660 .SIMDSize = prog_data->simd_size / 16,
661 .ThreadDepthCounterMaximum = 0,
662 .ThreadHeightCounterMaximum = 0,
663 .ThreadWidthCounterMaximum = pipeline->cs_thread_width_max - 1,
664 .RightExecutionMask = pipeline->cs_right_mask,
665 .BottomExecutionMask = 0xffffffff);
666
667 anv_batch_emit(&cmd_buffer->batch, GENX(MEDIA_STATE_FLUSH));
668 }
669
670 static void
671 cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
672 {
673 const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
674 const struct anv_image_view *iview =
675 anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
676 const struct anv_image *image = iview ? iview->image : NULL;
677 const bool has_depth = iview && iview->format->depth_format;
678 const bool has_stencil = iview && iview->format->has_stencil;
679
680 /* FIXME: Implement the PMA stall W/A */
681 /* FIXME: Width and Height are wrong */
682
683 /* Emit 3DSTATE_DEPTH_BUFFER */
684 if (has_depth) {
685 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DEPTH_BUFFER),
686 .SurfaceType = SURFTYPE_2D,
687 .DepthWriteEnable = iview->format->depth_format,
688 .StencilWriteEnable = has_stencil,
689 .HierarchicalDepthBufferEnable = false,
690 .SurfaceFormat = iview->format->depth_format,
691 .SurfacePitch = image->depth_surface.isl.row_pitch - 1,
692 .SurfaceBaseAddress = {
693 .bo = image->bo,
694 .offset = image->depth_surface.offset,
695 },
696 .Height = fb->height - 1,
697 .Width = fb->width - 1,
698 .LOD = 0,
699 .Depth = 1 - 1,
700 .MinimumArrayElement = 0,
701 .DepthBufferObjectControlState = GENX(MOCS),
702 .RenderTargetViewExtent = 1 - 1,
703 .SurfaceQPitch = isl_surf_get_array_pitch_el_rows(&image->depth_surface.isl) >> 2);
704 } else {
705 /* Even when no depth buffer is present, the hardware requires that
706 * 3DSTATE_DEPTH_BUFFER be programmed correctly. The Broadwell PRM says:
707 *
708 * If a null depth buffer is bound, the driver must instead bind depth as:
709 * 3DSTATE_DEPTH.SurfaceType = SURFTYPE_2D
710 * 3DSTATE_DEPTH.Width = 1
711 * 3DSTATE_DEPTH.Height = 1
712 * 3DSTATE_DEPTH.SuraceFormat = D16_UNORM
713 * 3DSTATE_DEPTH.SurfaceBaseAddress = 0
714 * 3DSTATE_DEPTH.HierarchicalDepthBufferEnable = 0
715 * 3DSTATE_WM_DEPTH_STENCIL.DepthTestEnable = 0
716 * 3DSTATE_WM_DEPTH_STENCIL.DepthBufferWriteEnable = 0
717 *
718 * The PRM is wrong, though. The width and height must be programmed to
719 * actual framebuffer's width and height, even when neither depth buffer
720 * nor stencil buffer is present.
721 */
722 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DEPTH_BUFFER),
723 .SurfaceType = SURFTYPE_2D,
724 .SurfaceFormat = D16_UNORM,
725 .Width = fb->width - 1,
726 .Height = fb->height - 1,
727 .StencilWriteEnable = has_stencil);
728 }
729
730 /* Emit 3DSTATE_STENCIL_BUFFER */
731 if (has_stencil) {
732 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_STENCIL_BUFFER),
733 .StencilBufferEnable = true,
734 .StencilBufferObjectControlState = GENX(MOCS),
735
736 /* Stencil buffers have strange pitch. The PRM says:
737 *
738 * The pitch must be set to 2x the value computed based on width,
739 * as the stencil buffer is stored with two rows interleaved.
740 */
741 .SurfacePitch = 2 * image->stencil_surface.isl.row_pitch - 1,
742
743 .SurfaceBaseAddress = {
744 .bo = image->bo,
745 .offset = image->offset + image->stencil_surface.offset,
746 },
747 .SurfaceQPitch = isl_surf_get_array_pitch_el_rows(&image->stencil_surface.isl) >> 2);
748 } else {
749 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_STENCIL_BUFFER));
750 }
751
752 /* Disable hierarchial depth buffers. */
753 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_HIER_DEPTH_BUFFER));
754
755 /* Clear the clear params. */
756 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_CLEAR_PARAMS));
757 }
758
759 void
760 genX(cmd_buffer_begin_subpass)(struct anv_cmd_buffer *cmd_buffer,
761 struct anv_subpass *subpass)
762 {
763 cmd_buffer->state.subpass = subpass;
764
765 cmd_buffer->state.descriptors_dirty |= VK_SHADER_STAGE_FRAGMENT_BIT;
766
767 cmd_buffer_emit_depth_stencil(cmd_buffer);
768 }
769
770 void genX(CmdBeginRenderPass)(
771 VkCommandBuffer commandBuffer,
772 const VkRenderPassBeginInfo* pRenderPassBegin,
773 VkSubpassContents contents)
774 {
775 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
776 ANV_FROM_HANDLE(anv_render_pass, pass, pRenderPassBegin->renderPass);
777 ANV_FROM_HANDLE(anv_framebuffer, framebuffer, pRenderPassBegin->framebuffer);
778
779 cmd_buffer->state.framebuffer = framebuffer;
780 cmd_buffer->state.pass = pass;
781
782 const VkRect2D *render_area = &pRenderPassBegin->renderArea;
783
784 anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DRAWING_RECTANGLE),
785 .ClippedDrawingRectangleYMin = render_area->offset.y,
786 .ClippedDrawingRectangleXMin = render_area->offset.x,
787 .ClippedDrawingRectangleYMax =
788 render_area->offset.y + render_area->extent.height - 1,
789 .ClippedDrawingRectangleXMax =
790 render_area->offset.x + render_area->extent.width - 1,
791 .DrawingRectangleOriginY = 0,
792 .DrawingRectangleOriginX = 0);
793
794 anv_cmd_buffer_clear_attachments(cmd_buffer, pass,
795 pRenderPassBegin->pClearValues);
796
797 genX(cmd_buffer_begin_subpass)(cmd_buffer, pass->subpasses);
798 }
799
800 void genX(CmdNextSubpass)(
801 VkCommandBuffer commandBuffer,
802 VkSubpassContents contents)
803 {
804 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
805
806 assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY);
807
808 genX(cmd_buffer_begin_subpass)(cmd_buffer, cmd_buffer->state.subpass + 1);
809 }
810
811 void genX(CmdEndRenderPass)(
812 VkCommandBuffer commandBuffer)
813 {
814 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
815
816 /* Emit a flushing pipe control at the end of a pass. This is kind of a
817 * hack but it ensures that render targets always actually get written.
818 * Eventually, we should do flushing based on image format transitions
819 * or something of that nature.
820 */
821 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL),
822 .PostSyncOperation = NoWrite,
823 .RenderTargetCacheFlushEnable = true,
824 .InstructionCacheInvalidateEnable = true,
825 .DepthCacheFlushEnable = true,
826 .VFCacheInvalidationEnable = true,
827 .TextureCacheInvalidationEnable = true,
828 .CommandStreamerStallEnable = true);
829 }
830
831 static void
832 emit_ps_depth_count(struct anv_batch *batch,
833 struct anv_bo *bo, uint32_t offset)
834 {
835 anv_batch_emit(batch, GENX(PIPE_CONTROL),
836 .DestinationAddressType = DAT_PPGTT,
837 .PostSyncOperation = WritePSDepthCount,
838 .Address = { bo, offset }); /* FIXME: This is only lower 32 bits */
839 }
840
841 void genX(CmdBeginQuery)(
842 VkCommandBuffer commandBuffer,
843 VkQueryPool queryPool,
844 uint32_t entry,
845 VkQueryControlFlags flags)
846 {
847 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
848 ANV_FROM_HANDLE(anv_query_pool, pool, queryPool);
849
850 switch (pool->type) {
851 case VK_QUERY_TYPE_OCCLUSION:
852 emit_ps_depth_count(&cmd_buffer->batch, &pool->bo,
853 entry * sizeof(struct anv_query_pool_slot));
854 break;
855
856 case VK_QUERY_TYPE_PIPELINE_STATISTICS:
857 default:
858 unreachable("");
859 }
860 }
861
862 void genX(CmdEndQuery)(
863 VkCommandBuffer commandBuffer,
864 VkQueryPool queryPool,
865 uint32_t entry)
866 {
867 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
868 ANV_FROM_HANDLE(anv_query_pool, pool, queryPool);
869
870 switch (pool->type) {
871 case VK_QUERY_TYPE_OCCLUSION:
872 emit_ps_depth_count(&cmd_buffer->batch, &pool->bo,
873 entry * sizeof(struct anv_query_pool_slot) + 8);
874 break;
875
876 case VK_QUERY_TYPE_PIPELINE_STATISTICS:
877 default:
878 unreachable("");
879 }
880 }
881
882 #define TIMESTAMP 0x2358
883
884 void genX(CmdWriteTimestamp)(
885 VkCommandBuffer commandBuffer,
886 VkPipelineStageFlagBits pipelineStage,
887 VkQueryPool queryPool,
888 uint32_t entry)
889 {
890 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
891 ANV_FROM_HANDLE(anv_query_pool, pool, queryPool);
892
893 assert(pool->type == VK_QUERY_TYPE_TIMESTAMP);
894
895 switch (pipelineStage) {
896 case VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT:
897 anv_batch_emit(&cmd_buffer->batch, GENX(MI_STORE_REGISTER_MEM),
898 .RegisterAddress = TIMESTAMP,
899 .MemoryAddress = { &pool->bo, entry * 8 });
900 anv_batch_emit(&cmd_buffer->batch, GENX(MI_STORE_REGISTER_MEM),
901 .RegisterAddress = TIMESTAMP + 4,
902 .MemoryAddress = { &pool->bo, entry * 8 + 4 });
903 break;
904
905 default:
906 /* Everything else is bottom-of-pipe */
907 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL),
908 .DestinationAddressType = DAT_PPGTT,
909 .PostSyncOperation = WriteTimestamp,
910 .Address = /* FIXME: This is only lower 32 bits */
911 { &pool->bo, entry * 8 });
912 break;
913 }
914 }
915
916 #define alu_opcode(v) __gen_field((v), 20, 31)
917 #define alu_operand1(v) __gen_field((v), 10, 19)
918 #define alu_operand2(v) __gen_field((v), 0, 9)
919 #define alu(opcode, operand1, operand2) \
920 alu_opcode(opcode) | alu_operand1(operand1) | alu_operand2(operand2)
921
922 #define OPCODE_NOOP 0x000
923 #define OPCODE_LOAD 0x080
924 #define OPCODE_LOADINV 0x480
925 #define OPCODE_LOAD0 0x081
926 #define OPCODE_LOAD1 0x481
927 #define OPCODE_ADD 0x100
928 #define OPCODE_SUB 0x101
929 #define OPCODE_AND 0x102
930 #define OPCODE_OR 0x103
931 #define OPCODE_XOR 0x104
932 #define OPCODE_STORE 0x180
933 #define OPCODE_STOREINV 0x580
934
935 #define OPERAND_R0 0x00
936 #define OPERAND_R1 0x01
937 #define OPERAND_R2 0x02
938 #define OPERAND_R3 0x03
939 #define OPERAND_R4 0x04
940 #define OPERAND_SRCA 0x20
941 #define OPERAND_SRCB 0x21
942 #define OPERAND_ACCU 0x31
943 #define OPERAND_ZF 0x32
944 #define OPERAND_CF 0x33
945
946 #define CS_GPR(n) (0x2600 + (n) * 8)
947
948 static void
949 emit_load_alu_reg_u64(struct anv_batch *batch, uint32_t reg,
950 struct anv_bo *bo, uint32_t offset)
951 {
952 anv_batch_emit(batch, GENX(MI_LOAD_REGISTER_MEM),
953 .RegisterAddress = reg,
954 .MemoryAddress = { bo, offset });
955 anv_batch_emit(batch, GENX(MI_LOAD_REGISTER_MEM),
956 .RegisterAddress = reg + 4,
957 .MemoryAddress = { bo, offset + 4 });
958 }
959
960 void genX(CmdCopyQueryPoolResults)(
961 VkCommandBuffer commandBuffer,
962 VkQueryPool queryPool,
963 uint32_t startQuery,
964 uint32_t queryCount,
965 VkBuffer destBuffer,
966 VkDeviceSize destOffset,
967 VkDeviceSize destStride,
968 VkQueryResultFlags flags)
969 {
970 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
971 ANV_FROM_HANDLE(anv_query_pool, pool, queryPool);
972 ANV_FROM_HANDLE(anv_buffer, buffer, destBuffer);
973 uint32_t slot_offset, dst_offset;
974
975 if (flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) {
976 /* Where is the availabilty info supposed to go? */
977 anv_finishme("VK_QUERY_RESULT_WITH_AVAILABILITY_BIT");
978 return;
979 }
980
981 assert(pool->type == VK_QUERY_TYPE_OCCLUSION);
982
983 /* FIXME: If we're not waiting, should we just do this on the CPU? */
984 if (flags & VK_QUERY_RESULT_WAIT_BIT)
985 anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL),
986 .CommandStreamerStallEnable = true,
987 .StallAtPixelScoreboard = true);
988
989 dst_offset = buffer->offset + destOffset;
990 for (uint32_t i = 0; i < queryCount; i++) {
991
992 slot_offset = (startQuery + i) * sizeof(struct anv_query_pool_slot);
993
994 emit_load_alu_reg_u64(&cmd_buffer->batch, CS_GPR(0), &pool->bo, slot_offset);
995 emit_load_alu_reg_u64(&cmd_buffer->batch, CS_GPR(1), &pool->bo, slot_offset + 8);
996
997 /* FIXME: We need to clamp the result for 32 bit. */
998
999 uint32_t *dw = anv_batch_emitn(&cmd_buffer->batch, 5, GENX(MI_MATH));
1000 dw[1] = alu(OPCODE_LOAD, OPERAND_SRCA, OPERAND_R1);
1001 dw[2] = alu(OPCODE_LOAD, OPERAND_SRCB, OPERAND_R0);
1002 dw[3] = alu(OPCODE_SUB, 0, 0);
1003 dw[4] = alu(OPCODE_STORE, OPERAND_R2, OPERAND_ACCU);
1004
1005 anv_batch_emit(&cmd_buffer->batch, GENX(MI_STORE_REGISTER_MEM),
1006 .RegisterAddress = CS_GPR(2),
1007 /* FIXME: This is only lower 32 bits */
1008 .MemoryAddress = { buffer->bo, dst_offset });
1009
1010 if (flags & VK_QUERY_RESULT_64_BIT)
1011 anv_batch_emit(&cmd_buffer->batch, GENX(MI_STORE_REGISTER_MEM),
1012 .RegisterAddress = CS_GPR(2) + 4,
1013 /* FIXME: This is only lower 32 bits */
1014 .MemoryAddress = { buffer->bo, dst_offset + 4 });
1015
1016 dst_offset += destStride;
1017 }
1018 }