radv: rework shaders ref counting
Introduce helpers like for descriptor set layouts. This will also help graphics pipeline libraries. Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Reviewed-By: Tatsuyuki Ishi <ishitatsuyuki@gmail.com> Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17628>
This commit is contained in:

committed by
Marge Bot

parent
6f4b6b4d11
commit
a2b8a92c72
@@ -217,10 +217,10 @@ radv_pipeline_destroy(struct radv_device *device, struct radv_pipeline *pipeline
|
||||
|
||||
for (unsigned i = 0; i < MESA_VULKAN_SHADER_STAGES; ++i)
|
||||
if (pipeline->shaders[i])
|
||||
radv_shader_destroy(device, pipeline->shaders[i]);
|
||||
radv_shader_unref(device, pipeline->shaders[i]);
|
||||
|
||||
if (pipeline->gs_copy_shader)
|
||||
radv_shader_destroy(device, pipeline->gs_copy_shader);
|
||||
radv_shader_unref(device, pipeline->gs_copy_shader);
|
||||
|
||||
if (pipeline->cs.buf)
|
||||
free(pipeline->cs.buf);
|
||||
|
@@ -104,7 +104,7 @@ radv_pipeline_cache_finish(struct radv_pipeline_cache *cache)
|
||||
if (cache->hash_table[i]) {
|
||||
for (int j = 0; j < MESA_VULKAN_SHADER_STAGES; ++j) {
|
||||
if (cache->hash_table[i]->shaders[j])
|
||||
radv_shader_destroy(cache->device, cache->hash_table[i]->shaders[j]);
|
||||
radv_shader_unref(cache->device, cache->hash_table[i]->shaders[j]);
|
||||
}
|
||||
if (cache->hash_table[i]->slab)
|
||||
radv_pipeline_slab_destroy(cache->device, cache->hash_table[i]->slab);
|
||||
@@ -432,7 +432,7 @@ radv_create_shaders_from_pipeline_cache(
|
||||
else {
|
||||
for (int i = 0; i < MESA_VULKAN_SHADER_STAGES; ++i)
|
||||
if (entry->shaders[i])
|
||||
p_atomic_inc(&entry->shaders[i]->ref_count);
|
||||
radv_shader_ref(entry->shaders[i]);
|
||||
p_atomic_inc(&entry->slab->ref_count);
|
||||
}
|
||||
|
||||
@@ -458,10 +458,10 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device, struct radv_pipel
|
||||
if (!entry->shaders[i])
|
||||
continue;
|
||||
|
||||
radv_shader_destroy(cache->device, pipeline->shaders[i]);
|
||||
radv_shader_unref(cache->device, pipeline->shaders[i]);
|
||||
|
||||
pipeline->shaders[i] = entry->shaders[i];
|
||||
p_atomic_inc(&pipeline->shaders[i]->ref_count);
|
||||
radv_shader_ref(pipeline->shaders[i]);
|
||||
}
|
||||
|
||||
radv_pipeline_slab_destroy(cache->device, pipeline->slab);
|
||||
@@ -548,7 +548,7 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device, struct radv_pipel
|
||||
continue;
|
||||
|
||||
entry->shaders[i] = pipeline->shaders[i];
|
||||
p_atomic_inc(&pipeline->shaders[i]->ref_count);
|
||||
radv_shader_ref(pipeline->shaders[i]);
|
||||
}
|
||||
|
||||
entry->slab = pipeline->slab;
|
||||
|
@@ -1955,7 +1955,7 @@ radv_shader_binary_upload(struct radv_device *device, const struct radv_shader_b
|
||||
};
|
||||
|
||||
if (!ac_rtld_upload(&info)) {
|
||||
radv_shader_destroy(device, shader);
|
||||
radv_shader_unref(device, shader);
|
||||
ac_rtld_close(&rtld_binary);
|
||||
return false;
|
||||
}
|
||||
@@ -2048,7 +2048,7 @@ radv_shader_create(struct radv_device *device, const struct radv_shader_binary *
|
||||
size_t disasm_size;
|
||||
if (!ac_rtld_get_section_by_name(&rtld_binary, ".AMDGPU.disasm", &disasm_data,
|
||||
&disasm_size)) {
|
||||
radv_shader_destroy(device, shader);
|
||||
radv_shader_unref(device, shader);
|
||||
ac_rtld_close(&rtld_binary);
|
||||
return NULL;
|
||||
}
|
||||
@@ -2503,8 +2503,7 @@ radv_create_ps_epilog(struct radv_device *device, const struct radv_ps_epilog_ke
|
||||
void
|
||||
radv_shader_destroy(struct radv_device *device, struct radv_shader *shader)
|
||||
{
|
||||
if (!p_atomic_dec_zero(&shader->ref_count))
|
||||
return;
|
||||
assert(shader->ref_count == 0);
|
||||
|
||||
free(shader->spirv);
|
||||
free(shader->nir_string);
|
||||
|
@@ -621,6 +621,22 @@ bool radv_can_dump_shader_stats(struct radv_device *device, nir_shader *nir);
|
||||
VkResult radv_dump_shader_stats(struct radv_device *device, struct radv_pipeline *pipeline,
|
||||
gl_shader_stage stage, FILE *output);
|
||||
|
||||
static inline struct radv_shader *
|
||||
radv_shader_ref(struct radv_shader *shader)
|
||||
{
|
||||
assert(shader && shader->ref_count >= 1);
|
||||
p_atomic_inc(&shader->ref_count);
|
||||
return shader;
|
||||
}
|
||||
|
||||
static inline void
|
||||
radv_shader_unref(struct radv_device *device, struct radv_shader *shader)
|
||||
{
|
||||
assert(shader && shader->ref_count >= 1);
|
||||
if (p_atomic_dec_zero(&shader->ref_count))
|
||||
radv_shader_destroy(device, shader);
|
||||
}
|
||||
|
||||
static inline unsigned
|
||||
calculate_tess_lds_size(enum amd_gfx_level gfx_level, unsigned tcs_num_input_vertices,
|
||||
unsigned tcs_num_output_vertices, unsigned tcs_num_inputs,
|
||||
|
Reference in New Issue
Block a user