VK_KHR_maintenance4 support

VK_KHR_maintenance4 adds a collection of minor features, including
3 new functions used to query the memory requirements without
having to create an object and query it.

Tests: dEQP-VK.api.buffer_memory_requirements.*.size_req_*
Tests: dEQP-VK.api.buffer.basic.*
Tests: dEQP-VK.api.info.vulkan1p3_limits_validation.khr_maintenance4
Tests: dEQP-VK.api.invariance.memory_requirements_matching
Tests: dEQP-VK.api.pipeline.pipeline_layout.lifetime.destroy_after_compute_pipeline_construction
Tests: dEQP-VK.api.pipeline.pipeline_layout.lifetime.destroy_after_graphics_pipeline_construction
Tests: dEQP-VK.pipeline.interface_matching.*
Tests: dEQP-VK.pipeline.push_constant.*
Tests: dEQP-VK.spirv_assembly.instruction.compute.localsize_id.*
Bug: b/204502926
Change-Id: Ib8ed96370b1fdc9981981e484ddb25bcdc1a4eee
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/63228
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
Commit-Queue: Alexis Hétu <sugoi@google.com>
diff --git a/src/Vulkan/VkGetProcAddress.cpp b/src/Vulkan/VkGetProcAddress.cpp
index a817211..b35267c 100644
--- a/src/Vulkan/VkGetProcAddress.cpp
+++ b/src/Vulkan/VkGetProcAddress.cpp
@@ -396,6 +396,14 @@
 	    {
 	        MAKE_VULKAN_DEVICE_ENTRY(vkGetDescriptorSetLayoutSupportKHR),
 	    } },
+	// VK_KHR_maintenance4
+	{
+	    VK_KHR_MAINTENANCE_4_EXTENSION_NAME,
+	    {
+	        MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceBufferMemoryRequirementsKHR),
+	        MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceImageMemoryRequirementsKHR),
+	        MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceImageSparseMemoryRequirementsKHR),
+	    } },
 	// VK_KHR_create_renderpass2
 	{
 	    VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME,
diff --git a/src/Vulkan/VkPhysicalDevice.cpp b/src/Vulkan/VkPhysicalDevice.cpp
index 3bf3f5c..0c04adf 100644
--- a/src/Vulkan/VkPhysicalDevice.cpp
+++ b/src/Vulkan/VkPhysicalDevice.cpp
@@ -692,11 +692,22 @@
 	properties->maxPerSetDescriptors = 1024;
 }
 
+template<typename T>
+static void getMaintenance4Properties(T *properties)
+{
+	properties->maxBufferSize = MAX_MEMORY_ALLOCATION_SIZE;
+}
+
 void PhysicalDevice::getProperties(VkPhysicalDeviceMaintenance3Properties *properties) const
 {
 	getMaintenance3Properties(properties);
 }
 
+void PhysicalDevice::getProperties(VkPhysicalDeviceMaintenance4Properties *properties) const
+{
+	getMaintenance4Properties(properties);
+}
+
 template<typename T>
 static void getMultiviewProperties(T *properties)
 {
diff --git a/src/Vulkan/VkPhysicalDevice.hpp b/src/Vulkan/VkPhysicalDevice.hpp
index d471445..6307ccd 100644
--- a/src/Vulkan/VkPhysicalDevice.hpp
+++ b/src/Vulkan/VkPhysicalDevice.hpp
@@ -52,6 +52,7 @@
 	const VkPhysicalDeviceProperties &getProperties() const;
 	void getProperties(VkPhysicalDeviceIDProperties *properties) const;
 	void getProperties(VkPhysicalDeviceMaintenance3Properties *properties) const;
+	void getProperties(VkPhysicalDeviceMaintenance4Properties *properties) const;
 	void getProperties(VkPhysicalDeviceMultiviewProperties *properties) const;
 	void getProperties(VkPhysicalDevicePointClippingProperties *properties) const;
 	void getProperties(VkPhysicalDeviceProtectedMemoryProperties *properties) const;
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp
index f579fb7..b8bdc8e 100644
--- a/src/Vulkan/libVulkan.cpp
+++ b/src/Vulkan/libVulkan.cpp
@@ -425,6 +425,7 @@
 	{ { VK_KHR_COPY_COMMANDS_2_EXTENSION_NAME, VK_KHR_COPY_COMMANDS_2_SPEC_VERSION } },
 	{ { VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME, VK_KHR_DYNAMIC_RENDERING_SPEC_VERSION } },
 	{ { VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME, VK_KHR_FORMAT_FEATURE_FLAGS_2_SPEC_VERSION } },
+	{ { VK_KHR_MAINTENANCE_4_EXTENSION_NAME, VK_KHR_MAINTENANCE_4_SPEC_VERSION } },
 	{ { VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, VK_KHR_SHADER_NON_SEMANTIC_INFO_SPEC_VERSION } },
 	{ { VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, VK_KHR_SYNCHRONIZATION_2_SPEC_VERSION } },
 	{ { VK_KHR_ZERO_INITIALIZE_WORKGROUP_MEMORY_EXTENSION_NAME, VK_KHR_ZERO_INITIALIZE_WORKGROUP_MEMORY_SPEC_VERSION } },
@@ -3437,6 +3438,12 @@
 				vk::Cast(physicalDevice)->getProperties(properties);
 			}
 			break;
+		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_4_PROPERTIES:
+			{
+				auto properties = reinterpret_cast<VkPhysicalDeviceMaintenance4Properties *>(extensionProperties);
+				vk::Cast(physicalDevice)->getProperties(properties);
+			}
+			break;
 		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES:
 			{
 				auto properties = reinterpret_cast<VkPhysicalDeviceMultiviewProperties *>(extensionProperties);