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