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
24 #include "radv_meta.h"
25 #include "radv_private.h"
26 #include "nir/nir_builder.h"
28 #include "util/format_rgb9e5.h"
29 #include "vk_format.h"
31 /** Vertex attributes for color clears. */
32 struct color_clear_vattrs
{
33 VkClearColorValue color
;
36 /** Vertex attributes for depthstencil clears. */
37 struct depthstencil_clear_vattrs
{
43 DEPTH_CLEAR_FAST_EXPCLEAR
,
44 DEPTH_CLEAR_FAST_NO_EXPCLEAR
48 build_color_shaders(struct nir_shader
**out_vs
,
49 struct nir_shader
**out_fs
,
55 nir_builder_init_simple_shader(&vs_b
, NULL
, MESA_SHADER_VERTEX
, NULL
);
56 nir_builder_init_simple_shader(&fs_b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
58 vs_b
.shader
->info
->name
= ralloc_strdup(vs_b
.shader
, "meta_clear_color_vs");
59 fs_b
.shader
->info
->name
= ralloc_strdup(fs_b
.shader
, "meta_clear_color_fs");
61 const struct glsl_type
*position_type
= glsl_vec4_type();
62 const struct glsl_type
*color_type
= glsl_vec4_type();
64 nir_variable
*vs_out_pos
=
65 nir_variable_create(vs_b
.shader
, nir_var_shader_out
, position_type
,
67 vs_out_pos
->data
.location
= VARYING_SLOT_POS
;
69 nir_variable
*vs_in_color
=
70 nir_variable_create(vs_b
.shader
, nir_var_shader_in
, color_type
,
72 vs_in_color
->data
.location
= VERT_ATTRIB_GENERIC0
;
74 nir_variable
*vs_out_color
=
75 nir_variable_create(vs_b
.shader
, nir_var_shader_out
, color_type
,
77 vs_out_color
->data
.location
= VARYING_SLOT_VAR0
;
78 vs_out_color
->data
.interpolation
= INTERP_MODE_FLAT
;
80 nir_variable
*fs_in_color
=
81 nir_variable_create(fs_b
.shader
, nir_var_shader_in
, color_type
,
83 fs_in_color
->data
.location
= vs_out_color
->data
.location
;
84 fs_in_color
->data
.interpolation
= vs_out_color
->data
.interpolation
;
86 nir_variable
*fs_out_color
=
87 nir_variable_create(fs_b
.shader
, nir_var_shader_out
, color_type
,
89 fs_out_color
->data
.location
= FRAG_RESULT_DATA0
+ frag_output
;
91 nir_ssa_def
*outvec
= radv_meta_gen_rect_vertices(&vs_b
);
93 nir_store_var(&vs_b
, vs_out_pos
, outvec
, 0xf);
94 nir_copy_var(&vs_b
, vs_out_color
, vs_in_color
);
95 nir_copy_var(&fs_b
, fs_out_color
, fs_in_color
);
97 const struct glsl_type
*layer_type
= glsl_int_type();
98 nir_variable
*vs_out_layer
=
99 nir_variable_create(vs_b
.shader
, nir_var_shader_out
, layer_type
,
101 vs_out_layer
->data
.location
= VARYING_SLOT_LAYER
;
102 vs_out_layer
->data
.interpolation
= INTERP_MODE_FLAT
;
103 nir_ssa_def
*inst_id
= nir_load_system_value(&vs_b
, nir_intrinsic_load_instance_id
, 0);
105 nir_store_var(&vs_b
, vs_out_layer
, inst_id
, 0x1);
107 *out_vs
= vs_b
.shader
;
108 *out_fs
= fs_b
.shader
;
112 create_pipeline(struct radv_device
*device
,
113 struct radv_render_pass
*render_pass
,
115 struct nir_shader
*vs_nir
,
116 struct nir_shader
*fs_nir
,
117 const VkPipelineVertexInputStateCreateInfo
*vi_state
,
118 const VkPipelineDepthStencilStateCreateInfo
*ds_state
,
119 const VkPipelineColorBlendStateCreateInfo
*cb_state
,
120 const struct radv_graphics_pipeline_create_info
*extra
,
121 const VkAllocationCallbacks
*alloc
,
122 struct radv_pipeline
**pipeline
)
124 VkDevice device_h
= radv_device_to_handle(device
);
127 struct radv_shader_module vs_m
= { .nir
= vs_nir
};
128 struct radv_shader_module fs_m
= { .nir
= fs_nir
};
130 VkPipeline pipeline_h
= VK_NULL_HANDLE
;
131 result
= radv_graphics_pipeline_create(device_h
,
132 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
133 &(VkGraphicsPipelineCreateInfo
) {
134 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
135 .stageCount
= fs_nir
? 2 : 1,
136 .pStages
= (VkPipelineShaderStageCreateInfo
[]) {
138 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
139 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
140 .module
= radv_shader_module_to_handle(&vs_m
),
144 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
145 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
146 .module
= radv_shader_module_to_handle(&fs_m
),
150 .pVertexInputState
= vi_state
,
151 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
152 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
153 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
154 .primitiveRestartEnable
= false,
156 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
157 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
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
= samples
,
172 .sampleShadingEnable
= false,
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
= 8,
187 .pDynamicStates
= (VkDynamicState
[]) {
188 /* Everything except stencil write mask */
189 VK_DYNAMIC_STATE_VIEWPORT
,
190 VK_DYNAMIC_STATE_SCISSOR
,
191 VK_DYNAMIC_STATE_LINE_WIDTH
,
192 VK_DYNAMIC_STATE_DEPTH_BIAS
,
193 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
194 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
195 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
196 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
200 .renderPass
= radv_render_pass_to_handle(render_pass
),
210 *pipeline
= radv_pipeline_from_handle(pipeline_h
);
216 create_color_renderpass(struct radv_device
*device
,
221 return radv_CreateRenderPass(radv_device_to_handle(device
),
222 &(VkRenderPassCreateInfo
) {
223 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
224 .attachmentCount
= 1,
225 .pAttachments
= &(VkAttachmentDescription
) {
228 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
229 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
230 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
231 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
234 .pSubpasses
= &(VkSubpassDescription
) {
235 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
236 .inputAttachmentCount
= 0,
237 .colorAttachmentCount
= 1,
238 .pColorAttachments
= &(VkAttachmentReference
) {
240 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
242 .pResolveAttachments
= NULL
,
243 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
244 .attachment
= VK_ATTACHMENT_UNUSED
,
245 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
247 .preserveAttachmentCount
= 1,
248 .pPreserveAttachments
= (uint32_t[]) { 0 },
250 .dependencyCount
= 0,
251 }, &device
->meta_state
.alloc
, pass
);
255 create_color_pipeline(struct radv_device
*device
,
257 uint32_t frag_output
,
258 struct radv_pipeline
**pipeline
,
261 struct nir_shader
*vs_nir
;
262 struct nir_shader
*fs_nir
;
264 build_color_shaders(&vs_nir
, &fs_nir
, frag_output
);
266 const VkPipelineVertexInputStateCreateInfo vi_state
= {
267 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
268 .vertexBindingDescriptionCount
= 1,
269 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
272 .stride
= sizeof(struct color_clear_vattrs
),
273 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
276 .vertexAttributeDescriptionCount
= 1,
277 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
282 .format
= VK_FORMAT_R32G32B32A32_SFLOAT
,
288 const VkPipelineDepthStencilStateCreateInfo ds_state
= {
289 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
290 .depthTestEnable
= false,
291 .depthWriteEnable
= false,
292 .depthBoundsTestEnable
= false,
293 .stencilTestEnable
= false,
296 VkPipelineColorBlendAttachmentState blend_attachment_state
[MAX_RTS
] = { 0 };
297 blend_attachment_state
[frag_output
] = (VkPipelineColorBlendAttachmentState
) {
298 .blendEnable
= false,
299 .colorWriteMask
= VK_COLOR_COMPONENT_A_BIT
|
300 VK_COLOR_COMPONENT_R_BIT
|
301 VK_COLOR_COMPONENT_G_BIT
|
302 VK_COLOR_COMPONENT_B_BIT
,
305 const VkPipelineColorBlendStateCreateInfo cb_state
= {
306 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
307 .logicOpEnable
= false,
308 .attachmentCount
= MAX_RTS
,
309 .pAttachments
= blend_attachment_state
313 struct radv_graphics_pipeline_create_info extra
= {
314 .use_rectlist
= true,
316 result
= create_pipeline(device
, radv_render_pass_from_handle(pass
),
317 samples
, vs_nir
, fs_nir
, &vi_state
, &ds_state
, &cb_state
,
318 &extra
, &device
->meta_state
.alloc
, pipeline
);
324 destroy_pipeline(struct radv_device
*device
, struct radv_pipeline
*pipeline
)
329 radv_DestroyPipeline(radv_device_to_handle(device
),
330 radv_pipeline_to_handle(pipeline
),
331 &device
->meta_state
.alloc
);
336 destroy_render_pass(struct radv_device
*device
, VkRenderPass renderpass
)
338 radv_DestroyRenderPass(radv_device_to_handle(device
), renderpass
,
339 &device
->meta_state
.alloc
);
343 radv_device_finish_meta_clear_state(struct radv_device
*device
)
345 struct radv_meta_state
*state
= &device
->meta_state
;
347 for (uint32_t i
= 0; i
< ARRAY_SIZE(state
->clear
); ++i
) {
348 for (uint32_t j
= 0; j
< ARRAY_SIZE(state
->clear
[i
].color_pipelines
); ++j
) {
349 destroy_pipeline(device
, state
->clear
[i
].color_pipelines
[j
]);
350 destroy_render_pass(device
, state
->clear
[i
].render_pass
[j
]);
353 for (uint32_t j
= 0; j
< NUM_DEPTH_CLEAR_PIPELINES
; j
++) {
354 destroy_pipeline(device
, state
->clear
[i
].depth_only_pipeline
[j
]);
355 destroy_pipeline(device
, state
->clear
[i
].stencil_only_pipeline
[j
]);
356 destroy_pipeline(device
, state
->clear
[i
].depthstencil_pipeline
[j
]);
358 destroy_render_pass(device
, state
->clear
[i
].depthstencil_rp
);
364 emit_color_clear(struct radv_cmd_buffer
*cmd_buffer
,
365 const VkClearAttachment
*clear_att
,
366 const VkClearRect
*clear_rect
)
368 struct radv_device
*device
= cmd_buffer
->device
;
369 const struct radv_subpass
*subpass
= cmd_buffer
->state
.subpass
;
370 const struct radv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
371 const uint32_t subpass_att
= clear_att
->colorAttachment
;
372 const uint32_t pass_att
= subpass
->color_attachments
[subpass_att
].attachment
;
373 const struct radv_image_view
*iview
= fb
->attachments
[pass_att
].attachment
;
374 const uint32_t samples
= iview
->image
->samples
;
375 const uint32_t samples_log2
= ffs(samples
) - 1;
376 unsigned fs_key
= radv_format_meta_fs_key(iview
->vk_format
);
377 struct radv_pipeline
*pipeline
;
378 VkClearColorValue clear_value
= clear_att
->clearValue
.color
;
379 VkCommandBuffer cmd_buffer_h
= radv_cmd_buffer_to_handle(cmd_buffer
);
380 VkPipeline pipeline_h
;
384 radv_finishme("color clears incomplete");
387 pipeline
= device
->meta_state
.clear
[samples_log2
].color_pipelines
[fs_key
];
388 pipeline_h
= radv_pipeline_to_handle(pipeline
);
391 radv_finishme("color clears incomplete");
394 assert(samples_log2
< ARRAY_SIZE(device
->meta_state
.clear
));
396 assert(clear_att
->aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
);
397 assert(clear_att
->colorAttachment
< subpass
->color_count
);
399 const struct color_clear_vattrs vertex_data
[3] = {
401 .color
= clear_value
,
404 .color
= clear_value
,
407 .color
= clear_value
,
411 struct radv_subpass clear_subpass
= {
413 .color_attachments
= (VkAttachmentReference
[]) {
414 subpass
->color_attachments
[clear_att
->colorAttachment
]
416 .depth_stencil_attachment
= (VkAttachmentReference
) { VK_ATTACHMENT_UNUSED
, VK_IMAGE_LAYOUT_UNDEFINED
}
419 radv_cmd_buffer_set_subpass(cmd_buffer
, &clear_subpass
, false);
421 radv_cmd_buffer_upload_data(cmd_buffer
, sizeof(vertex_data
), 16, vertex_data
, &offset
);
422 struct radv_buffer vertex_buffer
= {
424 .size
= sizeof(vertex_data
),
425 .bo
= cmd_buffer
->upload
.upload_bo
,
430 radv_CmdBindVertexBuffers(cmd_buffer_h
, 0, 1,
431 (VkBuffer
[]) { radv_buffer_to_handle(&vertex_buffer
) },
432 (VkDeviceSize
[]) { 0 });
434 if (cmd_buffer
->state
.pipeline
!= pipeline
) {
435 radv_CmdBindPipeline(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
439 radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkViewport
) {
440 .x
= clear_rect
->rect
.offset
.x
,
441 .y
= clear_rect
->rect
.offset
.y
,
442 .width
= clear_rect
->rect
.extent
.width
,
443 .height
= clear_rect
->rect
.extent
.height
,
448 radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &clear_rect
->rect
);
450 radv_CmdDraw(cmd_buffer_h
, 3, clear_rect
->layerCount
, 0, 0);
452 radv_cmd_buffer_set_subpass(cmd_buffer
, subpass
, false);
457 build_depthstencil_shader(struct nir_shader
**out_vs
, struct nir_shader
**out_fs
)
459 nir_builder vs_b
, fs_b
;
461 nir_builder_init_simple_shader(&vs_b
, NULL
, MESA_SHADER_VERTEX
, NULL
);
462 nir_builder_init_simple_shader(&fs_b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
464 vs_b
.shader
->info
->name
= ralloc_strdup(vs_b
.shader
, "meta_clear_depthstencil_vs");
465 fs_b
.shader
->info
->name
= ralloc_strdup(fs_b
.shader
, "meta_clear_depthstencil_fs");
466 const struct glsl_type
*position_out_type
= glsl_vec4_type();
467 const struct glsl_type
*position_type
= glsl_float_type();
469 nir_variable
*vs_in_pos
=
470 nir_variable_create(vs_b
.shader
, nir_var_shader_in
, position_type
,
472 vs_in_pos
->data
.location
= VERT_ATTRIB_GENERIC0
;
474 nir_variable
*vs_out_pos
=
475 nir_variable_create(vs_b
.shader
, nir_var_shader_out
, position_out_type
,
477 vs_out_pos
->data
.location
= VARYING_SLOT_POS
;
479 nir_ssa_def
*outvec
= radv_meta_gen_rect_vertices_comp2(&vs_b
, nir_load_var(&vs_b
, vs_in_pos
));
480 nir_store_var(&vs_b
, vs_out_pos
, outvec
, 0xf);
482 const struct glsl_type
*layer_type
= glsl_int_type();
483 nir_variable
*vs_out_layer
=
484 nir_variable_create(vs_b
.shader
, nir_var_shader_out
, layer_type
,
486 vs_out_layer
->data
.location
= VARYING_SLOT_LAYER
;
487 vs_out_layer
->data
.interpolation
= INTERP_MODE_FLAT
;
488 nir_ssa_def
*inst_id
= nir_load_system_value(&vs_b
, nir_intrinsic_load_instance_id
, 0);
489 nir_store_var(&vs_b
, vs_out_layer
, inst_id
, 0x1);
491 *out_vs
= vs_b
.shader
;
492 *out_fs
= fs_b
.shader
;
496 create_depthstencil_renderpass(struct radv_device
*device
,
498 VkRenderPass
*render_pass
)
500 return radv_CreateRenderPass(radv_device_to_handle(device
),
501 &(VkRenderPassCreateInfo
) {
502 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
503 .attachmentCount
= 1,
504 .pAttachments
= &(VkAttachmentDescription
) {
505 .format
= VK_FORMAT_UNDEFINED
,
507 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
508 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
509 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
510 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
513 .pSubpasses
= &(VkSubpassDescription
) {
514 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
515 .inputAttachmentCount
= 0,
516 .colorAttachmentCount
= 0,
517 .pColorAttachments
= NULL
,
518 .pResolveAttachments
= NULL
,
519 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
521 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
523 .preserveAttachmentCount
= 1,
524 .pPreserveAttachments
= (uint32_t[]) { 0 },
526 .dependencyCount
= 0,
527 }, &device
->meta_state
.alloc
, render_pass
);
531 create_depthstencil_pipeline(struct radv_device
*device
,
532 VkImageAspectFlags aspects
,
535 struct radv_pipeline
**pipeline
,
536 VkRenderPass render_pass
)
538 struct nir_shader
*vs_nir
, *fs_nir
;
540 build_depthstencil_shader(&vs_nir
, &fs_nir
);
542 const VkPipelineVertexInputStateCreateInfo vi_state
= {
543 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
544 .vertexBindingDescriptionCount
= 1,
545 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
548 .stride
= sizeof(struct depthstencil_clear_vattrs
),
549 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
552 .vertexAttributeDescriptionCount
= 1,
553 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
558 .format
= VK_FORMAT_R32_SFLOAT
,
564 const VkPipelineDepthStencilStateCreateInfo ds_state
= {
565 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
566 .depthTestEnable
= (aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
),
567 .depthCompareOp
= VK_COMPARE_OP_ALWAYS
,
568 .depthWriteEnable
= (aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
),
569 .depthBoundsTestEnable
= false,
570 .stencilTestEnable
= (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
),
572 .passOp
= VK_STENCIL_OP_REPLACE
,
573 .compareOp
= VK_COMPARE_OP_ALWAYS
,
574 .writeMask
= UINT32_MAX
,
575 .reference
= 0, /* dynamic */
577 .back
= { 0 /* dont care */ },
580 const VkPipelineColorBlendStateCreateInfo cb_state
= {
581 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
582 .logicOpEnable
= false,
583 .attachmentCount
= 0,
584 .pAttachments
= NULL
,
587 struct radv_graphics_pipeline_create_info extra
= {
588 .use_rectlist
= true,
591 if (aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
592 extra
.db_depth_clear
= index
== DEPTH_CLEAR_SLOW
? false : true;
593 extra
.db_depth_disable_expclear
= index
== DEPTH_CLEAR_FAST_NO_EXPCLEAR
? true : false;
595 if (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
596 extra
.db_stencil_clear
= index
== DEPTH_CLEAR_SLOW
? false : true;
597 extra
.db_stencil_disable_expclear
= index
== DEPTH_CLEAR_FAST_NO_EXPCLEAR
? true : false;
599 result
= create_pipeline(device
, radv_render_pass_from_handle(render_pass
),
600 samples
, vs_nir
, fs_nir
, &vi_state
, &ds_state
, &cb_state
,
601 &extra
, &device
->meta_state
.alloc
, pipeline
);
605 static bool depth_view_can_fast_clear(const struct radv_image_view
*iview
,
606 VkImageLayout layout
,
607 const VkClearRect
*clear_rect
)
609 if (clear_rect
->rect
.offset
.x
|| clear_rect
->rect
.offset
.y
||
610 clear_rect
->rect
.extent
.width
!= iview
->extent
.width
||
611 clear_rect
->rect
.extent
.height
!= iview
->extent
.height
)
613 if (iview
->image
->surface
.htile_size
&&
614 iview
->base_mip
== 0 &&
615 iview
->base_layer
== 0 &&
616 radv_layout_can_expclear(iview
->image
, layout
) &&
617 !radv_image_extent_compare(iview
->image
, &iview
->extent
))
622 static struct radv_pipeline
*
623 pick_depthstencil_pipeline(struct radv_meta_state
*meta_state
,
624 const struct radv_image_view
*iview
,
626 VkImageAspectFlags aspects
,
627 VkImageLayout layout
,
628 const VkClearRect
*clear_rect
,
629 VkClearDepthStencilValue clear_value
)
631 bool fast
= depth_view_can_fast_clear(iview
, layout
, clear_rect
);
632 int index
= DEPTH_CLEAR_SLOW
;
635 /* we don't know the previous clear values, so we always have
636 * the NO_EXPCLEAR path */
637 index
= DEPTH_CLEAR_FAST_NO_EXPCLEAR
;
641 case VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
:
642 return meta_state
->clear
[samples_log2
].depthstencil_pipeline
[index
];
643 case VK_IMAGE_ASPECT_DEPTH_BIT
:
644 return meta_state
->clear
[samples_log2
].depth_only_pipeline
[index
];
645 case VK_IMAGE_ASPECT_STENCIL_BIT
:
646 return meta_state
->clear
[samples_log2
].stencil_only_pipeline
[index
];
648 unreachable("expected depth or stencil aspect");
652 emit_depthstencil_clear(struct radv_cmd_buffer
*cmd_buffer
,
653 const VkClearAttachment
*clear_att
,
654 const VkClearRect
*clear_rect
)
656 struct radv_device
*device
= cmd_buffer
->device
;
657 struct radv_meta_state
*meta_state
= &device
->meta_state
;
658 const struct radv_subpass
*subpass
= cmd_buffer
->state
.subpass
;
659 const struct radv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
660 const uint32_t pass_att
= subpass
->depth_stencil_attachment
.attachment
;
661 VkClearDepthStencilValue clear_value
= clear_att
->clearValue
.depthStencil
;
662 VkImageAspectFlags aspects
= clear_att
->aspectMask
;
663 const struct radv_image_view
*iview
= fb
->attachments
[pass_att
].attachment
;
664 const uint32_t samples
= iview
->image
->samples
;
665 const uint32_t samples_log2
= ffs(samples
) - 1;
666 VkCommandBuffer cmd_buffer_h
= radv_cmd_buffer_to_handle(cmd_buffer
);
669 assert(aspects
== VK_IMAGE_ASPECT_DEPTH_BIT
||
670 aspects
== VK_IMAGE_ASPECT_STENCIL_BIT
||
671 aspects
== (VK_IMAGE_ASPECT_DEPTH_BIT
|
672 VK_IMAGE_ASPECT_STENCIL_BIT
));
673 assert(pass_att
!= VK_ATTACHMENT_UNUSED
);
675 const struct depthstencil_clear_vattrs vertex_data
[3] = {
677 .depth_clear
= clear_value
.depth
,
680 .depth_clear
= clear_value
.depth
,
683 .depth_clear
= clear_value
.depth
,
687 radv_cmd_buffer_upload_data(cmd_buffer
, sizeof(vertex_data
), 16, vertex_data
, &offset
);
688 struct radv_buffer vertex_buffer
= {
690 .size
= sizeof(vertex_data
),
691 .bo
= cmd_buffer
->upload
.upload_bo
,
695 if (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
696 radv_CmdSetStencilReference(cmd_buffer_h
, VK_STENCIL_FACE_FRONT_BIT
,
697 clear_value
.stencil
);
700 radv_CmdBindVertexBuffers(cmd_buffer_h
, 0, 1,
701 (VkBuffer
[]) { radv_buffer_to_handle(&vertex_buffer
) },
702 (VkDeviceSize
[]) { 0 });
704 struct radv_pipeline
*pipeline
= pick_depthstencil_pipeline(meta_state
,
708 subpass
->depth_stencil_attachment
.layout
,
711 if (cmd_buffer
->state
.pipeline
!= pipeline
) {
712 radv_CmdBindPipeline(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
713 radv_pipeline_to_handle(pipeline
));
716 if (depth_view_can_fast_clear(iview
, subpass
->depth_stencil_attachment
.layout
, clear_rect
))
717 radv_set_depth_clear_regs(cmd_buffer
, iview
->image
, clear_value
, aspects
);
719 radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkViewport
) {
720 .x
= clear_rect
->rect
.offset
.x
,
721 .y
= clear_rect
->rect
.offset
.y
,
722 .width
= clear_rect
->rect
.extent
.width
,
723 .height
= clear_rect
->rect
.extent
.height
,
728 radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &clear_rect
->rect
);
730 radv_CmdDraw(cmd_buffer_h
, 3, clear_rect
->layerCount
, 0, 0);
734 static VkFormat pipeline_formats
[] = {
735 VK_FORMAT_R8G8B8A8_UNORM
,
736 VK_FORMAT_R8G8B8A8_UINT
,
737 VK_FORMAT_R8G8B8A8_SINT
,
738 VK_FORMAT_R16G16B16A16_UNORM
,
739 VK_FORMAT_R16G16B16A16_SNORM
,
740 VK_FORMAT_R16G16B16A16_UINT
,
741 VK_FORMAT_R16G16B16A16_SINT
,
742 VK_FORMAT_R32_SFLOAT
,
743 VK_FORMAT_R32G32_SFLOAT
,
744 VK_FORMAT_R32G32B32A32_SFLOAT
748 radv_device_init_meta_clear_state(struct radv_device
*device
)
751 struct radv_meta_state
*state
= &device
->meta_state
;
753 memset(&device
->meta_state
.clear
, 0, sizeof(device
->meta_state
.clear
));
755 for (uint32_t i
= 0; i
< ARRAY_SIZE(state
->clear
); ++i
) {
756 uint32_t samples
= 1 << i
;
757 for (uint32_t j
= 0; j
< ARRAY_SIZE(pipeline_formats
); ++j
) {
758 VkFormat format
= pipeline_formats
[j
];
759 unsigned fs_key
= radv_format_meta_fs_key(format
);
760 assert(!state
->clear
[i
].color_pipelines
[fs_key
]);
762 res
= create_color_renderpass(device
, format
, samples
,
763 &state
->clear
[i
].render_pass
[fs_key
]);
764 if (res
!= VK_SUCCESS
)
767 res
= create_color_pipeline(device
, samples
, 0, &state
->clear
[i
].color_pipelines
[fs_key
],
768 state
->clear
[i
].render_pass
[fs_key
]);
769 if (res
!= VK_SUCCESS
)
774 res
= create_depthstencil_renderpass(device
,
776 &state
->clear
[i
].depthstencil_rp
);
777 if (res
!= VK_SUCCESS
)
780 for (uint32_t j
= 0; j
< NUM_DEPTH_CLEAR_PIPELINES
; j
++) {
781 res
= create_depthstencil_pipeline(device
,
782 VK_IMAGE_ASPECT_DEPTH_BIT
,
785 &state
->clear
[i
].depth_only_pipeline
[j
],
786 state
->clear
[i
].depthstencil_rp
);
787 if (res
!= VK_SUCCESS
)
790 res
= create_depthstencil_pipeline(device
,
791 VK_IMAGE_ASPECT_STENCIL_BIT
,
794 &state
->clear
[i
].stencil_only_pipeline
[j
],
795 state
->clear
[i
].depthstencil_rp
);
796 if (res
!= VK_SUCCESS
)
799 res
= create_depthstencil_pipeline(device
,
800 VK_IMAGE_ASPECT_DEPTH_BIT
|
801 VK_IMAGE_ASPECT_STENCIL_BIT
,
804 &state
->clear
[i
].depthstencil_pipeline
[j
],
805 state
->clear
[i
].depthstencil_rp
);
806 if (res
!= VK_SUCCESS
)
813 radv_device_finish_meta_clear_state(device
);
818 emit_fast_color_clear(struct radv_cmd_buffer
*cmd_buffer
,
819 const VkClearAttachment
*clear_att
,
820 const VkClearRect
*clear_rect
,
821 enum radv_cmd_flush_bits
*pre_flush
,
822 enum radv_cmd_flush_bits
*post_flush
)
824 const struct radv_subpass
*subpass
= cmd_buffer
->state
.subpass
;
825 const uint32_t subpass_att
= clear_att
->colorAttachment
;
826 const uint32_t pass_att
= subpass
->color_attachments
[subpass_att
].attachment
;
827 VkImageLayout image_layout
= subpass
->color_attachments
[subpass_att
].layout
;
828 const struct radv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
829 const struct radv_image_view
*iview
= fb
->attachments
[pass_att
].attachment
;
830 VkClearColorValue clear_value
= clear_att
->clearValue
.color
;
831 uint32_t clear_color
[2];
834 if (!iview
->image
->cmask
.size
&& !iview
->image
->surface
.dcc_size
)
837 if (cmd_buffer
->device
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
)
840 if (!radv_layout_can_fast_clear(iview
->image
, image_layout
, radv_image_queue_family_mask(iview
->image
, cmd_buffer
->queue_family_index
, cmd_buffer
->queue_family_index
)))
842 if (vk_format_get_blocksizebits(iview
->image
->vk_format
) > 64)
845 /* don't fast clear 3D */
846 if (iview
->image
->type
== VK_IMAGE_TYPE_3D
)
849 /* all layers are bound */
850 if (iview
->base_layer
> 0)
852 if (iview
->image
->array_size
!= iview
->layer_count
)
855 if (iview
->image
->levels
> 1)
858 if (iview
->image
->surface
.level
[0].mode
< RADEON_SURF_MODE_1D
)
861 if (!radv_image_extent_compare(iview
->image
, &iview
->extent
))
864 if (clear_rect
->rect
.offset
.x
|| clear_rect
->rect
.offset
.y
||
865 clear_rect
->rect
.extent
.width
!= iview
->image
->extent
.width
||
866 clear_rect
->rect
.extent
.height
!= iview
->image
->extent
.height
)
869 if (clear_rect
->baseArrayLayer
!= 0)
871 if (clear_rect
->layerCount
!= iview
->image
->array_size
)
875 ret
= radv_format_pack_clear_color(iview
->image
->vk_format
,
876 clear_color
, &clear_value
);
881 cmd_buffer
->state
.flush_bits
|= (RADV_CMD_FLAG_FLUSH_AND_INV_CB
|
882 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META
) & ~ *pre_flush
;
883 *pre_flush
|= cmd_buffer
->state
.flush_bits
;
885 cmd_buffer
->state
.flush_bits
|= RADV_CMD_FLAG_FLUSH_AND_INV_CB
|
886 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META
;
887 /* clear cmask buffer */
888 if (iview
->image
->surface
.dcc_size
) {
889 radv_fill_buffer(cmd_buffer
, iview
->image
->bo
,
890 iview
->image
->offset
+ iview
->image
->dcc_offset
,
891 iview
->image
->surface
.dcc_size
, 0x20202020);
893 radv_fill_buffer(cmd_buffer
, iview
->image
->bo
,
894 iview
->image
->offset
+ iview
->image
->cmask
.offset
,
895 iview
->image
->cmask
.size
, 0);
899 *post_flush
|= RADV_CMD_FLAG_CS_PARTIAL_FLUSH
|
900 RADV_CMD_FLAG_INV_VMEM_L1
|
901 RADV_CMD_FLAG_WRITEBACK_GLOBAL_L2
;
903 cmd_buffer
->state
.flush_bits
|= RADV_CMD_FLAG_CS_PARTIAL_FLUSH
|
904 RADV_CMD_FLAG_INV_VMEM_L1
|
905 RADV_CMD_FLAG_WRITEBACK_GLOBAL_L2
;
907 radv_set_color_clear_regs(cmd_buffer
, iview
->image
, subpass_att
, clear_color
);
915 * The parameters mean that same as those in vkCmdClearAttachments.
918 emit_clear(struct radv_cmd_buffer
*cmd_buffer
,
919 const VkClearAttachment
*clear_att
,
920 const VkClearRect
*clear_rect
,
921 enum radv_cmd_flush_bits
*pre_flush
,
922 enum radv_cmd_flush_bits
*post_flush
)
924 if (clear_att
->aspectMask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
926 if (!emit_fast_color_clear(cmd_buffer
, clear_att
, clear_rect
,
927 pre_flush
, post_flush
))
928 emit_color_clear(cmd_buffer
, clear_att
, clear_rect
);
930 assert(clear_att
->aspectMask
& (VK_IMAGE_ASPECT_DEPTH_BIT
|
931 VK_IMAGE_ASPECT_STENCIL_BIT
));
932 emit_depthstencil_clear(cmd_buffer
, clear_att
, clear_rect
);
937 subpass_needs_clear(const struct radv_cmd_buffer
*cmd_buffer
)
939 const struct radv_cmd_state
*cmd_state
= &cmd_buffer
->state
;
942 if (!cmd_state
->subpass
)
944 ds
= cmd_state
->subpass
->depth_stencil_attachment
.attachment
;
945 for (uint32_t i
= 0; i
< cmd_state
->subpass
->color_count
; ++i
) {
946 uint32_t a
= cmd_state
->subpass
->color_attachments
[i
].attachment
;
947 if (cmd_state
->attachments
[a
].pending_clear_aspects
) {
952 if (ds
!= VK_ATTACHMENT_UNUSED
&&
953 cmd_state
->attachments
[ds
].pending_clear_aspects
) {
961 * Emit any pending attachment clears for the current subpass.
963 * @see radv_attachment_state::pending_clear_aspects
966 radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer
*cmd_buffer
)
968 struct radv_cmd_state
*cmd_state
= &cmd_buffer
->state
;
969 struct radv_meta_saved_state saved_state
;
970 enum radv_cmd_flush_bits pre_flush
= 0;
971 enum radv_cmd_flush_bits post_flush
= 0;
973 if (!subpass_needs_clear(cmd_buffer
))
976 radv_meta_save_graphics_reset_vport_scissor(&saved_state
, cmd_buffer
);
978 VkClearRect clear_rect
= {
979 .rect
= cmd_state
->render_area
,
981 .layerCount
= cmd_state
->framebuffer
->layers
,
984 for (uint32_t i
= 0; i
< cmd_state
->subpass
->color_count
; ++i
) {
985 uint32_t a
= cmd_state
->subpass
->color_attachments
[i
].attachment
;
987 if (!cmd_state
->attachments
[a
].pending_clear_aspects
)
990 assert(cmd_state
->attachments
[a
].pending_clear_aspects
==
991 VK_IMAGE_ASPECT_COLOR_BIT
);
993 VkClearAttachment clear_att
= {
994 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
995 .colorAttachment
= i
, /* Use attachment index relative to subpass */
996 .clearValue
= cmd_state
->attachments
[a
].clear_value
,
999 emit_clear(cmd_buffer
, &clear_att
, &clear_rect
, &pre_flush
, &post_flush
);
1000 cmd_state
->attachments
[a
].pending_clear_aspects
= 0;
1003 uint32_t ds
= cmd_state
->subpass
->depth_stencil_attachment
.attachment
;
1005 if (ds
!= VK_ATTACHMENT_UNUSED
) {
1007 if (cmd_state
->attachments
[ds
].pending_clear_aspects
) {
1009 VkClearAttachment clear_att
= {
1010 .aspectMask
= cmd_state
->attachments
[ds
].pending_clear_aspects
,
1011 .clearValue
= cmd_state
->attachments
[ds
].clear_value
,
1014 emit_clear(cmd_buffer
, &clear_att
, &clear_rect
,
1015 &pre_flush
, &post_flush
);
1016 cmd_state
->attachments
[ds
].pending_clear_aspects
= 0;
1020 radv_meta_restore(&saved_state
, cmd_buffer
);
1021 cmd_buffer
->state
.flush_bits
|= post_flush
;
1025 radv_clear_image_layer(struct radv_cmd_buffer
*cmd_buffer
,
1026 struct radv_image
*image
,
1027 VkImageLayout image_layout
,
1028 const VkImageSubresourceRange
*range
,
1029 VkFormat format
, int level
, int layer
,
1030 const VkClearValue
*clear_val
)
1032 VkDevice device_h
= radv_device_to_handle(cmd_buffer
->device
);
1033 struct radv_image_view iview
;
1034 radv_image_view_init(&iview
, cmd_buffer
->device
,
1035 &(VkImageViewCreateInfo
) {
1036 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1037 .image
= radv_image_to_handle(image
),
1038 .viewType
= radv_meta_get_view_type(image
),
1040 .subresourceRange
= {
1041 .aspectMask
= range
->aspectMask
,
1042 .baseMipLevel
= range
->baseMipLevel
+ level
,
1044 .baseArrayLayer
= range
->baseArrayLayer
+ layer
,
1048 cmd_buffer
, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
);
1051 radv_CreateFramebuffer(device_h
,
1052 &(VkFramebufferCreateInfo
) {
1053 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
1054 .attachmentCount
= 1,
1055 .pAttachments
= (VkImageView
[]) {
1056 radv_image_view_to_handle(&iview
),
1058 .width
= iview
.extent
.width
,
1059 .height
= iview
.extent
.height
,
1062 &cmd_buffer
->pool
->alloc
,
1065 VkAttachmentDescription att_desc
= {
1066 .format
= iview
.vk_format
,
1067 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
1068 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
1069 .stencilLoadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
1070 .stencilStoreOp
= VK_ATTACHMENT_STORE_OP_STORE
,
1071 .initialLayout
= image_layout
,
1072 .finalLayout
= image_layout
,
1075 VkSubpassDescription subpass_desc
= {
1076 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
1077 .inputAttachmentCount
= 0,
1078 .colorAttachmentCount
= 0,
1079 .pColorAttachments
= NULL
,
1080 .pResolveAttachments
= NULL
,
1081 .pDepthStencilAttachment
= NULL
,
1082 .preserveAttachmentCount
= 0,
1083 .pPreserveAttachments
= NULL
,
1086 const VkAttachmentReference att_ref
= {
1088 .layout
= image_layout
,
1091 if (range
->aspectMask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
1092 subpass_desc
.colorAttachmentCount
= 1;
1093 subpass_desc
.pColorAttachments
= &att_ref
;
1095 subpass_desc
.pDepthStencilAttachment
= &att_ref
;
1099 radv_CreateRenderPass(device_h
,
1100 &(VkRenderPassCreateInfo
) {
1101 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
1102 .attachmentCount
= 1,
1103 .pAttachments
= &att_desc
,
1105 .pSubpasses
= &subpass_desc
,
1107 &cmd_buffer
->pool
->alloc
,
1110 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
1111 &(VkRenderPassBeginInfo
) {
1112 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
1114 .offset
= { 0, 0, },
1116 .width
= iview
.extent
.width
,
1117 .height
= iview
.extent
.height
,
1122 .clearValueCount
= 0,
1123 .pClearValues
= NULL
,
1125 VK_SUBPASS_CONTENTS_INLINE
);
1127 VkClearAttachment clear_att
= {
1128 .aspectMask
= range
->aspectMask
,
1129 .colorAttachment
= 0,
1130 .clearValue
= *clear_val
,
1133 VkClearRect clear_rect
= {
1136 .extent
= { iview
.extent
.width
, iview
.extent
.height
},
1138 .baseArrayLayer
= range
->baseArrayLayer
,
1139 .layerCount
= 1, /* FINISHME: clear multi-layer framebuffer */
1142 emit_clear(cmd_buffer
, &clear_att
, &clear_rect
, NULL
, NULL
);
1144 radv_CmdEndRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
));
1145 radv_DestroyRenderPass(device_h
, pass
,
1146 &cmd_buffer
->pool
->alloc
);
1147 radv_DestroyFramebuffer(device_h
, fb
,
1148 &cmd_buffer
->pool
->alloc
);
1151 radv_cmd_clear_image(struct radv_cmd_buffer
*cmd_buffer
,
1152 struct radv_image
*image
,
1153 VkImageLayout image_layout
,
1154 const VkClearValue
*clear_value
,
1155 uint32_t range_count
,
1156 const VkImageSubresourceRange
*ranges
,
1159 VkFormat format
= image
->vk_format
;
1160 VkClearValue internal_clear_value
= *clear_value
;
1162 if (format
== VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
) {
1164 format
= VK_FORMAT_R32_UINT
;
1165 value
= float3_to_rgb9e5(clear_value
->color
.float32
);
1166 internal_clear_value
.color
.uint32
[0] = value
;
1169 if (format
== VK_FORMAT_R4G4_UNORM_PACK8
) {
1171 format
= VK_FORMAT_R8_UINT
;
1172 r
= float_to_ubyte(clear_value
->color
.float32
[0]) >> 4;
1173 g
= float_to_ubyte(clear_value
->color
.float32
[1]) >> 4;
1174 internal_clear_value
.color
.uint32
[0] = (r
<< 4) | (g
& 0xf);
1177 for (uint32_t r
= 0; r
< range_count
; r
++) {
1178 const VkImageSubresourceRange
*range
= &ranges
[r
];
1179 for (uint32_t l
= 0; l
< radv_get_levelCount(image
, range
); ++l
) {
1180 const uint32_t layer_count
= image
->type
== VK_IMAGE_TYPE_3D
?
1181 radv_minify(image
->extent
.depth
, range
->baseMipLevel
+ l
) :
1182 radv_get_layerCount(image
, range
);
1183 for (uint32_t s
= 0; s
< layer_count
; ++s
) {
1186 struct radv_meta_blit2d_surf surf
;
1187 surf
.format
= format
;
1189 surf
.level
= range
->baseMipLevel
+ l
;
1190 surf
.layer
= range
->baseArrayLayer
+ s
;
1191 surf
.aspect_mask
= range
->aspectMask
;
1192 radv_meta_clear_image_cs(cmd_buffer
, &surf
,
1193 &internal_clear_value
.color
);
1195 radv_clear_image_layer(cmd_buffer
, image
, image_layout
,
1196 range
, format
, l
, s
, &internal_clear_value
);
1203 union meta_saved_state
{
1204 struct radv_meta_saved_state gfx
;
1205 struct radv_meta_saved_compute_state compute
;
1208 void radv_CmdClearColorImage(
1209 VkCommandBuffer commandBuffer
,
1211 VkImageLayout imageLayout
,
1212 const VkClearColorValue
* pColor
,
1213 uint32_t rangeCount
,
1214 const VkImageSubresourceRange
* pRanges
)
1216 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1217 RADV_FROM_HANDLE(radv_image
, image
, image_h
);
1218 union meta_saved_state saved_state
;
1219 bool cs
= cmd_buffer
->queue_family_index
== RADV_QUEUE_COMPUTE
;
1222 radv_meta_begin_cleari(cmd_buffer
, &saved_state
.compute
);
1224 radv_meta_save_graphics_reset_vport_scissor(&saved_state
.gfx
, cmd_buffer
);
1226 radv_cmd_clear_image(cmd_buffer
, image
, imageLayout
,
1227 (const VkClearValue
*) pColor
,
1228 rangeCount
, pRanges
, cs
);
1231 radv_meta_end_cleari(cmd_buffer
, &saved_state
.compute
);
1233 radv_meta_restore(&saved_state
.gfx
, cmd_buffer
);
1236 void radv_CmdClearDepthStencilImage(
1237 VkCommandBuffer commandBuffer
,
1239 VkImageLayout imageLayout
,
1240 const VkClearDepthStencilValue
* pDepthStencil
,
1241 uint32_t rangeCount
,
1242 const VkImageSubresourceRange
* pRanges
)
1244 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1245 RADV_FROM_HANDLE(radv_image
, image
, image_h
);
1246 struct radv_meta_saved_state saved_state
;
1248 radv_meta_save_graphics_reset_vport_scissor(&saved_state
, cmd_buffer
);
1250 radv_cmd_clear_image(cmd_buffer
, image
, imageLayout
,
1251 (const VkClearValue
*) pDepthStencil
,
1252 rangeCount
, pRanges
, false);
1254 radv_meta_restore(&saved_state
, cmd_buffer
);
1257 void radv_CmdClearAttachments(
1258 VkCommandBuffer commandBuffer
,
1259 uint32_t attachmentCount
,
1260 const VkClearAttachment
* pAttachments
,
1262 const VkClearRect
* pRects
)
1264 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1265 struct radv_meta_saved_state saved_state
;
1266 enum radv_cmd_flush_bits pre_flush
= 0;
1267 enum radv_cmd_flush_bits post_flush
= 0;
1269 if (!cmd_buffer
->state
.subpass
)
1272 radv_meta_save_graphics_reset_vport_scissor(&saved_state
, cmd_buffer
);
1274 /* FINISHME: We can do better than this dumb loop. It thrashes too much
1277 for (uint32_t a
= 0; a
< attachmentCount
; ++a
) {
1278 for (uint32_t r
= 0; r
< rectCount
; ++r
) {
1279 emit_clear(cmd_buffer
, &pAttachments
[a
], &pRects
[r
], &pre_flush
, &post_flush
);
1283 radv_meta_restore(&saved_state
, cmd_buffer
);
1284 cmd_buffer
->state
.flush_bits
|= post_flush
;