2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 #include "radv_meta.h"
28 #include "radv_private.h"
33 build_dcc_decompress_compute_shader(struct radv_device
*dev
)
36 const struct glsl_type
*buf_type
= glsl_sampler_type(GLSL_SAMPLER_DIM_2D
,
40 const struct glsl_type
*img_type
= glsl_sampler_type(GLSL_SAMPLER_DIM_2D
,
44 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_COMPUTE
, NULL
);
45 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, "dcc_decompress_compute");
47 /* We need at least 16/16/1 to cover an entire DCC block in a single workgroup. */
48 b
.shader
->info
.cs
.local_size
[0] = 16;
49 b
.shader
->info
.cs
.local_size
[1] = 16;
50 b
.shader
->info
.cs
.local_size
[2] = 1;
51 nir_variable
*input_img
= nir_variable_create(b
.shader
, nir_var_uniform
,
53 input_img
->data
.descriptor_set
= 0;
54 input_img
->data
.binding
= 0;
56 nir_variable
*output_img
= nir_variable_create(b
.shader
, nir_var_uniform
,
58 output_img
->data
.descriptor_set
= 0;
59 output_img
->data
.binding
= 1;
61 nir_ssa_def
*invoc_id
= nir_load_system_value(&b
, nir_intrinsic_load_local_invocation_id
, 0);
62 nir_ssa_def
*wg_id
= nir_load_system_value(&b
, nir_intrinsic_load_work_group_id
, 0);
63 nir_ssa_def
*block_size
= nir_imm_ivec4(&b
,
64 b
.shader
->info
.cs
.local_size
[0],
65 b
.shader
->info
.cs
.local_size
[1],
66 b
.shader
->info
.cs
.local_size
[2], 0);
68 nir_ssa_def
*global_id
= nir_iadd(&b
, nir_imul(&b
, wg_id
, block_size
), invoc_id
);
69 nir_ssa_def
*input_img_deref
= &nir_build_deref_var(&b
, input_img
)->dest
.ssa
;
71 nir_tex_instr
*tex
= nir_tex_instr_create(b
.shader
, 3);
72 tex
->sampler_dim
= GLSL_SAMPLER_DIM_2D
;
73 tex
->op
= nir_texop_txf
;
74 tex
->src
[0].src_type
= nir_tex_src_coord
;
75 tex
->src
[0].src
= nir_src_for_ssa(nir_channels(&b
, global_id
, 3));
76 tex
->src
[1].src_type
= nir_tex_src_lod
;
77 tex
->src
[1].src
= nir_src_for_ssa(nir_imm_int(&b
, 0));
78 tex
->src
[2].src_type
= nir_tex_src_texture_deref
;
79 tex
->src
[2].src
= nir_src_for_ssa(input_img_deref
);
80 tex
->dest_type
= nir_type_float
;
81 tex
->is_array
= false;
82 tex
->coord_components
= 2;
84 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
85 nir_builder_instr_insert(&b
, &tex
->instr
);
87 nir_intrinsic_instr
*membar
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_memory_barrier
);
88 nir_builder_instr_insert(&b
, &membar
->instr
);
90 nir_intrinsic_instr
*bar
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_barrier
);
91 nir_builder_instr_insert(&b
, &bar
->instr
);
93 nir_ssa_def
*outval
= &tex
->dest
.ssa
;
94 nir_intrinsic_instr
*store
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_image_deref_store
);
95 store
->src
[0] = nir_src_for_ssa(&nir_build_deref_var(&b
, output_img
)->dest
.ssa
);
96 store
->src
[1] = nir_src_for_ssa(global_id
);
97 store
->src
[2] = nir_src_for_ssa(nir_ssa_undef(&b
, 1, 32));
98 store
->src
[3] = nir_src_for_ssa(outval
);
100 nir_builder_instr_insert(&b
, &store
->instr
);
105 create_dcc_compress_compute(struct radv_device
*device
)
107 VkResult result
= VK_SUCCESS
;
108 struct radv_shader_module cs
= { .nir
= NULL
};
110 cs
.nir
= build_dcc_decompress_compute_shader(device
);
112 VkDescriptorSetLayoutCreateInfo ds_create_info
= {
113 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
114 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
116 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
119 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
120 .descriptorCount
= 1,
121 .stageFlags
= VK_SHADER_STAGE_COMPUTE_BIT
,
122 .pImmutableSamplers
= NULL
126 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
,
127 .descriptorCount
= 1,
128 .stageFlags
= VK_SHADER_STAGE_COMPUTE_BIT
,
129 .pImmutableSamplers
= NULL
134 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
136 &device
->meta_state
.alloc
,
137 &device
->meta_state
.fast_clear_flush
.dcc_decompress_compute_ds_layout
);
138 if (result
!= VK_SUCCESS
)
142 VkPipelineLayoutCreateInfo pl_create_info
= {
143 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
145 .pSetLayouts
= &device
->meta_state
.fast_clear_flush
.dcc_decompress_compute_ds_layout
,
146 .pushConstantRangeCount
= 1,
147 .pPushConstantRanges
= &(VkPushConstantRange
){VK_SHADER_STAGE_COMPUTE_BIT
, 0, 8},
150 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
152 &device
->meta_state
.alloc
,
153 &device
->meta_state
.fast_clear_flush
.dcc_decompress_compute_p_layout
);
154 if (result
!= VK_SUCCESS
)
159 VkPipelineShaderStageCreateInfo pipeline_shader_stage
= {
160 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
161 .stage
= VK_SHADER_STAGE_COMPUTE_BIT
,
162 .module
= radv_shader_module_to_handle(&cs
),
164 .pSpecializationInfo
= NULL
,
167 VkComputePipelineCreateInfo vk_pipeline_info
= {
168 .sType
= VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
,
169 .stage
= pipeline_shader_stage
,
171 .layout
= device
->meta_state
.fast_clear_flush
.dcc_decompress_compute_p_layout
,
174 result
= radv_CreateComputePipelines(radv_device_to_handle(device
),
175 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
176 1, &vk_pipeline_info
, NULL
,
177 &device
->meta_state
.fast_clear_flush
.dcc_decompress_compute_pipeline
);
178 if (result
!= VK_SUCCESS
)
187 create_pass(struct radv_device
*device
)
190 VkDevice device_h
= radv_device_to_handle(device
);
191 const VkAllocationCallbacks
*alloc
= &device
->meta_state
.alloc
;
192 VkAttachmentDescription attachment
;
194 attachment
.format
= VK_FORMAT_UNDEFINED
;
195 attachment
.samples
= 1;
196 attachment
.loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
;
197 attachment
.storeOp
= VK_ATTACHMENT_STORE_OP_STORE
;
198 attachment
.initialLayout
= VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
;
199 attachment
.finalLayout
= VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
;
201 result
= radv_CreateRenderPass(device_h
,
202 &(VkRenderPassCreateInfo
) {
203 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
204 .attachmentCount
= 1,
205 .pAttachments
= &attachment
,
207 .pSubpasses
= &(VkSubpassDescription
) {
208 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
209 .inputAttachmentCount
= 0,
210 .colorAttachmentCount
= 1,
211 .pColorAttachments
= (VkAttachmentReference
[]) {
214 .layout
= VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
,
217 .pResolveAttachments
= NULL
,
218 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
219 .attachment
= VK_ATTACHMENT_UNUSED
,
221 .preserveAttachmentCount
= 0,
222 .pPreserveAttachments
= NULL
,
224 .dependencyCount
= 0,
227 &device
->meta_state
.fast_clear_flush
.pass
);
233 create_pipeline_layout(struct radv_device
*device
, VkPipelineLayout
*layout
)
235 VkPipelineLayoutCreateInfo pl_create_info
= {
236 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
239 .pushConstantRangeCount
= 0,
240 .pPushConstantRanges
= NULL
,
243 return radv_CreatePipelineLayout(radv_device_to_handle(device
),
245 &device
->meta_state
.alloc
,
250 create_pipeline(struct radv_device
*device
,
251 VkShaderModule vs_module_h
,
252 VkPipelineLayout layout
)
255 VkDevice device_h
= radv_device_to_handle(device
);
257 struct radv_shader_module fs_module
= {
258 .nir
= radv_meta_build_nir_fs_noop(),
261 if (!fs_module
.nir
) {
262 /* XXX: Need more accurate error */
263 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
267 const VkPipelineShaderStageCreateInfo stages
[2] = {
269 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
270 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
271 .module
= vs_module_h
,
275 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
276 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
277 .module
= radv_shader_module_to_handle(&fs_module
),
282 const VkPipelineVertexInputStateCreateInfo vi_state
= {
283 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
284 .vertexBindingDescriptionCount
= 0,
285 .vertexAttributeDescriptionCount
= 0,
288 const VkPipelineInputAssemblyStateCreateInfo ia_state
= {
289 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
290 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
291 .primitiveRestartEnable
= false,
294 const VkPipelineColorBlendStateCreateInfo blend_state
= {
295 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
296 .logicOpEnable
= false,
297 .attachmentCount
= 1,
298 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
300 .colorWriteMask
= VK_COLOR_COMPONENT_R_BIT
|
301 VK_COLOR_COMPONENT_G_BIT
|
302 VK_COLOR_COMPONENT_B_BIT
|
303 VK_COLOR_COMPONENT_A_BIT
,
307 const VkPipelineRasterizationStateCreateInfo rs_state
= {
308 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
309 .depthClampEnable
= false,
310 .rasterizerDiscardEnable
= false,
311 .polygonMode
= VK_POLYGON_MODE_FILL
,
312 .cullMode
= VK_CULL_MODE_NONE
,
313 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
,
316 result
= radv_graphics_pipeline_create(device_h
,
317 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
318 &(VkGraphicsPipelineCreateInfo
) {
319 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
323 .pVertexInputState
= &vi_state
,
324 .pInputAssemblyState
= &ia_state
,
326 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
327 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
331 .pRasterizationState
= &rs_state
,
332 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
333 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
334 .rasterizationSamples
= 1,
335 .sampleShadingEnable
= false,
337 .alphaToCoverageEnable
= false,
338 .alphaToOneEnable
= false,
340 .pColorBlendState
= &blend_state
,
341 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
342 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
343 .dynamicStateCount
= 2,
344 .pDynamicStates
= (VkDynamicState
[]) {
345 VK_DYNAMIC_STATE_VIEWPORT
,
346 VK_DYNAMIC_STATE_SCISSOR
,
350 .renderPass
= device
->meta_state
.fast_clear_flush
.pass
,
353 &(struct radv_graphics_pipeline_create_info
) {
354 .use_rectlist
= true,
355 .custom_blend_mode
= V_028808_CB_ELIMINATE_FAST_CLEAR
,
357 &device
->meta_state
.alloc
,
358 &device
->meta_state
.fast_clear_flush
.cmask_eliminate_pipeline
);
359 if (result
!= VK_SUCCESS
)
362 result
= radv_graphics_pipeline_create(device_h
,
363 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
364 &(VkGraphicsPipelineCreateInfo
) {
365 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
369 .pVertexInputState
= &vi_state
,
370 .pInputAssemblyState
= &ia_state
,
372 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
373 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
377 .pRasterizationState
= &rs_state
,
378 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
379 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
380 .rasterizationSamples
= 1,
381 .sampleShadingEnable
= false,
383 .alphaToCoverageEnable
= false,
384 .alphaToOneEnable
= false,
386 .pColorBlendState
= &blend_state
,
387 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
388 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
389 .dynamicStateCount
= 2,
390 .pDynamicStates
= (VkDynamicState
[]) {
391 VK_DYNAMIC_STATE_VIEWPORT
,
392 VK_DYNAMIC_STATE_SCISSOR
,
396 .renderPass
= device
->meta_state
.fast_clear_flush
.pass
,
399 &(struct radv_graphics_pipeline_create_info
) {
400 .use_rectlist
= true,
401 .custom_blend_mode
= V_028808_CB_FMASK_DECOMPRESS
,
403 &device
->meta_state
.alloc
,
404 &device
->meta_state
.fast_clear_flush
.fmask_decompress_pipeline
);
405 if (result
!= VK_SUCCESS
)
408 result
= radv_graphics_pipeline_create(device_h
,
409 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
410 &(VkGraphicsPipelineCreateInfo
) {
411 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
415 .pVertexInputState
= &vi_state
,
416 .pInputAssemblyState
= &ia_state
,
418 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
419 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
423 .pRasterizationState
= &rs_state
,
424 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
425 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
426 .rasterizationSamples
= 1,
427 .sampleShadingEnable
= false,
429 .alphaToCoverageEnable
= false,
430 .alphaToOneEnable
= false,
432 .pColorBlendState
= &blend_state
,
433 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
434 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
435 .dynamicStateCount
= 2,
436 .pDynamicStates
= (VkDynamicState
[]) {
437 VK_DYNAMIC_STATE_VIEWPORT
,
438 VK_DYNAMIC_STATE_SCISSOR
,
442 .renderPass
= device
->meta_state
.fast_clear_flush
.pass
,
445 &(struct radv_graphics_pipeline_create_info
) {
446 .use_rectlist
= true,
447 .custom_blend_mode
= V_028808_CB_DCC_DECOMPRESS
,
449 &device
->meta_state
.alloc
,
450 &device
->meta_state
.fast_clear_flush
.dcc_decompress_pipeline
);
451 if (result
!= VK_SUCCESS
)
457 ralloc_free(fs_module
.nir
);
462 radv_device_finish_meta_fast_clear_flush_state(struct radv_device
*device
)
464 struct radv_meta_state
*state
= &device
->meta_state
;
466 radv_DestroyPipeline(radv_device_to_handle(device
),
467 state
->fast_clear_flush
.dcc_decompress_pipeline
,
469 radv_DestroyPipeline(radv_device_to_handle(device
),
470 state
->fast_clear_flush
.fmask_decompress_pipeline
,
472 radv_DestroyPipeline(radv_device_to_handle(device
),
473 state
->fast_clear_flush
.cmask_eliminate_pipeline
,
475 radv_DestroyRenderPass(radv_device_to_handle(device
),
476 state
->fast_clear_flush
.pass
, &state
->alloc
);
477 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
478 state
->fast_clear_flush
.p_layout
,
481 radv_DestroyPipeline(radv_device_to_handle(device
),
482 state
->fast_clear_flush
.dcc_decompress_compute_pipeline
,
484 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
485 state
->fast_clear_flush
.dcc_decompress_compute_p_layout
,
487 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device
),
488 state
->fast_clear_flush
.dcc_decompress_compute_ds_layout
,
493 radv_device_init_meta_fast_clear_flush_state_internal(struct radv_device
*device
)
495 VkResult res
= VK_SUCCESS
;
497 mtx_lock(&device
->meta_state
.mtx
);
498 if (device
->meta_state
.fast_clear_flush
.cmask_eliminate_pipeline
) {
499 mtx_unlock(&device
->meta_state
.mtx
);
503 struct radv_shader_module vs_module
= { .nir
= radv_meta_build_nir_vs_generate_vertices() };
504 if (!vs_module
.nir
) {
505 /* XXX: Need more accurate error */
506 res
= VK_ERROR_OUT_OF_HOST_MEMORY
;
510 res
= create_pass(device
);
511 if (res
!= VK_SUCCESS
)
514 res
= create_pipeline_layout(device
,
515 &device
->meta_state
.fast_clear_flush
.p_layout
);
516 if (res
!= VK_SUCCESS
)
519 VkShaderModule vs_module_h
= radv_shader_module_to_handle(&vs_module
);
520 res
= create_pipeline(device
, vs_module_h
,
521 device
->meta_state
.fast_clear_flush
.p_layout
);
522 if (res
!= VK_SUCCESS
)
525 res
= create_dcc_compress_compute(device
);
526 if (res
!= VK_SUCCESS
)
532 radv_device_finish_meta_fast_clear_flush_state(device
);
535 ralloc_free(vs_module
.nir
);
536 mtx_unlock(&device
->meta_state
.mtx
);
543 radv_device_init_meta_fast_clear_flush_state(struct radv_device
*device
, bool on_demand
)
548 return radv_device_init_meta_fast_clear_flush_state_internal(device
);
552 emit_fast_clear_flush(struct radv_cmd_buffer
*cmd_buffer
,
553 const VkExtent2D
*resolve_extent
,
556 VkCommandBuffer cmd_buffer_h
= radv_cmd_buffer_to_handle(cmd_buffer
);
558 radv_CmdBindPipeline(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
561 radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkViewport
) {
564 .width
= resolve_extent
->width
,
565 .height
= resolve_extent
->height
,
570 radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkRect2D
) {
571 .offset
= (VkOffset2D
) { 0, 0 },
572 .extent
= (VkExtent2D
) { resolve_extent
->width
, resolve_extent
->height
},
575 radv_CmdDraw(cmd_buffer_h
, 3, 1, 0, 0);
576 cmd_buffer
->state
.flush_bits
|= (RADV_CMD_FLAG_FLUSH_AND_INV_CB
|
577 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META
);
581 radv_emit_set_predication_state_from_image(struct radv_cmd_buffer
*cmd_buffer
,
582 struct radv_image
*image
, bool value
)
587 va
= radv_buffer_get_va(image
->bo
) + image
->offset
;
588 va
+= image
->dcc_pred_offset
;
591 si_emit_set_predication_state(cmd_buffer
, true, va
);
597 radv_emit_color_decompress(struct radv_cmd_buffer
*cmd_buffer
,
598 struct radv_image
*image
,
599 const VkImageSubresourceRange
*subresourceRange
,
602 struct radv_meta_saved_state saved_state
;
603 VkDevice device_h
= radv_device_to_handle(cmd_buffer
->device
);
604 VkCommandBuffer cmd_buffer_h
= radv_cmd_buffer_to_handle(cmd_buffer
);
605 uint32_t layer_count
= radv_get_layerCount(image
, subresourceRange
);
606 bool old_predicating
= false;
609 assert(cmd_buffer
->queue_family_index
== RADV_QUEUE_GENERAL
);
611 if (!cmd_buffer
->device
->meta_state
.fast_clear_flush
.cmask_eliminate_pipeline
) {
612 VkResult ret
= radv_device_init_meta_fast_clear_flush_state_internal(cmd_buffer
->device
);
613 if (ret
!= VK_SUCCESS
) {
614 cmd_buffer
->record_result
= ret
;
619 radv_meta_save(&saved_state
, cmd_buffer
,
620 RADV_META_SAVE_GRAPHICS_PIPELINE
|
621 RADV_META_SAVE_PASS
);
623 if (decompress_dcc
&& radv_image_has_dcc(image
)) {
624 pipeline
= cmd_buffer
->device
->meta_state
.fast_clear_flush
.dcc_decompress_pipeline
;
625 } else if (radv_image_has_fmask(image
)) {
626 pipeline
= cmd_buffer
->device
->meta_state
.fast_clear_flush
.fmask_decompress_pipeline
;
628 pipeline
= cmd_buffer
->device
->meta_state
.fast_clear_flush
.cmask_eliminate_pipeline
;
631 if (!decompress_dcc
&& radv_image_has_dcc(image
)) {
632 old_predicating
= cmd_buffer
->state
.predicating
;
634 radv_emit_set_predication_state_from_image(cmd_buffer
, image
, true);
635 cmd_buffer
->state
.predicating
= true;
637 for (uint32_t layer
= 0; layer
< layer_count
; ++layer
) {
638 struct radv_image_view iview
;
640 radv_image_view_init(&iview
, cmd_buffer
->device
,
641 &(VkImageViewCreateInfo
) {
642 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
643 .image
= radv_image_to_handle(image
),
644 .viewType
= radv_meta_get_view_type(image
),
645 .format
= image
->vk_format
,
646 .subresourceRange
= {
647 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
650 .baseArrayLayer
= subresourceRange
->baseArrayLayer
+ layer
,
656 radv_CreateFramebuffer(device_h
,
657 &(VkFramebufferCreateInfo
) {
658 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
659 .attachmentCount
= 1,
660 .pAttachments
= (VkImageView
[]) {
661 radv_image_view_to_handle(&iview
)
663 .width
= image
->info
.width
,
664 .height
= image
->info
.height
,
667 &cmd_buffer
->pool
->alloc
,
670 radv_CmdBeginRenderPass(cmd_buffer_h
,
671 &(VkRenderPassBeginInfo
) {
672 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
673 .renderPass
= cmd_buffer
->device
->meta_state
.fast_clear_flush
.pass
,
685 .clearValueCount
= 0,
686 .pClearValues
= NULL
,
688 VK_SUBPASS_CONTENTS_INLINE
);
690 emit_fast_clear_flush(cmd_buffer
,
691 &(VkExtent2D
) { image
->info
.width
, image
->info
.height
},
693 radv_CmdEndRenderPass(cmd_buffer_h
);
695 radv_DestroyFramebuffer(device_h
, fb_h
,
696 &cmd_buffer
->pool
->alloc
);
699 if (!decompress_dcc
&& radv_image_has_dcc(image
)) {
700 cmd_buffer
->state
.predicating
= old_predicating
;
702 radv_emit_set_predication_state_from_image(cmd_buffer
, image
, false);
704 /* Clear the image's fast-clear eliminate predicate because
705 * FMASK and DCC also imply a fast-clear eliminate.
707 radv_set_dcc_need_cmask_elim_pred(cmd_buffer
, image
, false);
709 if (cmd_buffer
->state
.predication_type
!= -1) {
710 /* Restore previous conditional rendering user state. */
711 si_emit_set_predication_state(cmd_buffer
,
712 cmd_buffer
->state
.predication_type
,
713 cmd_buffer
->state
.predication_va
);
716 radv_meta_restore(&saved_state
, cmd_buffer
);
720 radv_fast_clear_flush_image_inplace(struct radv_cmd_buffer
*cmd_buffer
,
721 struct radv_image
*image
,
722 const VkImageSubresourceRange
*subresourceRange
)
724 radv_emit_color_decompress(cmd_buffer
, image
, subresourceRange
, false);
728 radv_decompress_dcc_gfx(struct radv_cmd_buffer
*cmd_buffer
,
729 struct radv_image
*image
,
730 const VkImageSubresourceRange
*subresourceRange
)
732 radv_emit_color_decompress(cmd_buffer
, image
, subresourceRange
, true);
736 radv_decompress_dcc_compute(struct radv_cmd_buffer
*cmd_buffer
,
737 struct radv_image
*image
,
738 const VkImageSubresourceRange
*subresourceRange
)
740 struct radv_meta_saved_state saved_state
;
741 struct radv_image_view iview
= {0};
742 struct radv_device
*device
= cmd_buffer
->device
;
744 /* This assumes the image is 2d with 1 layer and 1 mipmap level */
745 struct radv_cmd_state
*state
= &cmd_buffer
->state
;
747 state
->flush_bits
|= RADV_CMD_FLAG_FLUSH_AND_INV_CB
|
748 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META
;
750 radv_meta_save(&saved_state
, cmd_buffer
, RADV_META_SAVE_DESCRIPTORS
|
751 RADV_META_SAVE_COMPUTE_PIPELINE
);
753 radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer
),
754 VK_PIPELINE_BIND_POINT_COMPUTE
,
755 device
->meta_state
.fast_clear_flush
.dcc_decompress_compute_pipeline
);
757 radv_image_view_init(&iview
, cmd_buffer
->device
,
758 &(VkImageViewCreateInfo
) {
759 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
760 .image
= radv_image_to_handle(image
),
761 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
762 .format
= image
->vk_format
,
763 .subresourceRange
= {
764 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
772 radv_meta_push_descriptor_set(cmd_buffer
,
773 VK_PIPELINE_BIND_POINT_COMPUTE
,
774 device
->meta_state
.fast_clear_flush
.dcc_decompress_compute_p_layout
,
776 2, /* descriptorWriteCount */
777 (VkWriteDescriptorSet
[]) {
779 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
781 .dstArrayElement
= 0,
782 .descriptorCount
= 1,
783 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
784 .pImageInfo
= (VkDescriptorImageInfo
[]) {
786 .sampler
= VK_NULL_HANDLE
,
787 .imageView
= radv_image_view_to_handle(&iview
),
788 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
793 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
795 .dstArrayElement
= 0,
796 .descriptorCount
= 1,
797 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
,
798 .pImageInfo
= (VkDescriptorImageInfo
[]) {
800 .sampler
= VK_NULL_HANDLE
,
801 .imageView
= radv_image_view_to_handle(&iview
),
802 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
808 radv_unaligned_dispatch(cmd_buffer
, image
->info
.width
, image
->info
.height
, 1);
810 /* The fill buffer below does its own saving */
811 radv_meta_restore(&saved_state
, cmd_buffer
);
813 state
->flush_bits
|= RADV_CMD_FLAG_CS_PARTIAL_FLUSH
|
814 RADV_CMD_FLAG_INV_VMEM_L1
;
816 state
->flush_bits
|= radv_clear_dcc(cmd_buffer
, image
, 0xffffffff);
818 state
->flush_bits
|= RADV_CMD_FLAG_FLUSH_AND_INV_CB
|
819 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META
;
823 radv_decompress_dcc(struct radv_cmd_buffer
*cmd_buffer
,
824 struct radv_image
*image
,
825 const VkImageSubresourceRange
*subresourceRange
)
827 if (cmd_buffer
->queue_family_index
== RADV_QUEUE_GENERAL
)
828 radv_decompress_dcc_gfx(cmd_buffer
, image
, subresourceRange
);
830 radv_decompress_dcc_compute(cmd_buffer
, image
, subresourceRange
);