blob: bcc4a05de6be8770fe721c4f55e1ad75e5675c2f [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>
Mark Lobodzinskid4950072017-08-01 13:02:20 -060028
29#include <iostream>
30#include <string>
31#include <sstream>
32#include <unordered_map>
33#include <unordered_set>
34#include <vector>
35#include <mutex>
36
37#include "vk_loader_platform.h"
38#include "vulkan/vk_layer.h"
39#include "vk_layer_config.h"
40#include "vk_dispatch_table_helper.h"
John Zulaufde972ac2017-10-26 12:07:05 -060041#include "vk_typemap_helper.h"
Mark Lobodzinskid4950072017-08-01 13:02:20 -060042
43#include "vk_layer_table.h"
44#include "vk_layer_data.h"
45#include "vk_layer_logging.h"
46#include "vk_layer_extension_utils.h"
47#include "vk_layer_utils.h"
48
49#include "parameter_name.h"
50#include "parameter_validation.h"
51
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -060052#if defined __ANDROID__
53#include <android/log.h>
54#define LOGCONSOLE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "DS", __VA_ARGS__))
55#else
56#define LOGCONSOLE(...) \
57 { \
58 printf(__VA_ARGS__); \
59 printf("\n"); \
60 }
61#endif
62
Mark Lobodzinskid4950072017-08-01 13:02:20 -060063namespace parameter_validation {
64
Mark Lobodzinski78a12a92017-08-08 14:16:51 -060065extern std::unordered_map<std::string, void *> custom_functions;
66
Mark Lobodzinskid4950072017-08-01 13:02:20 -060067extern bool parameter_validation_vkCreateInstance(VkInstance instance, const VkInstanceCreateInfo *pCreateInfo,
68 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance);
69extern bool parameter_validation_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator);
70extern bool parameter_validation_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
71 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
72extern bool parameter_validation_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator);
73extern bool parameter_validation_vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
74 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool);
75extern bool parameter_validation_vkCreateDebugReportCallbackEXT(VkInstance instance,
76 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
77 const VkAllocationCallbacks *pAllocator,
78 VkDebugReportCallbackEXT *pMsgCallback);
79extern bool parameter_validation_vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
80 const VkAllocationCallbacks *pAllocator);
Mark Young6ba8abe2017-11-09 10:37:04 -070081extern bool parameter_validation_vkCreateDebugUtilsMessengerEXT(VkInstance instance,
82 const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
83 const VkAllocationCallbacks *pAllocator,
84 VkDebugUtilsMessengerEXT *pMessenger);
85extern bool parameter_validation_vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
86 const VkAllocationCallbacks *pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -060087extern bool parameter_validation_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
88 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool);
Petr Krause91f7a12017-12-14 20:57:36 +010089extern bool parameter_validation_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
90 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
91extern bool parameter_validation_vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
92 const VkAllocationCallbacks *pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -060093
94// TODO : This can be much smarter, using separate locks for separate global data
95std::mutex global_lock;
96
97static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
98std::unordered_map<void *, layer_data *> layer_data_map;
99std::unordered_map<void *, instance_layer_data *> instance_layer_data_map;
100
101void InitializeManualParameterValidationFunctionPointers(void);
102
103static void init_parameter_validation(instance_layer_data *instance_data, const VkAllocationCallbacks *pAllocator) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700104 layer_debug_report_actions(instance_data->report_data, instance_data->logging_callback, pAllocator,
105 "lunarg_parameter_validation");
106 layer_debug_messenger_actions(instance_data->report_data, instance_data->logging_messenger, pAllocator,
107 "lunarg_parameter_validation");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600108}
109
Mark Young6ba8abe2017-11-09 10:37:04 -0700110static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION},
111 {VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_SPEC_VERSION}};
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600112
113static const VkLayerProperties global_layer = {
Dave Houltonb3bbec72018-01-17 10:13:33 -0700114 "VK_LAYER_LUNARG_parameter_validation",
115 VK_LAYER_API_VERSION,
116 1,
117 "LunarG Validation Layer",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600118};
119
120static const int MaxParamCheckerStringLength = 256;
121
John Zulauf71968502017-10-26 13:51:15 -0600122template <typename T>
123static inline bool in_inclusive_range(const T &value, const T &min, const T &max) {
124 // Using only < for generality and || for early abort
125 return !((value < min) || (max < value));
126}
127
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600128static bool validate_string(debug_report_data *report_data, const char *apiName, const ParameterName &stringName,
129 const char *validateString) {
130 assert(apiName != nullptr);
131 assert(validateString != nullptr);
132
133 bool skip = false;
134
135 VkStringErrorFlags result = vk_string_validate(MaxParamCheckerStringLength, validateString);
136
137 if (result == VK_STRING_ERROR_NONE) {
138 return skip;
139 } else if (result & VK_STRING_ERROR_LENGTH) {
140 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
141 INVALID_USAGE, LayerName, "%s: string %s exceeds max length %d", apiName, stringName.get_name().c_str(),
142 MaxParamCheckerStringLength);
143 } else if (result & VK_STRING_ERROR_BAD_DATA) {
144 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
145 INVALID_USAGE, LayerName, "%s: string %s contains invalid characters or is badly formed", apiName,
146 stringName.get_name().c_str());
147 }
148 return skip;
149}
150
151static bool ValidateDeviceQueueFamily(layer_data *device_data, uint32_t queue_family, const char *cmd_name,
152 const char *parameter_name, int32_t error_code, bool optional = false,
153 const char *vu_note = nullptr) {
154 bool skip = false;
155
156 if (!vu_note) vu_note = validation_error_map[error_code];
157 if (!optional && queue_family == VK_QUEUE_FAMILY_IGNORED) {
158 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
159 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
160 "%s: %s is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family index value. %s",
161 cmd_name, parameter_name, vu_note);
162 } else if (device_data->queueFamilyIndexMap.find(queue_family) == device_data->queueFamilyIndexMap.end()) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700163 skip |= log_msg(
164 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
165 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
166 "%s: %s (= %" PRIu32
167 ") is not one of the queue families given via VkDeviceQueueCreateInfo structures when the device was created. %s",
168 cmd_name, parameter_name, queue_family, vu_note);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600169 }
170
171 return skip;
172}
173
174static bool ValidateQueueFamilies(layer_data *device_data, uint32_t queue_family_count, const uint32_t *queue_families,
175 const char *cmd_name, const char *array_parameter_name, int32_t unique_error_code,
176 int32_t valid_error_code, bool optional = false, const char *unique_vu_note = nullptr,
177 const char *valid_vu_note = nullptr) {
178 bool skip = false;
179 if (!unique_vu_note) unique_vu_note = validation_error_map[unique_error_code];
180 if (!valid_vu_note) valid_vu_note = validation_error_map[valid_error_code];
181 if (queue_families) {
182 std::unordered_set<uint32_t> set;
183 for (uint32_t i = 0; i < queue_family_count; ++i) {
184 std::string parameter_name = std::string(array_parameter_name) + "[" + std::to_string(i) + "]";
185
186 if (set.count(queue_families[i])) {
187 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
188 HandleToUint64(device_data->device), __LINE__, VALIDATION_ERROR_056002e8, LayerName,
189 "%s: %s (=%" PRIu32 ") is not unique within %s array. %s", cmd_name, parameter_name.c_str(),
190 queue_families[i], array_parameter_name, unique_vu_note);
191 } else {
192 set.insert(queue_families[i]);
193 skip |= ValidateDeviceQueueFamily(device_data, queue_families[i], cmd_name, parameter_name.c_str(),
194 valid_error_code, optional, valid_vu_note);
195 }
196 }
197 }
198 return skip;
199}
200
201VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600202 VkInstance *pInstance) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600203 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
204
205 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
206 assert(chain_info != nullptr);
207 assert(chain_info->u.pLayerInfo != nullptr);
208
209 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
210 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
211 if (fpCreateInstance == NULL) {
212 return VK_ERROR_INITIALIZATION_FAILED;
213 }
214
215 // Advance the link info for the next element on the chain
216 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
217
218 result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
219
220 if (result == VK_SUCCESS) {
221 InitializeManualParameterValidationFunctionPointers();
222 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), instance_layer_data_map);
223 assert(my_instance_data != nullptr);
224
225 layer_init_instance_dispatch_table(*pInstance, &my_instance_data->dispatch_table, fpGetInstanceProcAddr);
226 my_instance_data->instance = *pInstance;
227 my_instance_data->report_data =
Mark Young6ba8abe2017-11-09 10:37:04 -0700228 debug_utils_create_instance(&my_instance_data->dispatch_table, *pInstance, pCreateInfo->enabledExtensionCount,
229 pCreateInfo->ppEnabledExtensionNames);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600230
231 // Look for one or more debug report create info structures
232 // and setup a callback(s) for each one found.
Mark Young6ba8abe2017-11-09 10:37:04 -0700233 if (!layer_copy_tmp_debug_messengers(pCreateInfo->pNext, &my_instance_data->num_tmp_debug_messengers,
234 &my_instance_data->tmp_messenger_create_infos,
235 &my_instance_data->tmp_debug_messengers)) {
236 if (my_instance_data->num_tmp_debug_messengers > 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600237 // Setup the temporary callback(s) here to catch early issues:
Mark Young6ba8abe2017-11-09 10:37:04 -0700238 if (layer_enable_tmp_debug_messengers(my_instance_data->report_data, my_instance_data->num_tmp_debug_messengers,
239 my_instance_data->tmp_messenger_create_infos,
240 my_instance_data->tmp_debug_messengers)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600241 // Failure of setting up one or more of the callback.
242 // Therefore, clean up and don't use those callbacks:
Mark Young6ba8abe2017-11-09 10:37:04 -0700243 layer_free_tmp_debug_messengers(my_instance_data->tmp_messenger_create_infos,
244 my_instance_data->tmp_debug_messengers);
245 my_instance_data->num_tmp_debug_messengers = 0;
246 }
247 }
248 }
249 if (!layer_copy_tmp_report_callbacks(pCreateInfo->pNext, &my_instance_data->num_tmp_report_callbacks,
250 &my_instance_data->tmp_report_create_infos, &my_instance_data->tmp_report_callbacks)) {
251 if (my_instance_data->num_tmp_report_callbacks > 0) {
252 // Setup the temporary callback(s) here to catch early issues:
253 if (layer_enable_tmp_report_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_report_callbacks,
254 my_instance_data->tmp_report_create_infos,
255 my_instance_data->tmp_report_callbacks)) {
256 // Failure of setting up one or more of the callback.
257 // Therefore, clean up and don't use those callbacks:
258 layer_free_tmp_report_callbacks(my_instance_data->tmp_report_create_infos,
259 my_instance_data->tmp_report_callbacks);
260 my_instance_data->num_tmp_report_callbacks = 0;
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600261 }
262 }
263 }
264
265 init_parameter_validation(my_instance_data, pAllocator);
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600266
267 uint32_t api_version = my_instance_data->extensions.InitFromInstanceCreateInfo(
268 (pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : VK_API_VERSION_1_0), pCreateInfo);
269
270 if (pCreateInfo->pApplicationInfo) {
271 uint32_t specified_api_version = pCreateInfo->pApplicationInfo->apiVersion & ~VK_VERSION_PATCH(~0);
272 if (!(specified_api_version == VK_API_VERSION_1_0) && !(specified_api_version == VK_API_VERSION_1_1)) {
273 LOGCONSOLE(
274 "Warning: Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number -- (0x%08x) assuming "
275 "%s.\n",
276 pCreateInfo->pApplicationInfo->apiVersion,
277 (api_version == VK_API_VERSION_1_0) ? "VK_API_VERSION_1_0" : "VK_API_VERSION_1_1");
278 }
279 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600280
281 // Ordinarily we'd check these before calling down the chain, but none of the layer support is in place until now, if we
282 // survive we can report the issue now.
283 parameter_validation_vkCreateInstance(*pInstance, pCreateInfo, pAllocator, pInstance);
284
285 if (pCreateInfo->pApplicationInfo) {
286 if (pCreateInfo->pApplicationInfo->pApplicationName) {
287 validate_string(my_instance_data->report_data, "vkCreateInstance",
288 "pCreateInfo->VkApplicationInfo->pApplicationName",
289 pCreateInfo->pApplicationInfo->pApplicationName);
290 }
291
292 if (pCreateInfo->pApplicationInfo->pEngineName) {
293 validate_string(my_instance_data->report_data, "vkCreateInstance", "pCreateInfo->VkApplicationInfo->pEngineName",
294 pCreateInfo->pApplicationInfo->pEngineName);
295 }
296 }
297
298 // Disable the tmp callbacks:
Mark Young6ba8abe2017-11-09 10:37:04 -0700299 if (my_instance_data->num_tmp_debug_messengers > 0) {
300 layer_disable_tmp_debug_messengers(my_instance_data->report_data, my_instance_data->num_tmp_debug_messengers,
301 my_instance_data->tmp_debug_messengers);
302 }
303 if (my_instance_data->num_tmp_report_callbacks > 0) {
304 layer_disable_tmp_report_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_report_callbacks,
305 my_instance_data->tmp_report_callbacks);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600306 }
307 }
308
309 return result;
310}
311
312VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
313 // Grab the key before the instance is destroyed.
314 dispatch_key key = get_dispatch_key(instance);
315 bool skip = false;
316 auto instance_data = GetLayerDataPtr(key, instance_layer_data_map);
317
318 // Enable the temporary callback(s) here to catch vkDestroyInstance issues:
319 bool callback_setup = false;
Mark Young6ba8abe2017-11-09 10:37:04 -0700320 if (instance_data->num_tmp_debug_messengers > 0) {
321 if (!layer_enable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers,
322 instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers)) {
323 callback_setup = true;
324 }
325 }
326 if (instance_data->num_tmp_report_callbacks > 0) {
327 if (!layer_enable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks,
328 instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600329 callback_setup = true;
330 }
331 }
332
333 skip |= parameter_validation_vkDestroyInstance(instance, pAllocator);
334
335 // Disable and cleanup the temporary callback(s):
336 if (callback_setup) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700337 layer_disable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers,
338 instance_data->tmp_debug_messengers);
339 layer_disable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks,
340 instance_data->tmp_report_callbacks);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600341 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700342 if (instance_data->num_tmp_debug_messengers > 0) {
343 layer_free_tmp_debug_messengers(instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers);
344 instance_data->num_tmp_debug_messengers = 0;
345 }
346 if (instance_data->num_tmp_report_callbacks > 0) {
347 layer_free_tmp_report_callbacks(instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks);
348 instance_data->num_tmp_report_callbacks = 0;
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600349 }
350
351 if (!skip) {
352 instance_data->dispatch_table.DestroyInstance(instance, pAllocator);
353
354 // Clean up logging callback, if any
Mark Young6ba8abe2017-11-09 10:37:04 -0700355 while (instance_data->logging_messenger.size() > 0) {
356 VkDebugUtilsMessengerEXT messenger = instance_data->logging_messenger.back();
357 layer_destroy_messenger_callback(instance_data->report_data, messenger, pAllocator);
358 instance_data->logging_messenger.pop_back();
359 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600360 while (instance_data->logging_callback.size() > 0) {
361 VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
Mark Young6ba8abe2017-11-09 10:37:04 -0700362 layer_destroy_report_callback(instance_data->report_data, callback, pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600363 instance_data->logging_callback.pop_back();
364 }
365
Mark Young6ba8abe2017-11-09 10:37:04 -0700366 layer_debug_utils_destroy_instance(instance_data->report_data);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600367 }
368
369 FreeLayerDataPtr(key, instance_layer_data_map);
370}
371
372VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance,
373 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
374 const VkAllocationCallbacks *pAllocator,
375 VkDebugReportCallbackEXT *pMsgCallback) {
376 bool skip = parameter_validation_vkCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
377 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
378
379 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
380 VkResult result = instance_data->dispatch_table.CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
381 if (result == VK_SUCCESS) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700382 result = layer_create_report_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback);
383 // If something happened during this call, clean up the message callback that was created earlier in the lower levels
384 if (VK_SUCCESS != result) {
385 instance_data->dispatch_table.DestroyDebugReportCallbackEXT(instance, *pMsgCallback, pAllocator);
386 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600387 }
388 return result;
389}
390
391VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
392 const VkAllocationCallbacks *pAllocator) {
393 bool skip = parameter_validation_vkDestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
394 if (!skip) {
395 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
396 instance_data->dispatch_table.DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Mark Young6ba8abe2017-11-09 10:37:04 -0700397 layer_destroy_report_callback(instance_data->report_data, msgCallback, pAllocator);
398 }
399}
400
401VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance,
402 const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
403 const VkAllocationCallbacks *pAllocator,
404 VkDebugUtilsMessengerEXT *pMessenger) {
405 bool skip = parameter_validation_vkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
406 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
407
408 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
409 VkResult result = instance_data->dispatch_table.CreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
410 if (VK_SUCCESS == result) {
411 result = layer_create_messenger_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMessenger);
412 // If something happened during this call, clean up the message callback that was created earlier in the lower levels
413 if (VK_SUCCESS != result) {
414 instance_data->dispatch_table.DestroyDebugUtilsMessengerEXT(instance, *pMessenger, pAllocator);
415 }
416 }
417 return result;
418}
419
420VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
421 const VkAllocationCallbacks *pAllocator) {
422 bool skip = parameter_validation_vkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
423 if (!skip) {
424 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
425 instance_data->dispatch_table.DestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
426 layer_destroy_messenger_callback(instance_data->report_data, messenger, pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600427 }
428}
429
430static bool ValidateDeviceCreateInfo(instance_layer_data *instance_data, VkPhysicalDevice physicalDevice,
431 const VkDeviceCreateInfo *pCreateInfo) {
432 bool skip = false;
433
434 if ((pCreateInfo->enabledLayerCount > 0) && (pCreateInfo->ppEnabledLayerNames != NULL)) {
435 for (size_t i = 0; i < pCreateInfo->enabledLayerCount; i++) {
436 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledLayerNames",
437 pCreateInfo->ppEnabledLayerNames[i]);
438 }
439 }
440
441 bool maint1 = false;
442 bool negative_viewport = false;
443
444 if ((pCreateInfo->enabledExtensionCount > 0) && (pCreateInfo->ppEnabledExtensionNames != NULL)) {
445 for (size_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
446 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledExtensionNames",
447 pCreateInfo->ppEnabledExtensionNames[i]);
448 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) maint1 = true;
449 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME) == 0)
450 negative_viewport = true;
451 }
452 }
453
454 if (maint1 && negative_viewport) {
455 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
456 __LINE__, VALIDATION_ERROR_056002ec, LayerName,
457 "VkDeviceCreateInfo->ppEnabledExtensionNames must not simultaneously include VK_KHR_maintenance1 and "
458 "VK_AMD_negative_viewport_height. %s",
459 validation_error_map[VALIDATION_ERROR_056002ec]);
460 }
461
462 if (pCreateInfo->pNext != NULL && pCreateInfo->pEnabledFeatures) {
463 // Check for get_physical_device_properties2 struct
John Zulaufde972ac2017-10-26 12:07:05 -0600464 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
465 if (features2) {
466 // Cannot include VkPhysicalDeviceFeatures2KHR and have non-null pEnabledFeatures
467 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
468 __LINE__, INVALID_USAGE, LayerName,
469 "VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceFeatures2KHR struct when "
470 "pCreateInfo->pEnabledFeatures is non-NULL.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600471 }
472 }
473
474 // Validate pCreateInfo->pQueueCreateInfos
475 if (pCreateInfo->pQueueCreateInfos) {
476 std::unordered_set<uint32_t> set;
477
478 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
479 const uint32_t requested_queue_family = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
480 if (requested_queue_family == VK_QUEUE_FAMILY_IGNORED) {
481 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
482 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
483 VALIDATION_ERROR_06c002fa, LayerName,
484 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700485 "].queueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family "
486 "index value. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600487 i, validation_error_map[VALIDATION_ERROR_06c002fa]);
488 } else if (set.count(requested_queue_family)) {
489 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
490 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
491 VALIDATION_ERROR_056002e8, LayerName,
492 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].queueFamilyIndex (=%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700493 ") is not unique within pCreateInfo->pQueueCreateInfos array. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600494 i, requested_queue_family, validation_error_map[VALIDATION_ERROR_056002e8]);
495 } else {
496 set.insert(requested_queue_family);
497 }
498
499 if (pCreateInfo->pQueueCreateInfos[i].pQueuePriorities != nullptr) {
500 for (uint32_t j = 0; j < pCreateInfo->pQueueCreateInfos[i].queueCount; ++j) {
501 const float queue_priority = pCreateInfo->pQueueCreateInfos[i].pQueuePriorities[j];
502 if (!(queue_priority >= 0.f) || !(queue_priority <= 1.f)) {
503 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
504 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
505 VALIDATION_ERROR_06c002fe, LayerName,
506 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].pQueuePriorities[%" PRIu32
507 "] (=%f) is not between 0 and 1 (inclusive). %s",
508 i, j, queue_priority, validation_error_map[VALIDATION_ERROR_06c002fe]);
509 }
510 }
511 }
512 }
513 }
514
515 return skip;
516}
517
518VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
519 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
520 // NOTE: Don't validate physicalDevice or any dispatchable object as the first parameter. We couldn't get here if it was wrong!
521
522 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
523 bool skip = false;
524 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
525 assert(my_instance_data != nullptr);
526 std::unique_lock<std::mutex> lock(global_lock);
527
528 skip |= parameter_validation_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
529
530 if (pCreateInfo != NULL) skip |= ValidateDeviceCreateInfo(my_instance_data, physicalDevice, pCreateInfo);
531
532 if (!skip) {
533 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
534 assert(chain_info != nullptr);
535 assert(chain_info->u.pLayerInfo != nullptr);
536
537 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
538 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
539 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice");
540 if (fpCreateDevice == NULL) {
541 return VK_ERROR_INITIALIZATION_FAILED;
542 }
543
544 // Advance the link info for the next element on the chain
545 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
546
547 lock.unlock();
548
549 result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
550
551 lock.lock();
552
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600553 if (result == VK_SUCCESS) {
554 layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
555 assert(my_device_data != nullptr);
556
Mark Young6ba8abe2017-11-09 10:37:04 -0700557 my_device_data->report_data = layer_debug_utils_create_device(my_instance_data->report_data, *pDevice);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600558 layer_init_device_dispatch_table(*pDevice, &my_device_data->dispatch_table, fpGetDeviceProcAddr);
559
Mark Lobodzinskibfb7ab92017-10-27 13:22:23 -0600560 // Query and save physical device limits for this device
561 VkPhysicalDeviceProperties device_properties = {};
562 my_instance_data->dispatch_table.GetPhysicalDeviceProperties(physicalDevice, &device_properties);
563
564 my_device_data->api_version = my_device_data->extensions.InitFromDeviceCreateInfo(
565 &my_instance_data->extensions, device_properties.apiVersion, pCreateInfo);
566
567 uint32_t specified_api_version = device_properties.apiVersion & ~VK_VERSION_PATCH(~0);
568 if (!(specified_api_version == VK_API_VERSION_1_0) && !(specified_api_version == VK_API_VERSION_1_1)) {
569 LOGCONSOLE(
570 "Warning: Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number -- (0x%8x) assuming "
571 "%s.\n",
572 device_properties.apiVersion,
573 (my_device_data->api_version == VK_API_VERSION_1_0) ? "VK_API_VERSION_1_0" : "VK_API_VERSION_1_1");
574 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600575
576 // Store createdevice data
577 if ((pCreateInfo != nullptr) && (pCreateInfo->pQueueCreateInfos != nullptr)) {
578 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
579 my_device_data->queueFamilyIndexMap.insert(std::make_pair(pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex,
580 pCreateInfo->pQueueCreateInfos[i].queueCount));
581 }
582 }
583
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600584 memcpy(&my_device_data->device_limits, &device_properties.limits, sizeof(VkPhysicalDeviceLimits));
585 my_device_data->physical_device = physicalDevice;
586 my_device_data->device = *pDevice;
587
588 // Save app-enabled features in this device's layer_data structure
John Zulauf1bde5bb2017-10-18 18:21:23 -0600589 // The enabled features can come from either pEnabledFeatures, or from the pNext chain
590 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
591 if ((nullptr == enabled_features_found) && my_device_data->extensions.vk_khr_get_physical_device_properties_2) {
John Zulaufde972ac2017-10-26 12:07:05 -0600592 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
593 if (features2) {
594 enabled_features_found = &(features2->features);
John Zulauf1bde5bb2017-10-18 18:21:23 -0600595 }
596 }
597 if (enabled_features_found) {
Dave Houltonb3bbec72018-01-17 10:13:33 -0700598 my_device_data->physical_device_features = *enabled_features_found;
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600599 } else {
600 memset(&my_device_data->physical_device_features, 0, sizeof(VkPhysicalDeviceFeatures));
601 }
602 }
603 }
604
605 return result;
606}
607
608VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
609 dispatch_key key = get_dispatch_key(device);
610 bool skip = false;
611 layer_data *device_data = GetLayerDataPtr(key, layer_data_map);
612 {
613 std::unique_lock<std::mutex> lock(global_lock);
614 skip |= parameter_validation_vkDestroyDevice(device, pAllocator);
615 }
616
617 if (!skip) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700618 layer_debug_utils_destroy_device(device);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600619 device_data->dispatch_table.DestroyDevice(device, pAllocator);
620 }
621 FreeLayerDataPtr(key, layer_data_map);
622}
623
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600624bool pv_vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
625 bool skip = false;
626 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
627
628 skip |=
629 ValidateDeviceQueueFamily(device_data, queueFamilyIndex, "vkGetDeviceQueue", "queueFamilyIndex", VALIDATION_ERROR_29600300);
630 const auto &queue_data = device_data->queueFamilyIndexMap.find(queueFamilyIndex);
631 if (queue_data != device_data->queueFamilyIndexMap.end() && queue_data->second <= queueIndex) {
632 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
633 HandleToUint64(device), __LINE__, VALIDATION_ERROR_29600302, LayerName,
634 "vkGetDeviceQueue: queueIndex (=%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700635 ") is not less than the number of queues requested from queueFamilyIndex (=%" PRIu32
636 ") when the device was created (i.e. is not less than %" PRIu32 "). %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600637 queueIndex, queueFamilyIndex, queue_data->second, validation_error_map[VALIDATION_ERROR_29600302]);
638 }
639 return skip;
640}
641
642VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
643 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool) {
644 layer_data *local_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
645 bool skip = false;
646 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
647 std::unique_lock<std::mutex> lock(global_lock);
648
649 skip |= ValidateDeviceQueueFamily(local_data, pCreateInfo->queueFamilyIndex, "vkCreateCommandPool",
650 "pCreateInfo->queueFamilyIndex", VALIDATION_ERROR_02c0004e);
651
652 skip |= parameter_validation_vkCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
653
654 lock.unlock();
655 if (!skip) {
656 result = local_data->dispatch_table.CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
657 }
658 return result;
659}
660
661VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
662 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool) {
663 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
664 bool skip = false;
665 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
666
667 skip |= parameter_validation_vkCreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
668
669 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
670 if (pCreateInfo != nullptr) {
671 // If queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, pipelineStatistics must be a valid combination of
672 // VkQueryPipelineStatisticFlagBits values
673 if ((pCreateInfo->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS) && (pCreateInfo->pipelineStatistics != 0) &&
674 ((pCreateInfo->pipelineStatistics & (~AllVkQueryPipelineStatisticFlagBits)) != 0)) {
675 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
676 __LINE__, VALIDATION_ERROR_11c00630, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700677 "vkCreateQueryPool(): if pCreateInfo->queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, "
678 "pCreateInfo->pipelineStatistics must be a valid combination of VkQueryPipelineStatisticFlagBits "
679 "values. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600680 validation_error_map[VALIDATION_ERROR_11c00630]);
681 }
682 }
683 if (!skip) {
684 result = device_data->dispatch_table.CreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
685 }
686 return result;
687}
688
Petr Krause91f7a12017-12-14 20:57:36 +0100689VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
690 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass) {
691 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
692 bool skip = false;
693 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
694
695 {
696 std::unique_lock<std::mutex> lock(global_lock);
697 skip |= parameter_validation_vkCreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
698
Dave Houltonb3bbec72018-01-17 10:13:33 -0700699 typedef bool (*PFN_manual_vkCreateRenderPass)(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
700 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
Petr Krause91f7a12017-12-14 20:57:36 +0100701 PFN_manual_vkCreateRenderPass custom_func = (PFN_manual_vkCreateRenderPass)custom_functions["vkCreateRenderPass"];
702 if (custom_func != nullptr) {
703 skip |= custom_func(device, pCreateInfo, pAllocator, pRenderPass);
704 }
705 }
706
707 if (!skip) {
708 result = device_data->dispatch_table.CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
709
710 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
711 if (result == VK_SUCCESS) {
712 std::unique_lock<std::mutex> lock(global_lock);
713 const auto renderPass = *pRenderPass;
714 auto &renderpass_state = device_data->renderpasses_states[renderPass];
715
716 for (uint32_t subpass = 0; subpass < pCreateInfo->subpassCount; ++subpass) {
717 bool uses_color = false;
718 for (uint32_t i = 0; i < pCreateInfo->pSubpasses[subpass].colorAttachmentCount && !uses_color; ++i)
719 if (pCreateInfo->pSubpasses[subpass].pColorAttachments[i].attachment != VK_ATTACHMENT_UNUSED) uses_color = true;
720
721 bool uses_depthstencil = false;
722 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment)
723 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)
724 uses_depthstencil = true;
725
726 if (uses_color) renderpass_state.subpasses_using_color_attachment.insert(subpass);
727 if (uses_depthstencil) renderpass_state.subpasses_using_depthstencil_attachment.insert(subpass);
728 }
729 }
730 }
731 return result;
732}
733
734VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator) {
735 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
736 bool skip = false;
737
738 {
739 std::unique_lock<std::mutex> lock(global_lock);
740 skip |= parameter_validation_vkDestroyRenderPass(device, renderPass, pAllocator);
741
Dave Houltonb3bbec72018-01-17 10:13:33 -0700742 typedef bool (*PFN_manual_vkDestroyRenderPass)(VkDevice device, VkRenderPass renderPass,
743 const VkAllocationCallbacks *pAllocator);
Petr Krause91f7a12017-12-14 20:57:36 +0100744 PFN_manual_vkDestroyRenderPass custom_func = (PFN_manual_vkDestroyRenderPass)custom_functions["vkDestroyRenderPass"];
745 if (custom_func != nullptr) {
746 skip |= custom_func(device, renderPass, pAllocator);
747 }
748 }
749
750 if (!skip) {
751 device_data->dispatch_table.DestroyRenderPass(device, renderPass, pAllocator);
752
753 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
754 {
755 std::unique_lock<std::mutex> lock(global_lock);
756 device_data->renderpasses_states.erase(renderPass);
757 }
758 }
759}
760
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600761bool pv_vkCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
762 VkBuffer *pBuffer) {
763 bool skip = false;
764 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
765 debug_report_data *report_data = device_data->report_data;
766
Petr Krause5c37652018-01-05 04:05:12 +0100767 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, VK_NULL_HANDLE, LayerName, "vkCreateBuffer"};
768
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600769 if (pCreateInfo != nullptr) {
Petr Krause5c37652018-01-05 04:05:12 +0100770 skip |= ValidateGreaterThanZero(pCreateInfo->size, "pCreateInfo->size", VALIDATION_ERROR_01400720, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600771
772 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
773 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
774 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
775 if (pCreateInfo->queueFamilyIndexCount <= 1) {
776 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
777 VALIDATION_ERROR_01400724, LayerName,
778 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
779 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
780 validation_error_map[VALIDATION_ERROR_01400724]);
781 }
782
783 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
784 // queueFamilyIndexCount uint32_t values
785 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
786 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
787 VALIDATION_ERROR_01400722, LayerName,
788 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
789 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
790 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
791 validation_error_map[VALIDATION_ERROR_01400722]);
792 } else {
793 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
794 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
795 "vkCreateBuffer", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
796 false, "", "");
797 }
798 }
799
800 // If flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain
801 // VK_BUFFER_CREATE_SPARSE_BINDING_BIT
802 if (((pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
803 ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) != VK_BUFFER_CREATE_SPARSE_BINDING_BIT)) {
804 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
805 VALIDATION_ERROR_0140072c, LayerName,
806 "vkCreateBuffer: if pCreateInfo->flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or "
807 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_BUFFER_CREATE_SPARSE_BINDING_BIT. %s",
808 validation_error_map[VALIDATION_ERROR_0140072c]);
809 }
810 }
811
812 return skip;
813}
814
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600815bool pv_vkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
816 VkImage *pImage) {
817 bool skip = false;
818 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
819 debug_report_data *report_data = device_data->report_data;
820
Petr Krause5c37652018-01-05 04:05:12 +0100821 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, VK_NULL_HANDLE, LayerName, "vkCreateImage"};
822
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600823 if (pCreateInfo != nullptr) {
824 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
825 FormatIsCompressed_ETC2_EAC(pCreateInfo->format)) {
826 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
827 DEVICE_FEATURE, LayerName,
828 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionETC2 feature is "
829 "not enabled: neither ETC2 nor EAC formats can be used to create images.",
830 string_VkFormat(pCreateInfo->format));
831 }
832
833 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
834 FormatIsCompressed_ASTC_LDR(pCreateInfo->format)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700835 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
836 DEVICE_FEATURE, LayerName,
837 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionASTC_LDR feature "
838 "is not enabled: ASTC formats cannot be used to create images.",
839 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600840 }
841
842 if ((device_data->physical_device_features.textureCompressionBC == false) && FormatIsCompressed_BC(pCreateInfo->format)) {
843 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
844 DEVICE_FEATURE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700845 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionBC feature is not "
846 "enabled: BC compressed formats cannot be used to create images.",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600847 string_VkFormat(pCreateInfo->format));
848 }
849
850 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
851 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
852 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
853 if (pCreateInfo->queueFamilyIndexCount <= 1) {
854 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
855 VALIDATION_ERROR_09e0075c, LayerName,
856 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
857 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
858 validation_error_map[VALIDATION_ERROR_09e0075c]);
859 }
860
861 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
862 // queueFamilyIndexCount uint32_t values
863 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
864 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
865 VALIDATION_ERROR_09e0075a, LayerName,
866 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
867 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
868 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
869 validation_error_map[VALIDATION_ERROR_09e0075a]);
870 } else {
871 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
872 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
873 "vkCreateImage", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
874 false, "", "");
875 }
876 }
877
Petr Krause5c37652018-01-05 04:05:12 +0100878 skip |=
879 ValidateGreaterThanZero(pCreateInfo->extent.width, "pCreateInfo->extent.width", VALIDATION_ERROR_09e00760, log_misc);
880 skip |=
881 ValidateGreaterThanZero(pCreateInfo->extent.height, "pCreateInfo->extent.height", VALIDATION_ERROR_09e00762, log_misc);
882 skip |=
883 ValidateGreaterThanZero(pCreateInfo->extent.depth, "pCreateInfo->extent.depth", VALIDATION_ERROR_09e00764, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600884
Petr Krause5c37652018-01-05 04:05:12 +0100885 skip |= ValidateGreaterThanZero(pCreateInfo->mipLevels, "pCreateInfo->mipLevels", VALIDATION_ERROR_09e00766, log_misc);
886 skip |= ValidateGreaterThanZero(pCreateInfo->arrayLayers, "pCreateInfo->arrayLayers", VALIDATION_ERROR_09e00768, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600887
Dave Houlton130c0212018-01-29 13:39:56 -0700888 // InitialLayout must be PREINITIALIZED or UNDEFINED
Dave Houltone19e20d2018-02-02 16:32:41 -0700889 if ((pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED) &&
890 (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED)) {
891 skip |= log_msg(
892 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dave Houlton130c0212018-01-29 13:39:56 -0700893 VALIDATION_ERROR_09e007c2, LayerName,
894 "vkCreateImage(): initialLayout is %s, must be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
895 string_VkImageLayout(pCreateInfo->initialLayout), validation_error_map[VALIDATION_ERROR_09e007c2]);
896 }
897
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600898 // If imageType is VK_IMAGE_TYPE_1D, both extent.height and extent.depth must be 1
Petr Kraus3ac9e812018-03-13 12:31:08 +0100899 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) &&
900 ((pCreateInfo->extent.height != 1) || (pCreateInfo->extent.depth != 1))) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600901 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) {
Petr Kraus3f433212018-03-13 12:31:27 +0100909 if (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) {
910 if (pCreateInfo->extent.width != pCreateInfo->extent.height) {
911 skip |= log_msg(
912 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, VK_NULL_HANDLE, __LINE__,
913 VALIDATION_ERROR_09e00774, LayerName,
914 "vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, but "
915 "pCreateInfo->extent.width (=%" PRIu32 ") and pCreateInfo->extent.height (=%" PRIu32 ") are not equal. %s",
916 pCreateInfo->extent.width, pCreateInfo->extent.height, validation_error_map[VALIDATION_ERROR_09e00774]);
917 }
918
919 if (pCreateInfo->arrayLayers < 6) {
920 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
921 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_09e00774, LayerName,
922 "vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, but "
923 "pCreateInfo->arrayLayers (=%" PRIu32 ") is not greater than or equal to 6. %s",
924 pCreateInfo->arrayLayers, validation_error_map[VALIDATION_ERROR_09e00774]);
925 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600926 }
927
928 if (pCreateInfo->extent.depth != 1) {
929 skip |= log_msg(
930 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
931 VALIDATION_ERROR_09e0077a, LayerName,
932 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1. %s",
933 validation_error_map[VALIDATION_ERROR_09e0077a]);
934 }
935 }
936
Dave Houlton130c0212018-01-29 13:39:56 -0700937 // 3D image may have only 1 layer
938 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_3D) && (pCreateInfo->arrayLayers != 1)) {
939 skip |=
940 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
941 VALIDATION_ERROR_09e00782, LayerName,
942 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_3D, pCreateInfo->arrayLayers must be 1. %s",
943 validation_error_map[VALIDATION_ERROR_09e00782]);
944 }
945
946 // If multi-sample, validate type, usage, tiling and mip levels.
947 if ((pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) &&
948 ((pCreateInfo->imageType != VK_IMAGE_TYPE_2D) || (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) ||
949 (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) || (pCreateInfo->mipLevels != 1))) {
950 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
951 VALIDATION_ERROR_09e00784, LayerName,
952 "vkCreateImage(): Multi-sample image with incompatible type, usage, tiling, or mips. %s",
953 validation_error_map[VALIDATION_ERROR_09e00784]);
954 }
955
956 if (0 != (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
957 VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
958 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
959 // At least one of the legal attachment bits must be set
960 if (0 == (pCreateInfo->usage & legal_flags)) {
961 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
962 VALIDATION_ERROR_09e0078c, LayerName,
963 "vkCreateImage(): Transient attachment image without a compatible attachment flag set. %s",
964 validation_error_map[VALIDATION_ERROR_09e0078c]);
965 }
966 // No flags other than the legal attachment bits may be set
967 legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
968 if (0 != (pCreateInfo->usage & ~legal_flags)) {
969 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
970 VALIDATION_ERROR_09e00786, LayerName,
971 "vkCreateImage(): Transient attachment image with incompatible usage flags set. %s",
972 validation_error_map[VALIDATION_ERROR_09e00786]);
973 }
974 }
975
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600976 // mipLevels must be less than or equal to floor(log2(max(extent.width,extent.height,extent.depth)))+1
977 uint32_t maxDim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
Petr Krause5c37652018-01-05 04:05:12 +0100978 if (maxDim > 0 && pCreateInfo->mipLevels > (floor(log2(maxDim)) + 1)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600979 skip |=
980 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
981 VALIDATION_ERROR_09e0077c, LayerName,
982 "vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
983 "floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1. %s",
984 validation_error_map[VALIDATION_ERROR_09e0077c]);
985 }
986
987 // If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
988 // VK_IMAGE_CREATE_SPARSE_BINDING_BIT
989 if (((pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
990 ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
991 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
992 VALIDATION_ERROR_09e007b6, LayerName,
993 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
994 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT. %s",
995 validation_error_map[VALIDATION_ERROR_09e007b6]);
996 }
997
998 // Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
999 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
1000 // Linear tiling is unsupported
1001 if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
1002 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1003 INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001004 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image "
1005 "tiling of VK_IMAGE_TILING_LINEAR is not supported");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001006 }
1007
1008 // Sparse 1D image isn't valid
1009 if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
1010 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1011 VALIDATION_ERROR_09e00794, LayerName,
1012 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image. %s",
1013 validation_error_map[VALIDATION_ERROR_09e00794]);
1014 }
1015
1016 // Sparse 2D image when device doesn't support it
1017 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage2D) &&
1018 (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
1019 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1020 VALIDATION_ERROR_09e00796, LayerName,
1021 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
1022 "feature is not enabled on the device. %s",
1023 validation_error_map[VALIDATION_ERROR_09e00796]);
1024 }
1025
1026 // Sparse 3D image when device doesn't support it
1027 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage3D) &&
1028 (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
1029 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1030 VALIDATION_ERROR_09e00798, LayerName,
1031 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
1032 "feature is not enabled on the device. %s",
1033 validation_error_map[VALIDATION_ERROR_09e00798]);
1034 }
1035
1036 // Multi-sample 2D image when device doesn't support it
1037 if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
1038 if ((VK_FALSE == device_data->physical_device_features.sparseResidency2Samples) &&
1039 (VK_SAMPLE_COUNT_2_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_09e0079a, LayerName,
1042 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if "
1043 "corresponding feature is not enabled on the device. %s",
1044 validation_error_map[VALIDATION_ERROR_09e0079a]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001045 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency4Samples) &&
1046 (VK_SAMPLE_COUNT_4_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_09e0079c, LayerName,
1049 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if "
1050 "corresponding feature is not enabled on the device. %s",
1051 validation_error_map[VALIDATION_ERROR_09e0079c]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001052 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency8Samples) &&
1053 (VK_SAMPLE_COUNT_8_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_09e0079e, LayerName,
1056 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if "
1057 "corresponding feature is not enabled on the device. %s",
1058 validation_error_map[VALIDATION_ERROR_09e0079e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001059 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency16Samples) &&
1060 (VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001061 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1062 __LINE__, VALIDATION_ERROR_09e007a0, LayerName,
1063 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if "
1064 "corresponding feature is not enabled on the device. %s",
1065 validation_error_map[VALIDATION_ERROR_09e007a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001066 }
1067 }
1068 }
1069 }
1070 return skip;
1071}
1072
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001073bool pv_vkCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1074 VkImageView *pView) {
1075 bool skip = false;
1076 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1077 debug_report_data *report_data = device_data->report_data;
1078
1079 if (pCreateInfo != nullptr) {
1080 if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) || (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D)) {
1081 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
1082 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1083 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1084 LayerName,
1085 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD, "
1086 "pCreateInfo->subresourceRange.layerCount must be 1",
1087 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) ? 1 : 2));
1088 }
1089 } else if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ||
1090 (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
1091 if ((pCreateInfo->subresourceRange.layerCount < 1) &&
1092 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1093 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1094 LayerName,
1095 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD_ARRAY, "
1096 "pCreateInfo->subresourceRange.layerCount must be >= 1",
1097 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ? 1 : 2));
1098 }
1099 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE) {
1100 if ((pCreateInfo->subresourceRange.layerCount != 6) &&
1101 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1102 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1103 LayerName,
1104 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE, "
1105 "pCreateInfo->subresourceRange.layerCount must be 6");
1106 }
1107 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
1108 if (((pCreateInfo->subresourceRange.layerCount == 0) || ((pCreateInfo->subresourceRange.layerCount % 6) != 0)) &&
1109 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1110 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1111 LayerName,
1112 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE_ARRAY, "
1113 "pCreateInfo->subresourceRange.layerCount must be a multiple of 6");
1114 }
1115 if (!device_data->physical_device_features.imageCubeArray) {
1116 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1117 LayerName, "vkCreateImageView: Device feature imageCubeArray not enabled.");
1118 }
1119 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_3D) {
1120 if (pCreateInfo->subresourceRange.baseArrayLayer != 0) {
1121 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1122 LayerName,
1123 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1124 "pCreateInfo->subresourceRange.baseArrayLayer must be 0");
1125 }
1126
1127 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
1128 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1129 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1130 LayerName,
1131 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1132 "pCreateInfo->subresourceRange.layerCount must be 1");
1133 }
1134 }
1135 }
1136 return skip;
1137}
1138
Petr Krausb3fcdb42018-01-09 22:09:09 +01001139bool pv_VkViewport(const layer_data *device_data, const VkViewport &viewport, const char *fn_name, const char *param_name,
1140 VkDebugReportObjectTypeEXT object_type, uint64_t object = 0) {
1141 bool skip = false;
1142 debug_report_data *report_data = device_data->report_data;
1143
1144 // Note: for numerical correctness
1145 // - float comparisons should expect NaN (comparison always false).
1146 // - VkPhysicalDeviceLimits::maxViewportDimensions is uint32_t, not float -> careful.
1147
1148 const auto f_lte_u32_exact = [](const float v1_f, const uint32_t v2_u32) {
John Zulaufac0876c2018-02-19 10:09:35 -07001149 if (std::isnan(v1_f)) return false;
Petr Krausb3fcdb42018-01-09 22:09:09 +01001150 if (v1_f <= 0.0f) return true;
1151
1152 float intpart;
1153 const float fract = modff(v1_f, &intpart);
1154
1155 assert(std::numeric_limits<float>::radix == 2);
1156 const float u32_max_plus1 = ldexpf(1.0f, 32); // hopefully exact
1157 if (intpart >= u32_max_plus1) return false;
1158
1159 uint32_t v1_u32 = static_cast<uint32_t>(intpart);
1160 if (v1_u32 < v2_u32)
1161 return true;
1162 else if (v1_u32 == v2_u32 && fract == 0.0f)
1163 return true;
1164 else
1165 return false;
1166 };
1167
1168 const auto f_lte_u32_direct = [](const float v1_f, const uint32_t v2_u32) {
1169 const float v2_f = static_cast<float>(v2_u32); // not accurate for > radix^digits; and undefined rounding mode
1170 return (v1_f <= v2_f);
1171 };
1172
1173 // width
1174 bool width_healthy = true;
1175 const auto max_w = device_data->device_limits.maxViewportDimensions[0];
1176
1177 if (!(viewport.width > 0.0f)) {
1178 width_healthy = false;
1179 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd4,
1180 LayerName, "%s: %s.width (=%f) is not greater than 0.0. %s", fn_name, param_name, viewport.width,
1181 validation_error_map[VALIDATION_ERROR_15000dd4]);
1182 } else if (!(f_lte_u32_exact(viewport.width, max_w) || f_lte_u32_direct(viewport.width, max_w))) {
1183 width_healthy = false;
1184 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd6,
1185 LayerName, "%s: %s.width (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32 "). %s",
1186 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1187 } else if (!f_lte_u32_exact(viewport.width, max_w) && f_lte_u32_direct(viewport.width, max_w)) {
1188 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1189 "%s: %s.width (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32
1190 "), but it is within the static_cast<float>(maxViewportDimensions[0]) limit. %s",
1191 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1192 }
1193
1194 // height
1195 bool height_healthy = true;
Petr Krausaf9c1222018-03-10 02:39:47 +01001196 const bool negative_height_enabled = device_data->api_version >= VK_API_VERSION_1_1 ||
1197 device_data->extensions.vk_khr_maintenance1 ||
1198 device_data->extensions.vk_amd_negative_viewport_height;
Petr Krausb3fcdb42018-01-09 22:09:09 +01001199 const auto max_h = device_data->device_limits.maxViewportDimensions[1];
1200
1201 if (!negative_height_enabled && !(viewport.height > 0.0f)) {
1202 height_healthy = false;
1203 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd8,
1204 LayerName, "%s: %s.height (=%f) is not greater 0.0. %s", fn_name, param_name, viewport.height,
1205 validation_error_map[VALIDATION_ERROR_15000dd8]);
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_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dda, LayerName,
1211 "%s: Absolute value of %s.height (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32 "). %s",
1212 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1213 } else if (!f_lte_u32_exact(fabsf(viewport.height), max_h) && f_lte_u32_direct(fabsf(viewport.height), max_h)) {
1214 height_healthy = false;
1215
1216 skip |= log_msg(
1217 report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1218 "%s: Absolute value of %s.height (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32
1219 "), but it is within the static_cast<float>(maxViewportDimensions[1]) limit. %s",
1220 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1221 }
1222
1223 // x
1224 bool x_healthy = true;
1225 if (!(viewport.x >= device_data->device_limits.viewportBoundsRange[0])) {
1226 x_healthy = false;
1227 skip |=
1228 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000ddc, LayerName,
1229 "%s: %s.x (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1230 viewport.x, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000ddc]);
1231 }
1232
1233 // x + width
1234 if (x_healthy && width_healthy) {
1235 const float right_bound = viewport.x + viewport.width;
1236 if (!(right_bound <= device_data->device_limits.viewportBoundsRange[1])) {
1237 skip |= log_msg(
1238 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1239 "%s: %s.x + %s.width (=%f + %f = %f) is greater than VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1240 fn_name, param_name, param_name, viewport.x, viewport.width, right_bound,
1241 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
1242 }
1243 }
1244
1245 // y
1246 bool y_healthy = true;
1247 if (!(viewport.y >= device_data->device_limits.viewportBoundsRange[0])) {
1248 y_healthy = false;
1249 skip |=
1250 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dde, LayerName,
1251 "%s: %s.y (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1252 viewport.y, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000dde]);
1253 } else if (negative_height_enabled && !(viewport.y <= device_data->device_limits.viewportBoundsRange[1])) {
1254 y_healthy = false;
1255 skip |=
1256 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de0, LayerName,
1257 "%s: %s.y (=%f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s", fn_name, param_name,
1258 viewport.y, device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_15000de0]);
1259 }
1260
1261 // y + height
1262 if (y_healthy && height_healthy) {
1263 const float boundary = viewport.y + viewport.height;
1264
1265 if (!(boundary <= device_data->device_limits.viewportBoundsRange[1])) {
1266 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a2,
1267 LayerName,
1268 "%s: %s.y + %s.height (=%f + %f = %f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1269 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1270 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
1271 } else if (negative_height_enabled && !(boundary >= device_data->device_limits.viewportBoundsRange[0])) {
1272 skip |= log_msg(
1273 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de2, LayerName,
1274 "%s: %s.y + %s.height (=%f + %f = %f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s",
1275 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1276 device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000de2]);
1277 }
1278 }
1279
1280 if (!device_data->extensions.vk_ext_depth_range_unrestricted) {
1281 // minDepth
1282 if (!(viewport.minDepth >= 0.0) || !(viewport.minDepth <= 1.0)) {
1283 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a4,
1284 LayerName,
1285 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.minDepth (=%f) is not within the "
1286 "[0.0, 1.0] range. %s",
1287 fn_name, param_name, viewport.minDepth, validation_error_map[VALIDATION_ERROR_150009a4]);
1288 }
1289
1290 // maxDepth
1291 if (!(viewport.maxDepth >= 0.0) || !(viewport.maxDepth <= 1.0)) {
1292 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a6,
1293 LayerName,
1294 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.maxDepth (=%f) is not within the "
1295 "[0.0, 1.0] range. %s",
1296 fn_name, param_name, viewport.maxDepth, validation_error_map[VALIDATION_ERROR_150009a6]);
1297 }
1298 }
1299
1300 return skip;
1301}
1302
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001303bool pv_vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1304 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1305 VkPipeline *pPipelines) {
1306 bool skip = false;
1307 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1308 debug_report_data *report_data = device_data->report_data;
1309
1310 if (pCreateInfos != nullptr) {
1311 for (uint32_t i = 0; i < createInfoCount; ++i) {
Petr Kraus299ba622017-11-24 03:09:03 +01001312 bool has_dynamic_viewport = false;
1313 bool has_dynamic_scissor = false;
1314 bool has_dynamic_line_width = false;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001315 bool has_dynamic_viewport_w_scaling_nv = false;
1316 bool has_dynamic_discard_rectangle_ext = false;
1317 bool has_dynamic_sample_locations_ext = false;
Petr Kraus299ba622017-11-24 03:09:03 +01001318 if (pCreateInfos[i].pDynamicState != nullptr) {
1319 const auto &dynamic_state_info = *pCreateInfos[i].pDynamicState;
1320 for (uint32_t state_index = 0; state_index < dynamic_state_info.dynamicStateCount; ++state_index) {
1321 const auto &dynamic_state = dynamic_state_info.pDynamicStates[state_index];
1322 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT) has_dynamic_viewport = true;
1323 if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR) has_dynamic_scissor = true;
1324 if (dynamic_state == VK_DYNAMIC_STATE_LINE_WIDTH) has_dynamic_line_width = true;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001325 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV) has_dynamic_viewport_w_scaling_nv = true;
1326 if (dynamic_state == VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT) has_dynamic_discard_rectangle_ext = true;
1327 if (dynamic_state == VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) has_dynamic_sample_locations_ext = true;
Petr Kraus299ba622017-11-24 03:09:03 +01001328 }
1329 }
1330
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001331 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1332 if (pCreateInfos[i].pVertexInputState != nullptr) {
1333 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
1334 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
1335 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
1336 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1337 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1338 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
1339 "vkCreateGraphicsPipelines: parameter "
1340 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
1341 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1342 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
1343 validation_error_map[VALIDATION_ERROR_14c004d4]);
1344 }
1345
1346 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
1347 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1348 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
1349 "vkCreateGraphicsPipelines: parameter "
1350 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
1351 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
1352 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
1353 validation_error_map[VALIDATION_ERROR_14c004d6]);
1354 }
1355 }
1356
1357 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
1358 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
1359 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
1360 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1361 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
1362 "vkCreateGraphicsPipelines: parameter "
1363 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
1364 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
1365 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
1366 validation_error_map[VALIDATION_ERROR_14a004d8]);
1367 }
1368
1369 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1370 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1371 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
1372 "vkCreateGraphicsPipelines: parameter "
1373 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
1374 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1375 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
1376 validation_error_map[VALIDATION_ERROR_14a004da]);
1377 }
1378
1379 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
1380 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1381 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
1382 "vkCreateGraphicsPipelines: parameter "
1383 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
1384 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
1385 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
1386 validation_error_map[VALIDATION_ERROR_14a004dc]);
1387 }
1388 }
1389 }
1390
1391 if (pCreateInfos[i].pStages != nullptr) {
1392 bool has_control = false;
1393 bool has_eval = false;
1394
1395 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
1396 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1397 has_control = true;
1398 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
1399 has_eval = true;
1400 }
1401 }
1402
1403 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1404 if (has_control && has_eval) {
1405 if (pCreateInfos[i].pTessellationState == nullptr) {
1406 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1407 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
1408 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1409 "shader stage and a tessellation evaluation shader stage, "
1410 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
1411 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
1412 } else {
1413 skip |= validate_struct_pnext(
1414 report_data, "vkCreateGraphicsPipelines",
1415 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
1416 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
1417
1418 skip |= validate_reserved_flags(
1419 report_data, "vkCreateGraphicsPipelines",
1420 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1421 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1422
1423 if (pCreateInfos[i].pTessellationState->sType !=
1424 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1425 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1426 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1427 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1428 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1429 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1430 }
1431
1432 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1433 pCreateInfos[i].pTessellationState->patchControlPoints >
1434 device_data->device_limits.maxTessellationPatchSize) {
1435 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1436 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1437 "vkCreateGraphicsPipelines: invalid parameter "
1438 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1439 "should be >0 and <=%u. %s",
1440 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1441 device_data->device_limits.maxTessellationPatchSize,
1442 validation_error_map[VALIDATION_ERROR_1080097c]);
1443 }
1444 }
1445 }
1446 }
1447
1448 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1449 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1450 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1451 if (pCreateInfos[i].pViewportState == nullptr) {
Petr Krausa6103552017-11-16 21:21:58 +01001452 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1453 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1454 "vkCreateGraphicsPipelines: Rasterization is enabled (pCreateInfos[%" PRIu32
1455 "].pRasterizationState->rasterizerDiscardEnable is VK_FALSE), but pCreateInfos[%" PRIu32
1456 "].pViewportState (=NULL) is not a valid pointer. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001457 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1458 } else {
Petr Krausa6103552017-11-16 21:21:58 +01001459 const auto &viewport_state = *pCreateInfos[i].pViewportState;
1460
1461 if (viewport_state.sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1462 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1463 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b00b, LayerName,
1464 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1465 "].pViewportState->sType is not VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO. %s",
1466 i, validation_error_map[VALIDATION_ERROR_10c2b00b]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001467 }
1468
Petr Krausa6103552017-11-16 21:21:58 +01001469 const VkStructureType allowed_structs_VkPipelineViewportStateCreateInfo[] = {
1470 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
1471 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV};
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001472 skip |= validate_struct_pnext(
1473 report_data, "vkCreateGraphicsPipelines",
Petr Krausa6103552017-11-16 21:21:58 +01001474 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}),
1475 "VkPipelineViewportSwizzleStateCreateInfoNV, VkPipelineViewportWScalingStateCreateInfoNV",
1476 viewport_state.pNext, ARRAY_SIZE(allowed_structs_VkPipelineViewportStateCreateInfo),
1477 allowed_structs_VkPipelineViewportStateCreateInfo, 65, VALIDATION_ERROR_10c1c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001478
1479 skip |= validate_reserved_flags(
1480 report_data, "vkCreateGraphicsPipelines",
1481 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
Petr Krausa6103552017-11-16 21:21:58 +01001482 viewport_state.flags, VALIDATION_ERROR_10c09005);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001483
Petr Krausa6103552017-11-16 21:21:58 +01001484 if (!device_data->physical_device_features.multiViewport) {
1485 if (viewport_state.viewportCount != 1) {
1486 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1487 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1488 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1489 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32
1490 ") is not 1. %s",
1491 i, viewport_state.viewportCount, validation_error_map[VALIDATION_ERROR_10c00980]);
1492 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001493
Petr Krausa6103552017-11-16 21:21:58 +01001494 if (viewport_state.scissorCount != 1) {
1495 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1496 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1497 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1498 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->scissorCount (=%" PRIu32
1499 ") is not 1. %s",
1500 i, viewport_state.scissorCount, validation_error_map[VALIDATION_ERROR_10c00982]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001501 }
Petr Krausa6103552017-11-16 21:21:58 +01001502 } else { // multiViewport enabled
1503 if (viewport_state.viewportCount == 0) {
1504 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1505 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c30a1b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001506 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001507 "].pViewportState->viewportCount is 0. %s",
1508 i, validation_error_map[VALIDATION_ERROR_10c30a1b]);
1509 } else if (viewport_state.viewportCount > device_data->device_limits.maxViewports) {
1510 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1511 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1512 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1513 "].pViewportState->viewportCount (=%" PRIu32
1514 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1515 i, viewport_state.viewportCount, device_data->device_limits.maxViewports,
1516 validation_error_map[VALIDATION_ERROR_10c00984]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001517 }
Petr Krausa6103552017-11-16 21:21:58 +01001518
1519 if (viewport_state.scissorCount == 0) {
1520 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1521 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b61b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001522 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001523 "].pViewportState->scissorCount is 0. %s",
1524 i, validation_error_map[VALIDATION_ERROR_10c2b61b]);
1525 } else if (viewport_state.scissorCount > device_data->device_limits.maxViewports) {
1526 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1527 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1528 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1529 "].pViewportState->scissorCount (=%" PRIu32
1530 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1531 i, viewport_state.scissorCount, device_data->device_limits.maxViewports,
1532 validation_error_map[VALIDATION_ERROR_10c00986]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001533 }
1534 }
1535
Petr Krausa6103552017-11-16 21:21:58 +01001536 if (viewport_state.scissorCount != viewport_state.viewportCount) {
1537 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1538 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1539 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1540 "].pViewportState->scissorCount (=%" PRIu32 ") is not identical to pCreateInfos[%" PRIu32
1541 "].pViewportState->viewportCount (=%" PRIu32 "). %s",
1542 i, viewport_state.scissorCount, i, viewport_state.viewportCount,
1543 validation_error_map[VALIDATION_ERROR_10c00988]);
1544 }
1545
Petr Krausa6103552017-11-16 21:21:58 +01001546 if (!has_dynamic_viewport && viewport_state.viewportCount > 0 && viewport_state.pViewports == nullptr) {
1547 skip |= log_msg(
1548 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1549 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1550 "vkCreateGraphicsPipelines: The viewport state is static (pCreateInfos[%" PRIu32
1551 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001552 "].pViewportState->pViewports (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001553 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1554 }
1555
1556 if (!has_dynamic_scissor && viewport_state.scissorCount > 0 && viewport_state.pScissors == nullptr) {
1557 skip |= log_msg(
1558 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1559 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1560 "vkCreateGraphicsPipelines: The scissor state is static (pCreateInfos[%" PRIu32
1561 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_SCISSOR), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001562 "].pViewportState->pScissors (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001563 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1564 }
1565
Petr Krausb3fcdb42018-01-09 22:09:09 +01001566 // validate the VkViewports
1567 if (!has_dynamic_viewport && viewport_state.pViewports) {
1568 for (uint32_t viewport_i = 0; viewport_i < viewport_state.viewportCount; ++viewport_i) {
1569 const auto &viewport = viewport_state.pViewports[viewport_i]; // will crash on invalid ptr
1570 const char fn_name[] = "vkCreateGraphicsPipelines";
1571 const std::string param_name = "pCreateInfos[" + std::to_string(i) + "].pViewportState->pViewports[" +
1572 std::to_string(viewport_i) + "]";
1573 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
1574 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
1575 }
1576 }
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001577
1578 if (has_dynamic_viewport_w_scaling_nv && !device_data->extensions.vk_nv_clip_space_w_scaling) {
1579 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1580 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1581 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001582 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001583 "VK_NV_clip_space_w_scaling extension is not enabled.",
1584 i);
1585 }
1586
1587 if (has_dynamic_discard_rectangle_ext && !device_data->extensions.vk_ext_discard_rectangles) {
1588 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1589 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1590 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001591 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001592 "VK_EXT_discard_rectangles extension is not enabled.",
1593 i);
1594 }
1595
1596 if (has_dynamic_sample_locations_ext && !device_data->extensions.vk_ext_sample_locations) {
1597 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1598 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1599 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001600 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001601 "VK_EXT_sample_locations extension is not enabled.",
1602 i);
1603 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001604 }
1605
1606 if (pCreateInfos[i].pMultisampleState == nullptr) {
1607 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1608 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1609 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1610 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1611 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1612 } else {
Dave Houltonb3bbec72018-01-17 10:13:33 -07001613 const VkStructureType valid_next_stypes[] = {LvlTypeMap<VkPipelineCoverageModulationStateCreateInfoNV>::kSType,
1614 LvlTypeMap<VkPipelineCoverageToColorStateCreateInfoNV>::kSType,
1615 LvlTypeMap<VkPipelineSampleLocationsStateCreateInfoEXT>::kSType};
Mike Schuchardt97662b02017-12-06 13:31:29 -07001616 const char *valid_struct_names =
Dave Houltona9df0ce2018-02-07 10:51:23 -07001617 "VkPipelineCoverageModulationStateCreateInfoNV, VkPipelineCoverageToColorStateCreateInfoNV, "
John Zulauf96b0e422017-11-14 11:43:19 -07001618 "VkPipelineSampleLocationsStateCreateInfoEXT";
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001619 skip |= validate_struct_pnext(
1620 report_data, "vkCreateGraphicsPipelines",
John Zulauf96b0e422017-11-14 11:43:19 -07001621 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}),
1622 valid_struct_names, pCreateInfos[i].pMultisampleState->pNext, 3, valid_next_stypes, GeneratedHeaderVersion,
1623 VALIDATION_ERROR_1001c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001624
1625 skip |= validate_reserved_flags(
1626 report_data, "vkCreateGraphicsPipelines",
1627 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1628 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1629
1630 skip |= validate_bool32(
1631 report_data, "vkCreateGraphicsPipelines",
1632 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1633 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1634
1635 skip |= validate_array(
1636 report_data, "vkCreateGraphicsPipelines",
1637 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1638 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1639 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1640 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1641
1642 skip |= validate_bool32(
1643 report_data, "vkCreateGraphicsPipelines",
1644 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1645 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1646
1647 skip |= validate_bool32(
1648 report_data, "vkCreateGraphicsPipelines",
1649 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1650 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1651
1652 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1653 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1654 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1655 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1656 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1657 i);
1658 }
John Zulauf7acac592017-11-06 11:15:53 -07001659 if (pCreateInfos[i].pMultisampleState->sampleShadingEnable == VK_TRUE) {
1660 if (!device_data->physical_device_features.sampleRateShading) {
1661 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1662 __LINE__, VALIDATION_ERROR_10000620, LayerName,
1663 "vkCreateGraphicsPipelines(): parameter "
1664 "pCreateInfos[%d].pMultisampleState->sampleShadingEnable: %s",
1665 i, validation_error_map[VALIDATION_ERROR_10000620]);
1666 }
1667 // TODO Add documentation issue about when minSampleShading must be in range and when it is ignored
1668 // For now a "least noise" test *only* when sampleShadingEnable is VK_TRUE.
1669 if (!in_inclusive_range(pCreateInfos[i].pMultisampleState->minSampleShading, 0.F, 1.0F)) {
1670 skip |= log_msg(
1671 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1672 VALIDATION_ERROR_10000624, LayerName,
1673 "vkCreateGraphicsPipelines(): parameter pCreateInfos[%d].pMultisampleState->minSampleShading: %s",
1674 i, validation_error_map[VALIDATION_ERROR_10000624]);
1675 }
1676 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001677 }
1678
Petr Krause91f7a12017-12-14 20:57:36 +01001679 bool uses_color_attachment = false;
1680 bool uses_depthstencil_attachment = false;
1681 {
1682 const auto subpasses_uses_it = device_data->renderpasses_states.find(pCreateInfos[i].renderPass);
1683 if (subpasses_uses_it != device_data->renderpasses_states.end()) {
1684 const auto &subpasses_uses = subpasses_uses_it->second;
1685 if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[i].subpass))
1686 uses_color_attachment = true;
1687 if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[i].subpass))
1688 uses_depthstencil_attachment = true;
1689 }
1690 }
1691
1692 if (pCreateInfos[i].pDepthStencilState != nullptr && uses_depthstencil_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001693 skip |= validate_struct_pnext(
1694 report_data, "vkCreateGraphicsPipelines",
1695 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1696 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1697
1698 skip |= validate_reserved_flags(
1699 report_data, "vkCreateGraphicsPipelines",
1700 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1701 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1702
1703 skip |= validate_bool32(
1704 report_data, "vkCreateGraphicsPipelines",
1705 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1706 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1707
1708 skip |= validate_bool32(
1709 report_data, "vkCreateGraphicsPipelines",
1710 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1711 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1712
1713 skip |= validate_ranged_enum(
1714 report_data, "vkCreateGraphicsPipelines",
1715 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1716 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1717 VALIDATION_ERROR_0f604001);
1718
1719 skip |= validate_bool32(
1720 report_data, "vkCreateGraphicsPipelines",
1721 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1722 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1723
1724 skip |= validate_bool32(
1725 report_data, "vkCreateGraphicsPipelines",
1726 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1727 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1728
1729 skip |= validate_ranged_enum(
1730 report_data, "vkCreateGraphicsPipelines",
1731 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1732 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1733 VALIDATION_ERROR_13a08601);
1734
1735 skip |= validate_ranged_enum(
1736 report_data, "vkCreateGraphicsPipelines",
1737 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1738 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1739 VALIDATION_ERROR_13a27801);
1740
1741 skip |= validate_ranged_enum(
1742 report_data, "vkCreateGraphicsPipelines",
1743 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1744 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1745 VALIDATION_ERROR_13a04201);
1746
1747 skip |= validate_ranged_enum(
1748 report_data, "vkCreateGraphicsPipelines",
1749 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1750 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1751 VALIDATION_ERROR_0f604001);
1752
1753 skip |= validate_ranged_enum(
1754 report_data, "vkCreateGraphicsPipelines",
1755 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1756 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1757 VALIDATION_ERROR_13a08601);
1758
1759 skip |= validate_ranged_enum(
1760 report_data, "vkCreateGraphicsPipelines",
1761 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1762 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1763 VALIDATION_ERROR_13a27801);
1764
1765 skip |= validate_ranged_enum(
1766 report_data, "vkCreateGraphicsPipelines",
1767 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1768 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1769 VALIDATION_ERROR_13a04201);
1770
1771 skip |= validate_ranged_enum(
1772 report_data, "vkCreateGraphicsPipelines",
1773 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1774 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1775 VALIDATION_ERROR_0f604001);
1776
1777 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1778 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1779 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1780 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1781 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1782 i);
1783 }
1784 }
1785
Petr Krause91f7a12017-12-14 20:57:36 +01001786 if (pCreateInfos[i].pColorBlendState != nullptr && uses_color_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001787 skip |= validate_struct_pnext(
1788 report_data, "vkCreateGraphicsPipelines",
1789 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1790 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1791
1792 skip |= validate_reserved_flags(
1793 report_data, "vkCreateGraphicsPipelines",
1794 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1795 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1796
1797 skip |= validate_bool32(
1798 report_data, "vkCreateGraphicsPipelines",
1799 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1800 pCreateInfos[i].pColorBlendState->logicOpEnable);
1801
1802 skip |= validate_array(
1803 report_data, "vkCreateGraphicsPipelines",
1804 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1805 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1806 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1807 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1808
1809 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1810 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1811 ++attachmentIndex) {
1812 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1813 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1814 ParameterName::IndexVector{i, attachmentIndex}),
1815 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1816
1817 skip |= validate_ranged_enum(
1818 report_data, "vkCreateGraphicsPipelines",
1819 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1820 ParameterName::IndexVector{i, attachmentIndex}),
1821 "VkBlendFactor", AllVkBlendFactorEnums,
1822 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1823 VALIDATION_ERROR_0f22cc01);
1824
1825 skip |= validate_ranged_enum(
1826 report_data, "vkCreateGraphicsPipelines",
1827 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1828 ParameterName::IndexVector{i, attachmentIndex}),
1829 "VkBlendFactor", AllVkBlendFactorEnums,
1830 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1831 VALIDATION_ERROR_0f207001);
1832
1833 skip |= validate_ranged_enum(
1834 report_data, "vkCreateGraphicsPipelines",
1835 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1836 ParameterName::IndexVector{i, attachmentIndex}),
1837 "VkBlendOp", AllVkBlendOpEnums,
1838 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1839 VALIDATION_ERROR_0f202001);
1840
1841 skip |= validate_ranged_enum(
1842 report_data, "vkCreateGraphicsPipelines",
1843 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1844 ParameterName::IndexVector{i, attachmentIndex}),
1845 "VkBlendFactor", AllVkBlendFactorEnums,
1846 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1847 VALIDATION_ERROR_0f22c601);
1848
1849 skip |= validate_ranged_enum(
1850 report_data, "vkCreateGraphicsPipelines",
1851 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1852 ParameterName::IndexVector{i, attachmentIndex}),
1853 "VkBlendFactor", AllVkBlendFactorEnums,
1854 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1855 VALIDATION_ERROR_0f206a01);
1856
1857 skip |= validate_ranged_enum(
1858 report_data, "vkCreateGraphicsPipelines",
1859 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1860 ParameterName::IndexVector{i, attachmentIndex}),
1861 "VkBlendOp", AllVkBlendOpEnums,
1862 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1863 VALIDATION_ERROR_0f200801);
1864
1865 skip |=
1866 validate_flags(report_data, "vkCreateGraphicsPipelines",
1867 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1868 ParameterName::IndexVector{i, attachmentIndex}),
1869 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1870 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1871 false, false, VALIDATION_ERROR_0f202201);
1872 }
1873 }
1874
1875 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1876 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1877 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1878 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1879 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1880 i);
1881 }
1882
1883 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1884 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1885 skip |= validate_ranged_enum(
1886 report_data, "vkCreateGraphicsPipelines",
1887 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1888 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1889 }
1890 }
1891 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001892
Petr Kraus9752aae2017-11-24 03:05:50 +01001893 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1894 if (pCreateInfos[i].basePipelineIndex != -1) {
1895 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001896 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1897 __LINE__, VALIDATION_ERROR_096005a8, LayerName,
1898 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be "
1899 "VK_NULL_HANDLE if pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag "
1900 "and pCreateInfos->basePipelineIndex is not -1. %s",
1901 validation_error_map[VALIDATION_ERROR_096005a8]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001902 }
1903 }
1904
Petr Kraus9752aae2017-11-24 03:05:50 +01001905 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
1906 if (pCreateInfos[i].basePipelineIndex != -1) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001907 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1908 __LINE__, VALIDATION_ERROR_096005aa, LayerName,
1909 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1910 "pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and "
1911 "pCreateInfos->basePipelineHandle is not VK_NULL_HANDLE. %s",
1912 validation_error_map[VALIDATION_ERROR_096005aa]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001913 }
1914 }
1915 }
1916
Petr Kraus9752aae2017-11-24 03:05:50 +01001917 if (pCreateInfos[i].pRasterizationState) {
1918 if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001919 (device_data->physical_device_features.fillModeNonSolid == false)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001920 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1921 __LINE__, DEVICE_FEATURE, LayerName,
1922 "vkCreateGraphicsPipelines parameter, VkPolygonMode "
1923 "pCreateInfos->pRasterizationState->polygonMode cannot be VK_POLYGON_MODE_POINT or "
1924 "VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001925 }
Petr Kraus299ba622017-11-24 03:09:03 +01001926
1927 if (!has_dynamic_line_width && !device_data->physical_device_features.wideLines &&
1928 (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
1929 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1930 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, 0, __LINE__, VALIDATION_ERROR_096005da, LayerName,
1931 "The line width state is static (pCreateInfos[%" PRIu32
1932 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
1933 "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
1934 "].pRasterizationState->lineWidth (=%f) is not 1.0. %s",
1935 i, i, pCreateInfos[i].pRasterizationState->lineWidth,
1936 validation_error_map[VALIDATION_ERROR_096005da]);
1937 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001938 }
1939
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001940 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1941 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1942 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1943 pCreateInfos[i].pStages[j].pName);
1944 }
1945 }
1946 }
1947
1948 return skip;
1949}
1950
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001951bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1952 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1953 VkPipeline *pPipelines) {
1954 bool skip = false;
1955 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1956
1957 for (uint32_t i = 0; i < createInfoCount; i++) {
1958 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1959 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1960 pCreateInfos[i].stage.pName);
1961 }
1962
1963 return skip;
1964}
1965
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001966bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1967 VkSampler *pSampler) {
1968 bool skip = false;
1969 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1970 debug_report_data *report_data = device_data->report_data;
1971
1972 if (pCreateInfo != nullptr) {
John Zulauf71968502017-10-26 13:51:15 -06001973 const auto &features = device_data->physical_device_features;
1974 const auto &limits = device_data->device_limits;
1975 if (pCreateInfo->anisotropyEnable == VK_TRUE) {
1976 if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
1977 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1978 VALIDATION_ERROR_1260085e, LayerName,
1979 "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found. %s",
1980 "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
1981 "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy,
1982 validation_error_map[VALIDATION_ERROR_1260085e]);
1983 }
1984
1985 // Anistropy cannot be enabled in sampler unless enabled as a feature
1986 if (features.samplerAnisotropy == VK_FALSE) {
1987 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1988 VALIDATION_ERROR_1260085c, LayerName,
1989 "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE. %s",
1990 "pCreateInfo->anisotropyEnable", validation_error_map[VALIDATION_ERROR_1260085c]);
1991 }
1992
1993 // Anistropy and unnormalized coordinates cannot be enabled simultaneously
1994 if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
1995 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1996 VALIDATION_ERROR_12600868, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001997 "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates must "
1998 "not both be VK_TRUE. %s",
John Zulauf71968502017-10-26 13:51:15 -06001999 validation_error_map[VALIDATION_ERROR_12600868]);
2000 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002001 }
2002
2003 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
2004 if (pCreateInfo->compareEnable == VK_TRUE) {
2005 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
2006 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
2007 }
2008
2009 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
2010 // valid VkBorderColor value
2011 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2012 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2013 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
2014 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
2015 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
2016 }
2017
2018 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
2019 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
2020 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
2021 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2022 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2023 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
2024 skip |=
2025 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2026 VALIDATION_ERROR_1260086e, LayerName,
2027 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
2028 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
2029 validation_error_map[VALIDATION_ERROR_1260086e]);
2030 }
John Zulauf275805c2017-10-26 15:34:49 -06002031
2032 // Checks for the IMG cubic filtering extension
2033 if (device_data->extensions.vk_img_filter_cubic) {
2034 if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
2035 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002036 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2037 VALIDATION_ERROR_12600872, LayerName,
2038 "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter "
2039 "are VK_FILTER_CUBIC_IMG. %s",
2040 validation_error_map[VALIDATION_ERROR_12600872]);
John Zulauf275805c2017-10-26 15:34:49 -06002041 }
2042 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002043 }
2044
2045 return skip;
2046}
2047
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002048bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2049 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
2050 bool skip = false;
2051 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2052 debug_report_data *report_data = device_data->report_data;
2053
2054 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2055 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
2056 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
2057 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
2058 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
2059 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
2060 // valid VkSampler handles
2061 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2062 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
2063 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
2064 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
2065 ++descriptor_index) {
2066 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
2067 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2068 __LINE__, REQUIRED_PARAMETER, LayerName,
2069 "vkCreateDescriptorSetLayout: required parameter "
Dave Houltona9df0ce2018-02-07 10:51:23 -07002070 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d] specified as VK_NULL_HANDLE",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002071 i, descriptor_index);
2072 }
2073 }
2074 }
2075
2076 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
2077 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
2078 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002079 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2080 __LINE__, VALIDATION_ERROR_04e00236, LayerName,
2081 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
2082 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits "
2083 "values. %s",
2084 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002085 }
2086 }
2087 }
2088 }
2089
2090 return skip;
2091}
2092
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002093bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
2094 const VkDescriptorSet *pDescriptorSets) {
2095 bool skip = false;
2096 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2097 debug_report_data *report_data = device_data->report_data;
2098
2099 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2100 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2101 // validate_array()
2102 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
2103 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2104 return skip;
2105}
2106
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002107bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
2108 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
2109 bool skip = false;
2110 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2111 debug_report_data *report_data = device_data->report_data;
2112
2113 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2114 if (pDescriptorWrites != NULL) {
2115 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
2116 // descriptorCount must be greater than 0
2117 if (pDescriptorWrites[i].descriptorCount == 0) {
2118 skip |=
2119 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2120 VALIDATION_ERROR_15c0441b, LayerName,
2121 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
2122 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
2123 }
2124
2125 // dstSet must be a valid VkDescriptorSet handle
2126 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2127 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
2128 pDescriptorWrites[i].dstSet);
2129
2130 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2131 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
2132 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
2133 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
2134 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
2135 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
2136 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2137 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
2138 if (pDescriptorWrites[i].pImageInfo == nullptr) {
2139 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2140 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
2141 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2142 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
2143 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
2144 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
2145 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
2146 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
2147 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
2148 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
2149 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
2150 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2151 ++descriptor_index) {
2152 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2153 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
2154 ParameterName::IndexVector{i, descriptor_index}),
2155 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
2156 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
2157 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
2158 ParameterName::IndexVector{i, descriptor_index}),
2159 "VkImageLayout", AllVkImageLayoutEnums,
2160 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
2161 VALIDATION_ERROR_UNDEFINED);
2162 }
2163 }
2164 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2165 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2166 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
2167 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2168 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
2169 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
2170 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
2171 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
2172 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2173 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
2174 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2175 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
2176 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
2177 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
2178 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
2179 } else {
2180 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
2181 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2182 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
2183 ParameterName::IndexVector{i, descriptorIndex}),
2184 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
2185 }
2186 }
2187 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
2188 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
2189 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
2190 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
2191 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
2192 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2193 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
2194 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2195 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
2196 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
2197 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
2198 } else {
2199 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2200 ++descriptor_index) {
2201 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2202 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
2203 ParameterName::IndexVector{i, descriptor_index}),
2204 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
2205 }
2206 }
2207 }
2208
2209 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2210 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
2211 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
2212 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2213 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2214 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
2215 skip |= log_msg(
2216 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2217 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
2218 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2219 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2220 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
2221 validation_error_map[VALIDATION_ERROR_15c0028e]);
2222 }
2223 }
2224 }
2225 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2226 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2227 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
2228 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2229 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2230 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
2231 skip |= log_msg(
2232 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2233 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
2234 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2235 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2236 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
2237 validation_error_map[VALIDATION_ERROR_15c00290]);
2238 }
2239 }
2240 }
2241 }
2242 }
2243 }
2244 return skip;
2245}
2246
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002247bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2248 VkRenderPass *pRenderPass) {
2249 bool skip = false;
2250 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2251 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
2252
2253 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
2254 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
2255 std::stringstream ss;
2256 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
2257 << validation_error_map[VALIDATION_ERROR_00809201];
2258 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2259 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
2260 }
2261 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
2262 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
2263 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2264 __LINE__, VALIDATION_ERROR_00800696, "DL",
2265 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
2266 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
2267 i, validation_error_map[VALIDATION_ERROR_00800696]);
2268 }
2269 }
2270
2271 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2272 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
2273 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2274 __LINE__, VALIDATION_ERROR_1400069a, "DL",
2275 "Cannot create a render pass with %d color attachments. Max is %d. %s",
2276 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
2277 validation_error_map[VALIDATION_ERROR_1400069a]);
2278 }
2279 }
2280 return skip;
2281}
2282
2283bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
2284 const VkCommandBuffer *pCommandBuffers) {
2285 bool skip = false;
2286 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2287 debug_report_data *report_data = device_data->report_data;
2288
2289 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2290 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2291 // validate_array()
2292 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
2293 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2294 return skip;
2295}
2296
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002297bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
2298 bool skip = false;
2299 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2300 debug_report_data *report_data = device_data->report_data;
2301 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
2302
2303 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2304 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
2305 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
2306 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
2307 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
2308
2309 if (pBeginInfo->pInheritanceInfo != NULL) {
2310 skip |=
2311 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
2312 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
2313
2314 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
2315 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
2316
2317 // TODO: This only needs to be validated when the inherited queries feature is enabled
2318 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2319 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
2320
2321 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
2322 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
2323 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
2324 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
2325 }
2326
2327 if (pInfo != NULL) {
2328 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2329 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2330 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
2331 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
2332 "inheritedQueries. %s",
2333 validation_error_map[VALIDATION_ERROR_02a00070]);
2334 }
2335 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2336 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2337 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
2338 VALIDATION_ERROR_02a00072);
2339 }
2340 }
2341
2342 return skip;
2343}
2344
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002345bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
2346 const VkViewport *pViewports) {
2347 bool skip = false;
2348 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2349
Petr Krausd55e77c2018-01-09 22:09:25 +01002350 if (!device_data->physical_device_features.multiViewport) {
2351 if (firstViewport != 0) {
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_1e000990, LayerName,
2355 "vkCmdSetViewport: The multiViewport feature is disabled, but firstViewport (=%" PRIu32 ") is not 0. %s",
Jeremy Kniager72437be2018-01-25 11:41:20 -07002356 firstViewport, validation_error_map[VALIDATION_ERROR_1e000990]);
Petr Krausd55e77c2018-01-09 22:09:25 +01002357 }
2358 if (viewportCount > 1) {
2359 skip |=
2360 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2361 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000992, LayerName,
2362 "vkCmdSetViewport: The multiViewport feature is disabled, but viewportCount (=%" PRIu32 ") is not 1. %s",
2363 viewportCount, validation_error_map[VALIDATION_ERROR_1e000992]);
2364 }
2365 } else { // multiViewport enabled
Petr Kraus7dfeed12018-02-27 20:51:20 +01002366 const uint64_t sum = static_cast<uint64_t>(firstViewport) + static_cast<uint64_t>(viewportCount);
Petr Krausd55e77c2018-01-09 22:09:25 +01002367 if (sum > device_data->device_limits.maxViewports) {
2368 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2369 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e00098e, LayerName,
2370 "vkCmdSetViewport: firstViewport + viewportCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2371 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2372 firstViewport, viewportCount, sum, device_data->device_limits.maxViewports,
2373 validation_error_map[VALIDATION_ERROR_1e00098e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002374 }
2375 }
Petr Krausb3fcdb42018-01-09 22:09:09 +01002376
2377 if (pViewports) {
2378 for (uint32_t viewport_i = 0; viewport_i < viewportCount; ++viewport_i) {
2379 const auto &viewport = pViewports[viewport_i]; // will crash on invalid ptr
2380 const char fn_name[] = "vkCmdSetViewport";
2381 const std::string param_name = "pViewports[" + std::to_string(viewport_i) + "]";
2382 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
2383 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer));
2384 }
2385 }
2386
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002387 return skip;
2388}
2389
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002390bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
2391 bool skip = false;
2392 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2393 debug_report_data *report_data = device_data->report_data;
2394
Petr Kraus6260f0a2018-02-27 21:15:55 +01002395 if (!device_data->physical_device_features.multiViewport) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002396 if (firstScissor != 0) {
Petr Kraus6260f0a2018-02-27 21:15:55 +01002397 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2398 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a2, LayerName,
2399 "vkCmdSetScissor: The multiViewport feature is disabled, but firstScissor (=%" PRIu32 ") is not 0. %s",
2400 firstScissor, validation_error_map[VALIDATION_ERROR_1d8004a2]);
2401 }
2402 if (scissorCount > 1) {
2403 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2404 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a4, LayerName,
2405 "vkCmdSetScissor: The multiViewport feature is disabled, but scissorCount (=%" PRIu32 ") is not 1. %s",
2406 scissorCount, validation_error_map[VALIDATION_ERROR_1d8004a4]);
2407 }
2408 } else { // multiViewport enabled
2409 const uint64_t sum = static_cast<uint64_t>(firstScissor) + static_cast<uint64_t>(scissorCount);
2410 if (sum > device_data->device_limits.maxViewports) {
2411 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2412 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a0, LayerName,
2413 "vkCmdSetScissor: firstScissor + scissorCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2414 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2415 firstScissor, scissorCount, sum, device_data->device_limits.maxViewports,
2416 validation_error_map[VALIDATION_ERROR_1d8004a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002417 }
2418 }
2419
Petr Kraus6260f0a2018-02-27 21:15:55 +01002420 if (pScissors) {
2421 for (uint32_t scissor_i = 0; scissor_i < scissorCount; ++scissor_i) {
2422 const auto &scissor = pScissors[scissor_i]; // will crash on invalid ptr
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002423
Petr Kraus6260f0a2018-02-27 21:15:55 +01002424 if (scissor.offset.x < 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.x (=%" PRIi32 ") is negative. %s", scissor_i,
2428 scissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2429 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002430
Petr Kraus6260f0a2018-02-27 21:15:55 +01002431 if (scissor.offset.y < 0) {
2432 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2433 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2434 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.y (=%" PRIi32 ") is negative. %s", scissor_i,
2435 scissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2436 }
2437
2438 const int64_t x_sum = static_cast<int64_t>(scissor.offset.x) + static_cast<int64_t>(scissor.extent.width);
2439 if (x_sum > INT32_MAX) {
2440 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2441 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a8, LayerName,
2442 "vkCmdSetScissor: offset.x + extent.width (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2443 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2444 scissor.offset.x, scissor.extent.width, x_sum, scissor_i,
2445 validation_error_map[VALIDATION_ERROR_1d8004a8]);
2446 }
2447
2448 const int64_t y_sum = static_cast<int64_t>(scissor.offset.y) + static_cast<int64_t>(scissor.extent.height);
2449 if (y_sum > INT32_MAX) {
2450 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2451 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004aa, LayerName,
2452 "vkCmdSetScissor: offset.y + extent.height (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2453 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2454 scissor.offset.y, scissor.extent.height, y_sum, scissor_i,
2455 validation_error_map[VALIDATION_ERROR_1d8004aa]);
2456 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002457 }
2458 }
Petr Kraus6260f0a2018-02-27 21:15:55 +01002459
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002460 return skip;
2461}
2462
Petr Kraus299ba622017-11-24 03:09:03 +01002463bool pv_vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
2464 bool skip = false;
2465 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2466 debug_report_data *report_data = device_data->report_data;
2467
2468 if (!device_data->physical_device_features.wideLines && (lineWidth != 1.0f)) {
2469 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2470 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d600628, LayerName,
2471 "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0. %s", lineWidth,
2472 validation_error_map[VALIDATION_ERROR_1d600628]);
2473 }
2474
2475 return skip;
2476}
2477
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002478bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2479 uint32_t firstInstance) {
2480 bool skip = false;
2481 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2482 if (vertexCount == 0) {
2483 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount 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 vertexCount, is 0");
2487 }
2488
2489 if (instanceCount == 0) {
2490 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2491 // this an error or leave as is.
2492 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2493 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2494 }
2495 return skip;
2496}
2497
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002498bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2499 bool skip = false;
2500 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2501
2502 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2503 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2504 __LINE__, DEVICE_FEATURE, LayerName,
2505 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2506 }
2507 return skip;
2508}
2509
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002510bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2511 uint32_t stride) {
2512 bool skip = false;
2513 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2514 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2515 skip |=
2516 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2517 DEVICE_FEATURE, LayerName,
2518 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2519 }
2520 return skip;
2521}
2522
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002523bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2524 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2525 bool skip = false;
2526 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2527
Dave Houltonf5217612018-02-02 16:18:52 -07002528 VkImageAspectFlags legal_aspect_flags =
2529 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2530 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2531 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2532 }
2533
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002534 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002535 if ((pRegions->srcSubresource.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->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2540 validation_error_map[VALIDATION_ERROR_0a600c01]);
2541 }
Dave Houltonf5217612018-02-02 16:18:52 -07002542 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002543 skip |= log_msg(
2544 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2545 VALIDATION_ERROR_0a600c01, LayerName,
2546 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2547 validation_error_map[VALIDATION_ERROR_0a600c01]);
2548 }
2549 }
2550 return skip;
2551}
2552
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002553bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2554 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2555 bool skip = false;
2556 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2557
Dave Houltonf5217612018-02-02 16:18:52 -07002558 VkImageAspectFlags legal_aspect_flags =
2559 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2560 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2561 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2562 }
2563
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002564 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002565 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002566 skip |= log_msg(
2567 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2568 UNRECOGNIZED_VALUE, LayerName,
2569 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2570 }
Dave Houltonf5217612018-02-02 16:18:52 -07002571 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002572 skip |= log_msg(
2573 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2574 UNRECOGNIZED_VALUE, LayerName,
2575 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2576 }
2577 }
2578 return skip;
2579}
2580
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002581bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2582 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2583 bool skip = false;
2584 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2585
Dave Houltonf5217612018-02-02 16:18:52 -07002586 VkImageAspectFlags legal_aspect_flags =
2587 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2588 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2589 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2590 }
2591
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002592 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002593 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002594 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2595 __LINE__, UNRECOGNIZED_VALUE, LayerName,
2596 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an "
2597 "unrecognized enumerator");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002598 }
2599 }
2600 return skip;
2601}
2602
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002603bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2604 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2605 bool skip = false;
2606 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2607
Dave Houltonf5217612018-02-02 16:18:52 -07002608 VkImageAspectFlags legal_aspect_flags =
2609 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2610 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2611 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2612 }
2613
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002614 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002615 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002616 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2617 UNRECOGNIZED_VALUE, LayerName,
2618 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2619 "enumerator");
2620 }
2621 }
2622 return skip;
2623}
2624
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002625bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2626 const void *pData) {
2627 bool skip = false;
2628 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2629
2630 if (dstOffset & 3) {
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_1e400048, LayerName,
2633 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2634 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2635 }
2636
2637 if ((dataSize <= 0) || (dataSize > 65536)) {
2638 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2639 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2640 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2641 "), must be greater than zero and less than or equal to 65536. %s",
2642 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2643 } else if (dataSize & 3) {
2644 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2645 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2646 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2647 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2648 }
2649 return skip;
2650}
2651
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002652bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2653 uint32_t data) {
2654 bool skip = false;
2655 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2656
2657 if (dstOffset & 3) {
2658 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2659 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2660 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2661 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2662 }
2663
2664 if (size != VK_WHOLE_SIZE) {
2665 if (size <= 0) {
2666 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2667 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2668 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2669 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2670 } else if (size & 3) {
2671 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2672 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2673 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2674 validation_error_map[VALIDATION_ERROR_1b400038]);
2675 }
2676 }
2677 return skip;
2678}
2679
2680VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2681 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2682}
2683
2684VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2685 VkLayerProperties *pProperties) {
2686 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2687}
2688
2689VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2690 VkExtensionProperties *pProperties) {
2691 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2692 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2693
2694 return VK_ERROR_LAYER_NOT_PRESENT;
2695}
2696
2697VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2698 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2699 // Parameter_validation does not have any physical device extensions
2700 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2701 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2702
2703 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2704 bool skip =
2705 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2706 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2707 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2708
2709 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2710}
2711
2712static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2713 if (!flag) {
2714 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2715 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2716 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2717 extension_name);
2718 }
2719
2720 return false;
2721}
2722
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002723bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2724 VkSwapchainKHR *pSwapchain) {
2725 bool skip = false;
2726 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2727 debug_report_data *report_data = device_data->report_data;
2728
Petr Krause5c37652018-01-05 04:05:12 +01002729 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, VK_NULL_HANDLE, LayerName,
2730 "vkCreateSwapchainKHR"};
2731
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002732 if (pCreateInfo != nullptr) {
2733 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2734 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002735 skip |=
2736 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2737 DEVICE_FEATURE, LayerName,
2738 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The textureCompressionETC2 "
2739 "feature is not enabled: neither ETC2 nor EAC formats can be used to create images.",
2740 string_VkFormat(pCreateInfo->imageFormat));
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002741 }
2742
2743 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2744 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2745 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2746 DEVICE_FEATURE, LayerName,
2747 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2748 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2749 string_VkFormat(pCreateInfo->imageFormat));
2750 }
2751
2752 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2753 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2754 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2755 DEVICE_FEATURE, LayerName,
2756 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2757 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2758 string_VkFormat(pCreateInfo->imageFormat));
2759 }
2760
2761 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2762 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2763 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2764 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2765 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2766 VALIDATION_ERROR_146009fc, LayerName,
2767 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2768 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2769 validation_error_map[VALIDATION_ERROR_146009fc]);
2770 }
2771
2772 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2773 // queueFamilyIndexCount uint32_t values
2774 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2775 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2776 VALIDATION_ERROR_146009fa, LayerName,
2777 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2778 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2779 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2780 validation_error_map[VALIDATION_ERROR_146009fa]);
2781 } else {
2782 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2783 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2784 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2785 INVALID_USAGE, false, "", "");
2786 }
2787 }
2788
Petr Krause5c37652018-01-05 04:05:12 +01002789 skip |= ValidateGreaterThanZero(pCreateInfo->imageArrayLayers, "pCreateInfo->imageArrayLayers", VALIDATION_ERROR_146009f6,
2790 log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002791 }
2792
2793 return skip;
2794}
2795
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002796bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2797 bool skip = false;
2798 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2799
2800 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002801 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2802 if (present_regions) {
2803 // TODO: This and all other pNext extension dependencies should be added to code-generation
2804 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2805 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2806 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2807 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2808 __LINE__, INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002809 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i but VkPresentRegionsKHR "
2810 "extension swapchainCount is %i. These values must be equal.",
John Zulaufde972ac2017-10-26 12:07:05 -06002811 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2812 }
2813 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2814 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2815 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2816 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2817 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2818 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2819 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002820 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2821 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2822 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002823 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002824 }
2825 }
2826
2827 return skip;
2828}
2829
2830#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002831bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2832 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2833 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2834 bool skip = false;
2835
2836 if (pCreateInfo->hwnd == nullptr) {
2837 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2838 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2839 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2840 validation_error_map[VALIDATION_ERROR_15a00a38]);
2841 }
2842
2843 return skip;
2844}
2845#endif // VK_USE_PLATFORM_WIN32_KHR
2846
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002847bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2848 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2849 if (pNameInfo->pObjectName) {
2850 device_data->report_data->debugObjectNameMap->insert(
2851 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2852 } else {
2853 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2854 }
2855 return false;
2856}
2857
Petr Krausc8655be2017-09-27 18:56:51 +02002858bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2859 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2860 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2861 bool skip = false;
2862
2863 if (pCreateInfo) {
2864 if (pCreateInfo->maxSets <= 0) {
2865 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2866 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2867 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2868 validation_error_map[VALIDATION_ERROR_0480025a]);
2869 }
2870
2871 if (pCreateInfo->pPoolSizes) {
2872 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2873 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2874 skip |= log_msg(
2875 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2876 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2877 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2878 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2879 }
2880 }
2881 }
2882 }
2883
2884 return skip;
2885}
2886
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002887bool pv_vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2888 bool skip = false;
2889 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2890
2891 if (groupCountX > device_data->device_limits.maxComputeWorkGroupCount[0]) {
2892 skip |= log_msg(
2893 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2894 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00304, LayerName,
2895 "vkCmdDispatch(): groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2896 groupCountX, device_data->device_limits.maxComputeWorkGroupCount[0], validation_error_map[VALIDATION_ERROR_19c00304]);
2897 }
2898
2899 if (groupCountY > device_data->device_limits.maxComputeWorkGroupCount[1]) {
2900 skip |= log_msg(
2901 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2902 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00306, LayerName,
2903 "vkCmdDispatch(): groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2904 groupCountY, device_data->device_limits.maxComputeWorkGroupCount[1], validation_error_map[VALIDATION_ERROR_19c00306]);
2905 }
2906
2907 if (groupCountZ > device_data->device_limits.maxComputeWorkGroupCount[2]) {
2908 skip |= log_msg(
2909 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2910 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00308, LayerName,
2911 "vkCmdDispatch(): groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2912 groupCountZ, device_data->device_limits.maxComputeWorkGroupCount[2], validation_error_map[VALIDATION_ERROR_19c00308]);
2913 }
2914
2915 return skip;
2916}
2917
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002918bool pv_vkCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002919 uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2920 bool skip = false;
2921 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2922
2923 // Paired if {} else if {} tests used to avoid any possible uint underflow
2924 uint32_t limit = device_data->device_limits.maxComputeWorkGroupCount[0];
2925 if (baseGroupX >= limit) {
2926 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2927 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034a, LayerName,
2928 "vkCmdDispatch(): baseGroupX (%" PRIu32
2929 ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2930 baseGroupX, limit, validation_error_map[VALIDATION_ERROR_19e0034a]);
2931 } else if (groupCountX > (limit - baseGroupX)) {
2932 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2933 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00350, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002934 "vkCmdDispatchBaseKHR(): baseGroupX (%" PRIu32 ") + groupCountX (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002935 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002936 baseGroupX, groupCountX, limit, validation_error_map[VALIDATION_ERROR_19e00350]);
2937 }
2938
2939 limit = device_data->device_limits.maxComputeWorkGroupCount[1];
2940 if (baseGroupY >= limit) {
2941 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2942 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034c, LayerName,
2943 "vkCmdDispatch(): baseGroupY (%" PRIu32
2944 ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2945 baseGroupY, limit, validation_error_map[VALIDATION_ERROR_19e0034c]);
2946 } else if (groupCountY > (limit - baseGroupY)) {
2947 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2948 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00352, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002949 "vkCmdDispatchBaseKHR(): baseGroupY (%" PRIu32 ") + groupCountY (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002950 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002951 baseGroupY, groupCountY, limit, validation_error_map[VALIDATION_ERROR_19e00352]);
2952 }
2953
2954 limit = device_data->device_limits.maxComputeWorkGroupCount[2];
2955 if (baseGroupZ >= limit) {
2956 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2957 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034e, LayerName,
2958 "vkCmdDispatch(): baseGroupZ (%" PRIu32
2959 ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2960 baseGroupZ, limit, validation_error_map[VALIDATION_ERROR_19e0034e]);
2961 } else if (groupCountZ > (limit - baseGroupZ)) {
2962 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2963 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00354, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002964 "vkCmdDispatchBaseKHR(): baseGroupZ (%" PRIu32 ") + groupCountZ (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002965 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002966 baseGroupZ, groupCountZ, limit, validation_error_map[VALIDATION_ERROR_19e00354]);
2967 }
2968
2969 return skip;
2970}
2971
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002972VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2973 const auto item = name_to_funcptr_map.find(funcName);
2974 if (item != name_to_funcptr_map.end()) {
2975 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2976 }
2977
2978 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2979 const auto &table = device_data->dispatch_table;
2980 if (!table.GetDeviceProcAddr) return nullptr;
2981 return table.GetDeviceProcAddr(device, funcName);
2982}
2983
2984VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2985 const auto item = name_to_funcptr_map.find(funcName);
2986 if (item != name_to_funcptr_map.end()) {
2987 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2988 }
2989
2990 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2991 auto &table = instance_data->dispatch_table;
2992 if (!table.GetInstanceProcAddr) return nullptr;
2993 return table.GetInstanceProcAddr(instance, funcName);
2994}
2995
2996VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2997 assert(instance);
2998 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2999
3000 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
3001 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
3002}
3003
3004// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
3005// 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 +02003006void InitializeManualParameterValidationFunctionPointers() {
Dave Houltonb3bbec72018-01-17 10:13:33 -07003007 custom_functions["vkGetDeviceQueue"] = (void *)pv_vkGetDeviceQueue;
3008 custom_functions["vkCreateBuffer"] = (void *)pv_vkCreateBuffer;
3009 custom_functions["vkCreateImage"] = (void *)pv_vkCreateImage;
3010 custom_functions["vkCreateImageView"] = (void *)pv_vkCreateImageView;
3011 custom_functions["vkCreateGraphicsPipelines"] = (void *)pv_vkCreateGraphicsPipelines;
3012 custom_functions["vkCreateComputePipelines"] = (void *)pv_vkCreateComputePipelines;
3013 custom_functions["vkCreateSampler"] = (void *)pv_vkCreateSampler;
3014 custom_functions["vkCreateDescriptorSetLayout"] = (void *)pv_vkCreateDescriptorSetLayout;
3015 custom_functions["vkFreeDescriptorSets"] = (void *)pv_vkFreeDescriptorSets;
3016 custom_functions["vkUpdateDescriptorSets"] = (void *)pv_vkUpdateDescriptorSets;
3017 custom_functions["vkCreateRenderPass"] = (void *)pv_vkCreateRenderPass;
3018 custom_functions["vkBeginCommandBuffer"] = (void *)pv_vkBeginCommandBuffer;
3019 custom_functions["vkCmdSetViewport"] = (void *)pv_vkCmdSetViewport;
3020 custom_functions["vkCmdSetScissor"] = (void *)pv_vkCmdSetScissor;
Petr Kraus299ba622017-11-24 03:09:03 +01003021 custom_functions["vkCmdSetLineWidth"] = (void *)pv_vkCmdSetLineWidth;
Dave Houltonb3bbec72018-01-17 10:13:33 -07003022 custom_functions["vkCmdDraw"] = (void *)pv_vkCmdDraw;
3023 custom_functions["vkCmdDrawIndirect"] = (void *)pv_vkCmdDrawIndirect;
3024 custom_functions["vkCmdDrawIndexedIndirect"] = (void *)pv_vkCmdDrawIndexedIndirect;
3025 custom_functions["vkCmdCopyImage"] = (void *)pv_vkCmdCopyImage;
3026 custom_functions["vkCmdBlitImage"] = (void *)pv_vkCmdBlitImage;
3027 custom_functions["vkCmdCopyBufferToImage"] = (void *)pv_vkCmdCopyBufferToImage;
3028 custom_functions["vkCmdCopyImageToBuffer"] = (void *)pv_vkCmdCopyImageToBuffer;
3029 custom_functions["vkCmdUpdateBuffer"] = (void *)pv_vkCmdUpdateBuffer;
3030 custom_functions["vkCmdFillBuffer"] = (void *)pv_vkCmdFillBuffer;
3031 custom_functions["vkCreateSwapchainKHR"] = (void *)pv_vkCreateSwapchainKHR;
3032 custom_functions["vkQueuePresentKHR"] = (void *)pv_vkQueuePresentKHR;
3033 custom_functions["vkCreateDescriptorPool"] = (void *)pv_vkCreateDescriptorPool;
3034 custom_functions["vkCmdDispatch"] = (void *)pv_vkCmdDispatch;
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07003035 custom_functions["vkCmdDispatchBaseKHR"] = (void *)pv_vkCmdDispatchBaseKHR;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06003036}
3037
3038} // namespace parameter_validation
3039
3040VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
3041 VkExtensionProperties *pProperties) {
3042 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
3043}
3044
3045VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
3046 VkLayerProperties *pProperties) {
3047 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
3048}
3049
3050VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
3051 VkLayerProperties *pProperties) {
3052 // the layer command handles VK_NULL_HANDLE just fine internally
3053 assert(physicalDevice == VK_NULL_HANDLE);
3054 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
3055}
3056
3057VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
3058 const char *pLayerName, uint32_t *pCount,
3059 VkExtensionProperties *pProperties) {
3060 // the layer command handles VK_NULL_HANDLE just fine internally
3061 assert(physicalDevice == VK_NULL_HANDLE);
3062 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
3063}
3064
3065VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
3066 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
3067}
3068
3069VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
3070 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
3071}
3072
3073VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
3074 const char *funcName) {
3075 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
3076}
3077
3078VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
3079 assert(pVersionStruct != NULL);
3080 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
3081
3082 // Fill in the function pointers if our version is at least capable of having the structure contain them.
3083 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
3084 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
3085 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
3086 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
3087 }
3088
3089 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
3090 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
3091 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
3092 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
3093 }
3094
3095 return VK_SUCCESS;
3096}