blob: 11706cd93cecb7fd2c1405480348d74bb4f92fd1 [file] [log] [blame]
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001/* Copyright (c) 2015-2017 The Khronos Group Inc.
2 * Copyright (c) 2015-2017 Valve Corporation
3 * Copyright (c) 2015-2017 LunarG, Inc.
4 * Copyright (C) 2015-2017 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Mark Lobodzinski <mark@LunarG.com>
19 */
20
21#define NOMINMAX
22
23#include <limits.h>
24#include <math.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <inttypes.h>
29
30#include <iostream>
31#include <string>
32#include <sstream>
33#include <unordered_map>
34#include <unordered_set>
35#include <vector>
36#include <mutex>
37
38#include "vk_loader_platform.h"
39#include "vulkan/vk_layer.h"
40#include "vk_layer_config.h"
41#include "vk_dispatch_table_helper.h"
42
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
52// TODO: remove on NDK update (r15 will probably have proper STL impl)
53#ifdef __ANDROID__
54namespace std {
55
56template <typename T>
57std::string to_string(T var) {
58 std::ostringstream ss;
59 ss << var;
60 return ss.str();
61}
62} // namespace std
63#endif
64
65namespace parameter_validation {
66
Mark Lobodzinski78a12a92017-08-08 14:16:51 -060067extern std::unordered_map<std::string, void *> custom_functions;
68
Mark Lobodzinskid4950072017-08-01 13:02:20 -060069extern bool parameter_validation_vkCreateInstance(VkInstance instance, const VkInstanceCreateInfo *pCreateInfo,
70 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance);
71extern bool parameter_validation_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator);
72extern bool parameter_validation_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
73 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
74extern bool parameter_validation_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator);
75extern bool parameter_validation_vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
76 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool);
77extern bool parameter_validation_vkCreateDebugReportCallbackEXT(VkInstance instance,
78 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
79 const VkAllocationCallbacks *pAllocator,
80 VkDebugReportCallbackEXT *pMsgCallback);
81extern bool parameter_validation_vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
82 const VkAllocationCallbacks *pAllocator);
83extern bool parameter_validation_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
84 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool);
Petr Kraus595468a2017-09-10 02:26:33 +020085extern bool parameter_validation_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
86 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
87extern bool parameter_validation_vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
88 const VkAllocationCallbacks *pAllocator);
Mark Lobodzinskid4950072017-08-01 13:02:20 -060089
90// TODO : This can be much smarter, using separate locks for separate global data
91std::mutex global_lock;
92
93static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
94std::unordered_map<void *, layer_data *> layer_data_map;
95std::unordered_map<void *, instance_layer_data *> instance_layer_data_map;
96
97void InitializeManualParameterValidationFunctionPointers(void);
98
99static void init_parameter_validation(instance_layer_data *instance_data, const VkAllocationCallbacks *pAllocator) {
100 layer_debug_actions(instance_data->report_data, instance_data->logging_callback, pAllocator, "lunarg_parameter_validation");
101}
102
103static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
104
105static const VkLayerProperties global_layer = {
106 "VK_LAYER_LUNARG_parameter_validation", VK_LAYER_API_VERSION, 1, "LunarG Validation Layer",
107};
108
109static const int MaxParamCheckerStringLength = 256;
110
111static bool validate_string(debug_report_data *report_data, const char *apiName, const ParameterName &stringName,
112 const char *validateString) {
113 assert(apiName != nullptr);
114 assert(validateString != nullptr);
115
116 bool skip = false;
117
118 VkStringErrorFlags result = vk_string_validate(MaxParamCheckerStringLength, validateString);
119
120 if (result == VK_STRING_ERROR_NONE) {
121 return skip;
122 } else if (result & VK_STRING_ERROR_LENGTH) {
123 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
124 INVALID_USAGE, LayerName, "%s: string %s exceeds max length %d", apiName, stringName.get_name().c_str(),
125 MaxParamCheckerStringLength);
126 } else if (result & VK_STRING_ERROR_BAD_DATA) {
127 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
128 INVALID_USAGE, LayerName, "%s: string %s contains invalid characters or is badly formed", apiName,
129 stringName.get_name().c_str());
130 }
131 return skip;
132}
133
134static bool ValidateDeviceQueueFamily(layer_data *device_data, uint32_t queue_family, const char *cmd_name,
135 const char *parameter_name, int32_t error_code, bool optional = false,
136 const char *vu_note = nullptr) {
137 bool skip = false;
138
139 if (!vu_note) vu_note = validation_error_map[error_code];
140 if (!optional && queue_family == VK_QUEUE_FAMILY_IGNORED) {
141 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
142 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
143 "%s: %s is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family index value. %s",
144 cmd_name, parameter_name, vu_note);
145 } else if (device_data->queueFamilyIndexMap.find(queue_family) == device_data->queueFamilyIndexMap.end()) {
146 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
147 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
148 "%s: %s (= %" PRIu32
149 ") is not one of the queue families given via VkDeviceQueueCreateInfo structures when "
150 "the device was created. %s",
151 cmd_name, parameter_name, queue_family, vu_note);
152 }
153
154 return skip;
155}
156
157static bool ValidateQueueFamilies(layer_data *device_data, uint32_t queue_family_count, const uint32_t *queue_families,
158 const char *cmd_name, const char *array_parameter_name, int32_t unique_error_code,
159 int32_t valid_error_code, bool optional = false, const char *unique_vu_note = nullptr,
160 const char *valid_vu_note = nullptr) {
161 bool skip = false;
162 if (!unique_vu_note) unique_vu_note = validation_error_map[unique_error_code];
163 if (!valid_vu_note) valid_vu_note = validation_error_map[valid_error_code];
164 if (queue_families) {
165 std::unordered_set<uint32_t> set;
166 for (uint32_t i = 0; i < queue_family_count; ++i) {
167 std::string parameter_name = std::string(array_parameter_name) + "[" + std::to_string(i) + "]";
168
169 if (set.count(queue_families[i])) {
170 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
171 HandleToUint64(device_data->device), __LINE__, VALIDATION_ERROR_056002e8, LayerName,
172 "%s: %s (=%" PRIu32 ") is not unique within %s array. %s", cmd_name, parameter_name.c_str(),
173 queue_families[i], array_parameter_name, unique_vu_note);
174 } else {
175 set.insert(queue_families[i]);
176 skip |= ValidateDeviceQueueFamily(device_data, queue_families[i], cmd_name, parameter_name.c_str(),
177 valid_error_code, optional, valid_vu_note);
178 }
179 }
180 }
181 return skip;
182}
183
184VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
185 VkInstance *pInstance) {
186 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
187
188 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
189 assert(chain_info != nullptr);
190 assert(chain_info->u.pLayerInfo != nullptr);
191
192 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
193 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
194 if (fpCreateInstance == NULL) {
195 return VK_ERROR_INITIALIZATION_FAILED;
196 }
197
198 // Advance the link info for the next element on the chain
199 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
200
201 result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
202
203 if (result == VK_SUCCESS) {
204 InitializeManualParameterValidationFunctionPointers();
205 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), instance_layer_data_map);
206 assert(my_instance_data != nullptr);
207
208 layer_init_instance_dispatch_table(*pInstance, &my_instance_data->dispatch_table, fpGetInstanceProcAddr);
209 my_instance_data->instance = *pInstance;
210 my_instance_data->report_data =
211 debug_report_create_instance(&my_instance_data->dispatch_table, *pInstance, pCreateInfo->enabledExtensionCount,
212 pCreateInfo->ppEnabledExtensionNames);
213
214 // Look for one or more debug report create info structures
215 // and setup a callback(s) for each one found.
216 if (!layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_instance_data->num_tmp_callbacks,
217 &my_instance_data->tmp_dbg_create_infos, &my_instance_data->tmp_callbacks)) {
218 if (my_instance_data->num_tmp_callbacks > 0) {
219 // Setup the temporary callback(s) here to catch early issues:
220 if (layer_enable_tmp_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_callbacks,
221 my_instance_data->tmp_dbg_create_infos, my_instance_data->tmp_callbacks)) {
222 // Failure of setting up one or more of the callback.
223 // Therefore, clean up and don't use those callbacks:
224 layer_free_tmp_callbacks(my_instance_data->tmp_dbg_create_infos, my_instance_data->tmp_callbacks);
225 my_instance_data->num_tmp_callbacks = 0;
226 }
227 }
228 }
229
230 init_parameter_validation(my_instance_data, pAllocator);
231 my_instance_data->extensions.InitFromInstanceCreateInfo(pCreateInfo);
232
233 // Ordinarily we'd check these before calling down the chain, but none of the layer support is in place until now, if we
234 // survive we can report the issue now.
235 parameter_validation_vkCreateInstance(*pInstance, pCreateInfo, pAllocator, pInstance);
236
237 if (pCreateInfo->pApplicationInfo) {
238 if (pCreateInfo->pApplicationInfo->pApplicationName) {
239 validate_string(my_instance_data->report_data, "vkCreateInstance",
240 "pCreateInfo->VkApplicationInfo->pApplicationName",
241 pCreateInfo->pApplicationInfo->pApplicationName);
242 }
243
244 if (pCreateInfo->pApplicationInfo->pEngineName) {
245 validate_string(my_instance_data->report_data, "vkCreateInstance", "pCreateInfo->VkApplicationInfo->pEngineName",
246 pCreateInfo->pApplicationInfo->pEngineName);
247 }
248 }
249
250 // Disable the tmp callbacks:
251 if (my_instance_data->num_tmp_callbacks > 0) {
252 layer_disable_tmp_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_callbacks,
253 my_instance_data->tmp_callbacks);
254 }
255 }
256
257 return result;
258}
259
260VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
261 // Grab the key before the instance is destroyed.
262 dispatch_key key = get_dispatch_key(instance);
263 bool skip = false;
264 auto instance_data = GetLayerDataPtr(key, instance_layer_data_map);
265
266 // Enable the temporary callback(s) here to catch vkDestroyInstance issues:
267 bool callback_setup = false;
268 if (instance_data->num_tmp_callbacks > 0) {
269 if (!layer_enable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks,
270 instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks)) {
271 callback_setup = true;
272 }
273 }
274
275 skip |= parameter_validation_vkDestroyInstance(instance, pAllocator);
276
277 // Disable and cleanup the temporary callback(s):
278 if (callback_setup) {
279 layer_disable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks, instance_data->tmp_callbacks);
280 }
281 if (instance_data->num_tmp_callbacks > 0) {
282 layer_free_tmp_callbacks(instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks);
283 instance_data->num_tmp_callbacks = 0;
284 }
285
286 if (!skip) {
287 instance_data->dispatch_table.DestroyInstance(instance, pAllocator);
288
289 // Clean up logging callback, if any
290 while (instance_data->logging_callback.size() > 0) {
291 VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
292 layer_destroy_msg_callback(instance_data->report_data, callback, pAllocator);
293 instance_data->logging_callback.pop_back();
294 }
295
296 layer_debug_report_destroy_instance(instance_data->report_data);
297 }
298
299 FreeLayerDataPtr(key, instance_layer_data_map);
300}
301
302VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance,
303 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
304 const VkAllocationCallbacks *pAllocator,
305 VkDebugReportCallbackEXT *pMsgCallback) {
306 bool skip = parameter_validation_vkCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
307 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
308
309 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
310 VkResult result = instance_data->dispatch_table.CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
311 if (result == VK_SUCCESS) {
312 result = layer_create_msg_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback);
313 }
314 return result;
315}
316
317VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
318 const VkAllocationCallbacks *pAllocator) {
319 bool skip = parameter_validation_vkDestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
320 if (!skip) {
321 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
322 instance_data->dispatch_table.DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
323 layer_destroy_msg_callback(instance_data->report_data, msgCallback, pAllocator);
324 }
325}
326
327static bool ValidateDeviceCreateInfo(instance_layer_data *instance_data, VkPhysicalDevice physicalDevice,
328 const VkDeviceCreateInfo *pCreateInfo) {
329 bool skip = false;
330
331 if ((pCreateInfo->enabledLayerCount > 0) && (pCreateInfo->ppEnabledLayerNames != NULL)) {
332 for (size_t i = 0; i < pCreateInfo->enabledLayerCount; i++) {
333 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledLayerNames",
334 pCreateInfo->ppEnabledLayerNames[i]);
335 }
336 }
337
338 bool maint1 = false;
339 bool negative_viewport = false;
340
341 if ((pCreateInfo->enabledExtensionCount > 0) && (pCreateInfo->ppEnabledExtensionNames != NULL)) {
342 for (size_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
343 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledExtensionNames",
344 pCreateInfo->ppEnabledExtensionNames[i]);
345 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) maint1 = true;
346 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME) == 0)
347 negative_viewport = true;
348 }
349 }
350
351 if (maint1 && negative_viewport) {
352 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
353 __LINE__, VALIDATION_ERROR_056002ec, LayerName,
354 "VkDeviceCreateInfo->ppEnabledExtensionNames must not simultaneously include VK_KHR_maintenance1 and "
355 "VK_AMD_negative_viewport_height. %s",
356 validation_error_map[VALIDATION_ERROR_056002ec]);
357 }
358
359 if (pCreateInfo->pNext != NULL && pCreateInfo->pEnabledFeatures) {
360 // Check for get_physical_device_properties2 struct
361 struct std_header {
362 VkStructureType sType;
363 const void *pNext;
364 };
365 std_header *cur_pnext = (std_header *)pCreateInfo->pNext;
366 while (cur_pnext) {
367 if (VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR == cur_pnext->sType) {
368 // Cannot include VkPhysicalDeviceFeatures2KHR and have non-null pEnabledFeatures
369 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
370 0, __LINE__, INVALID_USAGE, LayerName,
371 "VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceFeatures2KHR struct when "
372 "pCreateInfo->pEnabledFeatures is non-NULL.");
373 break;
374 }
375 cur_pnext = (std_header *)cur_pnext->pNext;
376 }
377 }
378 if (pCreateInfo->pNext != NULL && pCreateInfo->pEnabledFeatures) {
379 // Check for get_physical_device_properties2 struct
380 struct std_header {
381 VkStructureType sType;
382 const void *pNext;
383 };
384 std_header *cur_pnext = (std_header *)pCreateInfo->pNext;
385 while (cur_pnext) {
386 if (VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR == cur_pnext->sType) {
387 // Cannot include VkPhysicalDeviceFeatures2KHR and have non-null pEnabledFeatures
388 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
389 0, __LINE__, INVALID_USAGE, LayerName,
390 "VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceFeatures2KHR struct when "
391 "pCreateInfo->pEnabledFeatures is non-NULL.");
392 break;
393 }
394 cur_pnext = (std_header *)cur_pnext->pNext;
395 }
396 }
397
398 // Validate pCreateInfo->pQueueCreateInfos
399 if (pCreateInfo->pQueueCreateInfos) {
400 std::unordered_set<uint32_t> set;
401
402 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
403 const uint32_t requested_queue_family = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
404 if (requested_queue_family == VK_QUEUE_FAMILY_IGNORED) {
405 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
406 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
407 VALIDATION_ERROR_06c002fa, LayerName,
408 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32
409 "].queueFamilyIndex is "
410 "VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family index value. %s",
411 i, validation_error_map[VALIDATION_ERROR_06c002fa]);
412 } else if (set.count(requested_queue_family)) {
413 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
414 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
415 VALIDATION_ERROR_056002e8, LayerName,
416 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].queueFamilyIndex (=%" PRIu32
417 ") is "
418 "not unique within pCreateInfo->pQueueCreateInfos array. %s",
419 i, requested_queue_family, validation_error_map[VALIDATION_ERROR_056002e8]);
420 } else {
421 set.insert(requested_queue_family);
422 }
423
424 if (pCreateInfo->pQueueCreateInfos[i].pQueuePriorities != nullptr) {
425 for (uint32_t j = 0; j < pCreateInfo->pQueueCreateInfos[i].queueCount; ++j) {
426 const float queue_priority = pCreateInfo->pQueueCreateInfos[i].pQueuePriorities[j];
427 if (!(queue_priority >= 0.f) || !(queue_priority <= 1.f)) {
428 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
429 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
430 VALIDATION_ERROR_06c002fe, LayerName,
431 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].pQueuePriorities[%" PRIu32
432 "] (=%f) is not between 0 and 1 (inclusive). %s",
433 i, j, queue_priority, validation_error_map[VALIDATION_ERROR_06c002fe]);
434 }
435 }
436 }
437 }
438 }
439
440 return skip;
441}
442
443VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
444 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
445 // NOTE: Don't validate physicalDevice or any dispatchable object as the first parameter. We couldn't get here if it was wrong!
446
447 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
448 bool skip = false;
449 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
450 assert(my_instance_data != nullptr);
451 std::unique_lock<std::mutex> lock(global_lock);
452
453 skip |= parameter_validation_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
454
455 if (pCreateInfo != NULL) skip |= ValidateDeviceCreateInfo(my_instance_data, physicalDevice, pCreateInfo);
456
457 if (!skip) {
458 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
459 assert(chain_info != nullptr);
460 assert(chain_info->u.pLayerInfo != nullptr);
461
462 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
463 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
464 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice");
465 if (fpCreateDevice == NULL) {
466 return VK_ERROR_INITIALIZATION_FAILED;
467 }
468
469 // Advance the link info for the next element on the chain
470 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
471
472 lock.unlock();
473
474 result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
475
476 lock.lock();
477
478 validate_result(my_instance_data->report_data, "vkCreateDevice", {}, result);
479
480 if (result == VK_SUCCESS) {
481 layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
482 assert(my_device_data != nullptr);
483
484 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
485 layer_init_device_dispatch_table(*pDevice, &my_device_data->dispatch_table, fpGetDeviceProcAddr);
486
487 my_device_data->extensions.InitFromDeviceCreateInfo(&my_instance_data->extensions, pCreateInfo);
488
489 // Store createdevice data
490 if ((pCreateInfo != nullptr) && (pCreateInfo->pQueueCreateInfos != nullptr)) {
491 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
492 my_device_data->queueFamilyIndexMap.insert(std::make_pair(pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex,
493 pCreateInfo->pQueueCreateInfos[i].queueCount));
494 }
495 }
496
497 // Query and save physical device limits for this device
498 VkPhysicalDeviceProperties device_properties = {};
499 my_instance_data->dispatch_table.GetPhysicalDeviceProperties(physicalDevice, &device_properties);
500 memcpy(&my_device_data->device_limits, &device_properties.limits, sizeof(VkPhysicalDeviceLimits));
501 my_device_data->physical_device = physicalDevice;
502 my_device_data->device = *pDevice;
503
504 // Save app-enabled features in this device's layer_data structure
505 if (pCreateInfo->pEnabledFeatures) {
506 my_device_data->physical_device_features = *pCreateInfo->pEnabledFeatures;
507 } else {
508 memset(&my_device_data->physical_device_features, 0, sizeof(VkPhysicalDeviceFeatures));
509 }
510 }
511 }
512
513 return result;
514}
515
516VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
517 dispatch_key key = get_dispatch_key(device);
518 bool skip = false;
519 layer_data *device_data = GetLayerDataPtr(key, layer_data_map);
520 {
521 std::unique_lock<std::mutex> lock(global_lock);
522 skip |= parameter_validation_vkDestroyDevice(device, pAllocator);
523 }
524
525 if (!skip) {
526 layer_debug_report_destroy_device(device);
527 device_data->dispatch_table.DestroyDevice(device, pAllocator);
528 }
529 FreeLayerDataPtr(key, layer_data_map);
530}
531
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600532bool pv_vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
533 bool skip = false;
534 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
535
536 skip |=
537 ValidateDeviceQueueFamily(device_data, queueFamilyIndex, "vkGetDeviceQueue", "queueFamilyIndex", VALIDATION_ERROR_29600300);
538 const auto &queue_data = device_data->queueFamilyIndexMap.find(queueFamilyIndex);
539 if (queue_data != device_data->queueFamilyIndexMap.end() && queue_data->second <= queueIndex) {
540 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
541 HandleToUint64(device), __LINE__, VALIDATION_ERROR_29600302, LayerName,
542 "vkGetDeviceQueue: queueIndex (=%" PRIu32
543 ") is not less than the number of queues requested from "
544 "queueFamilyIndex (=%" PRIu32 ") when the device was created (i.e. is not less than %" PRIu32 "). %s",
545 queueIndex, queueFamilyIndex, queue_data->second, validation_error_map[VALIDATION_ERROR_29600302]);
546 }
547 return skip;
548}
549
550VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
551 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool) {
552 layer_data *local_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
553 bool skip = false;
554 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
555 std::unique_lock<std::mutex> lock(global_lock);
556
557 skip |= ValidateDeviceQueueFamily(local_data, pCreateInfo->queueFamilyIndex, "vkCreateCommandPool",
558 "pCreateInfo->queueFamilyIndex", VALIDATION_ERROR_02c0004e);
559
560 skip |= parameter_validation_vkCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
561
562 lock.unlock();
563 if (!skip) {
564 result = local_data->dispatch_table.CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
565 }
566 return result;
567}
568
569VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
570 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool) {
571 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
572 bool skip = false;
573 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
574
575 skip |= parameter_validation_vkCreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
576
577 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
578 if (pCreateInfo != nullptr) {
579 // If queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, pipelineStatistics must be a valid combination of
580 // VkQueryPipelineStatisticFlagBits values
581 if ((pCreateInfo->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS) && (pCreateInfo->pipelineStatistics != 0) &&
582 ((pCreateInfo->pipelineStatistics & (~AllVkQueryPipelineStatisticFlagBits)) != 0)) {
583 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
584 __LINE__, VALIDATION_ERROR_11c00630, LayerName,
585 "vkCreateQueryPool(): if pCreateInfo->queryType is "
586 "VK_QUERY_TYPE_PIPELINE_STATISTICS, pCreateInfo->pipelineStatistics must be "
587 "a valid combination of VkQueryPipelineStatisticFlagBits values. %s",
588 validation_error_map[VALIDATION_ERROR_11c00630]);
589 }
590 }
591 if (!skip) {
592 result = device_data->dispatch_table.CreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
593 }
594 return result;
595}
596
Petr Kraus595468a2017-09-10 02:26:33 +0200597VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
598 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass) {
599 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
600 bool skip = false;
601 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
602
603 {
604 std::unique_lock<std::mutex> lock(global_lock);
605 skip |= parameter_validation_vkCreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
606
607 typedef bool (*PFN_manual_vkCreateRenderPass)(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
608 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
609 PFN_manual_vkCreateRenderPass custom_func = (PFN_manual_vkCreateRenderPass)custom_functions["vkCreateRenderPass"];
610 if (custom_func != nullptr) {
611 skip |= custom_func(device, pCreateInfo, pAllocator, pRenderPass);
612 }
613 }
614
615 if (!skip) {
616 result = device_data->dispatch_table.CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
617
618 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
619 if (result == VK_SUCCESS) {
620 std::unique_lock<std::mutex> lock(global_lock);
621 const auto renderPass = *pRenderPass;
622 auto &renderpass_state = device_data->renderpasses_states[renderPass];
623
624 for (uint32_t subpass = 0; subpass < pCreateInfo->subpassCount; ++subpass) {
625 bool uses_color = false;
626 for (uint32_t i = 0; i < pCreateInfo->pSubpasses[subpass].colorAttachmentCount && !uses_color; ++i)
627 if (pCreateInfo->pSubpasses[subpass].pColorAttachments[i].attachment != VK_ATTACHMENT_UNUSED) uses_color = true;
628
629 bool uses_depthstencil = false;
630 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment)
631 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)
632 uses_depthstencil = true;
633
634 if (uses_color) renderpass_state.subpasses_using_color_attachment.insert(subpass);
635 if (uses_depthstencil) renderpass_state.subpasses_using_depthstencil_attachment.insert(subpass);
636 }
637 }
638 }
639 return result;
640}
641
642VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator) {
643 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
644 bool skip = false;
645
646 {
647 std::unique_lock<std::mutex> lock(global_lock);
648 skip |= parameter_validation_vkDestroyRenderPass(device, renderPass, pAllocator);
649
650 typedef bool (*PFN_manual_vkDestroyRenderPass)(VkDevice device, VkRenderPass renderPass,
651 const VkAllocationCallbacks *pAllocator);
652 PFN_manual_vkDestroyRenderPass custom_func = (PFN_manual_vkDestroyRenderPass)custom_functions["vkDestroyRenderPass"];
653 if (custom_func != nullptr) {
654 skip |= custom_func(device, renderPass, pAllocator);
655 }
656 }
657
658 if (!skip) {
659 device_data->dispatch_table.DestroyRenderPass(device, renderPass, pAllocator);
660
661 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
662 {
663 std::unique_lock<std::mutex> lock(global_lock);
664 device_data->renderpasses_states.erase(renderPass);
665 }
666 }
667}
668
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600669bool pv_vkCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
670 VkBuffer *pBuffer) {
671 bool skip = false;
672 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
673 debug_report_data *report_data = device_data->report_data;
674
675 if (pCreateInfo != nullptr) {
676 // Buffer size must be greater than 0 (error 00663)
677 skip |=
678 ValidateGreaterThan(report_data, "vkCreateBuffer", "pCreateInfo->size", static_cast<uint32_t>(pCreateInfo->size), 0u);
679
680 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
681 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
682 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
683 if (pCreateInfo->queueFamilyIndexCount <= 1) {
684 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
685 VALIDATION_ERROR_01400724, LayerName,
686 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
687 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
688 validation_error_map[VALIDATION_ERROR_01400724]);
689 }
690
691 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
692 // queueFamilyIndexCount uint32_t values
693 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
694 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
695 VALIDATION_ERROR_01400722, LayerName,
696 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
697 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
698 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
699 validation_error_map[VALIDATION_ERROR_01400722]);
700 } else {
701 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
702 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
703 "vkCreateBuffer", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
704 false, "", "");
705 }
706 }
707
708 // If flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain
709 // VK_BUFFER_CREATE_SPARSE_BINDING_BIT
710 if (((pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
711 ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) != VK_BUFFER_CREATE_SPARSE_BINDING_BIT)) {
712 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
713 VALIDATION_ERROR_0140072c, LayerName,
714 "vkCreateBuffer: if pCreateInfo->flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or "
715 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_BUFFER_CREATE_SPARSE_BINDING_BIT. %s",
716 validation_error_map[VALIDATION_ERROR_0140072c]);
717 }
718 }
719
720 return skip;
721}
722
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600723bool pv_vkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
724 VkImage *pImage) {
725 bool skip = false;
726 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
727 debug_report_data *report_data = device_data->report_data;
728
729 if (pCreateInfo != nullptr) {
730 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
731 FormatIsCompressed_ETC2_EAC(pCreateInfo->format)) {
732 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
733 DEVICE_FEATURE, LayerName,
734 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionETC2 feature is "
735 "not enabled: neither ETC2 nor EAC formats can be used to create images.",
736 string_VkFormat(pCreateInfo->format));
737 }
738
739 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
740 FormatIsCompressed_ASTC_LDR(pCreateInfo->format)) {
741 skip |=
742 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
743 DEVICE_FEATURE, LayerName,
744 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionASTC_LDR feature is "
745 "not enabled: ASTC formats cannot be used to create images.",
746 string_VkFormat(pCreateInfo->format));
747 }
748
749 if ((device_data->physical_device_features.textureCompressionBC == false) && FormatIsCompressed_BC(pCreateInfo->format)) {
750 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
751 DEVICE_FEATURE, LayerName,
752 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionBC feature is "
753 "not enabled: BC compressed formats cannot be used to create images.",
754 string_VkFormat(pCreateInfo->format));
755 }
756
757 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
758 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
759 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
760 if (pCreateInfo->queueFamilyIndexCount <= 1) {
761 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
762 VALIDATION_ERROR_09e0075c, LayerName,
763 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
764 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
765 validation_error_map[VALIDATION_ERROR_09e0075c]);
766 }
767
768 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
769 // queueFamilyIndexCount uint32_t values
770 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
771 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
772 VALIDATION_ERROR_09e0075a, LayerName,
773 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
774 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
775 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
776 validation_error_map[VALIDATION_ERROR_09e0075a]);
777 } else {
778 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
779 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
780 "vkCreateImage", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
781 false, "", "");
782 }
783 }
784
785 // width, height, and depth members of extent must be greater than 0
786 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->extent.width", pCreateInfo->extent.width, 0u);
787 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->extent.height", pCreateInfo->extent.height, 0u);
788 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->extent.depth", pCreateInfo->extent.depth, 0u);
789
790 // mipLevels must be greater than 0
791 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->mipLevels", pCreateInfo->mipLevels, 0u);
792
793 // arrayLayers must be greater than 0
794 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->arrayLayers", pCreateInfo->arrayLayers, 0u);
795
796 // If imageType is VK_IMAGE_TYPE_1D, both extent.height and extent.depth must be 1
797 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) && (pCreateInfo->extent.height != 1) && (pCreateInfo->extent.depth != 1)) {
798 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
799 VALIDATION_ERROR_09e00778, LayerName,
800 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_1D, both "
801 "pCreateInfo->extent.height and pCreateInfo->extent.depth must be 1. %s",
802 validation_error_map[VALIDATION_ERROR_09e00778]);
803 }
804
805 if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D) {
806 // If imageType is VK_IMAGE_TYPE_2D and flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, extent.width and
807 // extent.height must be equal
808 if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
809 (pCreateInfo->extent.width != pCreateInfo->extent.height)) {
810 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
811 VALIDATION_ERROR_09e00774, LayerName,
812 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D and "
813 "pCreateInfo->flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, "
814 "pCreateInfo->extent.width and pCreateInfo->extent.height must be equal. %s",
815 validation_error_map[VALIDATION_ERROR_09e00774]);
816 }
817
818 if (pCreateInfo->extent.depth != 1) {
819 skip |= log_msg(
820 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
821 VALIDATION_ERROR_09e0077a, LayerName,
822 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1. %s",
823 validation_error_map[VALIDATION_ERROR_09e0077a]);
824 }
825 }
826
827 // mipLevels must be less than or equal to floor(log2(max(extent.width,extent.height,extent.depth)))+1
828 uint32_t maxDim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
829 if (pCreateInfo->mipLevels > (floor(log2(maxDim)) + 1)) {
830 skip |=
831 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
832 VALIDATION_ERROR_09e0077c, LayerName,
833 "vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
834 "floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1. %s",
835 validation_error_map[VALIDATION_ERROR_09e0077c]);
836 }
837
838 // If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
839 // VK_IMAGE_CREATE_SPARSE_BINDING_BIT
840 if (((pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
841 ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
842 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
843 VALIDATION_ERROR_09e007b6, LayerName,
844 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
845 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT. %s",
846 validation_error_map[VALIDATION_ERROR_09e007b6]);
847 }
848
849 // Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
850 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
851 // Linear tiling is unsupported
852 if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
853 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
854 INVALID_USAGE, LayerName,
855 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT "
856 "then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
857 }
858
859 // Sparse 1D image isn't valid
860 if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
861 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
862 VALIDATION_ERROR_09e00794, LayerName,
863 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image. %s",
864 validation_error_map[VALIDATION_ERROR_09e00794]);
865 }
866
867 // Sparse 2D image when device doesn't support it
868 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage2D) &&
869 (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
870 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
871 VALIDATION_ERROR_09e00796, LayerName,
872 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
873 "feature is not enabled on the device. %s",
874 validation_error_map[VALIDATION_ERROR_09e00796]);
875 }
876
877 // Sparse 3D image when device doesn't support it
878 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage3D) &&
879 (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
880 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
881 VALIDATION_ERROR_09e00798, LayerName,
882 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
883 "feature is not enabled on the device. %s",
884 validation_error_map[VALIDATION_ERROR_09e00798]);
885 }
886
887 // Multi-sample 2D image when device doesn't support it
888 if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
889 if ((VK_FALSE == device_data->physical_device_features.sparseResidency2Samples) &&
890 (VK_SAMPLE_COUNT_2_BIT == pCreateInfo->samples)) {
891 skip |= log_msg(
892 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
893 VALIDATION_ERROR_09e0079a, LayerName,
894 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if corresponding "
895 "feature is not enabled on the device. %s",
896 validation_error_map[VALIDATION_ERROR_09e0079a]);
897 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency4Samples) &&
898 (VK_SAMPLE_COUNT_4_BIT == pCreateInfo->samples)) {
899 skip |= log_msg(
900 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
901 VALIDATION_ERROR_09e0079c, LayerName,
902 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if corresponding "
903 "feature is not enabled on the device. %s",
904 validation_error_map[VALIDATION_ERROR_09e0079c]);
905 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency8Samples) &&
906 (VK_SAMPLE_COUNT_8_BIT == pCreateInfo->samples)) {
907 skip |= log_msg(
908 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
909 VALIDATION_ERROR_09e0079e, LayerName,
910 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if corresponding "
911 "feature is not enabled on the device. %s",
912 validation_error_map[VALIDATION_ERROR_09e0079e]);
913 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency16Samples) &&
914 (VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
915 skip |= log_msg(
916 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
917 VALIDATION_ERROR_09e007a0, LayerName,
918 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if corresponding "
919 "feature is not enabled on the device. %s",
920 validation_error_map[VALIDATION_ERROR_09e007a0]);
921 }
922 }
923 }
924 }
925 return skip;
926}
927
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600928bool pv_vkCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
929 VkImageView *pView) {
930 bool skip = false;
931 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
932 debug_report_data *report_data = device_data->report_data;
933
934 if (pCreateInfo != nullptr) {
935 if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) || (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D)) {
936 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
937 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
938 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
939 LayerName,
940 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD, "
941 "pCreateInfo->subresourceRange.layerCount must be 1",
942 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) ? 1 : 2));
943 }
944 } else if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ||
945 (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
946 if ((pCreateInfo->subresourceRange.layerCount < 1) &&
947 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
948 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
949 LayerName,
950 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD_ARRAY, "
951 "pCreateInfo->subresourceRange.layerCount must be >= 1",
952 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ? 1 : 2));
953 }
954 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE) {
955 if ((pCreateInfo->subresourceRange.layerCount != 6) &&
956 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
957 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
958 LayerName,
959 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE, "
960 "pCreateInfo->subresourceRange.layerCount must be 6");
961 }
962 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
963 if (((pCreateInfo->subresourceRange.layerCount == 0) || ((pCreateInfo->subresourceRange.layerCount % 6) != 0)) &&
964 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
965 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
966 LayerName,
967 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE_ARRAY, "
968 "pCreateInfo->subresourceRange.layerCount must be a multiple of 6");
969 }
970 if (!device_data->physical_device_features.imageCubeArray) {
971 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
972 LayerName, "vkCreateImageView: Device feature imageCubeArray not enabled.");
973 }
974 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_3D) {
975 if (pCreateInfo->subresourceRange.baseArrayLayer != 0) {
976 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
977 LayerName,
978 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
979 "pCreateInfo->subresourceRange.baseArrayLayer must be 0");
980 }
981
982 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
983 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
984 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
985 LayerName,
986 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
987 "pCreateInfo->subresourceRange.layerCount must be 1");
988 }
989 }
990 }
991 return skip;
992}
993
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600994bool pv_vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
995 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
996 VkPipeline *pPipelines) {
997 bool skip = false;
998 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
999 debug_report_data *report_data = device_data->report_data;
1000
1001 if (pCreateInfos != nullptr) {
1002 for (uint32_t i = 0; i < createInfoCount; ++i) {
1003 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1004 if (pCreateInfos[i].pVertexInputState != nullptr) {
1005 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
1006 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
1007 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
1008 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1009 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1010 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
1011 "vkCreateGraphicsPipelines: parameter "
1012 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
1013 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1014 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
1015 validation_error_map[VALIDATION_ERROR_14c004d4]);
1016 }
1017
1018 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
1019 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1020 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
1021 "vkCreateGraphicsPipelines: parameter "
1022 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
1023 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
1024 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
1025 validation_error_map[VALIDATION_ERROR_14c004d6]);
1026 }
1027 }
1028
1029 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
1030 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
1031 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
1032 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1033 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
1034 "vkCreateGraphicsPipelines: parameter "
1035 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
1036 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
1037 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
1038 validation_error_map[VALIDATION_ERROR_14a004d8]);
1039 }
1040
1041 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1042 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1043 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
1044 "vkCreateGraphicsPipelines: parameter "
1045 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
1046 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1047 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
1048 validation_error_map[VALIDATION_ERROR_14a004da]);
1049 }
1050
1051 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
1052 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1053 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
1054 "vkCreateGraphicsPipelines: parameter "
1055 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
1056 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
1057 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
1058 validation_error_map[VALIDATION_ERROR_14a004dc]);
1059 }
1060 }
1061 }
1062
1063 if (pCreateInfos[i].pStages != nullptr) {
1064 bool has_control = false;
1065 bool has_eval = false;
1066
1067 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
1068 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1069 has_control = true;
1070 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
1071 has_eval = true;
1072 }
1073 }
1074
1075 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1076 if (has_control && has_eval) {
1077 if (pCreateInfos[i].pTessellationState == nullptr) {
1078 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1079 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
1080 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1081 "shader stage and a tessellation evaluation shader stage, "
1082 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
1083 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
1084 } else {
1085 skip |= validate_struct_pnext(
1086 report_data, "vkCreateGraphicsPipelines",
1087 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
1088 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
1089
1090 skip |= validate_reserved_flags(
1091 report_data, "vkCreateGraphicsPipelines",
1092 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1093 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1094
1095 if (pCreateInfos[i].pTessellationState->sType !=
1096 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1097 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1098 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1099 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1100 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1101 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1102 }
1103
1104 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1105 pCreateInfos[i].pTessellationState->patchControlPoints >
1106 device_data->device_limits.maxTessellationPatchSize) {
1107 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1108 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1109 "vkCreateGraphicsPipelines: invalid parameter "
1110 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1111 "should be >0 and <=%u. %s",
1112 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1113 device_data->device_limits.maxTessellationPatchSize,
1114 validation_error_map[VALIDATION_ERROR_1080097c]);
1115 }
1116 }
1117 }
1118 }
1119
1120 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1121 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1122 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1123 if (pCreateInfos[i].pViewportState == nullptr) {
1124 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1125 __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1126 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1127 "is VK_FALSE, pCreateInfos[%d].pViewportState must be a pointer to a valid "
1128 "VkPipelineViewportStateCreateInfo structure. %s",
1129 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1130 } else {
1131 if (pCreateInfos[i].pViewportState->scissorCount != pCreateInfos[i].pViewportState->viewportCount) {
1132 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1133 __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1134 "Graphics Pipeline viewport count (%u) must match scissor count (%u). %s",
1135 pCreateInfos[i].pViewportState->viewportCount, pCreateInfos[i].pViewportState->scissorCount,
1136 validation_error_map[VALIDATION_ERROR_10c00988]);
1137 }
1138
1139 skip |= validate_struct_pnext(
1140 report_data, "vkCreateGraphicsPipelines",
1141 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}), NULL,
1142 pCreateInfos[i].pViewportState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_10c1c40d);
1143
1144 skip |= validate_reserved_flags(
1145 report_data, "vkCreateGraphicsPipelines",
1146 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
1147 pCreateInfos[i].pViewportState->flags, VALIDATION_ERROR_10c09005);
1148
1149 if (pCreateInfos[i].pViewportState->sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1150 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1151 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1152 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pViewportState->sType must be "
1153 "VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO",
1154 i);
1155 }
1156
1157 if (device_data->physical_device_features.multiViewport == false) {
1158 if (pCreateInfos[i].pViewportState->viewportCount != 1) {
1159 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1160 __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1161 "vkCreateGraphicsPipelines: The multiViewport feature is not enabled, so "
1162 "pCreateInfos[%d].pViewportState->viewportCount must be 1 but is %d. %s",
1163 i, pCreateInfos[i].pViewportState->viewportCount,
1164 validation_error_map[VALIDATION_ERROR_10c00980]);
1165 }
1166 if (pCreateInfos[i].pViewportState->scissorCount != 1) {
1167 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1168 __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1169 "vkCreateGraphicsPipelines: The multiViewport feature is not enabled, so "
1170 "pCreateInfos[%d].pViewportState->scissorCount must be 1 but is %d. %s",
1171 i, pCreateInfos[i].pViewportState->scissorCount,
1172 validation_error_map[VALIDATION_ERROR_10c00982]);
1173 }
1174 } else {
1175 if ((pCreateInfos[i].pViewportState->viewportCount < 1) ||
1176 (pCreateInfos[i].pViewportState->viewportCount > device_data->device_limits.maxViewports)) {
1177 skip |=
1178 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1179 __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1180 "vkCreateGraphicsPipelines: multiViewport feature is enabled; "
1181 "pCreateInfos[%d].pViewportState->viewportCount is %d but must be between 1 and "
1182 "maxViewports (%d), inclusive. %s",
1183 i, pCreateInfos[i].pViewportState->viewportCount, device_data->device_limits.maxViewports,
1184 validation_error_map[VALIDATION_ERROR_10c00984]);
1185 }
1186 if ((pCreateInfos[i].pViewportState->scissorCount < 1) ||
1187 (pCreateInfos[i].pViewportState->scissorCount > device_data->device_limits.maxViewports)) {
1188 skip |=
1189 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1190 __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1191 "vkCreateGraphicsPipelines: multiViewport feature is enabled; "
1192 "pCreateInfos[%d].pViewportState->scissorCount is %d but must be between 1 and "
1193 "maxViewports (%d), inclusive. %s",
1194 i, pCreateInfos[i].pViewportState->scissorCount, device_data->device_limits.maxViewports,
1195 validation_error_map[VALIDATION_ERROR_10c00986]);
1196 }
1197 }
1198
1199 if (pCreateInfos[i].pDynamicState != nullptr) {
1200 bool has_dynamic_viewport = false;
1201 bool has_dynamic_scissor = false;
1202
1203 for (uint32_t state_index = 0; state_index < pCreateInfos[i].pDynamicState->dynamicStateCount;
1204 ++state_index) {
1205 if (pCreateInfos[i].pDynamicState->pDynamicStates[state_index] == VK_DYNAMIC_STATE_VIEWPORT) {
1206 has_dynamic_viewport = true;
1207 } else if (pCreateInfos[i].pDynamicState->pDynamicStates[state_index] == VK_DYNAMIC_STATE_SCISSOR) {
1208 has_dynamic_scissor = true;
1209 }
1210 }
1211
1212 // If no element of the pDynamicStates member of pDynamicState is VK_DYNAMIC_STATE_VIEWPORT, the pViewports
1213 // member of pViewportState must be a pointer to an array of pViewportState->viewportCount VkViewport
1214 // structures
1215 if (!has_dynamic_viewport && (pCreateInfos[i].pViewportState->pViewports == nullptr)) {
1216 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1217 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1218 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pDynamicState->pDynamicStates does not "
1219 "contain VK_DYNAMIC_STATE_VIEWPORT, pCreateInfos[%d].pViewportState->pViewports must "
1220 "not be NULL. %s",
1221 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1222 }
1223
1224 // If no element of the pDynamicStates member of pDynamicState is VK_DYNAMIC_STATE_SCISSOR, the pScissors
1225 // member
1226 // of pViewportState must be a pointer to an array of pViewportState->scissorCount VkRect2D structures
1227 if (!has_dynamic_scissor && (pCreateInfos[i].pViewportState->pScissors == nullptr)) {
1228 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1229 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1230 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pDynamicState->pDynamicStates does not "
1231 "contain VK_DYNAMIC_STATE_SCISSOR, pCreateInfos[%d].pViewportState->pScissors must not "
1232 "be NULL. %s",
1233 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1234 }
1235 }
1236 }
1237
1238 if (pCreateInfos[i].pMultisampleState == nullptr) {
1239 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1240 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1241 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1242 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1243 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1244 } else {
1245 skip |= validate_struct_pnext(
1246 report_data, "vkCreateGraphicsPipelines",
1247 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}), NULL,
1248 pCreateInfos[i].pMultisampleState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1001c40d);
1249
1250 skip |= validate_reserved_flags(
1251 report_data, "vkCreateGraphicsPipelines",
1252 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1253 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1254
1255 skip |= validate_bool32(
1256 report_data, "vkCreateGraphicsPipelines",
1257 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1258 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1259
1260 skip |= validate_array(
1261 report_data, "vkCreateGraphicsPipelines",
1262 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1263 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1264 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1265 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1266
1267 skip |= validate_bool32(
1268 report_data, "vkCreateGraphicsPipelines",
1269 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1270 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1271
1272 skip |= validate_bool32(
1273 report_data, "vkCreateGraphicsPipelines",
1274 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1275 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1276
1277 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1278 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1279 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1280 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1281 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1282 i);
1283 }
1284 }
1285
Petr Kraus595468a2017-09-10 02:26:33 +02001286 bool uses_color_attachment = false;
1287 bool uses_depthstencil_attachment = false;
1288 {
1289 const auto subpasses_uses_it = device_data->renderpasses_states.find(pCreateInfos[i].renderPass);
1290 if (subpasses_uses_it != device_data->renderpasses_states.end()) {
1291 const auto &subpasses_uses = subpasses_uses_it->second;
1292 if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[i].subpass))
1293 uses_color_attachment = true;
1294 if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[i].subpass))
1295 uses_depthstencil_attachment = true;
1296 }
1297 }
1298
1299 if (pCreateInfos[i].pDepthStencilState != nullptr && uses_depthstencil_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001300 skip |= validate_struct_pnext(
1301 report_data, "vkCreateGraphicsPipelines",
1302 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1303 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1304
1305 skip |= validate_reserved_flags(
1306 report_data, "vkCreateGraphicsPipelines",
1307 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1308 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1309
1310 skip |= validate_bool32(
1311 report_data, "vkCreateGraphicsPipelines",
1312 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1313 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1314
1315 skip |= validate_bool32(
1316 report_data, "vkCreateGraphicsPipelines",
1317 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1318 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1319
1320 skip |= validate_ranged_enum(
1321 report_data, "vkCreateGraphicsPipelines",
1322 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1323 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1324 VALIDATION_ERROR_0f604001);
1325
1326 skip |= validate_bool32(
1327 report_data, "vkCreateGraphicsPipelines",
1328 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1329 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1330
1331 skip |= validate_bool32(
1332 report_data, "vkCreateGraphicsPipelines",
1333 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1334 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1335
1336 skip |= validate_ranged_enum(
1337 report_data, "vkCreateGraphicsPipelines",
1338 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1339 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1340 VALIDATION_ERROR_13a08601);
1341
1342 skip |= validate_ranged_enum(
1343 report_data, "vkCreateGraphicsPipelines",
1344 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1345 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1346 VALIDATION_ERROR_13a27801);
1347
1348 skip |= validate_ranged_enum(
1349 report_data, "vkCreateGraphicsPipelines",
1350 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1351 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1352 VALIDATION_ERROR_13a04201);
1353
1354 skip |= validate_ranged_enum(
1355 report_data, "vkCreateGraphicsPipelines",
1356 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1357 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1358 VALIDATION_ERROR_0f604001);
1359
1360 skip |= validate_ranged_enum(
1361 report_data, "vkCreateGraphicsPipelines",
1362 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1363 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1364 VALIDATION_ERROR_13a08601);
1365
1366 skip |= validate_ranged_enum(
1367 report_data, "vkCreateGraphicsPipelines",
1368 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1369 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1370 VALIDATION_ERROR_13a27801);
1371
1372 skip |= validate_ranged_enum(
1373 report_data, "vkCreateGraphicsPipelines",
1374 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1375 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1376 VALIDATION_ERROR_13a04201);
1377
1378 skip |= validate_ranged_enum(
1379 report_data, "vkCreateGraphicsPipelines",
1380 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1381 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1382 VALIDATION_ERROR_0f604001);
1383
1384 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1385 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1386 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1387 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1388 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1389 i);
1390 }
1391 }
1392
Petr Kraus595468a2017-09-10 02:26:33 +02001393 if (pCreateInfos[i].pColorBlendState != nullptr && uses_color_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001394 skip |= validate_struct_pnext(
1395 report_data, "vkCreateGraphicsPipelines",
1396 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1397 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1398
1399 skip |= validate_reserved_flags(
1400 report_data, "vkCreateGraphicsPipelines",
1401 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1402 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1403
1404 skip |= validate_bool32(
1405 report_data, "vkCreateGraphicsPipelines",
1406 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1407 pCreateInfos[i].pColorBlendState->logicOpEnable);
1408
1409 skip |= validate_array(
1410 report_data, "vkCreateGraphicsPipelines",
1411 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1412 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1413 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1414 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1415
1416 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1417 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1418 ++attachmentIndex) {
1419 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1420 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1421 ParameterName::IndexVector{i, attachmentIndex}),
1422 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1423
1424 skip |= validate_ranged_enum(
1425 report_data, "vkCreateGraphicsPipelines",
1426 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1427 ParameterName::IndexVector{i, attachmentIndex}),
1428 "VkBlendFactor", AllVkBlendFactorEnums,
1429 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1430 VALIDATION_ERROR_0f22cc01);
1431
1432 skip |= validate_ranged_enum(
1433 report_data, "vkCreateGraphicsPipelines",
1434 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1435 ParameterName::IndexVector{i, attachmentIndex}),
1436 "VkBlendFactor", AllVkBlendFactorEnums,
1437 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1438 VALIDATION_ERROR_0f207001);
1439
1440 skip |= validate_ranged_enum(
1441 report_data, "vkCreateGraphicsPipelines",
1442 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1443 ParameterName::IndexVector{i, attachmentIndex}),
1444 "VkBlendOp", AllVkBlendOpEnums,
1445 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1446 VALIDATION_ERROR_0f202001);
1447
1448 skip |= validate_ranged_enum(
1449 report_data, "vkCreateGraphicsPipelines",
1450 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1451 ParameterName::IndexVector{i, attachmentIndex}),
1452 "VkBlendFactor", AllVkBlendFactorEnums,
1453 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1454 VALIDATION_ERROR_0f22c601);
1455
1456 skip |= validate_ranged_enum(
1457 report_data, "vkCreateGraphicsPipelines",
1458 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1459 ParameterName::IndexVector{i, attachmentIndex}),
1460 "VkBlendFactor", AllVkBlendFactorEnums,
1461 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1462 VALIDATION_ERROR_0f206a01);
1463
1464 skip |= validate_ranged_enum(
1465 report_data, "vkCreateGraphicsPipelines",
1466 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1467 ParameterName::IndexVector{i, attachmentIndex}),
1468 "VkBlendOp", AllVkBlendOpEnums,
1469 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1470 VALIDATION_ERROR_0f200801);
1471
1472 skip |=
1473 validate_flags(report_data, "vkCreateGraphicsPipelines",
1474 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1475 ParameterName::IndexVector{i, attachmentIndex}),
1476 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1477 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1478 false, false, VALIDATION_ERROR_0f202201);
1479 }
1480 }
1481
1482 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1483 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1484 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1485 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1486 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1487 i);
1488 }
1489
1490 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1491 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1492 skip |= validate_ranged_enum(
1493 report_data, "vkCreateGraphicsPipelines",
1494 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1495 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1496 }
1497 }
1498 }
1499 }
1500
1501 if (pCreateInfos != nullptr) {
1502 if (pCreateInfos->flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1503 if (pCreateInfos->basePipelineIndex != -1) {
1504 if (pCreateInfos->basePipelineHandle != VK_NULL_HANDLE) {
1505 skip |= log_msg(
1506 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1507 VALIDATION_ERROR_096005a8, LayerName,
1508 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be VK_NULL_HANDLE if "
1509 "pCreateInfos->flags "
1510 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineIndex is not -1. %s",
1511 validation_error_map[VALIDATION_ERROR_096005a8]);
1512 }
1513 }
1514
1515 if (pCreateInfos->basePipelineHandle != VK_NULL_HANDLE) {
1516 if (pCreateInfos->basePipelineIndex != -1) {
1517 skip |= log_msg(
1518 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1519 VALIDATION_ERROR_096005aa, LayerName,
1520 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1521 "pCreateInfos->flags "
1522 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineHandle is not "
1523 "VK_NULL_HANDLE. %s",
1524 validation_error_map[VALIDATION_ERROR_096005aa]);
1525 }
1526 }
1527 }
1528
1529 if (pCreateInfos->pRasterizationState != nullptr) {
1530 if (pCreateInfos->pRasterizationState->cullMode & ~VK_CULL_MODE_FRONT_AND_BACK) {
1531 skip |= log_msg(
1532 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1533 UNRECOGNIZED_VALUE, LayerName,
1534 "vkCreateGraphicsPipelines parameter, VkCullMode pCreateInfos->pRasterizationState->cullMode, is an "
1535 "unrecognized enumerator");
1536 }
1537
1538 if ((pCreateInfos->pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
1539 (device_data->physical_device_features.fillModeNonSolid == false)) {
1540 skip |= log_msg(
1541 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1542 DEVICE_FEATURE, LayerName,
1543 "vkCreateGraphicsPipelines parameter, VkPolygonMode pCreateInfos->pRasterizationState->polygonMode cannot "
1544 "be "
1545 "VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
1546 }
1547 }
1548
1549 size_t i = 0;
1550 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1551 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1552 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1553 pCreateInfos[i].pStages[j].pName);
1554 }
1555 }
1556 }
1557
1558 return skip;
1559}
1560
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001561bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1562 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1563 VkPipeline *pPipelines) {
1564 bool skip = false;
1565 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1566
1567 for (uint32_t i = 0; i < createInfoCount; i++) {
1568 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1569 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1570 pCreateInfos[i].stage.pName);
1571 }
1572
1573 return skip;
1574}
1575
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001576bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1577 VkSampler *pSampler) {
1578 bool skip = false;
1579 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1580 debug_report_data *report_data = device_data->report_data;
1581
1582 if (pCreateInfo != nullptr) {
1583 if ((device_data->physical_device_features.samplerAnisotropy == false) && (pCreateInfo->maxAnisotropy != 1.0)) {
1584 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1585 DEVICE_FEATURE, LayerName,
1586 "vkCreateSampler(): The samplerAnisotropy feature was not enabled at device-creation time, so the "
1587 "maxAnisotropy member of the VkSamplerCreateInfo structure must be 1.0 but is %f.",
1588 pCreateInfo->maxAnisotropy);
1589 }
1590
1591 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1592 if (pCreateInfo->compareEnable == VK_TRUE) {
1593 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1594 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
1595 }
1596
1597 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
1598 // valid VkBorderColor value
1599 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1600 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1601 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
1602 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
1603 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
1604 }
1605
1606 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
1607 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
1608 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
1609 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1610 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1611 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
1612 skip |=
1613 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1614 VALIDATION_ERROR_1260086e, LayerName,
1615 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
1616 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
1617 validation_error_map[VALIDATION_ERROR_1260086e]);
1618 }
1619 }
1620
1621 return skip;
1622}
1623
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001624bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1625 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
1626 bool skip = false;
1627 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1628 debug_report_data *report_data = device_data->report_data;
1629
1630 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1631 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
1632 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
1633 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
1634 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
1635 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
1636 // valid VkSampler handles
1637 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1638 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
1639 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
1640 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
1641 ++descriptor_index) {
1642 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
1643 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1644 __LINE__, REQUIRED_PARAMETER, LayerName,
1645 "vkCreateDescriptorSetLayout: required parameter "
1646 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d]"
1647 " specified as VK_NULL_HANDLE",
1648 i, descriptor_index);
1649 }
1650 }
1651 }
1652
1653 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
1654 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
1655 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
1656 skip |= log_msg(
1657 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1658 VALIDATION_ERROR_04e00236, LayerName,
1659 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
1660 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits values. %s",
1661 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
1662 }
1663 }
1664 }
1665 }
1666
1667 return skip;
1668}
1669
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001670bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
1671 const VkDescriptorSet *pDescriptorSets) {
1672 bool skip = false;
1673 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1674 debug_report_data *report_data = device_data->report_data;
1675
1676 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1677 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1678 // validate_array()
1679 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
1680 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1681 return skip;
1682}
1683
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001684bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
1685 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
1686 bool skip = false;
1687 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1688 debug_report_data *report_data = device_data->report_data;
1689
1690 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1691 if (pDescriptorWrites != NULL) {
1692 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
1693 // descriptorCount must be greater than 0
1694 if (pDescriptorWrites[i].descriptorCount == 0) {
1695 skip |=
1696 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1697 VALIDATION_ERROR_15c0441b, LayerName,
1698 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
1699 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
1700 }
1701
1702 // dstSet must be a valid VkDescriptorSet handle
1703 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1704 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
1705 pDescriptorWrites[i].dstSet);
1706
1707 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1708 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
1709 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
1710 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
1711 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
1712 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
1713 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
1714 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
1715 if (pDescriptorWrites[i].pImageInfo == nullptr) {
1716 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1717 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
1718 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1719 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
1720 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
1721 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
1722 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
1723 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
1724 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
1725 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
1726 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
1727 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1728 ++descriptor_index) {
1729 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1730 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
1731 ParameterName::IndexVector{i, descriptor_index}),
1732 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
1733 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
1734 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
1735 ParameterName::IndexVector{i, descriptor_index}),
1736 "VkImageLayout", AllVkImageLayoutEnums,
1737 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
1738 VALIDATION_ERROR_UNDEFINED);
1739 }
1740 }
1741 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1742 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1743 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1744 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1745 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1746 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
1747 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
1748 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
1749 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1750 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
1751 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1752 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
1753 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
1754 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
1755 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
1756 } else {
1757 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
1758 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1759 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
1760 ParameterName::IndexVector{i, descriptorIndex}),
1761 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
1762 }
1763 }
1764 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
1765 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
1766 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
1767 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
1768 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
1769 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1770 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
1771 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1772 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
1773 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
1774 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
1775 } else {
1776 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1777 ++descriptor_index) {
1778 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1779 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
1780 ParameterName::IndexVector{i, descriptor_index}),
1781 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
1782 }
1783 }
1784 }
1785
1786 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1787 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
1788 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
1789 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1790 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1791 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
1792 skip |= log_msg(
1793 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1794 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
1795 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1796 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1797 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
1798 validation_error_map[VALIDATION_ERROR_15c0028e]);
1799 }
1800 }
1801 }
1802 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1803 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1804 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
1805 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1806 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1807 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
1808 skip |= log_msg(
1809 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1810 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
1811 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1812 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1813 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
1814 validation_error_map[VALIDATION_ERROR_15c00290]);
1815 }
1816 }
1817 }
1818 }
1819 }
1820 }
1821 return skip;
1822}
1823
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001824bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1825 VkRenderPass *pRenderPass) {
1826 bool skip = false;
1827 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1828 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
1829
1830 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
1831 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
1832 std::stringstream ss;
1833 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
1834 << validation_error_map[VALIDATION_ERROR_00809201];
1835 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1836 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
1837 }
1838 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
1839 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
1840 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1841 __LINE__, VALIDATION_ERROR_00800696, "DL",
1842 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
1843 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
1844 i, validation_error_map[VALIDATION_ERROR_00800696]);
1845 }
1846 }
1847
1848 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
1849 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
1850 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1851 __LINE__, VALIDATION_ERROR_1400069a, "DL",
1852 "Cannot create a render pass with %d color attachments. Max is %d. %s",
1853 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
1854 validation_error_map[VALIDATION_ERROR_1400069a]);
1855 }
1856 }
1857 return skip;
1858}
1859
1860bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
1861 const VkCommandBuffer *pCommandBuffers) {
1862 bool skip = false;
1863 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1864 debug_report_data *report_data = device_data->report_data;
1865
1866 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1867 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1868 // validate_array()
1869 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
1870 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1871 return skip;
1872}
1873
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001874bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
1875 bool skip = false;
1876 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1877 debug_report_data *report_data = device_data->report_data;
1878 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
1879
1880 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1881 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
1882 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
1883 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
1884 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
1885
1886 if (pBeginInfo->pInheritanceInfo != NULL) {
1887 skip |=
1888 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
1889 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
1890
1891 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
1892 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
1893
1894 // TODO: This only needs to be validated when the inherited queries feature is enabled
1895 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
1896 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
1897
1898 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
1899 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
1900 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
1901 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
1902 }
1903
1904 if (pInfo != NULL) {
1905 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
1906 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1907 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
1908 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
1909 "inheritedQueries. %s",
1910 validation_error_map[VALIDATION_ERROR_02a00070]);
1911 }
1912 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
1913 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
1914 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
1915 VALIDATION_ERROR_02a00072);
1916 }
1917 }
1918
1919 return skip;
1920}
1921
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001922bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
1923 const VkViewport *pViewports) {
1924 bool skip = false;
1925 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1926
1927 skip |= validate_array(device_data->report_data, "vkCmdSetViewport", "viewportCount", "pViewports", viewportCount, pViewports,
1928 true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1929
1930 if (viewportCount > 0 && pViewports != nullptr) {
1931 const VkPhysicalDeviceLimits &limits = device_data->device_limits;
1932 for (uint32_t viewportIndex = 0; viewportIndex < viewportCount; ++viewportIndex) {
1933 const VkViewport &viewport = pViewports[viewportIndex];
1934
1935 if (device_data->physical_device_features.multiViewport == false) {
1936 if (viewportCount != 1) {
1937 skip |= log_msg(
1938 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1939 __LINE__, DEVICE_FEATURE, LayerName,
1940 "vkCmdSetViewport(): The multiViewport feature is not enabled, so viewportCount must be 1 but is %d.",
1941 viewportCount);
1942 }
1943 if (firstViewport != 0) {
1944 skip |= log_msg(
1945 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1946 __LINE__, DEVICE_FEATURE, LayerName,
1947 "vkCmdSetViewport(): The multiViewport feature is not enabled, so firstViewport must be 0 but is %d.",
1948 firstViewport);
1949 }
1950 }
1951
1952 if (viewport.width <= 0 || viewport.width > limits.maxViewportDimensions[0]) {
1953 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1954 __LINE__, VALIDATION_ERROR_15000996, LayerName,
1955 "vkCmdSetViewport %d: width (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
1956 viewport.width, limits.maxViewportDimensions[0], validation_error_map[VALIDATION_ERROR_15000996]);
1957 }
1958
1959 if (device_data->extensions.vk_amd_negative_viewport_height || device_data->extensions.vk_khr_maintenance1) {
1960 // Check lower bound against negative viewport height instead of zero
1961 if (viewport.height <= -(static_cast<int32_t>(limits.maxViewportDimensions[1])) ||
1962 (viewport.height > limits.maxViewportDimensions[1])) {
1963 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1964 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, VALIDATION_ERROR_1500099a, LayerName,
1965 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (-%u,%u). %s", viewportIndex,
1966 viewport.height, limits.maxViewportDimensions[1], limits.maxViewportDimensions[1],
1967 validation_error_map[VALIDATION_ERROR_1500099a]);
1968 }
1969 } else {
1970 if ((viewport.height <= 0) || (viewport.height > limits.maxViewportDimensions[1])) {
1971 skip |=
1972 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1973 __LINE__, VALIDATION_ERROR_15000998, LayerName,
1974 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
1975 viewport.height, limits.maxViewportDimensions[1], validation_error_map[VALIDATION_ERROR_15000998]);
1976 }
1977 }
1978
1979 if (viewport.x < limits.viewportBoundsRange[0] || viewport.x > limits.viewportBoundsRange[1]) {
1980 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1981 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
1982 "vkCmdSetViewport %d: x (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.x,
1983 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
1984 validation_error_map[VALIDATION_ERROR_1500099e]);
1985 }
1986
1987 if (viewport.y < limits.viewportBoundsRange[0] || viewport.y > limits.viewportBoundsRange[1]) {
1988 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1989 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
1990 "vkCmdSetViewport %d: y (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.y,
1991 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
1992 validation_error_map[VALIDATION_ERROR_1500099e]);
1993 }
1994
1995 if (viewport.x + viewport.width > limits.viewportBoundsRange[1]) {
1996 skip |=
1997 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1998 __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1999 "vkCmdSetViewport %d: x (%f) + width (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.x,
2000 viewport.width, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
2001 }
2002
2003 if (viewport.y + viewport.height > limits.viewportBoundsRange[1]) {
2004 skip |=
2005 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2006 __LINE__, VALIDATION_ERROR_150009a2, LayerName,
2007 "vkCmdSetViewport %d: y (%f) + height (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.y,
2008 viewport.height, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
2009 }
2010 }
2011 }
2012 return skip;
2013}
2014
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002015bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
2016 bool skip = false;
2017 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2018 debug_report_data *report_data = device_data->report_data;
2019
2020 if (device_data->physical_device_features.multiViewport == false) {
2021 if (scissorCount != 1) {
2022 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2023 DEVICE_FEATURE, LayerName,
2024 "vkCmdSetScissor(): The multiViewport feature is not enabled, so scissorCount must be 1 but is %d.",
2025 scissorCount);
2026 }
2027 if (firstScissor != 0) {
2028 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2029 DEVICE_FEATURE, LayerName,
2030 "vkCmdSetScissor(): The multiViewport feature is not enabled, so firstScissor must be 0 but is %d.",
2031 firstScissor);
2032 }
2033 }
2034
2035 for (uint32_t scissorIndex = 0; scissorIndex < scissorCount; ++scissorIndex) {
2036 const VkRect2D &pScissor = pScissors[scissorIndex];
2037
2038 if (pScissor.offset.x < 0) {
2039 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2040 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.x (%d) must not be negative. %s",
2041 scissorIndex, pScissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2042 } else if (static_cast<int32_t>(pScissor.extent.width) > (INT_MAX - pScissor.offset.x)) {
2043 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2044 VALIDATION_ERROR_1d8004a8, LayerName,
2045 "vkCmdSetScissor %d: adding offset.x (%d) and extent.width (%u) will overflow. %s", scissorIndex,
2046 pScissor.offset.x, pScissor.extent.width, validation_error_map[VALIDATION_ERROR_1d8004a8]);
2047 }
2048
2049 if (pScissor.offset.y < 0) {
2050 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2051 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.y (%d) must not be negative. %s",
2052 scissorIndex, pScissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2053 } else if (static_cast<int32_t>(pScissor.extent.height) > (INT_MAX - pScissor.offset.y)) {
2054 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2055 VALIDATION_ERROR_1d8004aa, LayerName,
2056 "vkCmdSetScissor %d: adding offset.y (%d) and extent.height (%u) will overflow. %s", scissorIndex,
2057 pScissor.offset.y, pScissor.extent.height, validation_error_map[VALIDATION_ERROR_1d8004aa]);
2058 }
2059 }
2060 return skip;
2061}
2062
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002063bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2064 uint32_t firstInstance) {
2065 bool skip = false;
2066 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2067 if (vertexCount == 0) {
2068 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
2069 // this an error or leave as is.
2070 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2071 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
2072 }
2073
2074 if (instanceCount == 0) {
2075 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2076 // this an error or leave as is.
2077 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2078 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2079 }
2080 return skip;
2081}
2082
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002083bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2084 bool skip = false;
2085 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2086
2087 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2088 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2089 __LINE__, DEVICE_FEATURE, LayerName,
2090 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2091 }
2092 return skip;
2093}
2094
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002095bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2096 uint32_t stride) {
2097 bool skip = false;
2098 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2099 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2100 skip |=
2101 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2102 DEVICE_FEATURE, LayerName,
2103 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2104 }
2105 return skip;
2106}
2107
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002108bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2109 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2110 bool skip = false;
2111 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2112
2113 if (pRegions != nullptr) {
2114 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2115 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2116 skip |= log_msg(
2117 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2118 VALIDATION_ERROR_0a600c01, LayerName,
2119 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2120 validation_error_map[VALIDATION_ERROR_0a600c01]);
2121 }
2122 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2123 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2124 skip |= log_msg(
2125 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2126 VALIDATION_ERROR_0a600c01, LayerName,
2127 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2128 validation_error_map[VALIDATION_ERROR_0a600c01]);
2129 }
2130 }
2131 return skip;
2132}
2133
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002134bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2135 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2136 bool skip = false;
2137 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2138
2139 if (pRegions != nullptr) {
2140 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2141 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2142 skip |= log_msg(
2143 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2144 UNRECOGNIZED_VALUE, LayerName,
2145 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2146 }
2147 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2148 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2149 skip |= log_msg(
2150 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2151 UNRECOGNIZED_VALUE, LayerName,
2152 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2153 }
2154 }
2155 return skip;
2156}
2157
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002158bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2159 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2160 bool skip = false;
2161 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2162
2163 if (pRegions != nullptr) {
2164 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2165 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2166 skip |= log_msg(
2167 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2168 UNRECOGNIZED_VALUE, LayerName,
2169 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2170 "enumerator");
2171 }
2172 }
2173 return skip;
2174}
2175
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002176bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2177 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2178 bool skip = false;
2179 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2180
2181 if (pRegions != nullptr) {
2182 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2183 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2184 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2185 UNRECOGNIZED_VALUE, LayerName,
2186 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2187 "enumerator");
2188 }
2189 }
2190 return skip;
2191}
2192
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002193bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2194 const void *pData) {
2195 bool skip = false;
2196 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2197
2198 if (dstOffset & 3) {
2199 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2200 __LINE__, VALIDATION_ERROR_1e400048, LayerName,
2201 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2202 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2203 }
2204
2205 if ((dataSize <= 0) || (dataSize > 65536)) {
2206 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2207 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2208 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2209 "), must be greater than zero and less than or equal to 65536. %s",
2210 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2211 } else if (dataSize & 3) {
2212 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2213 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2214 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2215 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2216 }
2217 return skip;
2218}
2219
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002220bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2221 uint32_t data) {
2222 bool skip = false;
2223 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2224
2225 if (dstOffset & 3) {
2226 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2227 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2228 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2229 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2230 }
2231
2232 if (size != VK_WHOLE_SIZE) {
2233 if (size <= 0) {
2234 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2235 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2236 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2237 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2238 } else if (size & 3) {
2239 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2240 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2241 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2242 validation_error_map[VALIDATION_ERROR_1b400038]);
2243 }
2244 }
2245 return skip;
2246}
2247
2248VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2249 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2250}
2251
2252VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2253 VkLayerProperties *pProperties) {
2254 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2255}
2256
2257VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2258 VkExtensionProperties *pProperties) {
2259 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2260 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2261
2262 return VK_ERROR_LAYER_NOT_PRESENT;
2263}
2264
2265VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2266 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2267 // Parameter_validation does not have any physical device extensions
2268 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2269 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2270
2271 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2272 bool skip =
2273 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2274 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2275 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2276
2277 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2278}
2279
2280static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2281 if (!flag) {
2282 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2283 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2284 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2285 extension_name);
2286 }
2287
2288 return false;
2289}
2290
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002291bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2292 VkSwapchainKHR *pSwapchain) {
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 if (pCreateInfo != nullptr) {
2298 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2299 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
2300 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2301 DEVICE_FEATURE, LayerName,
2302 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2303 "textureCompressionETC2 feature is not enabled: neither ETC2 nor EAC formats can be used to create "
2304 "images.",
2305 string_VkFormat(pCreateInfo->imageFormat));
2306 }
2307
2308 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2309 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2310 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2311 DEVICE_FEATURE, LayerName,
2312 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2313 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2314 string_VkFormat(pCreateInfo->imageFormat));
2315 }
2316
2317 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2318 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2319 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2320 DEVICE_FEATURE, LayerName,
2321 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2322 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2323 string_VkFormat(pCreateInfo->imageFormat));
2324 }
2325
2326 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2327 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2328 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2329 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2330 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2331 VALIDATION_ERROR_146009fc, LayerName,
2332 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2333 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2334 validation_error_map[VALIDATION_ERROR_146009fc]);
2335 }
2336
2337 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2338 // queueFamilyIndexCount uint32_t values
2339 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2340 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2341 VALIDATION_ERROR_146009fa, LayerName,
2342 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2343 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2344 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2345 validation_error_map[VALIDATION_ERROR_146009fa]);
2346 } else {
2347 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2348 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2349 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2350 INVALID_USAGE, false, "", "");
2351 }
2352 }
2353
2354 // imageArrayLayers must be greater than 0
2355 skip |= ValidateGreaterThan(report_data, "vkCreateSwapchainKHR", "pCreateInfo->imageArrayLayers",
2356 pCreateInfo->imageArrayLayers, 0u);
2357 }
2358
2359 return skip;
2360}
2361
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002362bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2363 bool skip = false;
2364 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2365
2366 if (pPresentInfo && pPresentInfo->pNext) {
2367 // Verify ext struct
2368 struct std_header {
2369 VkStructureType sType;
2370 const void *pNext;
2371 };
2372 std_header *pnext = (std_header *)pPresentInfo->pNext;
2373 while (pnext) {
2374 if (VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR == pnext->sType) {
2375 // TODO: This and all other pNext extension dependencies should be added to code-generation
2376 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present,
2377 "vkQueuePresentKHR", VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2378 VkPresentRegionsKHR *present_regions = (VkPresentRegionsKHR *)pnext;
2379 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2380 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2381 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, INVALID_USAGE, LayerName,
2382 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i"
2383 " but VkPresentRegionsKHR extension swapchainCount is %i. These values must be equal.",
2384 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2385 }
2386 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2387 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2388 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2389 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions,
2390 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2391 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2392 skip |=
2393 validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
2394 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2395 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2396 VALIDATION_ERROR_UNDEFINED);
2397 }
2398 }
2399 pnext = (std_header *)pnext->pNext;
2400 }
2401 }
2402
2403 return skip;
2404}
2405
2406#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002407bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2408 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2409 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2410 bool skip = false;
2411
2412 if (pCreateInfo->hwnd == nullptr) {
2413 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2414 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2415 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2416 validation_error_map[VALIDATION_ERROR_15a00a38]);
2417 }
2418
2419 return skip;
2420}
2421#endif // VK_USE_PLATFORM_WIN32_KHR
2422
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002423bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2424 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2425 if (pNameInfo->pObjectName) {
2426 device_data->report_data->debugObjectNameMap->insert(
2427 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2428 } else {
2429 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2430 }
2431 return false;
2432}
2433
2434VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2435 const auto item = name_to_funcptr_map.find(funcName);
2436 if (item != name_to_funcptr_map.end()) {
2437 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2438 }
2439
2440 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2441 const auto &table = device_data->dispatch_table;
2442 if (!table.GetDeviceProcAddr) return nullptr;
2443 return table.GetDeviceProcAddr(device, funcName);
2444}
2445
2446VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2447 const auto item = name_to_funcptr_map.find(funcName);
2448 if (item != name_to_funcptr_map.end()) {
2449 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2450 }
2451
2452 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2453 auto &table = instance_data->dispatch_table;
2454 if (!table.GetInstanceProcAddr) return nullptr;
2455 return table.GetInstanceProcAddr(instance, funcName);
2456}
2457
2458VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2459 assert(instance);
2460 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2461
2462 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2463 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2464}
2465
2466// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2467// and the address filled in here. The autogenerated source will call these routines if the pointers are not NULL.
2468void InitializeManualParameterValidationFunctionPointers(void) {
Mark Lobodzinski78a12a92017-08-08 14:16:51 -06002469 custom_functions["vkGetDeviceQueue"] = (void*)pv_vkGetDeviceQueue;
2470 custom_functions["vkCreateBuffer"] = (void*)pv_vkCreateBuffer;
2471 custom_functions["vkCreateImage"] = (void*)pv_vkCreateImage;
2472 custom_functions["vkCreateImageView"] = (void*)pv_vkCreateImageView;
2473 custom_functions["vkCreateGraphicsPipelines"] = (void*)pv_vkCreateGraphicsPipelines;
2474 custom_functions["vkCreateComputePipelines"] = (void*)pv_vkCreateComputePipelines;
2475 custom_functions["vkCreateSampler"] = (void*)pv_vkCreateSampler;
2476 custom_functions["vkCreateDescriptorSetLayout"] = (void*)pv_vkCreateDescriptorSetLayout;
2477 custom_functions["vkFreeDescriptorSets"] = (void*)pv_vkFreeDescriptorSets;
2478 custom_functions["vkUpdateDescriptorSets"] = (void*)pv_vkUpdateDescriptorSets;
2479 custom_functions["vkCreateRenderPass"] = (void*)pv_vkCreateRenderPass;
2480 custom_functions["vkBeginCommandBuffer"] = (void*)pv_vkBeginCommandBuffer;
2481 custom_functions["vkCmdSetViewport"] = (void*)pv_vkCmdSetViewport;
2482 custom_functions["vkCmdSetScissor"] = (void*)pv_vkCmdSetScissor;
2483 custom_functions["vkCmdDraw"] = (void*)pv_vkCmdDraw;
2484 custom_functions["vkCmdDrawIndirect"] = (void*)pv_vkCmdDrawIndirect;
2485 custom_functions["vkCmdDrawIndexedIndirect"] = (void*)pv_vkCmdDrawIndexedIndirect;
2486 custom_functions["vkCmdCopyImage"] = (void*)pv_vkCmdCopyImage;
2487 custom_functions["vkCmdBlitImage"] = (void*)pv_vkCmdBlitImage;
2488 custom_functions["vkCmdCopyBufferToImage"] = (void*)pv_vkCmdCopyBufferToImage;
2489 custom_functions["vkCmdCopyImageToBuffer"] = (void*)pv_vkCmdCopyImageToBuffer;
2490 custom_functions["vkCmdUpdateBuffer"] = (void*)pv_vkCmdUpdateBuffer;
2491 custom_functions["vkCmdFillBuffer"] = (void*)pv_vkCmdFillBuffer;
2492 custom_functions["vkCreateSwapchainKHR"] = (void*)pv_vkCreateSwapchainKHR;
2493 custom_functions["vkQueuePresentKHR"] = (void*)pv_vkQueuePresentKHR;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002494}
2495
2496} // namespace parameter_validation
2497
2498VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2499 VkExtensionProperties *pProperties) {
2500 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
2501}
2502
2503VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
2504 VkLayerProperties *pProperties) {
2505 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
2506}
2507
2508VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2509 VkLayerProperties *pProperties) {
2510 // the layer command handles VK_NULL_HANDLE just fine internally
2511 assert(physicalDevice == VK_NULL_HANDLE);
2512 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
2513}
2514
2515VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
2516 const char *pLayerName, uint32_t *pCount,
2517 VkExtensionProperties *pProperties) {
2518 // the layer command handles VK_NULL_HANDLE just fine internally
2519 assert(physicalDevice == VK_NULL_HANDLE);
2520 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
2521}
2522
2523VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
2524 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
2525}
2526
2527VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2528 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
2529}
2530
2531VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
2532 const char *funcName) {
2533 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
2534}
2535
2536VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
2537 assert(pVersionStruct != NULL);
2538 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
2539
2540 // Fill in the function pointers if our version is at least capable of having the structure contain them.
2541 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
2542 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
2543 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
2544 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
2545 }
2546
2547 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2548 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
2549 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2550 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
2551 }
2552
2553 return VK_SUCCESS;
2554}