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
30 #include "anv_private.h"
32 #include "vk_format_info.h"
35 /** \file anv_cmd_buffer.c
37 * This file contains all of the stuff for emitting commands into a command
38 * buffer. This includes implementations of most of the vkCmd*
39 * entrypoints. This file is concerned entirely with state emission and
40 * not with the command buffer data structure itself. As far as this file
41 * is concerned, most of anv_cmd_buffer is magic.
44 /* TODO: These are taken from GLES. We should check the Vulkan spec */
45 const struct anv_dynamic_state default_dynamic_state
= {
58 .blend_constants
= { 0.0f
, 0.0f
, 0.0f
, 0.0f
},
63 .stencil_compare_mask
= {
67 .stencil_write_mask
= {
71 .stencil_reference
= {
95 .primitive_topology
= 0,
96 .depth_test_enable
= 0,
97 .depth_write_enable
= 0,
98 .depth_compare_op
= 0,
99 .depth_bounds_test_enable
= 0,
100 .stencil_test_enable
= 0,
106 * Copy the dynamic state from src to dest based on the copy_mask.
108 * Avoid copying states that have not changed, except for VIEWPORT, SCISSOR and
109 * BLEND_CONSTANTS (always copy them if they are in the copy_mask).
111 * Returns a mask of the states which changed.
114 anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
115 const struct anv_dynamic_state
*src
,
116 anv_cmd_dirty_mask_t copy_mask
)
118 anv_cmd_dirty_mask_t changed
= 0;
120 if (copy_mask
& ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
) {
121 dest
->viewport
.count
= src
->viewport
.count
;
122 typed_memcpy(dest
->viewport
.viewports
, src
->viewport
.viewports
,
123 src
->viewport
.count
);
124 changed
|= ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
;
127 if (copy_mask
& ANV_CMD_DIRTY_DYNAMIC_SCISSOR
) {
128 dest
->scissor
.count
= src
->scissor
.count
;
129 typed_memcpy(dest
->scissor
.scissors
, src
->scissor
.scissors
,
131 changed
|= ANV_CMD_DIRTY_DYNAMIC_SCISSOR
;
134 if (copy_mask
& ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
) {
135 typed_memcpy(dest
->blend_constants
, src
->blend_constants
, 4);
136 changed
|= ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
;
139 #define ANV_CMP_COPY(field, flag) \
140 if (copy_mask & flag) { \
141 if (dest->field != src->field) { \
142 dest->field = src->field; \
147 ANV_CMP_COPY(line_width
, ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
);
149 ANV_CMP_COPY(depth_bias
.bias
, ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
);
150 ANV_CMP_COPY(depth_bias
.clamp
, ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
);
151 ANV_CMP_COPY(depth_bias
.slope
, ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
);
153 ANV_CMP_COPY(depth_bounds
.min
, ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
);
154 ANV_CMP_COPY(depth_bounds
.max
, ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
);
156 ANV_CMP_COPY(stencil_compare_mask
.front
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
);
157 ANV_CMP_COPY(stencil_compare_mask
.back
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
);
159 ANV_CMP_COPY(stencil_write_mask
.front
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
);
160 ANV_CMP_COPY(stencil_write_mask
.back
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
);
162 ANV_CMP_COPY(stencil_reference
.front
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
);
163 ANV_CMP_COPY(stencil_reference
.back
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
);
165 ANV_CMP_COPY(line_stipple
.factor
, ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE
);
166 ANV_CMP_COPY(line_stipple
.pattern
, ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE
);
168 ANV_CMP_COPY(cull_mode
, ANV_CMD_DIRTY_DYNAMIC_CULL_MODE
);
169 ANV_CMP_COPY(front_face
, ANV_CMD_DIRTY_DYNAMIC_FRONT_FACE
);
170 ANV_CMP_COPY(primitive_topology
, ANV_CMD_DIRTY_DYNAMIC_PRIMITIVE_TOPOLOGY
);
171 ANV_CMP_COPY(depth_test_enable
, ANV_CMD_DIRTY_DYNAMIC_DEPTH_TEST_ENABLE
);
172 ANV_CMP_COPY(depth_write_enable
, ANV_CMD_DIRTY_DYNAMIC_DEPTH_WRITE_ENABLE
);
173 ANV_CMP_COPY(depth_compare_op
, ANV_CMD_DIRTY_DYNAMIC_DEPTH_COMPARE_OP
);
174 ANV_CMP_COPY(depth_bounds_test_enable
, ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE
);
175 ANV_CMP_COPY(stencil_test_enable
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_TEST_ENABLE
);
177 if (copy_mask
& VK_DYNAMIC_STATE_STENCIL_OP_EXT
) {
178 ANV_CMP_COPY(stencil_op
.front
.fail_op
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP
);
179 ANV_CMP_COPY(stencil_op
.front
.pass_op
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP
);
180 ANV_CMP_COPY(stencil_op
.front
.depth_fail_op
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP
);
181 ANV_CMP_COPY(stencil_op
.front
.compare_op
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP
);
182 ANV_CMP_COPY(stencil_op
.back
.fail_op
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP
);
183 ANV_CMP_COPY(stencil_op
.back
.pass_op
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP
);
184 ANV_CMP_COPY(stencil_op
.back
.depth_fail_op
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP
);
185 ANV_CMP_COPY(stencil_op
.back
.compare_op
, ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP
);
188 ANV_CMP_COPY(dyn_vbo_stride
, ANV_CMD_DIRTY_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE
);
189 ANV_CMP_COPY(dyn_vbo_size
, ANV_CMD_DIRTY_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE
);
197 anv_cmd_state_init(struct anv_cmd_buffer
*cmd_buffer
)
199 struct anv_cmd_state
*state
= &cmd_buffer
->state
;
201 memset(state
, 0, sizeof(*state
));
203 state
->current_pipeline
= UINT32_MAX
;
204 state
->restart_index
= UINT32_MAX
;
205 state
->gfx
.dynamic
= default_dynamic_state
;
209 anv_cmd_pipeline_state_finish(struct anv_cmd_buffer
*cmd_buffer
,
210 struct anv_cmd_pipeline_state
*pipe_state
)
212 for (uint32_t i
= 0; i
< ARRAY_SIZE(pipe_state
->push_descriptors
); i
++) {
213 if (pipe_state
->push_descriptors
[i
]) {
214 anv_descriptor_set_layout_unref(cmd_buffer
->device
,
215 pipe_state
->push_descriptors
[i
]->set
.layout
);
216 vk_free(&cmd_buffer
->pool
->alloc
, pipe_state
->push_descriptors
[i
]);
222 anv_cmd_state_finish(struct anv_cmd_buffer
*cmd_buffer
)
224 struct anv_cmd_state
*state
= &cmd_buffer
->state
;
226 anv_cmd_pipeline_state_finish(cmd_buffer
, &state
->gfx
.base
);
227 anv_cmd_pipeline_state_finish(cmd_buffer
, &state
->compute
.base
);
229 vk_free(&cmd_buffer
->pool
->alloc
, state
->attachments
);
233 anv_cmd_state_reset(struct anv_cmd_buffer
*cmd_buffer
)
235 anv_cmd_state_finish(cmd_buffer
);
236 anv_cmd_state_init(cmd_buffer
);
239 static VkResult
anv_create_cmd_buffer(
240 struct anv_device
* device
,
241 struct anv_cmd_pool
* pool
,
242 VkCommandBufferLevel level
,
243 VkCommandBuffer
* pCommandBuffer
)
245 struct anv_cmd_buffer
*cmd_buffer
;
248 cmd_buffer
= vk_alloc(&pool
->alloc
, sizeof(*cmd_buffer
), 8,
249 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
250 if (cmd_buffer
== NULL
)
251 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
253 vk_object_base_init(&device
->vk
, &cmd_buffer
->base
,
254 VK_OBJECT_TYPE_COMMAND_BUFFER
);
256 cmd_buffer
->batch
.status
= VK_SUCCESS
;
258 cmd_buffer
->device
= device
;
259 cmd_buffer
->pool
= pool
;
260 cmd_buffer
->level
= level
;
262 result
= anv_cmd_buffer_init_batch_bo_chain(cmd_buffer
);
263 if (result
!= VK_SUCCESS
)
266 anv_state_stream_init(&cmd_buffer
->surface_state_stream
,
267 &device
->surface_state_pool
, 4096);
268 anv_state_stream_init(&cmd_buffer
->dynamic_state_stream
,
269 &device
->dynamic_state_pool
, 16384);
271 anv_cmd_state_init(cmd_buffer
);
274 list_addtail(&cmd_buffer
->pool_link
, &pool
->cmd_buffers
);
276 /* Init the pool_link so we can safefly call list_del when we destroy
279 list_inithead(&cmd_buffer
->pool_link
);
282 *pCommandBuffer
= anv_cmd_buffer_to_handle(cmd_buffer
);
287 vk_free(&cmd_buffer
->pool
->alloc
, cmd_buffer
);
292 VkResult
anv_AllocateCommandBuffers(
294 const VkCommandBufferAllocateInfo
* pAllocateInfo
,
295 VkCommandBuffer
* pCommandBuffers
)
297 ANV_FROM_HANDLE(anv_device
, device
, _device
);
298 ANV_FROM_HANDLE(anv_cmd_pool
, pool
, pAllocateInfo
->commandPool
);
300 VkResult result
= VK_SUCCESS
;
303 for (i
= 0; i
< pAllocateInfo
->commandBufferCount
; i
++) {
304 result
= anv_create_cmd_buffer(device
, pool
, pAllocateInfo
->level
,
305 &pCommandBuffers
[i
]);
306 if (result
!= VK_SUCCESS
)
310 if (result
!= VK_SUCCESS
) {
311 anv_FreeCommandBuffers(_device
, pAllocateInfo
->commandPool
,
313 for (i
= 0; i
< pAllocateInfo
->commandBufferCount
; i
++)
314 pCommandBuffers
[i
] = VK_NULL_HANDLE
;
321 anv_cmd_buffer_destroy(struct anv_cmd_buffer
*cmd_buffer
)
323 list_del(&cmd_buffer
->pool_link
);
325 anv_cmd_buffer_fini_batch_bo_chain(cmd_buffer
);
327 anv_state_stream_finish(&cmd_buffer
->surface_state_stream
);
328 anv_state_stream_finish(&cmd_buffer
->dynamic_state_stream
);
330 anv_cmd_state_finish(cmd_buffer
);
332 vk_object_base_finish(&cmd_buffer
->base
);
333 vk_free(&cmd_buffer
->pool
->alloc
, cmd_buffer
);
336 void anv_FreeCommandBuffers(
338 VkCommandPool commandPool
,
339 uint32_t commandBufferCount
,
340 const VkCommandBuffer
* pCommandBuffers
)
342 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
343 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, pCommandBuffers
[i
]);
348 anv_cmd_buffer_destroy(cmd_buffer
);
353 anv_cmd_buffer_reset(struct anv_cmd_buffer
*cmd_buffer
)
355 cmd_buffer
->usage_flags
= 0;
356 cmd_buffer
->perf_query_pool
= NULL
;
357 anv_cmd_buffer_reset_batch_bo_chain(cmd_buffer
);
358 anv_cmd_state_reset(cmd_buffer
);
360 anv_state_stream_finish(&cmd_buffer
->surface_state_stream
);
361 anv_state_stream_init(&cmd_buffer
->surface_state_stream
,
362 &cmd_buffer
->device
->surface_state_pool
, 4096);
364 anv_state_stream_finish(&cmd_buffer
->dynamic_state_stream
);
365 anv_state_stream_init(&cmd_buffer
->dynamic_state_stream
,
366 &cmd_buffer
->device
->dynamic_state_pool
, 16384);
370 VkResult
anv_ResetCommandBuffer(
371 VkCommandBuffer commandBuffer
,
372 VkCommandBufferResetFlags flags
)
374 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
375 return anv_cmd_buffer_reset(cmd_buffer
);
378 #define anv_genX_call(devinfo, func, ...) \
379 switch ((devinfo)->gen) { \
381 if ((devinfo)->is_haswell) { \
382 gen75_##func(__VA_ARGS__); \
384 gen7_##func(__VA_ARGS__); \
388 gen8_##func(__VA_ARGS__); \
391 gen9_##func(__VA_ARGS__); \
394 gen10_##func(__VA_ARGS__); \
397 gen11_##func(__VA_ARGS__); \
400 gen12_##func(__VA_ARGS__); \
403 assert(!"Unknown hardware generation"); \
407 anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
)
409 anv_genX_call(&cmd_buffer
->device
->info
,
410 cmd_buffer_emit_state_base_address
,
415 anv_cmd_buffer_mark_image_written(struct anv_cmd_buffer
*cmd_buffer
,
416 const struct anv_image
*image
,
417 VkImageAspectFlagBits aspect
,
418 enum isl_aux_usage aux_usage
,
421 uint32_t layer_count
)
423 anv_genX_call(&cmd_buffer
->device
->info
,
424 cmd_buffer_mark_image_written
,
425 cmd_buffer
, image
, aspect
, aux_usage
,
426 level
, base_layer
, layer_count
);
430 anv_cmd_emit_conditional_render_predicate(struct anv_cmd_buffer
*cmd_buffer
)
432 anv_genX_call(&cmd_buffer
->device
->info
,
433 cmd_emit_conditional_render_predicate
,
438 mem_update(void *dst
, const void *src
, size_t size
)
440 if (memcmp(dst
, src
, size
) == 0)
443 memcpy(dst
, src
, size
);
448 set_dirty_for_bind_map(struct anv_cmd_buffer
*cmd_buffer
,
449 gl_shader_stage stage
,
450 const struct anv_pipeline_bind_map
*map
)
452 if (mem_update(cmd_buffer
->state
.surface_sha1s
[stage
],
453 map
->surface_sha1
, sizeof(map
->surface_sha1
)))
454 cmd_buffer
->state
.descriptors_dirty
|= mesa_to_vk_shader_stage(stage
);
456 if (mem_update(cmd_buffer
->state
.sampler_sha1s
[stage
],
457 map
->sampler_sha1
, sizeof(map
->sampler_sha1
)))
458 cmd_buffer
->state
.descriptors_dirty
|= mesa_to_vk_shader_stage(stage
);
460 if (mem_update(cmd_buffer
->state
.push_sha1s
[stage
],
461 map
->push_sha1
, sizeof(map
->push_sha1
)))
462 cmd_buffer
->state
.push_constants_dirty
|= mesa_to_vk_shader_stage(stage
);
465 void anv_CmdBindPipeline(
466 VkCommandBuffer commandBuffer
,
467 VkPipelineBindPoint pipelineBindPoint
,
468 VkPipeline _pipeline
)
470 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
471 ANV_FROM_HANDLE(anv_pipeline
, pipeline
, _pipeline
);
473 switch (pipelineBindPoint
) {
474 case VK_PIPELINE_BIND_POINT_COMPUTE
: {
475 struct anv_compute_pipeline
*compute_pipeline
=
476 anv_pipeline_to_compute(pipeline
);
477 if (cmd_buffer
->state
.compute
.pipeline
== compute_pipeline
)
480 cmd_buffer
->state
.compute
.pipeline
= compute_pipeline
;
481 cmd_buffer
->state
.compute
.pipeline_dirty
= true;
482 set_dirty_for_bind_map(cmd_buffer
, MESA_SHADER_COMPUTE
,
483 &compute_pipeline
->cs
->bind_map
);
487 case VK_PIPELINE_BIND_POINT_GRAPHICS
: {
488 struct anv_graphics_pipeline
*gfx_pipeline
=
489 anv_pipeline_to_graphics(pipeline
);
490 if (cmd_buffer
->state
.gfx
.pipeline
== gfx_pipeline
)
493 cmd_buffer
->state
.gfx
.pipeline
= gfx_pipeline
;
494 cmd_buffer
->state
.gfx
.vb_dirty
|= gfx_pipeline
->vb_used
;
495 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_PIPELINE
;
497 anv_foreach_stage(stage
, gfx_pipeline
->active_stages
) {
498 set_dirty_for_bind_map(cmd_buffer
, stage
,
499 &gfx_pipeline
->shaders
[stage
]->bind_map
);
502 /* Apply the dynamic state from the pipeline */
503 cmd_buffer
->state
.gfx
.dirty
|=
504 anv_dynamic_state_copy(&cmd_buffer
->state
.gfx
.dynamic
,
505 &gfx_pipeline
->dynamic_state
,
506 gfx_pipeline
->dynamic_state_mask
);
511 assert(!"invalid bind point");
516 void anv_CmdSetViewport(
517 VkCommandBuffer commandBuffer
,
518 uint32_t firstViewport
,
519 uint32_t viewportCount
,
520 const VkViewport
* pViewports
)
522 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
524 const uint32_t total_count
= firstViewport
+ viewportCount
;
525 if (cmd_buffer
->state
.gfx
.dynamic
.viewport
.count
< total_count
)
526 cmd_buffer
->state
.gfx
.dynamic
.viewport
.count
= total_count
;
528 memcpy(cmd_buffer
->state
.gfx
.dynamic
.viewport
.viewports
+ firstViewport
,
529 pViewports
, viewportCount
* sizeof(*pViewports
));
531 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
;
534 void anv_CmdSetViewportWithCountEXT(
535 VkCommandBuffer commandBuffer
,
536 uint32_t viewportCount
,
537 const VkViewport
* pViewports
)
539 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
541 cmd_buffer
->state
.gfx
.dynamic
.viewport
.count
= viewportCount
;
543 memcpy(cmd_buffer
->state
.gfx
.dynamic
.viewport
.viewports
,
544 pViewports
, viewportCount
* sizeof(*pViewports
));
546 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
;
549 void anv_CmdSetScissor(
550 VkCommandBuffer commandBuffer
,
551 uint32_t firstScissor
,
552 uint32_t scissorCount
,
553 const VkRect2D
* pScissors
)
555 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
557 const uint32_t total_count
= firstScissor
+ scissorCount
;
558 if (cmd_buffer
->state
.gfx
.dynamic
.scissor
.count
< total_count
)
559 cmd_buffer
->state
.gfx
.dynamic
.scissor
.count
= total_count
;
561 memcpy(cmd_buffer
->state
.gfx
.dynamic
.scissor
.scissors
+ firstScissor
,
562 pScissors
, scissorCount
* sizeof(*pScissors
));
564 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_SCISSOR
;
567 void anv_CmdSetScissorWithCountEXT(
568 VkCommandBuffer commandBuffer
,
569 uint32_t scissorCount
,
570 const VkRect2D
* pScissors
)
572 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
574 cmd_buffer
->state
.gfx
.dynamic
.scissor
.count
= scissorCount
;
576 memcpy(cmd_buffer
->state
.gfx
.dynamic
.scissor
.scissors
,
577 pScissors
, scissorCount
* sizeof(*pScissors
));
579 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_SCISSOR
;
582 void anv_CmdSetPrimitiveTopologyEXT(
583 VkCommandBuffer commandBuffer
,
584 VkPrimitiveTopology primitiveTopology
)
586 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
588 cmd_buffer
->state
.gfx
.dynamic
.primitive_topology
= primitiveTopology
;
590 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_PRIMITIVE_TOPOLOGY
;
593 void anv_CmdSetLineWidth(
594 VkCommandBuffer commandBuffer
,
597 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
599 cmd_buffer
->state
.gfx
.dynamic
.line_width
= lineWidth
;
600 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
;
603 void anv_CmdSetDepthBias(
604 VkCommandBuffer commandBuffer
,
605 float depthBiasConstantFactor
,
606 float depthBiasClamp
,
607 float depthBiasSlopeFactor
)
609 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
611 cmd_buffer
->state
.gfx
.dynamic
.depth_bias
.bias
= depthBiasConstantFactor
;
612 cmd_buffer
->state
.gfx
.dynamic
.depth_bias
.clamp
= depthBiasClamp
;
613 cmd_buffer
->state
.gfx
.dynamic
.depth_bias
.slope
= depthBiasSlopeFactor
;
615 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
;
618 void anv_CmdSetBlendConstants(
619 VkCommandBuffer commandBuffer
,
620 const float blendConstants
[4])
622 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
624 memcpy(cmd_buffer
->state
.gfx
.dynamic
.blend_constants
,
625 blendConstants
, sizeof(float) * 4);
627 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
;
630 void anv_CmdSetDepthBounds(
631 VkCommandBuffer commandBuffer
,
632 float minDepthBounds
,
633 float maxDepthBounds
)
635 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
637 cmd_buffer
->state
.gfx
.dynamic
.depth_bounds
.min
= minDepthBounds
;
638 cmd_buffer
->state
.gfx
.dynamic
.depth_bounds
.max
= maxDepthBounds
;
640 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
;
643 void anv_CmdSetStencilCompareMask(
644 VkCommandBuffer commandBuffer
,
645 VkStencilFaceFlags faceMask
,
646 uint32_t compareMask
)
648 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
650 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
)
651 cmd_buffer
->state
.gfx
.dynamic
.stencil_compare_mask
.front
= compareMask
;
652 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
)
653 cmd_buffer
->state
.gfx
.dynamic
.stencil_compare_mask
.back
= compareMask
;
655 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
;
658 void anv_CmdSetStencilWriteMask(
659 VkCommandBuffer commandBuffer
,
660 VkStencilFaceFlags faceMask
,
663 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
665 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
)
666 cmd_buffer
->state
.gfx
.dynamic
.stencil_write_mask
.front
= writeMask
;
667 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
)
668 cmd_buffer
->state
.gfx
.dynamic
.stencil_write_mask
.back
= writeMask
;
670 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
;
673 void anv_CmdSetStencilReference(
674 VkCommandBuffer commandBuffer
,
675 VkStencilFaceFlags faceMask
,
678 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
680 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
)
681 cmd_buffer
->state
.gfx
.dynamic
.stencil_reference
.front
= reference
;
682 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
)
683 cmd_buffer
->state
.gfx
.dynamic
.stencil_reference
.back
= reference
;
685 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
;
688 void anv_CmdSetLineStippleEXT(
689 VkCommandBuffer commandBuffer
,
690 uint32_t lineStippleFactor
,
691 uint16_t lineStipplePattern
)
693 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
695 cmd_buffer
->state
.gfx
.dynamic
.line_stipple
.factor
= lineStippleFactor
;
696 cmd_buffer
->state
.gfx
.dynamic
.line_stipple
.pattern
= lineStipplePattern
;
698 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE
;
701 void anv_CmdSetCullModeEXT(
702 VkCommandBuffer commandBuffer
,
703 VkCullModeFlags cullMode
)
705 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
707 cmd_buffer
->state
.gfx
.dynamic
.cull_mode
= cullMode
;
709 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_CULL_MODE
;
712 void anv_CmdSetFrontFaceEXT(
713 VkCommandBuffer commandBuffer
,
714 VkFrontFace frontFace
)
716 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
718 cmd_buffer
->state
.gfx
.dynamic
.front_face
= frontFace
;
720 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_FRONT_FACE
;
723 void anv_CmdSetDepthTestEnableEXT(
724 VkCommandBuffer commandBuffer
,
725 VkBool32 depthTestEnable
)
728 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
730 cmd_buffer
->state
.gfx
.dynamic
.depth_test_enable
= depthTestEnable
;
732 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_DEPTH_TEST_ENABLE
;
735 void anv_CmdSetDepthWriteEnableEXT(
736 VkCommandBuffer commandBuffer
,
737 VkBool32 depthWriteEnable
)
739 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
741 cmd_buffer
->state
.gfx
.dynamic
.depth_write_enable
= depthWriteEnable
;
743 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_DEPTH_WRITE_ENABLE
;
746 void anv_CmdSetDepthCompareOpEXT(
747 VkCommandBuffer commandBuffer
,
748 VkCompareOp depthCompareOp
)
750 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
752 cmd_buffer
->state
.gfx
.dynamic
.depth_compare_op
= depthCompareOp
;
754 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_DEPTH_COMPARE_OP
;
757 void anv_CmdSetDepthBoundsTestEnableEXT(
758 VkCommandBuffer commandBuffer
,
759 VkBool32 depthBoundsTestEnable
)
761 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
763 cmd_buffer
->state
.gfx
.dynamic
.depth_bounds_test_enable
= depthBoundsTestEnable
;
765 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE
;
768 void anv_CmdSetStencilTestEnableEXT(
769 VkCommandBuffer commandBuffer
,
770 VkBool32 stencilTestEnable
)
772 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
774 cmd_buffer
->state
.gfx
.dynamic
.stencil_test_enable
= stencilTestEnable
;
776 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_STENCIL_TEST_ENABLE
;
779 void anv_CmdSetStencilOpEXT(
780 VkCommandBuffer commandBuffer
,
781 VkStencilFaceFlags faceMask
,
784 VkStencilOp depthFailOp
,
785 VkCompareOp compareOp
)
787 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
789 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
) {
790 cmd_buffer
->state
.gfx
.dynamic
.stencil_op
.front
.fail_op
= failOp
;
791 cmd_buffer
->state
.gfx
.dynamic
.stencil_op
.front
.pass_op
= passOp
;
792 cmd_buffer
->state
.gfx
.dynamic
.stencil_op
.front
.depth_fail_op
= depthFailOp
;
793 cmd_buffer
->state
.gfx
.dynamic
.stencil_op
.front
.compare_op
= compareOp
;
796 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
) {
797 cmd_buffer
->state
.gfx
.dynamic
.stencil_op
.back
.fail_op
= failOp
;
798 cmd_buffer
->state
.gfx
.dynamic
.stencil_op
.back
.pass_op
= passOp
;
799 cmd_buffer
->state
.gfx
.dynamic
.stencil_op
.back
.depth_fail_op
= depthFailOp
;
800 cmd_buffer
->state
.gfx
.dynamic
.stencil_op
.back
.compare_op
= compareOp
;
803 cmd_buffer
->state
.gfx
.dirty
|= ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP
;
807 anv_cmd_buffer_bind_descriptor_set(struct anv_cmd_buffer
*cmd_buffer
,
808 VkPipelineBindPoint bind_point
,
809 struct anv_pipeline_layout
*layout
,
811 struct anv_descriptor_set
*set
,
812 uint32_t *dynamic_offset_count
,
813 const uint32_t **dynamic_offsets
)
815 struct anv_descriptor_set_layout
*set_layout
=
816 layout
->set
[set_index
].layout
;
818 VkShaderStageFlags stages
= set_layout
->shader_stages
;
819 struct anv_cmd_pipeline_state
*pipe_state
;
821 switch (bind_point
) {
822 case VK_PIPELINE_BIND_POINT_GRAPHICS
:
823 stages
&= VK_SHADER_STAGE_ALL_GRAPHICS
;
824 pipe_state
= &cmd_buffer
->state
.gfx
.base
;
827 case VK_PIPELINE_BIND_POINT_COMPUTE
:
828 stages
&= VK_SHADER_STAGE_COMPUTE_BIT
;
829 pipe_state
= &cmd_buffer
->state
.compute
.base
;
833 unreachable("invalid bind point");
836 VkShaderStageFlags dirty_stages
= 0;
837 if (pipe_state
->descriptors
[set_index
] != set
) {
838 pipe_state
->descriptors
[set_index
] = set
;
839 dirty_stages
|= stages
;
842 /* If it's a push descriptor set, we have to flag things as dirty
843 * regardless of whether or not the CPU-side data structure changed as we
844 * may have edited in-place.
846 if (set
->pool
== NULL
)
847 dirty_stages
|= stages
;
849 if (dynamic_offsets
) {
850 if (set_layout
->dynamic_offset_count
> 0) {
851 uint32_t dynamic_offset_start
=
852 layout
->set
[set_index
].dynamic_offset_start
;
854 anv_foreach_stage(stage
, stages
) {
855 struct anv_push_constants
*push
=
856 &cmd_buffer
->state
.push_constants
[stage
];
857 uint32_t *push_offsets
=
858 &push
->dynamic_offsets
[dynamic_offset_start
];
860 /* Assert that everything is in range */
861 assert(set_layout
->dynamic_offset_count
<= *dynamic_offset_count
);
862 assert(dynamic_offset_start
+ set_layout
->dynamic_offset_count
<=
863 ARRAY_SIZE(push
->dynamic_offsets
));
865 unsigned mask
= set_layout
->stage_dynamic_offsets
[stage
];
866 STATIC_ASSERT(MAX_DYNAMIC_BUFFERS
<= sizeof(mask
) * 8);
868 int i
= u_bit_scan(&mask
);
869 if (push_offsets
[i
] != (*dynamic_offsets
)[i
]) {
870 push_offsets
[i
] = (*dynamic_offsets
)[i
];
871 dirty_stages
|= mesa_to_vk_shader_stage(stage
);
876 *dynamic_offsets
+= set_layout
->dynamic_offset_count
;
877 *dynamic_offset_count
-= set_layout
->dynamic_offset_count
;
881 cmd_buffer
->state
.descriptors_dirty
|= dirty_stages
;
882 cmd_buffer
->state
.push_constants_dirty
|= dirty_stages
;
885 void anv_CmdBindDescriptorSets(
886 VkCommandBuffer commandBuffer
,
887 VkPipelineBindPoint pipelineBindPoint
,
888 VkPipelineLayout _layout
,
890 uint32_t descriptorSetCount
,
891 const VkDescriptorSet
* pDescriptorSets
,
892 uint32_t dynamicOffsetCount
,
893 const uint32_t* pDynamicOffsets
)
895 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
896 ANV_FROM_HANDLE(anv_pipeline_layout
, layout
, _layout
);
898 assert(firstSet
+ descriptorSetCount
<= MAX_SETS
);
900 for (uint32_t i
= 0; i
< descriptorSetCount
; i
++) {
901 ANV_FROM_HANDLE(anv_descriptor_set
, set
, pDescriptorSets
[i
]);
902 anv_cmd_buffer_bind_descriptor_set(cmd_buffer
, pipelineBindPoint
,
903 layout
, firstSet
+ i
, set
,
909 void anv_CmdBindVertexBuffers2EXT(
910 VkCommandBuffer commandBuffer
,
911 uint32_t firstBinding
,
912 uint32_t bindingCount
,
913 const VkBuffer
* pBuffers
,
914 const VkDeviceSize
* pOffsets
,
915 const VkDeviceSize
* pSizes
,
916 const VkDeviceSize
* pStrides
)
918 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
919 struct anv_vertex_binding
*vb
= cmd_buffer
->state
.vertex_bindings
;
921 /* We have to defer setting up vertex buffer since we need the buffer
922 * stride from the pipeline. */
925 cmd_buffer
->state
.gfx
.dynamic
.dyn_vbo_size
= true;
927 cmd_buffer
->state
.gfx
.dynamic
.dyn_vbo_stride
= true;
929 assert(firstBinding
+ bindingCount
<= MAX_VBS
);
930 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
931 vb
[firstBinding
+ i
].buffer
= anv_buffer_from_handle(pBuffers
[i
]);
932 vb
[firstBinding
+ i
].offset
= pOffsets
[i
];
933 vb
[firstBinding
+ i
].size
= pSizes
? pSizes
[i
] : 0;
934 vb
[firstBinding
+ i
].stride
= pStrides
? pStrides
[i
] : 0;
935 cmd_buffer
->state
.gfx
.vb_dirty
|= 1 << (firstBinding
+ i
);
939 void anv_CmdBindVertexBuffers(
940 VkCommandBuffer commandBuffer
,
941 uint32_t firstBinding
,
942 uint32_t bindingCount
,
943 const VkBuffer
* pBuffers
,
944 const VkDeviceSize
* pOffsets
)
946 return anv_CmdBindVertexBuffers2EXT(commandBuffer
, firstBinding
,
947 bindingCount
, pBuffers
, pOffsets
,
951 void anv_CmdBindTransformFeedbackBuffersEXT(
952 VkCommandBuffer commandBuffer
,
953 uint32_t firstBinding
,
954 uint32_t bindingCount
,
955 const VkBuffer
* pBuffers
,
956 const VkDeviceSize
* pOffsets
,
957 const VkDeviceSize
* pSizes
)
959 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
960 struct anv_xfb_binding
*xfb
= cmd_buffer
->state
.xfb_bindings
;
962 /* We have to defer setting up vertex buffer since we need the buffer
963 * stride from the pipeline. */
965 assert(firstBinding
+ bindingCount
<= MAX_XFB_BUFFERS
);
966 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
967 if (pBuffers
[i
] == VK_NULL_HANDLE
) {
968 xfb
[firstBinding
+ i
].buffer
= NULL
;
970 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBuffers
[i
]);
971 xfb
[firstBinding
+ i
].buffer
= buffer
;
972 xfb
[firstBinding
+ i
].offset
= pOffsets
[i
];
973 xfb
[firstBinding
+ i
].size
=
974 anv_buffer_get_range(buffer
, pOffsets
[i
],
975 pSizes
? pSizes
[i
] : VK_WHOLE_SIZE
);
981 anv_isl_format_for_descriptor_type(VkDescriptorType type
)
984 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
985 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
986 return ISL_FORMAT_R32G32B32A32_FLOAT
;
988 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
989 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
990 return ISL_FORMAT_RAW
;
993 unreachable("Invalid descriptor type");
998 anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
999 const void *data
, uint32_t size
, uint32_t alignment
)
1001 struct anv_state state
;
1003 state
= anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, size
, alignment
);
1004 memcpy(state
.map
, data
, size
);
1006 VG(VALGRIND_CHECK_MEM_IS_DEFINED(state
.map
, size
));
1012 anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1013 uint32_t *a
, uint32_t *b
,
1014 uint32_t dwords
, uint32_t alignment
)
1016 struct anv_state state
;
1019 state
= anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
,
1020 dwords
* 4, alignment
);
1022 for (uint32_t i
= 0; i
< dwords
; i
++)
1025 VG(VALGRIND_CHECK_MEM_IS_DEFINED(p
, dwords
* 4));
1031 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1032 gl_shader_stage stage
)
1034 struct anv_push_constants
*data
=
1035 &cmd_buffer
->state
.push_constants
[stage
];
1037 struct anv_state state
=
1038 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
,
1039 sizeof(struct anv_push_constants
),
1040 32 /* bottom 5 bits MBZ */);
1041 memcpy(state
.map
, data
, sizeof(struct anv_push_constants
));
1047 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
)
1049 struct anv_push_constants
*data
=
1050 &cmd_buffer
->state
.push_constants
[MESA_SHADER_COMPUTE
];
1051 struct anv_compute_pipeline
*pipeline
= cmd_buffer
->state
.compute
.pipeline
;
1052 const struct brw_cs_prog_data
*cs_prog_data
= get_cs_prog_data(pipeline
);
1053 const struct anv_push_range
*range
= &pipeline
->cs
->bind_map
.push_ranges
[0];
1055 const struct anv_cs_parameters cs_params
= anv_cs_parameters(pipeline
);
1056 const unsigned total_push_constants_size
=
1057 brw_cs_push_const_total_size(cs_prog_data
, cs_params
.threads
);
1058 if (total_push_constants_size
== 0)
1059 return (struct anv_state
) { .offset
= 0 };
1061 const unsigned push_constant_alignment
=
1062 cmd_buffer
->device
->info
.gen
< 8 ? 32 : 64;
1063 const unsigned aligned_total_push_constants_size
=
1064 ALIGN(total_push_constants_size
, push_constant_alignment
);
1065 struct anv_state state
=
1066 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
,
1067 aligned_total_push_constants_size
,
1068 push_constant_alignment
);
1070 void *dst
= state
.map
;
1071 const void *src
= (char *)data
+ (range
->start
* 32);
1073 if (cs_prog_data
->push
.cross_thread
.size
> 0) {
1074 memcpy(dst
, src
, cs_prog_data
->push
.cross_thread
.size
);
1075 dst
+= cs_prog_data
->push
.cross_thread
.size
;
1076 src
+= cs_prog_data
->push
.cross_thread
.size
;
1079 if (cs_prog_data
->push
.per_thread
.size
> 0) {
1080 for (unsigned t
= 0; t
< cs_params
.threads
; t
++) {
1081 memcpy(dst
, src
, cs_prog_data
->push
.per_thread
.size
);
1083 uint32_t *subgroup_id
= dst
+
1084 offsetof(struct anv_push_constants
, cs
.subgroup_id
) -
1085 (range
->start
* 32 + cs_prog_data
->push
.cross_thread
.size
);
1088 dst
+= cs_prog_data
->push
.per_thread
.size
;
1095 void anv_CmdPushConstants(
1096 VkCommandBuffer commandBuffer
,
1097 VkPipelineLayout layout
,
1098 VkShaderStageFlags stageFlags
,
1101 const void* pValues
)
1103 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1105 anv_foreach_stage(stage
, stageFlags
) {
1106 memcpy(cmd_buffer
->state
.push_constants
[stage
].client_data
+ offset
,
1110 cmd_buffer
->state
.push_constants_dirty
|= stageFlags
;
1113 VkResult
anv_CreateCommandPool(
1115 const VkCommandPoolCreateInfo
* pCreateInfo
,
1116 const VkAllocationCallbacks
* pAllocator
,
1117 VkCommandPool
* pCmdPool
)
1119 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1120 struct anv_cmd_pool
*pool
;
1122 pool
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*pool
), 8,
1123 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1125 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1127 vk_object_base_init(&device
->vk
, &pool
->base
, VK_OBJECT_TYPE_COMMAND_POOL
);
1130 pool
->alloc
= *pAllocator
;
1132 pool
->alloc
= device
->vk
.alloc
;
1134 list_inithead(&pool
->cmd_buffers
);
1136 *pCmdPool
= anv_cmd_pool_to_handle(pool
);
1141 void anv_DestroyCommandPool(
1143 VkCommandPool commandPool
,
1144 const VkAllocationCallbacks
* pAllocator
)
1146 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1147 ANV_FROM_HANDLE(anv_cmd_pool
, pool
, commandPool
);
1152 list_for_each_entry_safe(struct anv_cmd_buffer
, cmd_buffer
,
1153 &pool
->cmd_buffers
, pool_link
) {
1154 anv_cmd_buffer_destroy(cmd_buffer
);
1157 vk_object_base_finish(&pool
->base
);
1158 vk_free2(&device
->vk
.alloc
, pAllocator
, pool
);
1161 VkResult
anv_ResetCommandPool(
1163 VkCommandPool commandPool
,
1164 VkCommandPoolResetFlags flags
)
1166 ANV_FROM_HANDLE(anv_cmd_pool
, pool
, commandPool
);
1168 list_for_each_entry(struct anv_cmd_buffer
, cmd_buffer
,
1169 &pool
->cmd_buffers
, pool_link
) {
1170 anv_cmd_buffer_reset(cmd_buffer
);
1176 void anv_TrimCommandPool(
1178 VkCommandPool commandPool
,
1179 VkCommandPoolTrimFlags flags
)
1181 /* Nothing for us to do here. Our pools stay pretty tidy. */
1185 * Return NULL if the current subpass has no depthstencil attachment.
1187 const struct anv_image_view
*
1188 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
)
1190 const struct anv_subpass
*subpass
= cmd_buffer
->state
.subpass
;
1192 if (subpass
->depth_stencil_attachment
== NULL
)
1195 const struct anv_image_view
*iview
=
1196 cmd_buffer
->state
.attachments
[subpass
->depth_stencil_attachment
->attachment
].image_view
;
1198 assert(iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
|
1199 VK_IMAGE_ASPECT_STENCIL_BIT
));
1204 static struct anv_descriptor_set
*
1205 anv_cmd_buffer_push_descriptor_set(struct anv_cmd_buffer
*cmd_buffer
,
1206 VkPipelineBindPoint bind_point
,
1207 struct anv_descriptor_set_layout
*layout
,
1210 struct anv_cmd_pipeline_state
*pipe_state
;
1211 if (bind_point
== VK_PIPELINE_BIND_POINT_COMPUTE
) {
1212 pipe_state
= &cmd_buffer
->state
.compute
.base
;
1214 assert(bind_point
== VK_PIPELINE_BIND_POINT_GRAPHICS
);
1215 pipe_state
= &cmd_buffer
->state
.gfx
.base
;
1218 struct anv_push_descriptor_set
**push_set
=
1219 &pipe_state
->push_descriptors
[_set
];
1221 if (*push_set
== NULL
) {
1222 *push_set
= vk_zalloc(&cmd_buffer
->pool
->alloc
,
1223 sizeof(struct anv_push_descriptor_set
), 8,
1224 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1225 if (*push_set
== NULL
) {
1226 anv_batch_set_error(&cmd_buffer
->batch
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1231 struct anv_descriptor_set
*set
= &(*push_set
)->set
;
1233 if (set
->layout
!= layout
) {
1235 anv_descriptor_set_layout_unref(cmd_buffer
->device
, set
->layout
);
1236 anv_descriptor_set_layout_ref(layout
);
1237 set
->layout
= layout
;
1239 set
->size
= anv_descriptor_set_layout_size(layout
);
1240 set
->buffer_view_count
= layout
->buffer_view_count
;
1241 set
->buffer_views
= (*push_set
)->buffer_views
;
1243 if (layout
->descriptor_buffer_size
&&
1244 ((*push_set
)->set_used_on_gpu
||
1245 set
->desc_mem
.alloc_size
< layout
->descriptor_buffer_size
)) {
1246 /* The previous buffer is either actively used by some GPU command (so
1247 * we can't modify it) or is too small. Allocate a new one.
1249 struct anv_state desc_mem
=
1250 anv_state_stream_alloc(&cmd_buffer
->dynamic_state_stream
,
1251 layout
->descriptor_buffer_size
, 32);
1252 if (set
->desc_mem
.alloc_size
) {
1253 /* TODO: Do we really need to copy all the time? */
1254 memcpy(desc_mem
.map
, set
->desc_mem
.map
,
1255 MIN2(desc_mem
.alloc_size
, set
->desc_mem
.alloc_size
));
1257 set
->desc_mem
= desc_mem
;
1259 struct anv_address addr
= {
1260 .bo
= cmd_buffer
->dynamic_state_stream
.state_pool
->block_pool
.bo
,
1261 .offset
= set
->desc_mem
.offset
,
1264 const struct isl_device
*isl_dev
= &cmd_buffer
->device
->isl_dev
;
1265 set
->desc_surface_state
=
1266 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
,
1267 isl_dev
->ss
.size
, isl_dev
->ss
.align
);
1268 anv_fill_buffer_surface_state(cmd_buffer
->device
,
1269 set
->desc_surface_state
,
1270 ISL_FORMAT_R32G32B32A32_FLOAT
,
1271 addr
, layout
->descriptor_buffer_size
, 1);
1277 void anv_CmdPushDescriptorSetKHR(
1278 VkCommandBuffer commandBuffer
,
1279 VkPipelineBindPoint pipelineBindPoint
,
1280 VkPipelineLayout _layout
,
1282 uint32_t descriptorWriteCount
,
1283 const VkWriteDescriptorSet
* pDescriptorWrites
)
1285 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1286 ANV_FROM_HANDLE(anv_pipeline_layout
, layout
, _layout
);
1288 assert(_set
< MAX_SETS
);
1290 struct anv_descriptor_set_layout
*set_layout
= layout
->set
[_set
].layout
;
1292 struct anv_descriptor_set
*set
=
1293 anv_cmd_buffer_push_descriptor_set(cmd_buffer
, pipelineBindPoint
,
1298 /* Go through the user supplied descriptors. */
1299 for (uint32_t i
= 0; i
< descriptorWriteCount
; i
++) {
1300 const VkWriteDescriptorSet
*write
= &pDescriptorWrites
[i
];
1302 switch (write
->descriptorType
) {
1303 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1304 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1305 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1306 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1307 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
1308 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
1309 anv_descriptor_set_write_image_view(cmd_buffer
->device
, set
,
1310 write
->pImageInfo
+ j
,
1311 write
->descriptorType
,
1313 write
->dstArrayElement
+ j
);
1317 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1318 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1319 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
1320 ANV_FROM_HANDLE(anv_buffer_view
, bview
,
1321 write
->pTexelBufferView
[j
]);
1323 anv_descriptor_set_write_buffer_view(cmd_buffer
->device
, set
,
1324 write
->descriptorType
,
1327 write
->dstArrayElement
+ j
);
1331 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1332 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1333 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1334 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1335 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
1336 ANV_FROM_HANDLE(anv_buffer
, buffer
, write
->pBufferInfo
[j
].buffer
);
1338 anv_descriptor_set_write_buffer(cmd_buffer
->device
, set
,
1339 &cmd_buffer
->surface_state_stream
,
1340 write
->descriptorType
,
1343 write
->dstArrayElement
+ j
,
1344 write
->pBufferInfo
[j
].offset
,
1345 write
->pBufferInfo
[j
].range
);
1354 anv_cmd_buffer_bind_descriptor_set(cmd_buffer
, pipelineBindPoint
,
1355 layout
, _set
, set
, NULL
, NULL
);
1358 void anv_CmdPushDescriptorSetWithTemplateKHR(
1359 VkCommandBuffer commandBuffer
,
1360 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1361 VkPipelineLayout _layout
,
1365 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1366 ANV_FROM_HANDLE(anv_descriptor_update_template
, template,
1367 descriptorUpdateTemplate
);
1368 ANV_FROM_HANDLE(anv_pipeline_layout
, layout
, _layout
);
1370 assert(_set
< MAX_PUSH_DESCRIPTORS
);
1372 struct anv_descriptor_set_layout
*set_layout
= layout
->set
[_set
].layout
;
1374 struct anv_descriptor_set
*set
=
1375 anv_cmd_buffer_push_descriptor_set(cmd_buffer
, template->bind_point
,
1380 anv_descriptor_set_write_template(cmd_buffer
->device
, set
,
1381 &cmd_buffer
->surface_state_stream
,
1385 anv_cmd_buffer_bind_descriptor_set(cmd_buffer
, template->bind_point
,
1386 layout
, _set
, set
, NULL
, NULL
);
1389 void anv_CmdSetDeviceMask(
1390 VkCommandBuffer commandBuffer
,
1391 uint32_t deviceMask
)