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