1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2016 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include <assert.h> 25bf215546Sopenharmony_ci#include <stdbool.h> 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "radv_meta.h" 28bf215546Sopenharmony_ci#include "radv_private.h" 29bf215546Sopenharmony_ci#include "sid.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_cienum radv_depth_op { 32bf215546Sopenharmony_ci DEPTH_DECOMPRESS, 33bf215546Sopenharmony_ci DEPTH_RESUMMARIZE, 34bf215546Sopenharmony_ci}; 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_cistatic nir_shader * 37bf215546Sopenharmony_cibuild_expand_depth_stencil_compute_shader(struct radv_device *dev) 38bf215546Sopenharmony_ci{ 39bf215546Sopenharmony_ci const struct glsl_type *img_type = glsl_image_type(GLSL_SAMPLER_DIM_2D, false, GLSL_TYPE_FLOAT); 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci nir_builder b = radv_meta_init_shader(dev, MESA_SHADER_COMPUTE, "expand_depth_stencil_compute"); 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci /* We need at least 8/8/1 to cover an entire HTILE block in a single workgroup. */ 44bf215546Sopenharmony_ci b.shader->info.workgroup_size[0] = 8; 45bf215546Sopenharmony_ci b.shader->info.workgroup_size[1] = 8; 46bf215546Sopenharmony_ci nir_variable *input_img = nir_variable_create(b.shader, nir_var_image, img_type, "in_img"); 47bf215546Sopenharmony_ci input_img->data.descriptor_set = 0; 48bf215546Sopenharmony_ci input_img->data.binding = 0; 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_ci nir_variable *output_img = nir_variable_create(b.shader, nir_var_image, img_type, "out_img"); 51bf215546Sopenharmony_ci output_img->data.descriptor_set = 0; 52bf215546Sopenharmony_ci output_img->data.binding = 1; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci nir_ssa_def *invoc_id = nir_load_local_invocation_id(&b); 55bf215546Sopenharmony_ci nir_ssa_def *wg_id = nir_load_workgroup_id(&b, 32); 56bf215546Sopenharmony_ci nir_ssa_def *block_size = 57bf215546Sopenharmony_ci nir_imm_ivec4(&b, b.shader->info.workgroup_size[0], b.shader->info.workgroup_size[1], 58bf215546Sopenharmony_ci b.shader->info.workgroup_size[2], 0); 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci nir_ssa_def *global_id = nir_iadd(&b, nir_imul(&b, wg_id, block_size), invoc_id); 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci nir_ssa_def *data = nir_image_deref_load( 63bf215546Sopenharmony_ci &b, 4, 32, &nir_build_deref_var(&b, input_img)->dest.ssa, global_id, nir_ssa_undef(&b, 1, 32), 64bf215546Sopenharmony_ci nir_imm_int(&b, 0), .image_dim = GLSL_SAMPLER_DIM_2D); 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci /* We need a NIR_SCOPE_DEVICE memory_scope because ACO will avoid 67bf215546Sopenharmony_ci * creating a vmcnt(0) because it expects the L1 cache to keep memory 68bf215546Sopenharmony_ci * operations in-order for the same workgroup. The vmcnt(0) seems 69bf215546Sopenharmony_ci * necessary however. */ 70bf215546Sopenharmony_ci nir_scoped_barrier(&b, .execution_scope = NIR_SCOPE_WORKGROUP, .memory_scope = NIR_SCOPE_DEVICE, 71bf215546Sopenharmony_ci .memory_semantics = NIR_MEMORY_ACQ_REL, .memory_modes = nir_var_mem_ssbo); 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci nir_image_deref_store(&b, &nir_build_deref_var(&b, output_img)->dest.ssa, global_id, 74bf215546Sopenharmony_ci nir_ssa_undef(&b, 1, 32), data, nir_imm_int(&b, 0), 75bf215546Sopenharmony_ci .image_dim = GLSL_SAMPLER_DIM_2D); 76bf215546Sopenharmony_ci return b.shader; 77bf215546Sopenharmony_ci} 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_cistatic VkResult 80bf215546Sopenharmony_cicreate_expand_depth_stencil_compute(struct radv_device *device) 81bf215546Sopenharmony_ci{ 82bf215546Sopenharmony_ci VkResult result = VK_SUCCESS; 83bf215546Sopenharmony_ci nir_shader *cs = build_expand_depth_stencil_compute_shader(device); 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci VkDescriptorSetLayoutCreateInfo ds_create_info = { 86bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, 87bf215546Sopenharmony_ci .flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR, 88bf215546Sopenharmony_ci .bindingCount = 2, 89bf215546Sopenharmony_ci .pBindings = (VkDescriptorSetLayoutBinding[]){ 90bf215546Sopenharmony_ci {.binding = 0, 91bf215546Sopenharmony_ci .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 92bf215546Sopenharmony_ci .descriptorCount = 1, 93bf215546Sopenharmony_ci .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, 94bf215546Sopenharmony_ci .pImmutableSamplers = NULL}, 95bf215546Sopenharmony_ci {.binding = 1, 96bf215546Sopenharmony_ci .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 97bf215546Sopenharmony_ci .descriptorCount = 1, 98bf215546Sopenharmony_ci .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, 99bf215546Sopenharmony_ci .pImmutableSamplers = NULL}, 100bf215546Sopenharmony_ci }}; 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci result = radv_CreateDescriptorSetLayout( 103bf215546Sopenharmony_ci radv_device_to_handle(device), &ds_create_info, &device->meta_state.alloc, 104bf215546Sopenharmony_ci &device->meta_state.expand_depth_stencil_compute_ds_layout); 105bf215546Sopenharmony_ci if (result != VK_SUCCESS) 106bf215546Sopenharmony_ci goto cleanup; 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci VkPipelineLayoutCreateInfo pl_create_info = { 109bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, 110bf215546Sopenharmony_ci .setLayoutCount = 1, 111bf215546Sopenharmony_ci .pSetLayouts = &device->meta_state.expand_depth_stencil_compute_ds_layout, 112bf215546Sopenharmony_ci .pushConstantRangeCount = 0, 113bf215546Sopenharmony_ci .pPushConstantRanges = NULL, 114bf215546Sopenharmony_ci }; 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci result = radv_CreatePipelineLayout( 117bf215546Sopenharmony_ci radv_device_to_handle(device), &pl_create_info, &device->meta_state.alloc, 118bf215546Sopenharmony_ci &device->meta_state.expand_depth_stencil_compute_p_layout); 119bf215546Sopenharmony_ci if (result != VK_SUCCESS) 120bf215546Sopenharmony_ci goto cleanup; 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci /* compute shader */ 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci VkPipelineShaderStageCreateInfo pipeline_shader_stage = { 125bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 126bf215546Sopenharmony_ci .stage = VK_SHADER_STAGE_COMPUTE_BIT, 127bf215546Sopenharmony_ci .module = vk_shader_module_handle_from_nir(cs), 128bf215546Sopenharmony_ci .pName = "main", 129bf215546Sopenharmony_ci .pSpecializationInfo = NULL, 130bf215546Sopenharmony_ci }; 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci VkComputePipelineCreateInfo vk_pipeline_info = { 133bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, 134bf215546Sopenharmony_ci .stage = pipeline_shader_stage, 135bf215546Sopenharmony_ci .flags = 0, 136bf215546Sopenharmony_ci .layout = device->meta_state.expand_depth_stencil_compute_p_layout, 137bf215546Sopenharmony_ci }; 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci result = radv_CreateComputePipelines( 140bf215546Sopenharmony_ci radv_device_to_handle(device), radv_pipeline_cache_to_handle(&device->meta_state.cache), 1, 141bf215546Sopenharmony_ci &vk_pipeline_info, NULL, 142bf215546Sopenharmony_ci &device->meta_state.expand_depth_stencil_compute_pipeline); 143bf215546Sopenharmony_ci if (result != VK_SUCCESS) 144bf215546Sopenharmony_ci goto cleanup; 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_cicleanup: 147bf215546Sopenharmony_ci ralloc_free(cs); 148bf215546Sopenharmony_ci return result; 149bf215546Sopenharmony_ci} 150bf215546Sopenharmony_ci 151bf215546Sopenharmony_cistatic VkResult 152bf215546Sopenharmony_cicreate_pipeline_layout(struct radv_device *device, VkPipelineLayout *layout) 153bf215546Sopenharmony_ci{ 154bf215546Sopenharmony_ci VkPipelineLayoutCreateInfo pl_create_info = { 155bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, 156bf215546Sopenharmony_ci .setLayoutCount = 0, 157bf215546Sopenharmony_ci .pSetLayouts = NULL, 158bf215546Sopenharmony_ci .pushConstantRangeCount = 0, 159bf215546Sopenharmony_ci .pPushConstantRanges = NULL, 160bf215546Sopenharmony_ci }; 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_ci return radv_CreatePipelineLayout(radv_device_to_handle(device), &pl_create_info, 163bf215546Sopenharmony_ci &device->meta_state.alloc, layout); 164bf215546Sopenharmony_ci} 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_cistatic VkResult 167bf215546Sopenharmony_cicreate_pipeline(struct radv_device *device, uint32_t samples, VkPipelineLayout layout, 168bf215546Sopenharmony_ci enum radv_depth_op op, VkPipeline *pipeline) 169bf215546Sopenharmony_ci{ 170bf215546Sopenharmony_ci VkResult result; 171bf215546Sopenharmony_ci VkDevice device_h = radv_device_to_handle(device); 172bf215546Sopenharmony_ci 173bf215546Sopenharmony_ci mtx_lock(&device->meta_state.mtx); 174bf215546Sopenharmony_ci if (*pipeline) { 175bf215546Sopenharmony_ci mtx_unlock(&device->meta_state.mtx); 176bf215546Sopenharmony_ci return VK_SUCCESS; 177bf215546Sopenharmony_ci } 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_ci nir_shader *vs_module = radv_meta_build_nir_vs_generate_vertices(device); 180bf215546Sopenharmony_ci nir_shader *fs_module = radv_meta_build_nir_fs_noop(device); 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci if (!vs_module || !fs_module) { 183bf215546Sopenharmony_ci /* XXX: Need more accurate error */ 184bf215546Sopenharmony_ci result = VK_ERROR_OUT_OF_HOST_MEMORY; 185bf215546Sopenharmony_ci goto cleanup; 186bf215546Sopenharmony_ci } 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_ci const VkPipelineSampleLocationsStateCreateInfoEXT sample_locs_create_info = { 189bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT, 190bf215546Sopenharmony_ci .sampleLocationsEnable = false, 191bf215546Sopenharmony_ci }; 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_ci const VkPipelineRenderingCreateInfo rendering_create_info = { 194bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO, 195bf215546Sopenharmony_ci .depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT, 196bf215546Sopenharmony_ci .stencilAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT, 197bf215546Sopenharmony_ci }; 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_ci const VkGraphicsPipelineCreateInfo pipeline_create_info = { 200bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, 201bf215546Sopenharmony_ci .pNext = &rendering_create_info, 202bf215546Sopenharmony_ci .stageCount = 2, 203bf215546Sopenharmony_ci .pStages = 204bf215546Sopenharmony_ci (VkPipelineShaderStageCreateInfo[]){ 205bf215546Sopenharmony_ci { 206bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 207bf215546Sopenharmony_ci .stage = VK_SHADER_STAGE_VERTEX_BIT, 208bf215546Sopenharmony_ci .module = vk_shader_module_handle_from_nir(vs_module), 209bf215546Sopenharmony_ci .pName = "main", 210bf215546Sopenharmony_ci }, 211bf215546Sopenharmony_ci { 212bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 213bf215546Sopenharmony_ci .stage = VK_SHADER_STAGE_FRAGMENT_BIT, 214bf215546Sopenharmony_ci .module = vk_shader_module_handle_from_nir(fs_module), 215bf215546Sopenharmony_ci .pName = "main", 216bf215546Sopenharmony_ci }, 217bf215546Sopenharmony_ci }, 218bf215546Sopenharmony_ci .pVertexInputState = 219bf215546Sopenharmony_ci &(VkPipelineVertexInputStateCreateInfo){ 220bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, 221bf215546Sopenharmony_ci .vertexBindingDescriptionCount = 0, 222bf215546Sopenharmony_ci .vertexAttributeDescriptionCount = 0, 223bf215546Sopenharmony_ci }, 224bf215546Sopenharmony_ci .pInputAssemblyState = 225bf215546Sopenharmony_ci &(VkPipelineInputAssemblyStateCreateInfo){ 226bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, 227bf215546Sopenharmony_ci .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, 228bf215546Sopenharmony_ci .primitiveRestartEnable = false, 229bf215546Sopenharmony_ci }, 230bf215546Sopenharmony_ci .pViewportState = 231bf215546Sopenharmony_ci &(VkPipelineViewportStateCreateInfo){ 232bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, 233bf215546Sopenharmony_ci .viewportCount = 1, 234bf215546Sopenharmony_ci .scissorCount = 1, 235bf215546Sopenharmony_ci }, 236bf215546Sopenharmony_ci .pRasterizationState = 237bf215546Sopenharmony_ci &(VkPipelineRasterizationStateCreateInfo){ 238bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, 239bf215546Sopenharmony_ci .depthClampEnable = false, 240bf215546Sopenharmony_ci .rasterizerDiscardEnable = false, 241bf215546Sopenharmony_ci .polygonMode = VK_POLYGON_MODE_FILL, 242bf215546Sopenharmony_ci .cullMode = VK_CULL_MODE_NONE, 243bf215546Sopenharmony_ci .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, 244bf215546Sopenharmony_ci }, 245bf215546Sopenharmony_ci .pMultisampleState = 246bf215546Sopenharmony_ci &(VkPipelineMultisampleStateCreateInfo){ 247bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, 248bf215546Sopenharmony_ci .pNext = &sample_locs_create_info, 249bf215546Sopenharmony_ci .rasterizationSamples = samples, 250bf215546Sopenharmony_ci .sampleShadingEnable = false, 251bf215546Sopenharmony_ci .pSampleMask = NULL, 252bf215546Sopenharmony_ci .alphaToCoverageEnable = false, 253bf215546Sopenharmony_ci .alphaToOneEnable = false, 254bf215546Sopenharmony_ci }, 255bf215546Sopenharmony_ci .pColorBlendState = 256bf215546Sopenharmony_ci &(VkPipelineColorBlendStateCreateInfo){ 257bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, 258bf215546Sopenharmony_ci .logicOpEnable = false, 259bf215546Sopenharmony_ci .attachmentCount = 0, 260bf215546Sopenharmony_ci .pAttachments = NULL, 261bf215546Sopenharmony_ci }, 262bf215546Sopenharmony_ci .pDepthStencilState = 263bf215546Sopenharmony_ci &(VkPipelineDepthStencilStateCreateInfo){ 264bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, 265bf215546Sopenharmony_ci .depthTestEnable = false, 266bf215546Sopenharmony_ci .depthWriteEnable = false, 267bf215546Sopenharmony_ci .depthBoundsTestEnable = false, 268bf215546Sopenharmony_ci .stencilTestEnable = false, 269bf215546Sopenharmony_ci }, 270bf215546Sopenharmony_ci .pDynamicState = 271bf215546Sopenharmony_ci &(VkPipelineDynamicStateCreateInfo){ 272bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, 273bf215546Sopenharmony_ci .dynamicStateCount = 3, 274bf215546Sopenharmony_ci .pDynamicStates = 275bf215546Sopenharmony_ci (VkDynamicState[]){ 276bf215546Sopenharmony_ci VK_DYNAMIC_STATE_VIEWPORT, 277bf215546Sopenharmony_ci VK_DYNAMIC_STATE_SCISSOR, 278bf215546Sopenharmony_ci VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, 279bf215546Sopenharmony_ci }, 280bf215546Sopenharmony_ci }, 281bf215546Sopenharmony_ci .layout = layout, 282bf215546Sopenharmony_ci .renderPass = VK_NULL_HANDLE, 283bf215546Sopenharmony_ci .subpass = 0, 284bf215546Sopenharmony_ci }; 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_ci struct radv_graphics_pipeline_create_info extra = { 287bf215546Sopenharmony_ci .use_rectlist = true, 288bf215546Sopenharmony_ci .depth_compress_disable = true, 289bf215546Sopenharmony_ci .stencil_compress_disable = true, 290bf215546Sopenharmony_ci .resummarize_enable = op == DEPTH_RESUMMARIZE, 291bf215546Sopenharmony_ci }; 292bf215546Sopenharmony_ci 293bf215546Sopenharmony_ci result = radv_graphics_pipeline_create( 294bf215546Sopenharmony_ci device_h, radv_pipeline_cache_to_handle(&device->meta_state.cache), &pipeline_create_info, 295bf215546Sopenharmony_ci &extra, &device->meta_state.alloc, pipeline); 296bf215546Sopenharmony_ci 297bf215546Sopenharmony_cicleanup: 298bf215546Sopenharmony_ci ralloc_free(fs_module); 299bf215546Sopenharmony_ci ralloc_free(vs_module); 300bf215546Sopenharmony_ci mtx_unlock(&device->meta_state.mtx); 301bf215546Sopenharmony_ci return result; 302bf215546Sopenharmony_ci} 303bf215546Sopenharmony_ci 304bf215546Sopenharmony_civoid 305bf215546Sopenharmony_ciradv_device_finish_meta_depth_decomp_state(struct radv_device *device) 306bf215546Sopenharmony_ci{ 307bf215546Sopenharmony_ci struct radv_meta_state *state = &device->meta_state; 308bf215546Sopenharmony_ci 309bf215546Sopenharmony_ci for (uint32_t i = 0; i < ARRAY_SIZE(state->depth_decomp); ++i) { 310bf215546Sopenharmony_ci radv_DestroyPipelineLayout(radv_device_to_handle(device), state->depth_decomp[i].p_layout, 311bf215546Sopenharmony_ci &state->alloc); 312bf215546Sopenharmony_ci 313bf215546Sopenharmony_ci radv_DestroyPipeline(radv_device_to_handle(device), 314bf215546Sopenharmony_ci state->depth_decomp[i].decompress_pipeline, &state->alloc); 315bf215546Sopenharmony_ci radv_DestroyPipeline(radv_device_to_handle(device), 316bf215546Sopenharmony_ci state->depth_decomp[i].resummarize_pipeline, &state->alloc); 317bf215546Sopenharmony_ci } 318bf215546Sopenharmony_ci 319bf215546Sopenharmony_ci radv_DestroyPipeline(radv_device_to_handle(device), 320bf215546Sopenharmony_ci state->expand_depth_stencil_compute_pipeline, &state->alloc); 321bf215546Sopenharmony_ci radv_DestroyPipelineLayout(radv_device_to_handle(device), 322bf215546Sopenharmony_ci state->expand_depth_stencil_compute_p_layout, &state->alloc); 323bf215546Sopenharmony_ci device->vk.dispatch_table.DestroyDescriptorSetLayout( 324bf215546Sopenharmony_ci radv_device_to_handle(device), state->expand_depth_stencil_compute_ds_layout, &state->alloc); 325bf215546Sopenharmony_ci} 326bf215546Sopenharmony_ci 327bf215546Sopenharmony_ciVkResult 328bf215546Sopenharmony_ciradv_device_init_meta_depth_decomp_state(struct radv_device *device, bool on_demand) 329bf215546Sopenharmony_ci{ 330bf215546Sopenharmony_ci struct radv_meta_state *state = &device->meta_state; 331bf215546Sopenharmony_ci VkResult res = VK_SUCCESS; 332bf215546Sopenharmony_ci 333bf215546Sopenharmony_ci for (uint32_t i = 0; i < ARRAY_SIZE(state->depth_decomp); ++i) { 334bf215546Sopenharmony_ci uint32_t samples = 1 << i; 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ci res = create_pipeline_layout(device, &state->depth_decomp[i].p_layout); 337bf215546Sopenharmony_ci if (res != VK_SUCCESS) 338bf215546Sopenharmony_ci return res; 339bf215546Sopenharmony_ci 340bf215546Sopenharmony_ci if (on_demand) 341bf215546Sopenharmony_ci continue; 342bf215546Sopenharmony_ci 343bf215546Sopenharmony_ci res = create_pipeline(device, samples, state->depth_decomp[i].p_layout, DEPTH_DECOMPRESS, 344bf215546Sopenharmony_ci &state->depth_decomp[i].decompress_pipeline); 345bf215546Sopenharmony_ci if (res != VK_SUCCESS) 346bf215546Sopenharmony_ci return res; 347bf215546Sopenharmony_ci 348bf215546Sopenharmony_ci res = create_pipeline(device, samples, state->depth_decomp[i].p_layout, DEPTH_RESUMMARIZE, 349bf215546Sopenharmony_ci &state->depth_decomp[i].resummarize_pipeline); 350bf215546Sopenharmony_ci if (res != VK_SUCCESS) 351bf215546Sopenharmony_ci return res; 352bf215546Sopenharmony_ci } 353bf215546Sopenharmony_ci 354bf215546Sopenharmony_ci return create_expand_depth_stencil_compute(device); 355bf215546Sopenharmony_ci} 356bf215546Sopenharmony_ci 357bf215546Sopenharmony_cistatic VkPipeline * 358bf215546Sopenharmony_ciradv_get_depth_pipeline(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image, 359bf215546Sopenharmony_ci const VkImageSubresourceRange *subresourceRange, enum radv_depth_op op) 360bf215546Sopenharmony_ci{ 361bf215546Sopenharmony_ci struct radv_meta_state *state = &cmd_buffer->device->meta_state; 362bf215546Sopenharmony_ci uint32_t samples = image->info.samples; 363bf215546Sopenharmony_ci uint32_t samples_log2 = ffs(samples) - 1; 364bf215546Sopenharmony_ci VkPipeline *pipeline; 365bf215546Sopenharmony_ci 366bf215546Sopenharmony_ci if (!state->depth_decomp[samples_log2].decompress_pipeline) { 367bf215546Sopenharmony_ci VkResult ret; 368bf215546Sopenharmony_ci 369bf215546Sopenharmony_ci ret = create_pipeline(cmd_buffer->device, samples, state->depth_decomp[samples_log2].p_layout, 370bf215546Sopenharmony_ci DEPTH_DECOMPRESS, &state->depth_decomp[samples_log2].decompress_pipeline); 371bf215546Sopenharmony_ci if (ret != VK_SUCCESS) { 372bf215546Sopenharmony_ci cmd_buffer->record_result = ret; 373bf215546Sopenharmony_ci return NULL; 374bf215546Sopenharmony_ci } 375bf215546Sopenharmony_ci 376bf215546Sopenharmony_ci ret = create_pipeline(cmd_buffer->device, samples, state->depth_decomp[samples_log2].p_layout, 377bf215546Sopenharmony_ci DEPTH_RESUMMARIZE, &state->depth_decomp[samples_log2].resummarize_pipeline); 378bf215546Sopenharmony_ci if (ret != VK_SUCCESS) { 379bf215546Sopenharmony_ci cmd_buffer->record_result = ret; 380bf215546Sopenharmony_ci return NULL; 381bf215546Sopenharmony_ci } 382bf215546Sopenharmony_ci } 383bf215546Sopenharmony_ci 384bf215546Sopenharmony_ci switch (op) { 385bf215546Sopenharmony_ci case DEPTH_DECOMPRESS: 386bf215546Sopenharmony_ci pipeline = &state->depth_decomp[samples_log2].decompress_pipeline; 387bf215546Sopenharmony_ci break; 388bf215546Sopenharmony_ci case DEPTH_RESUMMARIZE: 389bf215546Sopenharmony_ci pipeline = &state->depth_decomp[samples_log2].resummarize_pipeline; 390bf215546Sopenharmony_ci break; 391bf215546Sopenharmony_ci default: 392bf215546Sopenharmony_ci unreachable("unknown operation"); 393bf215546Sopenharmony_ci } 394bf215546Sopenharmony_ci 395bf215546Sopenharmony_ci return pipeline; 396bf215546Sopenharmony_ci} 397bf215546Sopenharmony_ci 398bf215546Sopenharmony_cistatic void 399bf215546Sopenharmony_ciradv_process_depth_image_layer(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image, 400bf215546Sopenharmony_ci const VkImageSubresourceRange *range, int level, int layer) 401bf215546Sopenharmony_ci{ 402bf215546Sopenharmony_ci struct radv_device *device = cmd_buffer->device; 403bf215546Sopenharmony_ci struct radv_image_view iview; 404bf215546Sopenharmony_ci uint32_t width, height; 405bf215546Sopenharmony_ci 406bf215546Sopenharmony_ci width = radv_minify(image->info.width, range->baseMipLevel + level); 407bf215546Sopenharmony_ci height = radv_minify(image->info.height, range->baseMipLevel + level); 408bf215546Sopenharmony_ci 409bf215546Sopenharmony_ci radv_image_view_init(&iview, device, 410bf215546Sopenharmony_ci &(VkImageViewCreateInfo){ 411bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, 412bf215546Sopenharmony_ci .image = radv_image_to_handle(image), 413bf215546Sopenharmony_ci .viewType = radv_meta_get_view_type(image), 414bf215546Sopenharmony_ci .format = image->vk.format, 415bf215546Sopenharmony_ci .subresourceRange = 416bf215546Sopenharmony_ci { 417bf215546Sopenharmony_ci .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT, 418bf215546Sopenharmony_ci .baseMipLevel = range->baseMipLevel + level, 419bf215546Sopenharmony_ci .levelCount = 1, 420bf215546Sopenharmony_ci .baseArrayLayer = range->baseArrayLayer + layer, 421bf215546Sopenharmony_ci .layerCount = 1, 422bf215546Sopenharmony_ci }, 423bf215546Sopenharmony_ci }, 424bf215546Sopenharmony_ci 0, NULL); 425bf215546Sopenharmony_ci 426bf215546Sopenharmony_ci const VkRenderingAttachmentInfo depth_att = { 427bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO, 428bf215546Sopenharmony_ci .imageView = radv_image_view_to_handle(&iview), 429bf215546Sopenharmony_ci .imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 430bf215546Sopenharmony_ci .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD, 431bf215546Sopenharmony_ci .storeOp = VK_ATTACHMENT_STORE_OP_STORE, 432bf215546Sopenharmony_ci }; 433bf215546Sopenharmony_ci 434bf215546Sopenharmony_ci const VkRenderingAttachmentInfo stencil_att = { 435bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO, 436bf215546Sopenharmony_ci .imageView = radv_image_view_to_handle(&iview), 437bf215546Sopenharmony_ci .imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 438bf215546Sopenharmony_ci .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD, 439bf215546Sopenharmony_ci .storeOp = VK_ATTACHMENT_STORE_OP_STORE, 440bf215546Sopenharmony_ci }; 441bf215546Sopenharmony_ci 442bf215546Sopenharmony_ci const VkRenderingInfo rendering_info = { 443bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_RENDERING_INFO, 444bf215546Sopenharmony_ci .renderArea = { 445bf215546Sopenharmony_ci .offset = { 0, 0 }, 446bf215546Sopenharmony_ci .extent = { width, height } 447bf215546Sopenharmony_ci }, 448bf215546Sopenharmony_ci .layerCount = 1, 449bf215546Sopenharmony_ci .pDepthAttachment = &depth_att, 450bf215546Sopenharmony_ci .pStencilAttachment = &stencil_att, 451bf215546Sopenharmony_ci }; 452bf215546Sopenharmony_ci 453bf215546Sopenharmony_ci radv_CmdBeginRendering(radv_cmd_buffer_to_handle(cmd_buffer), &rendering_info); 454bf215546Sopenharmony_ci 455bf215546Sopenharmony_ci radv_CmdDraw(radv_cmd_buffer_to_handle(cmd_buffer), 3, 1, 0, 0); 456bf215546Sopenharmony_ci 457bf215546Sopenharmony_ci radv_CmdEndRendering(radv_cmd_buffer_to_handle(cmd_buffer)); 458bf215546Sopenharmony_ci 459bf215546Sopenharmony_ci radv_image_view_finish(&iview); 460bf215546Sopenharmony_ci} 461bf215546Sopenharmony_ci 462bf215546Sopenharmony_cistatic void 463bf215546Sopenharmony_ciradv_process_depth_stencil(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image, 464bf215546Sopenharmony_ci const VkImageSubresourceRange *subresourceRange, 465bf215546Sopenharmony_ci struct radv_sample_locations_state *sample_locs, enum radv_depth_op op) 466bf215546Sopenharmony_ci{ 467bf215546Sopenharmony_ci struct radv_meta_saved_state saved_state; 468bf215546Sopenharmony_ci VkCommandBuffer cmd_buffer_h = radv_cmd_buffer_to_handle(cmd_buffer); 469bf215546Sopenharmony_ci VkPipeline *pipeline; 470bf215546Sopenharmony_ci 471bf215546Sopenharmony_ci radv_meta_save( 472bf215546Sopenharmony_ci &saved_state, cmd_buffer, 473bf215546Sopenharmony_ci RADV_META_SAVE_GRAPHICS_PIPELINE | RADV_META_SAVE_SAMPLE_LOCATIONS | RADV_META_SAVE_PASS); 474bf215546Sopenharmony_ci 475bf215546Sopenharmony_ci pipeline = radv_get_depth_pipeline(cmd_buffer, image, subresourceRange, op); 476bf215546Sopenharmony_ci 477bf215546Sopenharmony_ci radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer), VK_PIPELINE_BIND_POINT_GRAPHICS, 478bf215546Sopenharmony_ci *pipeline); 479bf215546Sopenharmony_ci 480bf215546Sopenharmony_ci if (sample_locs) { 481bf215546Sopenharmony_ci assert(image->vk.create_flags & VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT); 482bf215546Sopenharmony_ci 483bf215546Sopenharmony_ci /* Set the sample locations specified during explicit or 484bf215546Sopenharmony_ci * automatic layout transitions, otherwise the depth decompress 485bf215546Sopenharmony_ci * pass uses the default HW locations. 486bf215546Sopenharmony_ci */ 487bf215546Sopenharmony_ci radv_CmdSetSampleLocationsEXT(cmd_buffer_h, 488bf215546Sopenharmony_ci &(VkSampleLocationsInfoEXT){ 489bf215546Sopenharmony_ci .sampleLocationsPerPixel = sample_locs->per_pixel, 490bf215546Sopenharmony_ci .sampleLocationGridSize = sample_locs->grid_size, 491bf215546Sopenharmony_ci .sampleLocationsCount = sample_locs->count, 492bf215546Sopenharmony_ci .pSampleLocations = sample_locs->locations, 493bf215546Sopenharmony_ci }); 494bf215546Sopenharmony_ci } 495bf215546Sopenharmony_ci 496bf215546Sopenharmony_ci for (uint32_t l = 0; l < radv_get_levelCount(image, subresourceRange); ++l) { 497bf215546Sopenharmony_ci 498bf215546Sopenharmony_ci /* Do not decompress levels without HTILE. */ 499bf215546Sopenharmony_ci if (!radv_htile_enabled(image, subresourceRange->baseMipLevel + l)) 500bf215546Sopenharmony_ci continue; 501bf215546Sopenharmony_ci 502bf215546Sopenharmony_ci uint32_t width = radv_minify(image->info.width, subresourceRange->baseMipLevel + l); 503bf215546Sopenharmony_ci uint32_t height = radv_minify(image->info.height, subresourceRange->baseMipLevel + l); 504bf215546Sopenharmony_ci 505bf215546Sopenharmony_ci radv_CmdSetViewport(cmd_buffer_h, 0, 1, 506bf215546Sopenharmony_ci &(VkViewport){.x = 0, 507bf215546Sopenharmony_ci .y = 0, 508bf215546Sopenharmony_ci .width = width, 509bf215546Sopenharmony_ci .height = height, 510bf215546Sopenharmony_ci .minDepth = 0.0f, 511bf215546Sopenharmony_ci .maxDepth = 1.0f}); 512bf215546Sopenharmony_ci 513bf215546Sopenharmony_ci radv_CmdSetScissor(cmd_buffer_h, 0, 1, 514bf215546Sopenharmony_ci &(VkRect2D){ 515bf215546Sopenharmony_ci .offset = {0, 0}, 516bf215546Sopenharmony_ci .extent = {width, height}, 517bf215546Sopenharmony_ci }); 518bf215546Sopenharmony_ci 519bf215546Sopenharmony_ci for (uint32_t s = 0; s < radv_get_layerCount(image, subresourceRange); s++) { 520bf215546Sopenharmony_ci radv_process_depth_image_layer(cmd_buffer, image, subresourceRange, l, s); 521bf215546Sopenharmony_ci } 522bf215546Sopenharmony_ci } 523bf215546Sopenharmony_ci 524bf215546Sopenharmony_ci radv_meta_restore(&saved_state, cmd_buffer); 525bf215546Sopenharmony_ci} 526bf215546Sopenharmony_ci 527bf215546Sopenharmony_cistatic void 528bf215546Sopenharmony_ciradv_expand_depth_stencil_compute(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image, 529bf215546Sopenharmony_ci const VkImageSubresourceRange *subresourceRange) 530bf215546Sopenharmony_ci{ 531bf215546Sopenharmony_ci struct radv_meta_saved_state saved_state; 532bf215546Sopenharmony_ci struct radv_image_view load_iview = {0}; 533bf215546Sopenharmony_ci struct radv_image_view store_iview = {0}; 534bf215546Sopenharmony_ci struct radv_device *device = cmd_buffer->device; 535bf215546Sopenharmony_ci 536bf215546Sopenharmony_ci assert(radv_image_is_tc_compat_htile(image)); 537bf215546Sopenharmony_ci 538bf215546Sopenharmony_ci cmd_buffer->state.flush_bits |= 539bf215546Sopenharmony_ci radv_dst_access_flush(cmd_buffer, VK_ACCESS_2_SHADER_WRITE_BIT, image); 540bf215546Sopenharmony_ci 541bf215546Sopenharmony_ci radv_meta_save(&saved_state, cmd_buffer, 542bf215546Sopenharmony_ci RADV_META_SAVE_DESCRIPTORS | RADV_META_SAVE_COMPUTE_PIPELINE); 543bf215546Sopenharmony_ci 544bf215546Sopenharmony_ci radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer), VK_PIPELINE_BIND_POINT_COMPUTE, 545bf215546Sopenharmony_ci device->meta_state.expand_depth_stencil_compute_pipeline); 546bf215546Sopenharmony_ci 547bf215546Sopenharmony_ci for (uint32_t l = 0; l < radv_get_levelCount(image, subresourceRange); l++) { 548bf215546Sopenharmony_ci uint32_t width, height; 549bf215546Sopenharmony_ci 550bf215546Sopenharmony_ci /* Do not decompress levels without HTILE. */ 551bf215546Sopenharmony_ci if (!radv_htile_enabled(image, subresourceRange->baseMipLevel + l)) 552bf215546Sopenharmony_ci continue; 553bf215546Sopenharmony_ci 554bf215546Sopenharmony_ci width = radv_minify(image->info.width, subresourceRange->baseMipLevel + l); 555bf215546Sopenharmony_ci height = radv_minify(image->info.height, subresourceRange->baseMipLevel + l); 556bf215546Sopenharmony_ci 557bf215546Sopenharmony_ci for (uint32_t s = 0; s < radv_get_layerCount(image, subresourceRange); s++) { 558bf215546Sopenharmony_ci radv_image_view_init( 559bf215546Sopenharmony_ci &load_iview, cmd_buffer->device, 560bf215546Sopenharmony_ci &(VkImageViewCreateInfo){ 561bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, 562bf215546Sopenharmony_ci .image = radv_image_to_handle(image), 563bf215546Sopenharmony_ci .viewType = VK_IMAGE_VIEW_TYPE_2D, 564bf215546Sopenharmony_ci .format = image->vk.format, 565bf215546Sopenharmony_ci .subresourceRange = {.aspectMask = subresourceRange->aspectMask, 566bf215546Sopenharmony_ci .baseMipLevel = subresourceRange->baseMipLevel + l, 567bf215546Sopenharmony_ci .levelCount = 1, 568bf215546Sopenharmony_ci .baseArrayLayer = subresourceRange->baseArrayLayer + s, 569bf215546Sopenharmony_ci .layerCount = 1}, 570bf215546Sopenharmony_ci }, 571bf215546Sopenharmony_ci 0, &(struct radv_image_view_extra_create_info){.enable_compression = true}); 572bf215546Sopenharmony_ci radv_image_view_init( 573bf215546Sopenharmony_ci &store_iview, cmd_buffer->device, 574bf215546Sopenharmony_ci &(VkImageViewCreateInfo){ 575bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, 576bf215546Sopenharmony_ci .image = radv_image_to_handle(image), 577bf215546Sopenharmony_ci .viewType = VK_IMAGE_VIEW_TYPE_2D, 578bf215546Sopenharmony_ci .format = image->vk.format, 579bf215546Sopenharmony_ci .subresourceRange = {.aspectMask = subresourceRange->aspectMask, 580bf215546Sopenharmony_ci .baseMipLevel = subresourceRange->baseMipLevel + l, 581bf215546Sopenharmony_ci .levelCount = 1, 582bf215546Sopenharmony_ci .baseArrayLayer = subresourceRange->baseArrayLayer + s, 583bf215546Sopenharmony_ci .layerCount = 1}, 584bf215546Sopenharmony_ci }, 585bf215546Sopenharmony_ci 0, &(struct radv_image_view_extra_create_info){.disable_compression = true}); 586bf215546Sopenharmony_ci 587bf215546Sopenharmony_ci radv_meta_push_descriptor_set( 588bf215546Sopenharmony_ci cmd_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, 589bf215546Sopenharmony_ci device->meta_state.expand_depth_stencil_compute_p_layout, 0, /* set */ 590bf215546Sopenharmony_ci 2, /* descriptorWriteCount */ 591bf215546Sopenharmony_ci (VkWriteDescriptorSet[]){{.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 592bf215546Sopenharmony_ci .dstBinding = 0, 593bf215546Sopenharmony_ci .dstArrayElement = 0, 594bf215546Sopenharmony_ci .descriptorCount = 1, 595bf215546Sopenharmony_ci .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 596bf215546Sopenharmony_ci .pImageInfo = 597bf215546Sopenharmony_ci (VkDescriptorImageInfo[]){ 598bf215546Sopenharmony_ci { 599bf215546Sopenharmony_ci .sampler = VK_NULL_HANDLE, 600bf215546Sopenharmony_ci .imageView = radv_image_view_to_handle(&load_iview), 601bf215546Sopenharmony_ci .imageLayout = VK_IMAGE_LAYOUT_GENERAL, 602bf215546Sopenharmony_ci }, 603bf215546Sopenharmony_ci }}, 604bf215546Sopenharmony_ci {.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 605bf215546Sopenharmony_ci .dstBinding = 1, 606bf215546Sopenharmony_ci .dstArrayElement = 0, 607bf215546Sopenharmony_ci .descriptorCount = 1, 608bf215546Sopenharmony_ci .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 609bf215546Sopenharmony_ci .pImageInfo = (VkDescriptorImageInfo[]){ 610bf215546Sopenharmony_ci { 611bf215546Sopenharmony_ci .sampler = VK_NULL_HANDLE, 612bf215546Sopenharmony_ci .imageView = radv_image_view_to_handle(&store_iview), 613bf215546Sopenharmony_ci .imageLayout = VK_IMAGE_LAYOUT_GENERAL, 614bf215546Sopenharmony_ci }, 615bf215546Sopenharmony_ci }}}); 616bf215546Sopenharmony_ci 617bf215546Sopenharmony_ci radv_unaligned_dispatch(cmd_buffer, width, height, 1); 618bf215546Sopenharmony_ci 619bf215546Sopenharmony_ci radv_image_view_finish(&load_iview); 620bf215546Sopenharmony_ci radv_image_view_finish(&store_iview); 621bf215546Sopenharmony_ci } 622bf215546Sopenharmony_ci } 623bf215546Sopenharmony_ci 624bf215546Sopenharmony_ci radv_meta_restore(&saved_state, cmd_buffer); 625bf215546Sopenharmony_ci 626bf215546Sopenharmony_ci cmd_buffer->state.flush_bits |= 627bf215546Sopenharmony_ci RADV_CMD_FLAG_CS_PARTIAL_FLUSH | RADV_CMD_FLAG_INV_VCACHE | 628bf215546Sopenharmony_ci radv_src_access_flush(cmd_buffer, VK_ACCESS_2_SHADER_WRITE_BIT, image); 629bf215546Sopenharmony_ci 630bf215546Sopenharmony_ci /* Initialize the HTILE metadata as "fully expanded". */ 631bf215546Sopenharmony_ci uint32_t htile_value = radv_get_htile_initial_value(cmd_buffer->device, image); 632bf215546Sopenharmony_ci 633bf215546Sopenharmony_ci cmd_buffer->state.flush_bits |= radv_clear_htile(cmd_buffer, image, subresourceRange, htile_value); 634bf215546Sopenharmony_ci} 635bf215546Sopenharmony_ci 636bf215546Sopenharmony_civoid 637bf215546Sopenharmony_ciradv_expand_depth_stencil(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image, 638bf215546Sopenharmony_ci const VkImageSubresourceRange *subresourceRange, 639bf215546Sopenharmony_ci struct radv_sample_locations_state *sample_locs) 640bf215546Sopenharmony_ci{ 641bf215546Sopenharmony_ci struct radv_barrier_data barrier = {0}; 642bf215546Sopenharmony_ci 643bf215546Sopenharmony_ci barrier.layout_transitions.depth_stencil_expand = 1; 644bf215546Sopenharmony_ci radv_describe_layout_transition(cmd_buffer, &barrier); 645bf215546Sopenharmony_ci 646bf215546Sopenharmony_ci if (cmd_buffer->qf == RADV_QUEUE_GENERAL) { 647bf215546Sopenharmony_ci radv_process_depth_stencil(cmd_buffer, image, subresourceRange, sample_locs, DEPTH_DECOMPRESS); 648bf215546Sopenharmony_ci } else { 649bf215546Sopenharmony_ci radv_expand_depth_stencil_compute(cmd_buffer, image, subresourceRange); 650bf215546Sopenharmony_ci } 651bf215546Sopenharmony_ci} 652bf215546Sopenharmony_ci 653bf215546Sopenharmony_civoid 654bf215546Sopenharmony_ciradv_resummarize_depth_stencil(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image, 655bf215546Sopenharmony_ci const VkImageSubresourceRange *subresourceRange, 656bf215546Sopenharmony_ci struct radv_sample_locations_state *sample_locs) 657bf215546Sopenharmony_ci{ 658bf215546Sopenharmony_ci struct radv_barrier_data barrier = {0}; 659bf215546Sopenharmony_ci 660bf215546Sopenharmony_ci barrier.layout_transitions.depth_stencil_resummarize = 1; 661bf215546Sopenharmony_ci radv_describe_layout_transition(cmd_buffer, &barrier); 662bf215546Sopenharmony_ci 663bf215546Sopenharmony_ci assert(cmd_buffer->qf == RADV_QUEUE_GENERAL); 664bf215546Sopenharmony_ci radv_process_depth_stencil(cmd_buffer, image, subresourceRange, sample_locs, DEPTH_RESUMMARIZE); 665bf215546Sopenharmony_ci} 666