blob: e74a846af46ab7738385b533f2dec2dd4603fdb8 [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
899 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) && (pCreateInfo->extent.height != 1) && (pCreateInfo->extent.depth != 1)) {
900 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 -0700901 VALIDATION_ERROR_09e00778, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700902 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_1D, both pCreateInfo->extent.height and "
903 "pCreateInfo->extent.depth must be 1. %s",
Dave Houltone19e20d2018-02-02 16:32:41 -0700904 validation_error_map[VALIDATION_ERROR_09e00778]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600905 }
906
907 if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D) {
908 // If imageType is VK_IMAGE_TYPE_2D and flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, extent.width and
909 // extent.height must be equal
910 if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
911 (pCreateInfo->extent.width != pCreateInfo->extent.height)) {
912 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
913 VALIDATION_ERROR_09e00774, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700914 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D and pCreateInfo->flags contains "
915 "VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, pCreateInfo->extent.width and pCreateInfo->extent.height "
916 "must be equal. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600917 validation_error_map[VALIDATION_ERROR_09e00774]);
918 }
919
920 if (pCreateInfo->extent.depth != 1) {
921 skip |= log_msg(
922 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
923 VALIDATION_ERROR_09e0077a, LayerName,
924 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1. %s",
925 validation_error_map[VALIDATION_ERROR_09e0077a]);
926 }
927 }
928
Dave Houlton130c0212018-01-29 13:39:56 -0700929 // 3D image may have only 1 layer
930 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_3D) && (pCreateInfo->arrayLayers != 1)) {
931 skip |=
932 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
933 VALIDATION_ERROR_09e00782, LayerName,
934 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_3D, pCreateInfo->arrayLayers must be 1. %s",
935 validation_error_map[VALIDATION_ERROR_09e00782]);
936 }
937
938 // If multi-sample, validate type, usage, tiling and mip levels.
939 if ((pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) &&
940 ((pCreateInfo->imageType != VK_IMAGE_TYPE_2D) || (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) ||
941 (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) || (pCreateInfo->mipLevels != 1))) {
942 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
943 VALIDATION_ERROR_09e00784, LayerName,
944 "vkCreateImage(): Multi-sample image with incompatible type, usage, tiling, or mips. %s",
945 validation_error_map[VALIDATION_ERROR_09e00784]);
946 }
947
948 if (0 != (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
949 VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
950 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
951 // At least one of the legal attachment bits must be set
952 if (0 == (pCreateInfo->usage & legal_flags)) {
953 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
954 VALIDATION_ERROR_09e0078c, LayerName,
955 "vkCreateImage(): Transient attachment image without a compatible attachment flag set. %s",
956 validation_error_map[VALIDATION_ERROR_09e0078c]);
957 }
958 // No flags other than the legal attachment bits may be set
959 legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
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_09e00786, LayerName,
963 "vkCreateImage(): Transient attachment image with incompatible usage flags set. %s",
964 validation_error_map[VALIDATION_ERROR_09e00786]);
965 }
966 }
967
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600968 // mipLevels must be less than or equal to floor(log2(max(extent.width,extent.height,extent.depth)))+1
969 uint32_t maxDim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
Petr Krause5c37652018-01-05 04:05:12 +0100970 if (maxDim > 0 && pCreateInfo->mipLevels > (floor(log2(maxDim)) + 1)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600971 skip |=
972 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
973 VALIDATION_ERROR_09e0077c, LayerName,
974 "vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
975 "floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1. %s",
976 validation_error_map[VALIDATION_ERROR_09e0077c]);
977 }
978
979 // If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
980 // VK_IMAGE_CREATE_SPARSE_BINDING_BIT
981 if (((pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
982 ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
983 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
984 VALIDATION_ERROR_09e007b6, LayerName,
985 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
986 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT. %s",
987 validation_error_map[VALIDATION_ERROR_09e007b6]);
988 }
989
990 // Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
991 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
992 // Linear tiling is unsupported
993 if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
994 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
995 INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700996 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image "
997 "tiling of VK_IMAGE_TILING_LINEAR is not supported");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600998 }
999
1000 // Sparse 1D image isn't valid
1001 if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
1002 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1003 VALIDATION_ERROR_09e00794, LayerName,
1004 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image. %s",
1005 validation_error_map[VALIDATION_ERROR_09e00794]);
1006 }
1007
1008 // Sparse 2D image when device doesn't support it
1009 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage2D) &&
1010 (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
1011 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1012 VALIDATION_ERROR_09e00796, LayerName,
1013 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
1014 "feature is not enabled on the device. %s",
1015 validation_error_map[VALIDATION_ERROR_09e00796]);
1016 }
1017
1018 // Sparse 3D image when device doesn't support it
1019 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage3D) &&
1020 (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
1021 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1022 VALIDATION_ERROR_09e00798, LayerName,
1023 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
1024 "feature is not enabled on the device. %s",
1025 validation_error_map[VALIDATION_ERROR_09e00798]);
1026 }
1027
1028 // Multi-sample 2D image when device doesn't support it
1029 if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
1030 if ((VK_FALSE == device_data->physical_device_features.sparseResidency2Samples) &&
1031 (VK_SAMPLE_COUNT_2_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001032 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1033 __LINE__, VALIDATION_ERROR_09e0079a, LayerName,
1034 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if "
1035 "corresponding feature is not enabled on the device. %s",
1036 validation_error_map[VALIDATION_ERROR_09e0079a]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001037 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency4Samples) &&
1038 (VK_SAMPLE_COUNT_4_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001039 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1040 __LINE__, VALIDATION_ERROR_09e0079c, LayerName,
1041 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if "
1042 "corresponding feature is not enabled on the device. %s",
1043 validation_error_map[VALIDATION_ERROR_09e0079c]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001044 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency8Samples) &&
1045 (VK_SAMPLE_COUNT_8_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001046 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1047 __LINE__, VALIDATION_ERROR_09e0079e, LayerName,
1048 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if "
1049 "corresponding feature is not enabled on the device. %s",
1050 validation_error_map[VALIDATION_ERROR_09e0079e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001051 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency16Samples) &&
1052 (VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001053 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1054 __LINE__, VALIDATION_ERROR_09e007a0, LayerName,
1055 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if "
1056 "corresponding feature is not enabled on the device. %s",
1057 validation_error_map[VALIDATION_ERROR_09e007a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001058 }
1059 }
1060 }
1061 }
1062 return skip;
1063}
1064
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001065bool pv_vkCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1066 VkImageView *pView) {
1067 bool skip = false;
1068 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1069 debug_report_data *report_data = device_data->report_data;
1070
1071 if (pCreateInfo != nullptr) {
1072 if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) || (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D)) {
1073 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
1074 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1075 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1076 LayerName,
1077 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD, "
1078 "pCreateInfo->subresourceRange.layerCount must be 1",
1079 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) ? 1 : 2));
1080 }
1081 } else if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ||
1082 (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
1083 if ((pCreateInfo->subresourceRange.layerCount < 1) &&
1084 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1085 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1086 LayerName,
1087 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD_ARRAY, "
1088 "pCreateInfo->subresourceRange.layerCount must be >= 1",
1089 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ? 1 : 2));
1090 }
1091 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE) {
1092 if ((pCreateInfo->subresourceRange.layerCount != 6) &&
1093 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1094 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1095 LayerName,
1096 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE, "
1097 "pCreateInfo->subresourceRange.layerCount must be 6");
1098 }
1099 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
1100 if (((pCreateInfo->subresourceRange.layerCount == 0) || ((pCreateInfo->subresourceRange.layerCount % 6) != 0)) &&
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_ARRAY, "
1105 "pCreateInfo->subresourceRange.layerCount must be a multiple of 6");
1106 }
1107 if (!device_data->physical_device_features.imageCubeArray) {
1108 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1109 LayerName, "vkCreateImageView: Device feature imageCubeArray not enabled.");
1110 }
1111 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_3D) {
1112 if (pCreateInfo->subresourceRange.baseArrayLayer != 0) {
1113 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1114 LayerName,
1115 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1116 "pCreateInfo->subresourceRange.baseArrayLayer must be 0");
1117 }
1118
1119 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
1120 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
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.layerCount must be 1");
1125 }
1126 }
1127 }
1128 return skip;
1129}
1130
Petr Krausb3fcdb42018-01-09 22:09:09 +01001131bool pv_VkViewport(const layer_data *device_data, const VkViewport &viewport, const char *fn_name, const char *param_name,
1132 VkDebugReportObjectTypeEXT object_type, uint64_t object = 0) {
1133 bool skip = false;
1134 debug_report_data *report_data = device_data->report_data;
1135
1136 // Note: for numerical correctness
1137 // - float comparisons should expect NaN (comparison always false).
1138 // - VkPhysicalDeviceLimits::maxViewportDimensions is uint32_t, not float -> careful.
1139
1140 const auto f_lte_u32_exact = [](const float v1_f, const uint32_t v2_u32) {
John Zulaufac0876c2018-02-19 10:09:35 -07001141 if (std::isnan(v1_f)) return false;
Petr Krausb3fcdb42018-01-09 22:09:09 +01001142 if (v1_f <= 0.0f) return true;
1143
1144 float intpart;
1145 const float fract = modff(v1_f, &intpart);
1146
1147 assert(std::numeric_limits<float>::radix == 2);
1148 const float u32_max_plus1 = ldexpf(1.0f, 32); // hopefully exact
1149 if (intpart >= u32_max_plus1) return false;
1150
1151 uint32_t v1_u32 = static_cast<uint32_t>(intpart);
1152 if (v1_u32 < v2_u32)
1153 return true;
1154 else if (v1_u32 == v2_u32 && fract == 0.0f)
1155 return true;
1156 else
1157 return false;
1158 };
1159
1160 const auto f_lte_u32_direct = [](const float v1_f, const uint32_t v2_u32) {
1161 const float v2_f = static_cast<float>(v2_u32); // not accurate for > radix^digits; and undefined rounding mode
1162 return (v1_f <= v2_f);
1163 };
1164
1165 // width
1166 bool width_healthy = true;
1167 const auto max_w = device_data->device_limits.maxViewportDimensions[0];
1168
1169 if (!(viewport.width > 0.0f)) {
1170 width_healthy = false;
1171 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd4,
1172 LayerName, "%s: %s.width (=%f) is not greater than 0.0. %s", fn_name, param_name, viewport.width,
1173 validation_error_map[VALIDATION_ERROR_15000dd4]);
1174 } else if (!(f_lte_u32_exact(viewport.width, max_w) || f_lte_u32_direct(viewport.width, max_w))) {
1175 width_healthy = false;
1176 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd6,
1177 LayerName, "%s: %s.width (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32 "). %s",
1178 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1179 } else if (!f_lte_u32_exact(viewport.width, max_w) && f_lte_u32_direct(viewport.width, max_w)) {
1180 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1181 "%s: %s.width (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32
1182 "), but it is within the static_cast<float>(maxViewportDimensions[0]) limit. %s",
1183 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1184 }
1185
1186 // height
1187 bool height_healthy = true;
Petr Krausaf9c1222018-03-10 02:39:47 +01001188 const bool negative_height_enabled = device_data->api_version >= VK_API_VERSION_1_1 ||
1189 device_data->extensions.vk_khr_maintenance1 ||
1190 device_data->extensions.vk_amd_negative_viewport_height;
Petr Krausb3fcdb42018-01-09 22:09:09 +01001191 const auto max_h = device_data->device_limits.maxViewportDimensions[1];
1192
1193 if (!negative_height_enabled && !(viewport.height > 0.0f)) {
1194 height_healthy = false;
1195 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd8,
1196 LayerName, "%s: %s.height (=%f) is not greater 0.0. %s", fn_name, param_name, viewport.height,
1197 validation_error_map[VALIDATION_ERROR_15000dd8]);
1198 } else if (!(f_lte_u32_exact(fabsf(viewport.height), max_h) || f_lte_u32_direct(fabsf(viewport.height), max_h))) {
1199 height_healthy = false;
1200
1201 skip |= log_msg(
1202 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dda, LayerName,
1203 "%s: Absolute value of %s.height (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32 "). %s",
1204 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1205 } else if (!f_lte_u32_exact(fabsf(viewport.height), max_h) && f_lte_u32_direct(fabsf(viewport.height), max_h)) {
1206 height_healthy = false;
1207
1208 skip |= log_msg(
1209 report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1210 "%s: Absolute value of %s.height (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32
1211 "), but it is within the static_cast<float>(maxViewportDimensions[1]) limit. %s",
1212 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1213 }
1214
1215 // x
1216 bool x_healthy = true;
1217 if (!(viewport.x >= device_data->device_limits.viewportBoundsRange[0])) {
1218 x_healthy = false;
1219 skip |=
1220 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000ddc, LayerName,
1221 "%s: %s.x (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1222 viewport.x, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000ddc]);
1223 }
1224
1225 // x + width
1226 if (x_healthy && width_healthy) {
1227 const float right_bound = viewport.x + viewport.width;
1228 if (!(right_bound <= device_data->device_limits.viewportBoundsRange[1])) {
1229 skip |= log_msg(
1230 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1231 "%s: %s.x + %s.width (=%f + %f = %f) is greater than VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1232 fn_name, param_name, param_name, viewport.x, viewport.width, right_bound,
1233 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
1234 }
1235 }
1236
1237 // y
1238 bool y_healthy = true;
1239 if (!(viewport.y >= device_data->device_limits.viewportBoundsRange[0])) {
1240 y_healthy = false;
1241 skip |=
1242 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dde, LayerName,
1243 "%s: %s.y (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1244 viewport.y, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000dde]);
1245 } else if (negative_height_enabled && !(viewport.y <= device_data->device_limits.viewportBoundsRange[1])) {
1246 y_healthy = false;
1247 skip |=
1248 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de0, LayerName,
1249 "%s: %s.y (=%f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s", fn_name, param_name,
1250 viewport.y, device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_15000de0]);
1251 }
1252
1253 // y + height
1254 if (y_healthy && height_healthy) {
1255 const float boundary = viewport.y + viewport.height;
1256
1257 if (!(boundary <= device_data->device_limits.viewportBoundsRange[1])) {
1258 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a2,
1259 LayerName,
1260 "%s: %s.y + %s.height (=%f + %f = %f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1261 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1262 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
1263 } else if (negative_height_enabled && !(boundary >= device_data->device_limits.viewportBoundsRange[0])) {
1264 skip |= log_msg(
1265 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de2, LayerName,
1266 "%s: %s.y + %s.height (=%f + %f = %f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s",
1267 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1268 device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000de2]);
1269 }
1270 }
1271
1272 if (!device_data->extensions.vk_ext_depth_range_unrestricted) {
1273 // minDepth
1274 if (!(viewport.minDepth >= 0.0) || !(viewport.minDepth <= 1.0)) {
1275 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a4,
1276 LayerName,
1277 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.minDepth (=%f) is not within the "
1278 "[0.0, 1.0] range. %s",
1279 fn_name, param_name, viewport.minDepth, validation_error_map[VALIDATION_ERROR_150009a4]);
1280 }
1281
1282 // maxDepth
1283 if (!(viewport.maxDepth >= 0.0) || !(viewport.maxDepth <= 1.0)) {
1284 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a6,
1285 LayerName,
1286 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.maxDepth (=%f) is not within the "
1287 "[0.0, 1.0] range. %s",
1288 fn_name, param_name, viewport.maxDepth, validation_error_map[VALIDATION_ERROR_150009a6]);
1289 }
1290 }
1291
1292 return skip;
1293}
1294
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001295bool pv_vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1296 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1297 VkPipeline *pPipelines) {
1298 bool skip = false;
1299 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1300 debug_report_data *report_data = device_data->report_data;
1301
1302 if (pCreateInfos != nullptr) {
1303 for (uint32_t i = 0; i < createInfoCount; ++i) {
Petr Kraus299ba622017-11-24 03:09:03 +01001304 bool has_dynamic_viewport = false;
1305 bool has_dynamic_scissor = false;
1306 bool has_dynamic_line_width = false;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001307 bool has_dynamic_viewport_w_scaling_nv = false;
1308 bool has_dynamic_discard_rectangle_ext = false;
1309 bool has_dynamic_sample_locations_ext = false;
Petr Kraus299ba622017-11-24 03:09:03 +01001310 if (pCreateInfos[i].pDynamicState != nullptr) {
1311 const auto &dynamic_state_info = *pCreateInfos[i].pDynamicState;
1312 for (uint32_t state_index = 0; state_index < dynamic_state_info.dynamicStateCount; ++state_index) {
1313 const auto &dynamic_state = dynamic_state_info.pDynamicStates[state_index];
1314 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT) has_dynamic_viewport = true;
1315 if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR) has_dynamic_scissor = true;
1316 if (dynamic_state == VK_DYNAMIC_STATE_LINE_WIDTH) has_dynamic_line_width = true;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001317 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV) has_dynamic_viewport_w_scaling_nv = true;
1318 if (dynamic_state == VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT) has_dynamic_discard_rectangle_ext = true;
1319 if (dynamic_state == VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) has_dynamic_sample_locations_ext = true;
Petr Kraus299ba622017-11-24 03:09:03 +01001320 }
1321 }
1322
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001323 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1324 if (pCreateInfos[i].pVertexInputState != nullptr) {
1325 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
1326 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
1327 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
1328 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1329 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1330 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
1331 "vkCreateGraphicsPipelines: parameter "
1332 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
1333 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1334 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
1335 validation_error_map[VALIDATION_ERROR_14c004d4]);
1336 }
1337
1338 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
1339 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1340 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
1341 "vkCreateGraphicsPipelines: parameter "
1342 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
1343 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
1344 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
1345 validation_error_map[VALIDATION_ERROR_14c004d6]);
1346 }
1347 }
1348
1349 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
1350 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
1351 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
1352 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1353 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
1354 "vkCreateGraphicsPipelines: parameter "
1355 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
1356 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
1357 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
1358 validation_error_map[VALIDATION_ERROR_14a004d8]);
1359 }
1360
1361 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1362 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1363 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
1364 "vkCreateGraphicsPipelines: parameter "
1365 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
1366 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1367 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
1368 validation_error_map[VALIDATION_ERROR_14a004da]);
1369 }
1370
1371 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
1372 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1373 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
1374 "vkCreateGraphicsPipelines: parameter "
1375 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
1376 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
1377 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
1378 validation_error_map[VALIDATION_ERROR_14a004dc]);
1379 }
1380 }
1381 }
1382
1383 if (pCreateInfos[i].pStages != nullptr) {
1384 bool has_control = false;
1385 bool has_eval = false;
1386
1387 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
1388 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1389 has_control = true;
1390 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
1391 has_eval = true;
1392 }
1393 }
1394
1395 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1396 if (has_control && has_eval) {
1397 if (pCreateInfos[i].pTessellationState == nullptr) {
1398 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1399 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
1400 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1401 "shader stage and a tessellation evaluation shader stage, "
1402 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
1403 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
1404 } else {
1405 skip |= validate_struct_pnext(
1406 report_data, "vkCreateGraphicsPipelines",
1407 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
1408 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
1409
1410 skip |= validate_reserved_flags(
1411 report_data, "vkCreateGraphicsPipelines",
1412 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1413 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1414
1415 if (pCreateInfos[i].pTessellationState->sType !=
1416 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1417 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1418 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1419 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1420 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1421 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1422 }
1423
1424 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1425 pCreateInfos[i].pTessellationState->patchControlPoints >
1426 device_data->device_limits.maxTessellationPatchSize) {
1427 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1428 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1429 "vkCreateGraphicsPipelines: invalid parameter "
1430 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1431 "should be >0 and <=%u. %s",
1432 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1433 device_data->device_limits.maxTessellationPatchSize,
1434 validation_error_map[VALIDATION_ERROR_1080097c]);
1435 }
1436 }
1437 }
1438 }
1439
1440 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1441 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1442 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1443 if (pCreateInfos[i].pViewportState == nullptr) {
Petr Krausa6103552017-11-16 21:21:58 +01001444 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1445 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1446 "vkCreateGraphicsPipelines: Rasterization is enabled (pCreateInfos[%" PRIu32
1447 "].pRasterizationState->rasterizerDiscardEnable is VK_FALSE), but pCreateInfos[%" PRIu32
1448 "].pViewportState (=NULL) is not a valid pointer. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001449 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1450 } else {
Petr Krausa6103552017-11-16 21:21:58 +01001451 const auto &viewport_state = *pCreateInfos[i].pViewportState;
1452
1453 if (viewport_state.sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1454 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1455 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b00b, LayerName,
1456 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1457 "].pViewportState->sType is not VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO. %s",
1458 i, validation_error_map[VALIDATION_ERROR_10c2b00b]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001459 }
1460
Petr Krausa6103552017-11-16 21:21:58 +01001461 const VkStructureType allowed_structs_VkPipelineViewportStateCreateInfo[] = {
1462 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
1463 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV};
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001464 skip |= validate_struct_pnext(
1465 report_data, "vkCreateGraphicsPipelines",
Petr Krausa6103552017-11-16 21:21:58 +01001466 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}),
1467 "VkPipelineViewportSwizzleStateCreateInfoNV, VkPipelineViewportWScalingStateCreateInfoNV",
1468 viewport_state.pNext, ARRAY_SIZE(allowed_structs_VkPipelineViewportStateCreateInfo),
1469 allowed_structs_VkPipelineViewportStateCreateInfo, 65, VALIDATION_ERROR_10c1c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001470
1471 skip |= validate_reserved_flags(
1472 report_data, "vkCreateGraphicsPipelines",
1473 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
Petr Krausa6103552017-11-16 21:21:58 +01001474 viewport_state.flags, VALIDATION_ERROR_10c09005);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001475
Petr Krausa6103552017-11-16 21:21:58 +01001476 if (!device_data->physical_device_features.multiViewport) {
1477 if (viewport_state.viewportCount != 1) {
1478 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1479 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1480 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1481 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32
1482 ") is not 1. %s",
1483 i, viewport_state.viewportCount, validation_error_map[VALIDATION_ERROR_10c00980]);
1484 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001485
Petr Krausa6103552017-11-16 21:21:58 +01001486 if (viewport_state.scissorCount != 1) {
1487 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1488 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1489 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1490 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->scissorCount (=%" PRIu32
1491 ") is not 1. %s",
1492 i, viewport_state.scissorCount, validation_error_map[VALIDATION_ERROR_10c00982]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001493 }
Petr Krausa6103552017-11-16 21:21:58 +01001494 } else { // multiViewport enabled
1495 if (viewport_state.viewportCount == 0) {
1496 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1497 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c30a1b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001498 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001499 "].pViewportState->viewportCount is 0. %s",
1500 i, validation_error_map[VALIDATION_ERROR_10c30a1b]);
1501 } else if (viewport_state.viewportCount > device_data->device_limits.maxViewports) {
1502 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1503 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1504 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1505 "].pViewportState->viewportCount (=%" PRIu32
1506 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1507 i, viewport_state.viewportCount, device_data->device_limits.maxViewports,
1508 validation_error_map[VALIDATION_ERROR_10c00984]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001509 }
Petr Krausa6103552017-11-16 21:21:58 +01001510
1511 if (viewport_state.scissorCount == 0) {
1512 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1513 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b61b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001514 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001515 "].pViewportState->scissorCount is 0. %s",
1516 i, validation_error_map[VALIDATION_ERROR_10c2b61b]);
1517 } else if (viewport_state.scissorCount > device_data->device_limits.maxViewports) {
1518 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1519 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1520 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1521 "].pViewportState->scissorCount (=%" PRIu32
1522 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1523 i, viewport_state.scissorCount, device_data->device_limits.maxViewports,
1524 validation_error_map[VALIDATION_ERROR_10c00986]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001525 }
1526 }
1527
Petr Krausa6103552017-11-16 21:21:58 +01001528 if (viewport_state.scissorCount != viewport_state.viewportCount) {
1529 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1530 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1531 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1532 "].pViewportState->scissorCount (=%" PRIu32 ") is not identical to pCreateInfos[%" PRIu32
1533 "].pViewportState->viewportCount (=%" PRIu32 "). %s",
1534 i, viewport_state.scissorCount, i, viewport_state.viewportCount,
1535 validation_error_map[VALIDATION_ERROR_10c00988]);
1536 }
1537
Petr Krausa6103552017-11-16 21:21:58 +01001538 if (!has_dynamic_viewport && viewport_state.viewportCount > 0 && viewport_state.pViewports == nullptr) {
1539 skip |= log_msg(
1540 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1541 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1542 "vkCreateGraphicsPipelines: The viewport state is static (pCreateInfos[%" PRIu32
1543 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001544 "].pViewportState->pViewports (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001545 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1546 }
1547
1548 if (!has_dynamic_scissor && viewport_state.scissorCount > 0 && viewport_state.pScissors == nullptr) {
1549 skip |= log_msg(
1550 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1551 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1552 "vkCreateGraphicsPipelines: The scissor state is static (pCreateInfos[%" PRIu32
1553 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_SCISSOR), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001554 "].pViewportState->pScissors (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001555 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1556 }
1557
Petr Krausb3fcdb42018-01-09 22:09:09 +01001558 // validate the VkViewports
1559 if (!has_dynamic_viewport && viewport_state.pViewports) {
1560 for (uint32_t viewport_i = 0; viewport_i < viewport_state.viewportCount; ++viewport_i) {
1561 const auto &viewport = viewport_state.pViewports[viewport_i]; // will crash on invalid ptr
1562 const char fn_name[] = "vkCreateGraphicsPipelines";
1563 const std::string param_name = "pCreateInfos[" + std::to_string(i) + "].pViewportState->pViewports[" +
1564 std::to_string(viewport_i) + "]";
1565 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
1566 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
1567 }
1568 }
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001569
1570 if (has_dynamic_viewport_w_scaling_nv && !device_data->extensions.vk_nv_clip_space_w_scaling) {
1571 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1572 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1573 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001574 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001575 "VK_NV_clip_space_w_scaling extension is not enabled.",
1576 i);
1577 }
1578
1579 if (has_dynamic_discard_rectangle_ext && !device_data->extensions.vk_ext_discard_rectangles) {
1580 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1581 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1582 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001583 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001584 "VK_EXT_discard_rectangles extension is not enabled.",
1585 i);
1586 }
1587
1588 if (has_dynamic_sample_locations_ext && !device_data->extensions.vk_ext_sample_locations) {
1589 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1590 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1591 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001592 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001593 "VK_EXT_sample_locations extension is not enabled.",
1594 i);
1595 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001596 }
1597
1598 if (pCreateInfos[i].pMultisampleState == nullptr) {
1599 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1600 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1601 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1602 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1603 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1604 } else {
Dave Houltonb3bbec72018-01-17 10:13:33 -07001605 const VkStructureType valid_next_stypes[] = {LvlTypeMap<VkPipelineCoverageModulationStateCreateInfoNV>::kSType,
1606 LvlTypeMap<VkPipelineCoverageToColorStateCreateInfoNV>::kSType,
1607 LvlTypeMap<VkPipelineSampleLocationsStateCreateInfoEXT>::kSType};
Mike Schuchardt97662b02017-12-06 13:31:29 -07001608 const char *valid_struct_names =
Dave Houltona9df0ce2018-02-07 10:51:23 -07001609 "VkPipelineCoverageModulationStateCreateInfoNV, VkPipelineCoverageToColorStateCreateInfoNV, "
John Zulauf96b0e422017-11-14 11:43:19 -07001610 "VkPipelineSampleLocationsStateCreateInfoEXT";
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001611 skip |= validate_struct_pnext(
1612 report_data, "vkCreateGraphicsPipelines",
John Zulauf96b0e422017-11-14 11:43:19 -07001613 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}),
1614 valid_struct_names, pCreateInfos[i].pMultisampleState->pNext, 3, valid_next_stypes, GeneratedHeaderVersion,
1615 VALIDATION_ERROR_1001c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001616
1617 skip |= validate_reserved_flags(
1618 report_data, "vkCreateGraphicsPipelines",
1619 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1620 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1621
1622 skip |= validate_bool32(
1623 report_data, "vkCreateGraphicsPipelines",
1624 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1625 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1626
1627 skip |= validate_array(
1628 report_data, "vkCreateGraphicsPipelines",
1629 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1630 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1631 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1632 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1633
1634 skip |= validate_bool32(
1635 report_data, "vkCreateGraphicsPipelines",
1636 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1637 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1638
1639 skip |= validate_bool32(
1640 report_data, "vkCreateGraphicsPipelines",
1641 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1642 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1643
1644 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1645 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1646 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1647 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1648 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1649 i);
1650 }
John Zulauf7acac592017-11-06 11:15:53 -07001651 if (pCreateInfos[i].pMultisampleState->sampleShadingEnable == VK_TRUE) {
1652 if (!device_data->physical_device_features.sampleRateShading) {
1653 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1654 __LINE__, VALIDATION_ERROR_10000620, LayerName,
1655 "vkCreateGraphicsPipelines(): parameter "
1656 "pCreateInfos[%d].pMultisampleState->sampleShadingEnable: %s",
1657 i, validation_error_map[VALIDATION_ERROR_10000620]);
1658 }
1659 // TODO Add documentation issue about when minSampleShading must be in range and when it is ignored
1660 // For now a "least noise" test *only* when sampleShadingEnable is VK_TRUE.
1661 if (!in_inclusive_range(pCreateInfos[i].pMultisampleState->minSampleShading, 0.F, 1.0F)) {
1662 skip |= log_msg(
1663 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1664 VALIDATION_ERROR_10000624, LayerName,
1665 "vkCreateGraphicsPipelines(): parameter pCreateInfos[%d].pMultisampleState->minSampleShading: %s",
1666 i, validation_error_map[VALIDATION_ERROR_10000624]);
1667 }
1668 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001669 }
1670
Petr Krause91f7a12017-12-14 20:57:36 +01001671 bool uses_color_attachment = false;
1672 bool uses_depthstencil_attachment = false;
1673 {
1674 const auto subpasses_uses_it = device_data->renderpasses_states.find(pCreateInfos[i].renderPass);
1675 if (subpasses_uses_it != device_data->renderpasses_states.end()) {
1676 const auto &subpasses_uses = subpasses_uses_it->second;
1677 if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[i].subpass))
1678 uses_color_attachment = true;
1679 if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[i].subpass))
1680 uses_depthstencil_attachment = true;
1681 }
1682 }
1683
1684 if (pCreateInfos[i].pDepthStencilState != nullptr && uses_depthstencil_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001685 skip |= validate_struct_pnext(
1686 report_data, "vkCreateGraphicsPipelines",
1687 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1688 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1689
1690 skip |= validate_reserved_flags(
1691 report_data, "vkCreateGraphicsPipelines",
1692 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1693 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1694
1695 skip |= validate_bool32(
1696 report_data, "vkCreateGraphicsPipelines",
1697 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1698 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1699
1700 skip |= validate_bool32(
1701 report_data, "vkCreateGraphicsPipelines",
1702 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1703 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1704
1705 skip |= validate_ranged_enum(
1706 report_data, "vkCreateGraphicsPipelines",
1707 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1708 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1709 VALIDATION_ERROR_0f604001);
1710
1711 skip |= validate_bool32(
1712 report_data, "vkCreateGraphicsPipelines",
1713 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1714 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1715
1716 skip |= validate_bool32(
1717 report_data, "vkCreateGraphicsPipelines",
1718 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1719 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1720
1721 skip |= validate_ranged_enum(
1722 report_data, "vkCreateGraphicsPipelines",
1723 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1724 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1725 VALIDATION_ERROR_13a08601);
1726
1727 skip |= validate_ranged_enum(
1728 report_data, "vkCreateGraphicsPipelines",
1729 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1730 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1731 VALIDATION_ERROR_13a27801);
1732
1733 skip |= validate_ranged_enum(
1734 report_data, "vkCreateGraphicsPipelines",
1735 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1736 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1737 VALIDATION_ERROR_13a04201);
1738
1739 skip |= validate_ranged_enum(
1740 report_data, "vkCreateGraphicsPipelines",
1741 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1742 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1743 VALIDATION_ERROR_0f604001);
1744
1745 skip |= validate_ranged_enum(
1746 report_data, "vkCreateGraphicsPipelines",
1747 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1748 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1749 VALIDATION_ERROR_13a08601);
1750
1751 skip |= validate_ranged_enum(
1752 report_data, "vkCreateGraphicsPipelines",
1753 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1754 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1755 VALIDATION_ERROR_13a27801);
1756
1757 skip |= validate_ranged_enum(
1758 report_data, "vkCreateGraphicsPipelines",
1759 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1760 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1761 VALIDATION_ERROR_13a04201);
1762
1763 skip |= validate_ranged_enum(
1764 report_data, "vkCreateGraphicsPipelines",
1765 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1766 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1767 VALIDATION_ERROR_0f604001);
1768
1769 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1770 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1771 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1772 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1773 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1774 i);
1775 }
1776 }
1777
Petr Krause91f7a12017-12-14 20:57:36 +01001778 if (pCreateInfos[i].pColorBlendState != nullptr && uses_color_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001779 skip |= validate_struct_pnext(
1780 report_data, "vkCreateGraphicsPipelines",
1781 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1782 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1783
1784 skip |= validate_reserved_flags(
1785 report_data, "vkCreateGraphicsPipelines",
1786 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1787 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1788
1789 skip |= validate_bool32(
1790 report_data, "vkCreateGraphicsPipelines",
1791 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1792 pCreateInfos[i].pColorBlendState->logicOpEnable);
1793
1794 skip |= validate_array(
1795 report_data, "vkCreateGraphicsPipelines",
1796 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1797 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1798 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1799 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1800
1801 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1802 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1803 ++attachmentIndex) {
1804 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1805 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1806 ParameterName::IndexVector{i, attachmentIndex}),
1807 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1808
1809 skip |= validate_ranged_enum(
1810 report_data, "vkCreateGraphicsPipelines",
1811 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1812 ParameterName::IndexVector{i, attachmentIndex}),
1813 "VkBlendFactor", AllVkBlendFactorEnums,
1814 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1815 VALIDATION_ERROR_0f22cc01);
1816
1817 skip |= validate_ranged_enum(
1818 report_data, "vkCreateGraphicsPipelines",
1819 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1820 ParameterName::IndexVector{i, attachmentIndex}),
1821 "VkBlendFactor", AllVkBlendFactorEnums,
1822 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1823 VALIDATION_ERROR_0f207001);
1824
1825 skip |= validate_ranged_enum(
1826 report_data, "vkCreateGraphicsPipelines",
1827 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1828 ParameterName::IndexVector{i, attachmentIndex}),
1829 "VkBlendOp", AllVkBlendOpEnums,
1830 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1831 VALIDATION_ERROR_0f202001);
1832
1833 skip |= validate_ranged_enum(
1834 report_data, "vkCreateGraphicsPipelines",
1835 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1836 ParameterName::IndexVector{i, attachmentIndex}),
1837 "VkBlendFactor", AllVkBlendFactorEnums,
1838 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1839 VALIDATION_ERROR_0f22c601);
1840
1841 skip |= validate_ranged_enum(
1842 report_data, "vkCreateGraphicsPipelines",
1843 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1844 ParameterName::IndexVector{i, attachmentIndex}),
1845 "VkBlendFactor", AllVkBlendFactorEnums,
1846 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1847 VALIDATION_ERROR_0f206a01);
1848
1849 skip |= validate_ranged_enum(
1850 report_data, "vkCreateGraphicsPipelines",
1851 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1852 ParameterName::IndexVector{i, attachmentIndex}),
1853 "VkBlendOp", AllVkBlendOpEnums,
1854 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1855 VALIDATION_ERROR_0f200801);
1856
1857 skip |=
1858 validate_flags(report_data, "vkCreateGraphicsPipelines",
1859 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1860 ParameterName::IndexVector{i, attachmentIndex}),
1861 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1862 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1863 false, false, VALIDATION_ERROR_0f202201);
1864 }
1865 }
1866
1867 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1868 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1869 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1870 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1871 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1872 i);
1873 }
1874
1875 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1876 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1877 skip |= validate_ranged_enum(
1878 report_data, "vkCreateGraphicsPipelines",
1879 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1880 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1881 }
1882 }
1883 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001884
Petr Kraus9752aae2017-11-24 03:05:50 +01001885 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1886 if (pCreateInfos[i].basePipelineIndex != -1) {
1887 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001888 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1889 __LINE__, VALIDATION_ERROR_096005a8, LayerName,
1890 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be "
1891 "VK_NULL_HANDLE if pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag "
1892 "and pCreateInfos->basePipelineIndex is not -1. %s",
1893 validation_error_map[VALIDATION_ERROR_096005a8]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001894 }
1895 }
1896
Petr Kraus9752aae2017-11-24 03:05:50 +01001897 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
1898 if (pCreateInfos[i].basePipelineIndex != -1) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001899 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1900 __LINE__, VALIDATION_ERROR_096005aa, LayerName,
1901 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1902 "pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and "
1903 "pCreateInfos->basePipelineHandle is not VK_NULL_HANDLE. %s",
1904 validation_error_map[VALIDATION_ERROR_096005aa]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001905 }
1906 }
1907 }
1908
Petr Kraus9752aae2017-11-24 03:05:50 +01001909 if (pCreateInfos[i].pRasterizationState) {
1910 if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001911 (device_data->physical_device_features.fillModeNonSolid == false)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001912 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1913 __LINE__, DEVICE_FEATURE, LayerName,
1914 "vkCreateGraphicsPipelines parameter, VkPolygonMode "
1915 "pCreateInfos->pRasterizationState->polygonMode cannot be VK_POLYGON_MODE_POINT or "
1916 "VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001917 }
Petr Kraus299ba622017-11-24 03:09:03 +01001918
1919 if (!has_dynamic_line_width && !device_data->physical_device_features.wideLines &&
1920 (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
1921 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1922 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, 0, __LINE__, VALIDATION_ERROR_096005da, LayerName,
1923 "The line width state is static (pCreateInfos[%" PRIu32
1924 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
1925 "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
1926 "].pRasterizationState->lineWidth (=%f) is not 1.0. %s",
1927 i, i, pCreateInfos[i].pRasterizationState->lineWidth,
1928 validation_error_map[VALIDATION_ERROR_096005da]);
1929 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001930 }
1931
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001932 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1933 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1934 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1935 pCreateInfos[i].pStages[j].pName);
1936 }
1937 }
1938 }
1939
1940 return skip;
1941}
1942
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001943bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1944 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1945 VkPipeline *pPipelines) {
1946 bool skip = false;
1947 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1948
1949 for (uint32_t i = 0; i < createInfoCount; i++) {
1950 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1951 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1952 pCreateInfos[i].stage.pName);
1953 }
1954
1955 return skip;
1956}
1957
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001958bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1959 VkSampler *pSampler) {
1960 bool skip = false;
1961 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1962 debug_report_data *report_data = device_data->report_data;
1963
1964 if (pCreateInfo != nullptr) {
John Zulauf71968502017-10-26 13:51:15 -06001965 const auto &features = device_data->physical_device_features;
1966 const auto &limits = device_data->device_limits;
1967 if (pCreateInfo->anisotropyEnable == VK_TRUE) {
1968 if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
1969 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1970 VALIDATION_ERROR_1260085e, LayerName,
1971 "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found. %s",
1972 "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
1973 "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy,
1974 validation_error_map[VALIDATION_ERROR_1260085e]);
1975 }
1976
1977 // Anistropy cannot be enabled in sampler unless enabled as a feature
1978 if (features.samplerAnisotropy == VK_FALSE) {
1979 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1980 VALIDATION_ERROR_1260085c, LayerName,
1981 "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE. %s",
1982 "pCreateInfo->anisotropyEnable", validation_error_map[VALIDATION_ERROR_1260085c]);
1983 }
1984
1985 // Anistropy and unnormalized coordinates cannot be enabled simultaneously
1986 if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
1987 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1988 VALIDATION_ERROR_12600868, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001989 "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates must "
1990 "not both be VK_TRUE. %s",
John Zulauf71968502017-10-26 13:51:15 -06001991 validation_error_map[VALIDATION_ERROR_12600868]);
1992 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001993 }
1994
1995 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1996 if (pCreateInfo->compareEnable == VK_TRUE) {
1997 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1998 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
1999 }
2000
2001 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
2002 // valid VkBorderColor value
2003 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2004 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2005 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
2006 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
2007 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
2008 }
2009
2010 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
2011 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
2012 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
2013 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2014 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2015 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
2016 skip |=
2017 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2018 VALIDATION_ERROR_1260086e, LayerName,
2019 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
2020 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
2021 validation_error_map[VALIDATION_ERROR_1260086e]);
2022 }
John Zulauf275805c2017-10-26 15:34:49 -06002023
2024 // Checks for the IMG cubic filtering extension
2025 if (device_data->extensions.vk_img_filter_cubic) {
2026 if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
2027 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002028 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2029 VALIDATION_ERROR_12600872, LayerName,
2030 "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter "
2031 "are VK_FILTER_CUBIC_IMG. %s",
2032 validation_error_map[VALIDATION_ERROR_12600872]);
John Zulauf275805c2017-10-26 15:34:49 -06002033 }
2034 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002035 }
2036
2037 return skip;
2038}
2039
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002040bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2041 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
2042 bool skip = false;
2043 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2044 debug_report_data *report_data = device_data->report_data;
2045
2046 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2047 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
2048 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
2049 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
2050 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
2051 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
2052 // valid VkSampler handles
2053 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2054 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
2055 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
2056 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
2057 ++descriptor_index) {
2058 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
2059 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2060 __LINE__, REQUIRED_PARAMETER, LayerName,
2061 "vkCreateDescriptorSetLayout: required parameter "
Dave Houltona9df0ce2018-02-07 10:51:23 -07002062 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d] specified as VK_NULL_HANDLE",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002063 i, descriptor_index);
2064 }
2065 }
2066 }
2067
2068 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
2069 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
2070 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002071 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2072 __LINE__, VALIDATION_ERROR_04e00236, LayerName,
2073 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
2074 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits "
2075 "values. %s",
2076 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002077 }
2078 }
2079 }
2080 }
2081
2082 return skip;
2083}
2084
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002085bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
2086 const VkDescriptorSet *pDescriptorSets) {
2087 bool skip = false;
2088 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2089 debug_report_data *report_data = device_data->report_data;
2090
2091 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2092 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2093 // validate_array()
2094 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
2095 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2096 return skip;
2097}
2098
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002099bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
2100 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
2101 bool skip = false;
2102 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2103 debug_report_data *report_data = device_data->report_data;
2104
2105 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2106 if (pDescriptorWrites != NULL) {
2107 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
2108 // descriptorCount must be greater than 0
2109 if (pDescriptorWrites[i].descriptorCount == 0) {
2110 skip |=
2111 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2112 VALIDATION_ERROR_15c0441b, LayerName,
2113 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
2114 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
2115 }
2116
2117 // dstSet must be a valid VkDescriptorSet handle
2118 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2119 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
2120 pDescriptorWrites[i].dstSet);
2121
2122 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2123 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
2124 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
2125 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
2126 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
2127 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
2128 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2129 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
2130 if (pDescriptorWrites[i].pImageInfo == nullptr) {
2131 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2132 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
2133 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2134 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
2135 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
2136 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
2137 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
2138 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
2139 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
2140 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
2141 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
2142 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2143 ++descriptor_index) {
2144 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2145 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
2146 ParameterName::IndexVector{i, descriptor_index}),
2147 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
2148 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
2149 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
2150 ParameterName::IndexVector{i, descriptor_index}),
2151 "VkImageLayout", AllVkImageLayoutEnums,
2152 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
2153 VALIDATION_ERROR_UNDEFINED);
2154 }
2155 }
2156 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2157 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2158 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
2159 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2160 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
2161 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
2162 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
2163 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
2164 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2165 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
2166 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2167 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
2168 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
2169 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
2170 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
2171 } else {
2172 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
2173 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2174 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
2175 ParameterName::IndexVector{i, descriptorIndex}),
2176 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
2177 }
2178 }
2179 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
2180 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
2181 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
2182 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
2183 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
2184 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2185 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
2186 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2187 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
2188 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
2189 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
2190 } else {
2191 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2192 ++descriptor_index) {
2193 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2194 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
2195 ParameterName::IndexVector{i, descriptor_index}),
2196 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
2197 }
2198 }
2199 }
2200
2201 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2202 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
2203 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
2204 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2205 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2206 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
2207 skip |= log_msg(
2208 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2209 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
2210 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2211 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2212 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
2213 validation_error_map[VALIDATION_ERROR_15c0028e]);
2214 }
2215 }
2216 }
2217 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2218 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2219 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
2220 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2221 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2222 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
2223 skip |= log_msg(
2224 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2225 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
2226 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2227 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2228 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
2229 validation_error_map[VALIDATION_ERROR_15c00290]);
2230 }
2231 }
2232 }
2233 }
2234 }
2235 }
2236 return skip;
2237}
2238
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002239bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2240 VkRenderPass *pRenderPass) {
2241 bool skip = false;
2242 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2243 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
2244
2245 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
2246 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
2247 std::stringstream ss;
2248 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
2249 << validation_error_map[VALIDATION_ERROR_00809201];
2250 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2251 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
2252 }
2253 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
2254 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
2255 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2256 __LINE__, VALIDATION_ERROR_00800696, "DL",
2257 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
2258 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
2259 i, validation_error_map[VALIDATION_ERROR_00800696]);
2260 }
2261 }
2262
2263 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2264 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
2265 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2266 __LINE__, VALIDATION_ERROR_1400069a, "DL",
2267 "Cannot create a render pass with %d color attachments. Max is %d. %s",
2268 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
2269 validation_error_map[VALIDATION_ERROR_1400069a]);
2270 }
2271 }
2272 return skip;
2273}
2274
2275bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
2276 const VkCommandBuffer *pCommandBuffers) {
2277 bool skip = false;
2278 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2279 debug_report_data *report_data = device_data->report_data;
2280
2281 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2282 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2283 // validate_array()
2284 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
2285 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2286 return skip;
2287}
2288
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002289bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
2290 bool skip = false;
2291 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2292 debug_report_data *report_data = device_data->report_data;
2293 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
2294
2295 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2296 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
2297 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
2298 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
2299 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
2300
2301 if (pBeginInfo->pInheritanceInfo != NULL) {
2302 skip |=
2303 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
2304 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
2305
2306 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
2307 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
2308
2309 // TODO: This only needs to be validated when the inherited queries feature is enabled
2310 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2311 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
2312
2313 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
2314 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
2315 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
2316 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
2317 }
2318
2319 if (pInfo != NULL) {
2320 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2321 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2322 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
2323 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
2324 "inheritedQueries. %s",
2325 validation_error_map[VALIDATION_ERROR_02a00070]);
2326 }
2327 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2328 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2329 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
2330 VALIDATION_ERROR_02a00072);
2331 }
2332 }
2333
2334 return skip;
2335}
2336
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002337bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
2338 const VkViewport *pViewports) {
2339 bool skip = false;
2340 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2341
Petr Krausd55e77c2018-01-09 22:09:25 +01002342 if (!device_data->physical_device_features.multiViewport) {
2343 if (firstViewport != 0) {
2344 skip |=
2345 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2346 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000990, LayerName,
2347 "vkCmdSetViewport: The multiViewport feature is disabled, but firstViewport (=%" PRIu32 ") is not 0. %s",
Jeremy Kniager72437be2018-01-25 11:41:20 -07002348 firstViewport, validation_error_map[VALIDATION_ERROR_1e000990]);
Petr Krausd55e77c2018-01-09 22:09:25 +01002349 }
2350 if (viewportCount > 1) {
2351 skip |=
2352 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2353 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000992, LayerName,
2354 "vkCmdSetViewport: The multiViewport feature is disabled, but viewportCount (=%" PRIu32 ") is not 1. %s",
2355 viewportCount, validation_error_map[VALIDATION_ERROR_1e000992]);
2356 }
2357 } else { // multiViewport enabled
Petr Kraus7dfeed12018-02-27 20:51:20 +01002358 const uint64_t sum = static_cast<uint64_t>(firstViewport) + static_cast<uint64_t>(viewportCount);
Petr Krausd55e77c2018-01-09 22:09:25 +01002359 if (sum > device_data->device_limits.maxViewports) {
2360 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2361 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e00098e, LayerName,
2362 "vkCmdSetViewport: firstViewport + viewportCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2363 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2364 firstViewport, viewportCount, sum, device_data->device_limits.maxViewports,
2365 validation_error_map[VALIDATION_ERROR_1e00098e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002366 }
2367 }
Petr Krausb3fcdb42018-01-09 22:09:09 +01002368
2369 if (pViewports) {
2370 for (uint32_t viewport_i = 0; viewport_i < viewportCount; ++viewport_i) {
2371 const auto &viewport = pViewports[viewport_i]; // will crash on invalid ptr
2372 const char fn_name[] = "vkCmdSetViewport";
2373 const std::string param_name = "pViewports[" + std::to_string(viewport_i) + "]";
2374 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
2375 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer));
2376 }
2377 }
2378
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002379 return skip;
2380}
2381
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002382bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
2383 bool skip = false;
2384 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2385 debug_report_data *report_data = device_data->report_data;
2386
Petr Kraus6260f0a2018-02-27 21:15:55 +01002387 if (!device_data->physical_device_features.multiViewport) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002388 if (firstScissor != 0) {
Petr Kraus6260f0a2018-02-27 21:15:55 +01002389 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2390 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a2, LayerName,
2391 "vkCmdSetScissor: The multiViewport feature is disabled, but firstScissor (=%" PRIu32 ") is not 0. %s",
2392 firstScissor, validation_error_map[VALIDATION_ERROR_1d8004a2]);
2393 }
2394 if (scissorCount > 1) {
2395 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2396 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a4, LayerName,
2397 "vkCmdSetScissor: The multiViewport feature is disabled, but scissorCount (=%" PRIu32 ") is not 1. %s",
2398 scissorCount, validation_error_map[VALIDATION_ERROR_1d8004a4]);
2399 }
2400 } else { // multiViewport enabled
2401 const uint64_t sum = static_cast<uint64_t>(firstScissor) + static_cast<uint64_t>(scissorCount);
2402 if (sum > device_data->device_limits.maxViewports) {
2403 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2404 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a0, LayerName,
2405 "vkCmdSetScissor: firstScissor + scissorCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2406 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2407 firstScissor, scissorCount, sum, device_data->device_limits.maxViewports,
2408 validation_error_map[VALIDATION_ERROR_1d8004a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002409 }
2410 }
2411
Petr Kraus6260f0a2018-02-27 21:15:55 +01002412 if (pScissors) {
2413 for (uint32_t scissor_i = 0; scissor_i < scissorCount; ++scissor_i) {
2414 const auto &scissor = pScissors[scissor_i]; // will crash on invalid ptr
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002415
Petr Kraus6260f0a2018-02-27 21:15:55 +01002416 if (scissor.offset.x < 0) {
2417 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2418 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2419 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.x (=%" PRIi32 ") is negative. %s", scissor_i,
2420 scissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2421 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002422
Petr Kraus6260f0a2018-02-27 21:15:55 +01002423 if (scissor.offset.y < 0) {
2424 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2425 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2426 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.y (=%" PRIi32 ") is negative. %s", scissor_i,
2427 scissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2428 }
2429
2430 const int64_t x_sum = static_cast<int64_t>(scissor.offset.x) + static_cast<int64_t>(scissor.extent.width);
2431 if (x_sum > INT32_MAX) {
2432 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2433 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a8, LayerName,
2434 "vkCmdSetScissor: offset.x + extent.width (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2435 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2436 scissor.offset.x, scissor.extent.width, x_sum, scissor_i,
2437 validation_error_map[VALIDATION_ERROR_1d8004a8]);
2438 }
2439
2440 const int64_t y_sum = static_cast<int64_t>(scissor.offset.y) + static_cast<int64_t>(scissor.extent.height);
2441 if (y_sum > INT32_MAX) {
2442 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2443 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004aa, LayerName,
2444 "vkCmdSetScissor: offset.y + extent.height (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2445 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2446 scissor.offset.y, scissor.extent.height, y_sum, scissor_i,
2447 validation_error_map[VALIDATION_ERROR_1d8004aa]);
2448 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002449 }
2450 }
Petr Kraus6260f0a2018-02-27 21:15:55 +01002451
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002452 return skip;
2453}
2454
Petr Kraus299ba622017-11-24 03:09:03 +01002455bool pv_vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
2456 bool skip = false;
2457 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2458 debug_report_data *report_data = device_data->report_data;
2459
2460 if (!device_data->physical_device_features.wideLines && (lineWidth != 1.0f)) {
2461 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2462 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d600628, LayerName,
2463 "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0. %s", lineWidth,
2464 validation_error_map[VALIDATION_ERROR_1d600628]);
2465 }
2466
2467 return skip;
2468}
2469
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002470bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2471 uint32_t firstInstance) {
2472 bool skip = false;
2473 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2474 if (vertexCount == 0) {
2475 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
2476 // this an error or leave as is.
2477 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2478 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
2479 }
2480
2481 if (instanceCount == 0) {
2482 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2483 // this an error or leave as is.
2484 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2485 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2486 }
2487 return skip;
2488}
2489
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002490bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2491 bool skip = false;
2492 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2493
2494 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2495 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2496 __LINE__, DEVICE_FEATURE, LayerName,
2497 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2498 }
2499 return skip;
2500}
2501
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002502bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2503 uint32_t stride) {
2504 bool skip = false;
2505 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2506 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2507 skip |=
2508 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2509 DEVICE_FEATURE, LayerName,
2510 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2511 }
2512 return skip;
2513}
2514
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002515bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2516 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2517 bool skip = false;
2518 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2519
Dave Houltonf5217612018-02-02 16:18:52 -07002520 VkImageAspectFlags legal_aspect_flags =
2521 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2522 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2523 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2524 }
2525
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002526 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002527 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002528 skip |= log_msg(
2529 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2530 VALIDATION_ERROR_0a600c01, LayerName,
2531 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2532 validation_error_map[VALIDATION_ERROR_0a600c01]);
2533 }
Dave Houltonf5217612018-02-02 16:18:52 -07002534 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002535 skip |= log_msg(
2536 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2537 VALIDATION_ERROR_0a600c01, LayerName,
2538 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2539 validation_error_map[VALIDATION_ERROR_0a600c01]);
2540 }
2541 }
2542 return skip;
2543}
2544
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002545bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2546 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2547 bool skip = false;
2548 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2549
Dave Houltonf5217612018-02-02 16:18:52 -07002550 VkImageAspectFlags legal_aspect_flags =
2551 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2552 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2553 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2554 }
2555
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002556 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002557 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002558 skip |= log_msg(
2559 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2560 UNRECOGNIZED_VALUE, LayerName,
2561 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2562 }
Dave Houltonf5217612018-02-02 16:18:52 -07002563 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002564 skip |= log_msg(
2565 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2566 UNRECOGNIZED_VALUE, LayerName,
2567 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2568 }
2569 }
2570 return skip;
2571}
2572
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002573bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2574 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2575 bool skip = false;
2576 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2577
Dave Houltonf5217612018-02-02 16:18:52 -07002578 VkImageAspectFlags legal_aspect_flags =
2579 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2580 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2581 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2582 }
2583
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002584 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002585 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002586 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2587 __LINE__, UNRECOGNIZED_VALUE, LayerName,
2588 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an "
2589 "unrecognized enumerator");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002590 }
2591 }
2592 return skip;
2593}
2594
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002595bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2596 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2597 bool skip = false;
2598 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2599
Dave Houltonf5217612018-02-02 16:18:52 -07002600 VkImageAspectFlags legal_aspect_flags =
2601 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2602 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2603 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2604 }
2605
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002606 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002607 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002608 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2609 UNRECOGNIZED_VALUE, LayerName,
2610 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2611 "enumerator");
2612 }
2613 }
2614 return skip;
2615}
2616
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002617bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2618 const void *pData) {
2619 bool skip = false;
2620 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2621
2622 if (dstOffset & 3) {
2623 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2624 __LINE__, VALIDATION_ERROR_1e400048, LayerName,
2625 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2626 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2627 }
2628
2629 if ((dataSize <= 0) || (dataSize > 65536)) {
2630 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2631 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2632 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2633 "), must be greater than zero and less than or equal to 65536. %s",
2634 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2635 } else if (dataSize & 3) {
2636 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2637 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2638 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2639 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2640 }
2641 return skip;
2642}
2643
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002644bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2645 uint32_t data) {
2646 bool skip = false;
2647 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2648
2649 if (dstOffset & 3) {
2650 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2651 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2652 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2653 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2654 }
2655
2656 if (size != VK_WHOLE_SIZE) {
2657 if (size <= 0) {
2658 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2659 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2660 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2661 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2662 } else if (size & 3) {
2663 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2664 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2665 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2666 validation_error_map[VALIDATION_ERROR_1b400038]);
2667 }
2668 }
2669 return skip;
2670}
2671
2672VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2673 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2674}
2675
2676VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2677 VkLayerProperties *pProperties) {
2678 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2679}
2680
2681VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2682 VkExtensionProperties *pProperties) {
2683 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2684 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2685
2686 return VK_ERROR_LAYER_NOT_PRESENT;
2687}
2688
2689VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2690 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2691 // Parameter_validation does not have any physical device extensions
2692 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2693 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2694
2695 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2696 bool skip =
2697 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2698 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2699 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2700
2701 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2702}
2703
2704static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2705 if (!flag) {
2706 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2707 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2708 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2709 extension_name);
2710 }
2711
2712 return false;
2713}
2714
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002715bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2716 VkSwapchainKHR *pSwapchain) {
2717 bool skip = false;
2718 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2719 debug_report_data *report_data = device_data->report_data;
2720
Petr Krause5c37652018-01-05 04:05:12 +01002721 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, VK_NULL_HANDLE, LayerName,
2722 "vkCreateSwapchainKHR"};
2723
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002724 if (pCreateInfo != nullptr) {
2725 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2726 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002727 skip |=
2728 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2729 DEVICE_FEATURE, LayerName,
2730 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The textureCompressionETC2 "
2731 "feature is not enabled: neither ETC2 nor EAC formats can be used to create images.",
2732 string_VkFormat(pCreateInfo->imageFormat));
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002733 }
2734
2735 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2736 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2737 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2738 DEVICE_FEATURE, LayerName,
2739 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2740 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2741 string_VkFormat(pCreateInfo->imageFormat));
2742 }
2743
2744 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2745 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2746 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2747 DEVICE_FEATURE, LayerName,
2748 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2749 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2750 string_VkFormat(pCreateInfo->imageFormat));
2751 }
2752
2753 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2754 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2755 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2756 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2757 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2758 VALIDATION_ERROR_146009fc, LayerName,
2759 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2760 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2761 validation_error_map[VALIDATION_ERROR_146009fc]);
2762 }
2763
2764 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2765 // queueFamilyIndexCount uint32_t values
2766 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2767 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2768 VALIDATION_ERROR_146009fa, LayerName,
2769 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2770 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2771 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2772 validation_error_map[VALIDATION_ERROR_146009fa]);
2773 } else {
2774 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2775 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2776 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2777 INVALID_USAGE, false, "", "");
2778 }
2779 }
2780
Petr Krause5c37652018-01-05 04:05:12 +01002781 skip |= ValidateGreaterThanZero(pCreateInfo->imageArrayLayers, "pCreateInfo->imageArrayLayers", VALIDATION_ERROR_146009f6,
2782 log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002783 }
2784
2785 return skip;
2786}
2787
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002788bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2789 bool skip = false;
2790 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2791
2792 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002793 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2794 if (present_regions) {
2795 // TODO: This and all other pNext extension dependencies should be added to code-generation
2796 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2797 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2798 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2799 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2800 __LINE__, INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002801 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i but VkPresentRegionsKHR "
2802 "extension swapchainCount is %i. These values must be equal.",
John Zulaufde972ac2017-10-26 12:07:05 -06002803 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2804 }
2805 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2806 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2807 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2808 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2809 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2810 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2811 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002812 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2813 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2814 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002815 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002816 }
2817 }
2818
2819 return skip;
2820}
2821
2822#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002823bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2824 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2825 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2826 bool skip = false;
2827
2828 if (pCreateInfo->hwnd == nullptr) {
2829 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2830 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2831 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2832 validation_error_map[VALIDATION_ERROR_15a00a38]);
2833 }
2834
2835 return skip;
2836}
2837#endif // VK_USE_PLATFORM_WIN32_KHR
2838
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002839bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2840 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2841 if (pNameInfo->pObjectName) {
2842 device_data->report_data->debugObjectNameMap->insert(
2843 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2844 } else {
2845 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2846 }
2847 return false;
2848}
2849
Petr Krausc8655be2017-09-27 18:56:51 +02002850bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2851 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2852 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2853 bool skip = false;
2854
2855 if (pCreateInfo) {
2856 if (pCreateInfo->maxSets <= 0) {
2857 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2858 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2859 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2860 validation_error_map[VALIDATION_ERROR_0480025a]);
2861 }
2862
2863 if (pCreateInfo->pPoolSizes) {
2864 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2865 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2866 skip |= log_msg(
2867 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2868 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2869 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2870 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2871 }
2872 }
2873 }
2874 }
2875
2876 return skip;
2877}
2878
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002879bool pv_vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2880 bool skip = false;
2881 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2882
2883 if (groupCountX > device_data->device_limits.maxComputeWorkGroupCount[0]) {
2884 skip |= log_msg(
2885 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2886 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00304, LayerName,
2887 "vkCmdDispatch(): groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2888 groupCountX, device_data->device_limits.maxComputeWorkGroupCount[0], validation_error_map[VALIDATION_ERROR_19c00304]);
2889 }
2890
2891 if (groupCountY > device_data->device_limits.maxComputeWorkGroupCount[1]) {
2892 skip |= log_msg(
2893 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2894 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00306, LayerName,
2895 "vkCmdDispatch(): groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2896 groupCountY, device_data->device_limits.maxComputeWorkGroupCount[1], validation_error_map[VALIDATION_ERROR_19c00306]);
2897 }
2898
2899 if (groupCountZ > device_data->device_limits.maxComputeWorkGroupCount[2]) {
2900 skip |= log_msg(
2901 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2902 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00308, LayerName,
2903 "vkCmdDispatch(): groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2904 groupCountZ, device_data->device_limits.maxComputeWorkGroupCount[2], validation_error_map[VALIDATION_ERROR_19c00308]);
2905 }
2906
2907 return skip;
2908}
2909
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002910bool pv_vkCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002911 uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2912 bool skip = false;
2913 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2914
2915 // Paired if {} else if {} tests used to avoid any possible uint underflow
2916 uint32_t limit = device_data->device_limits.maxComputeWorkGroupCount[0];
2917 if (baseGroupX >= limit) {
2918 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2919 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034a, LayerName,
2920 "vkCmdDispatch(): baseGroupX (%" PRIu32
2921 ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2922 baseGroupX, limit, validation_error_map[VALIDATION_ERROR_19e0034a]);
2923 } else if (groupCountX > (limit - baseGroupX)) {
2924 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2925 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00350, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002926 "vkCmdDispatchBaseKHR(): baseGroupX (%" PRIu32 ") + groupCountX (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002927 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002928 baseGroupX, groupCountX, limit, validation_error_map[VALIDATION_ERROR_19e00350]);
2929 }
2930
2931 limit = device_data->device_limits.maxComputeWorkGroupCount[1];
2932 if (baseGroupY >= limit) {
2933 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2934 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034c, LayerName,
2935 "vkCmdDispatch(): baseGroupY (%" PRIu32
2936 ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2937 baseGroupY, limit, validation_error_map[VALIDATION_ERROR_19e0034c]);
2938 } else if (groupCountY > (limit - baseGroupY)) {
2939 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2940 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00352, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002941 "vkCmdDispatchBaseKHR(): baseGroupY (%" PRIu32 ") + groupCountY (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002942 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002943 baseGroupY, groupCountY, limit, validation_error_map[VALIDATION_ERROR_19e00352]);
2944 }
2945
2946 limit = device_data->device_limits.maxComputeWorkGroupCount[2];
2947 if (baseGroupZ >= limit) {
2948 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2949 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034e, LayerName,
2950 "vkCmdDispatch(): baseGroupZ (%" PRIu32
2951 ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2952 baseGroupZ, limit, validation_error_map[VALIDATION_ERROR_19e0034e]);
2953 } else if (groupCountZ > (limit - baseGroupZ)) {
2954 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2955 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00354, LayerName,
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07002956 "vkCmdDispatchBaseKHR(): baseGroupZ (%" PRIu32 ") + groupCountZ (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002957 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002958 baseGroupZ, groupCountZ, limit, validation_error_map[VALIDATION_ERROR_19e00354]);
2959 }
2960
2961 return skip;
2962}
2963
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002964VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2965 const auto item = name_to_funcptr_map.find(funcName);
2966 if (item != name_to_funcptr_map.end()) {
2967 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2968 }
2969
2970 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2971 const auto &table = device_data->dispatch_table;
2972 if (!table.GetDeviceProcAddr) return nullptr;
2973 return table.GetDeviceProcAddr(device, funcName);
2974}
2975
2976VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2977 const auto item = name_to_funcptr_map.find(funcName);
2978 if (item != name_to_funcptr_map.end()) {
2979 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2980 }
2981
2982 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2983 auto &table = instance_data->dispatch_table;
2984 if (!table.GetInstanceProcAddr) return nullptr;
2985 return table.GetInstanceProcAddr(instance, funcName);
2986}
2987
2988VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2989 assert(instance);
2990 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2991
2992 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2993 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2994}
2995
2996// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2997// and the address filled in here. The autogenerated source will call these routines if the pointers are not NULL.
Petr Krausc8655be2017-09-27 18:56:51 +02002998void InitializeManualParameterValidationFunctionPointers() {
Dave Houltonb3bbec72018-01-17 10:13:33 -07002999 custom_functions["vkGetDeviceQueue"] = (void *)pv_vkGetDeviceQueue;
3000 custom_functions["vkCreateBuffer"] = (void *)pv_vkCreateBuffer;
3001 custom_functions["vkCreateImage"] = (void *)pv_vkCreateImage;
3002 custom_functions["vkCreateImageView"] = (void *)pv_vkCreateImageView;
3003 custom_functions["vkCreateGraphicsPipelines"] = (void *)pv_vkCreateGraphicsPipelines;
3004 custom_functions["vkCreateComputePipelines"] = (void *)pv_vkCreateComputePipelines;
3005 custom_functions["vkCreateSampler"] = (void *)pv_vkCreateSampler;
3006 custom_functions["vkCreateDescriptorSetLayout"] = (void *)pv_vkCreateDescriptorSetLayout;
3007 custom_functions["vkFreeDescriptorSets"] = (void *)pv_vkFreeDescriptorSets;
3008 custom_functions["vkUpdateDescriptorSets"] = (void *)pv_vkUpdateDescriptorSets;
3009 custom_functions["vkCreateRenderPass"] = (void *)pv_vkCreateRenderPass;
3010 custom_functions["vkBeginCommandBuffer"] = (void *)pv_vkBeginCommandBuffer;
3011 custom_functions["vkCmdSetViewport"] = (void *)pv_vkCmdSetViewport;
3012 custom_functions["vkCmdSetScissor"] = (void *)pv_vkCmdSetScissor;
Petr Kraus299ba622017-11-24 03:09:03 +01003013 custom_functions["vkCmdSetLineWidth"] = (void *)pv_vkCmdSetLineWidth;
Dave Houltonb3bbec72018-01-17 10:13:33 -07003014 custom_functions["vkCmdDraw"] = (void *)pv_vkCmdDraw;
3015 custom_functions["vkCmdDrawIndirect"] = (void *)pv_vkCmdDrawIndirect;
3016 custom_functions["vkCmdDrawIndexedIndirect"] = (void *)pv_vkCmdDrawIndexedIndirect;
3017 custom_functions["vkCmdCopyImage"] = (void *)pv_vkCmdCopyImage;
3018 custom_functions["vkCmdBlitImage"] = (void *)pv_vkCmdBlitImage;
3019 custom_functions["vkCmdCopyBufferToImage"] = (void *)pv_vkCmdCopyBufferToImage;
3020 custom_functions["vkCmdCopyImageToBuffer"] = (void *)pv_vkCmdCopyImageToBuffer;
3021 custom_functions["vkCmdUpdateBuffer"] = (void *)pv_vkCmdUpdateBuffer;
3022 custom_functions["vkCmdFillBuffer"] = (void *)pv_vkCmdFillBuffer;
3023 custom_functions["vkCreateSwapchainKHR"] = (void *)pv_vkCreateSwapchainKHR;
3024 custom_functions["vkQueuePresentKHR"] = (void *)pv_vkQueuePresentKHR;
3025 custom_functions["vkCreateDescriptorPool"] = (void *)pv_vkCreateDescriptorPool;
3026 custom_functions["vkCmdDispatch"] = (void *)pv_vkCmdDispatch;
Mark Lobodzinskibf973a12018-03-01 08:50:21 -07003027 custom_functions["vkCmdDispatchBaseKHR"] = (void *)pv_vkCmdDispatchBaseKHR;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06003028}
3029
3030} // namespace parameter_validation
3031
3032VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
3033 VkExtensionProperties *pProperties) {
3034 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
3035}
3036
3037VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
3038 VkLayerProperties *pProperties) {
3039 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
3040}
3041
3042VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
3043 VkLayerProperties *pProperties) {
3044 // the layer command handles VK_NULL_HANDLE just fine internally
3045 assert(physicalDevice == VK_NULL_HANDLE);
3046 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
3047}
3048
3049VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
3050 const char *pLayerName, uint32_t *pCount,
3051 VkExtensionProperties *pProperties) {
3052 // the layer command handles VK_NULL_HANDLE just fine internally
3053 assert(physicalDevice == VK_NULL_HANDLE);
3054 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
3055}
3056
3057VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
3058 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
3059}
3060
3061VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
3062 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
3063}
3064
3065VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
3066 const char *funcName) {
3067 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
3068}
3069
3070VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
3071 assert(pVersionStruct != NULL);
3072 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
3073
3074 // Fill in the function pointers if our version is at least capable of having the structure contain them.
3075 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
3076 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
3077 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
3078 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
3079 }
3080
3081 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
3082 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
3083 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
3084 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
3085 }
3086
3087 return VK_SUCCESS;
3088}