From 62bfc700f74971db970748acf8b832dbee4c2805 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alejandro=20Pi=C3=B1eiro?= Date: Sat, 4 Jul 2020 00:54:19 +0200 Subject: [PATCH] vulkan/util: add struct vk_pipeline_cache_header Header is defined at vkGetPipelineCacheData spec, in any vulkan version, and anv, tu and radv were using the same struct, and v3dv was about to do the same. Defining the same struct four times seemed odd, so let's define on a common place. Reviewed-by: Jason Ekstrand Reviewed-by: Bas Nieuwenhuizen Acked-by: Jonathan Marek Part-of: --- src/amd/vulkan/radv_pipeline_cache.c | 13 +++---------- src/freedreno/vulkan/tu_pipeline_cache.c | 14 +++----------- src/intel/vulkan/anv_pipeline_cache.c | 15 ++++----------- src/vulkan/util/vk_util.h | 8 ++++++++ 4 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c index 12657d06819..8cbf312019c 100644 --- a/src/amd/vulkan/radv_pipeline_cache.c +++ b/src/amd/vulkan/radv_pipeline_cache.c @@ -28,6 +28,7 @@ #include "radv_debug.h" #include "radv_private.h" #include "radv_shader.h" +#include "vulkan/util/vk_util.h" #include "ac_nir_to_llvm.h" @@ -452,20 +453,12 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device, return; } -struct cache_header { - uint32_t header_size; - uint32_t header_version; - uint32_t vendor_id; - uint32_t device_id; - uint8_t uuid[VK_UUID_SIZE]; -}; - bool radv_pipeline_cache_load(struct radv_pipeline_cache *cache, const void *data, size_t size) { struct radv_device *device = cache->device; - struct cache_header header; + struct vk_pipeline_cache_header header; if (size < sizeof(header)) return false; @@ -569,7 +562,7 @@ VkResult radv_GetPipelineCacheData( { RADV_FROM_HANDLE(radv_device, device, _device); RADV_FROM_HANDLE(radv_pipeline_cache, cache, _cache); - struct cache_header *header; + struct vk_pipeline_cache_header *header; VkResult result = VK_SUCCESS; radv_pipeline_cache_lock(cache); diff --git a/src/freedreno/vulkan/tu_pipeline_cache.c b/src/freedreno/vulkan/tu_pipeline_cache.c index dd10a9f65bc..10051f40454 100644 --- a/src/freedreno/vulkan/tu_pipeline_cache.c +++ b/src/freedreno/vulkan/tu_pipeline_cache.c @@ -27,6 +27,7 @@ #include "util/disk_cache.h" #include "util/mesa-sha1.h" #include "util/u_atomic.h" +#include "vulkan/util/vk_util.h" struct cache_entry_variant_info { @@ -196,22 +197,13 @@ tu_pipeline_cache_add_entry(struct tu_pipeline_cache *cache, tu_pipeline_cache_set_entry(cache, entry); } -struct cache_header -{ - uint32_t header_size; - uint32_t header_version; - uint32_t vendor_id; - uint32_t device_id; - uint8_t uuid[VK_UUID_SIZE]; -}; - static void tu_pipeline_cache_load(struct tu_pipeline_cache *cache, const void *data, size_t size) { struct tu_device *device = cache->device; - struct cache_header header; + struct vk_pipeline_cache_header header; if (size < sizeof(header)) return; @@ -307,7 +299,7 @@ tu_GetPipelineCacheData(VkDevice _device, { TU_FROM_HANDLE(tu_device, device, _device); TU_FROM_HANDLE(tu_pipeline_cache, cache, _cache); - struct cache_header *header; + struct vk_pipeline_cache_header *header; VkResult result = VK_SUCCESS; pthread_mutex_lock(&cache->mutex); diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c index ac2326c6648..fa9cfe4f777 100644 --- a/src/intel/vulkan/anv_pipeline_cache.c +++ b/src/intel/vulkan/anv_pipeline_cache.c @@ -29,6 +29,7 @@ #include "nir/nir_serialize.h" #include "anv_private.h" #include "nir/nir_xfb_info.h" +#include "vulkan/util/vk_util.h" struct anv_shader_bin * anv_shader_bin_create(struct anv_device *device, @@ -475,14 +476,6 @@ anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache, } } -struct cache_header { - uint32_t header_size; - uint32_t header_version; - uint32_t vendor_id; - uint32_t device_id; - uint8_t uuid[VK_UUID_SIZE]; -}; - static void anv_pipeline_cache_load(struct anv_pipeline_cache *cache, const void *data, size_t size) @@ -496,7 +489,7 @@ anv_pipeline_cache_load(struct anv_pipeline_cache *cache, struct blob_reader blob; blob_reader_init(&blob, data, size); - struct cache_header header; + struct vk_pipeline_cache_header header; blob_copy_bytes(&blob, &header, sizeof(header)); uint32_t count = blob_read_uint32(&blob); if (blob.overrun) @@ -586,8 +579,8 @@ VkResult anv_GetPipelineCacheData( blob_init_fixed(&blob, NULL, SIZE_MAX); } - struct cache_header header = { - .header_size = sizeof(struct cache_header), + struct vk_pipeline_cache_header header = { + .header_size = sizeof(struct vk_pipeline_cache_header), .header_version = VK_PIPELINE_CACHE_HEADER_VERSION_ONE, .vendor_id = 0x8086, .device_id = device->info.chipset_id, diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h index 8ae384b9fb5..1b846b4bed3 100644 --- a/src/vulkan/util/vk_util.h +++ b/src/vulkan/util/vk_util.h @@ -212,6 +212,14 @@ uint32_t vk_get_driver_version(void); uint32_t vk_get_version_override(void); +struct vk_pipeline_cache_header { + uint32_t header_size; + uint32_t header_version; + uint32_t vendor_id; + uint32_t device_id; + uint8_t uuid[VK_UUID_SIZE]; +}; + #define VK_EXT_OFFSET (1000000000UL) #define VK_ENUM_EXTENSION(__enum) \ ((__enum) >= VK_EXT_OFFSET ? ((((__enum) - VK_EXT_OFFSET) / 1000UL) + 1) : 0) -- 2.30.2