blob: 69f12837ed87078fc177a12f05d7ea6e457b9373 [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;
Petr Krausaf9c1222018-03-10 02:39:47 +01001189 const bool negative_height_enabled = device_data->api_version >= VK_API_VERSION_1_1 ||
1190 device_data->extensions.vk_khr_maintenance1 ||
1191 device_data->extensions.vk_amd_negative_viewport_height;
Petr Krausb3fcdb42018-01-09 22:09:09 +01001192 const auto max_h = device_data->device_limits.maxViewportDimensions[1];
1193
1194 if (!negative_height_enabled && !(viewport.height > 0.0f)) {
1195 height_healthy = false;
1196 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd8,
1197 LayerName, "%s: %s.height (=%f) is not greater 0.0. %s", fn_name, param_name, viewport.height,
1198 validation_error_map[VALIDATION_ERROR_15000dd8]);
1199 } else if (!(f_lte_u32_exact(fabsf(viewport.height), max_h) || f_lte_u32_direct(fabsf(viewport.height), max_h))) {
1200 height_healthy = false;
1201
1202 skip |= log_msg(
1203 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dda, LayerName,
1204 "%s: Absolute value of %s.height (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32 "). %s",
1205 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1206 } else if (!f_lte_u32_exact(fabsf(viewport.height), max_h) && f_lte_u32_direct(fabsf(viewport.height), max_h)) {
1207 height_healthy = false;
1208
1209 skip |= log_msg(
1210 report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1211 "%s: Absolute value of %s.height (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32
1212 "), but it is within the static_cast<float>(maxViewportDimensions[1]) limit. %s",
1213 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1214 }
1215
1216 // x
1217 bool x_healthy = true;
1218 if (!(viewport.x >= device_data->device_limits.viewportBoundsRange[0])) {
1219 x_healthy = false;
1220 skip |=
1221 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000ddc, LayerName,
1222 "%s: %s.x (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1223 viewport.x, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000ddc]);
1224 }
1225
1226 // x + width
1227 if (x_healthy && width_healthy) {
1228 const float right_bound = viewport.x + viewport.width;
1229 if (!(right_bound <= device_data->device_limits.viewportBoundsRange[1])) {
1230 skip |= log_msg(
1231 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1232 "%s: %s.x + %s.width (=%f + %f = %f) is greater than VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1233 fn_name, param_name, param_name, viewport.x, viewport.width, right_bound,
1234 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
1235 }
1236 }
1237
1238 // y
1239 bool y_healthy = true;
1240 if (!(viewport.y >= device_data->device_limits.viewportBoundsRange[0])) {
1241 y_healthy = false;
1242 skip |=
1243 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dde, LayerName,
1244 "%s: %s.y (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1245 viewport.y, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000dde]);
1246 } else if (negative_height_enabled && !(viewport.y <= device_data->device_limits.viewportBoundsRange[1])) {
1247 y_healthy = false;
1248 skip |=
1249 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de0, LayerName,
1250 "%s: %s.y (=%f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s", fn_name, param_name,
1251 viewport.y, device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_15000de0]);
1252 }
1253
1254 // y + height
1255 if (y_healthy && height_healthy) {
1256 const float boundary = viewport.y + viewport.height;
1257
1258 if (!(boundary <= device_data->device_limits.viewportBoundsRange[1])) {
1259 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a2,
1260 LayerName,
1261 "%s: %s.y + %s.height (=%f + %f = %f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1262 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1263 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
1264 } else if (negative_height_enabled && !(boundary >= device_data->device_limits.viewportBoundsRange[0])) {
1265 skip |= log_msg(
1266 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de2, LayerName,
1267 "%s: %s.y + %s.height (=%f + %f = %f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s",
1268 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1269 device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000de2]);
1270 }
1271 }
1272
1273 if (!device_data->extensions.vk_ext_depth_range_unrestricted) {
1274 // minDepth
1275 if (!(viewport.minDepth >= 0.0) || !(viewport.minDepth <= 1.0)) {
1276 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a4,
1277 LayerName,
1278 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.minDepth (=%f) is not within the "
1279 "[0.0, 1.0] range. %s",
1280 fn_name, param_name, viewport.minDepth, validation_error_map[VALIDATION_ERROR_150009a4]);
1281 }
1282
1283 // maxDepth
1284 if (!(viewport.maxDepth >= 0.0) || !(viewport.maxDepth <= 1.0)) {
1285 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a6,
1286 LayerName,
1287 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.maxDepth (=%f) is not within the "
1288 "[0.0, 1.0] range. %s",
1289 fn_name, param_name, viewport.maxDepth, validation_error_map[VALIDATION_ERROR_150009a6]);
1290 }
1291 }
1292
1293 return skip;
1294}
1295
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001296bool pv_vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1297 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1298 VkPipeline *pPipelines) {
1299 bool skip = false;
1300 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1301 debug_report_data *report_data = device_data->report_data;
1302
1303 if (pCreateInfos != nullptr) {
1304 for (uint32_t i = 0; i < createInfoCount; ++i) {
Petr Kraus299ba622017-11-24 03:09:03 +01001305 bool has_dynamic_viewport = false;
1306 bool has_dynamic_scissor = false;
1307 bool has_dynamic_line_width = false;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001308 bool has_dynamic_viewport_w_scaling_nv = false;
1309 bool has_dynamic_discard_rectangle_ext = false;
1310 bool has_dynamic_sample_locations_ext = false;
Petr Kraus299ba622017-11-24 03:09:03 +01001311 if (pCreateInfos[i].pDynamicState != nullptr) {
1312 const auto &dynamic_state_info = *pCreateInfos[i].pDynamicState;
1313 for (uint32_t state_index = 0; state_index < dynamic_state_info.dynamicStateCount; ++state_index) {
1314 const auto &dynamic_state = dynamic_state_info.pDynamicStates[state_index];
1315 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT) has_dynamic_viewport = true;
1316 if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR) has_dynamic_scissor = true;
1317 if (dynamic_state == VK_DYNAMIC_STATE_LINE_WIDTH) has_dynamic_line_width = true;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001318 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV) has_dynamic_viewport_w_scaling_nv = true;
1319 if (dynamic_state == VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT) has_dynamic_discard_rectangle_ext = true;
1320 if (dynamic_state == VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) has_dynamic_sample_locations_ext = true;
Petr Kraus299ba622017-11-24 03:09:03 +01001321 }
1322 }
1323
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001324 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1325 if (pCreateInfos[i].pVertexInputState != nullptr) {
1326 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
1327 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
1328 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
1329 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1330 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1331 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
1332 "vkCreateGraphicsPipelines: parameter "
1333 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
1334 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1335 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
1336 validation_error_map[VALIDATION_ERROR_14c004d4]);
1337 }
1338
1339 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
1340 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1341 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
1342 "vkCreateGraphicsPipelines: parameter "
1343 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
1344 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
1345 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
1346 validation_error_map[VALIDATION_ERROR_14c004d6]);
1347 }
1348 }
1349
1350 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
1351 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
1352 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
1353 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1354 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
1355 "vkCreateGraphicsPipelines: parameter "
1356 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
1357 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
1358 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
1359 validation_error_map[VALIDATION_ERROR_14a004d8]);
1360 }
1361
1362 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1363 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1364 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
1365 "vkCreateGraphicsPipelines: parameter "
1366 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
1367 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1368 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
1369 validation_error_map[VALIDATION_ERROR_14a004da]);
1370 }
1371
1372 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
1373 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1374 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
1375 "vkCreateGraphicsPipelines: parameter "
1376 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
1377 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
1378 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
1379 validation_error_map[VALIDATION_ERROR_14a004dc]);
1380 }
1381 }
1382 }
1383
1384 if (pCreateInfos[i].pStages != nullptr) {
1385 bool has_control = false;
1386 bool has_eval = false;
1387
1388 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
1389 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1390 has_control = true;
1391 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
1392 has_eval = true;
1393 }
1394 }
1395
1396 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1397 if (has_control && has_eval) {
1398 if (pCreateInfos[i].pTessellationState == nullptr) {
1399 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1400 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
1401 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1402 "shader stage and a tessellation evaluation shader stage, "
1403 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
1404 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
1405 } else {
1406 skip |= validate_struct_pnext(
1407 report_data, "vkCreateGraphicsPipelines",
1408 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
1409 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
1410
1411 skip |= validate_reserved_flags(
1412 report_data, "vkCreateGraphicsPipelines",
1413 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1414 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1415
1416 if (pCreateInfos[i].pTessellationState->sType !=
1417 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1418 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1419 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1420 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1421 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1422 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1423 }
1424
1425 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1426 pCreateInfos[i].pTessellationState->patchControlPoints >
1427 device_data->device_limits.maxTessellationPatchSize) {
1428 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1429 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1430 "vkCreateGraphicsPipelines: invalid parameter "
1431 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1432 "should be >0 and <=%u. %s",
1433 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1434 device_data->device_limits.maxTessellationPatchSize,
1435 validation_error_map[VALIDATION_ERROR_1080097c]);
1436 }
1437 }
1438 }
1439 }
1440
1441 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1442 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1443 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1444 if (pCreateInfos[i].pViewportState == nullptr) {
Petr Krausa6103552017-11-16 21:21:58 +01001445 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1446 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1447 "vkCreateGraphicsPipelines: Rasterization is enabled (pCreateInfos[%" PRIu32
1448 "].pRasterizationState->rasterizerDiscardEnable is VK_FALSE), but pCreateInfos[%" PRIu32
1449 "].pViewportState (=NULL) is not a valid pointer. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001450 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1451 } else {
Petr Krausa6103552017-11-16 21:21:58 +01001452 const auto &viewport_state = *pCreateInfos[i].pViewportState;
1453
1454 if (viewport_state.sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1455 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1456 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b00b, LayerName,
1457 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1458 "].pViewportState->sType is not VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO. %s",
1459 i, validation_error_map[VALIDATION_ERROR_10c2b00b]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001460 }
1461
Petr Krausa6103552017-11-16 21:21:58 +01001462 const VkStructureType allowed_structs_VkPipelineViewportStateCreateInfo[] = {
1463 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
1464 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV};
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001465 skip |= validate_struct_pnext(
1466 report_data, "vkCreateGraphicsPipelines",
Petr Krausa6103552017-11-16 21:21:58 +01001467 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}),
1468 "VkPipelineViewportSwizzleStateCreateInfoNV, VkPipelineViewportWScalingStateCreateInfoNV",
1469 viewport_state.pNext, ARRAY_SIZE(allowed_structs_VkPipelineViewportStateCreateInfo),
1470 allowed_structs_VkPipelineViewportStateCreateInfo, 65, VALIDATION_ERROR_10c1c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001471
1472 skip |= validate_reserved_flags(
1473 report_data, "vkCreateGraphicsPipelines",
1474 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
Petr Krausa6103552017-11-16 21:21:58 +01001475 viewport_state.flags, VALIDATION_ERROR_10c09005);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001476
Petr Krausa6103552017-11-16 21:21:58 +01001477 if (!device_data->physical_device_features.multiViewport) {
1478 if (viewport_state.viewportCount != 1) {
1479 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1480 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1481 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1482 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32
1483 ") is not 1. %s",
1484 i, viewport_state.viewportCount, validation_error_map[VALIDATION_ERROR_10c00980]);
1485 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001486
Petr Krausa6103552017-11-16 21:21:58 +01001487 if (viewport_state.scissorCount != 1) {
1488 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1489 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1490 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1491 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->scissorCount (=%" PRIu32
1492 ") is not 1. %s",
1493 i, viewport_state.scissorCount, validation_error_map[VALIDATION_ERROR_10c00982]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001494 }
Petr Krausa6103552017-11-16 21:21:58 +01001495 } else { // multiViewport enabled
1496 if (viewport_state.viewportCount == 0) {
1497 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1498 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c30a1b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001499 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001500 "].pViewportState->viewportCount is 0. %s",
1501 i, validation_error_map[VALIDATION_ERROR_10c30a1b]);
1502 } else if (viewport_state.viewportCount > device_data->device_limits.maxViewports) {
1503 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1504 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1505 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1506 "].pViewportState->viewportCount (=%" PRIu32
1507 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1508 i, viewport_state.viewportCount, device_data->device_limits.maxViewports,
1509 validation_error_map[VALIDATION_ERROR_10c00984]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001510 }
Petr Krausa6103552017-11-16 21:21:58 +01001511
1512 if (viewport_state.scissorCount == 0) {
1513 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1514 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b61b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001515 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001516 "].pViewportState->scissorCount is 0. %s",
1517 i, validation_error_map[VALIDATION_ERROR_10c2b61b]);
1518 } else if (viewport_state.scissorCount > device_data->device_limits.maxViewports) {
1519 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1520 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1521 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1522 "].pViewportState->scissorCount (=%" PRIu32
1523 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1524 i, viewport_state.scissorCount, device_data->device_limits.maxViewports,
1525 validation_error_map[VALIDATION_ERROR_10c00986]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001526 }
1527 }
1528
Petr Krausa6103552017-11-16 21:21:58 +01001529 if (viewport_state.scissorCount != viewport_state.viewportCount) {
1530 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1531 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1532 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1533 "].pViewportState->scissorCount (=%" PRIu32 ") is not identical to pCreateInfos[%" PRIu32
1534 "].pViewportState->viewportCount (=%" PRIu32 "). %s",
1535 i, viewport_state.scissorCount, i, viewport_state.viewportCount,
1536 validation_error_map[VALIDATION_ERROR_10c00988]);
1537 }
1538
Petr Krausa6103552017-11-16 21:21:58 +01001539 if (!has_dynamic_viewport && viewport_state.viewportCount > 0 && viewport_state.pViewports == nullptr) {
1540 skip |= log_msg(
1541 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1542 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1543 "vkCreateGraphicsPipelines: The viewport state is static (pCreateInfos[%" PRIu32
1544 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001545 "].pViewportState->pViewports (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001546 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1547 }
1548
1549 if (!has_dynamic_scissor && viewport_state.scissorCount > 0 && viewport_state.pScissors == nullptr) {
1550 skip |= log_msg(
1551 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1552 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1553 "vkCreateGraphicsPipelines: The scissor state is static (pCreateInfos[%" PRIu32
1554 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_SCISSOR), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001555 "].pViewportState->pScissors (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001556 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1557 }
1558
Petr Krausb3fcdb42018-01-09 22:09:09 +01001559 // validate the VkViewports
1560 if (!has_dynamic_viewport && viewport_state.pViewports) {
1561 for (uint32_t viewport_i = 0; viewport_i < viewport_state.viewportCount; ++viewport_i) {
1562 const auto &viewport = viewport_state.pViewports[viewport_i]; // will crash on invalid ptr
1563 const char fn_name[] = "vkCreateGraphicsPipelines";
1564 const std::string param_name = "pCreateInfos[" + std::to_string(i) + "].pViewportState->pViewports[" +
1565 std::to_string(viewport_i) + "]";
1566 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
1567 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
1568 }
1569 }
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001570
1571 if (has_dynamic_viewport_w_scaling_nv && !device_data->extensions.vk_nv_clip_space_w_scaling) {
1572 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1573 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1574 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001575 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001576 "VK_NV_clip_space_w_scaling extension is not enabled.",
1577 i);
1578 }
1579
1580 if (has_dynamic_discard_rectangle_ext && !device_data->extensions.vk_ext_discard_rectangles) {
1581 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1582 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1583 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001584 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001585 "VK_EXT_discard_rectangles extension is not enabled.",
1586 i);
1587 }
1588
1589 if (has_dynamic_sample_locations_ext && !device_data->extensions.vk_ext_sample_locations) {
1590 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1591 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1592 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001593 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001594 "VK_EXT_sample_locations extension is not enabled.",
1595 i);
1596 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001597 }
1598
1599 if (pCreateInfos[i].pMultisampleState == nullptr) {
1600 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1601 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1602 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1603 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1604 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1605 } else {
Dave Houltonb3bbec72018-01-17 10:13:33 -07001606 const VkStructureType valid_next_stypes[] = {LvlTypeMap<VkPipelineCoverageModulationStateCreateInfoNV>::kSType,
1607 LvlTypeMap<VkPipelineCoverageToColorStateCreateInfoNV>::kSType,
1608 LvlTypeMap<VkPipelineSampleLocationsStateCreateInfoEXT>::kSType};
Mike Schuchardt97662b02017-12-06 13:31:29 -07001609 const char *valid_struct_names =
Dave Houltona9df0ce2018-02-07 10:51:23 -07001610 "VkPipelineCoverageModulationStateCreateInfoNV, VkPipelineCoverageToColorStateCreateInfoNV, "
John Zulauf96b0e422017-11-14 11:43:19 -07001611 "VkPipelineSampleLocationsStateCreateInfoEXT";
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001612 skip |= validate_struct_pnext(
1613 report_data, "vkCreateGraphicsPipelines",
John Zulauf96b0e422017-11-14 11:43:19 -07001614 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}),
1615 valid_struct_names, pCreateInfos[i].pMultisampleState->pNext, 3, valid_next_stypes, GeneratedHeaderVersion,
1616 VALIDATION_ERROR_1001c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001617
1618 skip |= validate_reserved_flags(
1619 report_data, "vkCreateGraphicsPipelines",
1620 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1621 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1622
1623 skip |= validate_bool32(
1624 report_data, "vkCreateGraphicsPipelines",
1625 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1626 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1627
1628 skip |= validate_array(
1629 report_data, "vkCreateGraphicsPipelines",
1630 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1631 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1632 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1633 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1634
1635 skip |= validate_bool32(
1636 report_data, "vkCreateGraphicsPipelines",
1637 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1638 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1639
1640 skip |= validate_bool32(
1641 report_data, "vkCreateGraphicsPipelines",
1642 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1643 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1644
1645 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1646 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1647 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1648 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1649 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1650 i);
1651 }
John Zulauf7acac592017-11-06 11:15:53 -07001652 if (pCreateInfos[i].pMultisampleState->sampleShadingEnable == VK_TRUE) {
1653 if (!device_data->physical_device_features.sampleRateShading) {
1654 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1655 __LINE__, VALIDATION_ERROR_10000620, LayerName,
1656 "vkCreateGraphicsPipelines(): parameter "
1657 "pCreateInfos[%d].pMultisampleState->sampleShadingEnable: %s",
1658 i, validation_error_map[VALIDATION_ERROR_10000620]);
1659 }
1660 // TODO Add documentation issue about when minSampleShading must be in range and when it is ignored
1661 // For now a "least noise" test *only* when sampleShadingEnable is VK_TRUE.
1662 if (!in_inclusive_range(pCreateInfos[i].pMultisampleState->minSampleShading, 0.F, 1.0F)) {
1663 skip |= log_msg(
1664 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1665 VALIDATION_ERROR_10000624, LayerName,
1666 "vkCreateGraphicsPipelines(): parameter pCreateInfos[%d].pMultisampleState->minSampleShading: %s",
1667 i, validation_error_map[VALIDATION_ERROR_10000624]);
1668 }
1669 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001670 }
1671
Petr Krause91f7a12017-12-14 20:57:36 +01001672 bool uses_color_attachment = false;
1673 bool uses_depthstencil_attachment = false;
1674 {
1675 const auto subpasses_uses_it = device_data->renderpasses_states.find(pCreateInfos[i].renderPass);
1676 if (subpasses_uses_it != device_data->renderpasses_states.end()) {
1677 const auto &subpasses_uses = subpasses_uses_it->second;
1678 if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[i].subpass))
1679 uses_color_attachment = true;
1680 if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[i].subpass))
1681 uses_depthstencil_attachment = true;
1682 }
1683 }
1684
1685 if (pCreateInfos[i].pDepthStencilState != nullptr && uses_depthstencil_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001686 skip |= validate_struct_pnext(
1687 report_data, "vkCreateGraphicsPipelines",
1688 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1689 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1690
1691 skip |= validate_reserved_flags(
1692 report_data, "vkCreateGraphicsPipelines",
1693 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1694 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1695
1696 skip |= validate_bool32(
1697 report_data, "vkCreateGraphicsPipelines",
1698 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1699 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1700
1701 skip |= validate_bool32(
1702 report_data, "vkCreateGraphicsPipelines",
1703 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1704 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1705
1706 skip |= validate_ranged_enum(
1707 report_data, "vkCreateGraphicsPipelines",
1708 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1709 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1710 VALIDATION_ERROR_0f604001);
1711
1712 skip |= validate_bool32(
1713 report_data, "vkCreateGraphicsPipelines",
1714 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1715 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1716
1717 skip |= validate_bool32(
1718 report_data, "vkCreateGraphicsPipelines",
1719 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1720 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1721
1722 skip |= validate_ranged_enum(
1723 report_data, "vkCreateGraphicsPipelines",
1724 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1725 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1726 VALIDATION_ERROR_13a08601);
1727
1728 skip |= validate_ranged_enum(
1729 report_data, "vkCreateGraphicsPipelines",
1730 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1731 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1732 VALIDATION_ERROR_13a27801);
1733
1734 skip |= validate_ranged_enum(
1735 report_data, "vkCreateGraphicsPipelines",
1736 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1737 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1738 VALIDATION_ERROR_13a04201);
1739
1740 skip |= validate_ranged_enum(
1741 report_data, "vkCreateGraphicsPipelines",
1742 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1743 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1744 VALIDATION_ERROR_0f604001);
1745
1746 skip |= validate_ranged_enum(
1747 report_data, "vkCreateGraphicsPipelines",
1748 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1749 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1750 VALIDATION_ERROR_13a08601);
1751
1752 skip |= validate_ranged_enum(
1753 report_data, "vkCreateGraphicsPipelines",
1754 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1755 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1756 VALIDATION_ERROR_13a27801);
1757
1758 skip |= validate_ranged_enum(
1759 report_data, "vkCreateGraphicsPipelines",
1760 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1761 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1762 VALIDATION_ERROR_13a04201);
1763
1764 skip |= validate_ranged_enum(
1765 report_data, "vkCreateGraphicsPipelines",
1766 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1767 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1768 VALIDATION_ERROR_0f604001);
1769
1770 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1771 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1772 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1773 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1774 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1775 i);
1776 }
1777 }
1778
Petr Krause91f7a12017-12-14 20:57:36 +01001779 if (pCreateInfos[i].pColorBlendState != nullptr && uses_color_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001780 skip |= validate_struct_pnext(
1781 report_data, "vkCreateGraphicsPipelines",
1782 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1783 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1784
1785 skip |= validate_reserved_flags(
1786 report_data, "vkCreateGraphicsPipelines",
1787 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1788 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1789
1790 skip |= validate_bool32(
1791 report_data, "vkCreateGraphicsPipelines",
1792 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1793 pCreateInfos[i].pColorBlendState->logicOpEnable);
1794
1795 skip |= validate_array(
1796 report_data, "vkCreateGraphicsPipelines",
1797 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1798 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1799 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1800 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1801
1802 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1803 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1804 ++attachmentIndex) {
1805 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1806 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1807 ParameterName::IndexVector{i, attachmentIndex}),
1808 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1809
1810 skip |= validate_ranged_enum(
1811 report_data, "vkCreateGraphicsPipelines",
1812 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1813 ParameterName::IndexVector{i, attachmentIndex}),
1814 "VkBlendFactor", AllVkBlendFactorEnums,
1815 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1816 VALIDATION_ERROR_0f22cc01);
1817
1818 skip |= validate_ranged_enum(
1819 report_data, "vkCreateGraphicsPipelines",
1820 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1821 ParameterName::IndexVector{i, attachmentIndex}),
1822 "VkBlendFactor", AllVkBlendFactorEnums,
1823 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1824 VALIDATION_ERROR_0f207001);
1825
1826 skip |= validate_ranged_enum(
1827 report_data, "vkCreateGraphicsPipelines",
1828 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1829 ParameterName::IndexVector{i, attachmentIndex}),
1830 "VkBlendOp", AllVkBlendOpEnums,
1831 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1832 VALIDATION_ERROR_0f202001);
1833
1834 skip |= validate_ranged_enum(
1835 report_data, "vkCreateGraphicsPipelines",
1836 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1837 ParameterName::IndexVector{i, attachmentIndex}),
1838 "VkBlendFactor", AllVkBlendFactorEnums,
1839 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1840 VALIDATION_ERROR_0f22c601);
1841
1842 skip |= validate_ranged_enum(
1843 report_data, "vkCreateGraphicsPipelines",
1844 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1845 ParameterName::IndexVector{i, attachmentIndex}),
1846 "VkBlendFactor", AllVkBlendFactorEnums,
1847 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1848 VALIDATION_ERROR_0f206a01);
1849
1850 skip |= validate_ranged_enum(
1851 report_data, "vkCreateGraphicsPipelines",
1852 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1853 ParameterName::IndexVector{i, attachmentIndex}),
1854 "VkBlendOp", AllVkBlendOpEnums,
1855 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1856 VALIDATION_ERROR_0f200801);
1857
1858 skip |=
1859 validate_flags(report_data, "vkCreateGraphicsPipelines",
1860 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1861 ParameterName::IndexVector{i, attachmentIndex}),
1862 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1863 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1864 false, false, VALIDATION_ERROR_0f202201);
1865 }
1866 }
1867
1868 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1869 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1870 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1871 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1872 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1873 i);
1874 }
1875
1876 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1877 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1878 skip |= validate_ranged_enum(
1879 report_data, "vkCreateGraphicsPipelines",
1880 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1881 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1882 }
1883 }
1884 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001885
Petr Kraus9752aae2017-11-24 03:05:50 +01001886 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1887 if (pCreateInfos[i].basePipelineIndex != -1) {
1888 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001889 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1890 __LINE__, VALIDATION_ERROR_096005a8, LayerName,
1891 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be "
1892 "VK_NULL_HANDLE if pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag "
1893 "and pCreateInfos->basePipelineIndex is not -1. %s",
1894 validation_error_map[VALIDATION_ERROR_096005a8]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001895 }
1896 }
1897
Petr Kraus9752aae2017-11-24 03:05:50 +01001898 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
1899 if (pCreateInfos[i].basePipelineIndex != -1) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001900 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1901 __LINE__, VALIDATION_ERROR_096005aa, LayerName,
1902 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1903 "pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and "
1904 "pCreateInfos->basePipelineHandle is not VK_NULL_HANDLE. %s",
1905 validation_error_map[VALIDATION_ERROR_096005aa]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001906 }
1907 }
1908 }
1909
Petr Kraus9752aae2017-11-24 03:05:50 +01001910 if (pCreateInfos[i].pRasterizationState) {
1911 if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001912 (device_data->physical_device_features.fillModeNonSolid == false)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001913 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1914 __LINE__, DEVICE_FEATURE, LayerName,
1915 "vkCreateGraphicsPipelines parameter, VkPolygonMode "
1916 "pCreateInfos->pRasterizationState->polygonMode cannot be VK_POLYGON_MODE_POINT or "
1917 "VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001918 }
Petr Kraus299ba622017-11-24 03:09:03 +01001919
1920 if (!has_dynamic_line_width && !device_data->physical_device_features.wideLines &&
1921 (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
1922 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1923 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, 0, __LINE__, VALIDATION_ERROR_096005da, LayerName,
1924 "The line width state is static (pCreateInfos[%" PRIu32
1925 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
1926 "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
1927 "].pRasterizationState->lineWidth (=%f) is not 1.0. %s",
1928 i, i, pCreateInfos[i].pRasterizationState->lineWidth,
1929 validation_error_map[VALIDATION_ERROR_096005da]);
1930 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001931 }
1932
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001933 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1934 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1935 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1936 pCreateInfos[i].pStages[j].pName);
1937 }
1938 }
1939 }
1940
1941 return skip;
1942}
1943
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001944bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1945 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1946 VkPipeline *pPipelines) {
1947 bool skip = false;
1948 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1949
1950 for (uint32_t i = 0; i < createInfoCount; i++) {
1951 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1952 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1953 pCreateInfos[i].stage.pName);
1954 }
1955
1956 return skip;
1957}
1958
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001959bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1960 VkSampler *pSampler) {
1961 bool skip = false;
1962 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1963 debug_report_data *report_data = device_data->report_data;
1964
1965 if (pCreateInfo != nullptr) {
John Zulauf71968502017-10-26 13:51:15 -06001966 const auto &features = device_data->physical_device_features;
1967 const auto &limits = device_data->device_limits;
1968 if (pCreateInfo->anisotropyEnable == VK_TRUE) {
1969 if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
1970 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1971 VALIDATION_ERROR_1260085e, LayerName,
1972 "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found. %s",
1973 "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
1974 "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy,
1975 validation_error_map[VALIDATION_ERROR_1260085e]);
1976 }
1977
1978 // Anistropy cannot be enabled in sampler unless enabled as a feature
1979 if (features.samplerAnisotropy == VK_FALSE) {
1980 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1981 VALIDATION_ERROR_1260085c, LayerName,
1982 "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE. %s",
1983 "pCreateInfo->anisotropyEnable", validation_error_map[VALIDATION_ERROR_1260085c]);
1984 }
1985
1986 // Anistropy and unnormalized coordinates cannot be enabled simultaneously
1987 if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
1988 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1989 VALIDATION_ERROR_12600868, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001990 "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates must "
1991 "not both be VK_TRUE. %s",
John Zulauf71968502017-10-26 13:51:15 -06001992 validation_error_map[VALIDATION_ERROR_12600868]);
1993 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001994 }
1995
1996 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1997 if (pCreateInfo->compareEnable == VK_TRUE) {
1998 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1999 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
2000 }
2001
2002 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
2003 // valid VkBorderColor value
2004 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2005 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2006 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
2007 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
2008 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
2009 }
2010
2011 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
2012 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
2013 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
2014 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2015 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2016 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
2017 skip |=
2018 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2019 VALIDATION_ERROR_1260086e, LayerName,
2020 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
2021 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
2022 validation_error_map[VALIDATION_ERROR_1260086e]);
2023 }
John Zulauf275805c2017-10-26 15:34:49 -06002024
2025 // Checks for the IMG cubic filtering extension
2026 if (device_data->extensions.vk_img_filter_cubic) {
2027 if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
2028 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002029 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2030 VALIDATION_ERROR_12600872, LayerName,
2031 "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter "
2032 "are VK_FILTER_CUBIC_IMG. %s",
2033 validation_error_map[VALIDATION_ERROR_12600872]);
John Zulauf275805c2017-10-26 15:34:49 -06002034 }
2035 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002036 }
2037
2038 return skip;
2039}
2040
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002041bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2042 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
2043 bool skip = false;
2044 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2045 debug_report_data *report_data = device_data->report_data;
2046
2047 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2048 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
2049 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
2050 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
2051 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
2052 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
2053 // valid VkSampler handles
2054 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2055 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
2056 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
2057 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
2058 ++descriptor_index) {
2059 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
2060 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2061 __LINE__, REQUIRED_PARAMETER, LayerName,
2062 "vkCreateDescriptorSetLayout: required parameter "
Dave Houltona9df0ce2018-02-07 10:51:23 -07002063 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d] specified as VK_NULL_HANDLE",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002064 i, descriptor_index);
2065 }
2066 }
2067 }
2068
2069 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
2070 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
2071 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002072 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2073 __LINE__, VALIDATION_ERROR_04e00236, LayerName,
2074 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
2075 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits "
2076 "values. %s",
2077 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002078 }
2079 }
2080 }
2081 }
2082
2083 return skip;
2084}
2085
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002086bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
2087 const VkDescriptorSet *pDescriptorSets) {
2088 bool skip = false;
2089 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2090 debug_report_data *report_data = device_data->report_data;
2091
2092 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2093 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2094 // validate_array()
2095 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
2096 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2097 return skip;
2098}
2099
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002100bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
2101 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
2102 bool skip = false;
2103 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2104 debug_report_data *report_data = device_data->report_data;
2105
2106 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2107 if (pDescriptorWrites != NULL) {
2108 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
2109 // descriptorCount must be greater than 0
2110 if (pDescriptorWrites[i].descriptorCount == 0) {
2111 skip |=
2112 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2113 VALIDATION_ERROR_15c0441b, LayerName,
2114 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
2115 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
2116 }
2117
2118 // dstSet must be a valid VkDescriptorSet handle
2119 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2120 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
2121 pDescriptorWrites[i].dstSet);
2122
2123 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2124 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
2125 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
2126 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
2127 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
2128 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
2129 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2130 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
2131 if (pDescriptorWrites[i].pImageInfo == nullptr) {
2132 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2133 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
2134 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2135 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
2136 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
2137 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
2138 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
2139 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
2140 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
2141 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
2142 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
2143 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2144 ++descriptor_index) {
2145 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2146 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
2147 ParameterName::IndexVector{i, descriptor_index}),
2148 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
2149 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
2150 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
2151 ParameterName::IndexVector{i, descriptor_index}),
2152 "VkImageLayout", AllVkImageLayoutEnums,
2153 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
2154 VALIDATION_ERROR_UNDEFINED);
2155 }
2156 }
2157 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2158 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2159 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
2160 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2161 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
2162 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
2163 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
2164 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
2165 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2166 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
2167 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2168 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
2169 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
2170 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
2171 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
2172 } else {
2173 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
2174 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2175 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
2176 ParameterName::IndexVector{i, descriptorIndex}),
2177 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
2178 }
2179 }
2180 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
2181 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
2182 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
2183 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
2184 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
2185 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2186 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
2187 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2188 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
2189 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
2190 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
2191 } else {
2192 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2193 ++descriptor_index) {
2194 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2195 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
2196 ParameterName::IndexVector{i, descriptor_index}),
2197 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
2198 }
2199 }
2200 }
2201
2202 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2203 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
2204 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
2205 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2206 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2207 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
2208 skip |= log_msg(
2209 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2210 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
2211 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2212 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2213 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
2214 validation_error_map[VALIDATION_ERROR_15c0028e]);
2215 }
2216 }
2217 }
2218 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2219 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2220 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
2221 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2222 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2223 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
2224 skip |= log_msg(
2225 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2226 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
2227 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2228 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2229 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
2230 validation_error_map[VALIDATION_ERROR_15c00290]);
2231 }
2232 }
2233 }
2234 }
2235 }
2236 }
2237 return skip;
2238}
2239
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002240bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2241 VkRenderPass *pRenderPass) {
2242 bool skip = false;
2243 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2244 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
2245
2246 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
2247 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
2248 std::stringstream ss;
2249 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
2250 << validation_error_map[VALIDATION_ERROR_00809201];
2251 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2252 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
2253 }
2254 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
2255 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
2256 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2257 __LINE__, VALIDATION_ERROR_00800696, "DL",
2258 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
2259 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
2260 i, validation_error_map[VALIDATION_ERROR_00800696]);
2261 }
2262 }
2263
2264 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2265 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
2266 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2267 __LINE__, VALIDATION_ERROR_1400069a, "DL",
2268 "Cannot create a render pass with %d color attachments. Max is %d. %s",
2269 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
2270 validation_error_map[VALIDATION_ERROR_1400069a]);
2271 }
2272 }
2273 return skip;
2274}
2275
2276bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
2277 const VkCommandBuffer *pCommandBuffers) {
2278 bool skip = false;
2279 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2280 debug_report_data *report_data = device_data->report_data;
2281
2282 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2283 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2284 // validate_array()
2285 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
2286 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2287 return skip;
2288}
2289
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002290bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
2291 bool skip = false;
2292 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2293 debug_report_data *report_data = device_data->report_data;
2294 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
2295
2296 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2297 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
2298 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
2299 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
2300 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
2301
2302 if (pBeginInfo->pInheritanceInfo != NULL) {
2303 skip |=
2304 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
2305 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
2306
2307 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
2308 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
2309
2310 // TODO: This only needs to be validated when the inherited queries feature is enabled
2311 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2312 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
2313
2314 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
2315 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
2316 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
2317 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
2318 }
2319
2320 if (pInfo != NULL) {
2321 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2322 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2323 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
2324 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
2325 "inheritedQueries. %s",
2326 validation_error_map[VALIDATION_ERROR_02a00070]);
2327 }
2328 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2329 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2330 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
2331 VALIDATION_ERROR_02a00072);
2332 }
2333 }
2334
2335 return skip;
2336}
2337
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002338bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
2339 const VkViewport *pViewports) {
2340 bool skip = false;
2341 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2342
Petr Krausd55e77c2018-01-09 22:09:25 +01002343 if (!device_data->physical_device_features.multiViewport) {
2344 if (firstViewport != 0) {
2345 skip |=
2346 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2347 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000990, LayerName,
2348 "vkCmdSetViewport: The multiViewport feature is disabled, but firstViewport (=%" PRIu32 ") is not 0. %s",
Jeremy Kniager72437be2018-01-25 11:41:20 -07002349 firstViewport, validation_error_map[VALIDATION_ERROR_1e000990]);
Petr Krausd55e77c2018-01-09 22:09:25 +01002350 }
2351 if (viewportCount > 1) {
2352 skip |=
2353 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2354 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000992, LayerName,
2355 "vkCmdSetViewport: The multiViewport feature is disabled, but viewportCount (=%" PRIu32 ") is not 1. %s",
2356 viewportCount, validation_error_map[VALIDATION_ERROR_1e000992]);
2357 }
2358 } else { // multiViewport enabled
Petr Kraus7dfeed12018-02-27 20:51:20 +01002359 const uint64_t sum = static_cast<uint64_t>(firstViewport) + static_cast<uint64_t>(viewportCount);
Petr Krausd55e77c2018-01-09 22:09:25 +01002360 if (sum > device_data->device_limits.maxViewports) {
2361 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2362 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e00098e, LayerName,
2363 "vkCmdSetViewport: firstViewport + viewportCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2364 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2365 firstViewport, viewportCount, sum, device_data->device_limits.maxViewports,
2366 validation_error_map[VALIDATION_ERROR_1e00098e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002367 }
2368 }
Petr Krausb3fcdb42018-01-09 22:09:09 +01002369
2370 if (pViewports) {
2371 for (uint32_t viewport_i = 0; viewport_i < viewportCount; ++viewport_i) {
2372 const auto &viewport = pViewports[viewport_i]; // will crash on invalid ptr
2373 const char fn_name[] = "vkCmdSetViewport";
2374 const std::string param_name = "pViewports[" + std::to_string(viewport_i) + "]";
2375 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
2376 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer));
2377 }
2378 }
2379
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002380 return skip;
2381}
2382
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002383bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
2384 bool skip = false;
2385 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2386 debug_report_data *report_data = device_data->report_data;
2387
Petr Kraus6260f0a2018-02-27 21:15:55 +01002388 if (!device_data->physical_device_features.multiViewport) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002389 if (firstScissor != 0) {
Petr Kraus6260f0a2018-02-27 21:15:55 +01002390 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2391 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a2, LayerName,
2392 "vkCmdSetScissor: The multiViewport feature is disabled, but firstScissor (=%" PRIu32 ") is not 0. %s",
2393 firstScissor, validation_error_map[VALIDATION_ERROR_1d8004a2]);
2394 }
2395 if (scissorCount > 1) {
2396 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2397 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a4, LayerName,
2398 "vkCmdSetScissor: The multiViewport feature is disabled, but scissorCount (=%" PRIu32 ") is not 1. %s",
2399 scissorCount, validation_error_map[VALIDATION_ERROR_1d8004a4]);
2400 }
2401 } else { // multiViewport enabled
2402 const uint64_t sum = static_cast<uint64_t>(firstScissor) + static_cast<uint64_t>(scissorCount);
2403 if (sum > device_data->device_limits.maxViewports) {
2404 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2405 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a0, LayerName,
2406 "vkCmdSetScissor: firstScissor + scissorCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2407 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2408 firstScissor, scissorCount, sum, device_data->device_limits.maxViewports,
2409 validation_error_map[VALIDATION_ERROR_1d8004a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002410 }
2411 }
2412
Petr Kraus6260f0a2018-02-27 21:15:55 +01002413 if (pScissors) {
2414 for (uint32_t scissor_i = 0; scissor_i < scissorCount; ++scissor_i) {
2415 const auto &scissor = pScissors[scissor_i]; // will crash on invalid ptr
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002416
Petr Kraus6260f0a2018-02-27 21:15:55 +01002417 if (scissor.offset.x < 0) {
2418 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2419 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2420 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.x (=%" PRIi32 ") is negative. %s", scissor_i,
2421 scissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2422 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002423
Petr Kraus6260f0a2018-02-27 21:15:55 +01002424 if (scissor.offset.y < 0) {
2425 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2426 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2427 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.y (=%" PRIi32 ") is negative. %s", scissor_i,
2428 scissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2429 }
2430
2431 const int64_t x_sum = static_cast<int64_t>(scissor.offset.x) + static_cast<int64_t>(scissor.extent.width);
2432 if (x_sum > INT32_MAX) {
2433 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2434 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a8, LayerName,
2435 "vkCmdSetScissor: offset.x + extent.width (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2436 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2437 scissor.offset.x, scissor.extent.width, x_sum, scissor_i,
2438 validation_error_map[VALIDATION_ERROR_1d8004a8]);
2439 }
2440
2441 const int64_t y_sum = static_cast<int64_t>(scissor.offset.y) + static_cast<int64_t>(scissor.extent.height);
2442 if (y_sum > INT32_MAX) {
2443 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2444 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004aa, LayerName,
2445 "vkCmdSetScissor: offset.y + extent.height (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2446 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2447 scissor.offset.y, scissor.extent.height, y_sum, scissor_i,
2448 validation_error_map[VALIDATION_ERROR_1d8004aa]);
2449 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002450 }
2451 }
Petr Kraus6260f0a2018-02-27 21:15:55 +01002452
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002453 return skip;
2454}
2455
Petr Kraus299ba622017-11-24 03:09:03 +01002456bool pv_vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
2457 bool skip = false;
2458 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2459 debug_report_data *report_data = device_data->report_data;
2460
2461 if (!device_data->physical_device_features.wideLines && (lineWidth != 1.0f)) {
2462 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2463 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d600628, LayerName,
2464 "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0. %s", lineWidth,
2465 validation_error_map[VALIDATION_ERROR_1d600628]);
2466 }
2467
2468 return skip;
2469}
2470
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002471bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2472 uint32_t firstInstance) {
2473 bool skip = false;
2474 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2475 if (vertexCount == 0) {
2476 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
2477 // this an error or leave as is.
2478 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2479 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
2480 }
2481
2482 if (instanceCount == 0) {
2483 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2484 // this an error or leave as is.
2485 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2486 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2487 }
2488 return skip;
2489}
2490
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002491bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2492 bool skip = false;
2493 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2494
2495 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2496 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2497 __LINE__, DEVICE_FEATURE, LayerName,
2498 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2499 }
2500 return skip;
2501}
2502
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002503bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2504 uint32_t stride) {
2505 bool skip = false;
2506 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2507 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2508 skip |=
2509 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2510 DEVICE_FEATURE, LayerName,
2511 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2512 }
2513 return skip;
2514}
2515
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002516bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2517 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2518 bool skip = false;
2519 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2520
Dave Houltonf5217612018-02-02 16:18:52 -07002521 VkImageAspectFlags legal_aspect_flags =
2522 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2523 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2524 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2525 }
2526
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002527 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002528 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002529 skip |= log_msg(
2530 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2531 VALIDATION_ERROR_0a600c01, LayerName,
2532 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2533 validation_error_map[VALIDATION_ERROR_0a600c01]);
2534 }
Dave Houltonf5217612018-02-02 16:18:52 -07002535 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002536 skip |= log_msg(
2537 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2538 VALIDATION_ERROR_0a600c01, LayerName,
2539 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2540 validation_error_map[VALIDATION_ERROR_0a600c01]);
2541 }
2542 }
2543 return skip;
2544}
2545
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002546bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2547 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2548 bool skip = false;
2549 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2550
Dave Houltonf5217612018-02-02 16:18:52 -07002551 VkImageAspectFlags legal_aspect_flags =
2552 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2553 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2554 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2555 }
2556
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002557 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002558 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002559 skip |= log_msg(
2560 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2561 UNRECOGNIZED_VALUE, LayerName,
2562 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2563 }
Dave Houltonf5217612018-02-02 16:18:52 -07002564 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002565 skip |= log_msg(
2566 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2567 UNRECOGNIZED_VALUE, LayerName,
2568 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2569 }
2570 }
2571 return skip;
2572}
2573
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002574bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2575 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2576 bool skip = false;
2577 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2578
Dave Houltonf5217612018-02-02 16:18:52 -07002579 VkImageAspectFlags legal_aspect_flags =
2580 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2581 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2582 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2583 }
2584
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002585 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002586 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002587 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2588 __LINE__, UNRECOGNIZED_VALUE, LayerName,
2589 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an "
2590 "unrecognized enumerator");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002591 }
2592 }
2593 return skip;
2594}
2595
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002596bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2597 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2598 bool skip = false;
2599 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2600
Dave Houltonf5217612018-02-02 16:18:52 -07002601 VkImageAspectFlags legal_aspect_flags =
2602 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2603 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2604 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2605 }
2606
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002607 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002608 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002609 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2610 UNRECOGNIZED_VALUE, LayerName,
2611 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2612 "enumerator");
2613 }
2614 }
2615 return skip;
2616}
2617
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002618bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2619 const void *pData) {
2620 bool skip = false;
2621 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2622
2623 if (dstOffset & 3) {
2624 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2625 __LINE__, VALIDATION_ERROR_1e400048, LayerName,
2626 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2627 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2628 }
2629
2630 if ((dataSize <= 0) || (dataSize > 65536)) {
2631 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2632 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2633 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2634 "), must be greater than zero and less than or equal to 65536. %s",
2635 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2636 } else if (dataSize & 3) {
2637 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2638 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2639 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2640 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2641 }
2642 return skip;
2643}
2644
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002645bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2646 uint32_t data) {
2647 bool skip = false;
2648 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2649
2650 if (dstOffset & 3) {
2651 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2652 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2653 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2654 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2655 }
2656
2657 if (size != VK_WHOLE_SIZE) {
2658 if (size <= 0) {
2659 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2660 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2661 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2662 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2663 } else if (size & 3) {
2664 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2665 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2666 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2667 validation_error_map[VALIDATION_ERROR_1b400038]);
2668 }
2669 }
2670 return skip;
2671}
2672
2673VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2674 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2675}
2676
2677VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2678 VkLayerProperties *pProperties) {
2679 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2680}
2681
2682VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2683 VkExtensionProperties *pProperties) {
2684 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2685 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2686
2687 return VK_ERROR_LAYER_NOT_PRESENT;
2688}
2689
2690VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2691 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2692 // Parameter_validation does not have any physical device extensions
2693 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2694 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2695
2696 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2697 bool skip =
2698 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2699 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2700 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2701
2702 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2703}
2704
2705static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2706 if (!flag) {
2707 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2708 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2709 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2710 extension_name);
2711 }
2712
2713 return false;
2714}
2715
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002716bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2717 VkSwapchainKHR *pSwapchain) {
2718 bool skip = false;
2719 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2720 debug_report_data *report_data = device_data->report_data;
2721
Petr Krause5c37652018-01-05 04:05:12 +01002722 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, VK_NULL_HANDLE, LayerName,
2723 "vkCreateSwapchainKHR"};
2724
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002725 if (pCreateInfo != nullptr) {
2726 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2727 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002728 skip |=
2729 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2730 DEVICE_FEATURE, LayerName,
2731 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The textureCompressionETC2 "
2732 "feature is not enabled: neither ETC2 nor EAC formats can be used to create images.",
2733 string_VkFormat(pCreateInfo->imageFormat));
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002734 }
2735
2736 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2737 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2738 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2739 DEVICE_FEATURE, LayerName,
2740 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2741 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2742 string_VkFormat(pCreateInfo->imageFormat));
2743 }
2744
2745 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2746 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2747 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2748 DEVICE_FEATURE, LayerName,
2749 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2750 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2751 string_VkFormat(pCreateInfo->imageFormat));
2752 }
2753
2754 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2755 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2756 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2757 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2758 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2759 VALIDATION_ERROR_146009fc, LayerName,
2760 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2761 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2762 validation_error_map[VALIDATION_ERROR_146009fc]);
2763 }
2764
2765 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2766 // queueFamilyIndexCount uint32_t values
2767 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2768 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2769 VALIDATION_ERROR_146009fa, LayerName,
2770 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2771 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2772 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2773 validation_error_map[VALIDATION_ERROR_146009fa]);
2774 } else {
2775 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2776 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2777 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2778 INVALID_USAGE, false, "", "");
2779 }
2780 }
2781
Petr Krause5c37652018-01-05 04:05:12 +01002782 skip |= ValidateGreaterThanZero(pCreateInfo->imageArrayLayers, "pCreateInfo->imageArrayLayers", VALIDATION_ERROR_146009f6,
2783 log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002784 }
2785
2786 return skip;
2787}
2788
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002789bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2790 bool skip = false;
2791 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2792
2793 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002794 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2795 if (present_regions) {
2796 // TODO: This and all other pNext extension dependencies should be added to code-generation
2797 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2798 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2799 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2800 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2801 __LINE__, INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002802 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i but VkPresentRegionsKHR "
2803 "extension swapchainCount is %i. These values must be equal.",
John Zulaufde972ac2017-10-26 12:07:05 -06002804 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2805 }
2806 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2807 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2808 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2809 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2810 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2811 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2812 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002813 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2814 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2815 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002816 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002817 }
2818 }
2819
2820 return skip;
2821}
2822
2823#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002824bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2825 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2826 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2827 bool skip = false;
2828
2829 if (pCreateInfo->hwnd == nullptr) {
2830 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2831 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2832 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2833 validation_error_map[VALIDATION_ERROR_15a00a38]);
2834 }
2835
2836 return skip;
2837}
2838#endif // VK_USE_PLATFORM_WIN32_KHR
2839
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002840bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2841 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2842 if (pNameInfo->pObjectName) {
2843 device_data->report_data->debugObjectNameMap->insert(
2844 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2845 } else {
2846 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2847 }
2848 return false;
2849}
2850
Petr Krausc8655be2017-09-27 18:56:51 +02002851bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2852 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2853 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2854 bool skip = false;
2855
2856 if (pCreateInfo) {
2857 if (pCreateInfo->maxSets <= 0) {
2858 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2859 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2860 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2861 validation_error_map[VALIDATION_ERROR_0480025a]);
2862 }
2863
2864 if (pCreateInfo->pPoolSizes) {
2865 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2866 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2867 skip |= log_msg(
2868 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2869 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2870 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2871 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2872 }
2873 }
2874 }
2875 }
2876
2877 return skip;
2878}
2879
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002880bool pv_vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2881 bool skip = false;
2882 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2883
2884 if (groupCountX > device_data->device_limits.maxComputeWorkGroupCount[0]) {
2885 skip |= log_msg(
2886 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2887 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00304, LayerName,
2888 "vkCmdDispatch(): groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2889 groupCountX, device_data->device_limits.maxComputeWorkGroupCount[0], validation_error_map[VALIDATION_ERROR_19c00304]);
2890 }
2891
2892 if (groupCountY > device_data->device_limits.maxComputeWorkGroupCount[1]) {
2893 skip |= log_msg(
2894 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2895 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00306, LayerName,
2896 "vkCmdDispatch(): groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2897 groupCountY, device_data->device_limits.maxComputeWorkGroupCount[1], validation_error_map[VALIDATION_ERROR_19c00306]);
2898 }
2899
2900 if (groupCountZ > device_data->device_limits.maxComputeWorkGroupCount[2]) {
2901 skip |= log_msg(
2902 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2903 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00308, LayerName,
2904 "vkCmdDispatch(): groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2905 groupCountZ, device_data->device_limits.maxComputeWorkGroupCount[2], validation_error_map[VALIDATION_ERROR_19c00308]);
2906 }
2907
2908 return skip;
2909}
2910
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002911bool pv_vkCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002912 uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2913 bool skip = false;
2914 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2915
2916 // Paired if {} else if {} tests used to avoid any possible uint underflow
2917 uint32_t limit = device_data->device_limits.maxComputeWorkGroupCount[0];
2918 if (baseGroupX >= limit) {
2919 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2920 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034a, LayerName,
2921 "vkCmdDispatch(): baseGroupX (%" PRIu32
2922 ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2923 baseGroupX, limit, validation_error_map[VALIDATION_ERROR_19e0034a]);
2924 } else if (groupCountX > (limit - baseGroupX)) {
2925 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2926 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00350, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002927 "vkCmdDispatchBaseKHR(): baseGroupX (%" PRIu32 ") + groupCountX (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002928 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002929 baseGroupX, groupCountX, limit, validation_error_map[VALIDATION_ERROR_19e00350]);
2930 }
2931
2932 limit = device_data->device_limits.maxComputeWorkGroupCount[1];
2933 if (baseGroupY >= limit) {
2934 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2935 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034c, LayerName,
2936 "vkCmdDispatch(): baseGroupY (%" PRIu32
2937 ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2938 baseGroupY, limit, validation_error_map[VALIDATION_ERROR_19e0034c]);
2939 } else if (groupCountY > (limit - baseGroupY)) {
2940 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2941 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00352, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002942 "vkCmdDispatchBaseKHR(): baseGroupY (%" PRIu32 ") + groupCountY (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002943 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002944 baseGroupY, groupCountY, limit, validation_error_map[VALIDATION_ERROR_19e00352]);
2945 }
2946
2947 limit = device_data->device_limits.maxComputeWorkGroupCount[2];
2948 if (baseGroupZ >= limit) {
2949 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2950 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034e, LayerName,
2951 "vkCmdDispatch(): baseGroupZ (%" PRIu32
2952 ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2953 baseGroupZ, limit, validation_error_map[VALIDATION_ERROR_19e0034e]);
2954 } else if (groupCountZ > (limit - baseGroupZ)) {
2955 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2956 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00354, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002957 "vkCmdDispatchBaseKHR(): baseGroupZ (%" PRIu32 ") + groupCountZ (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002958 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002959 baseGroupZ, groupCountZ, limit, validation_error_map[VALIDATION_ERROR_19e00354]);
2960 }
2961
2962 return skip;
2963}
2964
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002965VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2966 const auto item = name_to_funcptr_map.find(funcName);
2967 if (item != name_to_funcptr_map.end()) {
2968 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2969 }
2970
2971 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2972 const auto &table = device_data->dispatch_table;
2973 if (!table.GetDeviceProcAddr) return nullptr;
2974 return table.GetDeviceProcAddr(device, funcName);
2975}
2976
2977VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2978 const auto item = name_to_funcptr_map.find(funcName);
2979 if (item != name_to_funcptr_map.end()) {
2980 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2981 }
2982
2983 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2984 auto &table = instance_data->dispatch_table;
2985 if (!table.GetInstanceProcAddr) return nullptr;
2986 return table.GetInstanceProcAddr(instance, funcName);
2987}
2988
2989VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2990 assert(instance);
2991 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2992
2993 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2994 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2995}
2996
2997// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2998// 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 +02002999void InitializeManualParameterValidationFunctionPointers() {
Dave Houltonb3bbec72018-01-17 10:13:33 -07003000 custom_functions["vkGetDeviceQueue"] = (void *)pv_vkGetDeviceQueue;
3001 custom_functions["vkCreateBuffer"] = (void *)pv_vkCreateBuffer;
3002 custom_functions["vkCreateImage"] = (void *)pv_vkCreateImage;
3003 custom_functions["vkCreateImageView"] = (void *)pv_vkCreateImageView;
3004 custom_functions["vkCreateGraphicsPipelines"] = (void *)pv_vkCreateGraphicsPipelines;
3005 custom_functions["vkCreateComputePipelines"] = (void *)pv_vkCreateComputePipelines;
3006 custom_functions["vkCreateSampler"] = (void *)pv_vkCreateSampler;
3007 custom_functions["vkCreateDescriptorSetLayout"] = (void *)pv_vkCreateDescriptorSetLayout;
3008 custom_functions["vkFreeDescriptorSets"] = (void *)pv_vkFreeDescriptorSets;
3009 custom_functions["vkUpdateDescriptorSets"] = (void *)pv_vkUpdateDescriptorSets;
3010 custom_functions["vkCreateRenderPass"] = (void *)pv_vkCreateRenderPass;
3011 custom_functions["vkBeginCommandBuffer"] = (void *)pv_vkBeginCommandBuffer;
3012 custom_functions["vkCmdSetViewport"] = (void *)pv_vkCmdSetViewport;
3013 custom_functions["vkCmdSetScissor"] = (void *)pv_vkCmdSetScissor;
Petr Kraus299ba622017-11-24 03:09:03 +01003014 custom_functions["vkCmdSetLineWidth"] = (void *)pv_vkCmdSetLineWidth;
Dave Houltonb3bbec72018-01-17 10:13:33 -07003015 custom_functions["vkCmdDraw"] = (void *)pv_vkCmdDraw;
3016 custom_functions["vkCmdDrawIndirect"] = (void *)pv_vkCmdDrawIndirect;
3017 custom_functions["vkCmdDrawIndexedIndirect"] = (void *)pv_vkCmdDrawIndexedIndirect;
3018 custom_functions["vkCmdCopyImage"] = (void *)pv_vkCmdCopyImage;
3019 custom_functions["vkCmdBlitImage"] = (void *)pv_vkCmdBlitImage;
3020 custom_functions["vkCmdCopyBufferToImage"] = (void *)pv_vkCmdCopyBufferToImage;
3021 custom_functions["vkCmdCopyImageToBuffer"] = (void *)pv_vkCmdCopyImageToBuffer;
3022 custom_functions["vkCmdUpdateBuffer"] = (void *)pv_vkCmdUpdateBuffer;
3023 custom_functions["vkCmdFillBuffer"] = (void *)pv_vkCmdFillBuffer;
3024 custom_functions["vkCreateSwapchainKHR"] = (void *)pv_vkCreateSwapchainKHR;
3025 custom_functions["vkQueuePresentKHR"] = (void *)pv_vkQueuePresentKHR;
3026 custom_functions["vkCreateDescriptorPool"] = (void *)pv_vkCreateDescriptorPool;
3027 custom_functions["vkCmdDispatch"] = (void *)pv_vkCmdDispatch;
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07003028 custom_functions["vkCmdDispatchBaseKHR"] = (void *)pv_vkCmdDispatchBaseKHR;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06003029}
3030
3031} // namespace parameter_validation
3032
3033VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
3034 VkExtensionProperties *pProperties) {
3035 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
3036}
3037
3038VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
3039 VkLayerProperties *pProperties) {
3040 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
3041}
3042
3043VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
3044 VkLayerProperties *pProperties) {
3045 // the layer command handles VK_NULL_HANDLE just fine internally
3046 assert(physicalDevice == VK_NULL_HANDLE);
3047 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
3048}
3049
3050VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
3051 const char *pLayerName, uint32_t *pCount,
3052 VkExtensionProperties *pProperties) {
3053 // the layer command handles VK_NULL_HANDLE just fine internally
3054 assert(physicalDevice == VK_NULL_HANDLE);
3055 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
3056}
3057
3058VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
3059 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
3060}
3061
3062VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
3063 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
3064}
3065
3066VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
3067 const char *funcName) {
3068 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
3069}
3070
3071VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
3072 assert(pVersionStruct != NULL);
3073 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
3074
3075 // Fill in the function pointers if our version is at least capable of having the structure contain them.
3076 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
3077 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
3078 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
3079 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
3080 }
3081
3082 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
3083 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
3084 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
3085 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
3086 }
3087
3088 return VK_SUCCESS;
3089}