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