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
25 #include "anv_meta_clear.h"
26 #include "anv_nir_builder.h"
27 #include "anv_private.h"
29 /** Vertex attributes for color clears. */
30 struct color_clear_vattrs
{
31 struct anv_vue_header vue_header
;
32 float position
[2]; /**< 3DPRIM_RECTLIST */
33 VkClearColorValue color
;
36 /** Vertex attributes for depthstencil clears. */
37 struct depthstencil_clear_vattrs
{
38 struct anv_vue_header vue_header
;
39 float position
[2]; /*<< 3DPRIM_RECTLIST */
43 meta_clear_begin(struct anv_meta_saved_state
*saved_state
,
44 struct anv_cmd_buffer
*cmd_buffer
)
46 anv_meta_save(saved_state
, cmd_buffer
,
47 (1 << VK_DYNAMIC_STATE_VIEWPORT
) |
48 (1 << VK_DYNAMIC_STATE_SCISSOR
) |
49 (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE
));
51 cmd_buffer
->state
.dynamic
.viewport
.count
= 0;
52 cmd_buffer
->state
.dynamic
.scissor
.count
= 0;
56 meta_clear_end(struct anv_meta_saved_state
*saved_state
,
57 struct anv_cmd_buffer
*cmd_buffer
)
59 anv_meta_restore(saved_state
, cmd_buffer
);
63 build_color_shaders(struct nir_shader
**out_vs
,
64 struct nir_shader
**out_fs
)
69 nir_builder_init_simple_shader(&vs_b
, MESA_SHADER_VERTEX
);
70 nir_builder_init_simple_shader(&fs_b
, MESA_SHADER_FRAGMENT
);
72 const struct glsl_type
*position_type
= glsl_vec4_type();
73 const struct glsl_type
*color_type
= glsl_vec4_type();
75 nir_variable
*vs_in_pos
=
76 nir_variable_create(vs_b
.shader
, nir_var_shader_in
, position_type
,
78 vs_in_pos
->data
.location
= VERT_ATTRIB_GENERIC0
;
80 nir_variable
*vs_out_pos
=
81 nir_variable_create(vs_b
.shader
, nir_var_shader_out
, position_type
,
83 vs_out_pos
->data
.location
= VARYING_SLOT_POS
;
85 nir_variable
*vs_in_color
=
86 nir_variable_create(vs_b
.shader
, nir_var_shader_in
, color_type
,
88 vs_in_color
->data
.location
= VERT_ATTRIB_GENERIC1
;
90 nir_variable
*vs_out_color
=
91 nir_variable_create(vs_b
.shader
, nir_var_shader_out
, color_type
,
93 vs_out_color
->data
.location
= VARYING_SLOT_VAR0
;
94 vs_out_color
->data
.interpolation
= INTERP_QUALIFIER_FLAT
;
96 nir_variable
*fs_in_color
=
97 nir_variable_create(fs_b
.shader
, nir_var_shader_in
, color_type
,
99 fs_in_color
->data
.location
= vs_out_color
->data
.location
;
100 fs_in_color
->data
.interpolation
= vs_out_color
->data
.interpolation
;
102 nir_variable
*fs_out_color
=
103 nir_variable_create(fs_b
.shader
, nir_var_shader_out
, color_type
,
105 fs_out_color
->data
.location
= FRAG_RESULT_DATA0
;
107 nir_copy_var(&vs_b
, vs_out_pos
, vs_in_pos
);
108 nir_copy_var(&vs_b
, vs_out_color
, vs_in_color
);
109 nir_copy_var(&fs_b
, fs_out_color
, fs_in_color
);
111 *out_vs
= vs_b
.shader
;
112 *out_fs
= fs_b
.shader
;
115 static struct anv_pipeline
*
116 create_pipeline(struct anv_device
*device
,
117 struct nir_shader
*vs_nir
,
118 struct nir_shader
*fs_nir
,
119 const VkPipelineVertexInputStateCreateInfo
*vi_state
,
120 const VkPipelineDepthStencilStateCreateInfo
*ds_state
,
121 const VkPipelineColorBlendStateCreateInfo
*cb_state
,
122 const VkAllocationCallbacks
*alloc
)
124 VkDevice device_h
= anv_device_to_handle(device
);
126 struct anv_shader_module vs_m
= { .nir
= vs_nir
};
127 struct anv_shader_module fs_m
= { .nir
= fs_nir
};
129 VkPipeline pipeline_h
;
130 anv_graphics_pipeline_create(device_h
,
131 &(VkGraphicsPipelineCreateInfo
) {
132 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
134 .pStages
= (VkPipelineShaderStageCreateInfo
[]) {
136 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
137 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
138 .module
= anv_shader_module_to_handle(&vs_m
),
142 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
143 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
144 .module
= anv_shader_module_to_handle(&fs_m
),
148 .pVertexInputState
= vi_state
,
149 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
150 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
151 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
152 .primitiveRestartEnable
= false,
154 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
155 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
157 .pViewports
= NULL
, /* dynamic */
159 .pScissors
= NULL
, /* dynamic */
161 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
162 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
163 .rasterizerDiscardEnable
= false,
164 .polygonMode
= VK_POLYGON_MODE_FILL
,
165 .cullMode
= VK_CULL_MODE_NONE
,
166 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
,
167 .depthBiasEnable
= false,
169 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
170 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
171 .rasterizationSamples
= 1, /* FINISHME: Multisampling */
172 .sampleShadingEnable
= false,
173 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
174 .alphaToCoverageEnable
= false,
175 .alphaToOneEnable
= false,
177 .pDepthStencilState
= ds_state
,
178 .pColorBlendState
= cb_state
,
179 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
180 /* The meta clear pipeline declares all state as dynamic.
181 * As a consequence, vkCmdBindPipeline writes no dynamic state
182 * to the cmd buffer. Therefore, at the end of the meta clear,
183 * we need only restore dynamic state was vkCmdSet.
185 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
186 .dynamicStateCount
= 9,
187 .pDynamicStates
= (VkDynamicState
[]) {
188 VK_DYNAMIC_STATE_VIEWPORT
,
189 VK_DYNAMIC_STATE_SCISSOR
,
190 VK_DYNAMIC_STATE_LINE_WIDTH
,
191 VK_DYNAMIC_STATE_DEPTH_BIAS
,
192 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
193 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
194 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
195 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
196 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
200 .renderPass
= anv_render_pass_to_handle(&anv_meta_dummy_renderpass
),
203 &(struct anv_graphics_pipeline_create_info
) {
204 .use_repclear
= true,
205 .disable_viewport
= true,
215 return anv_pipeline_from_handle(pipeline_h
);
219 init_color_pipeline(struct anv_device
*device
)
221 struct nir_shader
*vs_nir
;
222 struct nir_shader
*fs_nir
;
223 build_color_shaders(&vs_nir
, &fs_nir
);
225 const VkPipelineVertexInputStateCreateInfo vi_state
= {
226 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
227 .vertexBindingDescriptionCount
= 1,
228 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
231 .stride
= sizeof(struct color_clear_vattrs
),
232 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
235 .vertexAttributeDescriptionCount
= 3,
236 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
241 .format
= VK_FORMAT_R32G32B32A32_UINT
,
242 .offset
= offsetof(struct color_clear_vattrs
, vue_header
),
248 .format
= VK_FORMAT_R32G32_SFLOAT
,
249 .offset
= offsetof(struct color_clear_vattrs
, position
),
255 .format
= VK_FORMAT_R32G32B32A32_SFLOAT
,
256 .offset
= offsetof(struct color_clear_vattrs
, color
),
261 const VkPipelineDepthStencilStateCreateInfo ds_state
= {
262 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
263 .depthTestEnable
= false,
264 .depthWriteEnable
= false,
265 .depthBoundsTestEnable
= false,
266 .stencilTestEnable
= false,
269 const VkPipelineColorBlendStateCreateInfo cb_state
= {
270 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
271 .logicOpEnable
= false,
272 .attachmentCount
= 1,
273 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
275 .blendEnable
= false,
276 .colorWriteMask
= VK_COLOR_COMPONENT_A_BIT
|
277 VK_COLOR_COMPONENT_R_BIT
|
278 VK_COLOR_COMPONENT_G_BIT
|
279 VK_COLOR_COMPONENT_B_BIT
,
284 device
->meta_state
.clear
.color_pipeline
=
285 create_pipeline(device
, vs_nir
, fs_nir
, &vi_state
, &ds_state
,
290 emit_load_color_clear(struct anv_cmd_buffer
*cmd_buffer
,
292 VkClearColorValue clear_value
)
294 struct anv_device
*device
= cmd_buffer
->device
;
295 VkCommandBuffer cmd_buffer_h
= anv_cmd_buffer_to_handle(cmd_buffer
);
296 const struct anv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
297 VkPipeline pipeline_h
=
298 anv_pipeline_to_handle(device
->meta_state
.clear
.color_pipeline
);
300 const struct color_clear_vattrs vertex_data
[3] = {
303 .position
= { 0.0, 0.0 },
304 .color
= clear_value
,
308 .position
= { fb
->width
, 0.0 },
309 .color
= clear_value
,
313 .position
= { fb
->width
, fb
->height
},
314 .color
= clear_value
,
318 struct anv_state state
=
319 anv_cmd_buffer_emit_dynamic(cmd_buffer
, vertex_data
, sizeof(vertex_data
), 16);
321 struct anv_buffer vertex_buffer
= {
323 .size
= sizeof(vertex_data
),
324 .bo
= &device
->dynamic_state_block_pool
.bo
,
325 .offset
= state
.offset
,
328 anv_cmd_buffer_begin_subpass(cmd_buffer
,
329 &(struct anv_subpass
) {
331 .color_attachments
= (uint32_t[]) { attachment
},
332 .depth_stencil_attachment
= VK_ATTACHMENT_UNUSED
,
335 ANV_CALL(CmdSetViewport
)(cmd_buffer_h
, 1,
341 .height
= fb
->height
,
347 ANV_CALL(CmdSetScissor
)(cmd_buffer_h
, 1,
351 .extent
= { fb
->width
, fb
->height
},
355 ANV_CALL(CmdBindVertexBuffers
)(cmd_buffer_h
, 0, 1,
356 (VkBuffer
[]) { anv_buffer_to_handle(&vertex_buffer
) },
357 (VkDeviceSize
[]) { 0 });
359 if (cmd_buffer
->state
.pipeline
!= device
->meta_state
.clear
.color_pipeline
) {
360 ANV_CALL(CmdBindPipeline
)(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
364 ANV_CALL(CmdDraw
)(cmd_buffer_h
, 3, 1, 0, 0);
369 build_depthstencil_shaders(struct nir_shader
**out_vs
,
370 struct nir_shader
**out_fs
)
375 nir_builder_init_simple_shader(&vs_b
, MESA_SHADER_VERTEX
);
376 nir_builder_init_simple_shader(&fs_b
, MESA_SHADER_FRAGMENT
);
378 const struct glsl_type
*position_type
= glsl_vec4_type();
380 nir_variable
*vs_in_pos
=
381 nir_variable_create(vs_b
.shader
, nir_var_shader_in
, position_type
,
383 vs_in_pos
->data
.location
= VERT_ATTRIB_GENERIC0
;
385 nir_variable
*vs_out_pos
=
386 nir_variable_create(vs_b
.shader
, nir_var_shader_out
, position_type
,
388 vs_out_pos
->data
.location
= VARYING_SLOT_POS
;
390 nir_copy_var(&vs_b
, vs_out_pos
, vs_in_pos
);
392 *out_vs
= vs_b
.shader
;
393 *out_fs
= fs_b
.shader
;
396 static struct anv_pipeline
*
397 create_depthstencil_pipeline(struct anv_device
*device
,
398 VkImageAspectFlags aspects
)
400 struct nir_shader
*vs_nir
;
401 struct nir_shader
*fs_nir
;
403 build_depthstencil_shaders(&vs_nir
, &fs_nir
);
405 const VkPipelineVertexInputStateCreateInfo vi_state
= {
406 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
407 .vertexBindingDescriptionCount
= 1,
408 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
411 .stride
= sizeof(struct depthstencil_clear_vattrs
),
412 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
415 .vertexAttributeDescriptionCount
= 2,
416 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
421 .format
= VK_FORMAT_R32G32B32A32_UINT
,
422 .offset
= offsetof(struct depthstencil_clear_vattrs
, vue_header
),
428 .format
= VK_FORMAT_R32G32_SFLOAT
,
429 .offset
= offsetof(struct depthstencil_clear_vattrs
, position
),
434 const VkPipelineDepthStencilStateCreateInfo ds_state
= {
435 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
436 .depthTestEnable
= (aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
),
437 .depthCompareOp
= VK_COMPARE_OP_ALWAYS
,
438 .depthWriteEnable
= (aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
),
439 .depthBoundsTestEnable
= false,
440 .stencilTestEnable
= (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
),
442 .passOp
= VK_STENCIL_OP_REPLACE
,
443 .compareOp
= VK_COMPARE_OP_ALWAYS
,
444 .writeMask
= UINT32_MAX
,
445 .reference
= 0, /* dynamic */
447 .back
= { 0 /* dont care */ },
450 const VkPipelineColorBlendStateCreateInfo cb_state
= {
451 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
452 .logicOpEnable
= false,
453 .attachmentCount
= 0,
454 .pAttachments
= NULL
,
457 return create_pipeline(device
, vs_nir
, fs_nir
, &vi_state
, &ds_state
,
462 emit_load_depthstencil_clear(struct anv_cmd_buffer
*cmd_buffer
,
464 VkImageAspectFlags aspects
,
465 VkClearDepthStencilValue clear_value
)
467 struct anv_device
*device
= cmd_buffer
->device
;
468 VkCommandBuffer cmd_buffer_h
= anv_cmd_buffer_to_handle(cmd_buffer
);
469 const struct anv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
471 const struct depthstencil_clear_vattrs vertex_data
[3] = {
474 .position
= { 0.0, 0.0 },
478 .position
= { fb
->width
, 0.0 },
482 .position
= { fb
->width
, fb
->height
},
486 struct anv_state state
=
487 anv_cmd_buffer_emit_dynamic(cmd_buffer
, vertex_data
, sizeof(vertex_data
), 16);
489 struct anv_buffer vertex_buffer
= {
491 .size
= sizeof(vertex_data
),
492 .bo
= &device
->dynamic_state_block_pool
.bo
,
493 .offset
= state
.offset
,
496 anv_cmd_buffer_begin_subpass(cmd_buffer
,
497 &(struct anv_subpass
) {
499 .depth_stencil_attachment
= attachment
,
502 ANV_CALL(CmdSetViewport
)(cmd_buffer_h
, 1,
508 .height
= fb
->height
,
510 /* Ignored when clearing only stencil. */
511 .minDepth
= clear_value
.depth
,
512 .maxDepth
= clear_value
.depth
,
516 ANV_CALL(CmdSetScissor
)(cmd_buffer_h
, 1,
520 .extent
= { fb
->width
, fb
->height
},
524 if (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
525 ANV_CALL(CmdSetStencilReference
)(cmd_buffer_h
, VK_STENCIL_FACE_FRONT_BIT
,
526 clear_value
.stencil
);
529 ANV_CALL(CmdBindVertexBuffers
)(cmd_buffer_h
, 0, 1,
530 (VkBuffer
[]) { anv_buffer_to_handle(&vertex_buffer
) },
531 (VkDeviceSize
[]) { 0 });
533 struct anv_pipeline
*pipeline
;
535 case VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
:
536 pipeline
= device
->meta_state
.clear
.depthstencil_pipeline
;
538 case VK_IMAGE_ASPECT_DEPTH_BIT
:
539 pipeline
= device
->meta_state
.clear
.depth_only_pipeline
;
541 case VK_IMAGE_ASPECT_STENCIL_BIT
:
542 pipeline
= device
->meta_state
.clear
.stencil_only_pipeline
;
545 unreachable("expected depth or stencil aspect");
548 if (cmd_buffer
->state
.pipeline
!= pipeline
) {
549 ANV_CALL(CmdBindPipeline
)(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
550 anv_pipeline_to_handle(pipeline
));
553 ANV_CALL(CmdDraw
)(cmd_buffer_h
, 3, 1, 0, 0);
557 init_depthstencil_pipelines(struct anv_device
*device
)
559 device
->meta_state
.clear
.depth_only_pipeline
=
560 create_depthstencil_pipeline(device
, VK_IMAGE_ASPECT_DEPTH_BIT
);
562 device
->meta_state
.clear
.stencil_only_pipeline
=
563 create_depthstencil_pipeline(device
, VK_IMAGE_ASPECT_STENCIL_BIT
);
565 device
->meta_state
.clear
.depthstencil_pipeline
=
566 create_depthstencil_pipeline(device
, VK_IMAGE_ASPECT_DEPTH_BIT
|
567 VK_IMAGE_ASPECT_STENCIL_BIT
);
571 anv_device_init_meta_clear_state(struct anv_device
*device
)
573 init_color_pipeline(device
);
574 init_depthstencil_pipelines(device
);
578 anv_device_finish_meta_clear_state(struct anv_device
*device
)
580 VkDevice device_h
= anv_device_to_handle(device
);
582 ANV_CALL(DestroyPipeline
)(device_h
,
583 anv_pipeline_to_handle(device
->meta_state
.clear
.color_pipeline
),
585 ANV_CALL(DestroyPipeline
)(device_h
,
586 anv_pipeline_to_handle(device
->meta_state
.clear
.depth_only_pipeline
),
588 ANV_CALL(DestroyPipeline
)(device_h
,
589 anv_pipeline_to_handle(device
->meta_state
.clear
.stencil_only_pipeline
),
591 ANV_CALL(DestroyPipeline
)(device_h
,
592 anv_pipeline_to_handle(device
->meta_state
.clear
.depthstencil_pipeline
),
597 anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer
*cmd_buffer
,
598 struct anv_render_pass
*pass
,
599 const VkClearValue
*clear_values
)
601 struct anv_meta_saved_state saved_state
;
603 /* Figure out whether or not we actually need to clear anything to avoid
604 * trashing state when clearing is a no-op.
606 bool needs_clear
= false;
607 for (uint32_t a
= 0; a
< pass
->attachment_count
; ++a
) {
608 struct anv_render_pass_attachment
*att
= &pass
->attachments
[a
];
610 if (anv_format_is_color(att
->format
)) {
611 if (att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
616 if ((att
->format
->depth_format
&&
617 att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) ||
618 (att
->format
->has_stencil
&&
619 att
->stencil_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
)) {
629 meta_clear_begin(&saved_state
, cmd_buffer
);
631 for (uint32_t a
= 0; a
< pass
->attachment_count
; ++a
) {
632 struct anv_render_pass_attachment
*att
= &pass
->attachments
[a
];
634 if (anv_format_is_color(att
->format
)) {
635 if (att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
636 emit_load_color_clear(cmd_buffer
, a
, clear_values
[a
].color
);
639 VkImageAspectFlags clear_aspects
= 0;
641 if (att
->format
->depth_format
&&
642 att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
643 clear_aspects
|= VK_IMAGE_ASPECT_DEPTH_BIT
;
646 if (att
->format
->has_stencil
&&
647 att
->stencil_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
648 clear_aspects
|= VK_IMAGE_ASPECT_STENCIL_BIT
;
652 emit_load_depthstencil_clear(cmd_buffer
, a
, clear_aspects
,
653 clear_values
[a
].depthStencil
);
658 meta_clear_end(&saved_state
, cmd_buffer
);
661 void anv_CmdClearColorImage(
662 VkCommandBuffer commandBuffer
,
664 VkImageLayout imageLayout
,
665 const VkClearColorValue
* pColor
,
667 const VkImageSubresourceRange
* pRanges
)
669 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
670 ANV_FROM_HANDLE(anv_image
, image
, _image
);
671 struct anv_meta_saved_state saved_state
;
673 meta_clear_begin(&saved_state
, cmd_buffer
);
675 for (uint32_t r
= 0; r
< rangeCount
; r
++) {
676 for (uint32_t l
= 0; l
< pRanges
[r
].levelCount
; l
++) {
677 for (uint32_t s
= 0; s
< pRanges
[r
].layerCount
; s
++) {
678 struct anv_image_view iview
;
679 anv_image_view_init(&iview
, cmd_buffer
->device
,
680 &(VkImageViewCreateInfo
) {
681 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
683 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
684 .format
= image
->format
->vk_format
,
685 .subresourceRange
= {
686 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
687 .baseMipLevel
= pRanges
[r
].baseMipLevel
+ l
,
689 .baseArrayLayer
= pRanges
[r
].baseArrayLayer
+ s
,
696 anv_CreateFramebuffer(anv_device_to_handle(cmd_buffer
->device
),
697 &(VkFramebufferCreateInfo
) {
698 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
699 .attachmentCount
= 1,
700 .pAttachments
= (VkImageView
[]) {
701 anv_image_view_to_handle(&iview
),
703 .width
= iview
.extent
.width
,
704 .height
= iview
.extent
.height
,
706 }, &cmd_buffer
->pool
->alloc
, &fb
);
709 anv_CreateRenderPass(anv_device_to_handle(cmd_buffer
->device
),
710 &(VkRenderPassCreateInfo
) {
711 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
712 .attachmentCount
= 1,
713 .pAttachments
= &(VkAttachmentDescription
) {
714 .format
= iview
.format
->vk_format
,
715 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
716 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
717 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
718 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
721 .pSubpasses
= &(VkSubpassDescription
) {
722 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
723 .inputAttachmentCount
= 0,
724 .colorAttachmentCount
= 1,
725 .pColorAttachments
= &(VkAttachmentReference
) {
727 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
729 .pResolveAttachments
= NULL
,
730 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
731 .attachment
= VK_ATTACHMENT_UNUSED
,
732 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
734 .preserveAttachmentCount
= 1,
735 .pPreserveAttachments
= &(VkAttachmentReference
) {
737 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
740 .dependencyCount
= 0,
741 }, &cmd_buffer
->pool
->alloc
, &pass
);
743 ANV_CALL(CmdBeginRenderPass
)(anv_cmd_buffer_to_handle(cmd_buffer
),
744 &(VkRenderPassBeginInfo
) {
745 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
749 .width
= iview
.extent
.width
,
750 .height
= iview
.extent
.height
,
755 .clearValueCount
= 1,
756 .pClearValues
= (VkClearValue
[]) {
757 { .color
= *pColor
},
759 }, VK_SUBPASS_CONTENTS_INLINE
);
761 ANV_CALL(CmdEndRenderPass
)(anv_cmd_buffer_to_handle(cmd_buffer
));
763 /* XXX: We're leaking the render pass and framebuffer */
768 meta_clear_end(&saved_state
, cmd_buffer
);
771 void anv_CmdClearDepthStencilImage(
772 VkCommandBuffer commandBuffer
,
774 VkImageLayout imageLayout
,
775 const VkClearDepthStencilValue
* pDepthStencil
,
777 const VkImageSubresourceRange
* pRanges
)
782 void anv_CmdClearAttachments(
783 VkCommandBuffer commandBuffer
,
784 uint32_t attachmentCount
,
785 const VkClearAttachment
* pAttachments
,
787 const VkClearRect
* pRects
)