intel: Removed ICD validation checks from img.c
authorMark Lobodzinski <mark@lunarg.com>
Tue, 22 Sep 2015 15:33:21 +0000 (09:33 -0600)
committerMark Lobodzinski <mark@lunarg.com>
Tue, 22 Sep 2015 22:43:33 +0000 (16:43 -0600)
Moved validation into device_limits layer, created layer utils
files for format utilities, added validation tests, updated validation
doc, updated test framework to call GetPhysicalDeviceProperties.

layers/CMakeLists.txt
layers/device_limits.cpp
layers/device_limits.h
layers/vk_layer_utils.cpp [new file with mode: 0644]
layers/vk_layer_utils.h [new file with mode: 0644]
layers/vk_validation_layer_details.md

index 500f2dc10351fa0a891c00bc620742c77defe8d9..c7ab0082cea477d01646efcc0b64ed72a0a532bc 100644 (file)
@@ -128,9 +128,9 @@ run_vk_layer_generate(APIDump api_dump.cpp)
 run_vk_layer_generate(ObjectTracker object_track.cpp)
 run_vk_layer_generate(Threading threading.cpp)
 
-add_library(layer_utils SHARED vk_layer_config.cpp vk_layer_extension_utils.cpp)
+add_library(layer_utils SHARED vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp)
 if (WIN32)
-    add_library(layer_utils_static STATIC vk_layer_config.cpp vk_layer_extension_utils.cpp)
+    add_library(layer_utils_static STATIC vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp)
     set_target_properties(layer_utils_static PROPERTIES OUTPUT_NAME layer_utils)
     target_link_libraries(layer_utils)
 else()
@@ -140,7 +140,7 @@ endif()
 add_vk_layer(Basic basic.cpp vk_layer_table.cpp)
 add_vk_layer(Multi multi.cpp vk_layer_table.cpp)
 add_vk_layer(DrawState draw_state.cpp vk_layer_debug_marker_table.cpp vk_layer_table.cpp)
-add_vk_layer(DeviceLimits device_limits.cpp vk_layer_debug_marker_table.cpp vk_layer_table.cpp)
+add_vk_layer(DeviceLimits device_limits.cpp vk_layer_debug_marker_table.cpp vk_layer_table.cpp vk_layer_utils.cpp)
 add_vk_layer(MemTracker mem_tracker.cpp vk_layer_table.cpp)
 add_vk_layer(ShaderChecker shader_checker.cpp vk_layer_table.cpp)
 add_vk_layer(Image image.cpp vk_layer_table.cpp)
index add4afc998ab22fc77d133c517a49a592f468793..ab788ec7642dee95dda4ca011279d86ef2947524 100644 (file)
@@ -50,6 +50,7 @@
 #include "vk_layer_data.h"
 #include "vk_layer_logging.h"
 #include "vk_layer_extension_utils.h"
+#include "vk_layer_utils.h"
 
 typedef struct _layer_data {
     debug_report_data *report_data;
@@ -62,11 +63,12 @@ static device_table_map device_limits_device_table_map;
 static instance_table_map device_limits_instance_table_map;
 
 // Track state of each instance
-unordered_map<VkInstance, unique_ptr<INSTANCE_STATE>> instanceMap;
-unordered_map<VkPhysicalDevice, unique_ptr<PHYSICAL_DEVICE_STATE>> physicalDeviceMap;
+unordered_map<VkInstance,       unique_ptr<INSTANCE_STATE>>                                   instanceMap;
+unordered_map<VkPhysicalDevice, unique_ptr<PHYSICAL_DEVICE_STATE>>                            physicalDeviceMap;
 unordered_map<VkPhysicalDevice, unordered_map<uint32_t, unique_ptr<VkQueueFamilyProperties>>> queueFamilyPropertiesMap;
-unordered_map<VkPhysicalDevice, unique_ptr<VkPhysicalDeviceFeatures>> physicalDeviceFeaturesMap;
-unordered_map<VkDevice, VkPhysicalDevice> deviceMap;
+unordered_map<VkPhysicalDevice, unique_ptr<VkPhysicalDeviceFeatures>>                         physicalDeviceFeaturesMap;
+unordered_map<VkPhysicalDevice, unique_ptr<VkPhysicalDeviceProperties>>                       physicalDevicePropertiesMap;
+unordered_map<VkDevice,         VkPhysicalDevice>                                             deviceMap;
 
 struct devExts {
     bool debug_marker_enabled;
@@ -207,18 +209,23 @@ VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, u
 
 VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
 {
+    VkResult result = VK_SUCCESS;
     auto it = physicalDeviceMap.find(physicalDevice);
     if (it != physicalDeviceMap.end()) {
-        VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
+        result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
         // Save Features
-        physicalDeviceFeaturesMap[physicalDevice] = unique_ptr<VkPhysicalDeviceFeatures>(new VkPhysicalDeviceFeatures(*pFeatures));
-        return result;
+        if (VK_SUCCESS == result) {
+            physicalDeviceFeaturesMap[physicalDevice] =
+                unique_ptr<VkPhysicalDeviceFeatures>(new VkPhysicalDeviceFeatures(*pFeatures));
+        }
     }
+    return result;
 }
 
 VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
 {
-    VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFormatProperties(physicalDevice, format, pFormatProperties);
+    VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFormatProperties(
+                                         physicalDevice, format, pFormatProperties);
     return result;
 }
 
@@ -230,7 +237,17 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysic
 
 VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
 {
-    VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceProperties(physicalDevice, pProperties);
+    VkResult result = VK_SUCCESS;
+    auto it = physicalDeviceMap.find(physicalDevice);
+    if (it != physicalDeviceMap.end()) {
+        result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->
+                                    GetPhysicalDeviceProperties(physicalDevice, pProperties);
+        if (VK_SUCCESS == result) {
+            // Save Properties
+            physicalDevicePropertiesMap[physicalDevice] =
+                unique_ptr<VkPhysicalDeviceProperties>(new VkPhysicalDeviceProperties(*pProperties));
+        }
+    }
     return result;
 }
 
@@ -423,6 +440,66 @@ VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueF
     return result;
 }
 
+VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
+    VkDevice                 device,
+    const VkImageCreateInfo *pCreateInfo,
+    VkImage                 *pImage)
+{
+    VkBool32                skipCall       = VK_FALSE;
+    VkResult                result         = VK_ERROR_VALIDATION_FAILED;
+    VkPhysicalDevice        physicalDevice = deviceMap[device];
+    VkImageType             type;
+    VkImageFormatProperties ImageFormatProperties = {0};
+
+    // Internal call to get format info.  Still goes through layers, could potentially go directly to ICD.
+    get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceImageFormatProperties(
+                       physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
+                       pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
+
+    auto pdp_it = physicalDevicePropertiesMap.find(physicalDevice);
+    if (pdp_it == physicalDevicePropertiesMap.end()) {
+        skipCall = log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
+                       DEVLIMITS_MUST_QUERY_PROPERTIES, "DL",
+                       "CreateImage called before querying device properties ");
+    }
+    uint32_t imageGranularity = pdp_it->second->limits.bufferImageGranularity;
+    imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
+
+    if ((pCreateInfo->extent.depth  > ImageFormatProperties.maxExtent.depth)  ||
+        (pCreateInfo->extent.width  > ImageFormatProperties.maxExtent.width)  ||
+        (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
+        skipCall = log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
+                       DEVLIMITS_LIMITS_VIOLATION, "DL",
+                       "CreateImage extents exceed allowable limits for format: "
+                       "Width = %d Height = %d Depth = %d:  Limits for Width = %d Height = %d Depth = %d for format %s.",
+                       pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
+                       ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
+                       string_VkFormat(pCreateInfo->format));
+
+    }
+
+    uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width               *
+                          (uint64_t)pCreateInfo->extent.height              *
+                          (uint64_t)pCreateInfo->extent.depth               *
+                          (uint64_t)pCreateInfo->arraySize                  *
+                          (uint64_t)pCreateInfo->samples                    *
+                          (uint64_t)vk_format_get_size(pCreateInfo->format) +
+                          (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
+
+    if (totalSize > ImageFormatProperties.maxResourceSize) {
+        skipCall = log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
+                       DEVLIMITS_LIMITS_VIOLATION, "DL",
+                       "CreateImage resource size exceeds allowable maximum "
+                       "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
+                       totalSize, ImageFormatProperties.maxResourceSize);
+    }
+    if (VK_FALSE == skipCall) {
+        result = get_dispatch_table(device_limits_device_table_map, device)->CreateImage(device, pCreateInfo, pImage);
+    }
+    return result;
+}
+
+
 VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
     VkInstance                          instance,
     VkFlags                             msgFlags,
@@ -518,6 +595,10 @@ VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const
         return (PFN_vkVoidFunction) vkDestroyRenderPass;
     if (!strcmp(funcName, "vkCreateBufferView"))
         return (PFN_vkVoidFunction) vkCreateBufferView;
+*/
+    if (!strcmp(funcName, "vkCreateImage"))
+        return (PFN_vkVoidFunction) vkCreateImage;
+/*
     if (!strcmp(funcName, "vkCreateImageView"))
         return (PFN_vkVoidFunction) vkCreateImageView;
     if (!strcmp(funcName, "CreatePipelineCache"))
index d9636648ab34267184a8021a0ebfefe46568faf4..6f11c23b91b51fd497b0eb83a49a214c2efd7907 100644 (file)
@@ -34,8 +34,10 @@ typedef enum _DEV_LIMITS_ERROR
     DEVLIMITS_INVALID_INSTANCE,                 // Invalid instance used
     DEVLIMITS_INVALID_PHYSICAL_DEVICE,          // Invalid physical device used
     DEVLIMITS_MUST_QUERY_COUNT,                 // Failed to make initial call to an API to query the count
+    DEVLIMITS_MUST_QUERY_PROPERTIES,            // Failed to make initial call to an API to query properties
     DEVLIMITS_COUNT_MISMATCH,                   // App requesting a count value different than actual value
     DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,     // Invalid queue requested based on queue family properties
+    DEVLIMITS_LIMITS_VIOLATION,                 // Driver-specified limits/properties were exceeded
 } DEV_LIMITS_ERROR;
 
 typedef enum _CALL_STATE
diff --git a/layers/vk_layer_utils.cpp b/layers/vk_layer_utils.cpp
new file mode 100644 (file)
index 0000000..c4d10f6
--- /dev/null
@@ -0,0 +1,500 @@
+/*
+ * Vulkan
+ *
+ * Copyright (C) 2015 LunarG, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include <string.h>
+#include "vulkan.h"
+#include "vk_layer_utils.h"
+
+typedef struct _VULKAN_FORMAT_INFO {
+    size_t size;
+    uint32_t channel_count;
+} VULKAN_FORMAT_INFO;
+
+
+// Set up data structure with number of bytes and number of channels
+// for each Vulkan format.
+static const VULKAN_FORMAT_INFO vk_format_table[VK_FORMAT_NUM] = {
+    { 0,  0 }, //    [VK_FORMAT_UNDEFINED]
+    { 1,  2 }, //    [VK_FORMAT_R4G4_UNORM]
+    { 1,  2 }, //    [VK_FORMAT_R4G4_USCALED]
+    { 2,  4 }, //    [VK_FORMAT_R4G4B4A4_UNORM]
+    { 2,  4 }, //    [VK_FORMAT_R4G4B4A4_USCALED]
+    { 2,  3 }, //    [VK_FORMAT_R5G6B5_UNORM]
+    { 2,  3 }, //    [VK_FORMAT_R5G6B5_USCALED]
+    { 2,  4 }, //    [VK_FORMAT_R5G5B5A1_UNORM]
+    { 2,  4 }, //    [VK_FORMAT_R5G5B5A1_USCALED]
+    { 1,  1 }, //    [VK_FORMAT_R8_UNORM]
+    { 1,  1 }, //    [VK_FORMAT_R8_SNORM]
+    { 1,  1 }, //    [VK_FORMAT_R8_USCALED]
+    { 1,  1 }, //    [VK_FORMAT_R8_SSCALED]
+    { 1,  1 }, //    [VK_FORMAT_R8_UINT]
+    { 1,  1 }, //    [VK_FORMAT_R8_SINT]
+    { 1,  1 }, //    [VK_FORMAT_R8_SRGB]
+    { 2,  2 }, //    [VK_FORMAT_R8G8_UNORM]
+    { 2,  2 }, //    [VK_FORMAT_R8G8_SNORM]
+    { 2,  2 }, //    [VK_FORMAT_R8G8_USCALED]
+    { 2,  2 }, //    [VK_FORMAT_R8G8_SSCALED]
+    { 2,  2 }, //    [VK_FORMAT_R8G8_UINT]
+    { 2,  2 }, //    [VK_FORMAT_R8G8_SINT]
+    { 2,  2 }, //    [VK_FORMAT_R8G8_SRGB]
+    { 3,  3 }, //    [VK_FORMAT_R8G8B8_UNORM]
+    { 3,  3 }, //    [VK_FORMAT_R8G8B8_SNORM]
+    { 3,  3 }, //    [VK_FORMAT_R8G8B8_USCALED]
+    { 3,  3 }, //    [VK_FORMAT_R8G8B8_SSCALED]
+    { 3,  3 }, //    [VK_FORMAT_R8G8B8_UINT]
+    { 3,  3 }, //    [VK_FORMAT_R8G8B8_SINT]
+    { 3,  3 }, //    [VK_FORMAT_R8G8B8_SRGB]
+    { 4,  4 }, //    [VK_FORMAT_R8G8B8A8_UNORM]
+    { 4,  4 }, //    [VK_FORMAT_R8G8B8A8_SNORM]
+    { 4,  4 }, //    [VK_FORMAT_R8G8B8A8_USCALED]
+    { 4,  4 }, //    [VK_FORMAT_R8G8B8A8_SSCALED]
+    { 4,  4 }, //    [VK_FORMAT_R8G8B8A8_UINT]
+    { 4,  4 }, //    [VK_FORMAT_R8G8B8A8_SINT]
+    { 4,  4 }, //    [VK_FORMAT_R8G8B8A8_SRGB]
+    { 4,  4 }, //    [VK_FORMAT_R10G10B10A2_UNORM]
+    { 4,  4 }, //    [VK_FORMAT_R10G10B10A2_SNORM]
+    { 4,  4 }, //    [VK_FORMAT_R10G10B10A2_USCALED]
+    { 4,  4 }, //    [VK_FORMAT_R10G10B10A2_SSCALED]
+    { 4,  4 }, //    [VK_FORMAT_R10G10B10A2_UINT]
+    { 4,  4 }, //    [VK_FORMAT_R10G10B10A2_SINT]
+    { 2,  1 }, //    [VK_FORMAT_R16_UNORM]
+    { 2,  1 }, //    [VK_FORMAT_R16_SNORM]
+    { 2,  1 }, //    [VK_FORMAT_R16_USCALED]
+    { 2,  1 }, //    [VK_FORMAT_R16_SSCALED]
+    { 2,  1 }, //    [VK_FORMAT_R16_UINT]
+    { 2,  1 }, //    [VK_FORMAT_R16_SINT]
+    { 2,  1 }, //    [VK_FORMAT_R16_SFLOAT]
+    { 4,  2 }, //    [VK_FORMAT_R16G16_UNORM]
+    { 4,  2 }, //    [VK_FORMAT_R16G16_SNORM]
+    { 4,  2 }, //    [VK_FORMAT_R16G16_USCALED]
+    { 4,  2 }, //    [VK_FORMAT_R16G16_SSCALED]
+    { 4,  2 }, //    [VK_FORMAT_R16G16_UINT]
+    { 4,  2 }, //    [VK_FORMAT_R16G16_SINT]
+    { 4,  2 }, //    [VK_FORMAT_R16G16_SFLOAT]
+    { 6,  3 }, //    [VK_FORMAT_R16G16B16_UNORM]
+    { 6,  3 }, //    [VK_FORMAT_R16G16B16_SNORM]
+    { 6,  3 }, //    [VK_FORMAT_R16G16B16_USCALED]
+    { 6,  3 }, //    [VK_FORMAT_R16G16B16_SSCALED]
+    { 6,  3 }, //    [VK_FORMAT_R16G16B16_UINT]
+    { 6,  3 }, //    [VK_FORMAT_R16G16B16_SINT]
+    { 6,  3 }, //    [VK_FORMAT_R16G16B16_SFLOAT]
+    { 8,  4 }, //    [VK_FORMAT_R16G16B16A16_UNORM]
+    { 8,  4 }, //    [VK_FORMAT_R16G16B16A16_SNORM]
+    { 8,  4 }, //    [VK_FORMAT_R16G16B16A16_USCALED]
+    { 8,  4 }, //    [VK_FORMAT_R16G16B16A16_SSCALED]
+    { 8,  4 }, //    [VK_FORMAT_R16G16B16A16_UINT]
+    { 8,  4 }, //    [VK_FORMAT_R16G16B16A16_SINT]
+    { 8,  4 }, //    [VK_FORMAT_R16G16B16A16_SFLOAT]
+    { 4,  1 }, //    [VK_FORMAT_R32_UINT]
+    { 4,  1 }, //    [VK_FORMAT_R32_SINT]
+    { 4,  1 }, //    [VK_FORMAT_R32_SFLOAT]
+    { 8,  2 }, //    [VK_FORMAT_R32G32_UINT]
+    { 8,  2 }, //    [VK_FORMAT_R32G32_SINT]
+    { 8,  2 }, //    [VK_FORMAT_R32G32_SFLOAT]
+    { 12, 3 }, //    [VK_FORMAT_R32G32B32_UINT]
+    { 12, 3 }, //    [VK_FORMAT_R32G32B32_SINT]
+    { 12, 3 }, //    [VK_FORMAT_R32G32B32_SFLOAT]
+    { 16, 4 }, //    [VK_FORMAT_R32G32B32A32_UINT]
+    { 16, 4 }, //    [VK_FORMAT_R32G32B32A32_SINT]
+    { 16, 4 }, //    [VK_FORMAT_R32G32B32A32_SFLOAT]
+    { 8,  1 }, //    [VK_FORMAT_R64_SFLOAT]
+    { 16, 2 }, //    [VK_FORMAT_R64G64_SFLOAT]
+    { 24, 3 }, //    [VK_FORMAT_R64G64B64_SFLOAT]
+    { 32, 4 }, //    [VK_FORMAT_R64G64B64A64_SFLOAT]
+    { 4,  3 }, //    [VK_FORMAT_R11G11B10_UFLOAT]
+    { 4,  3 }, //    [VK_FORMAT_R9G9B9E5_UFLOAT]
+    { 2,  1 }, //    [VK_FORMAT_D16_UNORM]
+    { 3,  1 }, //    [VK_FORMAT_D24_UNORM_X8]
+    { 4,  1 }, //    [VK_FORMAT_D32_SFLOAT]
+    { 1,  1 }, //    [VK_FORMAT_S8_UINT]
+    { 3,  2 }, //    [VK_FORMAT_D16_UNORM_S8_UINT]
+    { 4,  2 }, //    [VK_FORMAT_D24_UNORM_S8_UINT]
+    { 4,  2 }, //    [VK_FORMAT_D32_SFLOAT_S8_UINT]
+    { 8,  4 }, //    [VK_FORMAT_BC1_RGB_UNORM]
+    { 8,  4 }, //    [VK_FORMAT_BC1_RGB_SRGB]
+    { 8,  4 }, //    [VK_FORMAT_BC1_RGBA_UNORM]
+    { 8,  4 }, //    [VK_FORMAT_BC1_RGBA_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_BC2_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_BC2_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_BC3_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_BC3_SRGB]
+    { 8,  4 }, //    [VK_FORMAT_BC4_UNORM]
+    { 8,  4 }, //    [VK_FORMAT_BC4_SNORM]
+    { 16, 4 }, //    [VK_FORMAT_BC5_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_BC5_SNORM]
+    { 16, 4 }, //    [VK_FORMAT_BC6H_UFLOAT]
+    { 16, 4 }, //    [VK_FORMAT_BC6H_SFLOAT]
+    { 16, 4 }, //    [VK_FORMAT_BC7_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_BC7_SRGB]
+    { 8, 3 },  //    [VK_FORMAT_ETC2_R8G8B8_UNORM]
+    { 8, 3 },  //    [VK_FORMAT_ETC2_R8G8B8_SRGB]
+    { 8, 4 },  //    [VK_FORMAT_ETC2_R8G8B8A1_UNORM]
+    { 8, 4 },  //    [VK_FORMAT_ETC2_R8G8B8A1_SRGB]
+    { 8, 4 },  //    [VK_FORMAT_ETC2_R8G8B8A8_UNORM]
+    { 8, 4 },  //    [VK_FORMAT_ETC2_R8G8B8A8_SRGB]
+    { 8, 1 },  //    [VK_FORMAT_EAC_R11_UNORM]
+    { 8, 1 },  //    [VK_FORMAT_EAC_R11_SNORM]
+    { 16, 2 }, //    [VK_FORMAT_EAC_R11G11_UNORM]
+    { 16, 2 }, //    [VK_FORMAT_EAC_R11G11_SNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_4x4_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_4x4_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_5x4_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_5x4_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_5x5_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_5x5_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_6x5_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_6x5_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_6x6_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_6x6_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_8x5_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_8x5_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_8x6_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_8x6_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_8x8_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_8x8_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_10x5_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_10x5_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_10x6_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_10x6_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_10x8_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_10x8_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_10x10_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_10x10_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_12x10_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_12x10_SRGB]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_12x12_UNORM]
+    { 16, 4 }, //    [VK_FORMAT_ASTC_12x12_SRGB]
+    { 2, 3 },  //    [VK_FORMAT_B5G6R5_UNORM]
+    { 2, 3 },  //    [VK_FORMAT_B5G6R5_USCALED]
+    { 3, 3 },  //    [VK_FORMAT_B8G8R8_UNORM]
+    { 3, 3 },  //    [VK_FORMAT_B8G8R8_SNORM]
+    { 3, 3 },  //    [VK_FORMAT_B8G8R8_USCALED]
+    { 3, 3 },  //    [VK_FORMAT_B8G8R8_SSCALED]
+    { 3, 3 },  //    [VK_FORMAT_B8G8R8_UINT]
+    { 3, 3 },  //    [VK_FORMAT_B8G8R8_SINT]
+    { 3, 3 },  //    [VK_FORMAT_B8G8R8_SRGB]
+    { 4, 4 },  //    [VK_FORMAT_B8G8R8A8_UNORM]
+    { 4, 4 },  //    [VK_FORMAT_B8G8R8A8_SNORM]
+    { 4, 4 },  //    [VK_FORMAT_B8G8R8A8_USCALED]
+    { 4, 4 },  //    [VK_FORMAT_B8G8R8A8_SSCALED]
+    { 4, 4 },  //    [VK_FORMAT_B8G8R8A8_UINT]
+    { 4, 4 },  //    [VK_FORMAT_B8G8R8A8_SINT]
+    { 4, 4 },  //    [VK_FORMAT_B8G8R8A8_SRGB]
+    { 4, 4 },  //    [VK_FORMAT_B10G10R10A2_UNORM]
+    { 4, 4 },  //    [VK_FORMAT_B10G10R10A2_SNORM]
+    { 4, 4 },  //    [VK_FORMAT_B10G10R10A2_USCALED]
+    { 4, 4 },  //    [VK_FORMAT_B10G10R10A2_SSCALED]
+    { 4, 4 },  //    [VK_FORMAT_B10G10R10A2_UINT]
+    { 4, 4 },  //    [VK_FORMAT_B10G10R10A2_SINT]
+};
+
+// Return true if format is a depth-stencil format
+bool vk_format_is_ds(VkFormat format)
+{
+    bool is_ds = false;
+
+    switch (format) {
+    case VK_FORMAT_D16_UNORM:
+    case VK_FORMAT_D24_UNORM_X8:
+    case VK_FORMAT_D32_SFLOAT:
+    case VK_FORMAT_S8_UINT:
+    case VK_FORMAT_D16_UNORM_S8_UINT:
+    case VK_FORMAT_D24_UNORM_S8_UINT:
+    case VK_FORMAT_D32_SFLOAT_S8_UINT:
+        is_ds = true;
+        break;
+    default:
+        break;
+    }
+
+    return is_ds;
+}
+
+// Return true if format is of time UNORM
+bool vk_format_is_norm(VkFormat format)
+{
+    bool is_norm = false;
+
+    switch (format) {
+    case VK_FORMAT_R4G4_UNORM:
+    case VK_FORMAT_R4G4B4A4_UNORM:
+    case VK_FORMAT_R5G6B5_UNORM:
+    case VK_FORMAT_R5G5B5A1_UNORM:
+    case VK_FORMAT_R8_UNORM:
+    case VK_FORMAT_R8_SNORM:
+    case VK_FORMAT_R8G8_UNORM:
+    case VK_FORMAT_R8G8_SNORM:
+    case VK_FORMAT_R8G8B8_UNORM:
+    case VK_FORMAT_R8G8B8_SNORM:
+    case VK_FORMAT_R8G8B8A8_UNORM:
+    case VK_FORMAT_R8G8B8A8_SNORM:
+    case VK_FORMAT_R10G10B10A2_UNORM:
+    case VK_FORMAT_R10G10B10A2_SNORM:
+    case VK_FORMAT_R16_UNORM:
+    case VK_FORMAT_R16_SNORM:
+    case VK_FORMAT_R16G16_UNORM:
+    case VK_FORMAT_R16G16_SNORM:
+    case VK_FORMAT_R16G16B16_UNORM:
+    case VK_FORMAT_R16G16B16_SNORM:
+    case VK_FORMAT_R16G16B16A16_UNORM:
+    case VK_FORMAT_R16G16B16A16_SNORM:
+    case VK_FORMAT_BC1_RGB_UNORM:
+    case VK_FORMAT_BC2_UNORM:
+    case VK_FORMAT_BC3_UNORM:
+    case VK_FORMAT_BC4_UNORM:
+    case VK_FORMAT_BC4_SNORM:
+    case VK_FORMAT_BC5_UNORM:
+    case VK_FORMAT_BC5_SNORM:
+    case VK_FORMAT_BC7_UNORM:
+    case VK_FORMAT_ETC2_R8G8B8_UNORM:
+    case VK_FORMAT_ETC2_R8G8B8A1_UNORM:
+    case VK_FORMAT_ETC2_R8G8B8A8_UNORM:
+    case VK_FORMAT_EAC_R11_UNORM:
+    case VK_FORMAT_EAC_R11_SNORM:
+    case VK_FORMAT_EAC_R11G11_UNORM:
+    case VK_FORMAT_EAC_R11G11_SNORM:
+    case VK_FORMAT_ASTC_4x4_UNORM:
+    case VK_FORMAT_ASTC_5x4_UNORM:
+    case VK_FORMAT_ASTC_5x5_UNORM:
+    case VK_FORMAT_ASTC_6x5_UNORM:
+    case VK_FORMAT_ASTC_6x6_UNORM:
+    case VK_FORMAT_ASTC_8x5_UNORM:
+    case VK_FORMAT_ASTC_8x6_UNORM:
+    case VK_FORMAT_ASTC_8x8_UNORM:
+    case VK_FORMAT_ASTC_10x5_UNORM:
+    case VK_FORMAT_ASTC_10x6_UNORM:
+    case VK_FORMAT_ASTC_10x8_UNORM:
+    case VK_FORMAT_ASTC_10x10_UNORM:
+    case VK_FORMAT_ASTC_12x10_UNORM:
+    case VK_FORMAT_ASTC_12x12_UNORM:
+    case VK_FORMAT_B5G6R5_UNORM:
+    case VK_FORMAT_B8G8R8_UNORM:
+    case VK_FORMAT_B8G8R8_SNORM:
+    case VK_FORMAT_B8G8R8A8_UNORM:
+    case VK_FORMAT_B8G8R8A8_SNORM:
+    case VK_FORMAT_B10G10R10A2_UNORM:
+    case VK_FORMAT_B10G10R10A2_SNORM:
+        is_norm = true;
+        break;
+    default:
+        break;
+    }
+
+    return is_norm;
+};
+
+// Return true if format is an integer format
+bool vk_format_is_int(VkFormat format)
+{
+    bool is_int = false;
+
+    switch (format) {
+    case VK_FORMAT_R8_UINT:
+    case VK_FORMAT_R8_SINT:
+    case VK_FORMAT_R8G8_UINT:
+    case VK_FORMAT_R8G8_SINT:
+    case VK_FORMAT_R8G8B8_UINT:
+    case VK_FORMAT_R8G8B8_SINT:
+    case VK_FORMAT_R8G8B8A8_UINT:
+    case VK_FORMAT_R8G8B8A8_SINT:
+    case VK_FORMAT_R10G10B10A2_UINT:
+    case VK_FORMAT_R10G10B10A2_SINT:
+    case VK_FORMAT_R16_UINT:
+    case VK_FORMAT_R16_SINT:
+    case VK_FORMAT_R16G16_UINT:
+    case VK_FORMAT_R16G16_SINT:
+    case VK_FORMAT_R16G16B16_UINT:
+    case VK_FORMAT_R16G16B16_SINT:
+    case VK_FORMAT_R16G16B16A16_UINT:
+    case VK_FORMAT_R16G16B16A16_SINT:
+    case VK_FORMAT_R32_UINT:
+    case VK_FORMAT_R32_SINT:
+    case VK_FORMAT_R32G32_UINT:
+    case VK_FORMAT_R32G32_SINT:
+    case VK_FORMAT_R32G32B32_UINT:
+    case VK_FORMAT_R32G32B32_SINT:
+    case VK_FORMAT_R32G32B32A32_UINT:
+    case VK_FORMAT_R32G32B32A32_SINT:
+    case VK_FORMAT_B8G8R8_UINT:
+    case VK_FORMAT_B8G8R8_SINT:
+    case VK_FORMAT_B8G8R8A8_UINT:
+    case VK_FORMAT_B8G8R8A8_SINT:
+    case VK_FORMAT_B10G10R10A2_UINT:
+    case VK_FORMAT_B10G10R10A2_SINT:
+        is_int = true;
+        break;
+    default:
+        break;
+    }
+
+    return is_int;
+}
+
+// Return true if format is a floating-point format
+bool vk_format_is_float(VkFormat format)
+{
+    bool is_float = false;
+
+    switch (format) {
+    case VK_FORMAT_R16_SFLOAT:
+    case VK_FORMAT_R16G16_SFLOAT:
+    case VK_FORMAT_R16G16B16_SFLOAT:
+    case VK_FORMAT_R16G16B16A16_SFLOAT:
+    case VK_FORMAT_R32_SFLOAT:
+    case VK_FORMAT_R32G32_SFLOAT:
+    case VK_FORMAT_R32G32B32_SFLOAT:
+    case VK_FORMAT_R32G32B32A32_SFLOAT:
+    case VK_FORMAT_R64_SFLOAT:
+    case VK_FORMAT_R64G64_SFLOAT:
+    case VK_FORMAT_R64G64B64_SFLOAT:
+    case VK_FORMAT_R64G64B64A64_SFLOAT:
+    case VK_FORMAT_R11G11B10_UFLOAT:
+    case VK_FORMAT_R9G9B9E5_UFLOAT:
+    case VK_FORMAT_BC6H_UFLOAT:
+    case VK_FORMAT_BC6H_SFLOAT:
+        is_float = true;
+        break;
+    default:
+        break;
+    }
+
+    return is_float;
+}
+
+// Return true if format is in the SRGB colorspace
+bool vk_format_is_srgb(VkFormat format)
+{
+    bool is_srgb = false;
+
+    switch (format) {
+    case VK_FORMAT_R8_SRGB:
+    case VK_FORMAT_R8G8_SRGB:
+    case VK_FORMAT_R8G8B8_SRGB:
+    case VK_FORMAT_R8G8B8A8_SRGB:
+    case VK_FORMAT_BC1_RGB_SRGB:
+    case VK_FORMAT_BC2_SRGB:
+    case VK_FORMAT_BC3_SRGB:
+    case VK_FORMAT_BC7_SRGB:
+    case VK_FORMAT_ETC2_R8G8B8_SRGB:
+    case VK_FORMAT_ETC2_R8G8B8A1_SRGB:
+    case VK_FORMAT_ETC2_R8G8B8A8_SRGB:
+    case VK_FORMAT_ASTC_4x4_SRGB:
+    case VK_FORMAT_ASTC_5x4_SRGB:
+    case VK_FORMAT_ASTC_5x5_SRGB:
+    case VK_FORMAT_ASTC_6x5_SRGB:
+    case VK_FORMAT_ASTC_6x6_SRGB:
+    case VK_FORMAT_ASTC_8x5_SRGB:
+    case VK_FORMAT_ASTC_8x6_SRGB:
+    case VK_FORMAT_ASTC_8x8_SRGB:
+    case VK_FORMAT_ASTC_10x5_SRGB:
+    case VK_FORMAT_ASTC_10x6_SRGB:
+    case VK_FORMAT_ASTC_10x8_SRGB:
+    case VK_FORMAT_ASTC_10x10_SRGB:
+    case VK_FORMAT_ASTC_12x10_SRGB:
+    case VK_FORMAT_ASTC_12x12_SRGB:
+    case VK_FORMAT_B8G8R8_SRGB:
+    case VK_FORMAT_B8G8R8A8_SRGB:
+        is_srgb = true;
+        break;
+    default:
+        break;
+    }
+
+    return is_srgb;
+}
+
+// Return true if format is compressed
+bool vk_format_is_compressed(VkFormat format)
+{
+    switch (format) {
+    case VK_FORMAT_BC1_RGB_UNORM:
+    case VK_FORMAT_BC1_RGB_SRGB:
+    case VK_FORMAT_BC2_UNORM:
+    case VK_FORMAT_BC2_SRGB:
+    case VK_FORMAT_BC3_UNORM:
+    case VK_FORMAT_BC3_SRGB:
+    case VK_FORMAT_BC4_UNORM:
+    case VK_FORMAT_BC4_SNORM:
+    case VK_FORMAT_BC5_UNORM:
+    case VK_FORMAT_BC5_SNORM:
+    case VK_FORMAT_BC6H_UFLOAT:
+    case VK_FORMAT_BC6H_SFLOAT:
+    case VK_FORMAT_BC7_UNORM:
+    case VK_FORMAT_BC7_SRGB:
+    case VK_FORMAT_ETC2_R8G8B8_UNORM:
+    case VK_FORMAT_ETC2_R8G8B8_SRGB:
+    case VK_FORMAT_ETC2_R8G8B8A1_UNORM:
+    case VK_FORMAT_ETC2_R8G8B8A1_SRGB:
+    case VK_FORMAT_ETC2_R8G8B8A8_UNORM:
+    case VK_FORMAT_ETC2_R8G8B8A8_SRGB:
+    case VK_FORMAT_EAC_R11_UNORM:
+    case VK_FORMAT_EAC_R11_SNORM:
+    case VK_FORMAT_EAC_R11G11_UNORM:
+    case VK_FORMAT_EAC_R11G11_SNORM:
+    case VK_FORMAT_ASTC_4x4_UNORM:
+    case VK_FORMAT_ASTC_4x4_SRGB:
+    case VK_FORMAT_ASTC_5x4_UNORM:
+    case VK_FORMAT_ASTC_5x4_SRGB:
+    case VK_FORMAT_ASTC_5x5_UNORM:
+    case VK_FORMAT_ASTC_5x5_SRGB:
+    case VK_FORMAT_ASTC_6x5_UNORM:
+    case VK_FORMAT_ASTC_6x5_SRGB:
+    case VK_FORMAT_ASTC_6x6_UNORM:
+    case VK_FORMAT_ASTC_6x6_SRGB:
+    case VK_FORMAT_ASTC_8x5_UNORM:
+    case VK_FORMAT_ASTC_8x5_SRGB:
+    case VK_FORMAT_ASTC_8x6_UNORM:
+    case VK_FORMAT_ASTC_8x6_SRGB:
+    case VK_FORMAT_ASTC_8x8_UNORM:
+    case VK_FORMAT_ASTC_8x8_SRGB:
+    case VK_FORMAT_ASTC_10x5_UNORM:
+    case VK_FORMAT_ASTC_10x5_SRGB:
+    case VK_FORMAT_ASTC_10x6_UNORM:
+    case VK_FORMAT_ASTC_10x6_SRGB:
+    case VK_FORMAT_ASTC_10x8_UNORM:
+    case VK_FORMAT_ASTC_10x8_SRGB:
+    case VK_FORMAT_ASTC_10x10_UNORM:
+    case VK_FORMAT_ASTC_10x10_SRGB:
+    case VK_FORMAT_ASTC_12x10_UNORM:
+    case VK_FORMAT_ASTC_12x10_SRGB:
+    case VK_FORMAT_ASTC_12x12_UNORM:
+    case VK_FORMAT_ASTC_12x12_SRGB:
+        return true;
+    default:
+        return false;
+    }
+}
+
+// Return size, in bytes, of a pixel of the specified format
+size_t vk_format_get_size(VkFormat format)
+{
+    return vk_format_table[format].size;
+}
+
+// Return the number of channels for a given format
+unsigned int vk_format_get_channel_count(VkFormat format)
+{
+    return vk_format_table[format].channel_count;
+}
diff --git a/layers/vk_layer_utils.h b/layers/vk_layer_utils.h
new file mode 100644 (file)
index 0000000..643e1d2
--- /dev/null
@@ -0,0 +1,56 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Lunarg, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+#pragma once
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline bool vk_format_is_undef(VkFormat format)
+{
+    return (format == VK_FORMAT_UNDEFINED);
+}
+
+bool vk_format_is_ds(VkFormat format);
+
+static inline bool vk_format_is_color(VkFormat format)
+{
+    return !(vk_format_is_undef(format) || vk_format_is_ds(format));
+}
+
+bool   vk_format_is_norm(VkFormat format);
+bool   vk_format_is_int(VkFormat format);
+bool   vk_format_is_float(VkFormat format);
+bool   vk_format_is_srgb(VkFormat format);
+bool   vk_format_is_compressed(VkFormat format);
+size_t vk_format_get_size(VkFormat format);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
index 3c7f521404a5217b34a4ad811fec369bc5ca3194..4ac8f211bbf27ef083e80b427103860b89d8ce40 100644 (file)
@@ -275,11 +275,14 @@ For the second category of errors, DeviceLimits stores its own internal record o
 | Querying array counts | For API calls where an array count should be queried with an initial call and a NULL array pointer, verify that such a call was made before making a call with non-null array pointer. | MUST_QUERY_COUNT | vkEnumeratePhysicalDevices vkGetPhysicalDeviceQueueFamilyProperties | NA | Create focused test |
 | Array count value | For API calls where an array of details is queried, verify that the size of the requested array matches the size of the array supported by the device. | COUNT_MISMATCH | vkEnumeratePhysicalDevices vkGetPhysicalDeviceQueueFamilyProperties | NA | Create focused test |
 | Queue Creation | When creating/requesting queues, make sure that QueueFamilyPropertiesIndex and index/count within that queue family are valid. | INVALID_QUEUE_CREATE_REQUEST | vkGetDeviceQueue vkCreateDevice | NA | Create focused test |
+| Query Properties | Before creating an Image, warn if physical device properties have not been queried | MUST_QUERY_PROPERTIES | vkCreateImage | NA | Add validation test |
+| Valid Image Extents | When creating an Image, ensure that image extents are within device limits for the specified format | LIMITS_VIOLATION | vkCreateImage | CreateImageLimitsViolationWidth | NA |
+| Valid Image Resource Size | When creating an image, ensure the the total image resource size is less than the queried device maximum resource size  | LIMITS_VIOLATION | vkCreateImage | CreateImageResourceSizeViolation | NA |
 | NA | Enum used for informational messages | NONE | | NA | None |
 
 ### Device Limitations Pending Work
 
- 1. For all Formats, call vkGetPhysicalDeviceFormatProperties to pull their properties for the underlying device. After that point, if the app attempts to use any formats in violation of those properties, flag errors.
+ 1. For all Formats, call vkGetPhysicalDeviceFormatProperties to pull their properties for the underlying device. After that point, if the app attempts to use any formats in violation of those properties, flag errors (this is done for Images).
 
 # Non-validation Layer Details