2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 #include "anv_private.h"
29 #include "genxml/gen_macros.h"
30 #include "genxml/genX_pack.h"
33 genX(cmd_buffer_emit_state_base_address
)(struct anv_cmd_buffer
*cmd_buffer
)
35 struct anv_device
*device
= cmd_buffer
->device
;
36 struct anv_bo
*scratch_bo
= NULL
;
38 cmd_buffer
->state
.scratch_size
=
39 anv_block_pool_size(&device
->scratch_block_pool
);
40 if (cmd_buffer
->state
.scratch_size
> 0)
41 scratch_bo
= &device
->scratch_block_pool
.bo
;
43 /* XXX: Do we need this on more than just BDW? */
45 /* Emit a render target cache flush.
47 * This isn't documented anywhere in the PRM. However, it seems to be
48 * necessary prior to changing the surface state base adress. Without
49 * this, we get GPU hangs when using multi-level command buffers which
50 * clear depth, reset state base address, and then go render stuff.
52 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
),
53 .RenderTargetCacheFlushEnable
= true);
56 anv_batch_emit(&cmd_buffer
->batch
, GENX(STATE_BASE_ADDRESS
),
57 .GeneralStateBaseAddress
= { scratch_bo
, 0 },
58 .GeneralStateMemoryObjectControlState
= GENX(MOCS
),
59 .GeneralStateBaseAddressModifyEnable
= true,
61 .SurfaceStateBaseAddress
= anv_cmd_buffer_surface_base_address(cmd_buffer
),
62 .SurfaceStateMemoryObjectControlState
= GENX(MOCS
),
63 .SurfaceStateBaseAddressModifyEnable
= true,
65 .DynamicStateBaseAddress
= { &device
->dynamic_state_block_pool
.bo
, 0 },
66 .DynamicStateMemoryObjectControlState
= GENX(MOCS
),
67 .DynamicStateBaseAddressModifyEnable
= true,
69 .IndirectObjectBaseAddress
= { NULL
, 0 },
70 .IndirectObjectMemoryObjectControlState
= GENX(MOCS
),
71 .IndirectObjectBaseAddressModifyEnable
= true,
73 .InstructionBaseAddress
= { &device
->instruction_block_pool
.bo
, 0 },
74 .InstructionMemoryObjectControlState
= GENX(MOCS
),
75 .InstructionBaseAddressModifyEnable
= true,
78 /* Broadwell requires that we specify a buffer size for a bunch of
79 * these fields. However, since we will be growing the BO's live, we
80 * just set them all to the maximum.
82 .GeneralStateBufferSize
= 0xfffff,
83 .GeneralStateBufferSizeModifyEnable
= true,
84 .DynamicStateBufferSize
= 0xfffff,
85 .DynamicStateBufferSizeModifyEnable
= true,
86 .IndirectObjectBufferSize
= 0xfffff,
87 .IndirectObjectBufferSizeModifyEnable
= true,
88 .InstructionBufferSize
= 0xfffff,
89 .InstructionBuffersizeModifyEnable
= true,
93 /* After re-setting the surface state base address, we have to do some
94 * cache flusing so that the sampler engine will pick up the new
95 * SURFACE_STATE objects and binding tables. From the Broadwell PRM,
96 * Shared Function > 3D Sampler > State > State Caching (page 96):
98 * Coherency with system memory in the state cache, like the texture
99 * cache is handled partially by software. It is expected that the
100 * command stream or shader will issue Cache Flush operation or
101 * Cache_Flush sampler message to ensure that the L1 cache remains
102 * coherent with system memory.
106 * Whenever the value of the Dynamic_State_Base_Addr,
107 * Surface_State_Base_Addr are altered, the L1 state cache must be
108 * invalidated to ensure the new surface or sampler state is fetched
109 * from system memory.
111 * The PIPE_CONTROL command has a "State Cache Invalidation Enable" bit
112 * which, according the PIPE_CONTROL instruction documentation in the
115 * Setting this bit is independent of any other bit in this packet.
116 * This bit controls the invalidation of the L1 and L2 state caches
117 * at the top of the pipe i.e. at the parsing time.
119 * Unfortunately, experimentation seems to indicate that state cache
120 * invalidation through a PIPE_CONTROL does nothing whatsoever in
121 * regards to surface state and binding tables. In stead, it seems that
122 * invalidating the texture cache is what is actually needed.
124 * XXX: As far as we have been able to determine through
125 * experimentation, shows that flush the texture cache appears to be
126 * sufficient. The theory here is that all of the sampling/rendering
127 * units cache the binding table in the texture cache. However, we have
128 * yet to be able to actually confirm this.
130 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPE_CONTROL
),
131 .TextureCacheInvalidationEnable
= true);
134 void genX(CmdPipelineBarrier
)(
135 VkCommandBuffer commandBuffer
,
136 VkPipelineStageFlags srcStageMask
,
137 VkPipelineStageFlags destStageMask
,
139 uint32_t memoryBarrierCount
,
140 const VkMemoryBarrier
* pMemoryBarriers
,
141 uint32_t bufferMemoryBarrierCount
,
142 const VkBufferMemoryBarrier
* pBufferMemoryBarriers
,
143 uint32_t imageMemoryBarrierCount
,
144 const VkImageMemoryBarrier
* pImageMemoryBarriers
)
146 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
149 /* XXX: Right now, we're really dumb and just flush whatever categories
150 * the app asks for. One of these days we may make this a bit better
151 * but right now that's all the hardware allows for in most areas.
153 VkAccessFlags src_flags
= 0;
154 VkAccessFlags dst_flags
= 0;
156 for (uint32_t i
= 0; i
< memoryBarrierCount
; i
++) {
157 src_flags
|= pMemoryBarriers
[i
].srcAccessMask
;
158 dst_flags
|= pMemoryBarriers
[i
].dstAccessMask
;
161 for (uint32_t i
= 0; i
< bufferMemoryBarrierCount
; i
++) {
162 src_flags
|= pBufferMemoryBarriers
[i
].srcAccessMask
;
163 dst_flags
|= pBufferMemoryBarriers
[i
].dstAccessMask
;
166 for (uint32_t i
= 0; i
< imageMemoryBarrierCount
; i
++) {
167 src_flags
|= pImageMemoryBarriers
[i
].srcAccessMask
;
168 dst_flags
|= pImageMemoryBarriers
[i
].dstAccessMask
;
171 /* Mask out the Source access flags we care about */
172 const uint32_t src_mask
=
173 VK_ACCESS_SHADER_WRITE_BIT
|
174 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
|
175 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
|
176 VK_ACCESS_TRANSFER_WRITE_BIT
;
178 src_flags
= src_flags
& src_mask
;
180 /* Mask out the destination access flags we care about */
181 const uint32_t dst_mask
=
182 VK_ACCESS_INDIRECT_COMMAND_READ_BIT
|
183 VK_ACCESS_INDEX_READ_BIT
|
184 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
|
185 VK_ACCESS_UNIFORM_READ_BIT
|
186 VK_ACCESS_SHADER_READ_BIT
|
187 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
|
188 VK_ACCESS_TRANSFER_READ_BIT
;
190 dst_flags
= dst_flags
& dst_mask
;
192 /* The src flags represent how things were used previously. This is
193 * what we use for doing flushes.
195 struct GENX(PIPE_CONTROL
) flush_cmd
= {
196 GENX(PIPE_CONTROL_header
),
197 .PostSyncOperation
= NoWrite
,
200 for_each_bit(b
, src_flags
) {
201 switch ((VkAccessFlagBits
)(1 << b
)) {
202 case VK_ACCESS_SHADER_WRITE_BIT
:
203 flush_cmd
.DCFlushEnable
= true;
205 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
:
206 flush_cmd
.RenderTargetCacheFlushEnable
= true;
208 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
:
209 flush_cmd
.DepthCacheFlushEnable
= true;
211 case VK_ACCESS_TRANSFER_WRITE_BIT
:
212 flush_cmd
.RenderTargetCacheFlushEnable
= true;
213 flush_cmd
.DepthCacheFlushEnable
= true;
216 unreachable("should've masked this out by now");
220 /* If we end up doing two PIPE_CONTROLs, the first, flusing one also has to
221 * stall and wait for the flushing to finish, so we don't re-dirty the
222 * caches with in-flight rendering after the second PIPE_CONTROL
227 flush_cmd
.CommandStreamerStallEnable
= true;
229 if (src_flags
&& dst_flags
) {
230 dw
= anv_batch_emit_dwords(&cmd_buffer
->batch
, GENX(PIPE_CONTROL_length
));
231 GENX(PIPE_CONTROL_pack
)(&cmd_buffer
->batch
, dw
, &flush_cmd
);
234 /* The dst flags represent how things will be used in the future. This
235 * is what we use for doing cache invalidations.
237 struct GENX(PIPE_CONTROL
) invalidate_cmd
= {
238 GENX(PIPE_CONTROL_header
),
239 .PostSyncOperation
= NoWrite
,
242 for_each_bit(b
, dst_flags
) {
243 switch ((VkAccessFlagBits
)(1 << b
)) {
244 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT
:
245 case VK_ACCESS_INDEX_READ_BIT
:
246 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
:
247 invalidate_cmd
.VFCacheInvalidationEnable
= true;
249 case VK_ACCESS_UNIFORM_READ_BIT
:
250 invalidate_cmd
.ConstantCacheInvalidationEnable
= true;
252 case VK_ACCESS_SHADER_READ_BIT
:
253 invalidate_cmd
.TextureCacheInvalidationEnable
= true;
255 case VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
:
256 invalidate_cmd
.TextureCacheInvalidationEnable
= true;
258 case VK_ACCESS_TRANSFER_READ_BIT
:
259 invalidate_cmd
.TextureCacheInvalidationEnable
= true;
262 unreachable("should've masked this out by now");
267 dw
= anv_batch_emit_dwords(&cmd_buffer
->batch
, GENX(PIPE_CONTROL_length
));
268 GENX(PIPE_CONTROL_pack
)(&cmd_buffer
->batch
, dw
, &invalidate_cmd
);
273 emit_base_vertex_instance_bo(struct anv_cmd_buffer
*cmd_buffer
,
274 struct anv_bo
*bo
, uint32_t offset
)
276 uint32_t *p
= anv_batch_emitn(&cmd_buffer
->batch
, 5,
277 GENX(3DSTATE_VERTEX_BUFFERS
));
279 GENX(VERTEX_BUFFER_STATE_pack
)(&cmd_buffer
->batch
, p
+ 1,
280 &(struct GENX(VERTEX_BUFFER_STATE
)) {
281 .VertexBufferIndex
= 32, /* Reserved for this */
282 .AddressModifyEnable
= true,
285 .MemoryObjectControlState
= GENX(MOCS
),
286 .BufferStartingAddress
= { bo
, offset
},
289 .VertexBufferMemoryObjectControlState
= GENX(MOCS
),
290 .BufferStartingAddress
= { bo
, offset
},
291 .EndAddress
= { bo
, offset
+ 8 },
297 emit_base_vertex_instance(struct anv_cmd_buffer
*cmd_buffer
,
298 uint32_t base_vertex
, uint32_t base_instance
)
300 struct anv_state id_state
=
301 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, 8, 4);
303 ((uint32_t *)id_state
.map
)[0] = base_vertex
;
304 ((uint32_t *)id_state
.map
)[1] = base_instance
;
306 if (!cmd_buffer
->device
->info
.has_llc
)
307 anv_state_clflush(id_state
);
309 emit_base_vertex_instance_bo(cmd_buffer
,
310 &cmd_buffer
->device
->dynamic_state_block_pool
.bo
, id_state
.offset
);
314 VkCommandBuffer commandBuffer
,
315 uint32_t vertexCount
,
316 uint32_t instanceCount
,
317 uint32_t firstVertex
,
318 uint32_t firstInstance
)
320 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
321 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
323 genX(cmd_buffer_flush_state
)(cmd_buffer
);
325 if (cmd_buffer
->state
.pipeline
->vs_prog_data
.uses_basevertex
||
326 cmd_buffer
->state
.pipeline
->vs_prog_data
.uses_baseinstance
)
327 emit_base_vertex_instance(cmd_buffer
, firstVertex
, firstInstance
);
329 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DPRIMITIVE
),
330 .VertexAccessType
= SEQUENTIAL
,
331 .PrimitiveTopologyType
= pipeline
->topology
,
332 .VertexCountPerInstance
= vertexCount
,
333 .StartVertexLocation
= firstVertex
,
334 .InstanceCount
= instanceCount
,
335 .StartInstanceLocation
= firstInstance
,
336 .BaseVertexLocation
= 0);
339 void genX(CmdDrawIndexed
)(
340 VkCommandBuffer commandBuffer
,
342 uint32_t instanceCount
,
344 int32_t vertexOffset
,
345 uint32_t firstInstance
)
347 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
348 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
350 genX(cmd_buffer_flush_state
)(cmd_buffer
);
352 if (cmd_buffer
->state
.pipeline
->vs_prog_data
.uses_basevertex
||
353 cmd_buffer
->state
.pipeline
->vs_prog_data
.uses_baseinstance
)
354 emit_base_vertex_instance(cmd_buffer
, vertexOffset
, firstInstance
);
356 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DPRIMITIVE
),
357 .VertexAccessType
= RANDOM
,
358 .PrimitiveTopologyType
= pipeline
->topology
,
359 .VertexCountPerInstance
= indexCount
,
360 .StartVertexLocation
= firstIndex
,
361 .InstanceCount
= instanceCount
,
362 .StartInstanceLocation
= firstInstance
,
363 .BaseVertexLocation
= vertexOffset
);
366 /* Auto-Draw / Indirect Registers */
367 #define GEN7_3DPRIM_END_OFFSET 0x2420
368 #define GEN7_3DPRIM_START_VERTEX 0x2430
369 #define GEN7_3DPRIM_VERTEX_COUNT 0x2434
370 #define GEN7_3DPRIM_INSTANCE_COUNT 0x2438
371 #define GEN7_3DPRIM_START_INSTANCE 0x243C
372 #define GEN7_3DPRIM_BASE_VERTEX 0x2440
375 emit_lrm(struct anv_batch
*batch
,
376 uint32_t reg
, struct anv_bo
*bo
, uint32_t offset
)
378 anv_batch_emit(batch
, GENX(MI_LOAD_REGISTER_MEM
),
379 .RegisterAddress
= reg
,
380 .MemoryAddress
= { bo
, offset
});
384 emit_lri(struct anv_batch
*batch
, uint32_t reg
, uint32_t imm
)
386 anv_batch_emit(batch
, GENX(MI_LOAD_REGISTER_IMM
),
387 .RegisterOffset
= reg
,
391 void genX(CmdDrawIndirect
)(
392 VkCommandBuffer commandBuffer
,
398 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
399 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
400 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
401 struct anv_bo
*bo
= buffer
->bo
;
402 uint32_t bo_offset
= buffer
->offset
+ offset
;
404 genX(cmd_buffer_flush_state
)(cmd_buffer
);
406 if (cmd_buffer
->state
.pipeline
->vs_prog_data
.uses_basevertex
||
407 cmd_buffer
->state
.pipeline
->vs_prog_data
.uses_baseinstance
)
408 emit_base_vertex_instance_bo(cmd_buffer
, bo
, bo_offset
+ 8);
410 emit_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
411 emit_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
412 emit_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
413 emit_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 12);
414 emit_lri(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, 0);
416 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DPRIMITIVE
),
417 .IndirectParameterEnable
= true,
418 .VertexAccessType
= SEQUENTIAL
,
419 .PrimitiveTopologyType
= pipeline
->topology
);
422 void genX(CmdDrawIndexedIndirect
)(
423 VkCommandBuffer commandBuffer
,
429 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
430 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
431 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.pipeline
;
432 struct anv_bo
*bo
= buffer
->bo
;
433 uint32_t bo_offset
= buffer
->offset
+ offset
;
435 genX(cmd_buffer_flush_state
)(cmd_buffer
);
437 /* TODO: We need to stomp base vertex to 0 somehow */
438 if (cmd_buffer
->state
.pipeline
->vs_prog_data
.uses_basevertex
||
439 cmd_buffer
->state
.pipeline
->vs_prog_data
.uses_baseinstance
)
440 emit_base_vertex_instance_bo(cmd_buffer
, bo
, bo_offset
+ 12);
442 emit_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
443 emit_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
444 emit_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
445 emit_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, bo
, bo_offset
+ 12);
446 emit_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 16);
448 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DPRIMITIVE
),
449 .IndirectParameterEnable
= true,
450 .VertexAccessType
= RANDOM
,
451 .PrimitiveTopologyType
= pipeline
->topology
);
455 void genX(CmdDispatch
)(
456 VkCommandBuffer commandBuffer
,
461 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
462 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.compute_pipeline
;
463 struct brw_cs_prog_data
*prog_data
= &pipeline
->cs_prog_data
;
465 if (prog_data
->uses_num_work_groups
) {
466 struct anv_state state
=
467 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, 12, 4);
468 uint32_t *sizes
= state
.map
;
472 if (!cmd_buffer
->device
->info
.has_llc
)
473 anv_state_clflush(state
);
474 cmd_buffer
->state
.num_workgroups_offset
= state
.offset
;
475 cmd_buffer
->state
.num_workgroups_bo
=
476 &cmd_buffer
->device
->dynamic_state_block_pool
.bo
;
479 genX(cmd_buffer_flush_compute_state
)(cmd_buffer
);
481 anv_batch_emit(&cmd_buffer
->batch
, GENX(GPGPU_WALKER
),
482 .SIMDSize
= prog_data
->simd_size
/ 16,
483 .ThreadDepthCounterMaximum
= 0,
484 .ThreadHeightCounterMaximum
= 0,
485 .ThreadWidthCounterMaximum
= pipeline
->cs_thread_width_max
- 1,
486 .ThreadGroupIDXDimension
= x
,
487 .ThreadGroupIDYDimension
= y
,
488 .ThreadGroupIDZDimension
= z
,
489 .RightExecutionMask
= pipeline
->cs_right_mask
,
490 .BottomExecutionMask
= 0xffffffff);
492 anv_batch_emit(&cmd_buffer
->batch
, GENX(MEDIA_STATE_FLUSH
));
495 #define GPGPU_DISPATCHDIMX 0x2500
496 #define GPGPU_DISPATCHDIMY 0x2504
497 #define GPGPU_DISPATCHDIMZ 0x2508
499 void genX(CmdDispatchIndirect
)(
500 VkCommandBuffer commandBuffer
,
504 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
505 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
506 struct anv_pipeline
*pipeline
= cmd_buffer
->state
.compute_pipeline
;
507 struct brw_cs_prog_data
*prog_data
= &pipeline
->cs_prog_data
;
508 struct anv_bo
*bo
= buffer
->bo
;
509 uint32_t bo_offset
= buffer
->offset
+ offset
;
510 struct anv_batch
*batch
= &cmd_buffer
->batch
;
512 if (prog_data
->uses_num_work_groups
) {
513 cmd_buffer
->state
.num_workgroups_offset
= bo_offset
;
514 cmd_buffer
->state
.num_workgroups_bo
= bo
;
517 genX(cmd_buffer_flush_compute_state
)(cmd_buffer
);
519 emit_lrm(batch
, GPGPU_DISPATCHDIMX
, bo
, bo_offset
);
520 emit_lrm(batch
, GPGPU_DISPATCHDIMY
, bo
, bo_offset
+ 4);
521 emit_lrm(batch
, GPGPU_DISPATCHDIMZ
, bo
, bo_offset
+ 8);
523 anv_batch_emit(batch
, GENX(GPGPU_WALKER
),
524 .IndirectParameterEnable
= true,
525 .SIMDSize
= prog_data
->simd_size
/ 16,
526 .ThreadDepthCounterMaximum
= 0,
527 .ThreadHeightCounterMaximum
= 0,
528 .ThreadWidthCounterMaximum
= pipeline
->cs_thread_width_max
- 1,
529 .RightExecutionMask
= pipeline
->cs_right_mask
,
530 .BottomExecutionMask
= 0xffffffff);
532 anv_batch_emit(batch
, GENX(MEDIA_STATE_FLUSH
));
536 genX(flush_pipeline_select_3d
)(struct anv_cmd_buffer
*cmd_buffer
)
538 if (cmd_buffer
->state
.current_pipeline
!= _3D
) {
539 anv_batch_emit(&cmd_buffer
->batch
, GENX(PIPELINE_SELECT
),
543 .PipelineSelection
= _3D
);
544 cmd_buffer
->state
.current_pipeline
= _3D
;
549 cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer
*cmd_buffer
)
551 struct anv_device
*device
= cmd_buffer
->device
;
552 const struct anv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
553 const struct anv_image_view
*iview
=
554 anv_cmd_buffer_get_depth_stencil_view(cmd_buffer
);
555 const struct anv_image
*image
= iview
? iview
->image
: NULL
;
556 const struct anv_format
*anv_format
=
557 iview
? anv_format_for_vk_format(iview
->vk_format
) : NULL
;
558 const bool has_depth
= iview
&& anv_format
->has_depth
;
559 const bool has_stencil
= iview
&& anv_format
->has_stencil
;
561 /* FIXME: Implement the PMA stall W/A */
562 /* FIXME: Width and Height are wrong */
564 /* Emit 3DSTATE_DEPTH_BUFFER */
566 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_DEPTH_BUFFER
),
567 .SurfaceType
= SURFTYPE_2D
,
568 .DepthWriteEnable
= true,
569 .StencilWriteEnable
= has_stencil
,
570 .HierarchicalDepthBufferEnable
= false,
571 .SurfaceFormat
= isl_surf_get_depth_format(&device
->isl_dev
,
572 &image
->depth_surface
.isl
),
573 .SurfacePitch
= image
->depth_surface
.isl
.row_pitch
- 1,
574 .SurfaceBaseAddress
= {
576 .offset
= image
->offset
+ image
->depth_surface
.offset
,
578 .Height
= fb
->height
- 1,
579 .Width
= fb
->width
- 1,
582 .MinimumArrayElement
= 0,
583 .DepthBufferObjectControlState
= GENX(MOCS
),
585 .SurfaceQPitch
= isl_surf_get_array_pitch_el_rows(&image
->depth_surface
.isl
) >> 2,
587 .RenderTargetViewExtent
= 1 - 1);
589 /* Even when no depth buffer is present, the hardware requires that
590 * 3DSTATE_DEPTH_BUFFER be programmed correctly. The Broadwell PRM says:
592 * If a null depth buffer is bound, the driver must instead bind depth as:
593 * 3DSTATE_DEPTH.SurfaceType = SURFTYPE_2D
594 * 3DSTATE_DEPTH.Width = 1
595 * 3DSTATE_DEPTH.Height = 1
596 * 3DSTATE_DEPTH.SuraceFormat = D16_UNORM
597 * 3DSTATE_DEPTH.SurfaceBaseAddress = 0
598 * 3DSTATE_DEPTH.HierarchicalDepthBufferEnable = 0
599 * 3DSTATE_WM_DEPTH_STENCIL.DepthTestEnable = 0
600 * 3DSTATE_WM_DEPTH_STENCIL.DepthBufferWriteEnable = 0
602 * The PRM is wrong, though. The width and height must be programmed to
603 * actual framebuffer's width and height, even when neither depth buffer
604 * nor stencil buffer is present.
606 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_DEPTH_BUFFER
),
607 .SurfaceType
= SURFTYPE_2D
,
608 .SurfaceFormat
= D16_UNORM
,
609 .Width
= fb
->width
- 1,
610 .Height
= fb
->height
- 1,
611 .StencilWriteEnable
= has_stencil
);
614 /* Emit 3DSTATE_STENCIL_BUFFER */
616 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_STENCIL_BUFFER
),
617 #if GEN_GEN >= 8 || GEN_IS_HASWELL
618 .StencilBufferEnable
= true,
620 .StencilBufferObjectControlState
= GENX(MOCS
),
622 /* Stencil buffers have strange pitch. The PRM says:
624 * The pitch must be set to 2x the value computed based on width,
625 * as the stencil buffer is stored with two rows interleaved.
627 .SurfacePitch
= 2 * image
->stencil_surface
.isl
.row_pitch
- 1,
630 .SurfaceQPitch
= isl_surf_get_array_pitch_el_rows(&image
->stencil_surface
.isl
) >> 2,
632 .SurfaceBaseAddress
= {
634 .offset
= image
->offset
+ image
->stencil_surface
.offset
,
637 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_STENCIL_BUFFER
));
640 /* Disable hierarchial depth buffers. */
641 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_HIER_DEPTH_BUFFER
));
643 /* Clear the clear params. */
644 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_CLEAR_PARAMS
));
648 * @see anv_cmd_buffer_set_subpass()
651 genX(cmd_buffer_set_subpass
)(struct anv_cmd_buffer
*cmd_buffer
,
652 struct anv_subpass
*subpass
)
654 cmd_buffer
->state
.subpass
= subpass
;
656 cmd_buffer
->state
.descriptors_dirty
|= VK_SHADER_STAGE_FRAGMENT_BIT
;
658 cmd_buffer_emit_depth_stencil(cmd_buffer
);
661 void genX(CmdBeginRenderPass
)(
662 VkCommandBuffer commandBuffer
,
663 const VkRenderPassBeginInfo
* pRenderPassBegin
,
664 VkSubpassContents contents
)
666 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
667 ANV_FROM_HANDLE(anv_render_pass
, pass
, pRenderPassBegin
->renderPass
);
668 ANV_FROM_HANDLE(anv_framebuffer
, framebuffer
, pRenderPassBegin
->framebuffer
);
670 cmd_buffer
->state
.framebuffer
= framebuffer
;
671 cmd_buffer
->state
.pass
= pass
;
672 anv_cmd_state_setup_attachments(cmd_buffer
, pRenderPassBegin
);
674 genX(flush_pipeline_select_3d
)(cmd_buffer
);
676 const VkRect2D
*render_area
= &pRenderPassBegin
->renderArea
;
678 anv_batch_emit(&cmd_buffer
->batch
, GENX(3DSTATE_DRAWING_RECTANGLE
),
679 .ClippedDrawingRectangleYMin
= render_area
->offset
.y
,
680 .ClippedDrawingRectangleXMin
= render_area
->offset
.x
,
681 .ClippedDrawingRectangleYMax
=
682 render_area
->offset
.y
+ render_area
->extent
.height
- 1,
683 .ClippedDrawingRectangleXMax
=
684 render_area
->offset
.x
+ render_area
->extent
.width
- 1,
685 .DrawingRectangleOriginY
= 0,
686 .DrawingRectangleOriginX
= 0);
688 genX(cmd_buffer_set_subpass
)(cmd_buffer
, pass
->subpasses
);
689 anv_cmd_buffer_clear_subpass(cmd_buffer
);
692 void genX(CmdNextSubpass
)(
693 VkCommandBuffer commandBuffer
,
694 VkSubpassContents contents
)
696 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
698 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
700 anv_cmd_buffer_resolve_subpass(cmd_buffer
);
701 genX(cmd_buffer_set_subpass
)(cmd_buffer
, cmd_buffer
->state
.subpass
+ 1);
702 anv_cmd_buffer_clear_subpass(cmd_buffer
);
705 void genX(CmdEndRenderPass
)(
706 VkCommandBuffer commandBuffer
)
708 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
710 anv_cmd_buffer_resolve_subpass(cmd_buffer
);