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