blob: 79fb5b5945f034bdbb7932dadd00a04f8938ba64 [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);
Mark Young6ba8abe2017-11-09 10:37:04 -070082extern bool parameter_validation_vkCreateDebugUtilsMessengerEXT(VkInstance instance,
83 const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
84 const VkAllocationCallbacks *pAllocator,
85 VkDebugUtilsMessengerEXT *pMessenger);
86extern bool parameter_validation_vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
87 const VkAllocationCallbacks *pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -060088extern bool parameter_validation_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
89 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool);
Petr Krause91f7a12017-12-14 20:57:36 +010090extern bool parameter_validation_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
91 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
92extern bool parameter_validation_vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
93 const VkAllocationCallbacks *pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -060094
95// TODO : This can be much smarter, using separate locks for separate global data
96std::mutex global_lock;
97
98static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
99std::unordered_map<void *, layer_data *> layer_data_map;
100std::unordered_map<void *, instance_layer_data *> instance_layer_data_map;
101
102void InitializeManualParameterValidationFunctionPointers(void);
103
104static void init_parameter_validation(instance_layer_data *instance_data, const VkAllocationCallbacks *pAllocator) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700105 layer_debug_report_actions(instance_data->report_data, instance_data->logging_callback, pAllocator,
106 "lunarg_parameter_validation");
107 layer_debug_messenger_actions(instance_data->report_data, instance_data->logging_messenger, pAllocator,
108 "lunarg_parameter_validation");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600109}
110
Mark Young6ba8abe2017-11-09 10:37:04 -0700111static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION},
112 {VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_SPEC_VERSION}};
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600113
114static const VkLayerProperties global_layer = {
Dave Houltonb3bbec72018-01-17 10:13:33 -0700115 "VK_LAYER_LUNARG_parameter_validation",
116 VK_LAYER_API_VERSION,
117 1,
118 "LunarG Validation Layer",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600119};
120
121static const int MaxParamCheckerStringLength = 256;
122
John Zulauf71968502017-10-26 13:51:15 -0600123template <typename T>
124static inline bool in_inclusive_range(const T &value, const T &min, const T &max) {
125 // Using only < for generality and || for early abort
126 return !((value < min) || (max < value));
127}
128
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600129static bool validate_string(debug_report_data *report_data, const char *apiName, const ParameterName &stringName,
130 const char *validateString) {
131 assert(apiName != nullptr);
132 assert(validateString != nullptr);
133
134 bool skip = false;
135
136 VkStringErrorFlags result = vk_string_validate(MaxParamCheckerStringLength, validateString);
137
138 if (result == VK_STRING_ERROR_NONE) {
139 return skip;
140 } else if (result & VK_STRING_ERROR_LENGTH) {
141 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
142 INVALID_USAGE, LayerName, "%s: string %s exceeds max length %d", apiName, stringName.get_name().c_str(),
143 MaxParamCheckerStringLength);
144 } else if (result & VK_STRING_ERROR_BAD_DATA) {
145 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
146 INVALID_USAGE, LayerName, "%s: string %s contains invalid characters or is badly formed", apiName,
147 stringName.get_name().c_str());
148 }
149 return skip;
150}
151
152static bool ValidateDeviceQueueFamily(layer_data *device_data, uint32_t queue_family, const char *cmd_name,
153 const char *parameter_name, int32_t error_code, bool optional = false,
154 const char *vu_note = nullptr) {
155 bool skip = false;
156
157 if (!vu_note) vu_note = validation_error_map[error_code];
158 if (!optional && queue_family == VK_QUEUE_FAMILY_IGNORED) {
159 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
160 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
161 "%s: %s is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family index value. %s",
162 cmd_name, parameter_name, vu_note);
163 } else if (device_data->queueFamilyIndexMap.find(queue_family) == device_data->queueFamilyIndexMap.end()) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700164 skip |= log_msg(
165 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
166 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
167 "%s: %s (= %" PRIu32
168 ") is not one of the queue families given via VkDeviceQueueCreateInfo structures when the device was created. %s",
169 cmd_name, parameter_name, queue_family, vu_note);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600170 }
171
172 return skip;
173}
174
175static bool ValidateQueueFamilies(layer_data *device_data, uint32_t queue_family_count, const uint32_t *queue_families,
176 const char *cmd_name, const char *array_parameter_name, int32_t unique_error_code,
177 int32_t valid_error_code, bool optional = false, const char *unique_vu_note = nullptr,
178 const char *valid_vu_note = nullptr) {
179 bool skip = false;
180 if (!unique_vu_note) unique_vu_note = validation_error_map[unique_error_code];
181 if (!valid_vu_note) valid_vu_note = validation_error_map[valid_error_code];
182 if (queue_families) {
183 std::unordered_set<uint32_t> set;
184 for (uint32_t i = 0; i < queue_family_count; ++i) {
185 std::string parameter_name = std::string(array_parameter_name) + "[" + std::to_string(i) + "]";
186
187 if (set.count(queue_families[i])) {
188 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
189 HandleToUint64(device_data->device), __LINE__, VALIDATION_ERROR_056002e8, LayerName,
190 "%s: %s (=%" PRIu32 ") is not unique within %s array. %s", cmd_name, parameter_name.c_str(),
191 queue_families[i], array_parameter_name, unique_vu_note);
192 } else {
193 set.insert(queue_families[i]);
194 skip |= ValidateDeviceQueueFamily(device_data, queue_families[i], cmd_name, parameter_name.c_str(),
195 valid_error_code, optional, valid_vu_note);
196 }
197 }
198 }
199 return skip;
200}
201
202VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600203 VkInstance *pInstance) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600204 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
205
206 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
207 assert(chain_info != nullptr);
208 assert(chain_info->u.pLayerInfo != nullptr);
209
210 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
211 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
212 if (fpCreateInstance == NULL) {
213 return VK_ERROR_INITIALIZATION_FAILED;
214 }
215
216 // Advance the link info for the next element on the chain
217 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
218
219 result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
220
221 if (result == VK_SUCCESS) {
222 InitializeManualParameterValidationFunctionPointers();
223 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), instance_layer_data_map);
224 assert(my_instance_data != nullptr);
225
226 layer_init_instance_dispatch_table(*pInstance, &my_instance_data->dispatch_table, fpGetInstanceProcAddr);
227 my_instance_data->instance = *pInstance;
228 my_instance_data->report_data =
Mark Young6ba8abe2017-11-09 10:37:04 -0700229 debug_utils_create_instance(&my_instance_data->dispatch_table, *pInstance, pCreateInfo->enabledExtensionCount,
230 pCreateInfo->ppEnabledExtensionNames);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600231
232 // Look for one or more debug report create info structures
233 // and setup a callback(s) for each one found.
Mark Young6ba8abe2017-11-09 10:37:04 -0700234 if (!layer_copy_tmp_debug_messengers(pCreateInfo->pNext, &my_instance_data->num_tmp_debug_messengers,
235 &my_instance_data->tmp_messenger_create_infos,
236 &my_instance_data->tmp_debug_messengers)) {
237 if (my_instance_data->num_tmp_debug_messengers > 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600238 // Setup the temporary callback(s) here to catch early issues:
Mark Young6ba8abe2017-11-09 10:37:04 -0700239 if (layer_enable_tmp_debug_messengers(my_instance_data->report_data, my_instance_data->num_tmp_debug_messengers,
240 my_instance_data->tmp_messenger_create_infos,
241 my_instance_data->tmp_debug_messengers)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600242 // Failure of setting up one or more of the callback.
243 // Therefore, clean up and don't use those callbacks:
Mark Young6ba8abe2017-11-09 10:37:04 -0700244 layer_free_tmp_debug_messengers(my_instance_data->tmp_messenger_create_infos,
245 my_instance_data->tmp_debug_messengers);
246 my_instance_data->num_tmp_debug_messengers = 0;
247 }
248 }
249 }
250 if (!layer_copy_tmp_report_callbacks(pCreateInfo->pNext, &my_instance_data->num_tmp_report_callbacks,
251 &my_instance_data->tmp_report_create_infos, &my_instance_data->tmp_report_callbacks)) {
252 if (my_instance_data->num_tmp_report_callbacks > 0) {
253 // Setup the temporary callback(s) here to catch early issues:
254 if (layer_enable_tmp_report_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_report_callbacks,
255 my_instance_data->tmp_report_create_infos,
256 my_instance_data->tmp_report_callbacks)) {
257 // Failure of setting up one or more of the callback.
258 // Therefore, clean up and don't use those callbacks:
259 layer_free_tmp_report_callbacks(my_instance_data->tmp_report_create_infos,
260 my_instance_data->tmp_report_callbacks);
261 my_instance_data->num_tmp_report_callbacks = 0;
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600262 }
263 }
264 }
265
266 init_parameter_validation(my_instance_data, pAllocator);
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600267
268 uint32_t api_version = my_instance_data->extensions.InitFromInstanceCreateInfo(
269 (pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : VK_API_VERSION_1_0), pCreateInfo);
270
271 if (pCreateInfo->pApplicationInfo) {
272 uint32_t specified_api_version = pCreateInfo->pApplicationInfo->apiVersion & ~VK_VERSION_PATCH(~0);
273 if (!(specified_api_version == VK_API_VERSION_1_0) && !(specified_api_version == VK_API_VERSION_1_1)) {
274 LOGCONSOLE(
275 "Warning: Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number -- (0x%08x) assuming "
276 "%s.\n",
277 pCreateInfo->pApplicationInfo->apiVersion,
278 (api_version == VK_API_VERSION_1_0) ? "VK_API_VERSION_1_0" : "VK_API_VERSION_1_1");
279 }
280 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600281
282 // Ordinarily we'd check these before calling down the chain, but none of the layer support is in place until now, if we
283 // survive we can report the issue now.
284 parameter_validation_vkCreateInstance(*pInstance, pCreateInfo, pAllocator, pInstance);
285
286 if (pCreateInfo->pApplicationInfo) {
287 if (pCreateInfo->pApplicationInfo->pApplicationName) {
288 validate_string(my_instance_data->report_data, "vkCreateInstance",
289 "pCreateInfo->VkApplicationInfo->pApplicationName",
290 pCreateInfo->pApplicationInfo->pApplicationName);
291 }
292
293 if (pCreateInfo->pApplicationInfo->pEngineName) {
294 validate_string(my_instance_data->report_data, "vkCreateInstance", "pCreateInfo->VkApplicationInfo->pEngineName",
295 pCreateInfo->pApplicationInfo->pEngineName);
296 }
297 }
298
299 // Disable the tmp callbacks:
Mark Young6ba8abe2017-11-09 10:37:04 -0700300 if (my_instance_data->num_tmp_debug_messengers > 0) {
301 layer_disable_tmp_debug_messengers(my_instance_data->report_data, my_instance_data->num_tmp_debug_messengers,
302 my_instance_data->tmp_debug_messengers);
303 }
304 if (my_instance_data->num_tmp_report_callbacks > 0) {
305 layer_disable_tmp_report_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_report_callbacks,
306 my_instance_data->tmp_report_callbacks);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600307 }
308 }
309
310 return result;
311}
312
313VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
314 // Grab the key before the instance is destroyed.
315 dispatch_key key = get_dispatch_key(instance);
316 bool skip = false;
317 auto instance_data = GetLayerDataPtr(key, instance_layer_data_map);
318
319 // Enable the temporary callback(s) here to catch vkDestroyInstance issues:
320 bool callback_setup = false;
Mark Young6ba8abe2017-11-09 10:37:04 -0700321 if (instance_data->num_tmp_debug_messengers > 0) {
322 if (!layer_enable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers,
323 instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers)) {
324 callback_setup = true;
325 }
326 }
327 if (instance_data->num_tmp_report_callbacks > 0) {
328 if (!layer_enable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks,
329 instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600330 callback_setup = true;
331 }
332 }
333
334 skip |= parameter_validation_vkDestroyInstance(instance, pAllocator);
335
336 // Disable and cleanup the temporary callback(s):
337 if (callback_setup) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700338 layer_disable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers,
339 instance_data->tmp_debug_messengers);
340 layer_disable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks,
341 instance_data->tmp_report_callbacks);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600342 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700343 if (instance_data->num_tmp_debug_messengers > 0) {
344 layer_free_tmp_debug_messengers(instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers);
345 instance_data->num_tmp_debug_messengers = 0;
346 }
347 if (instance_data->num_tmp_report_callbacks > 0) {
348 layer_free_tmp_report_callbacks(instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks);
349 instance_data->num_tmp_report_callbacks = 0;
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600350 }
351
352 if (!skip) {
353 instance_data->dispatch_table.DestroyInstance(instance, pAllocator);
354
355 // Clean up logging callback, if any
Mark Young6ba8abe2017-11-09 10:37:04 -0700356 while (instance_data->logging_messenger.size() > 0) {
357 VkDebugUtilsMessengerEXT messenger = instance_data->logging_messenger.back();
358 layer_destroy_messenger_callback(instance_data->report_data, messenger, pAllocator);
359 instance_data->logging_messenger.pop_back();
360 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600361 while (instance_data->logging_callback.size() > 0) {
362 VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
Mark Young6ba8abe2017-11-09 10:37:04 -0700363 layer_destroy_report_callback(instance_data->report_data, callback, pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600364 instance_data->logging_callback.pop_back();
365 }
366
Mark Young6ba8abe2017-11-09 10:37:04 -0700367 layer_debug_utils_destroy_instance(instance_data->report_data);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600368 }
369
370 FreeLayerDataPtr(key, instance_layer_data_map);
371}
372
373VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance,
374 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
375 const VkAllocationCallbacks *pAllocator,
376 VkDebugReportCallbackEXT *pMsgCallback) {
377 bool skip = parameter_validation_vkCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
378 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
379
380 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
381 VkResult result = instance_data->dispatch_table.CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
382 if (result == VK_SUCCESS) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700383 result = layer_create_report_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback);
384 // If something happened during this call, clean up the message callback that was created earlier in the lower levels
385 if (VK_SUCCESS != result) {
386 instance_data->dispatch_table.DestroyDebugReportCallbackEXT(instance, *pMsgCallback, pAllocator);
387 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600388 }
389 return result;
390}
391
392VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
393 const VkAllocationCallbacks *pAllocator) {
394 bool skip = parameter_validation_vkDestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
395 if (!skip) {
396 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
397 instance_data->dispatch_table.DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Mark Young6ba8abe2017-11-09 10:37:04 -0700398 layer_destroy_report_callback(instance_data->report_data, msgCallback, pAllocator);
399 }
400}
401
402VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance,
403 const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
404 const VkAllocationCallbacks *pAllocator,
405 VkDebugUtilsMessengerEXT *pMessenger) {
406 bool skip = parameter_validation_vkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
407 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
408
409 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
410 VkResult result = instance_data->dispatch_table.CreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
411 if (VK_SUCCESS == result) {
412 result = layer_create_messenger_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMessenger);
413 // If something happened during this call, clean up the message callback that was created earlier in the lower levels
414 if (VK_SUCCESS != result) {
415 instance_data->dispatch_table.DestroyDebugUtilsMessengerEXT(instance, *pMessenger, pAllocator);
416 }
417 }
418 return result;
419}
420
421VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
422 const VkAllocationCallbacks *pAllocator) {
423 bool skip = parameter_validation_vkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
424 if (!skip) {
425 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
426 instance_data->dispatch_table.DestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
427 layer_destroy_messenger_callback(instance_data->report_data, messenger, pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600428 }
429}
430
431static bool ValidateDeviceCreateInfo(instance_layer_data *instance_data, VkPhysicalDevice physicalDevice,
432 const VkDeviceCreateInfo *pCreateInfo) {
433 bool skip = false;
434
435 if ((pCreateInfo->enabledLayerCount > 0) && (pCreateInfo->ppEnabledLayerNames != NULL)) {
436 for (size_t i = 0; i < pCreateInfo->enabledLayerCount; i++) {
437 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledLayerNames",
438 pCreateInfo->ppEnabledLayerNames[i]);
439 }
440 }
441
442 bool maint1 = false;
443 bool negative_viewport = false;
444
445 if ((pCreateInfo->enabledExtensionCount > 0) && (pCreateInfo->ppEnabledExtensionNames != NULL)) {
446 for (size_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
447 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledExtensionNames",
448 pCreateInfo->ppEnabledExtensionNames[i]);
449 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) maint1 = true;
450 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME) == 0)
451 negative_viewport = true;
452 }
453 }
454
455 if (maint1 && negative_viewport) {
456 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
457 __LINE__, VALIDATION_ERROR_056002ec, LayerName,
458 "VkDeviceCreateInfo->ppEnabledExtensionNames must not simultaneously include VK_KHR_maintenance1 and "
459 "VK_AMD_negative_viewport_height. %s",
460 validation_error_map[VALIDATION_ERROR_056002ec]);
461 }
462
463 if (pCreateInfo->pNext != NULL && pCreateInfo->pEnabledFeatures) {
464 // Check for get_physical_device_properties2 struct
John Zulaufde972ac2017-10-26 12:07:05 -0600465 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
466 if (features2) {
467 // Cannot include VkPhysicalDeviceFeatures2KHR and have non-null pEnabledFeatures
468 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
469 __LINE__, INVALID_USAGE, LayerName,
470 "VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceFeatures2KHR struct when "
471 "pCreateInfo->pEnabledFeatures is non-NULL.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600472 }
473 }
474
475 // Validate pCreateInfo->pQueueCreateInfos
476 if (pCreateInfo->pQueueCreateInfos) {
477 std::unordered_set<uint32_t> set;
478
479 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
480 const uint32_t requested_queue_family = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
481 if (requested_queue_family == VK_QUEUE_FAMILY_IGNORED) {
482 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
483 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
484 VALIDATION_ERROR_06c002fa, LayerName,
485 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700486 "].queueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family "
487 "index value. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600488 i, validation_error_map[VALIDATION_ERROR_06c002fa]);
489 } else if (set.count(requested_queue_family)) {
490 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
491 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
492 VALIDATION_ERROR_056002e8, LayerName,
493 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].queueFamilyIndex (=%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700494 ") is not unique within pCreateInfo->pQueueCreateInfos array. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600495 i, requested_queue_family, validation_error_map[VALIDATION_ERROR_056002e8]);
496 } else {
497 set.insert(requested_queue_family);
498 }
499
500 if (pCreateInfo->pQueueCreateInfos[i].pQueuePriorities != nullptr) {
501 for (uint32_t j = 0; j < pCreateInfo->pQueueCreateInfos[i].queueCount; ++j) {
502 const float queue_priority = pCreateInfo->pQueueCreateInfos[i].pQueuePriorities[j];
503 if (!(queue_priority >= 0.f) || !(queue_priority <= 1.f)) {
504 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
505 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
506 VALIDATION_ERROR_06c002fe, LayerName,
507 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].pQueuePriorities[%" PRIu32
508 "] (=%f) is not between 0 and 1 (inclusive). %s",
509 i, j, queue_priority, validation_error_map[VALIDATION_ERROR_06c002fe]);
510 }
511 }
512 }
513 }
514 }
515
516 return skip;
517}
518
519VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
520 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
521 // NOTE: Don't validate physicalDevice or any dispatchable object as the first parameter. We couldn't get here if it was wrong!
522
523 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
524 bool skip = false;
525 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
526 assert(my_instance_data != nullptr);
527 std::unique_lock<std::mutex> lock(global_lock);
528
529 skip |= parameter_validation_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
530
531 if (pCreateInfo != NULL) skip |= ValidateDeviceCreateInfo(my_instance_data, physicalDevice, pCreateInfo);
532
533 if (!skip) {
534 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
535 assert(chain_info != nullptr);
536 assert(chain_info->u.pLayerInfo != nullptr);
537
538 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
539 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
540 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice");
541 if (fpCreateDevice == NULL) {
542 return VK_ERROR_INITIALIZATION_FAILED;
543 }
544
545 // Advance the link info for the next element on the chain
546 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
547
548 lock.unlock();
549
550 result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
551
552 lock.lock();
553
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600554 if (result == VK_SUCCESS) {
555 layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
556 assert(my_device_data != nullptr);
557
Mark Young6ba8abe2017-11-09 10:37:04 -0700558 my_device_data->report_data = layer_debug_utils_create_device(my_instance_data->report_data, *pDevice);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600559 layer_init_device_dispatch_table(*pDevice, &my_device_data->dispatch_table, fpGetDeviceProcAddr);
560
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600561 // Query and save physical device limits for this device
562 VkPhysicalDeviceProperties device_properties = {};
563 my_instance_data->dispatch_table.GetPhysicalDeviceProperties(physicalDevice, &device_properties);
564
565 my_device_data->api_version = my_device_data->extensions.InitFromDeviceCreateInfo(
566 &my_instance_data->extensions, device_properties.apiVersion, pCreateInfo);
567
568 uint32_t specified_api_version = device_properties.apiVersion & ~VK_VERSION_PATCH(~0);
569 if (!(specified_api_version == VK_API_VERSION_1_0) && !(specified_api_version == VK_API_VERSION_1_1)) {
570 LOGCONSOLE(
571 "Warning: Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number -- (0x%8x) assuming "
572 "%s.\n",
573 device_properties.apiVersion,
574 (my_device_data->api_version == VK_API_VERSION_1_0) ? "VK_API_VERSION_1_0" : "VK_API_VERSION_1_1");
575 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600576
577 // Store createdevice data
578 if ((pCreateInfo != nullptr) && (pCreateInfo->pQueueCreateInfos != nullptr)) {
579 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
580 my_device_data->queueFamilyIndexMap.insert(std::make_pair(pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex,
581 pCreateInfo->pQueueCreateInfos[i].queueCount));
582 }
583 }
584
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600585 memcpy(&my_device_data->device_limits, &device_properties.limits, sizeof(VkPhysicalDeviceLimits));
586 my_device_data->physical_device = physicalDevice;
587 my_device_data->device = *pDevice;
588
589 // Save app-enabled features in this device's layer_data structure
John Zulauf1bde5bb2017-10-18 18:21:23 -0600590 // The enabled features can come from either pEnabledFeatures, or from the pNext chain
591 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
592 if ((nullptr == enabled_features_found) && my_device_data->extensions.vk_khr_get_physical_device_properties_2) {
John Zulaufde972ac2017-10-26 12:07:05 -0600593 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
594 if (features2) {
595 enabled_features_found = &(features2->features);
John Zulauf1bde5bb2017-10-18 18:21:23 -0600596 }
597 }
598 if (enabled_features_found) {
Dave Houltonb3bbec72018-01-17 10:13:33 -0700599 my_device_data->physical_device_features = *enabled_features_found;
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600600 } else {
601 memset(&my_device_data->physical_device_features, 0, sizeof(VkPhysicalDeviceFeatures));
602 }
603 }
604 }
605
606 return result;
607}
608
609VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
610 dispatch_key key = get_dispatch_key(device);
611 bool skip = false;
612 layer_data *device_data = GetLayerDataPtr(key, layer_data_map);
613 {
614 std::unique_lock<std::mutex> lock(global_lock);
615 skip |= parameter_validation_vkDestroyDevice(device, pAllocator);
616 }
617
618 if (!skip) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700619 layer_debug_utils_destroy_device(device);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600620 device_data->dispatch_table.DestroyDevice(device, pAllocator);
621 }
622 FreeLayerDataPtr(key, layer_data_map);
623}
624
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600625bool pv_vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
626 bool skip = false;
627 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
628
629 skip |=
630 ValidateDeviceQueueFamily(device_data, queueFamilyIndex, "vkGetDeviceQueue", "queueFamilyIndex", VALIDATION_ERROR_29600300);
631 const auto &queue_data = device_data->queueFamilyIndexMap.find(queueFamilyIndex);
632 if (queue_data != device_data->queueFamilyIndexMap.end() && queue_data->second <= queueIndex) {
633 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
634 HandleToUint64(device), __LINE__, VALIDATION_ERROR_29600302, LayerName,
635 "vkGetDeviceQueue: queueIndex (=%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700636 ") is not less than the number of queues requested from queueFamilyIndex (=%" PRIu32
637 ") when the device was created (i.e. is not less than %" PRIu32 "). %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600638 queueIndex, queueFamilyIndex, queue_data->second, validation_error_map[VALIDATION_ERROR_29600302]);
639 }
640 return skip;
641}
642
643VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
644 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool) {
645 layer_data *local_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
646 bool skip = false;
647 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
648 std::unique_lock<std::mutex> lock(global_lock);
649
650 skip |= ValidateDeviceQueueFamily(local_data, pCreateInfo->queueFamilyIndex, "vkCreateCommandPool",
651 "pCreateInfo->queueFamilyIndex", VALIDATION_ERROR_02c0004e);
652
653 skip |= parameter_validation_vkCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
654
655 lock.unlock();
656 if (!skip) {
657 result = local_data->dispatch_table.CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
658 }
659 return result;
660}
661
662VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
663 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool) {
664 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
665 bool skip = false;
666 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
667
668 skip |= parameter_validation_vkCreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
669
670 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
671 if (pCreateInfo != nullptr) {
672 // If queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, pipelineStatistics must be a valid combination of
673 // VkQueryPipelineStatisticFlagBits values
674 if ((pCreateInfo->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS) && (pCreateInfo->pipelineStatistics != 0) &&
675 ((pCreateInfo->pipelineStatistics & (~AllVkQueryPipelineStatisticFlagBits)) != 0)) {
676 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
677 __LINE__, VALIDATION_ERROR_11c00630, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700678 "vkCreateQueryPool(): if pCreateInfo->queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, "
679 "pCreateInfo->pipelineStatistics must be a valid combination of VkQueryPipelineStatisticFlagBits "
680 "values. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600681 validation_error_map[VALIDATION_ERROR_11c00630]);
682 }
683 }
684 if (!skip) {
685 result = device_data->dispatch_table.CreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
686 }
687 return result;
688}
689
Petr Krause91f7a12017-12-14 20:57:36 +0100690VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
691 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass) {
692 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
693 bool skip = false;
694 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
695
696 {
697 std::unique_lock<std::mutex> lock(global_lock);
698 skip |= parameter_validation_vkCreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
699
Dave Houltonb3bbec72018-01-17 10:13:33 -0700700 typedef bool (*PFN_manual_vkCreateRenderPass)(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
701 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
Petr Krause91f7a12017-12-14 20:57:36 +0100702 PFN_manual_vkCreateRenderPass custom_func = (PFN_manual_vkCreateRenderPass)custom_functions["vkCreateRenderPass"];
703 if (custom_func != nullptr) {
704 skip |= custom_func(device, pCreateInfo, pAllocator, pRenderPass);
705 }
706 }
707
708 if (!skip) {
709 result = device_data->dispatch_table.CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
710
711 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
712 if (result == VK_SUCCESS) {
713 std::unique_lock<std::mutex> lock(global_lock);
714 const auto renderPass = *pRenderPass;
715 auto &renderpass_state = device_data->renderpasses_states[renderPass];
716
717 for (uint32_t subpass = 0; subpass < pCreateInfo->subpassCount; ++subpass) {
718 bool uses_color = false;
719 for (uint32_t i = 0; i < pCreateInfo->pSubpasses[subpass].colorAttachmentCount && !uses_color; ++i)
720 if (pCreateInfo->pSubpasses[subpass].pColorAttachments[i].attachment != VK_ATTACHMENT_UNUSED) uses_color = true;
721
722 bool uses_depthstencil = false;
723 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment)
724 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)
725 uses_depthstencil = true;
726
727 if (uses_color) renderpass_state.subpasses_using_color_attachment.insert(subpass);
728 if (uses_depthstencil) renderpass_state.subpasses_using_depthstencil_attachment.insert(subpass);
729 }
730 }
731 }
732 return result;
733}
734
735VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator) {
736 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
737 bool skip = false;
738
739 {
740 std::unique_lock<std::mutex> lock(global_lock);
741 skip |= parameter_validation_vkDestroyRenderPass(device, renderPass, pAllocator);
742
Dave Houltonb3bbec72018-01-17 10:13:33 -0700743 typedef bool (*PFN_manual_vkDestroyRenderPass)(VkDevice device, VkRenderPass renderPass,
744 const VkAllocationCallbacks *pAllocator);
Petr Krause91f7a12017-12-14 20:57:36 +0100745 PFN_manual_vkDestroyRenderPass custom_func = (PFN_manual_vkDestroyRenderPass)custom_functions["vkDestroyRenderPass"];
746 if (custom_func != nullptr) {
747 skip |= custom_func(device, renderPass, pAllocator);
748 }
749 }
750
751 if (!skip) {
752 device_data->dispatch_table.DestroyRenderPass(device, renderPass, pAllocator);
753
754 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
755 {
756 std::unique_lock<std::mutex> lock(global_lock);
757 device_data->renderpasses_states.erase(renderPass);
758 }
759 }
760}
761
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600762bool pv_vkCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
763 VkBuffer *pBuffer) {
764 bool skip = false;
765 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
766 debug_report_data *report_data = device_data->report_data;
767
Petr Krause5c37652018-01-05 04:05:12 +0100768 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, VK_NULL_HANDLE, LayerName, "vkCreateBuffer"};
769
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600770 if (pCreateInfo != nullptr) {
Petr Krause5c37652018-01-05 04:05:12 +0100771 skip |= ValidateGreaterThanZero(pCreateInfo->size, "pCreateInfo->size", VALIDATION_ERROR_01400720, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600772
773 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
774 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
775 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
776 if (pCreateInfo->queueFamilyIndexCount <= 1) {
777 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
778 VALIDATION_ERROR_01400724, LayerName,
779 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
780 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
781 validation_error_map[VALIDATION_ERROR_01400724]);
782 }
783
784 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
785 // queueFamilyIndexCount uint32_t values
786 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
787 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
788 VALIDATION_ERROR_01400722, LayerName,
789 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
790 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
791 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
792 validation_error_map[VALIDATION_ERROR_01400722]);
793 } else {
794 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
795 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
796 "vkCreateBuffer", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
797 false, "", "");
798 }
799 }
800
801 // If flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain
802 // VK_BUFFER_CREATE_SPARSE_BINDING_BIT
803 if (((pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
804 ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) != VK_BUFFER_CREATE_SPARSE_BINDING_BIT)) {
805 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
806 VALIDATION_ERROR_0140072c, LayerName,
807 "vkCreateBuffer: if pCreateInfo->flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or "
808 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_BUFFER_CREATE_SPARSE_BINDING_BIT. %s",
809 validation_error_map[VALIDATION_ERROR_0140072c]);
810 }
811 }
812
813 return skip;
814}
815
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600816bool pv_vkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
817 VkImage *pImage) {
818 bool skip = false;
819 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
820 debug_report_data *report_data = device_data->report_data;
821
Petr Krause5c37652018-01-05 04:05:12 +0100822 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, VK_NULL_HANDLE, LayerName, "vkCreateImage"};
823
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600824 if (pCreateInfo != nullptr) {
825 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
826 FormatIsCompressed_ETC2_EAC(pCreateInfo->format)) {
827 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
828 DEVICE_FEATURE, LayerName,
829 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionETC2 feature is "
830 "not enabled: neither ETC2 nor EAC formats can be used to create images.",
831 string_VkFormat(pCreateInfo->format));
832 }
833
834 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
835 FormatIsCompressed_ASTC_LDR(pCreateInfo->format)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700836 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
837 DEVICE_FEATURE, LayerName,
838 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionASTC_LDR feature "
839 "is not enabled: ASTC formats cannot be used to create images.",
840 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600841 }
842
843 if ((device_data->physical_device_features.textureCompressionBC == false) && FormatIsCompressed_BC(pCreateInfo->format)) {
844 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
845 DEVICE_FEATURE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700846 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionBC feature is not "
847 "enabled: BC compressed formats cannot be used to create images.",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600848 string_VkFormat(pCreateInfo->format));
849 }
850
851 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
852 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
853 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
854 if (pCreateInfo->queueFamilyIndexCount <= 1) {
855 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
856 VALIDATION_ERROR_09e0075c, LayerName,
857 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
858 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
859 validation_error_map[VALIDATION_ERROR_09e0075c]);
860 }
861
862 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
863 // queueFamilyIndexCount uint32_t values
864 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
865 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
866 VALIDATION_ERROR_09e0075a, LayerName,
867 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
868 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
869 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
870 validation_error_map[VALIDATION_ERROR_09e0075a]);
871 } else {
872 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
873 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
874 "vkCreateImage", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
875 false, "", "");
876 }
877 }
878
Petr Krause5c37652018-01-05 04:05:12 +0100879 skip |=
880 ValidateGreaterThanZero(pCreateInfo->extent.width, "pCreateInfo->extent.width", VALIDATION_ERROR_09e00760, log_misc);
881 skip |=
882 ValidateGreaterThanZero(pCreateInfo->extent.height, "pCreateInfo->extent.height", VALIDATION_ERROR_09e00762, log_misc);
883 skip |=
884 ValidateGreaterThanZero(pCreateInfo->extent.depth, "pCreateInfo->extent.depth", VALIDATION_ERROR_09e00764, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600885
Petr Krause5c37652018-01-05 04:05:12 +0100886 skip |= ValidateGreaterThanZero(pCreateInfo->mipLevels, "pCreateInfo->mipLevels", VALIDATION_ERROR_09e00766, log_misc);
887 skip |= ValidateGreaterThanZero(pCreateInfo->arrayLayers, "pCreateInfo->arrayLayers", VALIDATION_ERROR_09e00768, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600888
Dave Houlton130c0212018-01-29 13:39:56 -0700889 // InitialLayout must be PREINITIALIZED or UNDEFINED
Dave Houltone19e20d2018-02-02 16:32:41 -0700890 if ((pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED) &&
891 (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED)) {
892 skip |= log_msg(
893 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dave Houlton130c0212018-01-29 13:39:56 -0700894 VALIDATION_ERROR_09e007c2, LayerName,
895 "vkCreateImage(): initialLayout is %s, must be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
896 string_VkImageLayout(pCreateInfo->initialLayout), validation_error_map[VALIDATION_ERROR_09e007c2]);
897 }
898
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600899 // If imageType is VK_IMAGE_TYPE_1D, both extent.height and extent.depth must be 1
900 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) && (pCreateInfo->extent.height != 1) && (pCreateInfo->extent.depth != 1)) {
901 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 -0700902 VALIDATION_ERROR_09e00778, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700903 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_1D, both pCreateInfo->extent.height and "
904 "pCreateInfo->extent.depth must be 1. %s",
Dave Houltone19e20d2018-02-02 16:32:41 -0700905 validation_error_map[VALIDATION_ERROR_09e00778]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600906 }
907
908 if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D) {
909 // If imageType is VK_IMAGE_TYPE_2D and flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, extent.width and
910 // extent.height must be equal
911 if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
912 (pCreateInfo->extent.width != pCreateInfo->extent.height)) {
913 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
914 VALIDATION_ERROR_09e00774, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700915 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D and pCreateInfo->flags contains "
916 "VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, pCreateInfo->extent.width and pCreateInfo->extent.height "
917 "must be equal. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600918 validation_error_map[VALIDATION_ERROR_09e00774]);
919 }
920
921 if (pCreateInfo->extent.depth != 1) {
922 skip |= log_msg(
923 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
924 VALIDATION_ERROR_09e0077a, LayerName,
925 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1. %s",
926 validation_error_map[VALIDATION_ERROR_09e0077a]);
927 }
928 }
929
Dave Houlton130c0212018-01-29 13:39:56 -0700930 // 3D image may have only 1 layer
931 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_3D) && (pCreateInfo->arrayLayers != 1)) {
932 skip |=
933 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
934 VALIDATION_ERROR_09e00782, LayerName,
935 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_3D, pCreateInfo->arrayLayers must be 1. %s",
936 validation_error_map[VALIDATION_ERROR_09e00782]);
937 }
938
939 // If multi-sample, validate type, usage, tiling and mip levels.
940 if ((pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) &&
941 ((pCreateInfo->imageType != VK_IMAGE_TYPE_2D) || (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) ||
942 (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) || (pCreateInfo->mipLevels != 1))) {
943 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
944 VALIDATION_ERROR_09e00784, LayerName,
945 "vkCreateImage(): Multi-sample image with incompatible type, usage, tiling, or mips. %s",
946 validation_error_map[VALIDATION_ERROR_09e00784]);
947 }
948
949 if (0 != (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
950 VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
951 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
952 // At least one of the legal attachment bits must be set
953 if (0 == (pCreateInfo->usage & legal_flags)) {
954 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
955 VALIDATION_ERROR_09e0078c, LayerName,
956 "vkCreateImage(): Transient attachment image without a compatible attachment flag set. %s",
957 validation_error_map[VALIDATION_ERROR_09e0078c]);
958 }
959 // No flags other than the legal attachment bits may be set
960 legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
961 if (0 != (pCreateInfo->usage & ~legal_flags)) {
962 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
963 VALIDATION_ERROR_09e00786, LayerName,
964 "vkCreateImage(): Transient attachment image with incompatible usage flags set. %s",
965 validation_error_map[VALIDATION_ERROR_09e00786]);
966 }
967 }
968
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600969 // mipLevels must be less than or equal to floor(log2(max(extent.width,extent.height,extent.depth)))+1
970 uint32_t maxDim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
Petr Krause5c37652018-01-05 04:05:12 +0100971 if (maxDim > 0 && pCreateInfo->mipLevels > (floor(log2(maxDim)) + 1)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600972 skip |=
973 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
974 VALIDATION_ERROR_09e0077c, LayerName,
975 "vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
976 "floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1. %s",
977 validation_error_map[VALIDATION_ERROR_09e0077c]);
978 }
979
980 // If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
981 // VK_IMAGE_CREATE_SPARSE_BINDING_BIT
982 if (((pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
983 ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
984 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
985 VALIDATION_ERROR_09e007b6, LayerName,
986 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
987 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT. %s",
988 validation_error_map[VALIDATION_ERROR_09e007b6]);
989 }
990
991 // Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
992 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
993 // Linear tiling is unsupported
994 if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
995 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
996 INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700997 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image "
998 "tiling of VK_IMAGE_TILING_LINEAR is not supported");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600999 }
1000
1001 // Sparse 1D image isn't valid
1002 if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
1003 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1004 VALIDATION_ERROR_09e00794, LayerName,
1005 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image. %s",
1006 validation_error_map[VALIDATION_ERROR_09e00794]);
1007 }
1008
1009 // Sparse 2D image when device doesn't support it
1010 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage2D) &&
1011 (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
1012 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1013 VALIDATION_ERROR_09e00796, LayerName,
1014 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
1015 "feature is not enabled on the device. %s",
1016 validation_error_map[VALIDATION_ERROR_09e00796]);
1017 }
1018
1019 // Sparse 3D image when device doesn't support it
1020 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage3D) &&
1021 (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
1022 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1023 VALIDATION_ERROR_09e00798, LayerName,
1024 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
1025 "feature is not enabled on the device. %s",
1026 validation_error_map[VALIDATION_ERROR_09e00798]);
1027 }
1028
1029 // Multi-sample 2D image when device doesn't support it
1030 if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
1031 if ((VK_FALSE == device_data->physical_device_features.sparseResidency2Samples) &&
1032 (VK_SAMPLE_COUNT_2_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001033 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1034 __LINE__, VALIDATION_ERROR_09e0079a, LayerName,
1035 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if "
1036 "corresponding feature is not enabled on the device. %s",
1037 validation_error_map[VALIDATION_ERROR_09e0079a]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001038 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency4Samples) &&
1039 (VK_SAMPLE_COUNT_4_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001040 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1041 __LINE__, VALIDATION_ERROR_09e0079c, LayerName,
1042 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if "
1043 "corresponding feature is not enabled on the device. %s",
1044 validation_error_map[VALIDATION_ERROR_09e0079c]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001045 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency8Samples) &&
1046 (VK_SAMPLE_COUNT_8_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001047 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1048 __LINE__, VALIDATION_ERROR_09e0079e, LayerName,
1049 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if "
1050 "corresponding feature is not enabled on the device. %s",
1051 validation_error_map[VALIDATION_ERROR_09e0079e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001052 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency16Samples) &&
1053 (VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001054 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1055 __LINE__, VALIDATION_ERROR_09e007a0, LayerName,
1056 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if "
1057 "corresponding feature is not enabled on the device. %s",
1058 validation_error_map[VALIDATION_ERROR_09e007a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001059 }
1060 }
1061 }
1062 }
1063 return skip;
1064}
1065
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001066bool pv_vkCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1067 VkImageView *pView) {
1068 bool skip = false;
1069 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1070 debug_report_data *report_data = device_data->report_data;
1071
1072 if (pCreateInfo != nullptr) {
1073 if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) || (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D)) {
1074 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
1075 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1076 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1077 LayerName,
1078 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD, "
1079 "pCreateInfo->subresourceRange.layerCount must be 1",
1080 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) ? 1 : 2));
1081 }
1082 } else if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ||
1083 (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
1084 if ((pCreateInfo->subresourceRange.layerCount < 1) &&
1085 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1086 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1087 LayerName,
1088 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD_ARRAY, "
1089 "pCreateInfo->subresourceRange.layerCount must be >= 1",
1090 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ? 1 : 2));
1091 }
1092 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE) {
1093 if ((pCreateInfo->subresourceRange.layerCount != 6) &&
1094 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1095 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1096 LayerName,
1097 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE, "
1098 "pCreateInfo->subresourceRange.layerCount must be 6");
1099 }
1100 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
1101 if (((pCreateInfo->subresourceRange.layerCount == 0) || ((pCreateInfo->subresourceRange.layerCount % 6) != 0)) &&
1102 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1103 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1104 LayerName,
1105 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE_ARRAY, "
1106 "pCreateInfo->subresourceRange.layerCount must be a multiple of 6");
1107 }
1108 if (!device_data->physical_device_features.imageCubeArray) {
1109 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1110 LayerName, "vkCreateImageView: Device feature imageCubeArray not enabled.");
1111 }
1112 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_3D) {
1113 if (pCreateInfo->subresourceRange.baseArrayLayer != 0) {
1114 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1115 LayerName,
1116 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1117 "pCreateInfo->subresourceRange.baseArrayLayer must be 0");
1118 }
1119
1120 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
1121 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1122 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1123 LayerName,
1124 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1125 "pCreateInfo->subresourceRange.layerCount must be 1");
1126 }
1127 }
1128 }
1129 return skip;
1130}
1131
Petr Krausb3fcdb42018-01-09 22:09:09 +01001132bool pv_VkViewport(const layer_data *device_data, const VkViewport &viewport, const char *fn_name, const char *param_name,
1133 VkDebugReportObjectTypeEXT object_type, uint64_t object = 0) {
1134 bool skip = false;
1135 debug_report_data *report_data = device_data->report_data;
1136
1137 // Note: for numerical correctness
1138 // - float comparisons should expect NaN (comparison always false).
1139 // - VkPhysicalDeviceLimits::maxViewportDimensions is uint32_t, not float -> careful.
1140
1141 const auto f_lte_u32_exact = [](const float v1_f, const uint32_t v2_u32) {
John Zulaufac0876c2018-02-19 10:09:35 -07001142 if (std::isnan(v1_f)) return false;
Petr Krausb3fcdb42018-01-09 22:09:09 +01001143 if (v1_f <= 0.0f) return true;
1144
1145 float intpart;
1146 const float fract = modff(v1_f, &intpart);
1147
1148 assert(std::numeric_limits<float>::radix == 2);
1149 const float u32_max_plus1 = ldexpf(1.0f, 32); // hopefully exact
1150 if (intpart >= u32_max_plus1) return false;
1151
1152 uint32_t v1_u32 = static_cast<uint32_t>(intpart);
1153 if (v1_u32 < v2_u32)
1154 return true;
1155 else if (v1_u32 == v2_u32 && fract == 0.0f)
1156 return true;
1157 else
1158 return false;
1159 };
1160
1161 const auto f_lte_u32_direct = [](const float v1_f, const uint32_t v2_u32) {
1162 const float v2_f = static_cast<float>(v2_u32); // not accurate for > radix^digits; and undefined rounding mode
1163 return (v1_f <= v2_f);
1164 };
1165
1166 // width
1167 bool width_healthy = true;
1168 const auto max_w = device_data->device_limits.maxViewportDimensions[0];
1169
1170 if (!(viewport.width > 0.0f)) {
1171 width_healthy = false;
1172 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd4,
1173 LayerName, "%s: %s.width (=%f) is not greater than 0.0. %s", fn_name, param_name, viewport.width,
1174 validation_error_map[VALIDATION_ERROR_15000dd4]);
1175 } else if (!(f_lte_u32_exact(viewport.width, max_w) || f_lte_u32_direct(viewport.width, max_w))) {
1176 width_healthy = false;
1177 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd6,
1178 LayerName, "%s: %s.width (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32 "). %s",
1179 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1180 } else if (!f_lte_u32_exact(viewport.width, max_w) && f_lte_u32_direct(viewport.width, max_w)) {
1181 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1182 "%s: %s.width (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32
1183 "), but it is within the static_cast<float>(maxViewportDimensions[0]) limit. %s",
1184 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1185 }
1186
1187 // height
1188 bool height_healthy = true;
1189 const bool negative_height_enabled =
1190 device_data->extensions.vk_khr_maintenance1 || device_data->extensions.vk_amd_negative_viewport_height;
1191 const auto max_h = device_data->device_limits.maxViewportDimensions[1];
1192
1193 if (!negative_height_enabled && !(viewport.height > 0.0f)) {
1194 height_healthy = false;
1195 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd8,
1196 LayerName, "%s: %s.height (=%f) is not greater 0.0. %s", fn_name, param_name, viewport.height,
1197 validation_error_map[VALIDATION_ERROR_15000dd8]);
1198 } else if (!(f_lte_u32_exact(fabsf(viewport.height), max_h) || f_lte_u32_direct(fabsf(viewport.height), max_h))) {
1199 height_healthy = false;
1200
1201 skip |= log_msg(
1202 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dda, LayerName,
1203 "%s: Absolute value of %s.height (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32 "). %s",
1204 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1205 } else if (!f_lte_u32_exact(fabsf(viewport.height), max_h) && f_lte_u32_direct(fabsf(viewport.height), max_h)) {
1206 height_healthy = false;
1207
1208 skip |= log_msg(
1209 report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1210 "%s: Absolute value of %s.height (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32
1211 "), but it is within the static_cast<float>(maxViewportDimensions[1]) limit. %s",
1212 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1213 }
1214
1215 // x
1216 bool x_healthy = true;
1217 if (!(viewport.x >= device_data->device_limits.viewportBoundsRange[0])) {
1218 x_healthy = false;
1219 skip |=
1220 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000ddc, LayerName,
1221 "%s: %s.x (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1222 viewport.x, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000ddc]);
1223 }
1224
1225 // x + width
1226 if (x_healthy && width_healthy) {
1227 const float right_bound = viewport.x + viewport.width;
1228 if (!(right_bound <= device_data->device_limits.viewportBoundsRange[1])) {
1229 skip |= log_msg(
1230 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1231 "%s: %s.x + %s.width (=%f + %f = %f) is greater than VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1232 fn_name, param_name, param_name, viewport.x, viewport.width, right_bound,
1233 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
1234 }
1235 }
1236
1237 // y
1238 bool y_healthy = true;
1239 if (!(viewport.y >= device_data->device_limits.viewportBoundsRange[0])) {
1240 y_healthy = false;
1241 skip |=
1242 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dde, LayerName,
1243 "%s: %s.y (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1244 viewport.y, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000dde]);
1245 } else if (negative_height_enabled && !(viewport.y <= device_data->device_limits.viewportBoundsRange[1])) {
1246 y_healthy = false;
1247 skip |=
1248 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de0, LayerName,
1249 "%s: %s.y (=%f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s", fn_name, param_name,
1250 viewport.y, device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_15000de0]);
1251 }
1252
1253 // y + height
1254 if (y_healthy && height_healthy) {
1255 const float boundary = viewport.y + viewport.height;
1256
1257 if (!(boundary <= device_data->device_limits.viewportBoundsRange[1])) {
1258 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a2,
1259 LayerName,
1260 "%s: %s.y + %s.height (=%f + %f = %f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1261 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1262 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
1263 } else if (negative_height_enabled && !(boundary >= device_data->device_limits.viewportBoundsRange[0])) {
1264 skip |= log_msg(
1265 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de2, LayerName,
1266 "%s: %s.y + %s.height (=%f + %f = %f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s",
1267 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1268 device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000de2]);
1269 }
1270 }
1271
1272 if (!device_data->extensions.vk_ext_depth_range_unrestricted) {
1273 // minDepth
1274 if (!(viewport.minDepth >= 0.0) || !(viewport.minDepth <= 1.0)) {
1275 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a4,
1276 LayerName,
1277 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.minDepth (=%f) is not within the "
1278 "[0.0, 1.0] range. %s",
1279 fn_name, param_name, viewport.minDepth, validation_error_map[VALIDATION_ERROR_150009a4]);
1280 }
1281
1282 // maxDepth
1283 if (!(viewport.maxDepth >= 0.0) || !(viewport.maxDepth <= 1.0)) {
1284 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a6,
1285 LayerName,
1286 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.maxDepth (=%f) is not within the "
1287 "[0.0, 1.0] range. %s",
1288 fn_name, param_name, viewport.maxDepth, validation_error_map[VALIDATION_ERROR_150009a6]);
1289 }
1290 }
1291
1292 return skip;
1293}
1294
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001295bool pv_vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1296 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1297 VkPipeline *pPipelines) {
1298 bool skip = false;
1299 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1300 debug_report_data *report_data = device_data->report_data;
1301
1302 if (pCreateInfos != nullptr) {
1303 for (uint32_t i = 0; i < createInfoCount; ++i) {
Petr Kraus299ba622017-11-24 03:09:03 +01001304 bool has_dynamic_viewport = false;
1305 bool has_dynamic_scissor = false;
1306 bool has_dynamic_line_width = false;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001307 bool has_dynamic_viewport_w_scaling_nv = false;
1308 bool has_dynamic_discard_rectangle_ext = false;
1309 bool has_dynamic_sample_locations_ext = false;
Petr Kraus299ba622017-11-24 03:09:03 +01001310 if (pCreateInfos[i].pDynamicState != nullptr) {
1311 const auto &dynamic_state_info = *pCreateInfos[i].pDynamicState;
1312 for (uint32_t state_index = 0; state_index < dynamic_state_info.dynamicStateCount; ++state_index) {
1313 const auto &dynamic_state = dynamic_state_info.pDynamicStates[state_index];
1314 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT) has_dynamic_viewport = true;
1315 if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR) has_dynamic_scissor = true;
1316 if (dynamic_state == VK_DYNAMIC_STATE_LINE_WIDTH) has_dynamic_line_width = true;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001317 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV) has_dynamic_viewport_w_scaling_nv = true;
1318 if (dynamic_state == VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT) has_dynamic_discard_rectangle_ext = true;
1319 if (dynamic_state == VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) has_dynamic_sample_locations_ext = true;
Petr Kraus299ba622017-11-24 03:09:03 +01001320 }
1321 }
1322
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001323 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1324 if (pCreateInfos[i].pVertexInputState != nullptr) {
1325 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
1326 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
1327 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
1328 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1329 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1330 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
1331 "vkCreateGraphicsPipelines: parameter "
1332 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
1333 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1334 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
1335 validation_error_map[VALIDATION_ERROR_14c004d4]);
1336 }
1337
1338 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
1339 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1340 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
1341 "vkCreateGraphicsPipelines: parameter "
1342 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
1343 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
1344 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
1345 validation_error_map[VALIDATION_ERROR_14c004d6]);
1346 }
1347 }
1348
1349 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
1350 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
1351 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
1352 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1353 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
1354 "vkCreateGraphicsPipelines: parameter "
1355 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
1356 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
1357 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
1358 validation_error_map[VALIDATION_ERROR_14a004d8]);
1359 }
1360
1361 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1362 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1363 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
1364 "vkCreateGraphicsPipelines: parameter "
1365 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
1366 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1367 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
1368 validation_error_map[VALIDATION_ERROR_14a004da]);
1369 }
1370
1371 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
1372 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1373 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
1374 "vkCreateGraphicsPipelines: parameter "
1375 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
1376 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
1377 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
1378 validation_error_map[VALIDATION_ERROR_14a004dc]);
1379 }
1380 }
1381 }
1382
1383 if (pCreateInfos[i].pStages != nullptr) {
1384 bool has_control = false;
1385 bool has_eval = false;
1386
1387 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
1388 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1389 has_control = true;
1390 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
1391 has_eval = true;
1392 }
1393 }
1394
1395 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1396 if (has_control && has_eval) {
1397 if (pCreateInfos[i].pTessellationState == nullptr) {
1398 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1399 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
1400 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1401 "shader stage and a tessellation evaluation shader stage, "
1402 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
1403 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
1404 } else {
1405 skip |= validate_struct_pnext(
1406 report_data, "vkCreateGraphicsPipelines",
1407 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
1408 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
1409
1410 skip |= validate_reserved_flags(
1411 report_data, "vkCreateGraphicsPipelines",
1412 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1413 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1414
1415 if (pCreateInfos[i].pTessellationState->sType !=
1416 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1417 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1418 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1419 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1420 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1421 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1422 }
1423
1424 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1425 pCreateInfos[i].pTessellationState->patchControlPoints >
1426 device_data->device_limits.maxTessellationPatchSize) {
1427 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1428 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1429 "vkCreateGraphicsPipelines: invalid parameter "
1430 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1431 "should be >0 and <=%u. %s",
1432 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1433 device_data->device_limits.maxTessellationPatchSize,
1434 validation_error_map[VALIDATION_ERROR_1080097c]);
1435 }
1436 }
1437 }
1438 }
1439
1440 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1441 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1442 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1443 if (pCreateInfos[i].pViewportState == nullptr) {
Petr Krausa6103552017-11-16 21:21:58 +01001444 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1445 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1446 "vkCreateGraphicsPipelines: Rasterization is enabled (pCreateInfos[%" PRIu32
1447 "].pRasterizationState->rasterizerDiscardEnable is VK_FALSE), but pCreateInfos[%" PRIu32
1448 "].pViewportState (=NULL) is not a valid pointer. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001449 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1450 } else {
Petr Krausa6103552017-11-16 21:21:58 +01001451 const auto &viewport_state = *pCreateInfos[i].pViewportState;
1452
1453 if (viewport_state.sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1454 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1455 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b00b, LayerName,
1456 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1457 "].pViewportState->sType is not VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO. %s",
1458 i, validation_error_map[VALIDATION_ERROR_10c2b00b]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001459 }
1460
Petr Krausa6103552017-11-16 21:21:58 +01001461 const VkStructureType allowed_structs_VkPipelineViewportStateCreateInfo[] = {
1462 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
1463 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV};
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001464 skip |= validate_struct_pnext(
1465 report_data, "vkCreateGraphicsPipelines",
Petr Krausa6103552017-11-16 21:21:58 +01001466 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}),
1467 "VkPipelineViewportSwizzleStateCreateInfoNV, VkPipelineViewportWScalingStateCreateInfoNV",
1468 viewport_state.pNext, ARRAY_SIZE(allowed_structs_VkPipelineViewportStateCreateInfo),
1469 allowed_structs_VkPipelineViewportStateCreateInfo, 65, VALIDATION_ERROR_10c1c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001470
1471 skip |= validate_reserved_flags(
1472 report_data, "vkCreateGraphicsPipelines",
1473 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
Petr Krausa6103552017-11-16 21:21:58 +01001474 viewport_state.flags, VALIDATION_ERROR_10c09005);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001475
Petr Krausa6103552017-11-16 21:21:58 +01001476 if (!device_data->physical_device_features.multiViewport) {
1477 if (viewport_state.viewportCount != 1) {
1478 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1479 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1480 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1481 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32
1482 ") is not 1. %s",
1483 i, viewport_state.viewportCount, validation_error_map[VALIDATION_ERROR_10c00980]);
1484 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001485
Petr Krausa6103552017-11-16 21:21:58 +01001486 if (viewport_state.scissorCount != 1) {
1487 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1488 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1489 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1490 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->scissorCount (=%" PRIu32
1491 ") is not 1. %s",
1492 i, viewport_state.scissorCount, validation_error_map[VALIDATION_ERROR_10c00982]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001493 }
Petr Krausa6103552017-11-16 21:21:58 +01001494 } else { // multiViewport enabled
1495 if (viewport_state.viewportCount == 0) {
1496 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1497 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c30a1b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001498 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001499 "].pViewportState->viewportCount is 0. %s",
1500 i, validation_error_map[VALIDATION_ERROR_10c30a1b]);
1501 } else if (viewport_state.viewportCount > device_data->device_limits.maxViewports) {
1502 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1503 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1504 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1505 "].pViewportState->viewportCount (=%" PRIu32
1506 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1507 i, viewport_state.viewportCount, device_data->device_limits.maxViewports,
1508 validation_error_map[VALIDATION_ERROR_10c00984]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001509 }
Petr Krausa6103552017-11-16 21:21:58 +01001510
1511 if (viewport_state.scissorCount == 0) {
1512 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1513 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b61b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001514 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001515 "].pViewportState->scissorCount is 0. %s",
1516 i, validation_error_map[VALIDATION_ERROR_10c2b61b]);
1517 } else if (viewport_state.scissorCount > device_data->device_limits.maxViewports) {
1518 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1519 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1520 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1521 "].pViewportState->scissorCount (=%" PRIu32
1522 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1523 i, viewport_state.scissorCount, device_data->device_limits.maxViewports,
1524 validation_error_map[VALIDATION_ERROR_10c00986]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001525 }
1526 }
1527
Petr Krausa6103552017-11-16 21:21:58 +01001528 if (viewport_state.scissorCount != viewport_state.viewportCount) {
1529 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1530 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1531 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1532 "].pViewportState->scissorCount (=%" PRIu32 ") is not identical to pCreateInfos[%" PRIu32
1533 "].pViewportState->viewportCount (=%" PRIu32 "). %s",
1534 i, viewport_state.scissorCount, i, viewport_state.viewportCount,
1535 validation_error_map[VALIDATION_ERROR_10c00988]);
1536 }
1537
Petr Krausa6103552017-11-16 21:21:58 +01001538 if (!has_dynamic_viewport && viewport_state.viewportCount > 0 && viewport_state.pViewports == nullptr) {
1539 skip |= log_msg(
1540 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1541 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1542 "vkCreateGraphicsPipelines: The viewport state is static (pCreateInfos[%" PRIu32
1543 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001544 "].pViewportState->pViewports (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001545 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1546 }
1547
1548 if (!has_dynamic_scissor && viewport_state.scissorCount > 0 && viewport_state.pScissors == nullptr) {
1549 skip |= log_msg(
1550 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1551 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1552 "vkCreateGraphicsPipelines: The scissor state is static (pCreateInfos[%" PRIu32
1553 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_SCISSOR), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001554 "].pViewportState->pScissors (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001555 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1556 }
1557
Petr Krausb3fcdb42018-01-09 22:09:09 +01001558 // validate the VkViewports
1559 if (!has_dynamic_viewport && viewport_state.pViewports) {
1560 for (uint32_t viewport_i = 0; viewport_i < viewport_state.viewportCount; ++viewport_i) {
1561 const auto &viewport = viewport_state.pViewports[viewport_i]; // will crash on invalid ptr
1562 const char fn_name[] = "vkCreateGraphicsPipelines";
1563 const std::string param_name = "pCreateInfos[" + std::to_string(i) + "].pViewportState->pViewports[" +
1564 std::to_string(viewport_i) + "]";
1565 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
1566 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
1567 }
1568 }
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001569
1570 if (has_dynamic_viewport_w_scaling_nv && !device_data->extensions.vk_nv_clip_space_w_scaling) {
1571 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1572 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1573 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001574 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001575 "VK_NV_clip_space_w_scaling extension is not enabled.",
1576 i);
1577 }
1578
1579 if (has_dynamic_discard_rectangle_ext && !device_data->extensions.vk_ext_discard_rectangles) {
1580 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1581 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1582 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001583 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001584 "VK_EXT_discard_rectangles extension is not enabled.",
1585 i);
1586 }
1587
1588 if (has_dynamic_sample_locations_ext && !device_data->extensions.vk_ext_sample_locations) {
1589 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1590 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1591 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001592 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001593 "VK_EXT_sample_locations extension is not enabled.",
1594 i);
1595 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001596 }
1597
1598 if (pCreateInfos[i].pMultisampleState == nullptr) {
1599 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1600 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1601 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1602 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1603 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1604 } else {
Dave Houltonb3bbec72018-01-17 10:13:33 -07001605 const VkStructureType valid_next_stypes[] = {LvlTypeMap<VkPipelineCoverageModulationStateCreateInfoNV>::kSType,
1606 LvlTypeMap<VkPipelineCoverageToColorStateCreateInfoNV>::kSType,
1607 LvlTypeMap<VkPipelineSampleLocationsStateCreateInfoEXT>::kSType};
Mike Schuchardt97662b02017-12-06 13:31:29 -07001608 const char *valid_struct_names =
Dave Houltona9df0ce2018-02-07 10:51:23 -07001609 "VkPipelineCoverageModulationStateCreateInfoNV, VkPipelineCoverageToColorStateCreateInfoNV, "
John Zulauf96b0e422017-11-14 11:43:19 -07001610 "VkPipelineSampleLocationsStateCreateInfoEXT";
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001611 skip |= validate_struct_pnext(
1612 report_data, "vkCreateGraphicsPipelines",
John Zulauf96b0e422017-11-14 11:43:19 -07001613 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}),
1614 valid_struct_names, pCreateInfos[i].pMultisampleState->pNext, 3, valid_next_stypes, GeneratedHeaderVersion,
1615 VALIDATION_ERROR_1001c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001616
1617 skip |= validate_reserved_flags(
1618 report_data, "vkCreateGraphicsPipelines",
1619 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1620 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1621
1622 skip |= validate_bool32(
1623 report_data, "vkCreateGraphicsPipelines",
1624 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1625 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1626
1627 skip |= validate_array(
1628 report_data, "vkCreateGraphicsPipelines",
1629 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1630 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1631 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1632 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1633
1634 skip |= validate_bool32(
1635 report_data, "vkCreateGraphicsPipelines",
1636 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1637 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1638
1639 skip |= validate_bool32(
1640 report_data, "vkCreateGraphicsPipelines",
1641 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1642 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1643
1644 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1645 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1646 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1647 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1648 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1649 i);
1650 }
John Zulauf7acac592017-11-06 11:15:53 -07001651 if (pCreateInfos[i].pMultisampleState->sampleShadingEnable == VK_TRUE) {
1652 if (!device_data->physical_device_features.sampleRateShading) {
1653 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1654 __LINE__, VALIDATION_ERROR_10000620, LayerName,
1655 "vkCreateGraphicsPipelines(): parameter "
1656 "pCreateInfos[%d].pMultisampleState->sampleShadingEnable: %s",
1657 i, validation_error_map[VALIDATION_ERROR_10000620]);
1658 }
1659 // TODO Add documentation issue about when minSampleShading must be in range and when it is ignored
1660 // For now a "least noise" test *only* when sampleShadingEnable is VK_TRUE.
1661 if (!in_inclusive_range(pCreateInfos[i].pMultisampleState->minSampleShading, 0.F, 1.0F)) {
1662 skip |= log_msg(
1663 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1664 VALIDATION_ERROR_10000624, LayerName,
1665 "vkCreateGraphicsPipelines(): parameter pCreateInfos[%d].pMultisampleState->minSampleShading: %s",
1666 i, validation_error_map[VALIDATION_ERROR_10000624]);
1667 }
1668 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001669 }
1670
Petr Krause91f7a12017-12-14 20:57:36 +01001671 bool uses_color_attachment = false;
1672 bool uses_depthstencil_attachment = false;
1673 {
1674 const auto subpasses_uses_it = device_data->renderpasses_states.find(pCreateInfos[i].renderPass);
1675 if (subpasses_uses_it != device_data->renderpasses_states.end()) {
1676 const auto &subpasses_uses = subpasses_uses_it->second;
1677 if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[i].subpass))
1678 uses_color_attachment = true;
1679 if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[i].subpass))
1680 uses_depthstencil_attachment = true;
1681 }
1682 }
1683
1684 if (pCreateInfos[i].pDepthStencilState != nullptr && uses_depthstencil_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001685 skip |= validate_struct_pnext(
1686 report_data, "vkCreateGraphicsPipelines",
1687 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1688 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1689
1690 skip |= validate_reserved_flags(
1691 report_data, "vkCreateGraphicsPipelines",
1692 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1693 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1694
1695 skip |= validate_bool32(
1696 report_data, "vkCreateGraphicsPipelines",
1697 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1698 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1699
1700 skip |= validate_bool32(
1701 report_data, "vkCreateGraphicsPipelines",
1702 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1703 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1704
1705 skip |= validate_ranged_enum(
1706 report_data, "vkCreateGraphicsPipelines",
1707 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1708 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1709 VALIDATION_ERROR_0f604001);
1710
1711 skip |= validate_bool32(
1712 report_data, "vkCreateGraphicsPipelines",
1713 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1714 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1715
1716 skip |= validate_bool32(
1717 report_data, "vkCreateGraphicsPipelines",
1718 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1719 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1720
1721 skip |= validate_ranged_enum(
1722 report_data, "vkCreateGraphicsPipelines",
1723 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1724 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1725 VALIDATION_ERROR_13a08601);
1726
1727 skip |= validate_ranged_enum(
1728 report_data, "vkCreateGraphicsPipelines",
1729 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1730 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1731 VALIDATION_ERROR_13a27801);
1732
1733 skip |= validate_ranged_enum(
1734 report_data, "vkCreateGraphicsPipelines",
1735 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1736 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1737 VALIDATION_ERROR_13a04201);
1738
1739 skip |= validate_ranged_enum(
1740 report_data, "vkCreateGraphicsPipelines",
1741 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1742 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1743 VALIDATION_ERROR_0f604001);
1744
1745 skip |= validate_ranged_enum(
1746 report_data, "vkCreateGraphicsPipelines",
1747 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1748 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1749 VALIDATION_ERROR_13a08601);
1750
1751 skip |= validate_ranged_enum(
1752 report_data, "vkCreateGraphicsPipelines",
1753 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1754 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1755 VALIDATION_ERROR_13a27801);
1756
1757 skip |= validate_ranged_enum(
1758 report_data, "vkCreateGraphicsPipelines",
1759 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1760 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1761 VALIDATION_ERROR_13a04201);
1762
1763 skip |= validate_ranged_enum(
1764 report_data, "vkCreateGraphicsPipelines",
1765 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1766 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1767 VALIDATION_ERROR_0f604001);
1768
1769 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1770 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1771 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1772 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1773 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1774 i);
1775 }
1776 }
1777
Petr Krause91f7a12017-12-14 20:57:36 +01001778 if (pCreateInfos[i].pColorBlendState != nullptr && uses_color_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001779 skip |= validate_struct_pnext(
1780 report_data, "vkCreateGraphicsPipelines",
1781 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1782 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1783
1784 skip |= validate_reserved_flags(
1785 report_data, "vkCreateGraphicsPipelines",
1786 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1787 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1788
1789 skip |= validate_bool32(
1790 report_data, "vkCreateGraphicsPipelines",
1791 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1792 pCreateInfos[i].pColorBlendState->logicOpEnable);
1793
1794 skip |= validate_array(
1795 report_data, "vkCreateGraphicsPipelines",
1796 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1797 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1798 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1799 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1800
1801 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1802 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1803 ++attachmentIndex) {
1804 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1805 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1806 ParameterName::IndexVector{i, attachmentIndex}),
1807 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1808
1809 skip |= validate_ranged_enum(
1810 report_data, "vkCreateGraphicsPipelines",
1811 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1812 ParameterName::IndexVector{i, attachmentIndex}),
1813 "VkBlendFactor", AllVkBlendFactorEnums,
1814 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1815 VALIDATION_ERROR_0f22cc01);
1816
1817 skip |= validate_ranged_enum(
1818 report_data, "vkCreateGraphicsPipelines",
1819 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1820 ParameterName::IndexVector{i, attachmentIndex}),
1821 "VkBlendFactor", AllVkBlendFactorEnums,
1822 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1823 VALIDATION_ERROR_0f207001);
1824
1825 skip |= validate_ranged_enum(
1826 report_data, "vkCreateGraphicsPipelines",
1827 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1828 ParameterName::IndexVector{i, attachmentIndex}),
1829 "VkBlendOp", AllVkBlendOpEnums,
1830 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1831 VALIDATION_ERROR_0f202001);
1832
1833 skip |= validate_ranged_enum(
1834 report_data, "vkCreateGraphicsPipelines",
1835 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1836 ParameterName::IndexVector{i, attachmentIndex}),
1837 "VkBlendFactor", AllVkBlendFactorEnums,
1838 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1839 VALIDATION_ERROR_0f22c601);
1840
1841 skip |= validate_ranged_enum(
1842 report_data, "vkCreateGraphicsPipelines",
1843 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1844 ParameterName::IndexVector{i, attachmentIndex}),
1845 "VkBlendFactor", AllVkBlendFactorEnums,
1846 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1847 VALIDATION_ERROR_0f206a01);
1848
1849 skip |= validate_ranged_enum(
1850 report_data, "vkCreateGraphicsPipelines",
1851 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1852 ParameterName::IndexVector{i, attachmentIndex}),
1853 "VkBlendOp", AllVkBlendOpEnums,
1854 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1855 VALIDATION_ERROR_0f200801);
1856
1857 skip |=
1858 validate_flags(report_data, "vkCreateGraphicsPipelines",
1859 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1860 ParameterName::IndexVector{i, attachmentIndex}),
1861 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1862 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1863 false, false, VALIDATION_ERROR_0f202201);
1864 }
1865 }
1866
1867 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1868 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1869 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1870 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1871 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1872 i);
1873 }
1874
1875 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1876 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1877 skip |= validate_ranged_enum(
1878 report_data, "vkCreateGraphicsPipelines",
1879 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1880 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1881 }
1882 }
1883 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001884
Petr Kraus9752aae2017-11-24 03:05:50 +01001885 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1886 if (pCreateInfos[i].basePipelineIndex != -1) {
1887 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001888 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1889 __LINE__, VALIDATION_ERROR_096005a8, LayerName,
1890 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be "
1891 "VK_NULL_HANDLE if pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag "
1892 "and pCreateInfos->basePipelineIndex is not -1. %s",
1893 validation_error_map[VALIDATION_ERROR_096005a8]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001894 }
1895 }
1896
Petr Kraus9752aae2017-11-24 03:05:50 +01001897 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
1898 if (pCreateInfos[i].basePipelineIndex != -1) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001899 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1900 __LINE__, VALIDATION_ERROR_096005aa, LayerName,
1901 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1902 "pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and "
1903 "pCreateInfos->basePipelineHandle is not VK_NULL_HANDLE. %s",
1904 validation_error_map[VALIDATION_ERROR_096005aa]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001905 }
1906 }
1907 }
1908
Petr Kraus9752aae2017-11-24 03:05:50 +01001909 if (pCreateInfos[i].pRasterizationState) {
1910 if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001911 (device_data->physical_device_features.fillModeNonSolid == false)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001912 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1913 __LINE__, DEVICE_FEATURE, LayerName,
1914 "vkCreateGraphicsPipelines parameter, VkPolygonMode "
1915 "pCreateInfos->pRasterizationState->polygonMode cannot be VK_POLYGON_MODE_POINT or "
1916 "VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001917 }
Petr Kraus299ba622017-11-24 03:09:03 +01001918
1919 if (!has_dynamic_line_width && !device_data->physical_device_features.wideLines &&
1920 (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
1921 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1922 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, 0, __LINE__, VALIDATION_ERROR_096005da, LayerName,
1923 "The line width state is static (pCreateInfos[%" PRIu32
1924 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
1925 "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
1926 "].pRasterizationState->lineWidth (=%f) is not 1.0. %s",
1927 i, i, pCreateInfos[i].pRasterizationState->lineWidth,
1928 validation_error_map[VALIDATION_ERROR_096005da]);
1929 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001930 }
1931
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001932 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1933 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1934 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1935 pCreateInfos[i].pStages[j].pName);
1936 }
1937 }
1938 }
1939
1940 return skip;
1941}
1942
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001943bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1944 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1945 VkPipeline *pPipelines) {
1946 bool skip = false;
1947 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1948
1949 for (uint32_t i = 0; i < createInfoCount; i++) {
1950 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1951 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1952 pCreateInfos[i].stage.pName);
1953 }
1954
1955 return skip;
1956}
1957
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001958bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1959 VkSampler *pSampler) {
1960 bool skip = false;
1961 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1962 debug_report_data *report_data = device_data->report_data;
1963
1964 if (pCreateInfo != nullptr) {
John Zulauf71968502017-10-26 13:51:15 -06001965 const auto &features = device_data->physical_device_features;
1966 const auto &limits = device_data->device_limits;
1967 if (pCreateInfo->anisotropyEnable == VK_TRUE) {
1968 if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
1969 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1970 VALIDATION_ERROR_1260085e, LayerName,
1971 "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found. %s",
1972 "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
1973 "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy,
1974 validation_error_map[VALIDATION_ERROR_1260085e]);
1975 }
1976
1977 // Anistropy cannot be enabled in sampler unless enabled as a feature
1978 if (features.samplerAnisotropy == VK_FALSE) {
1979 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1980 VALIDATION_ERROR_1260085c, LayerName,
1981 "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE. %s",
1982 "pCreateInfo->anisotropyEnable", validation_error_map[VALIDATION_ERROR_1260085c]);
1983 }
1984
1985 // Anistropy and unnormalized coordinates cannot be enabled simultaneously
1986 if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
1987 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1988 VALIDATION_ERROR_12600868, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001989 "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates must "
1990 "not both be VK_TRUE. %s",
John Zulauf71968502017-10-26 13:51:15 -06001991 validation_error_map[VALIDATION_ERROR_12600868]);
1992 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001993 }
1994
1995 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1996 if (pCreateInfo->compareEnable == VK_TRUE) {
1997 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1998 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
1999 }
2000
2001 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
2002 // valid VkBorderColor value
2003 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2004 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2005 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
2006 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
2007 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
2008 }
2009
2010 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
2011 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
2012 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
2013 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2014 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2015 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
2016 skip |=
2017 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2018 VALIDATION_ERROR_1260086e, LayerName,
2019 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
2020 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
2021 validation_error_map[VALIDATION_ERROR_1260086e]);
2022 }
John Zulauf275805c2017-10-26 15:34:49 -06002023
2024 // Checks for the IMG cubic filtering extension
2025 if (device_data->extensions.vk_img_filter_cubic) {
2026 if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
2027 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002028 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2029 VALIDATION_ERROR_12600872, LayerName,
2030 "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter "
2031 "are VK_FILTER_CUBIC_IMG. %s",
2032 validation_error_map[VALIDATION_ERROR_12600872]);
John Zulauf275805c2017-10-26 15:34:49 -06002033 }
2034 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002035 }
2036
2037 return skip;
2038}
2039
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002040bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2041 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
2042 bool skip = false;
2043 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2044 debug_report_data *report_data = device_data->report_data;
2045
2046 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2047 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
2048 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
2049 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
2050 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
2051 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
2052 // valid VkSampler handles
2053 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2054 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
2055 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
2056 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
2057 ++descriptor_index) {
2058 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
2059 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2060 __LINE__, REQUIRED_PARAMETER, LayerName,
2061 "vkCreateDescriptorSetLayout: required parameter "
Dave Houltona9df0ce2018-02-07 10:51:23 -07002062 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d] specified as VK_NULL_HANDLE",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002063 i, descriptor_index);
2064 }
2065 }
2066 }
2067
2068 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
2069 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
2070 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002071 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2072 __LINE__, VALIDATION_ERROR_04e00236, LayerName,
2073 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
2074 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits "
2075 "values. %s",
2076 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002077 }
2078 }
2079 }
2080 }
2081
2082 return skip;
2083}
2084
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002085bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
2086 const VkDescriptorSet *pDescriptorSets) {
2087 bool skip = false;
2088 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2089 debug_report_data *report_data = device_data->report_data;
2090
2091 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2092 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2093 // validate_array()
2094 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
2095 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2096 return skip;
2097}
2098
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002099bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
2100 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
2101 bool skip = false;
2102 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2103 debug_report_data *report_data = device_data->report_data;
2104
2105 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2106 if (pDescriptorWrites != NULL) {
2107 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
2108 // descriptorCount must be greater than 0
2109 if (pDescriptorWrites[i].descriptorCount == 0) {
2110 skip |=
2111 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2112 VALIDATION_ERROR_15c0441b, LayerName,
2113 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
2114 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
2115 }
2116
2117 // dstSet must be a valid VkDescriptorSet handle
2118 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2119 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
2120 pDescriptorWrites[i].dstSet);
2121
2122 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2123 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
2124 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
2125 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
2126 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
2127 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
2128 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2129 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
2130 if (pDescriptorWrites[i].pImageInfo == nullptr) {
2131 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2132 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
2133 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2134 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
2135 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
2136 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
2137 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
2138 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
2139 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
2140 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
2141 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
2142 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2143 ++descriptor_index) {
2144 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2145 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
2146 ParameterName::IndexVector{i, descriptor_index}),
2147 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
2148 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
2149 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
2150 ParameterName::IndexVector{i, descriptor_index}),
2151 "VkImageLayout", AllVkImageLayoutEnums,
2152 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
2153 VALIDATION_ERROR_UNDEFINED);
2154 }
2155 }
2156 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2157 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2158 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
2159 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2160 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
2161 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
2162 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
2163 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
2164 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2165 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
2166 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2167 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
2168 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
2169 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
2170 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
2171 } else {
2172 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
2173 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2174 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
2175 ParameterName::IndexVector{i, descriptorIndex}),
2176 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
2177 }
2178 }
2179 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
2180 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
2181 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
2182 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
2183 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
2184 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2185 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
2186 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2187 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
2188 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
2189 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
2190 } else {
2191 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2192 ++descriptor_index) {
2193 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2194 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
2195 ParameterName::IndexVector{i, descriptor_index}),
2196 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
2197 }
2198 }
2199 }
2200
2201 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2202 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
2203 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
2204 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2205 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2206 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
2207 skip |= log_msg(
2208 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2209 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
2210 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2211 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2212 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
2213 validation_error_map[VALIDATION_ERROR_15c0028e]);
2214 }
2215 }
2216 }
2217 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2218 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2219 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
2220 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2221 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2222 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
2223 skip |= log_msg(
2224 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2225 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
2226 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2227 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2228 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
2229 validation_error_map[VALIDATION_ERROR_15c00290]);
2230 }
2231 }
2232 }
2233 }
2234 }
2235 }
2236 return skip;
2237}
2238
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002239bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2240 VkRenderPass *pRenderPass) {
2241 bool skip = false;
2242 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2243 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
2244
2245 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
2246 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
2247 std::stringstream ss;
2248 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
2249 << validation_error_map[VALIDATION_ERROR_00809201];
2250 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2251 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
2252 }
2253 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
2254 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
2255 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2256 __LINE__, VALIDATION_ERROR_00800696, "DL",
2257 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
2258 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
2259 i, validation_error_map[VALIDATION_ERROR_00800696]);
2260 }
2261 }
2262
2263 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2264 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
2265 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2266 __LINE__, VALIDATION_ERROR_1400069a, "DL",
2267 "Cannot create a render pass with %d color attachments. Max is %d. %s",
2268 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
2269 validation_error_map[VALIDATION_ERROR_1400069a]);
2270 }
2271 }
2272 return skip;
2273}
2274
2275bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
2276 const VkCommandBuffer *pCommandBuffers) {
2277 bool skip = false;
2278 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2279 debug_report_data *report_data = device_data->report_data;
2280
2281 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2282 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2283 // validate_array()
2284 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
2285 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2286 return skip;
2287}
2288
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002289bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
2290 bool skip = false;
2291 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2292 debug_report_data *report_data = device_data->report_data;
2293 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
2294
2295 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2296 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
2297 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
2298 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
2299 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
2300
2301 if (pBeginInfo->pInheritanceInfo != NULL) {
2302 skip |=
2303 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
2304 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
2305
2306 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
2307 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
2308
2309 // TODO: This only needs to be validated when the inherited queries feature is enabled
2310 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2311 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
2312
2313 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
2314 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
2315 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
2316 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
2317 }
2318
2319 if (pInfo != NULL) {
2320 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2321 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2322 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
2323 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
2324 "inheritedQueries. %s",
2325 validation_error_map[VALIDATION_ERROR_02a00070]);
2326 }
2327 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2328 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2329 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
2330 VALIDATION_ERROR_02a00072);
2331 }
2332 }
2333
2334 return skip;
2335}
2336
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002337bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
2338 const VkViewport *pViewports) {
2339 bool skip = false;
2340 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2341
Petr Krausd55e77c2018-01-09 22:09:25 +01002342 if (!device_data->physical_device_features.multiViewport) {
2343 if (firstViewport != 0) {
2344 skip |=
2345 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2346 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000990, LayerName,
2347 "vkCmdSetViewport: The multiViewport feature is disabled, but firstViewport (=%" PRIu32 ") is not 0. %s",
Jeremy Kniager72437be2018-01-25 11:41:20 -07002348 firstViewport, validation_error_map[VALIDATION_ERROR_1e000990]);
Petr Krausd55e77c2018-01-09 22:09:25 +01002349 }
2350 if (viewportCount > 1) {
2351 skip |=
2352 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2353 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000992, LayerName,
2354 "vkCmdSetViewport: The multiViewport feature is disabled, but viewportCount (=%" PRIu32 ") is not 1. %s",
2355 viewportCount, validation_error_map[VALIDATION_ERROR_1e000992]);
2356 }
2357 } else { // multiViewport enabled
Petr Kraus7dfeed12018-02-27 20:51:20 +01002358 const uint64_t sum = static_cast<uint64_t>(firstViewport) + static_cast<uint64_t>(viewportCount);
Petr Krausd55e77c2018-01-09 22:09:25 +01002359 if (sum > device_data->device_limits.maxViewports) {
2360 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2361 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e00098e, LayerName,
2362 "vkCmdSetViewport: firstViewport + viewportCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2363 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2364 firstViewport, viewportCount, sum, device_data->device_limits.maxViewports,
2365 validation_error_map[VALIDATION_ERROR_1e00098e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002366 }
2367 }
Petr Krausb3fcdb42018-01-09 22:09:09 +01002368
2369 if (pViewports) {
2370 for (uint32_t viewport_i = 0; viewport_i < viewportCount; ++viewport_i) {
2371 const auto &viewport = pViewports[viewport_i]; // will crash on invalid ptr
2372 const char fn_name[] = "vkCmdSetViewport";
2373 const std::string param_name = "pViewports[" + std::to_string(viewport_i) + "]";
2374 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
2375 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer));
2376 }
2377 }
2378
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002379 return skip;
2380}
2381
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002382bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
2383 bool skip = false;
2384 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2385 debug_report_data *report_data = device_data->report_data;
2386
Petr Kraus6260f0a2018-02-27 21:15:55 +01002387 if (!device_data->physical_device_features.multiViewport) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002388 if (firstScissor != 0) {
Petr Kraus6260f0a2018-02-27 21:15:55 +01002389 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2390 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a2, LayerName,
2391 "vkCmdSetScissor: The multiViewport feature is disabled, but firstScissor (=%" PRIu32 ") is not 0. %s",
2392 firstScissor, validation_error_map[VALIDATION_ERROR_1d8004a2]);
2393 }
2394 if (scissorCount > 1) {
2395 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2396 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a4, LayerName,
2397 "vkCmdSetScissor: The multiViewport feature is disabled, but scissorCount (=%" PRIu32 ") is not 1. %s",
2398 scissorCount, validation_error_map[VALIDATION_ERROR_1d8004a4]);
2399 }
2400 } else { // multiViewport enabled
2401 const uint64_t sum = static_cast<uint64_t>(firstScissor) + static_cast<uint64_t>(scissorCount);
2402 if (sum > device_data->device_limits.maxViewports) {
2403 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2404 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a0, LayerName,
2405 "vkCmdSetScissor: firstScissor + scissorCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2406 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2407 firstScissor, scissorCount, sum, device_data->device_limits.maxViewports,
2408 validation_error_map[VALIDATION_ERROR_1d8004a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002409 }
2410 }
2411
Petr Kraus6260f0a2018-02-27 21:15:55 +01002412 if (pScissors) {
2413 for (uint32_t scissor_i = 0; scissor_i < scissorCount; ++scissor_i) {
2414 const auto &scissor = pScissors[scissor_i]; // will crash on invalid ptr
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002415
Petr Kraus6260f0a2018-02-27 21:15:55 +01002416 if (scissor.offset.x < 0) {
2417 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2418 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2419 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.x (=%" PRIi32 ") is negative. %s", scissor_i,
2420 scissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2421 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002422
Petr Kraus6260f0a2018-02-27 21:15:55 +01002423 if (scissor.offset.y < 0) {
2424 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2425 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2426 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.y (=%" PRIi32 ") is negative. %s", scissor_i,
2427 scissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2428 }
2429
2430 const int64_t x_sum = static_cast<int64_t>(scissor.offset.x) + static_cast<int64_t>(scissor.extent.width);
2431 if (x_sum > INT32_MAX) {
2432 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2433 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a8, LayerName,
2434 "vkCmdSetScissor: offset.x + extent.width (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2435 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2436 scissor.offset.x, scissor.extent.width, x_sum, scissor_i,
2437 validation_error_map[VALIDATION_ERROR_1d8004a8]);
2438 }
2439
2440 const int64_t y_sum = static_cast<int64_t>(scissor.offset.y) + static_cast<int64_t>(scissor.extent.height);
2441 if (y_sum > INT32_MAX) {
2442 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2443 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004aa, LayerName,
2444 "vkCmdSetScissor: offset.y + extent.height (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2445 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2446 scissor.offset.y, scissor.extent.height, y_sum, scissor_i,
2447 validation_error_map[VALIDATION_ERROR_1d8004aa]);
2448 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002449 }
2450 }
Petr Kraus6260f0a2018-02-27 21:15:55 +01002451
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002452 return skip;
2453}
2454
Petr Kraus299ba622017-11-24 03:09:03 +01002455bool pv_vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
2456 bool skip = false;
2457 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2458 debug_report_data *report_data = device_data->report_data;
2459
2460 if (!device_data->physical_device_features.wideLines && (lineWidth != 1.0f)) {
2461 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2462 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d600628, LayerName,
2463 "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0. %s", lineWidth,
2464 validation_error_map[VALIDATION_ERROR_1d600628]);
2465 }
2466
2467 return skip;
2468}
2469
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002470bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2471 uint32_t firstInstance) {
2472 bool skip = false;
2473 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2474 if (vertexCount == 0) {
2475 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
2476 // this an error or leave as is.
2477 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2478 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
2479 }
2480
2481 if (instanceCount == 0) {
2482 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2483 // this an error or leave as is.
2484 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2485 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2486 }
2487 return skip;
2488}
2489
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002490bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2491 bool skip = false;
2492 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2493
2494 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2495 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2496 __LINE__, DEVICE_FEATURE, LayerName,
2497 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2498 }
2499 return skip;
2500}
2501
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002502bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2503 uint32_t stride) {
2504 bool skip = false;
2505 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2506 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2507 skip |=
2508 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2509 DEVICE_FEATURE, LayerName,
2510 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2511 }
2512 return skip;
2513}
2514
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002515bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2516 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2517 bool skip = false;
2518 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2519
Dave Houltonf5217612018-02-02 16:18:52 -07002520 VkImageAspectFlags legal_aspect_flags =
2521 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2522 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2523 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2524 }
2525
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002526 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002527 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002528 skip |= log_msg(
2529 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2530 VALIDATION_ERROR_0a600c01, LayerName,
2531 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2532 validation_error_map[VALIDATION_ERROR_0a600c01]);
2533 }
Dave Houltonf5217612018-02-02 16:18:52 -07002534 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002535 skip |= log_msg(
2536 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2537 VALIDATION_ERROR_0a600c01, LayerName,
2538 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2539 validation_error_map[VALIDATION_ERROR_0a600c01]);
2540 }
2541 }
2542 return skip;
2543}
2544
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002545bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2546 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2547 bool skip = false;
2548 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2549
Dave Houltonf5217612018-02-02 16:18:52 -07002550 VkImageAspectFlags legal_aspect_flags =
2551 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2552 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2553 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2554 }
2555
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002556 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002557 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002558 skip |= log_msg(
2559 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2560 UNRECOGNIZED_VALUE, LayerName,
2561 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2562 }
Dave Houltonf5217612018-02-02 16:18:52 -07002563 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002564 skip |= log_msg(
2565 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2566 UNRECOGNIZED_VALUE, LayerName,
2567 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2568 }
2569 }
2570 return skip;
2571}
2572
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002573bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2574 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2575 bool skip = false;
2576 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2577
Dave Houltonf5217612018-02-02 16:18:52 -07002578 VkImageAspectFlags legal_aspect_flags =
2579 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2580 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2581 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2582 }
2583
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002584 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002585 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002586 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2587 __LINE__, UNRECOGNIZED_VALUE, LayerName,
2588 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an "
2589 "unrecognized enumerator");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002590 }
2591 }
2592 return skip;
2593}
2594
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002595bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2596 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2597 bool skip = false;
2598 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2599
Dave Houltonf5217612018-02-02 16:18:52 -07002600 VkImageAspectFlags legal_aspect_flags =
2601 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2602 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2603 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2604 }
2605
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002606 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002607 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002608 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2609 UNRECOGNIZED_VALUE, LayerName,
2610 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2611 "enumerator");
2612 }
2613 }
2614 return skip;
2615}
2616
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002617bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2618 const void *pData) {
2619 bool skip = false;
2620 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2621
2622 if (dstOffset & 3) {
2623 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2624 __LINE__, VALIDATION_ERROR_1e400048, LayerName,
2625 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2626 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2627 }
2628
2629 if ((dataSize <= 0) || (dataSize > 65536)) {
2630 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2631 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2632 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2633 "), must be greater than zero and less than or equal to 65536. %s",
2634 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2635 } else if (dataSize & 3) {
2636 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2637 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2638 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2639 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2640 }
2641 return skip;
2642}
2643
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002644bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2645 uint32_t data) {
2646 bool skip = false;
2647 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2648
2649 if (dstOffset & 3) {
2650 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2651 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2652 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2653 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2654 }
2655
2656 if (size != VK_WHOLE_SIZE) {
2657 if (size <= 0) {
2658 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2659 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2660 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2661 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2662 } else if (size & 3) {
2663 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2664 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2665 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2666 validation_error_map[VALIDATION_ERROR_1b400038]);
2667 }
2668 }
2669 return skip;
2670}
2671
2672VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2673 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2674}
2675
2676VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2677 VkLayerProperties *pProperties) {
2678 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2679}
2680
2681VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2682 VkExtensionProperties *pProperties) {
2683 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2684 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2685
2686 return VK_ERROR_LAYER_NOT_PRESENT;
2687}
2688
2689VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2690 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2691 // Parameter_validation does not have any physical device extensions
2692 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2693 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2694
2695 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2696 bool skip =
2697 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2698 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2699 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2700
2701 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2702}
2703
2704static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2705 if (!flag) {
2706 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2707 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2708 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2709 extension_name);
2710 }
2711
2712 return false;
2713}
2714
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002715bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2716 VkSwapchainKHR *pSwapchain) {
2717 bool skip = false;
2718 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2719 debug_report_data *report_data = device_data->report_data;
2720
Petr Krause5c37652018-01-05 04:05:12 +01002721 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, VK_NULL_HANDLE, LayerName,
2722 "vkCreateSwapchainKHR"};
2723
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002724 if (pCreateInfo != nullptr) {
2725 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2726 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002727 skip |=
2728 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2729 DEVICE_FEATURE, LayerName,
2730 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The textureCompressionETC2 "
2731 "feature is not enabled: neither ETC2 nor EAC formats can be used to create images.",
2732 string_VkFormat(pCreateInfo->imageFormat));
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002733 }
2734
2735 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2736 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2737 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2738 DEVICE_FEATURE, LayerName,
2739 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2740 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2741 string_VkFormat(pCreateInfo->imageFormat));
2742 }
2743
2744 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2745 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2746 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2747 DEVICE_FEATURE, LayerName,
2748 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2749 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2750 string_VkFormat(pCreateInfo->imageFormat));
2751 }
2752
2753 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2754 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2755 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2756 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2757 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2758 VALIDATION_ERROR_146009fc, LayerName,
2759 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2760 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2761 validation_error_map[VALIDATION_ERROR_146009fc]);
2762 }
2763
2764 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2765 // queueFamilyIndexCount uint32_t values
2766 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2767 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2768 VALIDATION_ERROR_146009fa, LayerName,
2769 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2770 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2771 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2772 validation_error_map[VALIDATION_ERROR_146009fa]);
2773 } else {
2774 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2775 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2776 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2777 INVALID_USAGE, false, "", "");
2778 }
2779 }
2780
Petr Krause5c37652018-01-05 04:05:12 +01002781 skip |= ValidateGreaterThanZero(pCreateInfo->imageArrayLayers, "pCreateInfo->imageArrayLayers", VALIDATION_ERROR_146009f6,
2782 log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002783 }
2784
2785 return skip;
2786}
2787
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002788bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2789 bool skip = false;
2790 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2791
2792 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002793 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2794 if (present_regions) {
2795 // TODO: This and all other pNext extension dependencies should be added to code-generation
2796 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2797 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2798 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2799 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2800 __LINE__, INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002801 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i but VkPresentRegionsKHR "
2802 "extension swapchainCount is %i. These values must be equal.",
John Zulaufde972ac2017-10-26 12:07:05 -06002803 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2804 }
2805 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2806 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2807 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2808 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2809 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2810 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2811 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002812 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2813 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2814 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002815 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002816 }
2817 }
2818
2819 return skip;
2820}
2821
2822#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002823bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2824 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2825 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2826 bool skip = false;
2827
2828 if (pCreateInfo->hwnd == nullptr) {
2829 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2830 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2831 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2832 validation_error_map[VALIDATION_ERROR_15a00a38]);
2833 }
2834
2835 return skip;
2836}
2837#endif // VK_USE_PLATFORM_WIN32_KHR
2838
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002839bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2840 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2841 if (pNameInfo->pObjectName) {
2842 device_data->report_data->debugObjectNameMap->insert(
2843 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2844 } else {
2845 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2846 }
2847 return false;
2848}
2849
Petr Krausc8655be2017-09-27 18:56:51 +02002850bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2851 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2852 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2853 bool skip = false;
2854
2855 if (pCreateInfo) {
2856 if (pCreateInfo->maxSets <= 0) {
2857 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2858 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2859 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2860 validation_error_map[VALIDATION_ERROR_0480025a]);
2861 }
2862
2863 if (pCreateInfo->pPoolSizes) {
2864 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2865 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2866 skip |= log_msg(
2867 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2868 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2869 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2870 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2871 }
2872 }
2873 }
2874 }
2875
2876 return skip;
2877}
2878
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002879bool pv_vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2880 bool skip = false;
2881 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2882
2883 if (groupCountX > device_data->device_limits.maxComputeWorkGroupCount[0]) {
2884 skip |= log_msg(
2885 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2886 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00304, LayerName,
2887 "vkCmdDispatch(): groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2888 groupCountX, device_data->device_limits.maxComputeWorkGroupCount[0], validation_error_map[VALIDATION_ERROR_19c00304]);
2889 }
2890
2891 if (groupCountY > device_data->device_limits.maxComputeWorkGroupCount[1]) {
2892 skip |= log_msg(
2893 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2894 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00306, LayerName,
2895 "vkCmdDispatch(): groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2896 groupCountY, device_data->device_limits.maxComputeWorkGroupCount[1], validation_error_map[VALIDATION_ERROR_19c00306]);
2897 }
2898
2899 if (groupCountZ > device_data->device_limits.maxComputeWorkGroupCount[2]) {
2900 skip |= log_msg(
2901 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2902 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00308, LayerName,
2903 "vkCmdDispatch(): groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2904 groupCountZ, device_data->device_limits.maxComputeWorkGroupCount[2], validation_error_map[VALIDATION_ERROR_19c00308]);
2905 }
2906
2907 return skip;
2908}
2909
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002910bool pv_vkCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002911 uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2912 bool skip = false;
2913 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2914
2915 // Paired if {} else if {} tests used to avoid any possible uint underflow
2916 uint32_t limit = device_data->device_limits.maxComputeWorkGroupCount[0];
2917 if (baseGroupX >= limit) {
2918 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2919 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034a, LayerName,
2920 "vkCmdDispatch(): baseGroupX (%" PRIu32
2921 ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2922 baseGroupX, limit, validation_error_map[VALIDATION_ERROR_19e0034a]);
2923 } else if (groupCountX > (limit - baseGroupX)) {
2924 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2925 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00350, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002926 "vkCmdDispatchBaseKHR(): baseGroupX (%" PRIu32 ") + groupCountX (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002927 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002928 baseGroupX, groupCountX, limit, validation_error_map[VALIDATION_ERROR_19e00350]);
2929 }
2930
2931 limit = device_data->device_limits.maxComputeWorkGroupCount[1];
2932 if (baseGroupY >= limit) {
2933 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2934 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034c, LayerName,
2935 "vkCmdDispatch(): baseGroupY (%" PRIu32
2936 ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2937 baseGroupY, limit, validation_error_map[VALIDATION_ERROR_19e0034c]);
2938 } else if (groupCountY > (limit - baseGroupY)) {
2939 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2940 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00352, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002941 "vkCmdDispatchBaseKHR(): baseGroupY (%" PRIu32 ") + groupCountY (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002942 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002943 baseGroupY, groupCountY, limit, validation_error_map[VALIDATION_ERROR_19e00352]);
2944 }
2945
2946 limit = device_data->device_limits.maxComputeWorkGroupCount[2];
2947 if (baseGroupZ >= limit) {
2948 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2949 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034e, LayerName,
2950 "vkCmdDispatch(): baseGroupZ (%" PRIu32
2951 ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2952 baseGroupZ, limit, validation_error_map[VALIDATION_ERROR_19e0034e]);
2953 } else if (groupCountZ > (limit - baseGroupZ)) {
2954 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2955 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00354, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002956 "vkCmdDispatchBaseKHR(): baseGroupZ (%" PRIu32 ") + groupCountZ (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002957 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002958 baseGroupZ, groupCountZ, limit, validation_error_map[VALIDATION_ERROR_19e00354]);
2959 }
2960
2961 return skip;
2962}
2963
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002964VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2965 const auto item = name_to_funcptr_map.find(funcName);
2966 if (item != name_to_funcptr_map.end()) {
2967 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2968 }
2969
2970 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2971 const auto &table = device_data->dispatch_table;
2972 if (!table.GetDeviceProcAddr) return nullptr;
2973 return table.GetDeviceProcAddr(device, funcName);
2974}
2975
2976VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2977 const auto item = name_to_funcptr_map.find(funcName);
2978 if (item != name_to_funcptr_map.end()) {
2979 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2980 }
2981
2982 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2983 auto &table = instance_data->dispatch_table;
2984 if (!table.GetInstanceProcAddr) return nullptr;
2985 return table.GetInstanceProcAddr(instance, funcName);
2986}
2987
2988VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2989 assert(instance);
2990 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2991
2992 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2993 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2994}
2995
2996// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2997// 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 +02002998void InitializeManualParameterValidationFunctionPointers() {
Dave Houltonb3bbec72018-01-17 10:13:33 -07002999 custom_functions["vkGetDeviceQueue"] = (void *)pv_vkGetDeviceQueue;
3000 custom_functions["vkCreateBuffer"] = (void *)pv_vkCreateBuffer;
3001 custom_functions["vkCreateImage"] = (void *)pv_vkCreateImage;
3002 custom_functions["vkCreateImageView"] = (void *)pv_vkCreateImageView;
3003 custom_functions["vkCreateGraphicsPipelines"] = (void *)pv_vkCreateGraphicsPipelines;
3004 custom_functions["vkCreateComputePipelines"] = (void *)pv_vkCreateComputePipelines;
3005 custom_functions["vkCreateSampler"] = (void *)pv_vkCreateSampler;
3006 custom_functions["vkCreateDescriptorSetLayout"] = (void *)pv_vkCreateDescriptorSetLayout;
3007 custom_functions["vkFreeDescriptorSets"] = (void *)pv_vkFreeDescriptorSets;
3008 custom_functions["vkUpdateDescriptorSets"] = (void *)pv_vkUpdateDescriptorSets;
3009 custom_functions["vkCreateRenderPass"] = (void *)pv_vkCreateRenderPass;
3010 custom_functions["vkBeginCommandBuffer"] = (void *)pv_vkBeginCommandBuffer;
3011 custom_functions["vkCmdSetViewport"] = (void *)pv_vkCmdSetViewport;
3012 custom_functions["vkCmdSetScissor"] = (void *)pv_vkCmdSetScissor;
Petr Kraus299ba622017-11-24 03:09:03 +01003013 custom_functions["vkCmdSetLineWidth"] = (void *)pv_vkCmdSetLineWidth;
Dave Houltonb3bbec72018-01-17 10:13:33 -07003014 custom_functions["vkCmdDraw"] = (void *)pv_vkCmdDraw;
3015 custom_functions["vkCmdDrawIndirect"] = (void *)pv_vkCmdDrawIndirect;
3016 custom_functions["vkCmdDrawIndexedIndirect"] = (void *)pv_vkCmdDrawIndexedIndirect;
3017 custom_functions["vkCmdCopyImage"] = (void *)pv_vkCmdCopyImage;
3018 custom_functions["vkCmdBlitImage"] = (void *)pv_vkCmdBlitImage;
3019 custom_functions["vkCmdCopyBufferToImage"] = (void *)pv_vkCmdCopyBufferToImage;
3020 custom_functions["vkCmdCopyImageToBuffer"] = (void *)pv_vkCmdCopyImageToBuffer;
3021 custom_functions["vkCmdUpdateBuffer"] = (void *)pv_vkCmdUpdateBuffer;
3022 custom_functions["vkCmdFillBuffer"] = (void *)pv_vkCmdFillBuffer;
3023 custom_functions["vkCreateSwapchainKHR"] = (void *)pv_vkCreateSwapchainKHR;
3024 custom_functions["vkQueuePresentKHR"] = (void *)pv_vkQueuePresentKHR;
3025 custom_functions["vkCreateDescriptorPool"] = (void *)pv_vkCreateDescriptorPool;
3026 custom_functions["vkCmdDispatch"] = (void *)pv_vkCmdDispatch;
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07003027 custom_functions["vkCmdDispatchBaseKHR"] = (void *)pv_vkCmdDispatchBaseKHR;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06003028}
3029
3030} // namespace parameter_validation
3031
3032VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
3033 VkExtensionProperties *pProperties) {
3034 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
3035}
3036
3037VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
3038 VkLayerProperties *pProperties) {
3039 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
3040}
3041
3042VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
3043 VkLayerProperties *pProperties) {
3044 // the layer command handles VK_NULL_HANDLE just fine internally
3045 assert(physicalDevice == VK_NULL_HANDLE);
3046 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
3047}
3048
3049VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
3050 const char *pLayerName, uint32_t *pCount,
3051 VkExtensionProperties *pProperties) {
3052 // the layer command handles VK_NULL_HANDLE just fine internally
3053 assert(physicalDevice == VK_NULL_HANDLE);
3054 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
3055}
3056
3057VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
3058 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
3059}
3060
3061VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
3062 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
3063}
3064
3065VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
3066 const char *funcName) {
3067 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
3068}
3069
3070VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
3071 assert(pVersionStruct != NULL);
3072 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
3073
3074 // Fill in the function pointers if our version is at least capable of having the structure contain them.
3075 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
3076 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
3077 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
3078 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
3079 }
3080
3081 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
3082 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
3083 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
3084 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
3085 }
3086
3087 return VK_SUCCESS;
3088}