radv: Use vk_descriptor_set_layout

Use the common ref counting and the common destroy entrypoint.

Signed-off-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17818>
This commit is contained in:
Konstantin Seurer
2022-07-30 17:35:57 +02:00
committed by Marge Bot
parent da2233a108
commit 19f8d33876
19 changed files with 60 additions and 108 deletions

View File

@@ -428,7 +428,7 @@ radv_destroy_cmd_buffer(struct radv_cmd_buffer *cmd_buffer)
struct radv_descriptor_set_header *set = &cmd_buffer->descriptors[i].push_set.set;
free(set->mapped_ptr);
if (set->layout)
radv_descriptor_set_layout_unref(cmd_buffer->device, set->layout);
vk_descriptor_set_layout_unref(&cmd_buffer->device->vk, &set->layout->vk);
vk_object_base_finish(&set->base);
}
@@ -5294,8 +5294,8 @@ radv_init_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer, struct radv_de
if (set->header.layout != layout) {
if (set->header.layout)
radv_descriptor_set_layout_unref(cmd_buffer->device, set->header.layout);
radv_descriptor_set_layout_ref(layout);
vk_descriptor_set_layout_unref(&cmd_buffer->device->vk, &set->header.layout->vk);
vk_descriptor_set_layout_ref(&layout->vk);
set->header.layout = layout;
}

View File

@@ -107,15 +107,6 @@ radv_mutable_descriptor_type_size_alignment(const VkMutableDescriptorTypeListVAL
return true;
}
void
radv_descriptor_set_layout_destroy(struct radv_device *device,
struct radv_descriptor_set_layout *set_layout)
{
assert(set_layout->ref_cnt == 0);
vk_object_base_finish(&set_layout->base);
vk_free2(&device->vk.alloc, NULL, set_layout);
}
VKAPI_ATTR VkResult VKAPI_CALL
radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
@@ -166,13 +157,10 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
* they are reference counted and may not be destroyed when vkDestroyDescriptorSetLayout is
* called.
*/
set_layout =
vk_zalloc(&device->vk.alloc, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
set_layout = vk_descriptor_set_layout_zalloc(&device->vk, size);
if (!set_layout)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
vk_object_base_init(&device->vk, &set_layout->base, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT);
set_layout->flags = pCreateInfo->flags;
set_layout->layout_size = size;
@@ -197,11 +185,10 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
VkResult result =
vk_create_sorted_bindings(pCreateInfo->pBindings, pCreateInfo->bindingCount, &bindings);
if (result != VK_SUCCESS) {
radv_descriptor_set_layout_destroy(device, set_layout);
vk_descriptor_set_layout_unref(&device->vk, &set_layout->vk);
return vk_error(device, result);
}
set_layout->ref_cnt = 1;
set_layout->binding_count = num_bindings;
set_layout->shader_stages = 0;
set_layout->dynamic_shader_stages = 0;
@@ -365,19 +352,6 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL
radv_DestroyDescriptorSetLayout(VkDevice _device, VkDescriptorSetLayout _set_layout,
const VkAllocationCallbacks *pAllocator)
{
RADV_FROM_HANDLE(radv_device, device, _device);
RADV_FROM_HANDLE(radv_descriptor_set_layout, set_layout, _set_layout);
if (!set_layout)
return;
radv_descriptor_set_layout_unref(device, set_layout);
}
VKAPI_ATTR void VKAPI_CALL
radv_GetDescriptorSetLayoutSupport(VkDevice device,
const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
@@ -517,7 +491,7 @@ radv_pipeline_layout_add_set(struct radv_pipeline_layout *layout, uint32_t set_i
layout->num_sets = MAX2(set_idx + 1, layout->num_sets);
layout->set[set_idx].layout = set_layout;
radv_descriptor_set_layout_ref(set_layout);
vk_descriptor_set_layout_ref(&set_layout->vk);
for (uint32_t b = 0; b < set_layout->binding_count; b++) {
dynamic_offset_count += set_layout->binding[b].array_size * set_layout->binding[b].dynamic_offset_count;
@@ -560,7 +534,7 @@ radv_pipeline_layout_finish(struct radv_device *device, struct radv_pipeline_lay
if (!layout->set[i].layout)
continue;
radv_descriptor_set_layout_unref(device, layout->set[i].layout);
vk_descriptor_set_layout_unref(&device->vk, &layout->set[i].layout->vk);
}
vk_object_base_finish(&layout->base);
@@ -750,7 +724,7 @@ radv_descriptor_set_create(struct radv_device *device, struct radv_descriptor_po
}
pool->entry_count++;
radv_descriptor_set_layout_ref(layout);
vk_descriptor_set_layout_ref(&layout->vk);
*out_set = set;
return VK_SUCCESS;
}
@@ -759,7 +733,7 @@ static void
radv_descriptor_set_destroy(struct radv_device *device, struct radv_descriptor_pool *pool,
struct radv_descriptor_set *set, bool free_bo)
{
radv_descriptor_set_layout_unref(device, set->header.layout);
vk_descriptor_set_layout_unref(&device->vk, &set->header.layout->vk);
if (pool->host_memory_base)
return;

View File

@@ -26,6 +26,7 @@
#include "radv_constants.h"
#include "vulkan/runtime/vk_descriptor_set_layout.h"
#include "vulkan/runtime/vk_object.h"
#include <vulkan/vulkan.h>
@@ -51,10 +52,7 @@ struct radv_descriptor_set_binding_layout {
};
struct radv_descriptor_set_layout {
struct vk_object_base base;
/* Descriptor set layouts can be destroyed at almost any time */
uint32_t ref_cnt;
struct vk_descriptor_set_layout vk;
/* Everything below is hashed and shouldn't contain any pointers. Be careful when modifying this
* structure.

View File

@@ -914,9 +914,9 @@ radv_device_finish_dgc_prepare_state(struct radv_device *device)
&device->meta_state.alloc);
radv_DestroyPipelineLayout(radv_device_to_handle(device),
device->meta_state.dgc_prepare.p_layout, &device->meta_state.alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device),
device->meta_state.dgc_prepare.ds_layout,
&device->meta_state.alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
device->meta_state.dgc_prepare.ds_layout,
&device->meta_state.alloc);
}
VkResult

View File

@@ -647,8 +647,8 @@ radv_device_finish_meta_blit_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->blit.pipeline_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->blit.ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->blit.ds_layout, &state->alloc);
}
static VkResult

View File

@@ -601,9 +601,9 @@ radv_device_finish_meta_blit2d_state(struct radv_device *device)
for (unsigned src = 0; src < BLIT2D_NUM_SRC_TYPES; src++) {
radv_DestroyPipelineLayout(radv_device_to_handle(device),
state->blit2d[log2_samples].p_layouts[src], &state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->blit2d[log2_samples].ds_layouts[src],
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->blit2d[log2_samples].ds_layouts[src],
&state->alloc);
for (unsigned j = 0; j < NUM_META_FS_KEYS; ++j) {
radv_DestroyPipeline(radv_device_to_handle(device),

View File

@@ -198,8 +198,8 @@ radv_device_finish_meta_itob_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->itob.img_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->itob.img_ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->itob.img_ds_layout, &state->alloc);
radv_DestroyPipeline(radv_device_to_handle(device), state->itob.pipeline, &state->alloc);
radv_DestroyPipeline(radv_device_to_handle(device), state->itob.pipeline_3d, &state->alloc);
}
@@ -374,8 +374,8 @@ radv_device_finish_meta_btoi_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->btoi.img_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->btoi.img_ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->btoi.img_ds_layout, &state->alloc);
radv_DestroyPipeline(radv_device_to_handle(device), state->btoi.pipeline, &state->alloc);
radv_DestroyPipeline(radv_device_to_handle(device), state->btoi.pipeline_3d, &state->alloc);
}
@@ -523,8 +523,8 @@ radv_device_finish_meta_btoi_r32g32b32_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->btoi_r32g32b32.img_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->btoi_r32g32b32.img_ds_layout, &state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->btoi_r32g32b32.img_ds_layout, &state->alloc);
radv_DestroyPipeline(radv_device_to_handle(device), state->btoi_r32g32b32.pipeline,
&state->alloc);
}
@@ -718,8 +718,8 @@ radv_device_finish_meta_itoi_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->itoi.img_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->itoi.img_ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->itoi.img_ds_layout, &state->alloc);
for (uint32_t i = 0; i < MAX_SAMPLES_LOG2; ++i) {
radv_DestroyPipeline(radv_device_to_handle(device), state->itoi.pipeline[i], &state->alloc);
@@ -878,8 +878,8 @@ radv_device_finish_meta_itoi_r32g32b32_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->itoi_r32g32b32.img_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->itoi_r32g32b32.img_ds_layout, &state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->itoi_r32g32b32.img_ds_layout, &state->alloc);
radv_DestroyPipeline(radv_device_to_handle(device), state->itoi_r32g32b32.pipeline,
&state->alloc);
}
@@ -1032,8 +1032,8 @@ radv_device_finish_meta_cleari_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->cleari.img_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->cleari.img_ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->cleari.img_ds_layout, &state->alloc);
for (uint32_t i = 0; i < MAX_SAMPLES_LOG2; ++i) {
radv_DestroyPipeline(radv_device_to_handle(device), state->cleari.pipeline[i], &state->alloc);
@@ -1149,8 +1149,8 @@ radv_device_finish_meta_cleari_r32g32b32_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->cleari_r32g32b32.img_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->cleari_r32g32b32.img_ds_layout, &state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->cleari_r32g32b32.img_ds_layout, &state->alloc);
radv_DestroyPipeline(radv_device_to_handle(device), state->cleari_r32g32b32.pipeline,
&state->alloc);
}

View File

@@ -245,8 +245,8 @@ finish_meta_clear_htile_mask_state(struct radv_device *device)
&state->alloc);
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->clear_htile_mask_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->clear_htile_mask_ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->clear_htile_mask_ds_layout, &state->alloc);
}
static void
@@ -260,8 +260,8 @@ finish_meta_clear_dcc_comp_to_single_state(struct radv_device *device)
}
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->clear_dcc_comp_to_single_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->clear_dcc_comp_to_single_ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->clear_dcc_comp_to_single_ds_layout, &state->alloc);
}
void

View File

@@ -37,8 +37,8 @@ radv_device_finish_meta_copy_vrs_htile_state(struct radv_device *device)
&state->alloc);
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->copy_vrs_htile_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->copy_vrs_htile_ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->copy_vrs_htile_ds_layout, &state->alloc);
}
static nir_shader *

View File

@@ -91,8 +91,8 @@ radv_device_finish_meta_dcc_retile_state(struct radv_device *device)
}
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->dcc_retile.p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->dcc_retile.ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->dcc_retile.ds_layout, &state->alloc);
/* Reset for next finish. */
memset(&state->dcc_retile, 0, sizeof(state->dcc_retile));

View File

@@ -320,8 +320,8 @@ radv_device_finish_meta_depth_decomp_state(struct radv_device *device)
state->expand_depth_stencil_compute_pipeline, &state->alloc);
radv_DestroyPipelineLayout(radv_device_to_handle(device),
state->expand_depth_stencil_compute_p_layout, &state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->expand_depth_stencil_compute_ds_layout, &state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->expand_depth_stencil_compute_ds_layout, &state->alloc);
}
VkResult

View File

@@ -635,8 +635,8 @@ radv_device_finish_meta_etc_decode_state(struct radv_device *device)
radv_DestroyPipeline(radv_device_to_handle(device), state->etc_decode.pipeline, &state->alloc);
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->etc_decode.p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->etc_decode.ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->etc_decode.ds_layout, &state->alloc);
}
static VkPipeline

View File

@@ -405,9 +405,9 @@ radv_device_finish_meta_fast_clear_flush_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device),
state->fast_clear_flush.dcc_decompress_compute_p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->fast_clear_flush.dcc_decompress_compute_ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->fast_clear_flush.dcc_decompress_compute_ds_layout,
&state->alloc);
}
static VkResult

View File

@@ -132,8 +132,8 @@ radv_device_finish_meta_fmask_copy_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->fmask_copy.p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->fmask_copy.ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
state->fmask_copy.ds_layout, &state->alloc);
for (uint32_t i = 0; i < MAX_SAMPLES_LOG2; ++i) {
radv_DestroyPipeline(radv_device_to_handle(device), state->fmask_copy.pipeline[i], &state->alloc);

View File

@@ -178,8 +178,8 @@ radv_device_finish_meta_fmask_expand_state(struct radv_device *device)
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->fmask_expand.p_layout,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->fmask_expand.ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->fmask_expand.ds_layout, &state->alloc);
}
static VkResult

View File

@@ -474,8 +474,8 @@ radv_device_finish_meta_resolve_compute_state(struct radv_device *device)
radv_DestroyPipeline(radv_device_to_handle(device), state->resolve_compute.stencil_zero_pipeline,
&state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->resolve_compute.ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->resolve_compute.ds_layout, &state->alloc);
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->resolve_compute.p_layout,
&state->alloc);
}

View File

@@ -601,8 +601,8 @@ radv_device_finish_meta_resolve_fragment_state(struct radv_device *device)
radv_DestroyPipeline(radv_device_to_handle(device),
state->resolve_fragment.stencil_zero_pipeline, &state->alloc);
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device), state->resolve_fragment.ds_layout,
&state->alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(
radv_device_to_handle(device), state->resolve_fragment.ds_layout, &state->alloc);
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->resolve_fragment.p_layout,
&state->alloc);
}

View File

@@ -1047,25 +1047,6 @@ struct radv_descriptor_update_template {
struct radv_descriptor_update_template_entry entry[0];
};
void radv_descriptor_set_layout_destroy(struct radv_device *device,
struct radv_descriptor_set_layout *set_layout);
static inline void
radv_descriptor_set_layout_ref(struct radv_descriptor_set_layout *set_layout)
{
assert(set_layout && set_layout->ref_cnt >= 1);
p_atomic_inc(&set_layout->ref_cnt);
}
static inline void
radv_descriptor_set_layout_unref(struct radv_device *device,
struct radv_descriptor_set_layout *set_layout)
{
assert(set_layout && set_layout->ref_cnt >= 1);
if (p_atomic_dec_zero(&set_layout->ref_cnt))
radv_descriptor_set_layout_destroy(device, set_layout);
}
struct radv_buffer {
struct vk_buffer vk;
@@ -3333,8 +3314,7 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, base, VkDescriptorPool,
VK_OBJECT_TYPE_DESCRIPTOR_POOL)
VK_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, header.base, VkDescriptorSet,
VK_OBJECT_TYPE_DESCRIPTOR_SET)
VK_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, base,
VkDescriptorSetLayout,
VK_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, vk.base, VkDescriptorSetLayout,
VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
VK_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, base,
VkDescriptorUpdateTemplate,

View File

@@ -958,9 +958,9 @@ radv_device_finish_meta_query_state(struct radv_device *device)
&device->meta_state.alloc);
if (device->meta_state.query.ds_layout)
radv_DestroyDescriptorSetLayout(radv_device_to_handle(device),
device->meta_state.query.ds_layout,
&device->meta_state.alloc);
device->vk.dispatch_table.DestroyDescriptorSetLayout(radv_device_to_handle(device),
device->meta_state.query.ds_layout,
&device->meta_state.alloc);
}
static void