blob: b818159cae2b9980fbc4e2b4de1210c2912e15f3 [file] [log] [blame]
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001/* Copyright (c) 2015-2017 The Khronos Group Inc.
2 * Copyright (c) 2015-2017 Valve Corporation
3 * Copyright (c) 2015-2017 LunarG, Inc.
4 * Copyright (C) 2015-2017 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Mark Lobodzinski <mark@LunarG.com>
19 */
20
21#define NOMINMAX
22
23#include <limits.h>
24#include <math.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <inttypes.h>
29
30#include <iostream>
31#include <string>
32#include <sstream>
33#include <unordered_map>
34#include <unordered_set>
35#include <vector>
36#include <mutex>
37
38#include "vk_loader_platform.h"
39#include "vulkan/vk_layer.h"
40#include "vk_layer_config.h"
41#include "vk_dispatch_table_helper.h"
John Zulaufde972ac2017-10-26 12:07:05 -060042#include "vk_typemap_helper.h"
Mark Lobodzinskid4950072017-08-01 13:02:20 -060043
44#include "vk_layer_table.h"
45#include "vk_layer_data.h"
46#include "vk_layer_logging.h"
47#include "vk_layer_extension_utils.h"
48#include "vk_layer_utils.h"
49
50#include "parameter_name.h"
51#include "parameter_validation.h"
52
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -060053#if defined __ANDROID__
54#include <android/log.h>
55#define LOGCONSOLE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "DS", __VA_ARGS__))
56#else
57#define LOGCONSOLE(...) \
58 { \
59 printf(__VA_ARGS__); \
60 printf("\n"); \
61 }
62#endif
63
Mark Lobodzinskid4950072017-08-01 13:02:20 -060064namespace parameter_validation {
65
Mark Lobodzinski78a12a92017-08-08 14:16:51 -060066extern std::unordered_map<std::string, void *> custom_functions;
67
Mark Lobodzinskid4950072017-08-01 13:02:20 -060068extern bool parameter_validation_vkCreateInstance(VkInstance instance, const VkInstanceCreateInfo *pCreateInfo,
69 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance);
70extern bool parameter_validation_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator);
71extern bool parameter_validation_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
72 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
73extern bool parameter_validation_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator);
74extern bool parameter_validation_vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
75 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool);
76extern bool parameter_validation_vkCreateDebugReportCallbackEXT(VkInstance instance,
77 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
78 const VkAllocationCallbacks *pAllocator,
79 VkDebugReportCallbackEXT *pMsgCallback);
80extern bool parameter_validation_vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
81 const VkAllocationCallbacks *pAllocator);
82extern bool parameter_validation_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
83 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool);
Petr Krause91f7a12017-12-14 20:57:36 +010084extern bool parameter_validation_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
85 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
86extern bool parameter_validation_vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
87 const VkAllocationCallbacks *pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -060088
89// TODO : This can be much smarter, using separate locks for separate global data
90std::mutex global_lock;
91
92static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
93std::unordered_map<void *, layer_data *> layer_data_map;
94std::unordered_map<void *, instance_layer_data *> instance_layer_data_map;
95
96void InitializeManualParameterValidationFunctionPointers(void);
97
98static void init_parameter_validation(instance_layer_data *instance_data, const VkAllocationCallbacks *pAllocator) {
99 layer_debug_actions(instance_data->report_data, instance_data->logging_callback, pAllocator, "lunarg_parameter_validation");
100}
101
102static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
103
104static const VkLayerProperties global_layer = {
Dave Houltonb3bbec72018-01-17 10:13:33 -0700105 "VK_LAYER_LUNARG_parameter_validation",
106 VK_LAYER_API_VERSION,
107 1,
108 "LunarG Validation Layer",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600109};
110
111static const int MaxParamCheckerStringLength = 256;
112
John Zulauf71968502017-10-26 13:51:15 -0600113template <typename T>
114static inline bool in_inclusive_range(const T &value, const T &min, const T &max) {
115 // Using only < for generality and || for early abort
116 return !((value < min) || (max < value));
117}
118
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600119static bool validate_string(debug_report_data *report_data, const char *apiName, const ParameterName &stringName,
120 const char *validateString) {
121 assert(apiName != nullptr);
122 assert(validateString != nullptr);
123
124 bool skip = false;
125
126 VkStringErrorFlags result = vk_string_validate(MaxParamCheckerStringLength, validateString);
127
128 if (result == VK_STRING_ERROR_NONE) {
129 return skip;
130 } else if (result & VK_STRING_ERROR_LENGTH) {
131 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
132 INVALID_USAGE, LayerName, "%s: string %s exceeds max length %d", apiName, stringName.get_name().c_str(),
133 MaxParamCheckerStringLength);
134 } else if (result & VK_STRING_ERROR_BAD_DATA) {
135 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
136 INVALID_USAGE, LayerName, "%s: string %s contains invalid characters or is badly formed", apiName,
137 stringName.get_name().c_str());
138 }
139 return skip;
140}
141
142static bool ValidateDeviceQueueFamily(layer_data *device_data, uint32_t queue_family, const char *cmd_name,
143 const char *parameter_name, int32_t error_code, bool optional = false,
144 const char *vu_note = nullptr) {
145 bool skip = false;
146
147 if (!vu_note) vu_note = validation_error_map[error_code];
148 if (!optional && queue_family == VK_QUEUE_FAMILY_IGNORED) {
149 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
150 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
151 "%s: %s is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family index value. %s",
152 cmd_name, parameter_name, vu_note);
153 } else if (device_data->queueFamilyIndexMap.find(queue_family) == device_data->queueFamilyIndexMap.end()) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700154 skip |= log_msg(
155 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
156 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
157 "%s: %s (= %" PRIu32
158 ") is not one of the queue families given via VkDeviceQueueCreateInfo structures when the device was created. %s",
159 cmd_name, parameter_name, queue_family, vu_note);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600160 }
161
162 return skip;
163}
164
165static bool ValidateQueueFamilies(layer_data *device_data, uint32_t queue_family_count, const uint32_t *queue_families,
166 const char *cmd_name, const char *array_parameter_name, int32_t unique_error_code,
167 int32_t valid_error_code, bool optional = false, const char *unique_vu_note = nullptr,
168 const char *valid_vu_note = nullptr) {
169 bool skip = false;
170 if (!unique_vu_note) unique_vu_note = validation_error_map[unique_error_code];
171 if (!valid_vu_note) valid_vu_note = validation_error_map[valid_error_code];
172 if (queue_families) {
173 std::unordered_set<uint32_t> set;
174 for (uint32_t i = 0; i < queue_family_count; ++i) {
175 std::string parameter_name = std::string(array_parameter_name) + "[" + std::to_string(i) + "]";
176
177 if (set.count(queue_families[i])) {
178 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
179 HandleToUint64(device_data->device), __LINE__, VALIDATION_ERROR_056002e8, LayerName,
180 "%s: %s (=%" PRIu32 ") is not unique within %s array. %s", cmd_name, parameter_name.c_str(),
181 queue_families[i], array_parameter_name, unique_vu_note);
182 } else {
183 set.insert(queue_families[i]);
184 skip |= ValidateDeviceQueueFamily(device_data, queue_families[i], cmd_name, parameter_name.c_str(),
185 valid_error_code, optional, valid_vu_note);
186 }
187 }
188 }
189 return skip;
190}
191
192VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600193 VkInstance *pInstance) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600194 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
195
196 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
197 assert(chain_info != nullptr);
198 assert(chain_info->u.pLayerInfo != nullptr);
199
200 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
201 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
202 if (fpCreateInstance == NULL) {
203 return VK_ERROR_INITIALIZATION_FAILED;
204 }
205
206 // Advance the link info for the next element on the chain
207 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
208
209 result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
210
211 if (result == VK_SUCCESS) {
212 InitializeManualParameterValidationFunctionPointers();
213 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), instance_layer_data_map);
214 assert(my_instance_data != nullptr);
215
216 layer_init_instance_dispatch_table(*pInstance, &my_instance_data->dispatch_table, fpGetInstanceProcAddr);
217 my_instance_data->instance = *pInstance;
218 my_instance_data->report_data =
219 debug_report_create_instance(&my_instance_data->dispatch_table, *pInstance, pCreateInfo->enabledExtensionCount,
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600220 pCreateInfo->ppEnabledExtensionNames);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600221
222 // Look for one or more debug report create info structures
223 // and setup a callback(s) for each one found.
224 if (!layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_instance_data->num_tmp_callbacks,
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600225 &my_instance_data->tmp_dbg_create_infos, &my_instance_data->tmp_callbacks)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600226 if (my_instance_data->num_tmp_callbacks > 0) {
227 // Setup the temporary callback(s) here to catch early issues:
228 if (layer_enable_tmp_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_callbacks,
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600229 my_instance_data->tmp_dbg_create_infos, my_instance_data->tmp_callbacks)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600230 // Failure of setting up one or more of the callback.
231 // Therefore, clean up and don't use those callbacks:
232 layer_free_tmp_callbacks(my_instance_data->tmp_dbg_create_infos, my_instance_data->tmp_callbacks);
233 my_instance_data->num_tmp_callbacks = 0;
234 }
235 }
236 }
237
238 init_parameter_validation(my_instance_data, pAllocator);
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600239
240 uint32_t api_version = my_instance_data->extensions.InitFromInstanceCreateInfo(
241 (pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : VK_API_VERSION_1_0), pCreateInfo);
242
243 if (pCreateInfo->pApplicationInfo) {
244 uint32_t specified_api_version = pCreateInfo->pApplicationInfo->apiVersion & ~VK_VERSION_PATCH(~0);
245 if (!(specified_api_version == VK_API_VERSION_1_0) && !(specified_api_version == VK_API_VERSION_1_1)) {
246 LOGCONSOLE(
247 "Warning: Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number -- (0x%08x) assuming "
248 "%s.\n",
249 pCreateInfo->pApplicationInfo->apiVersion,
250 (api_version == VK_API_VERSION_1_0) ? "VK_API_VERSION_1_0" : "VK_API_VERSION_1_1");
251 }
252 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600253
254 // Ordinarily we'd check these before calling down the chain, but none of the layer support is in place until now, if we
255 // survive we can report the issue now.
256 parameter_validation_vkCreateInstance(*pInstance, pCreateInfo, pAllocator, pInstance);
257
258 if (pCreateInfo->pApplicationInfo) {
259 if (pCreateInfo->pApplicationInfo->pApplicationName) {
260 validate_string(my_instance_data->report_data, "vkCreateInstance",
261 "pCreateInfo->VkApplicationInfo->pApplicationName",
262 pCreateInfo->pApplicationInfo->pApplicationName);
263 }
264
265 if (pCreateInfo->pApplicationInfo->pEngineName) {
266 validate_string(my_instance_data->report_data, "vkCreateInstance", "pCreateInfo->VkApplicationInfo->pEngineName",
267 pCreateInfo->pApplicationInfo->pEngineName);
268 }
269 }
270
271 // Disable the tmp callbacks:
272 if (my_instance_data->num_tmp_callbacks > 0) {
273 layer_disable_tmp_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_callbacks,
274 my_instance_data->tmp_callbacks);
275 }
276 }
277
278 return result;
279}
280
281VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
282 // Grab the key before the instance is destroyed.
283 dispatch_key key = get_dispatch_key(instance);
284 bool skip = false;
285 auto instance_data = GetLayerDataPtr(key, instance_layer_data_map);
286
287 // Enable the temporary callback(s) here to catch vkDestroyInstance issues:
288 bool callback_setup = false;
289 if (instance_data->num_tmp_callbacks > 0) {
290 if (!layer_enable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks,
291 instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks)) {
292 callback_setup = true;
293 }
294 }
295
296 skip |= parameter_validation_vkDestroyInstance(instance, pAllocator);
297
298 // Disable and cleanup the temporary callback(s):
299 if (callback_setup) {
300 layer_disable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks, instance_data->tmp_callbacks);
301 }
302 if (instance_data->num_tmp_callbacks > 0) {
303 layer_free_tmp_callbacks(instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks);
304 instance_data->num_tmp_callbacks = 0;
305 }
306
307 if (!skip) {
308 instance_data->dispatch_table.DestroyInstance(instance, pAllocator);
309
310 // Clean up logging callback, if any
311 while (instance_data->logging_callback.size() > 0) {
312 VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
313 layer_destroy_msg_callback(instance_data->report_data, callback, pAllocator);
314 instance_data->logging_callback.pop_back();
315 }
316
317 layer_debug_report_destroy_instance(instance_data->report_data);
318 }
319
320 FreeLayerDataPtr(key, instance_layer_data_map);
321}
322
323VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance,
324 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
325 const VkAllocationCallbacks *pAllocator,
326 VkDebugReportCallbackEXT *pMsgCallback) {
327 bool skip = parameter_validation_vkCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
328 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
329
330 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
331 VkResult result = instance_data->dispatch_table.CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
332 if (result == VK_SUCCESS) {
333 result = layer_create_msg_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback);
334 }
335 return result;
336}
337
338VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
339 const VkAllocationCallbacks *pAllocator) {
340 bool skip = parameter_validation_vkDestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
341 if (!skip) {
342 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
343 instance_data->dispatch_table.DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
344 layer_destroy_msg_callback(instance_data->report_data, msgCallback, pAllocator);
345 }
346}
347
348static bool ValidateDeviceCreateInfo(instance_layer_data *instance_data, VkPhysicalDevice physicalDevice,
349 const VkDeviceCreateInfo *pCreateInfo) {
350 bool skip = false;
351
352 if ((pCreateInfo->enabledLayerCount > 0) && (pCreateInfo->ppEnabledLayerNames != NULL)) {
353 for (size_t i = 0; i < pCreateInfo->enabledLayerCount; i++) {
354 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledLayerNames",
355 pCreateInfo->ppEnabledLayerNames[i]);
356 }
357 }
358
359 bool maint1 = false;
360 bool negative_viewport = false;
361
362 if ((pCreateInfo->enabledExtensionCount > 0) && (pCreateInfo->ppEnabledExtensionNames != NULL)) {
363 for (size_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
364 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledExtensionNames",
365 pCreateInfo->ppEnabledExtensionNames[i]);
366 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) maint1 = true;
367 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME) == 0)
368 negative_viewport = true;
369 }
370 }
371
372 if (maint1 && negative_viewport) {
373 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
374 __LINE__, VALIDATION_ERROR_056002ec, LayerName,
375 "VkDeviceCreateInfo->ppEnabledExtensionNames must not simultaneously include VK_KHR_maintenance1 and "
376 "VK_AMD_negative_viewport_height. %s",
377 validation_error_map[VALIDATION_ERROR_056002ec]);
378 }
379
380 if (pCreateInfo->pNext != NULL && pCreateInfo->pEnabledFeatures) {
381 // Check for get_physical_device_properties2 struct
John Zulaufde972ac2017-10-26 12:07:05 -0600382 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
383 if (features2) {
384 // Cannot include VkPhysicalDeviceFeatures2KHR and have non-null pEnabledFeatures
385 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
386 __LINE__, INVALID_USAGE, LayerName,
387 "VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceFeatures2KHR struct when "
388 "pCreateInfo->pEnabledFeatures is non-NULL.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600389 }
390 }
391
392 // Validate pCreateInfo->pQueueCreateInfos
393 if (pCreateInfo->pQueueCreateInfos) {
394 std::unordered_set<uint32_t> set;
395
396 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
397 const uint32_t requested_queue_family = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
398 if (requested_queue_family == VK_QUEUE_FAMILY_IGNORED) {
399 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
400 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
401 VALIDATION_ERROR_06c002fa, LayerName,
402 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700403 "].queueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family "
404 "index value. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600405 i, validation_error_map[VALIDATION_ERROR_06c002fa]);
406 } else if (set.count(requested_queue_family)) {
407 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
408 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
409 VALIDATION_ERROR_056002e8, LayerName,
410 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].queueFamilyIndex (=%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700411 ") is not unique within pCreateInfo->pQueueCreateInfos array. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600412 i, requested_queue_family, validation_error_map[VALIDATION_ERROR_056002e8]);
413 } else {
414 set.insert(requested_queue_family);
415 }
416
417 if (pCreateInfo->pQueueCreateInfos[i].pQueuePriorities != nullptr) {
418 for (uint32_t j = 0; j < pCreateInfo->pQueueCreateInfos[i].queueCount; ++j) {
419 const float queue_priority = pCreateInfo->pQueueCreateInfos[i].pQueuePriorities[j];
420 if (!(queue_priority >= 0.f) || !(queue_priority <= 1.f)) {
421 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
422 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
423 VALIDATION_ERROR_06c002fe, LayerName,
424 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].pQueuePriorities[%" PRIu32
425 "] (=%f) is not between 0 and 1 (inclusive). %s",
426 i, j, queue_priority, validation_error_map[VALIDATION_ERROR_06c002fe]);
427 }
428 }
429 }
430 }
431 }
432
433 return skip;
434}
435
436VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
437 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
438 // NOTE: Don't validate physicalDevice or any dispatchable object as the first parameter. We couldn't get here if it was wrong!
439
440 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
441 bool skip = false;
442 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
443 assert(my_instance_data != nullptr);
444 std::unique_lock<std::mutex> lock(global_lock);
445
446 skip |= parameter_validation_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
447
448 if (pCreateInfo != NULL) skip |= ValidateDeviceCreateInfo(my_instance_data, physicalDevice, pCreateInfo);
449
450 if (!skip) {
451 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
452 assert(chain_info != nullptr);
453 assert(chain_info->u.pLayerInfo != nullptr);
454
455 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
456 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
457 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice");
458 if (fpCreateDevice == NULL) {
459 return VK_ERROR_INITIALIZATION_FAILED;
460 }
461
462 // Advance the link info for the next element on the chain
463 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
464
465 lock.unlock();
466
467 result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
468
469 lock.lock();
470
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600471 if (result == VK_SUCCESS) {
472 layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
473 assert(my_device_data != nullptr);
474
475 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
476 layer_init_device_dispatch_table(*pDevice, &my_device_data->dispatch_table, fpGetDeviceProcAddr);
477
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600478 // Query and save physical device limits for this device
479 VkPhysicalDeviceProperties device_properties = {};
480 my_instance_data->dispatch_table.GetPhysicalDeviceProperties(physicalDevice, &device_properties);
481
482 my_device_data->api_version = my_device_data->extensions.InitFromDeviceCreateInfo(
483 &my_instance_data->extensions, device_properties.apiVersion, pCreateInfo);
484
485 uint32_t specified_api_version = device_properties.apiVersion & ~VK_VERSION_PATCH(~0);
486 if (!(specified_api_version == VK_API_VERSION_1_0) && !(specified_api_version == VK_API_VERSION_1_1)) {
487 LOGCONSOLE(
488 "Warning: Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number -- (0x%8x) assuming "
489 "%s.\n",
490 device_properties.apiVersion,
491 (my_device_data->api_version == VK_API_VERSION_1_0) ? "VK_API_VERSION_1_0" : "VK_API_VERSION_1_1");
492 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600493
494 // Store createdevice data
495 if ((pCreateInfo != nullptr) && (pCreateInfo->pQueueCreateInfos != nullptr)) {
496 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
497 my_device_data->queueFamilyIndexMap.insert(std::make_pair(pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex,
498 pCreateInfo->pQueueCreateInfos[i].queueCount));
499 }
500 }
501
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600502 memcpy(&my_device_data->device_limits, &device_properties.limits, sizeof(VkPhysicalDeviceLimits));
503 my_device_data->physical_device = physicalDevice;
504 my_device_data->device = *pDevice;
505
506 // Save app-enabled features in this device's layer_data structure
John Zulauf1bde5bb2017-10-18 18:21:23 -0600507 // The enabled features can come from either pEnabledFeatures, or from the pNext chain
508 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
509 if ((nullptr == enabled_features_found) && my_device_data->extensions.vk_khr_get_physical_device_properties_2) {
John Zulaufde972ac2017-10-26 12:07:05 -0600510 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
511 if (features2) {
512 enabled_features_found = &(features2->features);
John Zulauf1bde5bb2017-10-18 18:21:23 -0600513 }
514 }
515 if (enabled_features_found) {
Dave Houltonb3bbec72018-01-17 10:13:33 -0700516 my_device_data->physical_device_features = *enabled_features_found;
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600517 } else {
518 memset(&my_device_data->physical_device_features, 0, sizeof(VkPhysicalDeviceFeatures));
519 }
520 }
521 }
522
523 return result;
524}
525
526VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
527 dispatch_key key = get_dispatch_key(device);
528 bool skip = false;
529 layer_data *device_data = GetLayerDataPtr(key, layer_data_map);
530 {
531 std::unique_lock<std::mutex> lock(global_lock);
532 skip |= parameter_validation_vkDestroyDevice(device, pAllocator);
533 }
534
535 if (!skip) {
536 layer_debug_report_destroy_device(device);
537 device_data->dispatch_table.DestroyDevice(device, pAllocator);
538 }
539 FreeLayerDataPtr(key, layer_data_map);
540}
541
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600542bool pv_vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
543 bool skip = false;
544 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
545
546 skip |=
547 ValidateDeviceQueueFamily(device_data, queueFamilyIndex, "vkGetDeviceQueue", "queueFamilyIndex", VALIDATION_ERROR_29600300);
548 const auto &queue_data = device_data->queueFamilyIndexMap.find(queueFamilyIndex);
549 if (queue_data != device_data->queueFamilyIndexMap.end() && queue_data->second <= queueIndex) {
550 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
551 HandleToUint64(device), __LINE__, VALIDATION_ERROR_29600302, LayerName,
552 "vkGetDeviceQueue: queueIndex (=%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700553 ") is not less than the number of queues requested from queueFamilyIndex (=%" PRIu32
554 ") when the device was created (i.e. is not less than %" PRIu32 "). %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600555 queueIndex, queueFamilyIndex, queue_data->second, validation_error_map[VALIDATION_ERROR_29600302]);
556 }
557 return skip;
558}
559
560VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
561 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool) {
562 layer_data *local_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
563 bool skip = false;
564 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
565 std::unique_lock<std::mutex> lock(global_lock);
566
567 skip |= ValidateDeviceQueueFamily(local_data, pCreateInfo->queueFamilyIndex, "vkCreateCommandPool",
568 "pCreateInfo->queueFamilyIndex", VALIDATION_ERROR_02c0004e);
569
570 skip |= parameter_validation_vkCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
571
572 lock.unlock();
573 if (!skip) {
574 result = local_data->dispatch_table.CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
575 }
576 return result;
577}
578
579VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
580 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool) {
581 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
582 bool skip = false;
583 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
584
585 skip |= parameter_validation_vkCreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
586
587 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
588 if (pCreateInfo != nullptr) {
589 // If queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, pipelineStatistics must be a valid combination of
590 // VkQueryPipelineStatisticFlagBits values
591 if ((pCreateInfo->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS) && (pCreateInfo->pipelineStatistics != 0) &&
592 ((pCreateInfo->pipelineStatistics & (~AllVkQueryPipelineStatisticFlagBits)) != 0)) {
593 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
594 __LINE__, VALIDATION_ERROR_11c00630, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700595 "vkCreateQueryPool(): if pCreateInfo->queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, "
596 "pCreateInfo->pipelineStatistics must be a valid combination of VkQueryPipelineStatisticFlagBits "
597 "values. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600598 validation_error_map[VALIDATION_ERROR_11c00630]);
599 }
600 }
601 if (!skip) {
602 result = device_data->dispatch_table.CreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
603 }
604 return result;
605}
606
Petr Krause91f7a12017-12-14 20:57:36 +0100607VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
608 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass) {
609 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
610 bool skip = false;
611 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
612
613 {
614 std::unique_lock<std::mutex> lock(global_lock);
615 skip |= parameter_validation_vkCreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
616
Dave Houltonb3bbec72018-01-17 10:13:33 -0700617 typedef bool (*PFN_manual_vkCreateRenderPass)(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
618 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
Petr Krause91f7a12017-12-14 20:57:36 +0100619 PFN_manual_vkCreateRenderPass custom_func = (PFN_manual_vkCreateRenderPass)custom_functions["vkCreateRenderPass"];
620 if (custom_func != nullptr) {
621 skip |= custom_func(device, pCreateInfo, pAllocator, pRenderPass);
622 }
623 }
624
625 if (!skip) {
626 result = device_data->dispatch_table.CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
627
628 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
629 if (result == VK_SUCCESS) {
630 std::unique_lock<std::mutex> lock(global_lock);
631 const auto renderPass = *pRenderPass;
632 auto &renderpass_state = device_data->renderpasses_states[renderPass];
633
634 for (uint32_t subpass = 0; subpass < pCreateInfo->subpassCount; ++subpass) {
635 bool uses_color = false;
636 for (uint32_t i = 0; i < pCreateInfo->pSubpasses[subpass].colorAttachmentCount && !uses_color; ++i)
637 if (pCreateInfo->pSubpasses[subpass].pColorAttachments[i].attachment != VK_ATTACHMENT_UNUSED) uses_color = true;
638
639 bool uses_depthstencil = false;
640 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment)
641 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)
642 uses_depthstencil = true;
643
644 if (uses_color) renderpass_state.subpasses_using_color_attachment.insert(subpass);
645 if (uses_depthstencil) renderpass_state.subpasses_using_depthstencil_attachment.insert(subpass);
646 }
647 }
648 }
649 return result;
650}
651
652VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator) {
653 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
654 bool skip = false;
655
656 {
657 std::unique_lock<std::mutex> lock(global_lock);
658 skip |= parameter_validation_vkDestroyRenderPass(device, renderPass, pAllocator);
659
Dave Houltonb3bbec72018-01-17 10:13:33 -0700660 typedef bool (*PFN_manual_vkDestroyRenderPass)(VkDevice device, VkRenderPass renderPass,
661 const VkAllocationCallbacks *pAllocator);
Petr Krause91f7a12017-12-14 20:57:36 +0100662 PFN_manual_vkDestroyRenderPass custom_func = (PFN_manual_vkDestroyRenderPass)custom_functions["vkDestroyRenderPass"];
663 if (custom_func != nullptr) {
664 skip |= custom_func(device, renderPass, pAllocator);
665 }
666 }
667
668 if (!skip) {
669 device_data->dispatch_table.DestroyRenderPass(device, renderPass, pAllocator);
670
671 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
672 {
673 std::unique_lock<std::mutex> lock(global_lock);
674 device_data->renderpasses_states.erase(renderPass);
675 }
676 }
677}
678
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600679bool pv_vkCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
680 VkBuffer *pBuffer) {
681 bool skip = false;
682 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
683 debug_report_data *report_data = device_data->report_data;
684
Petr Krause5c37652018-01-05 04:05:12 +0100685 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, VK_NULL_HANDLE, LayerName, "vkCreateBuffer"};
686
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600687 if (pCreateInfo != nullptr) {
Petr Krause5c37652018-01-05 04:05:12 +0100688 skip |= ValidateGreaterThanZero(pCreateInfo->size, "pCreateInfo->size", VALIDATION_ERROR_01400720, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600689
690 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
691 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
692 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
693 if (pCreateInfo->queueFamilyIndexCount <= 1) {
694 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
695 VALIDATION_ERROR_01400724, LayerName,
696 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
697 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
698 validation_error_map[VALIDATION_ERROR_01400724]);
699 }
700
701 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
702 // queueFamilyIndexCount uint32_t values
703 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
704 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
705 VALIDATION_ERROR_01400722, LayerName,
706 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
707 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
708 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
709 validation_error_map[VALIDATION_ERROR_01400722]);
710 } else {
711 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
712 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
713 "vkCreateBuffer", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
714 false, "", "");
715 }
716 }
717
718 // If flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain
719 // VK_BUFFER_CREATE_SPARSE_BINDING_BIT
720 if (((pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
721 ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) != VK_BUFFER_CREATE_SPARSE_BINDING_BIT)) {
722 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
723 VALIDATION_ERROR_0140072c, LayerName,
724 "vkCreateBuffer: if pCreateInfo->flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or "
725 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_BUFFER_CREATE_SPARSE_BINDING_BIT. %s",
726 validation_error_map[VALIDATION_ERROR_0140072c]);
727 }
728 }
729
730 return skip;
731}
732
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600733bool pv_vkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
734 VkImage *pImage) {
735 bool skip = false;
736 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
737 debug_report_data *report_data = device_data->report_data;
738
Petr Krause5c37652018-01-05 04:05:12 +0100739 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, VK_NULL_HANDLE, LayerName, "vkCreateImage"};
740
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600741 if (pCreateInfo != nullptr) {
742 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
743 FormatIsCompressed_ETC2_EAC(pCreateInfo->format)) {
744 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
745 DEVICE_FEATURE, LayerName,
746 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionETC2 feature is "
747 "not enabled: neither ETC2 nor EAC formats can be used to create images.",
748 string_VkFormat(pCreateInfo->format));
749 }
750
751 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
752 FormatIsCompressed_ASTC_LDR(pCreateInfo->format)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700753 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
754 DEVICE_FEATURE, LayerName,
755 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionASTC_LDR feature "
756 "is not enabled: ASTC formats cannot be used to create images.",
757 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600758 }
759
760 if ((device_data->physical_device_features.textureCompressionBC == false) && FormatIsCompressed_BC(pCreateInfo->format)) {
761 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
762 DEVICE_FEATURE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700763 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionBC feature is not "
764 "enabled: BC compressed formats cannot be used to create images.",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600765 string_VkFormat(pCreateInfo->format));
766 }
767
768 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
769 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
770 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
771 if (pCreateInfo->queueFamilyIndexCount <= 1) {
772 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
773 VALIDATION_ERROR_09e0075c, LayerName,
774 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
775 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
776 validation_error_map[VALIDATION_ERROR_09e0075c]);
777 }
778
779 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
780 // queueFamilyIndexCount uint32_t values
781 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
782 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
783 VALIDATION_ERROR_09e0075a, LayerName,
784 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
785 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
786 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
787 validation_error_map[VALIDATION_ERROR_09e0075a]);
788 } else {
789 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
790 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
791 "vkCreateImage", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
792 false, "", "");
793 }
794 }
795
Petr Krause5c37652018-01-05 04:05:12 +0100796 skip |=
797 ValidateGreaterThanZero(pCreateInfo->extent.width, "pCreateInfo->extent.width", VALIDATION_ERROR_09e00760, log_misc);
798 skip |=
799 ValidateGreaterThanZero(pCreateInfo->extent.height, "pCreateInfo->extent.height", VALIDATION_ERROR_09e00762, log_misc);
800 skip |=
801 ValidateGreaterThanZero(pCreateInfo->extent.depth, "pCreateInfo->extent.depth", VALIDATION_ERROR_09e00764, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600802
Petr Krause5c37652018-01-05 04:05:12 +0100803 skip |= ValidateGreaterThanZero(pCreateInfo->mipLevels, "pCreateInfo->mipLevels", VALIDATION_ERROR_09e00766, log_misc);
804 skip |= ValidateGreaterThanZero(pCreateInfo->arrayLayers, "pCreateInfo->arrayLayers", VALIDATION_ERROR_09e00768, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600805
Dave Houlton130c0212018-01-29 13:39:56 -0700806 // InitialLayout must be PREINITIALIZED or UNDEFINED
Dave Houltone19e20d2018-02-02 16:32:41 -0700807 if ((pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED) &&
808 (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED)) {
809 skip |= log_msg(
810 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dave Houlton130c0212018-01-29 13:39:56 -0700811 VALIDATION_ERROR_09e007c2, LayerName,
812 "vkCreateImage(): initialLayout is %s, must be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
813 string_VkImageLayout(pCreateInfo->initialLayout), validation_error_map[VALIDATION_ERROR_09e007c2]);
814 }
815
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600816 // If imageType is VK_IMAGE_TYPE_1D, both extent.height and extent.depth must be 1
817 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) && (pCreateInfo->extent.height != 1) && (pCreateInfo->extent.depth != 1)) {
818 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dave Houltone19e20d2018-02-02 16:32:41 -0700819 VALIDATION_ERROR_09e00778, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700820 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_1D, both pCreateInfo->extent.height and "
821 "pCreateInfo->extent.depth must be 1. %s",
Dave Houltone19e20d2018-02-02 16:32:41 -0700822 validation_error_map[VALIDATION_ERROR_09e00778]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600823 }
824
825 if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D) {
826 // If imageType is VK_IMAGE_TYPE_2D and flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, extent.width and
827 // extent.height must be equal
828 if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
829 (pCreateInfo->extent.width != pCreateInfo->extent.height)) {
830 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
831 VALIDATION_ERROR_09e00774, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700832 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D and pCreateInfo->flags contains "
833 "VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, pCreateInfo->extent.width and pCreateInfo->extent.height "
834 "must be equal. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600835 validation_error_map[VALIDATION_ERROR_09e00774]);
836 }
837
838 if (pCreateInfo->extent.depth != 1) {
839 skip |= log_msg(
840 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
841 VALIDATION_ERROR_09e0077a, LayerName,
842 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1. %s",
843 validation_error_map[VALIDATION_ERROR_09e0077a]);
844 }
845 }
846
Dave Houlton130c0212018-01-29 13:39:56 -0700847 // 3D image may have only 1 layer
848 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_3D) && (pCreateInfo->arrayLayers != 1)) {
849 skip |=
850 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
851 VALIDATION_ERROR_09e00782, LayerName,
852 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_3D, pCreateInfo->arrayLayers must be 1. %s",
853 validation_error_map[VALIDATION_ERROR_09e00782]);
854 }
855
856 // If multi-sample, validate type, usage, tiling and mip levels.
857 if ((pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) &&
858 ((pCreateInfo->imageType != VK_IMAGE_TYPE_2D) || (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) ||
859 (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) || (pCreateInfo->mipLevels != 1))) {
860 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
861 VALIDATION_ERROR_09e00784, LayerName,
862 "vkCreateImage(): Multi-sample image with incompatible type, usage, tiling, or mips. %s",
863 validation_error_map[VALIDATION_ERROR_09e00784]);
864 }
865
866 if (0 != (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
867 VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
868 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
869 // At least one of the legal attachment bits must be set
870 if (0 == (pCreateInfo->usage & legal_flags)) {
871 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
872 VALIDATION_ERROR_09e0078c, LayerName,
873 "vkCreateImage(): Transient attachment image without a compatible attachment flag set. %s",
874 validation_error_map[VALIDATION_ERROR_09e0078c]);
875 }
876 // No flags other than the legal attachment bits may be set
877 legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
878 if (0 != (pCreateInfo->usage & ~legal_flags)) {
879 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
880 VALIDATION_ERROR_09e00786, LayerName,
881 "vkCreateImage(): Transient attachment image with incompatible usage flags set. %s",
882 validation_error_map[VALIDATION_ERROR_09e00786]);
883 }
884 }
885
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600886 // mipLevels must be less than or equal to floor(log2(max(extent.width,extent.height,extent.depth)))+1
887 uint32_t maxDim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
Petr Krause5c37652018-01-05 04:05:12 +0100888 if (maxDim > 0 && pCreateInfo->mipLevels > (floor(log2(maxDim)) + 1)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600889 skip |=
890 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
891 VALIDATION_ERROR_09e0077c, LayerName,
892 "vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
893 "floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1. %s",
894 validation_error_map[VALIDATION_ERROR_09e0077c]);
895 }
896
897 // If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
898 // VK_IMAGE_CREATE_SPARSE_BINDING_BIT
899 if (((pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
900 ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
901 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
902 VALIDATION_ERROR_09e007b6, LayerName,
903 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
904 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT. %s",
905 validation_error_map[VALIDATION_ERROR_09e007b6]);
906 }
907
908 // Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
909 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
910 // Linear tiling is unsupported
911 if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
912 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
913 INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700914 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image "
915 "tiling of VK_IMAGE_TILING_LINEAR is not supported");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600916 }
917
918 // Sparse 1D image isn't valid
919 if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
920 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
921 VALIDATION_ERROR_09e00794, LayerName,
922 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image. %s",
923 validation_error_map[VALIDATION_ERROR_09e00794]);
924 }
925
926 // Sparse 2D image when device doesn't support it
927 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage2D) &&
928 (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
929 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
930 VALIDATION_ERROR_09e00796, LayerName,
931 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
932 "feature is not enabled on the device. %s",
933 validation_error_map[VALIDATION_ERROR_09e00796]);
934 }
935
936 // Sparse 3D image when device doesn't support it
937 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage3D) &&
938 (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
939 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
940 VALIDATION_ERROR_09e00798, LayerName,
941 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
942 "feature is not enabled on the device. %s",
943 validation_error_map[VALIDATION_ERROR_09e00798]);
944 }
945
946 // Multi-sample 2D image when device doesn't support it
947 if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
948 if ((VK_FALSE == device_data->physical_device_features.sparseResidency2Samples) &&
949 (VK_SAMPLE_COUNT_2_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700950 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
951 __LINE__, VALIDATION_ERROR_09e0079a, LayerName,
952 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if "
953 "corresponding feature is not enabled on the device. %s",
954 validation_error_map[VALIDATION_ERROR_09e0079a]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600955 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency4Samples) &&
956 (VK_SAMPLE_COUNT_4_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700957 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
958 __LINE__, VALIDATION_ERROR_09e0079c, LayerName,
959 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if "
960 "corresponding feature is not enabled on the device. %s",
961 validation_error_map[VALIDATION_ERROR_09e0079c]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600962 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency8Samples) &&
963 (VK_SAMPLE_COUNT_8_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700964 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
965 __LINE__, VALIDATION_ERROR_09e0079e, LayerName,
966 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if "
967 "corresponding feature is not enabled on the device. %s",
968 validation_error_map[VALIDATION_ERROR_09e0079e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600969 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency16Samples) &&
970 (VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700971 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
972 __LINE__, VALIDATION_ERROR_09e007a0, LayerName,
973 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if "
974 "corresponding feature is not enabled on the device. %s",
975 validation_error_map[VALIDATION_ERROR_09e007a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600976 }
977 }
978 }
979 }
980 return skip;
981}
982
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600983bool pv_vkCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
984 VkImageView *pView) {
985 bool skip = false;
986 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
987 debug_report_data *report_data = device_data->report_data;
988
989 if (pCreateInfo != nullptr) {
990 if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) || (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D)) {
991 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
992 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
993 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
994 LayerName,
995 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD, "
996 "pCreateInfo->subresourceRange.layerCount must be 1",
997 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) ? 1 : 2));
998 }
999 } else if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ||
1000 (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
1001 if ((pCreateInfo->subresourceRange.layerCount < 1) &&
1002 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1003 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1004 LayerName,
1005 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD_ARRAY, "
1006 "pCreateInfo->subresourceRange.layerCount must be >= 1",
1007 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ? 1 : 2));
1008 }
1009 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE) {
1010 if ((pCreateInfo->subresourceRange.layerCount != 6) &&
1011 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1012 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1013 LayerName,
1014 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE, "
1015 "pCreateInfo->subresourceRange.layerCount must be 6");
1016 }
1017 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
1018 if (((pCreateInfo->subresourceRange.layerCount == 0) || ((pCreateInfo->subresourceRange.layerCount % 6) != 0)) &&
1019 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1020 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1021 LayerName,
1022 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE_ARRAY, "
1023 "pCreateInfo->subresourceRange.layerCount must be a multiple of 6");
1024 }
1025 if (!device_data->physical_device_features.imageCubeArray) {
1026 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1027 LayerName, "vkCreateImageView: Device feature imageCubeArray not enabled.");
1028 }
1029 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_3D) {
1030 if (pCreateInfo->subresourceRange.baseArrayLayer != 0) {
1031 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1032 LayerName,
1033 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1034 "pCreateInfo->subresourceRange.baseArrayLayer must be 0");
1035 }
1036
1037 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
1038 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1039 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1040 LayerName,
1041 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1042 "pCreateInfo->subresourceRange.layerCount must be 1");
1043 }
1044 }
1045 }
1046 return skip;
1047}
1048
Petr Krausb3fcdb42018-01-09 22:09:09 +01001049bool pv_VkViewport(const layer_data *device_data, const VkViewport &viewport, const char *fn_name, const char *param_name,
1050 VkDebugReportObjectTypeEXT object_type, uint64_t object = 0) {
1051 bool skip = false;
1052 debug_report_data *report_data = device_data->report_data;
1053
1054 // Note: for numerical correctness
1055 // - float comparisons should expect NaN (comparison always false).
1056 // - VkPhysicalDeviceLimits::maxViewportDimensions is uint32_t, not float -> careful.
1057
1058 const auto f_lte_u32_exact = [](const float v1_f, const uint32_t v2_u32) {
John Zulaufac0876c2018-02-19 10:09:35 -07001059 if (std::isnan(v1_f)) return false;
Petr Krausb3fcdb42018-01-09 22:09:09 +01001060 if (v1_f <= 0.0f) return true;
1061
1062 float intpart;
1063 const float fract = modff(v1_f, &intpart);
1064
1065 assert(std::numeric_limits<float>::radix == 2);
1066 const float u32_max_plus1 = ldexpf(1.0f, 32); // hopefully exact
1067 if (intpart >= u32_max_plus1) return false;
1068
1069 uint32_t v1_u32 = static_cast<uint32_t>(intpart);
1070 if (v1_u32 < v2_u32)
1071 return true;
1072 else if (v1_u32 == v2_u32 && fract == 0.0f)
1073 return true;
1074 else
1075 return false;
1076 };
1077
1078 const auto f_lte_u32_direct = [](const float v1_f, const uint32_t v2_u32) {
1079 const float v2_f = static_cast<float>(v2_u32); // not accurate for > radix^digits; and undefined rounding mode
1080 return (v1_f <= v2_f);
1081 };
1082
1083 // width
1084 bool width_healthy = true;
1085 const auto max_w = device_data->device_limits.maxViewportDimensions[0];
1086
1087 if (!(viewport.width > 0.0f)) {
1088 width_healthy = false;
1089 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd4,
1090 LayerName, "%s: %s.width (=%f) is not greater than 0.0. %s", fn_name, param_name, viewport.width,
1091 validation_error_map[VALIDATION_ERROR_15000dd4]);
1092 } else if (!(f_lte_u32_exact(viewport.width, max_w) || f_lte_u32_direct(viewport.width, max_w))) {
1093 width_healthy = false;
1094 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd6,
1095 LayerName, "%s: %s.width (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32 "). %s",
1096 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1097 } else if (!f_lte_u32_exact(viewport.width, max_w) && f_lte_u32_direct(viewport.width, max_w)) {
1098 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1099 "%s: %s.width (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32
1100 "), but it is within the static_cast<float>(maxViewportDimensions[0]) limit. %s",
1101 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1102 }
1103
1104 // height
1105 bool height_healthy = true;
1106 const bool negative_height_enabled =
1107 device_data->extensions.vk_khr_maintenance1 || device_data->extensions.vk_amd_negative_viewport_height;
1108 const auto max_h = device_data->device_limits.maxViewportDimensions[1];
1109
1110 if (!negative_height_enabled && !(viewport.height > 0.0f)) {
1111 height_healthy = false;
1112 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd8,
1113 LayerName, "%s: %s.height (=%f) is not greater 0.0. %s", fn_name, param_name, viewport.height,
1114 validation_error_map[VALIDATION_ERROR_15000dd8]);
1115 } else if (!(f_lte_u32_exact(fabsf(viewport.height), max_h) || f_lte_u32_direct(fabsf(viewport.height), max_h))) {
1116 height_healthy = false;
1117
1118 skip |= log_msg(
1119 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dda, LayerName,
1120 "%s: Absolute value of %s.height (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32 "). %s",
1121 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1122 } else if (!f_lte_u32_exact(fabsf(viewport.height), max_h) && f_lte_u32_direct(fabsf(viewport.height), max_h)) {
1123 height_healthy = false;
1124
1125 skip |= log_msg(
1126 report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1127 "%s: Absolute value of %s.height (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32
1128 "), but it is within the static_cast<float>(maxViewportDimensions[1]) limit. %s",
1129 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1130 }
1131
1132 // x
1133 bool x_healthy = true;
1134 if (!(viewport.x >= device_data->device_limits.viewportBoundsRange[0])) {
1135 x_healthy = false;
1136 skip |=
1137 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000ddc, LayerName,
1138 "%s: %s.x (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1139 viewport.x, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000ddc]);
1140 }
1141
1142 // x + width
1143 if (x_healthy && width_healthy) {
1144 const float right_bound = viewport.x + viewport.width;
1145 if (!(right_bound <= device_data->device_limits.viewportBoundsRange[1])) {
1146 skip |= log_msg(
1147 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1148 "%s: %s.x + %s.width (=%f + %f = %f) is greater than VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1149 fn_name, param_name, param_name, viewport.x, viewport.width, right_bound,
1150 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
1151 }
1152 }
1153
1154 // y
1155 bool y_healthy = true;
1156 if (!(viewport.y >= device_data->device_limits.viewportBoundsRange[0])) {
1157 y_healthy = false;
1158 skip |=
1159 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dde, LayerName,
1160 "%s: %s.y (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1161 viewport.y, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000dde]);
1162 } else if (negative_height_enabled && !(viewport.y <= device_data->device_limits.viewportBoundsRange[1])) {
1163 y_healthy = false;
1164 skip |=
1165 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de0, LayerName,
1166 "%s: %s.y (=%f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s", fn_name, param_name,
1167 viewport.y, device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_15000de0]);
1168 }
1169
1170 // y + height
1171 if (y_healthy && height_healthy) {
1172 const float boundary = viewport.y + viewport.height;
1173
1174 if (!(boundary <= device_data->device_limits.viewportBoundsRange[1])) {
1175 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a2,
1176 LayerName,
1177 "%s: %s.y + %s.height (=%f + %f = %f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1178 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1179 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
1180 } else if (negative_height_enabled && !(boundary >= device_data->device_limits.viewportBoundsRange[0])) {
1181 skip |= log_msg(
1182 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de2, LayerName,
1183 "%s: %s.y + %s.height (=%f + %f = %f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s",
1184 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1185 device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000de2]);
1186 }
1187 }
1188
1189 if (!device_data->extensions.vk_ext_depth_range_unrestricted) {
1190 // minDepth
1191 if (!(viewport.minDepth >= 0.0) || !(viewport.minDepth <= 1.0)) {
1192 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a4,
1193 LayerName,
1194 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.minDepth (=%f) is not within the "
1195 "[0.0, 1.0] range. %s",
1196 fn_name, param_name, viewport.minDepth, validation_error_map[VALIDATION_ERROR_150009a4]);
1197 }
1198
1199 // maxDepth
1200 if (!(viewport.maxDepth >= 0.0) || !(viewport.maxDepth <= 1.0)) {
1201 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a6,
1202 LayerName,
1203 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.maxDepth (=%f) is not within the "
1204 "[0.0, 1.0] range. %s",
1205 fn_name, param_name, viewport.maxDepth, validation_error_map[VALIDATION_ERROR_150009a6]);
1206 }
1207 }
1208
1209 return skip;
1210}
1211
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001212bool pv_vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1213 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1214 VkPipeline *pPipelines) {
1215 bool skip = false;
1216 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1217 debug_report_data *report_data = device_data->report_data;
1218
1219 if (pCreateInfos != nullptr) {
1220 for (uint32_t i = 0; i < createInfoCount; ++i) {
Petr Kraus299ba622017-11-24 03:09:03 +01001221 bool has_dynamic_viewport = false;
1222 bool has_dynamic_scissor = false;
1223 bool has_dynamic_line_width = false;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001224 bool has_dynamic_viewport_w_scaling_nv = false;
1225 bool has_dynamic_discard_rectangle_ext = false;
1226 bool has_dynamic_sample_locations_ext = false;
Petr Kraus299ba622017-11-24 03:09:03 +01001227 if (pCreateInfos[i].pDynamicState != nullptr) {
1228 const auto &dynamic_state_info = *pCreateInfos[i].pDynamicState;
1229 for (uint32_t state_index = 0; state_index < dynamic_state_info.dynamicStateCount; ++state_index) {
1230 const auto &dynamic_state = dynamic_state_info.pDynamicStates[state_index];
1231 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT) has_dynamic_viewport = true;
1232 if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR) has_dynamic_scissor = true;
1233 if (dynamic_state == VK_DYNAMIC_STATE_LINE_WIDTH) has_dynamic_line_width = true;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001234 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV) has_dynamic_viewport_w_scaling_nv = true;
1235 if (dynamic_state == VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT) has_dynamic_discard_rectangle_ext = true;
1236 if (dynamic_state == VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) has_dynamic_sample_locations_ext = true;
Petr Kraus299ba622017-11-24 03:09:03 +01001237 }
1238 }
1239
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001240 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1241 if (pCreateInfos[i].pVertexInputState != nullptr) {
1242 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
1243 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
1244 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
1245 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1246 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1247 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
1248 "vkCreateGraphicsPipelines: parameter "
1249 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
1250 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1251 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
1252 validation_error_map[VALIDATION_ERROR_14c004d4]);
1253 }
1254
1255 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
1256 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1257 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
1258 "vkCreateGraphicsPipelines: parameter "
1259 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
1260 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
1261 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
1262 validation_error_map[VALIDATION_ERROR_14c004d6]);
1263 }
1264 }
1265
1266 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
1267 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
1268 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
1269 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1270 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
1271 "vkCreateGraphicsPipelines: parameter "
1272 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
1273 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
1274 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
1275 validation_error_map[VALIDATION_ERROR_14a004d8]);
1276 }
1277
1278 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1279 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1280 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
1281 "vkCreateGraphicsPipelines: parameter "
1282 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
1283 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1284 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
1285 validation_error_map[VALIDATION_ERROR_14a004da]);
1286 }
1287
1288 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
1289 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1290 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
1291 "vkCreateGraphicsPipelines: parameter "
1292 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
1293 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
1294 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
1295 validation_error_map[VALIDATION_ERROR_14a004dc]);
1296 }
1297 }
1298 }
1299
1300 if (pCreateInfos[i].pStages != nullptr) {
1301 bool has_control = false;
1302 bool has_eval = false;
1303
1304 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
1305 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1306 has_control = true;
1307 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
1308 has_eval = true;
1309 }
1310 }
1311
1312 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1313 if (has_control && has_eval) {
1314 if (pCreateInfos[i].pTessellationState == nullptr) {
1315 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1316 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
1317 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1318 "shader stage and a tessellation evaluation shader stage, "
1319 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
1320 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
1321 } else {
1322 skip |= validate_struct_pnext(
1323 report_data, "vkCreateGraphicsPipelines",
1324 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
1325 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
1326
1327 skip |= validate_reserved_flags(
1328 report_data, "vkCreateGraphicsPipelines",
1329 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1330 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1331
1332 if (pCreateInfos[i].pTessellationState->sType !=
1333 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1334 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1335 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1336 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1337 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1338 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1339 }
1340
1341 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1342 pCreateInfos[i].pTessellationState->patchControlPoints >
1343 device_data->device_limits.maxTessellationPatchSize) {
1344 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1345 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1346 "vkCreateGraphicsPipelines: invalid parameter "
1347 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1348 "should be >0 and <=%u. %s",
1349 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1350 device_data->device_limits.maxTessellationPatchSize,
1351 validation_error_map[VALIDATION_ERROR_1080097c]);
1352 }
1353 }
1354 }
1355 }
1356
1357 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1358 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1359 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1360 if (pCreateInfos[i].pViewportState == nullptr) {
Petr Krausa6103552017-11-16 21:21:58 +01001361 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1362 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1363 "vkCreateGraphicsPipelines: Rasterization is enabled (pCreateInfos[%" PRIu32
1364 "].pRasterizationState->rasterizerDiscardEnable is VK_FALSE), but pCreateInfos[%" PRIu32
1365 "].pViewportState (=NULL) is not a valid pointer. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001366 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1367 } else {
Petr Krausa6103552017-11-16 21:21:58 +01001368 const auto &viewport_state = *pCreateInfos[i].pViewportState;
1369
1370 if (viewport_state.sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1371 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1372 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b00b, LayerName,
1373 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1374 "].pViewportState->sType is not VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO. %s",
1375 i, validation_error_map[VALIDATION_ERROR_10c2b00b]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001376 }
1377
Petr Krausa6103552017-11-16 21:21:58 +01001378 const VkStructureType allowed_structs_VkPipelineViewportStateCreateInfo[] = {
1379 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
1380 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV};
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001381 skip |= validate_struct_pnext(
1382 report_data, "vkCreateGraphicsPipelines",
Petr Krausa6103552017-11-16 21:21:58 +01001383 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}),
1384 "VkPipelineViewportSwizzleStateCreateInfoNV, VkPipelineViewportWScalingStateCreateInfoNV",
1385 viewport_state.pNext, ARRAY_SIZE(allowed_structs_VkPipelineViewportStateCreateInfo),
1386 allowed_structs_VkPipelineViewportStateCreateInfo, 65, VALIDATION_ERROR_10c1c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001387
1388 skip |= validate_reserved_flags(
1389 report_data, "vkCreateGraphicsPipelines",
1390 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
Petr Krausa6103552017-11-16 21:21:58 +01001391 viewport_state.flags, VALIDATION_ERROR_10c09005);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001392
Petr Krausa6103552017-11-16 21:21:58 +01001393 if (!device_data->physical_device_features.multiViewport) {
1394 if (viewport_state.viewportCount != 1) {
1395 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1396 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1397 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1398 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32
1399 ") is not 1. %s",
1400 i, viewport_state.viewportCount, validation_error_map[VALIDATION_ERROR_10c00980]);
1401 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001402
Petr Krausa6103552017-11-16 21:21:58 +01001403 if (viewport_state.scissorCount != 1) {
1404 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1405 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1406 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1407 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->scissorCount (=%" PRIu32
1408 ") is not 1. %s",
1409 i, viewport_state.scissorCount, validation_error_map[VALIDATION_ERROR_10c00982]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001410 }
Petr Krausa6103552017-11-16 21:21:58 +01001411 } else { // multiViewport enabled
1412 if (viewport_state.viewportCount == 0) {
1413 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1414 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c30a1b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001415 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001416 "].pViewportState->viewportCount is 0. %s",
1417 i, validation_error_map[VALIDATION_ERROR_10c30a1b]);
1418 } else if (viewport_state.viewportCount > device_data->device_limits.maxViewports) {
1419 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1420 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1421 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1422 "].pViewportState->viewportCount (=%" PRIu32
1423 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1424 i, viewport_state.viewportCount, device_data->device_limits.maxViewports,
1425 validation_error_map[VALIDATION_ERROR_10c00984]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001426 }
Petr Krausa6103552017-11-16 21:21:58 +01001427
1428 if (viewport_state.scissorCount == 0) {
1429 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1430 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b61b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001431 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001432 "].pViewportState->scissorCount is 0. %s",
1433 i, validation_error_map[VALIDATION_ERROR_10c2b61b]);
1434 } else if (viewport_state.scissorCount > device_data->device_limits.maxViewports) {
1435 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1436 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1437 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1438 "].pViewportState->scissorCount (=%" PRIu32
1439 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1440 i, viewport_state.scissorCount, device_data->device_limits.maxViewports,
1441 validation_error_map[VALIDATION_ERROR_10c00986]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001442 }
1443 }
1444
Petr Krausa6103552017-11-16 21:21:58 +01001445 if (viewport_state.scissorCount != viewport_state.viewportCount) {
1446 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1447 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1448 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1449 "].pViewportState->scissorCount (=%" PRIu32 ") is not identical to pCreateInfos[%" PRIu32
1450 "].pViewportState->viewportCount (=%" PRIu32 "). %s",
1451 i, viewport_state.scissorCount, i, viewport_state.viewportCount,
1452 validation_error_map[VALIDATION_ERROR_10c00988]);
1453 }
1454
Petr Krausa6103552017-11-16 21:21:58 +01001455 if (!has_dynamic_viewport && viewport_state.viewportCount > 0 && viewport_state.pViewports == nullptr) {
1456 skip |= log_msg(
1457 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1458 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1459 "vkCreateGraphicsPipelines: The viewport state is static (pCreateInfos[%" PRIu32
1460 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001461 "].pViewportState->pViewports (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001462 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1463 }
1464
1465 if (!has_dynamic_scissor && viewport_state.scissorCount > 0 && viewport_state.pScissors == nullptr) {
1466 skip |= log_msg(
1467 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1468 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1469 "vkCreateGraphicsPipelines: The scissor state is static (pCreateInfos[%" PRIu32
1470 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_SCISSOR), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001471 "].pViewportState->pScissors (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001472 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1473 }
1474
Petr Krausb3fcdb42018-01-09 22:09:09 +01001475 // validate the VkViewports
1476 if (!has_dynamic_viewport && viewport_state.pViewports) {
1477 for (uint32_t viewport_i = 0; viewport_i < viewport_state.viewportCount; ++viewport_i) {
1478 const auto &viewport = viewport_state.pViewports[viewport_i]; // will crash on invalid ptr
1479 const char fn_name[] = "vkCreateGraphicsPipelines";
1480 const std::string param_name = "pCreateInfos[" + std::to_string(i) + "].pViewportState->pViewports[" +
1481 std::to_string(viewport_i) + "]";
1482 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
1483 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
1484 }
1485 }
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001486
1487 if (has_dynamic_viewport_w_scaling_nv && !device_data->extensions.vk_nv_clip_space_w_scaling) {
1488 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1489 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1490 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001491 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001492 "VK_NV_clip_space_w_scaling extension is not enabled.",
1493 i);
1494 }
1495
1496 if (has_dynamic_discard_rectangle_ext && !device_data->extensions.vk_ext_discard_rectangles) {
1497 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1498 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1499 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001500 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001501 "VK_EXT_discard_rectangles extension is not enabled.",
1502 i);
1503 }
1504
1505 if (has_dynamic_sample_locations_ext && !device_data->extensions.vk_ext_sample_locations) {
1506 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1507 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1508 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001509 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001510 "VK_EXT_sample_locations extension is not enabled.",
1511 i);
1512 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001513 }
1514
1515 if (pCreateInfos[i].pMultisampleState == nullptr) {
1516 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1517 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1518 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1519 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1520 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1521 } else {
Dave Houltonb3bbec72018-01-17 10:13:33 -07001522 const VkStructureType valid_next_stypes[] = {LvlTypeMap<VkPipelineCoverageModulationStateCreateInfoNV>::kSType,
1523 LvlTypeMap<VkPipelineCoverageToColorStateCreateInfoNV>::kSType,
1524 LvlTypeMap<VkPipelineSampleLocationsStateCreateInfoEXT>::kSType};
Mike Schuchardt97662b02017-12-06 13:31:29 -07001525 const char *valid_struct_names =
Dave Houltona9df0ce2018-02-07 10:51:23 -07001526 "VkPipelineCoverageModulationStateCreateInfoNV, VkPipelineCoverageToColorStateCreateInfoNV, "
John Zulauf96b0e422017-11-14 11:43:19 -07001527 "VkPipelineSampleLocationsStateCreateInfoEXT";
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001528 skip |= validate_struct_pnext(
1529 report_data, "vkCreateGraphicsPipelines",
John Zulauf96b0e422017-11-14 11:43:19 -07001530 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}),
1531 valid_struct_names, pCreateInfos[i].pMultisampleState->pNext, 3, valid_next_stypes, GeneratedHeaderVersion,
1532 VALIDATION_ERROR_1001c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001533
1534 skip |= validate_reserved_flags(
1535 report_data, "vkCreateGraphicsPipelines",
1536 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1537 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1538
1539 skip |= validate_bool32(
1540 report_data, "vkCreateGraphicsPipelines",
1541 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1542 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1543
1544 skip |= validate_array(
1545 report_data, "vkCreateGraphicsPipelines",
1546 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1547 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1548 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1549 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1550
1551 skip |= validate_bool32(
1552 report_data, "vkCreateGraphicsPipelines",
1553 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1554 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1555
1556 skip |= validate_bool32(
1557 report_data, "vkCreateGraphicsPipelines",
1558 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1559 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1560
1561 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1562 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1563 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1564 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1565 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1566 i);
1567 }
John Zulauf7acac592017-11-06 11:15:53 -07001568 if (pCreateInfos[i].pMultisampleState->sampleShadingEnable == VK_TRUE) {
1569 if (!device_data->physical_device_features.sampleRateShading) {
1570 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1571 __LINE__, VALIDATION_ERROR_10000620, LayerName,
1572 "vkCreateGraphicsPipelines(): parameter "
1573 "pCreateInfos[%d].pMultisampleState->sampleShadingEnable: %s",
1574 i, validation_error_map[VALIDATION_ERROR_10000620]);
1575 }
1576 // TODO Add documentation issue about when minSampleShading must be in range and when it is ignored
1577 // For now a "least noise" test *only* when sampleShadingEnable is VK_TRUE.
1578 if (!in_inclusive_range(pCreateInfos[i].pMultisampleState->minSampleShading, 0.F, 1.0F)) {
1579 skip |= log_msg(
1580 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1581 VALIDATION_ERROR_10000624, LayerName,
1582 "vkCreateGraphicsPipelines(): parameter pCreateInfos[%d].pMultisampleState->minSampleShading: %s",
1583 i, validation_error_map[VALIDATION_ERROR_10000624]);
1584 }
1585 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001586 }
1587
Petr Krause91f7a12017-12-14 20:57:36 +01001588 bool uses_color_attachment = false;
1589 bool uses_depthstencil_attachment = false;
1590 {
1591 const auto subpasses_uses_it = device_data->renderpasses_states.find(pCreateInfos[i].renderPass);
1592 if (subpasses_uses_it != device_data->renderpasses_states.end()) {
1593 const auto &subpasses_uses = subpasses_uses_it->second;
1594 if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[i].subpass))
1595 uses_color_attachment = true;
1596 if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[i].subpass))
1597 uses_depthstencil_attachment = true;
1598 }
1599 }
1600
1601 if (pCreateInfos[i].pDepthStencilState != nullptr && uses_depthstencil_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001602 skip |= validate_struct_pnext(
1603 report_data, "vkCreateGraphicsPipelines",
1604 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1605 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1606
1607 skip |= validate_reserved_flags(
1608 report_data, "vkCreateGraphicsPipelines",
1609 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1610 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1611
1612 skip |= validate_bool32(
1613 report_data, "vkCreateGraphicsPipelines",
1614 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1615 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1616
1617 skip |= validate_bool32(
1618 report_data, "vkCreateGraphicsPipelines",
1619 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1620 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1621
1622 skip |= validate_ranged_enum(
1623 report_data, "vkCreateGraphicsPipelines",
1624 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1625 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1626 VALIDATION_ERROR_0f604001);
1627
1628 skip |= validate_bool32(
1629 report_data, "vkCreateGraphicsPipelines",
1630 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1631 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1632
1633 skip |= validate_bool32(
1634 report_data, "vkCreateGraphicsPipelines",
1635 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1636 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1637
1638 skip |= validate_ranged_enum(
1639 report_data, "vkCreateGraphicsPipelines",
1640 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1641 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1642 VALIDATION_ERROR_13a08601);
1643
1644 skip |= validate_ranged_enum(
1645 report_data, "vkCreateGraphicsPipelines",
1646 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1647 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1648 VALIDATION_ERROR_13a27801);
1649
1650 skip |= validate_ranged_enum(
1651 report_data, "vkCreateGraphicsPipelines",
1652 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1653 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1654 VALIDATION_ERROR_13a04201);
1655
1656 skip |= validate_ranged_enum(
1657 report_data, "vkCreateGraphicsPipelines",
1658 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1659 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1660 VALIDATION_ERROR_0f604001);
1661
1662 skip |= validate_ranged_enum(
1663 report_data, "vkCreateGraphicsPipelines",
1664 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1665 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1666 VALIDATION_ERROR_13a08601);
1667
1668 skip |= validate_ranged_enum(
1669 report_data, "vkCreateGraphicsPipelines",
1670 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1671 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1672 VALIDATION_ERROR_13a27801);
1673
1674 skip |= validate_ranged_enum(
1675 report_data, "vkCreateGraphicsPipelines",
1676 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1677 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1678 VALIDATION_ERROR_13a04201);
1679
1680 skip |= validate_ranged_enum(
1681 report_data, "vkCreateGraphicsPipelines",
1682 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1683 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1684 VALIDATION_ERROR_0f604001);
1685
1686 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1687 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1688 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1689 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1690 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1691 i);
1692 }
1693 }
1694
Petr Krause91f7a12017-12-14 20:57:36 +01001695 if (pCreateInfos[i].pColorBlendState != nullptr && uses_color_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001696 skip |= validate_struct_pnext(
1697 report_data, "vkCreateGraphicsPipelines",
1698 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1699 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1700
1701 skip |= validate_reserved_flags(
1702 report_data, "vkCreateGraphicsPipelines",
1703 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1704 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1705
1706 skip |= validate_bool32(
1707 report_data, "vkCreateGraphicsPipelines",
1708 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1709 pCreateInfos[i].pColorBlendState->logicOpEnable);
1710
1711 skip |= validate_array(
1712 report_data, "vkCreateGraphicsPipelines",
1713 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1714 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1715 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1716 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1717
1718 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1719 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1720 ++attachmentIndex) {
1721 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1722 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1723 ParameterName::IndexVector{i, attachmentIndex}),
1724 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1725
1726 skip |= validate_ranged_enum(
1727 report_data, "vkCreateGraphicsPipelines",
1728 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1729 ParameterName::IndexVector{i, attachmentIndex}),
1730 "VkBlendFactor", AllVkBlendFactorEnums,
1731 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1732 VALIDATION_ERROR_0f22cc01);
1733
1734 skip |= validate_ranged_enum(
1735 report_data, "vkCreateGraphicsPipelines",
1736 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1737 ParameterName::IndexVector{i, attachmentIndex}),
1738 "VkBlendFactor", AllVkBlendFactorEnums,
1739 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1740 VALIDATION_ERROR_0f207001);
1741
1742 skip |= validate_ranged_enum(
1743 report_data, "vkCreateGraphicsPipelines",
1744 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1745 ParameterName::IndexVector{i, attachmentIndex}),
1746 "VkBlendOp", AllVkBlendOpEnums,
1747 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1748 VALIDATION_ERROR_0f202001);
1749
1750 skip |= validate_ranged_enum(
1751 report_data, "vkCreateGraphicsPipelines",
1752 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1753 ParameterName::IndexVector{i, attachmentIndex}),
1754 "VkBlendFactor", AllVkBlendFactorEnums,
1755 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1756 VALIDATION_ERROR_0f22c601);
1757
1758 skip |= validate_ranged_enum(
1759 report_data, "vkCreateGraphicsPipelines",
1760 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1761 ParameterName::IndexVector{i, attachmentIndex}),
1762 "VkBlendFactor", AllVkBlendFactorEnums,
1763 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1764 VALIDATION_ERROR_0f206a01);
1765
1766 skip |= validate_ranged_enum(
1767 report_data, "vkCreateGraphicsPipelines",
1768 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1769 ParameterName::IndexVector{i, attachmentIndex}),
1770 "VkBlendOp", AllVkBlendOpEnums,
1771 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1772 VALIDATION_ERROR_0f200801);
1773
1774 skip |=
1775 validate_flags(report_data, "vkCreateGraphicsPipelines",
1776 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1777 ParameterName::IndexVector{i, attachmentIndex}),
1778 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1779 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1780 false, false, VALIDATION_ERROR_0f202201);
1781 }
1782 }
1783
1784 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1785 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1786 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1787 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1788 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1789 i);
1790 }
1791
1792 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1793 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1794 skip |= validate_ranged_enum(
1795 report_data, "vkCreateGraphicsPipelines",
1796 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1797 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1798 }
1799 }
1800 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001801
Petr Kraus9752aae2017-11-24 03:05:50 +01001802 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1803 if (pCreateInfos[i].basePipelineIndex != -1) {
1804 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001805 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1806 __LINE__, VALIDATION_ERROR_096005a8, LayerName,
1807 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be "
1808 "VK_NULL_HANDLE if pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag "
1809 "and pCreateInfos->basePipelineIndex is not -1. %s",
1810 validation_error_map[VALIDATION_ERROR_096005a8]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001811 }
1812 }
1813
Petr Kraus9752aae2017-11-24 03:05:50 +01001814 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
1815 if (pCreateInfos[i].basePipelineIndex != -1) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001816 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1817 __LINE__, VALIDATION_ERROR_096005aa, LayerName,
1818 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1819 "pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and "
1820 "pCreateInfos->basePipelineHandle is not VK_NULL_HANDLE. %s",
1821 validation_error_map[VALIDATION_ERROR_096005aa]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001822 }
1823 }
1824 }
1825
Petr Kraus9752aae2017-11-24 03:05:50 +01001826 if (pCreateInfos[i].pRasterizationState) {
1827 if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001828 (device_data->physical_device_features.fillModeNonSolid == false)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001829 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1830 __LINE__, DEVICE_FEATURE, LayerName,
1831 "vkCreateGraphicsPipelines parameter, VkPolygonMode "
1832 "pCreateInfos->pRasterizationState->polygonMode cannot be VK_POLYGON_MODE_POINT or "
1833 "VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001834 }
Petr Kraus299ba622017-11-24 03:09:03 +01001835
1836 if (!has_dynamic_line_width && !device_data->physical_device_features.wideLines &&
1837 (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
1838 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1839 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, 0, __LINE__, VALIDATION_ERROR_096005da, LayerName,
1840 "The line width state is static (pCreateInfos[%" PRIu32
1841 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
1842 "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
1843 "].pRasterizationState->lineWidth (=%f) is not 1.0. %s",
1844 i, i, pCreateInfos[i].pRasterizationState->lineWidth,
1845 validation_error_map[VALIDATION_ERROR_096005da]);
1846 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001847 }
1848
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001849 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1850 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1851 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1852 pCreateInfos[i].pStages[j].pName);
1853 }
1854 }
1855 }
1856
1857 return skip;
1858}
1859
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001860bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1861 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1862 VkPipeline *pPipelines) {
1863 bool skip = false;
1864 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1865
1866 for (uint32_t i = 0; i < createInfoCount; i++) {
1867 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1868 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1869 pCreateInfos[i].stage.pName);
1870 }
1871
1872 return skip;
1873}
1874
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001875bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1876 VkSampler *pSampler) {
1877 bool skip = false;
1878 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1879 debug_report_data *report_data = device_data->report_data;
1880
1881 if (pCreateInfo != nullptr) {
John Zulauf71968502017-10-26 13:51:15 -06001882 const auto &features = device_data->physical_device_features;
1883 const auto &limits = device_data->device_limits;
1884 if (pCreateInfo->anisotropyEnable == VK_TRUE) {
1885 if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
1886 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1887 VALIDATION_ERROR_1260085e, LayerName,
1888 "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found. %s",
1889 "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
1890 "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy,
1891 validation_error_map[VALIDATION_ERROR_1260085e]);
1892 }
1893
1894 // Anistropy cannot be enabled in sampler unless enabled as a feature
1895 if (features.samplerAnisotropy == VK_FALSE) {
1896 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1897 VALIDATION_ERROR_1260085c, LayerName,
1898 "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE. %s",
1899 "pCreateInfo->anisotropyEnable", validation_error_map[VALIDATION_ERROR_1260085c]);
1900 }
1901
1902 // Anistropy and unnormalized coordinates cannot be enabled simultaneously
1903 if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
1904 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1905 VALIDATION_ERROR_12600868, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001906 "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates must "
1907 "not both be VK_TRUE. %s",
John Zulauf71968502017-10-26 13:51:15 -06001908 validation_error_map[VALIDATION_ERROR_12600868]);
1909 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001910 }
1911
1912 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1913 if (pCreateInfo->compareEnable == VK_TRUE) {
1914 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1915 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
1916 }
1917
1918 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
1919 // valid VkBorderColor value
1920 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1921 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1922 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
1923 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
1924 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
1925 }
1926
1927 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
1928 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
1929 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
1930 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1931 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1932 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
1933 skip |=
1934 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1935 VALIDATION_ERROR_1260086e, LayerName,
1936 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
1937 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
1938 validation_error_map[VALIDATION_ERROR_1260086e]);
1939 }
John Zulauf275805c2017-10-26 15:34:49 -06001940
1941 // Checks for the IMG cubic filtering extension
1942 if (device_data->extensions.vk_img_filter_cubic) {
1943 if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
1944 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001945 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1946 VALIDATION_ERROR_12600872, LayerName,
1947 "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter "
1948 "are VK_FILTER_CUBIC_IMG. %s",
1949 validation_error_map[VALIDATION_ERROR_12600872]);
John Zulauf275805c2017-10-26 15:34:49 -06001950 }
1951 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001952 }
1953
1954 return skip;
1955}
1956
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001957bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1958 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
1959 bool skip = false;
1960 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1961 debug_report_data *report_data = device_data->report_data;
1962
1963 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1964 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
1965 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
1966 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
1967 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
1968 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
1969 // valid VkSampler handles
1970 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1971 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
1972 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
1973 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
1974 ++descriptor_index) {
1975 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
1976 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1977 __LINE__, REQUIRED_PARAMETER, LayerName,
1978 "vkCreateDescriptorSetLayout: required parameter "
Dave Houltona9df0ce2018-02-07 10:51:23 -07001979 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d] specified as VK_NULL_HANDLE",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001980 i, descriptor_index);
1981 }
1982 }
1983 }
1984
1985 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
1986 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
1987 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001988 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1989 __LINE__, VALIDATION_ERROR_04e00236, LayerName,
1990 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
1991 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits "
1992 "values. %s",
1993 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001994 }
1995 }
1996 }
1997 }
1998
1999 return skip;
2000}
2001
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002002bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
2003 const VkDescriptorSet *pDescriptorSets) {
2004 bool skip = false;
2005 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2006 debug_report_data *report_data = device_data->report_data;
2007
2008 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2009 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2010 // validate_array()
2011 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
2012 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2013 return skip;
2014}
2015
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002016bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
2017 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
2018 bool skip = false;
2019 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2020 debug_report_data *report_data = device_data->report_data;
2021
2022 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2023 if (pDescriptorWrites != NULL) {
2024 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
2025 // descriptorCount must be greater than 0
2026 if (pDescriptorWrites[i].descriptorCount == 0) {
2027 skip |=
2028 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2029 VALIDATION_ERROR_15c0441b, LayerName,
2030 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
2031 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
2032 }
2033
2034 // dstSet must be a valid VkDescriptorSet handle
2035 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2036 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
2037 pDescriptorWrites[i].dstSet);
2038
2039 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2040 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
2041 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
2042 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
2043 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
2044 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
2045 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2046 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
2047 if (pDescriptorWrites[i].pImageInfo == nullptr) {
2048 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2049 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
2050 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2051 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
2052 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
2053 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
2054 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
2055 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
2056 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
2057 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
2058 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
2059 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2060 ++descriptor_index) {
2061 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2062 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
2063 ParameterName::IndexVector{i, descriptor_index}),
2064 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
2065 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
2066 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
2067 ParameterName::IndexVector{i, descriptor_index}),
2068 "VkImageLayout", AllVkImageLayoutEnums,
2069 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
2070 VALIDATION_ERROR_UNDEFINED);
2071 }
2072 }
2073 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2074 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2075 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
2076 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2077 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
2078 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
2079 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
2080 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
2081 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2082 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
2083 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2084 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
2085 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
2086 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
2087 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
2088 } else {
2089 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
2090 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2091 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
2092 ParameterName::IndexVector{i, descriptorIndex}),
2093 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
2094 }
2095 }
2096 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
2097 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
2098 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
2099 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
2100 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
2101 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2102 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
2103 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2104 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
2105 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
2106 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
2107 } else {
2108 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2109 ++descriptor_index) {
2110 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2111 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
2112 ParameterName::IndexVector{i, descriptor_index}),
2113 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
2114 }
2115 }
2116 }
2117
2118 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2119 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
2120 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
2121 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2122 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2123 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
2124 skip |= log_msg(
2125 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2126 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
2127 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2128 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2129 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
2130 validation_error_map[VALIDATION_ERROR_15c0028e]);
2131 }
2132 }
2133 }
2134 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2135 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2136 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
2137 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2138 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2139 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
2140 skip |= log_msg(
2141 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2142 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
2143 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2144 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2145 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
2146 validation_error_map[VALIDATION_ERROR_15c00290]);
2147 }
2148 }
2149 }
2150 }
2151 }
2152 }
2153 return skip;
2154}
2155
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002156bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2157 VkRenderPass *pRenderPass) {
2158 bool skip = false;
2159 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2160 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
2161
2162 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
2163 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
2164 std::stringstream ss;
2165 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
2166 << validation_error_map[VALIDATION_ERROR_00809201];
2167 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2168 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
2169 }
2170 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
2171 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
2172 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2173 __LINE__, VALIDATION_ERROR_00800696, "DL",
2174 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
2175 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
2176 i, validation_error_map[VALIDATION_ERROR_00800696]);
2177 }
2178 }
2179
2180 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2181 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
2182 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2183 __LINE__, VALIDATION_ERROR_1400069a, "DL",
2184 "Cannot create a render pass with %d color attachments. Max is %d. %s",
2185 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
2186 validation_error_map[VALIDATION_ERROR_1400069a]);
2187 }
2188 }
2189 return skip;
2190}
2191
2192bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
2193 const VkCommandBuffer *pCommandBuffers) {
2194 bool skip = false;
2195 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2196 debug_report_data *report_data = device_data->report_data;
2197
2198 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2199 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2200 // validate_array()
2201 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
2202 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2203 return skip;
2204}
2205
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002206bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
2207 bool skip = false;
2208 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2209 debug_report_data *report_data = device_data->report_data;
2210 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
2211
2212 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2213 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
2214 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
2215 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
2216 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
2217
2218 if (pBeginInfo->pInheritanceInfo != NULL) {
2219 skip |=
2220 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
2221 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
2222
2223 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
2224 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
2225
2226 // TODO: This only needs to be validated when the inherited queries feature is enabled
2227 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2228 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
2229
2230 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
2231 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
2232 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
2233 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
2234 }
2235
2236 if (pInfo != NULL) {
2237 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2238 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2239 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
2240 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
2241 "inheritedQueries. %s",
2242 validation_error_map[VALIDATION_ERROR_02a00070]);
2243 }
2244 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2245 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2246 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
2247 VALIDATION_ERROR_02a00072);
2248 }
2249 }
2250
2251 return skip;
2252}
2253
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002254bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
2255 const VkViewport *pViewports) {
2256 bool skip = false;
2257 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2258
Petr Krausd55e77c2018-01-09 22:09:25 +01002259 if (!device_data->physical_device_features.multiViewport) {
2260 if (firstViewport != 0) {
2261 skip |=
2262 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2263 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000990, LayerName,
2264 "vkCmdSetViewport: The multiViewport feature is disabled, but firstViewport (=%" PRIu32 ") is not 0. %s",
Jeremy Kniager72437be2018-01-25 11:41:20 -07002265 firstViewport, validation_error_map[VALIDATION_ERROR_1e000990]);
Petr Krausd55e77c2018-01-09 22:09:25 +01002266 }
2267 if (viewportCount > 1) {
2268 skip |=
2269 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2270 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000992, LayerName,
2271 "vkCmdSetViewport: The multiViewport feature is disabled, but viewportCount (=%" PRIu32 ") is not 1. %s",
2272 viewportCount, validation_error_map[VALIDATION_ERROR_1e000992]);
2273 }
2274 } else { // multiViewport enabled
Petr Kraus7dfeed12018-02-27 20:51:20 +01002275 const uint64_t sum = static_cast<uint64_t>(firstViewport) + static_cast<uint64_t>(viewportCount);
Petr Krausd55e77c2018-01-09 22:09:25 +01002276 if (sum > device_data->device_limits.maxViewports) {
2277 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2278 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e00098e, LayerName,
2279 "vkCmdSetViewport: firstViewport + viewportCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2280 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2281 firstViewport, viewportCount, sum, device_data->device_limits.maxViewports,
2282 validation_error_map[VALIDATION_ERROR_1e00098e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002283 }
2284 }
Petr Krausb3fcdb42018-01-09 22:09:09 +01002285
2286 if (pViewports) {
2287 for (uint32_t viewport_i = 0; viewport_i < viewportCount; ++viewport_i) {
2288 const auto &viewport = pViewports[viewport_i]; // will crash on invalid ptr
2289 const char fn_name[] = "vkCmdSetViewport";
2290 const std::string param_name = "pViewports[" + std::to_string(viewport_i) + "]";
2291 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
2292 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer));
2293 }
2294 }
2295
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002296 return skip;
2297}
2298
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002299bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
2300 bool skip = false;
2301 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2302 debug_report_data *report_data = device_data->report_data;
2303
Petr Kraus6260f0a2018-02-27 21:15:55 +01002304 if (!device_data->physical_device_features.multiViewport) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002305 if (firstScissor != 0) {
Petr Kraus6260f0a2018-02-27 21:15:55 +01002306 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2307 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a2, LayerName,
2308 "vkCmdSetScissor: The multiViewport feature is disabled, but firstScissor (=%" PRIu32 ") is not 0. %s",
2309 firstScissor, validation_error_map[VALIDATION_ERROR_1d8004a2]);
2310 }
2311 if (scissorCount > 1) {
2312 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2313 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a4, LayerName,
2314 "vkCmdSetScissor: The multiViewport feature is disabled, but scissorCount (=%" PRIu32 ") is not 1. %s",
2315 scissorCount, validation_error_map[VALIDATION_ERROR_1d8004a4]);
2316 }
2317 } else { // multiViewport enabled
2318 const uint64_t sum = static_cast<uint64_t>(firstScissor) + static_cast<uint64_t>(scissorCount);
2319 if (sum > device_data->device_limits.maxViewports) {
2320 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2321 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a0, LayerName,
2322 "vkCmdSetScissor: firstScissor + scissorCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2323 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2324 firstScissor, scissorCount, sum, device_data->device_limits.maxViewports,
2325 validation_error_map[VALIDATION_ERROR_1d8004a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002326 }
2327 }
2328
Petr Kraus6260f0a2018-02-27 21:15:55 +01002329 if (pScissors) {
2330 for (uint32_t scissor_i = 0; scissor_i < scissorCount; ++scissor_i) {
2331 const auto &scissor = pScissors[scissor_i]; // will crash on invalid ptr
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002332
Petr Kraus6260f0a2018-02-27 21:15:55 +01002333 if (scissor.offset.x < 0) {
2334 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2335 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2336 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.x (=%" PRIi32 ") is negative. %s", scissor_i,
2337 scissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2338 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002339
Petr Kraus6260f0a2018-02-27 21:15:55 +01002340 if (scissor.offset.y < 0) {
2341 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2342 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2343 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.y (=%" PRIi32 ") is negative. %s", scissor_i,
2344 scissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2345 }
2346
2347 const int64_t x_sum = static_cast<int64_t>(scissor.offset.x) + static_cast<int64_t>(scissor.extent.width);
2348 if (x_sum > INT32_MAX) {
2349 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2350 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a8, LayerName,
2351 "vkCmdSetScissor: offset.x + extent.width (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2352 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2353 scissor.offset.x, scissor.extent.width, x_sum, scissor_i,
2354 validation_error_map[VALIDATION_ERROR_1d8004a8]);
2355 }
2356
2357 const int64_t y_sum = static_cast<int64_t>(scissor.offset.y) + static_cast<int64_t>(scissor.extent.height);
2358 if (y_sum > INT32_MAX) {
2359 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2360 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004aa, LayerName,
2361 "vkCmdSetScissor: offset.y + extent.height (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2362 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2363 scissor.offset.y, scissor.extent.height, y_sum, scissor_i,
2364 validation_error_map[VALIDATION_ERROR_1d8004aa]);
2365 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002366 }
2367 }
Petr Kraus6260f0a2018-02-27 21:15:55 +01002368
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002369 return skip;
2370}
2371
Petr Kraus299ba622017-11-24 03:09:03 +01002372bool pv_vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
2373 bool skip = false;
2374 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2375 debug_report_data *report_data = device_data->report_data;
2376
2377 if (!device_data->physical_device_features.wideLines && (lineWidth != 1.0f)) {
2378 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2379 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d600628, LayerName,
2380 "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0. %s", lineWidth,
2381 validation_error_map[VALIDATION_ERROR_1d600628]);
2382 }
2383
2384 return skip;
2385}
2386
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002387bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2388 uint32_t firstInstance) {
2389 bool skip = false;
2390 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2391 if (vertexCount == 0) {
2392 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
2393 // this an error or leave as is.
2394 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2395 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
2396 }
2397
2398 if (instanceCount == 0) {
2399 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2400 // this an error or leave as is.
2401 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2402 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2403 }
2404 return skip;
2405}
2406
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002407bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2408 bool skip = false;
2409 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2410
2411 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2412 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2413 __LINE__, DEVICE_FEATURE, LayerName,
2414 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2415 }
2416 return skip;
2417}
2418
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002419bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2420 uint32_t stride) {
2421 bool skip = false;
2422 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2423 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2424 skip |=
2425 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2426 DEVICE_FEATURE, LayerName,
2427 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2428 }
2429 return skip;
2430}
2431
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002432bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2433 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2434 bool skip = false;
2435 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2436
Dave Houltonf5217612018-02-02 16:18:52 -07002437 VkImageAspectFlags legal_aspect_flags =
2438 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2439 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2440 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2441 }
2442
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002443 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002444 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002445 skip |= log_msg(
2446 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2447 VALIDATION_ERROR_0a600c01, LayerName,
2448 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2449 validation_error_map[VALIDATION_ERROR_0a600c01]);
2450 }
Dave Houltonf5217612018-02-02 16:18:52 -07002451 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002452 skip |= log_msg(
2453 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2454 VALIDATION_ERROR_0a600c01, LayerName,
2455 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2456 validation_error_map[VALIDATION_ERROR_0a600c01]);
2457 }
2458 }
2459 return skip;
2460}
2461
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002462bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2463 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2464 bool skip = false;
2465 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2466
Dave Houltonf5217612018-02-02 16:18:52 -07002467 VkImageAspectFlags legal_aspect_flags =
2468 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2469 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2470 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2471 }
2472
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002473 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002474 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002475 skip |= log_msg(
2476 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2477 UNRECOGNIZED_VALUE, LayerName,
2478 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2479 }
Dave Houltonf5217612018-02-02 16:18:52 -07002480 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002481 skip |= log_msg(
2482 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2483 UNRECOGNIZED_VALUE, LayerName,
2484 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2485 }
2486 }
2487 return skip;
2488}
2489
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002490bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2491 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2492 bool skip = false;
2493 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2494
Dave Houltonf5217612018-02-02 16:18:52 -07002495 VkImageAspectFlags legal_aspect_flags =
2496 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2497 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2498 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2499 }
2500
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002501 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002502 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002503 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2504 __LINE__, UNRECOGNIZED_VALUE, LayerName,
2505 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an "
2506 "unrecognized enumerator");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002507 }
2508 }
2509 return skip;
2510}
2511
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002512bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2513 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2514 bool skip = false;
2515 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2516
Dave Houltonf5217612018-02-02 16:18:52 -07002517 VkImageAspectFlags legal_aspect_flags =
2518 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2519 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2520 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2521 }
2522
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002523 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002524 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002525 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2526 UNRECOGNIZED_VALUE, LayerName,
2527 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2528 "enumerator");
2529 }
2530 }
2531 return skip;
2532}
2533
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002534bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2535 const void *pData) {
2536 bool skip = false;
2537 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2538
2539 if (dstOffset & 3) {
2540 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2541 __LINE__, VALIDATION_ERROR_1e400048, LayerName,
2542 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2543 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2544 }
2545
2546 if ((dataSize <= 0) || (dataSize > 65536)) {
2547 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2548 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2549 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2550 "), must be greater than zero and less than or equal to 65536. %s",
2551 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2552 } else if (dataSize & 3) {
2553 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2554 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2555 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2556 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2557 }
2558 return skip;
2559}
2560
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002561bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2562 uint32_t data) {
2563 bool skip = false;
2564 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2565
2566 if (dstOffset & 3) {
2567 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2568 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2569 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2570 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2571 }
2572
2573 if (size != VK_WHOLE_SIZE) {
2574 if (size <= 0) {
2575 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2576 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2577 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2578 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2579 } else if (size & 3) {
2580 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2581 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2582 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2583 validation_error_map[VALIDATION_ERROR_1b400038]);
2584 }
2585 }
2586 return skip;
2587}
2588
2589VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2590 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2591}
2592
2593VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2594 VkLayerProperties *pProperties) {
2595 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2596}
2597
2598VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2599 VkExtensionProperties *pProperties) {
2600 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2601 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2602
2603 return VK_ERROR_LAYER_NOT_PRESENT;
2604}
2605
2606VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2607 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2608 // Parameter_validation does not have any physical device extensions
2609 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2610 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2611
2612 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2613 bool skip =
2614 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2615 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2616 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2617
2618 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2619}
2620
2621static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2622 if (!flag) {
2623 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2624 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2625 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2626 extension_name);
2627 }
2628
2629 return false;
2630}
2631
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002632bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2633 VkSwapchainKHR *pSwapchain) {
2634 bool skip = false;
2635 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2636 debug_report_data *report_data = device_data->report_data;
2637
Petr Krause5c37652018-01-05 04:05:12 +01002638 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, VK_NULL_HANDLE, LayerName,
2639 "vkCreateSwapchainKHR"};
2640
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002641 if (pCreateInfo != nullptr) {
2642 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2643 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002644 skip |=
2645 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2646 DEVICE_FEATURE, LayerName,
2647 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The textureCompressionETC2 "
2648 "feature is not enabled: neither ETC2 nor EAC formats can be used to create images.",
2649 string_VkFormat(pCreateInfo->imageFormat));
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002650 }
2651
2652 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2653 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2654 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2655 DEVICE_FEATURE, LayerName,
2656 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2657 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2658 string_VkFormat(pCreateInfo->imageFormat));
2659 }
2660
2661 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2662 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2663 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2664 DEVICE_FEATURE, LayerName,
2665 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2666 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2667 string_VkFormat(pCreateInfo->imageFormat));
2668 }
2669
2670 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2671 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2672 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2673 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2674 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2675 VALIDATION_ERROR_146009fc, LayerName,
2676 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2677 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2678 validation_error_map[VALIDATION_ERROR_146009fc]);
2679 }
2680
2681 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2682 // queueFamilyIndexCount uint32_t values
2683 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2684 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2685 VALIDATION_ERROR_146009fa, LayerName,
2686 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2687 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2688 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2689 validation_error_map[VALIDATION_ERROR_146009fa]);
2690 } else {
2691 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2692 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2693 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2694 INVALID_USAGE, false, "", "");
2695 }
2696 }
2697
Petr Krause5c37652018-01-05 04:05:12 +01002698 skip |= ValidateGreaterThanZero(pCreateInfo->imageArrayLayers, "pCreateInfo->imageArrayLayers", VALIDATION_ERROR_146009f6,
2699 log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002700 }
2701
2702 return skip;
2703}
2704
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002705bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2706 bool skip = false;
2707 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2708
2709 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002710 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2711 if (present_regions) {
2712 // TODO: This and all other pNext extension dependencies should be added to code-generation
2713 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2714 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2715 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2716 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2717 __LINE__, INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002718 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i but VkPresentRegionsKHR "
2719 "extension swapchainCount is %i. These values must be equal.",
John Zulaufde972ac2017-10-26 12:07:05 -06002720 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2721 }
2722 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2723 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2724 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2725 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2726 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2727 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2728 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002729 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2730 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2731 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002732 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002733 }
2734 }
2735
2736 return skip;
2737}
2738
2739#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002740bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2741 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2742 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2743 bool skip = false;
2744
2745 if (pCreateInfo->hwnd == nullptr) {
2746 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2747 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2748 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2749 validation_error_map[VALIDATION_ERROR_15a00a38]);
2750 }
2751
2752 return skip;
2753}
2754#endif // VK_USE_PLATFORM_WIN32_KHR
2755
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002756bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2757 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2758 if (pNameInfo->pObjectName) {
2759 device_data->report_data->debugObjectNameMap->insert(
2760 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2761 } else {
2762 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2763 }
2764 return false;
2765}
2766
Petr Krausc8655be2017-09-27 18:56:51 +02002767bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2768 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2769 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2770 bool skip = false;
2771
2772 if (pCreateInfo) {
2773 if (pCreateInfo->maxSets <= 0) {
2774 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2775 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2776 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2777 validation_error_map[VALIDATION_ERROR_0480025a]);
2778 }
2779
2780 if (pCreateInfo->pPoolSizes) {
2781 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2782 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2783 skip |= log_msg(
2784 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2785 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2786 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2787 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2788 }
2789 }
2790 }
2791 }
2792
2793 return skip;
2794}
2795
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002796bool pv_vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2797 bool skip = false;
2798 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2799
2800 if (groupCountX > device_data->device_limits.maxComputeWorkGroupCount[0]) {
2801 skip |= log_msg(
2802 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2803 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00304, LayerName,
2804 "vkCmdDispatch(): groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2805 groupCountX, device_data->device_limits.maxComputeWorkGroupCount[0], validation_error_map[VALIDATION_ERROR_19c00304]);
2806 }
2807
2808 if (groupCountY > device_data->device_limits.maxComputeWorkGroupCount[1]) {
2809 skip |= log_msg(
2810 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2811 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00306, LayerName,
2812 "vkCmdDispatch(): groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2813 groupCountY, device_data->device_limits.maxComputeWorkGroupCount[1], validation_error_map[VALIDATION_ERROR_19c00306]);
2814 }
2815
2816 if (groupCountZ > device_data->device_limits.maxComputeWorkGroupCount[2]) {
2817 skip |= log_msg(
2818 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2819 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00308, LayerName,
2820 "vkCmdDispatch(): groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2821 groupCountZ, device_data->device_limits.maxComputeWorkGroupCount[2], validation_error_map[VALIDATION_ERROR_19c00308]);
2822 }
2823
2824 return skip;
2825}
2826
2827bool pv_vkCmdDispatchBaseKHX(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
2828 uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2829 bool skip = false;
2830 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2831
2832 // Paired if {} else if {} tests used to avoid any possible uint underflow
2833 uint32_t limit = device_data->device_limits.maxComputeWorkGroupCount[0];
2834 if (baseGroupX >= limit) {
2835 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2836 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034a, LayerName,
2837 "vkCmdDispatch(): baseGroupX (%" PRIu32
2838 ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2839 baseGroupX, limit, validation_error_map[VALIDATION_ERROR_19e0034a]);
2840 } else if (groupCountX > (limit - baseGroupX)) {
2841 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2842 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00350, LayerName,
2843 "vkCmdDispatchBaseKHX(): baseGroupX (%" PRIu32 ") + groupCountX (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002844 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002845 baseGroupX, groupCountX, limit, validation_error_map[VALIDATION_ERROR_19e00350]);
2846 }
2847
2848 limit = device_data->device_limits.maxComputeWorkGroupCount[1];
2849 if (baseGroupY >= limit) {
2850 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2851 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034c, LayerName,
2852 "vkCmdDispatch(): baseGroupY (%" PRIu32
2853 ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2854 baseGroupY, limit, validation_error_map[VALIDATION_ERROR_19e0034c]);
2855 } else if (groupCountY > (limit - baseGroupY)) {
2856 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2857 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00352, LayerName,
2858 "vkCmdDispatchBaseKHX(): baseGroupY (%" PRIu32 ") + groupCountY (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002859 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002860 baseGroupY, groupCountY, limit, validation_error_map[VALIDATION_ERROR_19e00352]);
2861 }
2862
2863 limit = device_data->device_limits.maxComputeWorkGroupCount[2];
2864 if (baseGroupZ >= limit) {
2865 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2866 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034e, LayerName,
2867 "vkCmdDispatch(): baseGroupZ (%" PRIu32
2868 ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2869 baseGroupZ, limit, validation_error_map[VALIDATION_ERROR_19e0034e]);
2870 } else if (groupCountZ > (limit - baseGroupZ)) {
2871 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2872 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00354, LayerName,
2873 "vkCmdDispatchBaseKHX(): baseGroupZ (%" PRIu32 ") + groupCountZ (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002874 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002875 baseGroupZ, groupCountZ, limit, validation_error_map[VALIDATION_ERROR_19e00354]);
2876 }
2877
2878 return skip;
2879}
2880
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002881VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2882 const auto item = name_to_funcptr_map.find(funcName);
2883 if (item != name_to_funcptr_map.end()) {
2884 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2885 }
2886
2887 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2888 const auto &table = device_data->dispatch_table;
2889 if (!table.GetDeviceProcAddr) return nullptr;
2890 return table.GetDeviceProcAddr(device, funcName);
2891}
2892
2893VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2894 const auto item = name_to_funcptr_map.find(funcName);
2895 if (item != name_to_funcptr_map.end()) {
2896 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2897 }
2898
2899 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2900 auto &table = instance_data->dispatch_table;
2901 if (!table.GetInstanceProcAddr) return nullptr;
2902 return table.GetInstanceProcAddr(instance, funcName);
2903}
2904
2905VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2906 assert(instance);
2907 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2908
2909 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2910 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2911}
2912
2913// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2914// and the address filled in here. The autogenerated source will call these routines if the pointers are not NULL.
Petr Krausc8655be2017-09-27 18:56:51 +02002915void InitializeManualParameterValidationFunctionPointers() {
Dave Houltonb3bbec72018-01-17 10:13:33 -07002916 custom_functions["vkGetDeviceQueue"] = (void *)pv_vkGetDeviceQueue;
2917 custom_functions["vkCreateBuffer"] = (void *)pv_vkCreateBuffer;
2918 custom_functions["vkCreateImage"] = (void *)pv_vkCreateImage;
2919 custom_functions["vkCreateImageView"] = (void *)pv_vkCreateImageView;
2920 custom_functions["vkCreateGraphicsPipelines"] = (void *)pv_vkCreateGraphicsPipelines;
2921 custom_functions["vkCreateComputePipelines"] = (void *)pv_vkCreateComputePipelines;
2922 custom_functions["vkCreateSampler"] = (void *)pv_vkCreateSampler;
2923 custom_functions["vkCreateDescriptorSetLayout"] = (void *)pv_vkCreateDescriptorSetLayout;
2924 custom_functions["vkFreeDescriptorSets"] = (void *)pv_vkFreeDescriptorSets;
2925 custom_functions["vkUpdateDescriptorSets"] = (void *)pv_vkUpdateDescriptorSets;
2926 custom_functions["vkCreateRenderPass"] = (void *)pv_vkCreateRenderPass;
2927 custom_functions["vkBeginCommandBuffer"] = (void *)pv_vkBeginCommandBuffer;
2928 custom_functions["vkCmdSetViewport"] = (void *)pv_vkCmdSetViewport;
2929 custom_functions["vkCmdSetScissor"] = (void *)pv_vkCmdSetScissor;
Petr Kraus299ba622017-11-24 03:09:03 +01002930 custom_functions["vkCmdSetLineWidth"] = (void *)pv_vkCmdSetLineWidth;
Dave Houltonb3bbec72018-01-17 10:13:33 -07002931 custom_functions["vkCmdDraw"] = (void *)pv_vkCmdDraw;
2932 custom_functions["vkCmdDrawIndirect"] = (void *)pv_vkCmdDrawIndirect;
2933 custom_functions["vkCmdDrawIndexedIndirect"] = (void *)pv_vkCmdDrawIndexedIndirect;
2934 custom_functions["vkCmdCopyImage"] = (void *)pv_vkCmdCopyImage;
2935 custom_functions["vkCmdBlitImage"] = (void *)pv_vkCmdBlitImage;
2936 custom_functions["vkCmdCopyBufferToImage"] = (void *)pv_vkCmdCopyBufferToImage;
2937 custom_functions["vkCmdCopyImageToBuffer"] = (void *)pv_vkCmdCopyImageToBuffer;
2938 custom_functions["vkCmdUpdateBuffer"] = (void *)pv_vkCmdUpdateBuffer;
2939 custom_functions["vkCmdFillBuffer"] = (void *)pv_vkCmdFillBuffer;
2940 custom_functions["vkCreateSwapchainKHR"] = (void *)pv_vkCreateSwapchainKHR;
2941 custom_functions["vkQueuePresentKHR"] = (void *)pv_vkQueuePresentKHR;
2942 custom_functions["vkCreateDescriptorPool"] = (void *)pv_vkCreateDescriptorPool;
2943 custom_functions["vkCmdDispatch"] = (void *)pv_vkCmdDispatch;
2944 custom_functions["vkCmdDispatchBaseKHX"] = (void *)pv_vkCmdDispatchBaseKHX;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002945}
2946
2947} // namespace parameter_validation
2948
2949VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2950 VkExtensionProperties *pProperties) {
2951 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
2952}
2953
2954VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
2955 VkLayerProperties *pProperties) {
2956 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
2957}
2958
2959VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2960 VkLayerProperties *pProperties) {
2961 // the layer command handles VK_NULL_HANDLE just fine internally
2962 assert(physicalDevice == VK_NULL_HANDLE);
2963 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
2964}
2965
2966VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
2967 const char *pLayerName, uint32_t *pCount,
2968 VkExtensionProperties *pProperties) {
2969 // the layer command handles VK_NULL_HANDLE just fine internally
2970 assert(physicalDevice == VK_NULL_HANDLE);
2971 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
2972}
2973
2974VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
2975 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
2976}
2977
2978VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2979 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
2980}
2981
2982VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
2983 const char *funcName) {
2984 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
2985}
2986
2987VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
2988 assert(pVersionStruct != NULL);
2989 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
2990
2991 // Fill in the function pointers if our version is at least capable of having the structure contain them.
2992 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
2993 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
2994 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
2995 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
2996 }
2997
2998 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2999 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
3000 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
3001 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
3002 }
3003
3004 return VK_SUCCESS;
3005}