From ce054124172584e0412f7b7f34926f0605d6f066 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Mon, 31 Jul 2023 15:49:25 +0200 Subject: [PATCH] radv: add support for a TCS epilogs cache in the device Similar to VS prologs and PS epilogs. Signed-off-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_cmd_buffer.c | 15 +++++++++++++++ src/amd/vulkan/radv_device.c | 33 +++++++++++++++++++++++++++++++++ src/amd/vulkan/radv_private.h | 7 +++++++ 3 files changed, 55 insertions(+) diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c index 738bae7..4f3ddc1 100644 --- a/src/amd/vulkan/radv_cmd_buffer.c +++ b/src/amd/vulkan/radv_cmd_buffer.c @@ -4268,6 +4268,21 @@ lookup_ps_epilog(struct radv_cmd_buffer *cmd_buffer) return epilog_entry->data; } +uint32_t +radv_hash_tcs_epilog(const void *key_) +{ + const struct radv_tcs_epilog_key *key = key_; + return _mesa_hash_data(key, sizeof(*key)); +} + +bool +radv_cmp_tcs_epilog(const void *a_, const void *b_) +{ + const struct radv_tcs_epilog_key *a = a_; + const struct radv_tcs_epilog_key *b = b_; + return memcmp(a, b, sizeof(*a)) == 0; +} + static void radv_emit_msaa_state(struct radv_cmd_buffer *cmd_buffer) { diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 7192967..4e3acd4 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -269,6 +269,30 @@ radv_device_finish_ps_epilogs(struct radv_device *device) } } +static VkResult +radv_device_init_tcs_epilogs(struct radv_device *device) +{ + u_rwlock_init(&device->tcs_epilogs_lock); + + device->tcs_epilogs = _mesa_hash_table_create(NULL, &radv_hash_tcs_epilog, &radv_cmp_tcs_epilog); + if (!device->tcs_epilogs) + return vk_error(device->physical_device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); + + return VK_SUCCESS; +} + +static void +radv_device_finish_tcs_epilogs(struct radv_device *device) +{ + if (device->tcs_epilogs) { + hash_table_foreach (device->tcs_epilogs, entry) { + free((void *)entry->key); + radv_shader_part_unref(device, entry->data); + } + _mesa_hash_table_destroy(device->tcs_epilogs, NULL); + } +} + VkResult radv_device_init_vrs_state(struct radv_device *device) { @@ -654,6 +678,7 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr bool attachment_vrs_enabled = false; bool image_float32_atomics = false; bool vs_prologs = false; + UNUSED bool tcs_epilogs = false; /* TODO: Enable for shader object */ bool ps_epilogs = false; bool global_bo_list = false; bool image_2d_view_of_3d = false; @@ -1038,6 +1063,12 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr goto fail; } + if (tcs_epilogs) { + result = radv_device_init_tcs_epilogs(device); + if (result != VK_SUCCESS) + goto fail; + } + if (ps_epilogs) { result = radv_device_init_ps_epilogs(device); if (result != VK_SUCCESS) @@ -1108,6 +1139,7 @@ fail: radv_device_finish_notifier(device); radv_device_finish_vs_prologs(device); + radv_device_finish_tcs_epilogs(device); radv_device_finish_ps_epilogs(device); radv_device_finish_border_color(device); @@ -1160,6 +1192,7 @@ radv_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator) radv_device_finish_notifier(device); radv_device_finish_vs_prologs(device); + radv_device_finish_tcs_epilogs(device); radv_device_finish_ps_epilogs(device); radv_device_finish_border_color(device); radv_device_finish_vrs_image(device); diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index f58b9ed..587c78f 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -1088,6 +1088,10 @@ struct radv_device { struct u_rwlock ps_epilogs_lock; struct hash_table *ps_epilogs; + /* TCS epilogs */ + struct u_rwlock tcs_epilogs_lock; + struct hash_table *tcs_epilogs; + simple_mtx_t trace_mtx; /* Whether per-vertex VRS is forced. */ @@ -1982,6 +1986,9 @@ struct radv_ps_epilog_key radv_generate_ps_epilog_key(const struct radv_device * const struct radv_ps_epilog_state *state, bool disable_mrt_compaction); +uint32_t radv_hash_tcs_epilog(const void *key_); +bool radv_cmp_tcs_epilog(const void *a_, const void *b_); + bool radv_needs_null_export_workaround(const struct radv_device *device, const struct radv_shader *ps, unsigned custom_blend_mode); -- 2.7.4