blob: 7b0cd78b199ebe65a7d65cb1fae11aaf18d06c68 [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()) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700143 skip |= log_msg(
144 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
145 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
146 "%s: %s (= %" PRIu32
147 ") is not one of the queue families given via VkDeviceQueueCreateInfo structures when the device was created. %s",
148 cmd_name, parameter_name, queue_family, vu_note);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600149 }
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
Dave Houltona9df0ce2018-02-07 10:51:23 -0700379 "].queueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family "
380 "index value. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600381 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
Dave Houltona9df0ce2018-02-07 10:51:23 -0700387 ") is not unique within pCreateInfo->pQueueCreateInfos array. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600388 i, requested_queue_family, validation_error_map[VALIDATION_ERROR_056002e8]);
389 } else {
390 set.insert(requested_queue_family);
391 }
392
393 if (pCreateInfo->pQueueCreateInfos[i].pQueuePriorities != nullptr) {
394 for (uint32_t j = 0; j < pCreateInfo->pQueueCreateInfos[i].queueCount; ++j) {
395 const float queue_priority = pCreateInfo->pQueueCreateInfos[i].pQueuePriorities[j];
396 if (!(queue_priority >= 0.f) || !(queue_priority <= 1.f)) {
397 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
398 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
399 VALIDATION_ERROR_06c002fe, LayerName,
400 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].pQueuePriorities[%" PRIu32
401 "] (=%f) is not between 0 and 1 (inclusive). %s",
402 i, j, queue_priority, validation_error_map[VALIDATION_ERROR_06c002fe]);
403 }
404 }
405 }
406 }
407 }
408
409 return skip;
410}
411
412VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
413 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
414 // NOTE: Don't validate physicalDevice or any dispatchable object as the first parameter. We couldn't get here if it was wrong!
415
416 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
417 bool skip = false;
418 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
419 assert(my_instance_data != nullptr);
420 std::unique_lock<std::mutex> lock(global_lock);
421
422 skip |= parameter_validation_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
423
424 if (pCreateInfo != NULL) skip |= ValidateDeviceCreateInfo(my_instance_data, physicalDevice, pCreateInfo);
425
426 if (!skip) {
427 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
428 assert(chain_info != nullptr);
429 assert(chain_info->u.pLayerInfo != nullptr);
430
431 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
432 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
433 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice");
434 if (fpCreateDevice == NULL) {
435 return VK_ERROR_INITIALIZATION_FAILED;
436 }
437
438 // Advance the link info for the next element on the chain
439 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
440
441 lock.unlock();
442
443 result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
444
445 lock.lock();
446
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600447 if (result == VK_SUCCESS) {
448 layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
449 assert(my_device_data != nullptr);
450
451 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
452 layer_init_device_dispatch_table(*pDevice, &my_device_data->dispatch_table, fpGetDeviceProcAddr);
453
454 my_device_data->extensions.InitFromDeviceCreateInfo(&my_instance_data->extensions, pCreateInfo);
455
456 // Store createdevice data
457 if ((pCreateInfo != nullptr) && (pCreateInfo->pQueueCreateInfos != nullptr)) {
458 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
459 my_device_data->queueFamilyIndexMap.insert(std::make_pair(pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex,
460 pCreateInfo->pQueueCreateInfos[i].queueCount));
461 }
462 }
463
464 // Query and save physical device limits for this device
465 VkPhysicalDeviceProperties device_properties = {};
466 my_instance_data->dispatch_table.GetPhysicalDeviceProperties(physicalDevice, &device_properties);
467 memcpy(&my_device_data->device_limits, &device_properties.limits, sizeof(VkPhysicalDeviceLimits));
468 my_device_data->physical_device = physicalDevice;
469 my_device_data->device = *pDevice;
470
471 // Save app-enabled features in this device's layer_data structure
John Zulauf1bde5bb2017-10-18 18:21:23 -0600472 // The enabled features can come from either pEnabledFeatures, or from the pNext chain
473 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
474 if ((nullptr == enabled_features_found) && my_device_data->extensions.vk_khr_get_physical_device_properties_2) {
John Zulaufde972ac2017-10-26 12:07:05 -0600475 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
476 if (features2) {
477 enabled_features_found = &(features2->features);
John Zulauf1bde5bb2017-10-18 18:21:23 -0600478 }
479 }
480 if (enabled_features_found) {
Dave Houltonb3bbec72018-01-17 10:13:33 -0700481 my_device_data->physical_device_features = *enabled_features_found;
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600482 } else {
483 memset(&my_device_data->physical_device_features, 0, sizeof(VkPhysicalDeviceFeatures));
484 }
485 }
486 }
487
488 return result;
489}
490
491VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
492 dispatch_key key = get_dispatch_key(device);
493 bool skip = false;
494 layer_data *device_data = GetLayerDataPtr(key, layer_data_map);
495 {
496 std::unique_lock<std::mutex> lock(global_lock);
497 skip |= parameter_validation_vkDestroyDevice(device, pAllocator);
498 }
499
500 if (!skip) {
501 layer_debug_report_destroy_device(device);
502 device_data->dispatch_table.DestroyDevice(device, pAllocator);
503 }
504 FreeLayerDataPtr(key, layer_data_map);
505}
506
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600507bool pv_vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
508 bool skip = false;
509 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
510
511 skip |=
512 ValidateDeviceQueueFamily(device_data, queueFamilyIndex, "vkGetDeviceQueue", "queueFamilyIndex", VALIDATION_ERROR_29600300);
513 const auto &queue_data = device_data->queueFamilyIndexMap.find(queueFamilyIndex);
514 if (queue_data != device_data->queueFamilyIndexMap.end() && queue_data->second <= queueIndex) {
515 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
516 HandleToUint64(device), __LINE__, VALIDATION_ERROR_29600302, LayerName,
517 "vkGetDeviceQueue: queueIndex (=%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -0700518 ") is not less than the number of queues requested from queueFamilyIndex (=%" PRIu32
519 ") when the device was created (i.e. is not less than %" PRIu32 "). %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600520 queueIndex, queueFamilyIndex, queue_data->second, validation_error_map[VALIDATION_ERROR_29600302]);
521 }
522 return skip;
523}
524
525VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
526 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool) {
527 layer_data *local_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
528 bool skip = false;
529 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
530 std::unique_lock<std::mutex> lock(global_lock);
531
532 skip |= ValidateDeviceQueueFamily(local_data, pCreateInfo->queueFamilyIndex, "vkCreateCommandPool",
533 "pCreateInfo->queueFamilyIndex", VALIDATION_ERROR_02c0004e);
534
535 skip |= parameter_validation_vkCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
536
537 lock.unlock();
538 if (!skip) {
539 result = local_data->dispatch_table.CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
540 }
541 return result;
542}
543
544VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
545 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool) {
546 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
547 bool skip = false;
548 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
549
550 skip |= parameter_validation_vkCreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
551
552 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
553 if (pCreateInfo != nullptr) {
554 // If queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, pipelineStatistics must be a valid combination of
555 // VkQueryPipelineStatisticFlagBits values
556 if ((pCreateInfo->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS) && (pCreateInfo->pipelineStatistics != 0) &&
557 ((pCreateInfo->pipelineStatistics & (~AllVkQueryPipelineStatisticFlagBits)) != 0)) {
558 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
559 __LINE__, VALIDATION_ERROR_11c00630, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700560 "vkCreateQueryPool(): if pCreateInfo->queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, "
561 "pCreateInfo->pipelineStatistics must be a valid combination of VkQueryPipelineStatisticFlagBits "
562 "values. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600563 validation_error_map[VALIDATION_ERROR_11c00630]);
564 }
565 }
566 if (!skip) {
567 result = device_data->dispatch_table.CreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
568 }
569 return result;
570}
571
Petr Krause91f7a12017-12-14 20:57:36 +0100572VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
573 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass) {
574 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
575 bool skip = false;
576 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
577
578 {
579 std::unique_lock<std::mutex> lock(global_lock);
580 skip |= parameter_validation_vkCreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
581
Dave Houltonb3bbec72018-01-17 10:13:33 -0700582 typedef bool (*PFN_manual_vkCreateRenderPass)(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
583 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
Petr Krause91f7a12017-12-14 20:57:36 +0100584 PFN_manual_vkCreateRenderPass custom_func = (PFN_manual_vkCreateRenderPass)custom_functions["vkCreateRenderPass"];
585 if (custom_func != nullptr) {
586 skip |= custom_func(device, pCreateInfo, pAllocator, pRenderPass);
587 }
588 }
589
590 if (!skip) {
591 result = device_data->dispatch_table.CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
592
593 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
594 if (result == VK_SUCCESS) {
595 std::unique_lock<std::mutex> lock(global_lock);
596 const auto renderPass = *pRenderPass;
597 auto &renderpass_state = device_data->renderpasses_states[renderPass];
598
599 for (uint32_t subpass = 0; subpass < pCreateInfo->subpassCount; ++subpass) {
600 bool uses_color = false;
601 for (uint32_t i = 0; i < pCreateInfo->pSubpasses[subpass].colorAttachmentCount && !uses_color; ++i)
602 if (pCreateInfo->pSubpasses[subpass].pColorAttachments[i].attachment != VK_ATTACHMENT_UNUSED) uses_color = true;
603
604 bool uses_depthstencil = false;
605 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment)
606 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)
607 uses_depthstencil = true;
608
609 if (uses_color) renderpass_state.subpasses_using_color_attachment.insert(subpass);
610 if (uses_depthstencil) renderpass_state.subpasses_using_depthstencil_attachment.insert(subpass);
611 }
612 }
613 }
614 return result;
615}
616
617VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator) {
618 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
619 bool skip = false;
620
621 {
622 std::unique_lock<std::mutex> lock(global_lock);
623 skip |= parameter_validation_vkDestroyRenderPass(device, renderPass, pAllocator);
624
Dave Houltonb3bbec72018-01-17 10:13:33 -0700625 typedef bool (*PFN_manual_vkDestroyRenderPass)(VkDevice device, VkRenderPass renderPass,
626 const VkAllocationCallbacks *pAllocator);
Petr Krause91f7a12017-12-14 20:57:36 +0100627 PFN_manual_vkDestroyRenderPass custom_func = (PFN_manual_vkDestroyRenderPass)custom_functions["vkDestroyRenderPass"];
628 if (custom_func != nullptr) {
629 skip |= custom_func(device, renderPass, pAllocator);
630 }
631 }
632
633 if (!skip) {
634 device_data->dispatch_table.DestroyRenderPass(device, renderPass, pAllocator);
635
636 // track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
637 {
638 std::unique_lock<std::mutex> lock(global_lock);
639 device_data->renderpasses_states.erase(renderPass);
640 }
641 }
642}
643
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600644bool pv_vkCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
645 VkBuffer *pBuffer) {
646 bool skip = false;
647 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
648 debug_report_data *report_data = device_data->report_data;
649
Petr Krause5c37652018-01-05 04:05:12 +0100650 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, VK_NULL_HANDLE, LayerName, "vkCreateBuffer"};
651
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600652 if (pCreateInfo != nullptr) {
Petr Krause5c37652018-01-05 04:05:12 +0100653 skip |= ValidateGreaterThanZero(pCreateInfo->size, "pCreateInfo->size", VALIDATION_ERROR_01400720, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600654
655 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
656 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
657 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
658 if (pCreateInfo->queueFamilyIndexCount <= 1) {
659 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
660 VALIDATION_ERROR_01400724, LayerName,
661 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
662 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
663 validation_error_map[VALIDATION_ERROR_01400724]);
664 }
665
666 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
667 // queueFamilyIndexCount uint32_t values
668 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
669 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
670 VALIDATION_ERROR_01400722, LayerName,
671 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
672 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
673 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
674 validation_error_map[VALIDATION_ERROR_01400722]);
675 } else {
676 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
677 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
678 "vkCreateBuffer", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
679 false, "", "");
680 }
681 }
682
683 // If flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain
684 // VK_BUFFER_CREATE_SPARSE_BINDING_BIT
685 if (((pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
686 ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) != VK_BUFFER_CREATE_SPARSE_BINDING_BIT)) {
687 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
688 VALIDATION_ERROR_0140072c, LayerName,
689 "vkCreateBuffer: if pCreateInfo->flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or "
690 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_BUFFER_CREATE_SPARSE_BINDING_BIT. %s",
691 validation_error_map[VALIDATION_ERROR_0140072c]);
692 }
693 }
694
695 return skip;
696}
697
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600698bool pv_vkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
699 VkImage *pImage) {
700 bool skip = false;
701 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
702 debug_report_data *report_data = device_data->report_data;
703
Petr Krause5c37652018-01-05 04:05:12 +0100704 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, VK_NULL_HANDLE, LayerName, "vkCreateImage"};
705
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600706 if (pCreateInfo != nullptr) {
707 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
708 FormatIsCompressed_ETC2_EAC(pCreateInfo->format)) {
709 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
710 DEVICE_FEATURE, LayerName,
711 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionETC2 feature is "
712 "not enabled: neither ETC2 nor EAC formats can be used to create images.",
713 string_VkFormat(pCreateInfo->format));
714 }
715
716 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
717 FormatIsCompressed_ASTC_LDR(pCreateInfo->format)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700718 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
719 DEVICE_FEATURE, LayerName,
720 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionASTC_LDR feature "
721 "is not enabled: ASTC formats cannot be used to create images.",
722 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600723 }
724
725 if ((device_data->physical_device_features.textureCompressionBC == false) && FormatIsCompressed_BC(pCreateInfo->format)) {
726 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
727 DEVICE_FEATURE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700728 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionBC feature is not "
729 "enabled: BC compressed formats cannot be used to create images.",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600730 string_VkFormat(pCreateInfo->format));
731 }
732
733 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
734 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
735 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
736 if (pCreateInfo->queueFamilyIndexCount <= 1) {
737 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
738 VALIDATION_ERROR_09e0075c, LayerName,
739 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
740 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
741 validation_error_map[VALIDATION_ERROR_09e0075c]);
742 }
743
744 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
745 // queueFamilyIndexCount uint32_t values
746 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
747 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
748 VALIDATION_ERROR_09e0075a, LayerName,
749 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
750 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
751 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
752 validation_error_map[VALIDATION_ERROR_09e0075a]);
753 } else {
754 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
755 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
756 "vkCreateImage", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
757 false, "", "");
758 }
759 }
760
Petr Krause5c37652018-01-05 04:05:12 +0100761 skip |=
762 ValidateGreaterThanZero(pCreateInfo->extent.width, "pCreateInfo->extent.width", VALIDATION_ERROR_09e00760, log_misc);
763 skip |=
764 ValidateGreaterThanZero(pCreateInfo->extent.height, "pCreateInfo->extent.height", VALIDATION_ERROR_09e00762, log_misc);
765 skip |=
766 ValidateGreaterThanZero(pCreateInfo->extent.depth, "pCreateInfo->extent.depth", VALIDATION_ERROR_09e00764, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600767
Petr Krause5c37652018-01-05 04:05:12 +0100768 skip |= ValidateGreaterThanZero(pCreateInfo->mipLevels, "pCreateInfo->mipLevels", VALIDATION_ERROR_09e00766, log_misc);
769 skip |= ValidateGreaterThanZero(pCreateInfo->arrayLayers, "pCreateInfo->arrayLayers", VALIDATION_ERROR_09e00768, log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600770
Dave Houlton130c0212018-01-29 13:39:56 -0700771 // InitialLayout must be PREINITIALIZED or UNDEFINED
Dave Houltone19e20d2018-02-02 16:32:41 -0700772 if ((pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED) &&
773 (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED)) {
774 skip |= log_msg(
775 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dave Houlton130c0212018-01-29 13:39:56 -0700776 VALIDATION_ERROR_09e007c2, LayerName,
777 "vkCreateImage(): initialLayout is %s, must be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
778 string_VkImageLayout(pCreateInfo->initialLayout), validation_error_map[VALIDATION_ERROR_09e007c2]);
779 }
780
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600781 // If imageType is VK_IMAGE_TYPE_1D, both extent.height and extent.depth must be 1
782 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) && (pCreateInfo->extent.height != 1) && (pCreateInfo->extent.depth != 1)) {
783 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dave Houltone19e20d2018-02-02 16:32:41 -0700784 VALIDATION_ERROR_09e00778, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700785 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_1D, both pCreateInfo->extent.height and "
786 "pCreateInfo->extent.depth must be 1. %s",
Dave Houltone19e20d2018-02-02 16:32:41 -0700787 validation_error_map[VALIDATION_ERROR_09e00778]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600788 }
789
790 if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D) {
791 // If imageType is VK_IMAGE_TYPE_2D and flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, extent.width and
792 // extent.height must be equal
793 if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
794 (pCreateInfo->extent.width != pCreateInfo->extent.height)) {
795 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
796 VALIDATION_ERROR_09e00774, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700797 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D and pCreateInfo->flags contains "
798 "VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, pCreateInfo->extent.width and pCreateInfo->extent.height "
799 "must be equal. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600800 validation_error_map[VALIDATION_ERROR_09e00774]);
801 }
802
803 if (pCreateInfo->extent.depth != 1) {
804 skip |= log_msg(
805 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
806 VALIDATION_ERROR_09e0077a, LayerName,
807 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1. %s",
808 validation_error_map[VALIDATION_ERROR_09e0077a]);
809 }
810 }
811
Dave Houlton130c0212018-01-29 13:39:56 -0700812 // 3D image may have only 1 layer
813 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_3D) && (pCreateInfo->arrayLayers != 1)) {
814 skip |=
815 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
816 VALIDATION_ERROR_09e00782, LayerName,
817 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_3D, pCreateInfo->arrayLayers must be 1. %s",
818 validation_error_map[VALIDATION_ERROR_09e00782]);
819 }
820
821 // If multi-sample, validate type, usage, tiling and mip levels.
822 if ((pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) &&
823 ((pCreateInfo->imageType != VK_IMAGE_TYPE_2D) || (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) ||
824 (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) || (pCreateInfo->mipLevels != 1))) {
825 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
826 VALIDATION_ERROR_09e00784, LayerName,
827 "vkCreateImage(): Multi-sample image with incompatible type, usage, tiling, or mips. %s",
828 validation_error_map[VALIDATION_ERROR_09e00784]);
829 }
830
831 if (0 != (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
832 VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
833 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
834 // At least one of the legal attachment bits must be set
835 if (0 == (pCreateInfo->usage & legal_flags)) {
836 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
837 VALIDATION_ERROR_09e0078c, LayerName,
838 "vkCreateImage(): Transient attachment image without a compatible attachment flag set. %s",
839 validation_error_map[VALIDATION_ERROR_09e0078c]);
840 }
841 // No flags other than the legal attachment bits may be set
842 legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
843 if (0 != (pCreateInfo->usage & ~legal_flags)) {
844 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
845 VALIDATION_ERROR_09e00786, LayerName,
846 "vkCreateImage(): Transient attachment image with incompatible usage flags set. %s",
847 validation_error_map[VALIDATION_ERROR_09e00786]);
848 }
849 }
850
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600851 // mipLevels must be less than or equal to floor(log2(max(extent.width,extent.height,extent.depth)))+1
852 uint32_t maxDim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
Petr Krause5c37652018-01-05 04:05:12 +0100853 if (maxDim > 0 && pCreateInfo->mipLevels > (floor(log2(maxDim)) + 1)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600854 skip |=
855 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
856 VALIDATION_ERROR_09e0077c, LayerName,
857 "vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
858 "floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1. %s",
859 validation_error_map[VALIDATION_ERROR_09e0077c]);
860 }
861
862 // If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
863 // VK_IMAGE_CREATE_SPARSE_BINDING_BIT
864 if (((pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
865 ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
866 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
867 VALIDATION_ERROR_09e007b6, LayerName,
868 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
869 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT. %s",
870 validation_error_map[VALIDATION_ERROR_09e007b6]);
871 }
872
873 // Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
874 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
875 // Linear tiling is unsupported
876 if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
877 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
878 INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700879 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image "
880 "tiling of VK_IMAGE_TILING_LINEAR is not supported");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600881 }
882
883 // Sparse 1D image isn't valid
884 if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
885 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
886 VALIDATION_ERROR_09e00794, LayerName,
887 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image. %s",
888 validation_error_map[VALIDATION_ERROR_09e00794]);
889 }
890
891 // Sparse 2D image when device doesn't support it
892 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage2D) &&
893 (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
894 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
895 VALIDATION_ERROR_09e00796, LayerName,
896 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
897 "feature is not enabled on the device. %s",
898 validation_error_map[VALIDATION_ERROR_09e00796]);
899 }
900
901 // Sparse 3D image when device doesn't support it
902 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage3D) &&
903 (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
904 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
905 VALIDATION_ERROR_09e00798, LayerName,
906 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
907 "feature is not enabled on the device. %s",
908 validation_error_map[VALIDATION_ERROR_09e00798]);
909 }
910
911 // Multi-sample 2D image when device doesn't support it
912 if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
913 if ((VK_FALSE == device_data->physical_device_features.sparseResidency2Samples) &&
914 (VK_SAMPLE_COUNT_2_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700915 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
916 __LINE__, VALIDATION_ERROR_09e0079a, LayerName,
917 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if "
918 "corresponding feature is not enabled on the device. %s",
919 validation_error_map[VALIDATION_ERROR_09e0079a]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600920 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency4Samples) &&
921 (VK_SAMPLE_COUNT_4_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700922 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
923 __LINE__, VALIDATION_ERROR_09e0079c, LayerName,
924 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if "
925 "corresponding feature is not enabled on the device. %s",
926 validation_error_map[VALIDATION_ERROR_09e0079c]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600927 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency8Samples) &&
928 (VK_SAMPLE_COUNT_8_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700929 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
930 __LINE__, VALIDATION_ERROR_09e0079e, LayerName,
931 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if "
932 "corresponding feature is not enabled on the device. %s",
933 validation_error_map[VALIDATION_ERROR_09e0079e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600934 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency16Samples) &&
935 (VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700936 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
937 __LINE__, VALIDATION_ERROR_09e007a0, LayerName,
938 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if "
939 "corresponding feature is not enabled on the device. %s",
940 validation_error_map[VALIDATION_ERROR_09e007a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600941 }
942 }
943 }
944 }
945 return skip;
946}
947
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600948bool pv_vkCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
949 VkImageView *pView) {
950 bool skip = false;
951 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
952 debug_report_data *report_data = device_data->report_data;
953
954 if (pCreateInfo != nullptr) {
955 if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) || (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D)) {
956 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
957 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
958 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
959 LayerName,
960 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD, "
961 "pCreateInfo->subresourceRange.layerCount must be 1",
962 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) ? 1 : 2));
963 }
964 } else if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ||
965 (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
966 if ((pCreateInfo->subresourceRange.layerCount < 1) &&
967 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
968 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
969 LayerName,
970 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD_ARRAY, "
971 "pCreateInfo->subresourceRange.layerCount must be >= 1",
972 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ? 1 : 2));
973 }
974 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE) {
975 if ((pCreateInfo->subresourceRange.layerCount != 6) &&
976 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
977 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
978 LayerName,
979 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE, "
980 "pCreateInfo->subresourceRange.layerCount must be 6");
981 }
982 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
983 if (((pCreateInfo->subresourceRange.layerCount == 0) || ((pCreateInfo->subresourceRange.layerCount % 6) != 0)) &&
984 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
985 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
986 LayerName,
987 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE_ARRAY, "
988 "pCreateInfo->subresourceRange.layerCount must be a multiple of 6");
989 }
990 if (!device_data->physical_device_features.imageCubeArray) {
991 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
992 LayerName, "vkCreateImageView: Device feature imageCubeArray not enabled.");
993 }
994 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_3D) {
995 if (pCreateInfo->subresourceRange.baseArrayLayer != 0) {
996 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
997 LayerName,
998 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
999 "pCreateInfo->subresourceRange.baseArrayLayer must be 0");
1000 }
1001
1002 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
1003 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1004 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1005 LayerName,
1006 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1007 "pCreateInfo->subresourceRange.layerCount must be 1");
1008 }
1009 }
1010 }
1011 return skip;
1012}
1013
Petr Krausb3fcdb42018-01-09 22:09:09 +01001014bool pv_VkViewport(const layer_data *device_data, const VkViewport &viewport, const char *fn_name, const char *param_name,
1015 VkDebugReportObjectTypeEXT object_type, uint64_t object = 0) {
1016 bool skip = false;
1017 debug_report_data *report_data = device_data->report_data;
1018
1019 // Note: for numerical correctness
1020 // - float comparisons should expect NaN (comparison always false).
1021 // - VkPhysicalDeviceLimits::maxViewportDimensions is uint32_t, not float -> careful.
1022
1023 const auto f_lte_u32_exact = [](const float v1_f, const uint32_t v2_u32) {
John Zulaufac0876c2018-02-19 10:09:35 -07001024 if (std::isnan(v1_f)) return false;
Petr Krausb3fcdb42018-01-09 22:09:09 +01001025 if (v1_f <= 0.0f) return true;
1026
1027 float intpart;
1028 const float fract = modff(v1_f, &intpart);
1029
1030 assert(std::numeric_limits<float>::radix == 2);
1031 const float u32_max_plus1 = ldexpf(1.0f, 32); // hopefully exact
1032 if (intpart >= u32_max_plus1) return false;
1033
1034 uint32_t v1_u32 = static_cast<uint32_t>(intpart);
1035 if (v1_u32 < v2_u32)
1036 return true;
1037 else if (v1_u32 == v2_u32 && fract == 0.0f)
1038 return true;
1039 else
1040 return false;
1041 };
1042
1043 const auto f_lte_u32_direct = [](const float v1_f, const uint32_t v2_u32) {
1044 const float v2_f = static_cast<float>(v2_u32); // not accurate for > radix^digits; and undefined rounding mode
1045 return (v1_f <= v2_f);
1046 };
1047
1048 // width
1049 bool width_healthy = true;
1050 const auto max_w = device_data->device_limits.maxViewportDimensions[0];
1051
1052 if (!(viewport.width > 0.0f)) {
1053 width_healthy = false;
1054 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd4,
1055 LayerName, "%s: %s.width (=%f) is not greater than 0.0. %s", fn_name, param_name, viewport.width,
1056 validation_error_map[VALIDATION_ERROR_15000dd4]);
1057 } else if (!(f_lte_u32_exact(viewport.width, max_w) || f_lte_u32_direct(viewport.width, max_w))) {
1058 width_healthy = false;
1059 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd6,
1060 LayerName, "%s: %s.width (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32 "). %s",
1061 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1062 } else if (!f_lte_u32_exact(viewport.width, max_w) && f_lte_u32_direct(viewport.width, max_w)) {
1063 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1064 "%s: %s.width (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32
1065 "), but it is within the static_cast<float>(maxViewportDimensions[0]) limit. %s",
1066 fn_name, param_name, viewport.width, max_w, validation_error_map[VALIDATION_ERROR_15000dd6]);
1067 }
1068
1069 // height
1070 bool height_healthy = true;
1071 const bool negative_height_enabled =
1072 device_data->extensions.vk_khr_maintenance1 || device_data->extensions.vk_amd_negative_viewport_height;
1073 const auto max_h = device_data->device_limits.maxViewportDimensions[1];
1074
1075 if (!negative_height_enabled && !(viewport.height > 0.0f)) {
1076 height_healthy = false;
1077 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dd8,
1078 LayerName, "%s: %s.height (=%f) is not greater 0.0. %s", fn_name, param_name, viewport.height,
1079 validation_error_map[VALIDATION_ERROR_15000dd8]);
1080 } else if (!(f_lte_u32_exact(fabsf(viewport.height), max_h) || f_lte_u32_direct(fabsf(viewport.height), max_h))) {
1081 height_healthy = false;
1082
1083 skip |= log_msg(
1084 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dda, LayerName,
1085 "%s: Absolute value of %s.height (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32 "). %s",
1086 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1087 } else if (!f_lte_u32_exact(fabsf(viewport.height), max_h) && f_lte_u32_direct(fabsf(viewport.height), max_h)) {
1088 height_healthy = false;
1089
1090 skip |= log_msg(
1091 report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, object_type, object, __LINE__, NONE, LayerName,
1092 "%s: Absolute value of %s.height (=%f) technically exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32
1093 "), but it is within the static_cast<float>(maxViewportDimensions[1]) limit. %s",
1094 fn_name, param_name, viewport.height, max_h, validation_error_map[VALIDATION_ERROR_15000dda]);
1095 }
1096
1097 // x
1098 bool x_healthy = true;
1099 if (!(viewport.x >= device_data->device_limits.viewportBoundsRange[0])) {
1100 x_healthy = false;
1101 skip |=
1102 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000ddc, LayerName,
1103 "%s: %s.x (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1104 viewport.x, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000ddc]);
1105 }
1106
1107 // x + width
1108 if (x_healthy && width_healthy) {
1109 const float right_bound = viewport.x + viewport.width;
1110 if (!(right_bound <= device_data->device_limits.viewportBoundsRange[1])) {
1111 skip |= log_msg(
1112 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1113 "%s: %s.x + %s.width (=%f + %f = %f) is greater than VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1114 fn_name, param_name, param_name, viewport.x, viewport.width, right_bound,
1115 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
1116 }
1117 }
1118
1119 // y
1120 bool y_healthy = true;
1121 if (!(viewport.y >= device_data->device_limits.viewportBoundsRange[0])) {
1122 y_healthy = false;
1123 skip |=
1124 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000dde, LayerName,
1125 "%s: %s.y (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s", fn_name, param_name,
1126 viewport.y, device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000dde]);
1127 } else if (negative_height_enabled && !(viewport.y <= device_data->device_limits.viewportBoundsRange[1])) {
1128 y_healthy = false;
1129 skip |=
1130 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de0, LayerName,
1131 "%s: %s.y (=%f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s", fn_name, param_name,
1132 viewport.y, device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_15000de0]);
1133 }
1134
1135 // y + height
1136 if (y_healthy && height_healthy) {
1137 const float boundary = viewport.y + viewport.height;
1138
1139 if (!(boundary <= device_data->device_limits.viewportBoundsRange[1])) {
1140 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a2,
1141 LayerName,
1142 "%s: %s.y + %s.height (=%f + %f = %f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f). %s",
1143 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1144 device_data->device_limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
1145 } else if (negative_height_enabled && !(boundary >= device_data->device_limits.viewportBoundsRange[0])) {
1146 skip |= log_msg(
1147 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_15000de2, LayerName,
1148 "%s: %s.y + %s.height (=%f + %f = %f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f). %s",
1149 fn_name, param_name, param_name, viewport.y, viewport.height, boundary,
1150 device_data->device_limits.viewportBoundsRange[0], validation_error_map[VALIDATION_ERROR_15000de2]);
1151 }
1152 }
1153
1154 if (!device_data->extensions.vk_ext_depth_range_unrestricted) {
1155 // minDepth
1156 if (!(viewport.minDepth >= 0.0) || !(viewport.minDepth <= 1.0)) {
1157 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a4,
1158 LayerName,
1159 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.minDepth (=%f) is not within the "
1160 "[0.0, 1.0] range. %s",
1161 fn_name, param_name, viewport.minDepth, validation_error_map[VALIDATION_ERROR_150009a4]);
1162 }
1163
1164 // maxDepth
1165 if (!(viewport.maxDepth >= 0.0) || !(viewport.maxDepth <= 1.0)) {
1166 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, object_type, object, __LINE__, VALIDATION_ERROR_150009a6,
1167 LayerName,
1168 "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.maxDepth (=%f) is not within the "
1169 "[0.0, 1.0] range. %s",
1170 fn_name, param_name, viewport.maxDepth, validation_error_map[VALIDATION_ERROR_150009a6]);
1171 }
1172 }
1173
1174 return skip;
1175}
1176
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001177bool pv_vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1178 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1179 VkPipeline *pPipelines) {
1180 bool skip = false;
1181 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1182 debug_report_data *report_data = device_data->report_data;
1183
1184 if (pCreateInfos != nullptr) {
1185 for (uint32_t i = 0; i < createInfoCount; ++i) {
Petr Kraus299ba622017-11-24 03:09:03 +01001186 bool has_dynamic_viewport = false;
1187 bool has_dynamic_scissor = false;
1188 bool has_dynamic_line_width = false;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001189 bool has_dynamic_viewport_w_scaling_nv = false;
1190 bool has_dynamic_discard_rectangle_ext = false;
1191 bool has_dynamic_sample_locations_ext = false;
Petr Kraus299ba622017-11-24 03:09:03 +01001192 if (pCreateInfos[i].pDynamicState != nullptr) {
1193 const auto &dynamic_state_info = *pCreateInfos[i].pDynamicState;
1194 for (uint32_t state_index = 0; state_index < dynamic_state_info.dynamicStateCount; ++state_index) {
1195 const auto &dynamic_state = dynamic_state_info.pDynamicStates[state_index];
1196 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT) has_dynamic_viewport = true;
1197 if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR) has_dynamic_scissor = true;
1198 if (dynamic_state == VK_DYNAMIC_STATE_LINE_WIDTH) has_dynamic_line_width = true;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001199 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV) has_dynamic_viewport_w_scaling_nv = true;
1200 if (dynamic_state == VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT) has_dynamic_discard_rectangle_ext = true;
1201 if (dynamic_state == VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) has_dynamic_sample_locations_ext = true;
Petr Kraus299ba622017-11-24 03:09:03 +01001202 }
1203 }
1204
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001205 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1206 if (pCreateInfos[i].pVertexInputState != nullptr) {
1207 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
1208 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
1209 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
1210 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1211 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1212 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
1213 "vkCreateGraphicsPipelines: parameter "
1214 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
1215 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1216 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
1217 validation_error_map[VALIDATION_ERROR_14c004d4]);
1218 }
1219
1220 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
1221 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1222 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
1223 "vkCreateGraphicsPipelines: parameter "
1224 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
1225 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
1226 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
1227 validation_error_map[VALIDATION_ERROR_14c004d6]);
1228 }
1229 }
1230
1231 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
1232 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
1233 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
1234 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1235 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
1236 "vkCreateGraphicsPipelines: parameter "
1237 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
1238 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
1239 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
1240 validation_error_map[VALIDATION_ERROR_14a004d8]);
1241 }
1242
1243 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1244 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1245 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
1246 "vkCreateGraphicsPipelines: parameter "
1247 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
1248 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1249 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
1250 validation_error_map[VALIDATION_ERROR_14a004da]);
1251 }
1252
1253 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
1254 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1255 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
1256 "vkCreateGraphicsPipelines: parameter "
1257 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
1258 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
1259 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
1260 validation_error_map[VALIDATION_ERROR_14a004dc]);
1261 }
1262 }
1263 }
1264
1265 if (pCreateInfos[i].pStages != nullptr) {
1266 bool has_control = false;
1267 bool has_eval = false;
1268
1269 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
1270 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1271 has_control = true;
1272 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
1273 has_eval = true;
1274 }
1275 }
1276
1277 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1278 if (has_control && has_eval) {
1279 if (pCreateInfos[i].pTessellationState == nullptr) {
1280 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1281 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
1282 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1283 "shader stage and a tessellation evaluation shader stage, "
1284 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
1285 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
1286 } else {
1287 skip |= validate_struct_pnext(
1288 report_data, "vkCreateGraphicsPipelines",
1289 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
1290 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
1291
1292 skip |= validate_reserved_flags(
1293 report_data, "vkCreateGraphicsPipelines",
1294 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1295 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1296
1297 if (pCreateInfos[i].pTessellationState->sType !=
1298 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1299 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1300 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1301 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1302 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1303 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1304 }
1305
1306 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1307 pCreateInfos[i].pTessellationState->patchControlPoints >
1308 device_data->device_limits.maxTessellationPatchSize) {
1309 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1310 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1311 "vkCreateGraphicsPipelines: invalid parameter "
1312 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1313 "should be >0 and <=%u. %s",
1314 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1315 device_data->device_limits.maxTessellationPatchSize,
1316 validation_error_map[VALIDATION_ERROR_1080097c]);
1317 }
1318 }
1319 }
1320 }
1321
1322 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1323 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1324 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1325 if (pCreateInfos[i].pViewportState == nullptr) {
Petr Krausa6103552017-11-16 21:21:58 +01001326 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1327 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1328 "vkCreateGraphicsPipelines: Rasterization is enabled (pCreateInfos[%" PRIu32
1329 "].pRasterizationState->rasterizerDiscardEnable is VK_FALSE), but pCreateInfos[%" PRIu32
1330 "].pViewportState (=NULL) is not a valid pointer. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001331 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1332 } else {
Petr Krausa6103552017-11-16 21:21:58 +01001333 const auto &viewport_state = *pCreateInfos[i].pViewportState;
1334
1335 if (viewport_state.sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1336 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1337 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b00b, LayerName,
1338 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1339 "].pViewportState->sType is not VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO. %s",
1340 i, validation_error_map[VALIDATION_ERROR_10c2b00b]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001341 }
1342
Petr Krausa6103552017-11-16 21:21:58 +01001343 const VkStructureType allowed_structs_VkPipelineViewportStateCreateInfo[] = {
1344 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
1345 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV};
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001346 skip |= validate_struct_pnext(
1347 report_data, "vkCreateGraphicsPipelines",
Petr Krausa6103552017-11-16 21:21:58 +01001348 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}),
1349 "VkPipelineViewportSwizzleStateCreateInfoNV, VkPipelineViewportWScalingStateCreateInfoNV",
1350 viewport_state.pNext, ARRAY_SIZE(allowed_structs_VkPipelineViewportStateCreateInfo),
1351 allowed_structs_VkPipelineViewportStateCreateInfo, 65, VALIDATION_ERROR_10c1c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001352
1353 skip |= validate_reserved_flags(
1354 report_data, "vkCreateGraphicsPipelines",
1355 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
Petr Krausa6103552017-11-16 21:21:58 +01001356 viewport_state.flags, VALIDATION_ERROR_10c09005);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001357
Petr Krausa6103552017-11-16 21:21:58 +01001358 if (!device_data->physical_device_features.multiViewport) {
1359 if (viewport_state.viewportCount != 1) {
1360 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1361 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1362 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1363 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32
1364 ") is not 1. %s",
1365 i, viewport_state.viewportCount, validation_error_map[VALIDATION_ERROR_10c00980]);
1366 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001367
Petr Krausa6103552017-11-16 21:21:58 +01001368 if (viewport_state.scissorCount != 1) {
1369 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1370 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1371 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1372 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->scissorCount (=%" PRIu32
1373 ") is not 1. %s",
1374 i, viewport_state.scissorCount, validation_error_map[VALIDATION_ERROR_10c00982]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001375 }
Petr Krausa6103552017-11-16 21:21:58 +01001376 } else { // multiViewport enabled
1377 if (viewport_state.viewportCount == 0) {
1378 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1379 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c30a1b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001380 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001381 "].pViewportState->viewportCount is 0. %s",
1382 i, validation_error_map[VALIDATION_ERROR_10c30a1b]);
1383 } else if (viewport_state.viewportCount > device_data->device_limits.maxViewports) {
1384 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1385 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1386 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1387 "].pViewportState->viewportCount (=%" PRIu32
1388 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1389 i, viewport_state.viewportCount, device_data->device_limits.maxViewports,
1390 validation_error_map[VALIDATION_ERROR_10c00984]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001391 }
Petr Krausa6103552017-11-16 21:21:58 +01001392
1393 if (viewport_state.scissorCount == 0) {
1394 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1395 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b61b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001396 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001397 "].pViewportState->scissorCount is 0. %s",
1398 i, validation_error_map[VALIDATION_ERROR_10c2b61b]);
1399 } else if (viewport_state.scissorCount > device_data->device_limits.maxViewports) {
1400 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1401 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1402 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1403 "].pViewportState->scissorCount (=%" PRIu32
1404 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1405 i, viewport_state.scissorCount, device_data->device_limits.maxViewports,
1406 validation_error_map[VALIDATION_ERROR_10c00986]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001407 }
1408 }
1409
Petr Krausa6103552017-11-16 21:21:58 +01001410 if (viewport_state.scissorCount != viewport_state.viewportCount) {
1411 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1412 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1413 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1414 "].pViewportState->scissorCount (=%" PRIu32 ") is not identical to pCreateInfos[%" PRIu32
1415 "].pViewportState->viewportCount (=%" PRIu32 "). %s",
1416 i, viewport_state.scissorCount, i, viewport_state.viewportCount,
1417 validation_error_map[VALIDATION_ERROR_10c00988]);
1418 }
1419
Petr Krausa6103552017-11-16 21:21:58 +01001420 if (!has_dynamic_viewport && viewport_state.viewportCount > 0 && viewport_state.pViewports == nullptr) {
1421 skip |= log_msg(
1422 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1423 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1424 "vkCreateGraphicsPipelines: The viewport state is static (pCreateInfos[%" PRIu32
1425 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001426 "].pViewportState->pViewports (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001427 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1428 }
1429
1430 if (!has_dynamic_scissor && viewport_state.scissorCount > 0 && viewport_state.pScissors == nullptr) {
1431 skip |= log_msg(
1432 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1433 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1434 "vkCreateGraphicsPipelines: The scissor state is static (pCreateInfos[%" PRIu32
1435 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_SCISSOR), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001436 "].pViewportState->pScissors (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001437 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1438 }
1439
Petr Krausb3fcdb42018-01-09 22:09:09 +01001440 // validate the VkViewports
1441 if (!has_dynamic_viewport && viewport_state.pViewports) {
1442 for (uint32_t viewport_i = 0; viewport_i < viewport_state.viewportCount; ++viewport_i) {
1443 const auto &viewport = viewport_state.pViewports[viewport_i]; // will crash on invalid ptr
1444 const char fn_name[] = "vkCreateGraphicsPipelines";
1445 const std::string param_name = "pCreateInfos[" + std::to_string(i) + "].pViewportState->pViewports[" +
1446 std::to_string(viewport_i) + "]";
1447 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
1448 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
1449 }
1450 }
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001451
1452 if (has_dynamic_viewport_w_scaling_nv && !device_data->extensions.vk_nv_clip_space_w_scaling) {
1453 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1454 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1455 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001456 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001457 "VK_NV_clip_space_w_scaling extension is not enabled.",
1458 i);
1459 }
1460
1461 if (has_dynamic_discard_rectangle_ext && !device_data->extensions.vk_ext_discard_rectangles) {
1462 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1463 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1464 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001465 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001466 "VK_EXT_discard_rectangles extension is not enabled.",
1467 i);
1468 }
1469
1470 if (has_dynamic_sample_locations_ext && !device_data->extensions.vk_ext_sample_locations) {
1471 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1472 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1473 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07001474 "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, but "
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001475 "VK_EXT_sample_locations extension is not enabled.",
1476 i);
1477 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001478 }
1479
1480 if (pCreateInfos[i].pMultisampleState == nullptr) {
1481 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1482 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1483 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1484 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1485 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1486 } else {
Dave Houltonb3bbec72018-01-17 10:13:33 -07001487 const VkStructureType valid_next_stypes[] = {LvlTypeMap<VkPipelineCoverageModulationStateCreateInfoNV>::kSType,
1488 LvlTypeMap<VkPipelineCoverageToColorStateCreateInfoNV>::kSType,
1489 LvlTypeMap<VkPipelineSampleLocationsStateCreateInfoEXT>::kSType};
Mike Schuchardt97662b02017-12-06 13:31:29 -07001490 const char *valid_struct_names =
Dave Houltona9df0ce2018-02-07 10:51:23 -07001491 "VkPipelineCoverageModulationStateCreateInfoNV, VkPipelineCoverageToColorStateCreateInfoNV, "
John Zulauf96b0e422017-11-14 11:43:19 -07001492 "VkPipelineSampleLocationsStateCreateInfoEXT";
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001493 skip |= validate_struct_pnext(
1494 report_data, "vkCreateGraphicsPipelines",
John Zulauf96b0e422017-11-14 11:43:19 -07001495 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}),
1496 valid_struct_names, pCreateInfos[i].pMultisampleState->pNext, 3, valid_next_stypes, GeneratedHeaderVersion,
1497 VALIDATION_ERROR_1001c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001498
1499 skip |= validate_reserved_flags(
1500 report_data, "vkCreateGraphicsPipelines",
1501 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1502 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1503
1504 skip |= validate_bool32(
1505 report_data, "vkCreateGraphicsPipelines",
1506 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1507 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1508
1509 skip |= validate_array(
1510 report_data, "vkCreateGraphicsPipelines",
1511 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1512 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1513 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1514 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1515
1516 skip |= validate_bool32(
1517 report_data, "vkCreateGraphicsPipelines",
1518 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1519 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1520
1521 skip |= validate_bool32(
1522 report_data, "vkCreateGraphicsPipelines",
1523 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1524 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1525
1526 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1527 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1528 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1529 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1530 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1531 i);
1532 }
John Zulauf7acac592017-11-06 11:15:53 -07001533 if (pCreateInfos[i].pMultisampleState->sampleShadingEnable == VK_TRUE) {
1534 if (!device_data->physical_device_features.sampleRateShading) {
1535 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1536 __LINE__, VALIDATION_ERROR_10000620, LayerName,
1537 "vkCreateGraphicsPipelines(): parameter "
1538 "pCreateInfos[%d].pMultisampleState->sampleShadingEnable: %s",
1539 i, validation_error_map[VALIDATION_ERROR_10000620]);
1540 }
1541 // TODO Add documentation issue about when minSampleShading must be in range and when it is ignored
1542 // For now a "least noise" test *only* when sampleShadingEnable is VK_TRUE.
1543 if (!in_inclusive_range(pCreateInfos[i].pMultisampleState->minSampleShading, 0.F, 1.0F)) {
1544 skip |= log_msg(
1545 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1546 VALIDATION_ERROR_10000624, LayerName,
1547 "vkCreateGraphicsPipelines(): parameter pCreateInfos[%d].pMultisampleState->minSampleShading: %s",
1548 i, validation_error_map[VALIDATION_ERROR_10000624]);
1549 }
1550 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001551 }
1552
Petr Krause91f7a12017-12-14 20:57:36 +01001553 bool uses_color_attachment = false;
1554 bool uses_depthstencil_attachment = false;
1555 {
1556 const auto subpasses_uses_it = device_data->renderpasses_states.find(pCreateInfos[i].renderPass);
1557 if (subpasses_uses_it != device_data->renderpasses_states.end()) {
1558 const auto &subpasses_uses = subpasses_uses_it->second;
1559 if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[i].subpass))
1560 uses_color_attachment = true;
1561 if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[i].subpass))
1562 uses_depthstencil_attachment = true;
1563 }
1564 }
1565
1566 if (pCreateInfos[i].pDepthStencilState != nullptr && uses_depthstencil_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001567 skip |= validate_struct_pnext(
1568 report_data, "vkCreateGraphicsPipelines",
1569 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1570 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1571
1572 skip |= validate_reserved_flags(
1573 report_data, "vkCreateGraphicsPipelines",
1574 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1575 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1576
1577 skip |= validate_bool32(
1578 report_data, "vkCreateGraphicsPipelines",
1579 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1580 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1581
1582 skip |= validate_bool32(
1583 report_data, "vkCreateGraphicsPipelines",
1584 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1585 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1586
1587 skip |= validate_ranged_enum(
1588 report_data, "vkCreateGraphicsPipelines",
1589 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1590 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1591 VALIDATION_ERROR_0f604001);
1592
1593 skip |= validate_bool32(
1594 report_data, "vkCreateGraphicsPipelines",
1595 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1596 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1597
1598 skip |= validate_bool32(
1599 report_data, "vkCreateGraphicsPipelines",
1600 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1601 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1602
1603 skip |= validate_ranged_enum(
1604 report_data, "vkCreateGraphicsPipelines",
1605 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1606 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1607 VALIDATION_ERROR_13a08601);
1608
1609 skip |= validate_ranged_enum(
1610 report_data, "vkCreateGraphicsPipelines",
1611 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1612 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1613 VALIDATION_ERROR_13a27801);
1614
1615 skip |= validate_ranged_enum(
1616 report_data, "vkCreateGraphicsPipelines",
1617 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1618 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1619 VALIDATION_ERROR_13a04201);
1620
1621 skip |= validate_ranged_enum(
1622 report_data, "vkCreateGraphicsPipelines",
1623 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1624 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1625 VALIDATION_ERROR_0f604001);
1626
1627 skip |= validate_ranged_enum(
1628 report_data, "vkCreateGraphicsPipelines",
1629 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1630 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1631 VALIDATION_ERROR_13a08601);
1632
1633 skip |= validate_ranged_enum(
1634 report_data, "vkCreateGraphicsPipelines",
1635 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1636 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1637 VALIDATION_ERROR_13a27801);
1638
1639 skip |= validate_ranged_enum(
1640 report_data, "vkCreateGraphicsPipelines",
1641 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1642 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1643 VALIDATION_ERROR_13a04201);
1644
1645 skip |= validate_ranged_enum(
1646 report_data, "vkCreateGraphicsPipelines",
1647 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1648 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1649 VALIDATION_ERROR_0f604001);
1650
1651 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1652 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1653 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1654 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1655 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1656 i);
1657 }
1658 }
1659
Petr Krause91f7a12017-12-14 20:57:36 +01001660 if (pCreateInfos[i].pColorBlendState != nullptr && uses_color_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001661 skip |= validate_struct_pnext(
1662 report_data, "vkCreateGraphicsPipelines",
1663 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1664 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1665
1666 skip |= validate_reserved_flags(
1667 report_data, "vkCreateGraphicsPipelines",
1668 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1669 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1670
1671 skip |= validate_bool32(
1672 report_data, "vkCreateGraphicsPipelines",
1673 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1674 pCreateInfos[i].pColorBlendState->logicOpEnable);
1675
1676 skip |= validate_array(
1677 report_data, "vkCreateGraphicsPipelines",
1678 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1679 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1680 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1681 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1682
1683 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1684 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1685 ++attachmentIndex) {
1686 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1687 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1688 ParameterName::IndexVector{i, attachmentIndex}),
1689 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1690
1691 skip |= validate_ranged_enum(
1692 report_data, "vkCreateGraphicsPipelines",
1693 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1694 ParameterName::IndexVector{i, attachmentIndex}),
1695 "VkBlendFactor", AllVkBlendFactorEnums,
1696 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1697 VALIDATION_ERROR_0f22cc01);
1698
1699 skip |= validate_ranged_enum(
1700 report_data, "vkCreateGraphicsPipelines",
1701 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1702 ParameterName::IndexVector{i, attachmentIndex}),
1703 "VkBlendFactor", AllVkBlendFactorEnums,
1704 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1705 VALIDATION_ERROR_0f207001);
1706
1707 skip |= validate_ranged_enum(
1708 report_data, "vkCreateGraphicsPipelines",
1709 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1710 ParameterName::IndexVector{i, attachmentIndex}),
1711 "VkBlendOp", AllVkBlendOpEnums,
1712 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1713 VALIDATION_ERROR_0f202001);
1714
1715 skip |= validate_ranged_enum(
1716 report_data, "vkCreateGraphicsPipelines",
1717 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1718 ParameterName::IndexVector{i, attachmentIndex}),
1719 "VkBlendFactor", AllVkBlendFactorEnums,
1720 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1721 VALIDATION_ERROR_0f22c601);
1722
1723 skip |= validate_ranged_enum(
1724 report_data, "vkCreateGraphicsPipelines",
1725 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1726 ParameterName::IndexVector{i, attachmentIndex}),
1727 "VkBlendFactor", AllVkBlendFactorEnums,
1728 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1729 VALIDATION_ERROR_0f206a01);
1730
1731 skip |= validate_ranged_enum(
1732 report_data, "vkCreateGraphicsPipelines",
1733 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1734 ParameterName::IndexVector{i, attachmentIndex}),
1735 "VkBlendOp", AllVkBlendOpEnums,
1736 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1737 VALIDATION_ERROR_0f200801);
1738
1739 skip |=
1740 validate_flags(report_data, "vkCreateGraphicsPipelines",
1741 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1742 ParameterName::IndexVector{i, attachmentIndex}),
1743 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1744 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1745 false, false, VALIDATION_ERROR_0f202201);
1746 }
1747 }
1748
1749 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1750 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1751 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1752 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1753 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1754 i);
1755 }
1756
1757 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1758 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1759 skip |= validate_ranged_enum(
1760 report_data, "vkCreateGraphicsPipelines",
1761 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1762 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1763 }
1764 }
1765 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001766
Petr Kraus9752aae2017-11-24 03:05:50 +01001767 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1768 if (pCreateInfos[i].basePipelineIndex != -1) {
1769 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001770 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1771 __LINE__, VALIDATION_ERROR_096005a8, LayerName,
1772 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be "
1773 "VK_NULL_HANDLE if pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag "
1774 "and pCreateInfos->basePipelineIndex is not -1. %s",
1775 validation_error_map[VALIDATION_ERROR_096005a8]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001776 }
1777 }
1778
Petr Kraus9752aae2017-11-24 03:05:50 +01001779 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
1780 if (pCreateInfos[i].basePipelineIndex != -1) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001781 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1782 __LINE__, VALIDATION_ERROR_096005aa, LayerName,
1783 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1784 "pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and "
1785 "pCreateInfos->basePipelineHandle is not VK_NULL_HANDLE. %s",
1786 validation_error_map[VALIDATION_ERROR_096005aa]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001787 }
1788 }
1789 }
1790
Petr Kraus9752aae2017-11-24 03:05:50 +01001791 if (pCreateInfos[i].pRasterizationState) {
1792 if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001793 (device_data->physical_device_features.fillModeNonSolid == false)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001794 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1795 __LINE__, DEVICE_FEATURE, LayerName,
1796 "vkCreateGraphicsPipelines parameter, VkPolygonMode "
1797 "pCreateInfos->pRasterizationState->polygonMode cannot be VK_POLYGON_MODE_POINT or "
1798 "VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001799 }
Petr Kraus299ba622017-11-24 03:09:03 +01001800
1801 if (!has_dynamic_line_width && !device_data->physical_device_features.wideLines &&
1802 (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
1803 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1804 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, 0, __LINE__, VALIDATION_ERROR_096005da, LayerName,
1805 "The line width state is static (pCreateInfos[%" PRIu32
1806 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
1807 "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
1808 "].pRasterizationState->lineWidth (=%f) is not 1.0. %s",
1809 i, i, pCreateInfos[i].pRasterizationState->lineWidth,
1810 validation_error_map[VALIDATION_ERROR_096005da]);
1811 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001812 }
1813
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001814 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1815 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1816 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1817 pCreateInfos[i].pStages[j].pName);
1818 }
1819 }
1820 }
1821
1822 return skip;
1823}
1824
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001825bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1826 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1827 VkPipeline *pPipelines) {
1828 bool skip = false;
1829 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1830
1831 for (uint32_t i = 0; i < createInfoCount; i++) {
1832 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1833 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1834 pCreateInfos[i].stage.pName);
1835 }
1836
1837 return skip;
1838}
1839
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001840bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1841 VkSampler *pSampler) {
1842 bool skip = false;
1843 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1844 debug_report_data *report_data = device_data->report_data;
1845
1846 if (pCreateInfo != nullptr) {
John Zulauf71968502017-10-26 13:51:15 -06001847 const auto &features = device_data->physical_device_features;
1848 const auto &limits = device_data->device_limits;
1849 if (pCreateInfo->anisotropyEnable == VK_TRUE) {
1850 if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
1851 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1852 VALIDATION_ERROR_1260085e, LayerName,
1853 "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found. %s",
1854 "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
1855 "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy,
1856 validation_error_map[VALIDATION_ERROR_1260085e]);
1857 }
1858
1859 // Anistropy cannot be enabled in sampler unless enabled as a feature
1860 if (features.samplerAnisotropy == VK_FALSE) {
1861 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1862 VALIDATION_ERROR_1260085c, LayerName,
1863 "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE. %s",
1864 "pCreateInfo->anisotropyEnable", validation_error_map[VALIDATION_ERROR_1260085c]);
1865 }
1866
1867 // Anistropy and unnormalized coordinates cannot be enabled simultaneously
1868 if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
1869 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1870 VALIDATION_ERROR_12600868, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001871 "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates must "
1872 "not both be VK_TRUE. %s",
John Zulauf71968502017-10-26 13:51:15 -06001873 validation_error_map[VALIDATION_ERROR_12600868]);
1874 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001875 }
1876
1877 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1878 if (pCreateInfo->compareEnable == VK_TRUE) {
1879 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1880 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
1881 }
1882
1883 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
1884 // valid VkBorderColor value
1885 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1886 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1887 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
1888 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
1889 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
1890 }
1891
1892 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
1893 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
1894 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
1895 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1896 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1897 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
1898 skip |=
1899 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1900 VALIDATION_ERROR_1260086e, LayerName,
1901 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
1902 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
1903 validation_error_map[VALIDATION_ERROR_1260086e]);
1904 }
John Zulauf275805c2017-10-26 15:34:49 -06001905
1906 // Checks for the IMG cubic filtering extension
1907 if (device_data->extensions.vk_img_filter_cubic) {
1908 if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
1909 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001910 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1911 VALIDATION_ERROR_12600872, LayerName,
1912 "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter "
1913 "are VK_FILTER_CUBIC_IMG. %s",
1914 validation_error_map[VALIDATION_ERROR_12600872]);
John Zulauf275805c2017-10-26 15:34:49 -06001915 }
1916 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001917 }
1918
1919 return skip;
1920}
1921
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001922bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1923 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
1924 bool skip = false;
1925 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1926 debug_report_data *report_data = device_data->report_data;
1927
1928 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1929 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
1930 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
1931 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
1932 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
1933 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
1934 // valid VkSampler handles
1935 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1936 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
1937 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
1938 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
1939 ++descriptor_index) {
1940 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
1941 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1942 __LINE__, REQUIRED_PARAMETER, LayerName,
1943 "vkCreateDescriptorSetLayout: required parameter "
Dave Houltona9df0ce2018-02-07 10:51:23 -07001944 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d] specified as VK_NULL_HANDLE",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001945 i, descriptor_index);
1946 }
1947 }
1948 }
1949
1950 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
1951 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
1952 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001953 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1954 __LINE__, VALIDATION_ERROR_04e00236, LayerName,
1955 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
1956 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits "
1957 "values. %s",
1958 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001959 }
1960 }
1961 }
1962 }
1963
1964 return skip;
1965}
1966
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001967bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
1968 const VkDescriptorSet *pDescriptorSets) {
1969 bool skip = false;
1970 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1971 debug_report_data *report_data = device_data->report_data;
1972
1973 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1974 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1975 // validate_array()
1976 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
1977 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1978 return skip;
1979}
1980
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001981bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
1982 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
1983 bool skip = false;
1984 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1985 debug_report_data *report_data = device_data->report_data;
1986
1987 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1988 if (pDescriptorWrites != NULL) {
1989 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
1990 // descriptorCount must be greater than 0
1991 if (pDescriptorWrites[i].descriptorCount == 0) {
1992 skip |=
1993 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1994 VALIDATION_ERROR_15c0441b, LayerName,
1995 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
1996 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
1997 }
1998
1999 // dstSet must be a valid VkDescriptorSet handle
2000 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2001 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
2002 pDescriptorWrites[i].dstSet);
2003
2004 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
2005 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
2006 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
2007 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
2008 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
2009 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
2010 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2011 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
2012 if (pDescriptorWrites[i].pImageInfo == nullptr) {
2013 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2014 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
2015 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2016 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
2017 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
2018 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
2019 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
2020 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
2021 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
2022 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
2023 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
2024 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2025 ++descriptor_index) {
2026 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2027 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
2028 ParameterName::IndexVector{i, descriptor_index}),
2029 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
2030 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
2031 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
2032 ParameterName::IndexVector{i, descriptor_index}),
2033 "VkImageLayout", AllVkImageLayoutEnums,
2034 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
2035 VALIDATION_ERROR_UNDEFINED);
2036 }
2037 }
2038 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2039 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2040 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
2041 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2042 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
2043 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
2044 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
2045 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
2046 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2047 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
2048 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2049 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
2050 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
2051 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
2052 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
2053 } else {
2054 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
2055 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2056 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
2057 ParameterName::IndexVector{i, descriptorIndex}),
2058 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
2059 }
2060 }
2061 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
2062 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
2063 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
2064 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
2065 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
2066 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2067 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
2068 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
2069 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
2070 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
2071 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
2072 } else {
2073 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
2074 ++descriptor_index) {
2075 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
2076 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
2077 ParameterName::IndexVector{i, descriptor_index}),
2078 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
2079 }
2080 }
2081 }
2082
2083 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
2084 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
2085 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
2086 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2087 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2088 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
2089 skip |= log_msg(
2090 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2091 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
2092 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2093 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2094 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
2095 validation_error_map[VALIDATION_ERROR_15c0028e]);
2096 }
2097 }
2098 }
2099 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
2100 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
2101 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
2102 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
2103 if (pDescriptorWrites[i].pBufferInfo != NULL) {
2104 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
2105 skip |= log_msg(
2106 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2107 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
2108 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
2109 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
2110 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
2111 validation_error_map[VALIDATION_ERROR_15c00290]);
2112 }
2113 }
2114 }
2115 }
2116 }
2117 }
2118 return skip;
2119}
2120
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002121bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2122 VkRenderPass *pRenderPass) {
2123 bool skip = false;
2124 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2125 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
2126
2127 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
2128 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
2129 std::stringstream ss;
2130 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
2131 << validation_error_map[VALIDATION_ERROR_00809201];
2132 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2133 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
2134 }
2135 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
2136 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
2137 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2138 __LINE__, VALIDATION_ERROR_00800696, "DL",
2139 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
2140 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
2141 i, validation_error_map[VALIDATION_ERROR_00800696]);
2142 }
2143 }
2144
2145 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2146 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
2147 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2148 __LINE__, VALIDATION_ERROR_1400069a, "DL",
2149 "Cannot create a render pass with %d color attachments. Max is %d. %s",
2150 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
2151 validation_error_map[VALIDATION_ERROR_1400069a]);
2152 }
2153 }
2154 return skip;
2155}
2156
2157bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
2158 const VkCommandBuffer *pCommandBuffers) {
2159 bool skip = false;
2160 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2161 debug_report_data *report_data = device_data->report_data;
2162
2163 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2164 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2165 // validate_array()
2166 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
2167 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2168 return skip;
2169}
2170
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002171bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
2172 bool skip = false;
2173 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2174 debug_report_data *report_data = device_data->report_data;
2175 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
2176
2177 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2178 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
2179 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
2180 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
2181 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
2182
2183 if (pBeginInfo->pInheritanceInfo != NULL) {
2184 skip |=
2185 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
2186 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
2187
2188 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
2189 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
2190
2191 // TODO: This only needs to be validated when the inherited queries feature is enabled
2192 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2193 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
2194
2195 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
2196 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
2197 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
2198 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
2199 }
2200
2201 if (pInfo != NULL) {
2202 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2203 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2204 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
2205 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
2206 "inheritedQueries. %s",
2207 validation_error_map[VALIDATION_ERROR_02a00070]);
2208 }
2209 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2210 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2211 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
2212 VALIDATION_ERROR_02a00072);
2213 }
2214 }
2215
2216 return skip;
2217}
2218
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002219bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
2220 const VkViewport *pViewports) {
2221 bool skip = false;
2222 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2223
Petr Krausd55e77c2018-01-09 22:09:25 +01002224 if (!device_data->physical_device_features.multiViewport) {
2225 if (firstViewport != 0) {
2226 skip |=
2227 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2228 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000990, LayerName,
2229 "vkCmdSetViewport: The multiViewport feature is disabled, but firstViewport (=%" PRIu32 ") is not 0. %s",
Jeremy Kniager72437be2018-01-25 11:41:20 -07002230 firstViewport, validation_error_map[VALIDATION_ERROR_1e000990]);
Petr Krausd55e77c2018-01-09 22:09:25 +01002231 }
2232 if (viewportCount > 1) {
2233 skip |=
2234 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2235 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e000992, LayerName,
2236 "vkCmdSetViewport: The multiViewport feature is disabled, but viewportCount (=%" PRIu32 ") is not 1. %s",
2237 viewportCount, validation_error_map[VALIDATION_ERROR_1e000992]);
2238 }
2239 } else { // multiViewport enabled
Petr Kraus7dfeed12018-02-27 20:51:20 +01002240 const uint64_t sum = static_cast<uint64_t>(firstViewport) + static_cast<uint64_t>(viewportCount);
Petr Krausd55e77c2018-01-09 22:09:25 +01002241 if (sum > device_data->device_limits.maxViewports) {
2242 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2243 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1e00098e, LayerName,
2244 "vkCmdSetViewport: firstViewport + viewportCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2245 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2246 firstViewport, viewportCount, sum, device_data->device_limits.maxViewports,
2247 validation_error_map[VALIDATION_ERROR_1e00098e]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002248 }
2249 }
Petr Krausb3fcdb42018-01-09 22:09:09 +01002250
2251 if (pViewports) {
2252 for (uint32_t viewport_i = 0; viewport_i < viewportCount; ++viewport_i) {
2253 const auto &viewport = pViewports[viewport_i]; // will crash on invalid ptr
2254 const char fn_name[] = "vkCmdSetViewport";
2255 const std::string param_name = "pViewports[" + std::to_string(viewport_i) + "]";
2256 skip |= pv_VkViewport(device_data, viewport, fn_name, param_name.c_str(),
2257 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer));
2258 }
2259 }
2260
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002261 return skip;
2262}
2263
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002264bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
2265 bool skip = false;
2266 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2267 debug_report_data *report_data = device_data->report_data;
2268
Petr Kraus6260f0a2018-02-27 21:15:55 +01002269 if (!device_data->physical_device_features.multiViewport) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002270 if (firstScissor != 0) {
Petr Kraus6260f0a2018-02-27 21:15:55 +01002271 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2272 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a2, LayerName,
2273 "vkCmdSetScissor: The multiViewport feature is disabled, but firstScissor (=%" PRIu32 ") is not 0. %s",
2274 firstScissor, validation_error_map[VALIDATION_ERROR_1d8004a2]);
2275 }
2276 if (scissorCount > 1) {
2277 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2278 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a4, LayerName,
2279 "vkCmdSetScissor: The multiViewport feature is disabled, but scissorCount (=%" PRIu32 ") is not 1. %s",
2280 scissorCount, validation_error_map[VALIDATION_ERROR_1d8004a4]);
2281 }
2282 } else { // multiViewport enabled
2283 const uint64_t sum = static_cast<uint64_t>(firstScissor) + static_cast<uint64_t>(scissorCount);
2284 if (sum > device_data->device_limits.maxViewports) {
2285 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2286 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a0, LayerName,
2287 "vkCmdSetScissor: firstScissor + scissorCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
2288 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
2289 firstScissor, scissorCount, sum, device_data->device_limits.maxViewports,
2290 validation_error_map[VALIDATION_ERROR_1d8004a0]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002291 }
2292 }
2293
Petr Kraus6260f0a2018-02-27 21:15:55 +01002294 if (pScissors) {
2295 for (uint32_t scissor_i = 0; scissor_i < scissorCount; ++scissor_i) {
2296 const auto &scissor = pScissors[scissor_i]; // will crash on invalid ptr
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002297
Petr Kraus6260f0a2018-02-27 21:15:55 +01002298 if (scissor.offset.x < 0) {
2299 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2300 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2301 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.x (=%" PRIi32 ") is negative. %s", scissor_i,
2302 scissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2303 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002304
Petr Kraus6260f0a2018-02-27 21:15:55 +01002305 if (scissor.offset.y < 0) {
2306 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2307 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a6, LayerName,
2308 "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.y (=%" PRIi32 ") is negative. %s", scissor_i,
2309 scissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2310 }
2311
2312 const int64_t x_sum = static_cast<int64_t>(scissor.offset.x) + static_cast<int64_t>(scissor.extent.width);
2313 if (x_sum > INT32_MAX) {
2314 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2315 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004a8, LayerName,
2316 "vkCmdSetScissor: offset.x + extent.width (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2317 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2318 scissor.offset.x, scissor.extent.width, x_sum, scissor_i,
2319 validation_error_map[VALIDATION_ERROR_1d8004a8]);
2320 }
2321
2322 const int64_t y_sum = static_cast<int64_t>(scissor.offset.y) + static_cast<int64_t>(scissor.extent.height);
2323 if (y_sum > INT32_MAX) {
2324 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2325 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d8004aa, LayerName,
2326 "vkCmdSetScissor: offset.y + extent.height (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
2327 ") of pScissors[%" PRIu32 "] will overflow int32_t. %s",
2328 scissor.offset.y, scissor.extent.height, y_sum, scissor_i,
2329 validation_error_map[VALIDATION_ERROR_1d8004aa]);
2330 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002331 }
2332 }
Petr Kraus6260f0a2018-02-27 21:15:55 +01002333
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002334 return skip;
2335}
2336
Petr Kraus299ba622017-11-24 03:09:03 +01002337bool pv_vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
2338 bool skip = false;
2339 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2340 debug_report_data *report_data = device_data->report_data;
2341
2342 if (!device_data->physical_device_features.wideLines && (lineWidth != 1.0f)) {
2343 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2344 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d600628, LayerName,
2345 "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0. %s", lineWidth,
2346 validation_error_map[VALIDATION_ERROR_1d600628]);
2347 }
2348
2349 return skip;
2350}
2351
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002352bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2353 uint32_t firstInstance) {
2354 bool skip = false;
2355 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2356 if (vertexCount == 0) {
2357 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
2358 // this an error or leave as is.
2359 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2360 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
2361 }
2362
2363 if (instanceCount == 0) {
2364 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2365 // this an error or leave as is.
2366 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2367 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2368 }
2369 return skip;
2370}
2371
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002372bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2373 bool skip = false;
2374 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2375
2376 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2377 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2378 __LINE__, DEVICE_FEATURE, LayerName,
2379 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2380 }
2381 return skip;
2382}
2383
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002384bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2385 uint32_t stride) {
2386 bool skip = false;
2387 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2388 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2389 skip |=
2390 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2391 DEVICE_FEATURE, LayerName,
2392 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2393 }
2394 return skip;
2395}
2396
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002397bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2398 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2399 bool skip = false;
2400 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2401
Dave Houltonf5217612018-02-02 16:18:52 -07002402 VkImageAspectFlags legal_aspect_flags =
2403 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2404 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2405 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2406 }
2407
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002408 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002409 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002410 skip |= log_msg(
2411 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2412 VALIDATION_ERROR_0a600c01, LayerName,
2413 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2414 validation_error_map[VALIDATION_ERROR_0a600c01]);
2415 }
Dave Houltonf5217612018-02-02 16:18:52 -07002416 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002417 skip |= log_msg(
2418 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2419 VALIDATION_ERROR_0a600c01, LayerName,
2420 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2421 validation_error_map[VALIDATION_ERROR_0a600c01]);
2422 }
2423 }
2424 return skip;
2425}
2426
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002427bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2428 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2429 bool skip = false;
2430 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2431
Dave Houltonf5217612018-02-02 16:18:52 -07002432 VkImageAspectFlags legal_aspect_flags =
2433 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2434 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2435 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2436 }
2437
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002438 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002439 if ((pRegions->srcSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002440 skip |= log_msg(
2441 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2442 UNRECOGNIZED_VALUE, LayerName,
2443 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2444 }
Dave Houltonf5217612018-02-02 16:18:52 -07002445 if ((pRegions->dstSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002446 skip |= log_msg(
2447 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2448 UNRECOGNIZED_VALUE, LayerName,
2449 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2450 }
2451 }
2452 return skip;
2453}
2454
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002455bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2456 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2457 bool skip = false;
2458 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2459
Dave Houltonf5217612018-02-02 16:18:52 -07002460 VkImageAspectFlags legal_aspect_flags =
2461 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2462 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2463 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2464 }
2465
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002466 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002467 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002468 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2469 __LINE__, UNRECOGNIZED_VALUE, LayerName,
2470 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an "
2471 "unrecognized enumerator");
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002472 }
2473 }
2474 return skip;
2475}
2476
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002477bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2478 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2479 bool skip = false;
2480 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2481
Dave Houltonf5217612018-02-02 16:18:52 -07002482 VkImageAspectFlags legal_aspect_flags =
2483 VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
2484 if (device_data->extensions.vk_khr_sampler_ycbcr_conversion) {
2485 legal_aspect_flags |= (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
2486 }
2487
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002488 if (pRegions != nullptr) {
Dave Houltonf5217612018-02-02 16:18:52 -07002489 if ((pRegions->imageSubresource.aspectMask & legal_aspect_flags) == 0) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002490 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2491 UNRECOGNIZED_VALUE, LayerName,
2492 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2493 "enumerator");
2494 }
2495 }
2496 return skip;
2497}
2498
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002499bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2500 const void *pData) {
2501 bool skip = false;
2502 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2503
2504 if (dstOffset & 3) {
2505 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2506 __LINE__, VALIDATION_ERROR_1e400048, LayerName,
2507 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2508 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2509 }
2510
2511 if ((dataSize <= 0) || (dataSize > 65536)) {
2512 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2513 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2514 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2515 "), must be greater than zero and less than or equal to 65536. %s",
2516 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2517 } else if (dataSize & 3) {
2518 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2519 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2520 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2521 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2522 }
2523 return skip;
2524}
2525
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002526bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2527 uint32_t data) {
2528 bool skip = false;
2529 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2530
2531 if (dstOffset & 3) {
2532 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2533 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2534 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2535 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2536 }
2537
2538 if (size != VK_WHOLE_SIZE) {
2539 if (size <= 0) {
2540 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2541 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2542 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2543 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2544 } else if (size & 3) {
2545 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2546 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2547 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2548 validation_error_map[VALIDATION_ERROR_1b400038]);
2549 }
2550 }
2551 return skip;
2552}
2553
2554VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2555 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2556}
2557
2558VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2559 VkLayerProperties *pProperties) {
2560 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2561}
2562
2563VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2564 VkExtensionProperties *pProperties) {
2565 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2566 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2567
2568 return VK_ERROR_LAYER_NOT_PRESENT;
2569}
2570
2571VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2572 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2573 // Parameter_validation does not have any physical device extensions
2574 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2575 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2576
2577 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2578 bool skip =
2579 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2580 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2581 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2582
2583 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2584}
2585
2586static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2587 if (!flag) {
2588 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2589 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2590 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2591 extension_name);
2592 }
2593
2594 return false;
2595}
2596
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002597bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2598 VkSwapchainKHR *pSwapchain) {
2599 bool skip = false;
2600 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2601 debug_report_data *report_data = device_data->report_data;
2602
Petr Krause5c37652018-01-05 04:05:12 +01002603 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, VK_NULL_HANDLE, LayerName,
2604 "vkCreateSwapchainKHR"};
2605
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002606 if (pCreateInfo != nullptr) {
2607 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2608 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002609 skip |=
2610 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2611 DEVICE_FEATURE, LayerName,
2612 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The textureCompressionETC2 "
2613 "feature is not enabled: neither ETC2 nor EAC formats can be used to create images.",
2614 string_VkFormat(pCreateInfo->imageFormat));
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002615 }
2616
2617 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2618 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2619 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2620 DEVICE_FEATURE, LayerName,
2621 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2622 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2623 string_VkFormat(pCreateInfo->imageFormat));
2624 }
2625
2626 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2627 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2628 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2629 DEVICE_FEATURE, LayerName,
2630 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2631 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2632 string_VkFormat(pCreateInfo->imageFormat));
2633 }
2634
2635 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2636 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2637 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2638 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2639 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2640 VALIDATION_ERROR_146009fc, LayerName,
2641 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2642 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2643 validation_error_map[VALIDATION_ERROR_146009fc]);
2644 }
2645
2646 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2647 // queueFamilyIndexCount uint32_t values
2648 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2649 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2650 VALIDATION_ERROR_146009fa, LayerName,
2651 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2652 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2653 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2654 validation_error_map[VALIDATION_ERROR_146009fa]);
2655 } else {
2656 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2657 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2658 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2659 INVALID_USAGE, false, "", "");
2660 }
2661 }
2662
Petr Krause5c37652018-01-05 04:05:12 +01002663 skip |= ValidateGreaterThanZero(pCreateInfo->imageArrayLayers, "pCreateInfo->imageArrayLayers", VALIDATION_ERROR_146009f6,
2664 log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002665 }
2666
2667 return skip;
2668}
2669
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002670bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2671 bool skip = false;
2672 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2673
2674 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002675 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2676 if (present_regions) {
2677 // TODO: This and all other pNext extension dependencies should be added to code-generation
2678 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2679 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2680 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2681 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2682 __LINE__, INVALID_USAGE, LayerName,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002683 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i but VkPresentRegionsKHR "
2684 "extension swapchainCount is %i. These values must be equal.",
John Zulaufde972ac2017-10-26 12:07:05 -06002685 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2686 }
2687 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2688 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2689 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2690 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2691 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2692 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2693 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002694 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2695 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2696 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002697 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002698 }
2699 }
2700
2701 return skip;
2702}
2703
2704#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002705bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2706 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2707 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2708 bool skip = false;
2709
2710 if (pCreateInfo->hwnd == nullptr) {
2711 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2712 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2713 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2714 validation_error_map[VALIDATION_ERROR_15a00a38]);
2715 }
2716
2717 return skip;
2718}
2719#endif // VK_USE_PLATFORM_WIN32_KHR
2720
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002721bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2722 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2723 if (pNameInfo->pObjectName) {
2724 device_data->report_data->debugObjectNameMap->insert(
2725 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2726 } else {
2727 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2728 }
2729 return false;
2730}
2731
Petr Krausc8655be2017-09-27 18:56:51 +02002732bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2733 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2734 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2735 bool skip = false;
2736
2737 if (pCreateInfo) {
2738 if (pCreateInfo->maxSets <= 0) {
2739 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2740 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2741 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2742 validation_error_map[VALIDATION_ERROR_0480025a]);
2743 }
2744
2745 if (pCreateInfo->pPoolSizes) {
2746 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2747 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2748 skip |= log_msg(
2749 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2750 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2751 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2752 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2753 }
2754 }
2755 }
2756 }
2757
2758 return skip;
2759}
2760
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002761bool pv_vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2762 bool skip = false;
2763 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2764
2765 if (groupCountX > device_data->device_limits.maxComputeWorkGroupCount[0]) {
2766 skip |= log_msg(
2767 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2768 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00304, LayerName,
2769 "vkCmdDispatch(): groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2770 groupCountX, device_data->device_limits.maxComputeWorkGroupCount[0], validation_error_map[VALIDATION_ERROR_19c00304]);
2771 }
2772
2773 if (groupCountY > device_data->device_limits.maxComputeWorkGroupCount[1]) {
2774 skip |= log_msg(
2775 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2776 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00306, LayerName,
2777 "vkCmdDispatch(): groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2778 groupCountY, device_data->device_limits.maxComputeWorkGroupCount[1], validation_error_map[VALIDATION_ERROR_19c00306]);
2779 }
2780
2781 if (groupCountZ > device_data->device_limits.maxComputeWorkGroupCount[2]) {
2782 skip |= log_msg(
2783 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2784 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00308, LayerName,
2785 "vkCmdDispatch(): groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2786 groupCountZ, device_data->device_limits.maxComputeWorkGroupCount[2], validation_error_map[VALIDATION_ERROR_19c00308]);
2787 }
2788
2789 return skip;
2790}
2791
2792bool pv_vkCmdDispatchBaseKHX(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
2793 uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2794 bool skip = false;
2795 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2796
2797 // Paired if {} else if {} tests used to avoid any possible uint underflow
2798 uint32_t limit = device_data->device_limits.maxComputeWorkGroupCount[0];
2799 if (baseGroupX >= limit) {
2800 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2801 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034a, LayerName,
2802 "vkCmdDispatch(): baseGroupX (%" PRIu32
2803 ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2804 baseGroupX, limit, validation_error_map[VALIDATION_ERROR_19e0034a]);
2805 } else if (groupCountX > (limit - baseGroupX)) {
2806 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2807 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00350, LayerName,
2808 "vkCmdDispatchBaseKHX(): baseGroupX (%" PRIu32 ") + groupCountX (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002809 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002810 baseGroupX, groupCountX, limit, validation_error_map[VALIDATION_ERROR_19e00350]);
2811 }
2812
2813 limit = device_data->device_limits.maxComputeWorkGroupCount[1];
2814 if (baseGroupY >= limit) {
2815 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2816 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034c, LayerName,
2817 "vkCmdDispatch(): baseGroupY (%" PRIu32
2818 ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2819 baseGroupY, limit, validation_error_map[VALIDATION_ERROR_19e0034c]);
2820 } else if (groupCountY > (limit - baseGroupY)) {
2821 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2822 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00352, LayerName,
2823 "vkCmdDispatchBaseKHX(): baseGroupY (%" PRIu32 ") + groupCountY (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002824 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002825 baseGroupY, groupCountY, limit, validation_error_map[VALIDATION_ERROR_19e00352]);
2826 }
2827
2828 limit = device_data->device_limits.maxComputeWorkGroupCount[2];
2829 if (baseGroupZ >= limit) {
2830 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2831 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034e, LayerName,
2832 "vkCmdDispatch(): baseGroupZ (%" PRIu32
2833 ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2834 baseGroupZ, limit, validation_error_map[VALIDATION_ERROR_19e0034e]);
2835 } else if (groupCountZ > (limit - baseGroupZ)) {
2836 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2837 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00354, LayerName,
2838 "vkCmdDispatchBaseKHX(): baseGroupZ (%" PRIu32 ") + groupCountZ (%" PRIu32
Dave Houltona9df0ce2018-02-07 10:51:23 -07002839 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002840 baseGroupZ, groupCountZ, limit, validation_error_map[VALIDATION_ERROR_19e00354]);
2841 }
2842
2843 return skip;
2844}
2845
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002846VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2847 const auto item = name_to_funcptr_map.find(funcName);
2848 if (item != name_to_funcptr_map.end()) {
2849 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2850 }
2851
2852 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2853 const auto &table = device_data->dispatch_table;
2854 if (!table.GetDeviceProcAddr) return nullptr;
2855 return table.GetDeviceProcAddr(device, funcName);
2856}
2857
2858VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2859 const auto item = name_to_funcptr_map.find(funcName);
2860 if (item != name_to_funcptr_map.end()) {
2861 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2862 }
2863
2864 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2865 auto &table = instance_data->dispatch_table;
2866 if (!table.GetInstanceProcAddr) return nullptr;
2867 return table.GetInstanceProcAddr(instance, funcName);
2868}
2869
2870VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2871 assert(instance);
2872 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2873
2874 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2875 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2876}
2877
2878// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2879// 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 +02002880void InitializeManualParameterValidationFunctionPointers() {
Dave Houltonb3bbec72018-01-17 10:13:33 -07002881 custom_functions["vkGetDeviceQueue"] = (void *)pv_vkGetDeviceQueue;
2882 custom_functions["vkCreateBuffer"] = (void *)pv_vkCreateBuffer;
2883 custom_functions["vkCreateImage"] = (void *)pv_vkCreateImage;
2884 custom_functions["vkCreateImageView"] = (void *)pv_vkCreateImageView;
2885 custom_functions["vkCreateGraphicsPipelines"] = (void *)pv_vkCreateGraphicsPipelines;
2886 custom_functions["vkCreateComputePipelines"] = (void *)pv_vkCreateComputePipelines;
2887 custom_functions["vkCreateSampler"] = (void *)pv_vkCreateSampler;
2888 custom_functions["vkCreateDescriptorSetLayout"] = (void *)pv_vkCreateDescriptorSetLayout;
2889 custom_functions["vkFreeDescriptorSets"] = (void *)pv_vkFreeDescriptorSets;
2890 custom_functions["vkUpdateDescriptorSets"] = (void *)pv_vkUpdateDescriptorSets;
2891 custom_functions["vkCreateRenderPass"] = (void *)pv_vkCreateRenderPass;
2892 custom_functions["vkBeginCommandBuffer"] = (void *)pv_vkBeginCommandBuffer;
2893 custom_functions["vkCmdSetViewport"] = (void *)pv_vkCmdSetViewport;
2894 custom_functions["vkCmdSetScissor"] = (void *)pv_vkCmdSetScissor;
Petr Kraus299ba622017-11-24 03:09:03 +01002895 custom_functions["vkCmdSetLineWidth"] = (void *)pv_vkCmdSetLineWidth;
Dave Houltonb3bbec72018-01-17 10:13:33 -07002896 custom_functions["vkCmdDraw"] = (void *)pv_vkCmdDraw;
2897 custom_functions["vkCmdDrawIndirect"] = (void *)pv_vkCmdDrawIndirect;
2898 custom_functions["vkCmdDrawIndexedIndirect"] = (void *)pv_vkCmdDrawIndexedIndirect;
2899 custom_functions["vkCmdCopyImage"] = (void *)pv_vkCmdCopyImage;
2900 custom_functions["vkCmdBlitImage"] = (void *)pv_vkCmdBlitImage;
2901 custom_functions["vkCmdCopyBufferToImage"] = (void *)pv_vkCmdCopyBufferToImage;
2902 custom_functions["vkCmdCopyImageToBuffer"] = (void *)pv_vkCmdCopyImageToBuffer;
2903 custom_functions["vkCmdUpdateBuffer"] = (void *)pv_vkCmdUpdateBuffer;
2904 custom_functions["vkCmdFillBuffer"] = (void *)pv_vkCmdFillBuffer;
2905 custom_functions["vkCreateSwapchainKHR"] = (void *)pv_vkCreateSwapchainKHR;
2906 custom_functions["vkQueuePresentKHR"] = (void *)pv_vkQueuePresentKHR;
2907 custom_functions["vkCreateDescriptorPool"] = (void *)pv_vkCreateDescriptorPool;
2908 custom_functions["vkCmdDispatch"] = (void *)pv_vkCmdDispatch;
2909 custom_functions["vkCmdDispatchBaseKHX"] = (void *)pv_vkCmdDispatchBaseKHX;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002910}
2911
2912} // namespace parameter_validation
2913
2914VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2915 VkExtensionProperties *pProperties) {
2916 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
2917}
2918
2919VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
2920 VkLayerProperties *pProperties) {
2921 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
2922}
2923
2924VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2925 VkLayerProperties *pProperties) {
2926 // the layer command handles VK_NULL_HANDLE just fine internally
2927 assert(physicalDevice == VK_NULL_HANDLE);
2928 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
2929}
2930
2931VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
2932 const char *pLayerName, uint32_t *pCount,
2933 VkExtensionProperties *pProperties) {
2934 // the layer command handles VK_NULL_HANDLE just fine internally
2935 assert(physicalDevice == VK_NULL_HANDLE);
2936 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
2937}
2938
2939VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
2940 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
2941}
2942
2943VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2944 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
2945}
2946
2947VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
2948 const char *funcName) {
2949 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
2950}
2951
2952VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
2953 assert(pVersionStruct != NULL);
2954 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
2955
2956 // Fill in the function pointers if our version is at least capable of having the structure contain them.
2957 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
2958 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
2959 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
2960 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
2961 }
2962
2963 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2964 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
2965 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2966 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
2967 }
2968
2969 return VK_SUCCESS;
2970}