Mesa (main): venus: cache VkFormatProperties
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat Feb 19 04:06:07 UTC 2022
Module: Mesa
Branch: main
Commit: 7cb2e9a8f073a6083e2b1dcaa025229ca337e517
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7cb2e9a8f073a6083e2b1dcaa025229ca337e517
Author: Chia-I Wu <olvaffe at gmail.com>
Date: Wed Feb 9 14:38:29 2022 -0800
venus: cache VkFormatProperties
This is for fossilize-replay which keeps querying for the same formats.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14966>
---
src/virtio/vulkan/vn_physical_device.c | 54 ++++++++++++++++++++++++++++++++--
src/virtio/vulkan/vn_physical_device.h | 10 +++++++
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/src/virtio/vulkan/vn_physical_device.c b/src/virtio/vulkan/vn_physical_device.c
index 8a53d57045f..474a62c5a38 100644
--- a/src/virtio/vulkan/vn_physical_device.c
+++ b/src/virtio/vulkan/vn_physical_device.c
@@ -1166,6 +1166,10 @@ vn_physical_device_init(struct vn_physical_device *physical_dev)
if (result != VK_SUCCESS)
goto fail;
+ simple_mtx_init(&physical_dev->format_update_mutex, mtx_plain);
+ util_sparse_array_init(&physical_dev->format_properties,
+ sizeof(struct vn_format_properties_entry), 64);
+
return VK_SUCCESS;
fail:
@@ -1180,6 +1184,9 @@ vn_physical_device_fini(struct vn_physical_device *physical_dev)
struct vn_instance *instance = physical_dev->instance;
const VkAllocationCallbacks *alloc = &instance->base.base.alloc;
+ simple_mtx_destroy(&physical_dev->format_update_mutex);
+ util_sparse_array_finish(&physical_dev->format_properties);
+
vn_wsi_fini(physical_dev);
vk_free(alloc, physical_dev->extension_spec_versions);
vk_free(alloc, physical_dev->queue_family_properties);
@@ -1574,6 +1581,27 @@ vn_GetPhysicalDeviceMemoryProperties(
*pMemoryProperties = physical_dev->memory_properties.memoryProperties;
}
+static struct vn_format_properties_entry *
+vn_physical_device_get_format_properties(
+ struct vn_physical_device *physical_dev, VkFormat format)
+{
+ return util_sparse_array_get(&physical_dev->format_properties, format);
+}
+
+static void
+vn_physical_device_add_format_properties(
+ struct vn_physical_device *physical_dev,
+ struct vn_format_properties_entry *entry,
+ const VkFormatProperties *props)
+{
+ simple_mtx_lock(&physical_dev->format_update_mutex);
+ if (!entry->valid) {
+ entry->properties = *props;
+ entry->valid = true;
+ }
+ simple_mtx_unlock(&physical_dev->format_update_mutex);
+}
+
void
vn_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
VkFormat format,
@@ -1581,10 +1609,19 @@ vn_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
{
struct vn_physical_device *physical_dev =
vn_physical_device_from_handle(physicalDevice);
+ struct vn_format_properties_entry *entry =
+ vn_physical_device_get_format_properties(physical_dev, format);
+
+ if (entry->valid) {
+ *pFormatProperties = entry->properties;
+ return;
+ }
- /* TODO query all formats during init */
vn_call_vkGetPhysicalDeviceFormatProperties(
physical_dev->instance, physicalDevice, format, pFormatProperties);
+
+ vn_physical_device_add_format_properties(physical_dev, entry,
+ pFormatProperties);
}
VkResult
@@ -2137,9 +2174,22 @@ vn_GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice,
struct vn_physical_device *physical_dev =
vn_physical_device_from_handle(physicalDevice);
- /* TODO query all formats during init */
+ struct vn_format_properties_entry *entry = NULL;
+ if (!pFormatProperties->pNext) {
+ entry = vn_physical_device_get_format_properties(physical_dev, format);
+ if (entry->valid) {
+ pFormatProperties->formatProperties = entry->properties;
+ return;
+ }
+ }
+
vn_call_vkGetPhysicalDeviceFormatProperties2(
physical_dev->instance, physicalDevice, format, pFormatProperties);
+
+ if (entry) {
+ vn_physical_device_add_format_properties(
+ physical_dev, entry, &pFormatProperties->formatProperties);
+ }
}
struct vn_physical_device_image_format_info {
diff --git a/src/virtio/vulkan/vn_physical_device.h b/src/virtio/vulkan/vn_physical_device.h
index a6d08adc8a2..f614ca46343 100644
--- a/src/virtio/vulkan/vn_physical_device.h
+++ b/src/virtio/vulkan/vn_physical_device.h
@@ -13,8 +13,15 @@
#include "vn_common.h"
+#include "util/sparse_array.h"
+
#include "vn_wsi.h"
+struct vn_format_properties_entry {
+ atomic_bool valid;
+ VkFormatProperties properties;
+};
+
struct vn_physical_device {
struct vn_physical_device_base base;
@@ -69,6 +76,9 @@ struct vn_physical_device {
VkExternalSemaphoreHandleTypeFlags external_timeline_semaphore_handles;
struct wsi_device wsi_device;
+
+ simple_mtx_t format_update_mutex;
+ struct util_sparse_array format_properties;
};
VK_DEFINE_HANDLE_CASTS(vn_physical_device,
base.base.base,
More information about the mesa-commit
mailing list