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_private.h"
27 #include "glsl/nir/nir_builder.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
, NULL
, MESA_SHADER_VERTEX
, NULL
);
70 nir_builder_init_simple_shader(&fs_b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
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
;
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
,
123 struct anv_pipeline
**pipeline
)
125 VkDevice device_h
= anv_device_to_handle(device
);
128 struct anv_shader_module vs_m
= { .nir
= vs_nir
};
129 struct anv_shader_module fs_m
= { .nir
= fs_nir
};
131 VkPipeline pipeline_h
;
132 result
= anv_graphics_pipeline_create(device_h
,
134 &(VkGraphicsPipelineCreateInfo
) {
135 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
137 .pStages
= (VkPipelineShaderStageCreateInfo
[]) {
139 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
140 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
141 .module
= anv_shader_module_to_handle(&vs_m
),
145 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
146 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
147 .module
= anv_shader_module_to_handle(&fs_m
),
151 .pVertexInputState
= vi_state
,
152 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
153 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
154 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
155 .primitiveRestartEnable
= false,
157 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
158 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
160 .pViewports
= NULL
, /* dynamic */
162 .pScissors
= NULL
, /* dynamic */
164 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
165 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
166 .rasterizerDiscardEnable
= false,
167 .polygonMode
= VK_POLYGON_MODE_FILL
,
168 .cullMode
= VK_CULL_MODE_NONE
,
169 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
,
170 .depthBiasEnable
= false,
172 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
173 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
174 .rasterizationSamples
= 1, /* FINISHME: Multisampling */
175 .sampleShadingEnable
= false,
176 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
177 .alphaToCoverageEnable
= false,
178 .alphaToOneEnable
= false,
180 .pDepthStencilState
= ds_state
,
181 .pColorBlendState
= cb_state
,
182 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
183 /* The meta clear pipeline declares all state as dynamic.
184 * As a consequence, vkCmdBindPipeline writes no dynamic state
185 * to the cmd buffer. Therefore, at the end of the meta clear,
186 * we need only restore dynamic state was vkCmdSet.
188 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
189 .dynamicStateCount
= 9,
190 .pDynamicStates
= (VkDynamicState
[]) {
191 VK_DYNAMIC_STATE_VIEWPORT
,
192 VK_DYNAMIC_STATE_SCISSOR
,
193 VK_DYNAMIC_STATE_LINE_WIDTH
,
194 VK_DYNAMIC_STATE_DEPTH_BIAS
,
195 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
196 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
197 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
198 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
199 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
203 .renderPass
= anv_render_pass_to_handle(&anv_meta_dummy_renderpass
),
206 &(struct anv_graphics_pipeline_create_info
) {
207 .use_repclear
= true,
208 .disable_viewport
= true,
218 *pipeline
= anv_pipeline_from_handle(pipeline_h
);
224 init_color_pipeline(struct anv_device
*device
)
226 struct nir_shader
*vs_nir
;
227 struct nir_shader
*fs_nir
;
228 build_color_shaders(&vs_nir
, &fs_nir
);
230 const VkPipelineVertexInputStateCreateInfo vi_state
= {
231 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
232 .vertexBindingDescriptionCount
= 1,
233 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
236 .stride
= sizeof(struct color_clear_vattrs
),
237 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
240 .vertexAttributeDescriptionCount
= 3,
241 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
246 .format
= VK_FORMAT_R32G32B32A32_UINT
,
247 .offset
= offsetof(struct color_clear_vattrs
, vue_header
),
253 .format
= VK_FORMAT_R32G32_SFLOAT
,
254 .offset
= offsetof(struct color_clear_vattrs
, position
),
260 .format
= VK_FORMAT_R32G32B32A32_SFLOAT
,
261 .offset
= offsetof(struct color_clear_vattrs
, color
),
266 const VkPipelineDepthStencilStateCreateInfo ds_state
= {
267 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
268 .depthTestEnable
= false,
269 .depthWriteEnable
= false,
270 .depthBoundsTestEnable
= false,
271 .stencilTestEnable
= false,
274 const VkPipelineColorBlendStateCreateInfo cb_state
= {
275 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
276 .logicOpEnable
= false,
277 .attachmentCount
= 1,
278 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
280 .blendEnable
= false,
281 .colorWriteMask
= VK_COLOR_COMPONENT_A_BIT
|
282 VK_COLOR_COMPONENT_R_BIT
|
283 VK_COLOR_COMPONENT_G_BIT
|
284 VK_COLOR_COMPONENT_B_BIT
,
290 create_pipeline(device
, vs_nir
, fs_nir
, &vi_state
, &ds_state
,
292 &device
->meta_state
.clear
.color_pipeline
);
296 emit_load_color_clear(struct anv_cmd_buffer
*cmd_buffer
,
298 VkClearColorValue clear_value
)
300 struct anv_device
*device
= cmd_buffer
->device
;
301 VkCommandBuffer cmd_buffer_h
= anv_cmd_buffer_to_handle(cmd_buffer
);
302 const struct anv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
303 VkPipeline pipeline_h
=
304 anv_pipeline_to_handle(device
->meta_state
.clear
.color_pipeline
);
306 const struct color_clear_vattrs vertex_data
[3] = {
309 .position
= { 0.0, 0.0 },
310 .color
= clear_value
,
314 .position
= { fb
->width
, 0.0 },
315 .color
= clear_value
,
319 .position
= { fb
->width
, fb
->height
},
320 .color
= clear_value
,
324 struct anv_state state
=
325 anv_cmd_buffer_emit_dynamic(cmd_buffer
, vertex_data
, sizeof(vertex_data
), 16);
327 struct anv_buffer vertex_buffer
= {
329 .size
= sizeof(vertex_data
),
330 .bo
= &device
->dynamic_state_block_pool
.bo
,
331 .offset
= state
.offset
,
334 anv_cmd_buffer_begin_subpass(cmd_buffer
,
335 &(struct anv_subpass
) {
337 .color_attachments
= (uint32_t[]) { attachment
},
338 .depth_stencil_attachment
= VK_ATTACHMENT_UNUSED
,
341 ANV_CALL(CmdSetViewport
)(cmd_buffer_h
, 1,
347 .height
= fb
->height
,
353 ANV_CALL(CmdSetScissor
)(cmd_buffer_h
, 1,
357 .extent
= { fb
->width
, fb
->height
},
361 ANV_CALL(CmdBindVertexBuffers
)(cmd_buffer_h
, 0, 1,
362 (VkBuffer
[]) { anv_buffer_to_handle(&vertex_buffer
) },
363 (VkDeviceSize
[]) { 0 });
365 if (cmd_buffer
->state
.pipeline
!= device
->meta_state
.clear
.color_pipeline
) {
366 ANV_CALL(CmdBindPipeline
)(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
370 ANV_CALL(CmdDraw
)(cmd_buffer_h
, 3, 1, 0, 0);
375 build_depthstencil_shaders(struct nir_shader
**out_vs
,
376 struct nir_shader
**out_fs
)
381 nir_builder_init_simple_shader(&vs_b
, NULL
, MESA_SHADER_VERTEX
, NULL
);
382 nir_builder_init_simple_shader(&fs_b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
384 const struct glsl_type
*position_type
= glsl_vec4_type();
386 nir_variable
*vs_in_pos
=
387 nir_variable_create(vs_b
.shader
, nir_var_shader_in
, position_type
,
389 vs_in_pos
->data
.location
= VERT_ATTRIB_GENERIC0
;
391 nir_variable
*vs_out_pos
=
392 nir_variable_create(vs_b
.shader
, nir_var_shader_out
, position_type
,
394 vs_out_pos
->data
.location
= VARYING_SLOT_POS
;
396 nir_copy_var(&vs_b
, vs_out_pos
, vs_in_pos
);
398 *out_vs
= vs_b
.shader
;
399 *out_fs
= fs_b
.shader
;
403 create_depthstencil_pipeline(struct anv_device
*device
,
404 VkImageAspectFlags aspects
,
405 struct anv_pipeline
**pipeline
)
407 struct nir_shader
*vs_nir
;
408 struct nir_shader
*fs_nir
;
410 build_depthstencil_shaders(&vs_nir
, &fs_nir
);
412 const VkPipelineVertexInputStateCreateInfo vi_state
= {
413 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
414 .vertexBindingDescriptionCount
= 1,
415 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
418 .stride
= sizeof(struct depthstencil_clear_vattrs
),
419 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
422 .vertexAttributeDescriptionCount
= 2,
423 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
428 .format
= VK_FORMAT_R32G32B32A32_UINT
,
429 .offset
= offsetof(struct depthstencil_clear_vattrs
, vue_header
),
435 .format
= VK_FORMAT_R32G32_SFLOAT
,
436 .offset
= offsetof(struct depthstencil_clear_vattrs
, position
),
441 const VkPipelineDepthStencilStateCreateInfo ds_state
= {
442 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
443 .depthTestEnable
= (aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
),
444 .depthCompareOp
= VK_COMPARE_OP_ALWAYS
,
445 .depthWriteEnable
= (aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
),
446 .depthBoundsTestEnable
= false,
447 .stencilTestEnable
= (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
),
449 .passOp
= VK_STENCIL_OP_REPLACE
,
450 .compareOp
= VK_COMPARE_OP_ALWAYS
,
451 .writeMask
= UINT32_MAX
,
452 .reference
= 0, /* dynamic */
454 .back
= { 0 /* dont care */ },
457 const VkPipelineColorBlendStateCreateInfo cb_state
= {
458 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
459 .logicOpEnable
= false,
460 .attachmentCount
= 0,
461 .pAttachments
= NULL
,
464 return create_pipeline(device
, vs_nir
, fs_nir
, &vi_state
, &ds_state
,
465 &cb_state
, NULL
, pipeline
);
469 emit_load_depthstencil_clear(struct anv_cmd_buffer
*cmd_buffer
,
471 VkImageAspectFlags aspects
,
472 VkClearDepthStencilValue clear_value
)
474 struct anv_device
*device
= cmd_buffer
->device
;
475 VkCommandBuffer cmd_buffer_h
= anv_cmd_buffer_to_handle(cmd_buffer
);
476 const struct anv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
478 const struct depthstencil_clear_vattrs vertex_data
[3] = {
481 .position
= { 0.0, 0.0 },
485 .position
= { fb
->width
, 0.0 },
489 .position
= { fb
->width
, fb
->height
},
493 struct anv_state state
=
494 anv_cmd_buffer_emit_dynamic(cmd_buffer
, vertex_data
, sizeof(vertex_data
), 16);
496 struct anv_buffer vertex_buffer
= {
498 .size
= sizeof(vertex_data
),
499 .bo
= &device
->dynamic_state_block_pool
.bo
,
500 .offset
= state
.offset
,
503 anv_cmd_buffer_begin_subpass(cmd_buffer
,
504 &(struct anv_subpass
) {
506 .depth_stencil_attachment
= attachment
,
509 ANV_CALL(CmdSetViewport
)(cmd_buffer_h
, 1,
515 .height
= fb
->height
,
517 /* Ignored when clearing only stencil. */
518 .minDepth
= clear_value
.depth
,
519 .maxDepth
= clear_value
.depth
,
523 ANV_CALL(CmdSetScissor
)(cmd_buffer_h
, 1,
527 .extent
= { fb
->width
, fb
->height
},
531 if (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
532 ANV_CALL(CmdSetStencilReference
)(cmd_buffer_h
, VK_STENCIL_FACE_FRONT_BIT
,
533 clear_value
.stencil
);
536 ANV_CALL(CmdBindVertexBuffers
)(cmd_buffer_h
, 0, 1,
537 (VkBuffer
[]) { anv_buffer_to_handle(&vertex_buffer
) },
538 (VkDeviceSize
[]) { 0 });
540 struct anv_pipeline
*pipeline
;
542 case VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
:
543 pipeline
= device
->meta_state
.clear
.depthstencil_pipeline
;
545 case VK_IMAGE_ASPECT_DEPTH_BIT
:
546 pipeline
= device
->meta_state
.clear
.depth_only_pipeline
;
548 case VK_IMAGE_ASPECT_STENCIL_BIT
:
549 pipeline
= device
->meta_state
.clear
.stencil_only_pipeline
;
552 unreachable("expected depth or stencil aspect");
555 if (cmd_buffer
->state
.pipeline
!= pipeline
) {
556 ANV_CALL(CmdBindPipeline
)(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
557 anv_pipeline_to_handle(pipeline
));
560 ANV_CALL(CmdDraw
)(cmd_buffer_h
, 3, 1, 0, 0);
564 init_depthstencil_pipelines(struct anv_device
*device
)
567 struct anv_meta_state
*state
= &device
->meta_state
;
570 create_depthstencil_pipeline(device
, VK_IMAGE_ASPECT_DEPTH_BIT
,
571 &state
->clear
.depth_only_pipeline
);
572 if (result
!= VK_SUCCESS
)
576 create_depthstencil_pipeline(device
, VK_IMAGE_ASPECT_STENCIL_BIT
,
577 &state
->clear
.stencil_only_pipeline
);
578 if (result
!= VK_SUCCESS
)
579 goto fail_depth_only
;
582 create_depthstencil_pipeline(device
,
583 VK_IMAGE_ASPECT_DEPTH_BIT
|
584 VK_IMAGE_ASPECT_STENCIL_BIT
,
585 &state
->clear
.depthstencil_pipeline
);
586 if (result
!= VK_SUCCESS
)
587 goto fail_stencil_only
;
592 anv_DestroyPipeline(anv_device_to_handle(device
),
593 anv_pipeline_to_handle(state
->clear
.stencil_only_pipeline
),
596 anv_DestroyPipeline(anv_device_to_handle(device
),
597 anv_pipeline_to_handle(state
->clear
.depth_only_pipeline
),
604 anv_device_init_meta_clear_state(struct anv_device
*device
)
608 result
= init_color_pipeline(device
);
609 if (result
!= VK_SUCCESS
)
612 result
= init_depthstencil_pipelines(device
);
613 if (result
!= VK_SUCCESS
)
614 goto fail_color_pipeline
;
619 anv_DestroyPipeline(anv_device_to_handle(device
),
620 anv_pipeline_to_handle(device
->meta_state
.clear
.color_pipeline
),
627 anv_device_finish_meta_clear_state(struct anv_device
*device
)
629 VkDevice device_h
= anv_device_to_handle(device
);
631 ANV_CALL(DestroyPipeline
)(device_h
,
632 anv_pipeline_to_handle(device
->meta_state
.clear
.color_pipeline
),
634 ANV_CALL(DestroyPipeline
)(device_h
,
635 anv_pipeline_to_handle(device
->meta_state
.clear
.depth_only_pipeline
),
637 ANV_CALL(DestroyPipeline
)(device_h
,
638 anv_pipeline_to_handle(device
->meta_state
.clear
.stencil_only_pipeline
),
640 ANV_CALL(DestroyPipeline
)(device_h
,
641 anv_pipeline_to_handle(device
->meta_state
.clear
.depthstencil_pipeline
),
646 anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer
*cmd_buffer
,
647 struct anv_render_pass
*pass
,
648 const VkClearValue
*clear_values
)
650 struct anv_meta_saved_state saved_state
;
652 /* Figure out whether or not we actually need to clear anything to avoid
653 * trashing state when clearing is a no-op.
655 bool needs_clear
= false;
656 for (uint32_t a
= 0; a
< pass
->attachment_count
; ++a
) {
657 struct anv_render_pass_attachment
*att
= &pass
->attachments
[a
];
659 if (anv_format_is_color(att
->format
)) {
660 if (att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
665 if ((att
->format
->depth_format
&&
666 att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) ||
667 (att
->format
->has_stencil
&&
668 att
->stencil_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
)) {
678 meta_clear_begin(&saved_state
, cmd_buffer
);
680 for (uint32_t a
= 0; a
< pass
->attachment_count
; ++a
) {
681 struct anv_render_pass_attachment
*att
= &pass
->attachments
[a
];
683 if (anv_format_is_color(att
->format
)) {
684 if (att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
685 emit_load_color_clear(cmd_buffer
, a
, clear_values
[a
].color
);
688 VkImageAspectFlags clear_aspects
= 0;
690 if (att
->format
->depth_format
&&
691 att
->load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
692 clear_aspects
|= VK_IMAGE_ASPECT_DEPTH_BIT
;
695 if (att
->format
->has_stencil
&&
696 att
->stencil_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
697 clear_aspects
|= VK_IMAGE_ASPECT_STENCIL_BIT
;
701 emit_load_depthstencil_clear(cmd_buffer
, a
, clear_aspects
,
702 clear_values
[a
].depthStencil
);
707 meta_clear_end(&saved_state
, cmd_buffer
);
710 void anv_CmdClearColorImage(
711 VkCommandBuffer commandBuffer
,
713 VkImageLayout imageLayout
,
714 const VkClearColorValue
* pColor
,
716 const VkImageSubresourceRange
* pRanges
)
718 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
719 ANV_FROM_HANDLE(anv_image
, image
, _image
);
720 struct anv_meta_saved_state saved_state
;
722 meta_clear_begin(&saved_state
, cmd_buffer
);
724 for (uint32_t r
= 0; r
< rangeCount
; r
++) {
725 for (uint32_t l
= 0; l
< pRanges
[r
].levelCount
; l
++) {
726 for (uint32_t s
= 0; s
< pRanges
[r
].layerCount
; s
++) {
727 struct anv_image_view iview
;
728 anv_image_view_init(&iview
, cmd_buffer
->device
,
729 &(VkImageViewCreateInfo
) {
730 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
732 .viewType
= anv_meta_get_view_type(image
),
733 .format
= image
->vk_format
,
734 .subresourceRange
= {
735 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
736 .baseMipLevel
= pRanges
[r
].baseMipLevel
+ l
,
738 .baseArrayLayer
= pRanges
[r
].baseArrayLayer
+ s
,
745 anv_CreateFramebuffer(anv_device_to_handle(cmd_buffer
->device
),
746 &(VkFramebufferCreateInfo
) {
747 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
748 .attachmentCount
= 1,
749 .pAttachments
= (VkImageView
[]) {
750 anv_image_view_to_handle(&iview
),
752 .width
= iview
.extent
.width
,
753 .height
= iview
.extent
.height
,
755 }, &cmd_buffer
->pool
->alloc
, &fb
);
758 anv_CreateRenderPass(anv_device_to_handle(cmd_buffer
->device
),
759 &(VkRenderPassCreateInfo
) {
760 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
761 .attachmentCount
= 1,
762 .pAttachments
= &(VkAttachmentDescription
) {
763 .format
= iview
.vk_format
,
764 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
765 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
766 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
767 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
770 .pSubpasses
= &(VkSubpassDescription
) {
771 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
772 .inputAttachmentCount
= 0,
773 .colorAttachmentCount
= 1,
774 .pColorAttachments
= &(VkAttachmentReference
) {
776 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
778 .pResolveAttachments
= NULL
,
779 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
780 .attachment
= VK_ATTACHMENT_UNUSED
,
781 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
783 .preserveAttachmentCount
= 1,
784 .pPreserveAttachments
= &(VkAttachmentReference
) {
786 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
789 .dependencyCount
= 0,
790 }, &cmd_buffer
->pool
->alloc
, &pass
);
792 ANV_CALL(CmdBeginRenderPass
)(anv_cmd_buffer_to_handle(cmd_buffer
),
793 &(VkRenderPassBeginInfo
) {
794 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
798 .width
= iview
.extent
.width
,
799 .height
= iview
.extent
.height
,
804 .clearValueCount
= 1,
805 .pClearValues
= (VkClearValue
[]) {
806 { .color
= *pColor
},
808 }, VK_SUBPASS_CONTENTS_INLINE
);
810 ANV_CALL(CmdEndRenderPass
)(anv_cmd_buffer_to_handle(cmd_buffer
));
812 /* XXX: We're leaking the render pass and framebuffer */
817 meta_clear_end(&saved_state
, cmd_buffer
);
820 void anv_CmdClearDepthStencilImage(
821 VkCommandBuffer commandBuffer
,
823 VkImageLayout imageLayout
,
824 const VkClearDepthStencilValue
* pDepthStencil
,
826 const VkImageSubresourceRange
* pRanges
)
831 void anv_CmdClearAttachments(
832 VkCommandBuffer commandBuffer
,
833 uint32_t attachmentCount
,
834 const VkClearAttachment
* pAttachments
,
836 const VkClearRect
* pRects
)