tests: Add PhysicalDeviceFormatProperties dev_profile
authorTony Barbour <tony@LunarG.com>
Thu, 27 Jul 2017 23:12:20 +0000 (17:12 -0600)
committerTony-LunarG <tony@lunarg.com>
Fri, 4 Aug 2017 15:54:54 +0000 (09:54 -0600)
Add spoofing PhysicalDeviceFormatProperties to the
device_profile_api layer

Add the following to ExceedMemoryAllocationCount to test:

PFN_vkSetPhysicalDeviceFormatPropertiesEXT fpvkSetPhysicalDeviceFormatPropertiesEXT =
    (PFN_vkSetPhysicalDeviceFormatPropertiesEXT)vkGetInstanceProcAddr(instance(), "vkSetPhysicalDeviceFormatPropertiesEXT");
PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT =
    (PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT)vkGetInstanceProcAddr(instance(), "vkGetOriginalPhysicalDeviceFormatPropertiesEXT");

VkFormatProperties formatProps;
fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &formatProps);
assert(!(formatProps.bufferFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT));
formatProps.bufferFeatures |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_B8G8R8A8_UNORM, formatProps);
memset(&formatProps, 0, sizeof(formatProps));
vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &formatProps);
assert(formatProps.bufferFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);

Change-Id: I46fe6a8ade59043b36c7f1baa5d613201692d5c0

tests/layers/device_profile_api.cpp
tests/layers/vk_device_profile_api_layer.h
tests/layers/vk_lunarg_device_profile_api_layer.h

index 40d28af..d203bd5 100644 (file)
@@ -38,6 +38,7 @@ static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION
 struct device_data {
     VkInstance instance;
     VkPhysicalDeviceProperties phy_device_props;
+    std::unordered_map<VkFormat, VkFormatProperties, std::hash<int> > format_properties_map;
 };
 
 static std::unordered_map<VkPhysicalDevice, struct device_data> device_profile_api_dev_data_map;
@@ -45,8 +46,11 @@ static std::unordered_map<VkPhysicalDevice, struct device_data> device_profile_a
 // device_profile_api Layer EXT APIs
 typedef void(VKAPI_PTR *PFN_vkGetOriginalPhysicalDeviceLimitsEXT)(VkPhysicalDevice physicalDevice,
                                                                   const VkPhysicalDeviceLimits *limits);
-
 typedef void(VKAPI_PTR *PFN_vkSetPhysicalDeviceLimitsEXT)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceLimits *newLimits);
+typedef void(VKAPI_PTR *PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT)(VkPhysicalDevice physicalDevice, VkFormat format,
+                                                                            const VkFormatProperties *properties);
+typedef void(VKAPI_PTR *PFN_vkSetPhysicalDeviceFormatPropertiesEXT)(VkPhysicalDevice physicalDevice, VkFormat format,
+                                                                    const VkFormatProperties newProperties);
 
 VKAPI_ATTR void VKAPI_CALL GetOriginalPhysicalDeviceLimitsEXT(VkPhysicalDevice physicalDevice, VkPhysicalDeviceLimits *orgLimits) {
     std::lock_guard<std::mutex> lock(global_lock);
@@ -72,6 +76,29 @@ VKAPI_ATTR void VKAPI_CALL SetPhysicalDeviceLimitsEXT(VkPhysicalDevice physicalD
     }
 }
 
+VKAPI_ATTR void VKAPI_CALL GetOriginalPhysicalDeviceFormatPropertiesEXT(VkPhysicalDevice physicalDevice, VkFormat format,
+                                                                        VkFormatProperties *properties) {
+    std::lock_guard<std::mutex> lock(global_lock);
+    auto device_profile_api_data_it = device_profile_api_dev_data_map.find(physicalDevice);
+    if (device_profile_api_data_it != device_profile_api_dev_data_map.end()) {
+        layer_data *device_profile_data =
+            GetLayerDataPtr(get_dispatch_key(device_profile_api_dev_data_map[physicalDevice].instance), layer_data_map);
+        device_profile_data->instance_dispatch_table->GetPhysicalDeviceFormatProperties(physicalDevice, format, properties);
+    }
+}
+
+VKAPI_ATTR void VKAPI_CALL SetPhysicalDeviceFormatPropertiesEXT(VkPhysicalDevice physicalDevice, VkFormat format,
+                                                                const VkFormatProperties newProperties) {
+    std::lock_guard<std::mutex> lock(global_lock);
+
+    // search if we got the device limits for this device and stored in device_profile_api layer
+    auto device_profile_api_data_it = device_profile_api_dev_data_map.find(physicalDevice);
+    if (device_profile_api_data_it != device_profile_api_dev_data_map.end()) {
+        memcpy(&(device_profile_api_dev_data_map[physicalDevice].format_properties_map[format]), &newProperties,
+               sizeof(VkFormatProperties));
+    }
+}
+
 VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
                                               VkInstance *pInstance) {
     VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
@@ -126,6 +153,28 @@ VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties(VkPhysicalDevice physical
     }
 }
 
+VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
+                                                             VkFormatProperties *pProperties) {
+    {
+        std::lock_guard<std::mutex> lock(global_lock);
+
+        // Search if we got the device limits for this device and stored in device_profile_api layer
+        auto device_profile_api_data_it = device_profile_api_dev_data_map.find(physicalDevice);
+        if (device_profile_api_data_it != device_profile_api_dev_data_map.end()) {
+            auto device_format_map_it = device_profile_api_dev_data_map[physicalDevice].format_properties_map.find(format);
+            if (device_format_map_it != device_profile_api_dev_data_map[physicalDevice].format_properties_map.end()) {
+                memcpy(pProperties, &device_profile_api_dev_data_map[physicalDevice].format_properties_map[format],
+                       sizeof(VkFormatProperties));
+            } else {
+                layer_data *device_profile_data =
+                    GetLayerDataPtr(get_dispatch_key(device_profile_api_dev_data_map[physicalDevice].instance), layer_data_map);
+                device_profile_data->instance_dispatch_table->GetPhysicalDeviceFormatProperties(physicalDevice, format,
+                                                                                                pProperties);
+            }
+        }
+    }
+}
+
 static const VkLayerProperties device_profile_api_LayerProps = {
     "VK_LAYER_LUNARG_device_profile_api", VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION),  // specVersion
     1,                                                                  // implementationVersion
@@ -166,6 +215,9 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance in
 
     if (!strcmp(name, "vkSetPhysicalDeviceLimitsEXT")) return (PFN_vkVoidFunction)SetPhysicalDeviceLimitsEXT;
     if (!strcmp(name, "vkGetOriginalPhysicalDeviceLimitsEXT")) return (PFN_vkVoidFunction)GetOriginalPhysicalDeviceLimitsEXT;
+    if (!strcmp(name, "vkSetPhysicalDeviceFormatPropertiesEXT")) return (PFN_vkVoidFunction)SetPhysicalDeviceFormatPropertiesEXT;
+    if (!strcmp(name, "vkGetOriginalPhysicalDeviceFormatPropertiesEXT"))
+        return (PFN_vkVoidFunction)GetOriginalPhysicalDeviceFormatPropertiesEXT;
     if (instance_dispatch_table(instance)->GetPhysicalDeviceProcAddr == NULL) return NULL;
     return instance_dispatch_table(instance)->GetPhysicalDeviceProcAddr(instance, name);
 
@@ -175,11 +227,15 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance
 
     if (!strcmp(name, "vkCreateInstance")) return (PFN_vkVoidFunction)CreateInstance;
     if (!strcmp(name, "vkGetPhysicalDeviceProperties")) return (PFN_vkVoidFunction)GetPhysicalDeviceProperties;
+    if (!strcmp(name, "vkGetPhysicalDeviceFormatProperties")) return (PFN_vkVoidFunction)GetPhysicalDeviceFormatProperties;
     if (!strcmp(name, "vkGetInstanceProcAddr")) return (PFN_vkVoidFunction)GetInstanceProcAddr;
     if (!strcmp(name, "vkEnumerateInstanceExtensionProperties")) return (PFN_vkVoidFunction)EnumerateInstanceExtensionProperties;
     if (!strcmp(name, "vkEnumerateInstanceLayerProperties")) return (PFN_vkVoidFunction)EnumerateInstanceLayerProperties;
     if (!strcmp(name, "vkSetPhysicalDeviceLimitsEXT")) return (PFN_vkVoidFunction)SetPhysicalDeviceLimitsEXT;
     if (!strcmp(name, "vkGetOriginalPhysicalDeviceLimitsEXT")) return (PFN_vkVoidFunction)GetOriginalPhysicalDeviceLimitsEXT;
+    if (!strcmp(name, "vkSetPhysicalDeviceFormatPropertiesEXT")) return (PFN_vkVoidFunction)SetPhysicalDeviceFormatPropertiesEXT;
+    if (!strcmp(name, "vkGetOriginalPhysicalDeviceFormatPropertiesEXT"))
+        return (PFN_vkVoidFunction)GetOriginalPhysicalDeviceFormatPropertiesEXT;
 
     assert(instance);
 
index f95ebd6..8a71aa3 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "vk_lunarg_device_profile_api_layer.h"
 
-typedef struct VkLayerDeviceProfileApifDispatchTable_ {
+typedef struct VkLayerDeviceProfileApiDispatchTable_ {
     PFN_vkSetPhysicalDeviceLimitsEXT vkSetPhysicalDeviceLimitsEXT;
     PFN_vkGetOriginalPhysicalDeviceLimitsEXT vkGetOriginalPhysicalDeviceLimitsEXT;
 } VkLayerDeviceProfileApiDispatchTable;
index 631a30f..07e6c83 100644 (file)
@@ -36,6 +36,10 @@ extern "C" {
 typedef void(VKAPI_PTR *PFN_vkSetPhysicalDeviceLimitsEXT)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceLimits *newLimits);
 typedef void(VKAPI_PTR *PFN_vkGetOriginalPhysicalDeviceLimitsEXT)(VkPhysicalDevice physicalDevice,
                                                                   const VkPhysicalDeviceLimits *orgLimits);
+typedef void(VKAPI_PTR *PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT)(VkPhysicalDevice physicalDevice, VkFormat format,
+                                                                            const VkFormatProperties *properties);
+typedef void(VKAPI_PTR *PFN_vkSetPhysicalDeviceFormatPropertiesEXT)(VkPhysicalDevice physicalDevice, VkFormat format,
+                                                                    const VkFormatProperties newProperties);
 #ifdef __cplusplus
 }  // extern "C"
 #endif  // __cplusplus