blob: ae4aea25f970f1e7cdfcbf15405d50fea1a34f00 [file] [log] [blame]
Jeff Bolz7e7e6e02019-01-11 22:53:41 -06001/* Copyright (c) 2015-2019 The Khronos Group Inc.
2 * Copyright (c) 2015-2019 Valve Corporation
3 * Copyright (c) 2015-2019 LunarG, Inc.
4 * Copyright (C) 2015-2019 Google Inc.
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -07005 *
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: Dustin Graves <dustin@lunarg.com>
19 * Author: Mark Lobodzinski <mark@lunarg.com>
20 */
21
22#pragma once
23
24#include <bitset>
25
26#include "parameter_name.h"
27#include "vk_typemap_helper.h"
28
29// Suppress unused warning on Linux
30#if defined(__GNUC__)
31#define DECORATE_UNUSED __attribute__((unused))
32#else
33#define DECORATE_UNUSED
34#endif
35
36static const char DECORATE_UNUSED *kVUID_PVError_NONE = "UNASSIGNED-GeneralParameterError-Info";
37static const char DECORATE_UNUSED *kVUID_PVError_InvalidUsage = "UNASSIGNED-GeneralParameterError-InvalidUsage";
38static const char DECORATE_UNUSED *kVUID_PVError_InvalidStructSType = "UNASSIGNED-GeneralParameterError-InvalidStructSType";
39static const char DECORATE_UNUSED *kVUID_PVError_InvalidStructPNext = "UNASSIGNED-GeneralParameterError-InvalidStructPNext";
40static const char DECORATE_UNUSED *kVUID_PVError_RequiredParameter = "UNASSIGNED-GeneralParameterError-RequiredParameter";
41static const char DECORATE_UNUSED *kVUID_PVError_ReservedParameter = "UNASSIGNED-GeneralParameterError-ReservedParameter";
42static const char DECORATE_UNUSED *kVUID_PVError_UnrecognizedValue = "UNASSIGNED-GeneralParameterError-UnrecognizedValue";
43static const char DECORATE_UNUSED *kVUID_PVError_DeviceLimit = "UNASSIGNED-GeneralParameterError-DeviceLimit";
44static const char DECORATE_UNUSED *kVUID_PVError_DeviceFeature = "UNASSIGNED-GeneralParameterError-DeviceFeature";
45static const char DECORATE_UNUSED *kVUID_PVError_FailureCode = "UNASSIGNED-GeneralParameterError-FailureCode";
46static const char DECORATE_UNUSED *kVUID_PVError_ExtensionNotEnabled = "UNASSIGNED-GeneralParameterError-ExtensionNotEnabled";
47
48#undef DECORATE_UNUSED
49
50extern const uint32_t GeneratedVulkanHeaderVersion;
51
52extern const VkQueryPipelineStatisticFlags AllVkQueryPipelineStatisticFlagBits;
53extern const VkColorComponentFlags AllVkColorComponentFlagBits;
54extern const VkShaderStageFlags AllVkShaderStageFlagBits;
55extern const VkQueryControlFlags AllVkQueryControlFlagBits;
56extern const VkImageUsageFlags AllVkImageUsageFlagBits;
57
58extern const std::vector<VkCompareOp> AllVkCompareOpEnums;
59extern const std::vector<VkStencilOp> AllVkStencilOpEnums;
60extern const std::vector<VkBlendFactor> AllVkBlendFactorEnums;
61extern const std::vector<VkBlendOp> AllVkBlendOpEnums;
62extern const std::vector<VkLogicOp> AllVkLogicOpEnums;
63extern const std::vector<VkBorderColor> AllVkBorderColorEnums;
64extern const std::vector<VkImageLayout> AllVkImageLayoutEnums;
65
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -070066// String returned by string_VkStructureType for an unrecognized type.
67const std::string UnsupportedStructureTypeString = "Unhandled VkStructureType";
68
69// String returned by string_VkResult for an unrecognized type.
70const std::string UnsupportedResultString = "Unhandled VkResult";
71
72// The base value used when computing the offset for an enumeration token value that is added by an extension.
73// When validating enumeration tokens, any value >= to this value is considered to be provided by an extension.
74// See Appendix C.10 "Assigning Extension Token Values" from the Vulkan specification
75const uint32_t ExtEnumBaseValue = 1000000000;
76
77// The value of all VK_xxx_MAX_ENUM tokens
78const uint32_t MaxEnumValue = 0x7FFFFFFF;
79
80// Misc parameters of log_msg that are likely constant per command (or low frequency change)
81struct LogMiscParams {
82 VkDebugReportObjectTypeEXT objectType;
83 uint64_t srcObject;
84 const char *api_name;
85};
86
87class StatelessValidation : public ValidationObject {
88 public:
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -070089 VkPhysicalDeviceLimits device_limits = {};
90 VkPhysicalDeviceFeatures physical_device_features = {};
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -070091
Mark Lobodzinskif27a6bc2019-02-04 13:00:49 -070092 // Override chassis read/write locks for this validation object
93 // This override takes a deferred lock. i.e. it is not acquired.
94 std::unique_lock<std::mutex> write_lock() { return std::unique_lock<std::mutex>(validation_object_mutex, std::defer_lock); }
95
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -070096 // Device extension properties -- storing properties gathered from VkPhysicalDeviceProperties2KHR::pNext chain
97 struct DeviceExtensionProperties {
98 VkPhysicalDeviceShadingRateImagePropertiesNV shading_rate_image_props;
99 VkPhysicalDeviceMeshShaderPropertiesNV mesh_shader_props;
100 };
101 DeviceExtensionProperties phys_dev_ext_props = {};
102
103 struct SubpassesUsageStates {
104 std::unordered_set<uint32_t> subpasses_using_color_attachment;
105 std::unordered_set<uint32_t> subpasses_using_depthstencil_attachment;
106 };
107
Mark Lobodzinskif27a6bc2019-02-04 13:00:49 -0700108 // Though this validation object is predominantly statless, the Framebuffer checks are greatly simplified by creating and
109 // updating a map of the renderpass usage states, and these accesses need thread protection. Use a mutex separate from the
110 // parent object's to maintain that functionality.
111 std::mutex renderpass_map_mutex;
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700112 std::unordered_map<VkRenderPass, SubpassesUsageStates> renderpasses_states;
113
114 // Constructor for stateles validation tracking
115 // StatelessValidation() : {}
116 /**
117 * Validate a minimum value.
118 *
119 * Verify that the specified value is greater than the specified lower bound.
120 *
121 * @param api_name Name of API call being validated.
122 * @param parameter_name Name of parameter being validated.
123 * @param value Value to validate.
124 * @param lower_bound Lower bound value to use for validation.
125 * @return Boolean value indicating that the call should be skipped.
126 */
127 template <typename T>
128 bool ValidateGreaterThan(const T value, const T lower_bound, const ParameterName &parameter_name, const std::string &vuid,
129 const LogMiscParams &misc) {
130 bool skip_call = false;
131
132 if (value <= lower_bound) {
133 std::ostringstream ss;
134 ss << misc.api_name << ": parameter " << parameter_name.get_name() << " (= " << value << ") is greater than "
135 << lower_bound;
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700136 skip_call |=
137 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, misc.objectType, misc.srcObject, vuid, "%s", ss.str().c_str());
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700138 }
139
140 return skip_call;
141 }
142
143 template <typename T>
144 bool ValidateGreaterThanZero(const T value, const ParameterName &parameter_name, const std::string &vuid,
145 const LogMiscParams &misc) {
146 return ValidateGreaterThan(value, T{0}, parameter_name, vuid, misc);
147 }
148 /**
149 * Validate a required pointer.
150 *
151 * Verify that a required pointer is not NULL.
152 *
153 * @param apiName Name of API call being validated.
154 * @param parameterName Name of parameter being validated.
155 * @param value Pointer to validate.
156 * @return Boolean value indicating that the call should be skipped.
157 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700158 bool validate_required_pointer(const char *apiName, const ParameterName &parameterName, const void *value,
159 const std::string &vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700160 bool skip_call = false;
161
162 if (value == NULL) {
163 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
164 "%s: required parameter %s specified as NULL.", apiName, parameterName.get_name().c_str());
165 }
166
167 return skip_call;
168 }
169
170 /**
171 * Validate array count and pointer to array.
172 *
173 * Verify that required count and array parameters are not 0 or NULL. If the
174 * count parameter is not optional, verify that it is not 0. If the array
175 * parameter is NULL, and it is not optional, verify that count is 0.
176 *
177 * @param apiName Name of API call being validated.
178 * @param countName Name of count parameter.
179 * @param arrayName Name of array parameter.
180 * @param count Number of elements in the array.
181 * @param array Array to validate.
182 * @param countRequired The 'count' parameter may not be 0 when true.
183 * @param arrayRequired The 'array' parameter may not be NULL when true.
184 * @return Boolean value indicating that the call should be skipped.
185 */
186 template <typename T1, typename T2>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700187 bool validate_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName, T1 count,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600188 const T2 *array, bool countRequired, bool arrayRequired, const char *count_required_vuid,
189 const char *array_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700190 bool skip_call = false;
191
192 // Count parameters not tagged as optional cannot be 0
193 if (countRequired && (count == 0)) {
194 skip_call |=
195 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, count_required_vuid,
196 "%s: parameter %s must be greater than 0.", apiName, countName.get_name().c_str());
197 }
198
199 // Array parameters not tagged as optional cannot be NULL, unless the count is 0
200 if (arrayRequired && (count != 0) && (*array == NULL)) {
201 skip_call |=
202 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, array_required_vuid,
203 "%s: required parameter %s specified as NULL.", apiName, arrayName.get_name().c_str());
204 }
205
206 return skip_call;
207 }
208
209 /**
210 * Validate pointer to array count and pointer to array.
211 *
212 * Verify that required count and array parameters are not NULL. If count
213 * is not NULL and its value is not optional, verify that it is not 0. If the
214 * array parameter is NULL, and it is not optional, verify that count is 0.
215 * The array parameter will typically be optional for this case (where count is
216 * a pointer), allowing the caller to retrieve the available count.
217 *
218 * @param apiName Name of API call being validated.
219 * @param countName Name of count parameter.
220 * @param arrayName Name of array parameter.
221 * @param count Pointer to the number of elements in the array.
222 * @param array Array to validate.
223 * @param countPtrRequired The 'count' parameter may not be NULL when true.
224 * @param countValueRequired The '*count' value may not be 0 when true.
225 * @param arrayRequired The 'array' parameter may not be NULL when true.
226 * @return Boolean value indicating that the call should be skipped.
227 */
228 template <typename T1, typename T2>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700229 bool validate_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName, const T1 *count,
230 const T2 *array, bool countPtrRequired, bool countValueRequired, bool arrayRequired,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600231 const char *count_required_vuid, const char *array_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700232 bool skip_call = false;
233
234 if (count == NULL) {
235 if (countPtrRequired) {
236 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
237 kVUID_PVError_RequiredParameter, "%s: required parameter %s specified as NULL", apiName,
238 countName.get_name().c_str());
239 }
240 } else {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700241 skip_call |= validate_array(apiName, countName, arrayName, *array ? (*count) : 0, &array, countValueRequired,
242 arrayRequired, count_required_vuid, array_required_vuid);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700243 }
244
245 return skip_call;
246 }
247
248 /**
249 * Validate a pointer to a Vulkan structure.
250 *
251 * Verify that a required pointer to a structure is not NULL. If the pointer is
252 * not NULL, verify that each structure's sType field is set to the correct
253 * VkStructureType value.
254 *
255 * @param apiName Name of API call being validated.
256 * @param parameterName Name of struct parameter being validated.
257 * @param sTypeName Name of expected VkStructureType value.
258 * @param value Pointer to the struct to validate.
259 * @param sType VkStructureType for structure validation.
260 * @param required The parameter may not be NULL when true.
261 * @return Boolean value indicating that the call should be skipped.
262 */
263 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700264 bool validate_struct_type(const char *apiName, const ParameterName &parameterName, const char *sTypeName, const T *value,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600265 VkStructureType sType, bool required, const char *struct_vuid, const char *stype_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700266 bool skip_call = false;
267
268 if (value == NULL) {
269 if (required) {
270 skip_call |=
271 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, struct_vuid,
272 "%s: required parameter %s specified as NULL", apiName, parameterName.get_name().c_str());
273 }
274 } else if (value->sType != sType) {
275 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, stype_vuid,
276 "%s: parameter %s->sType must be %s.", apiName, parameterName.get_name().c_str(), sTypeName);
277 }
278
279 return skip_call;
280 }
281
282 /**
283 * Validate an array of Vulkan structures
284 *
285 * Verify that required count and array parameters are not 0 or NULL. If
286 * the array contains 1 or more structures, verify that each structure's
287 * sType field is set to the correct VkStructureType value.
288 *
289 * @param apiName Name of API call being validated.
290 * @param countName Name of count parameter.
291 * @param arrayName Name of array parameter.
292 * @param sTypeName Name of expected VkStructureType value.
293 * @param count Number of elements in the array.
294 * @param array Array to validate.
295 * @param sType VkStructureType for structure validation.
296 * @param countRequired The 'count' parameter may not be 0 when true.
297 * @param arrayRequired The 'array' parameter may not be NULL when true.
298 * @return Boolean value indicating that the call should be skipped.
299 */
300 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700301 bool validate_struct_type_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName,
302 const char *sTypeName, uint32_t count, const T *array, VkStructureType sType,
Jasper St. Pierre6c98f8c2019-01-22 15:18:03 -0800303 bool countRequired, bool arrayRequired, const char *stype_vuid, const char *param_vuid,
304 const char *count_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700305 bool skip_call = false;
306
307 if ((count == 0) || (array == NULL)) {
Jasper St. Pierre6c98f8c2019-01-22 15:18:03 -0800308 skip_call |= validate_array(apiName, countName, arrayName, count, &array, countRequired, arrayRequired,
309 count_required_vuid, param_vuid);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700310 } else {
311 // Verify that all structs in the array have the correct type
312 for (uint32_t i = 0; i < count; ++i) {
313 if (array[i].sType != sType) {
314 skip_call |=
315 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, stype_vuid,
316 "%s: parameter %s[%d].sType must be %s", apiName, arrayName.get_name().c_str(), i, sTypeName);
317 }
318 }
319 }
320
321 return skip_call;
322 }
323
324 /**
325 * Validate an array of Vulkan structures.
326 *
327 * Verify that required count and array parameters are not NULL. If count
328 * is not NULL and its value is not optional, verify that it is not 0.
329 * If the array contains 1 or more structures, verify that each structure's
330 * sType field is set to the correct VkStructureType value.
331 *
332 * @param apiName Name of API call being validated.
333 * @param countName Name of count parameter.
334 * @param arrayName Name of array parameter.
335 * @param sTypeName Name of expected VkStructureType value.
336 * @param count Pointer to the number of elements in the array.
337 * @param array Array to validate.
338 * @param sType VkStructureType for structure validation.
339 * @param countPtrRequired The 'count' parameter may not be NULL when true.
340 * @param countValueRequired The '*count' value may not be 0 when true.
341 * @param arrayRequired The 'array' parameter may not be NULL when true.
342 * @return Boolean value indicating that the call should be skipped.
343 */
344 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700345 bool validate_struct_type_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName,
346 const char *sTypeName, uint32_t *count, const T *array, VkStructureType sType,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600347 bool countPtrRequired, bool countValueRequired, bool arrayRequired, const char *stype_vuid,
Jasper St. Pierre6c98f8c2019-01-22 15:18:03 -0800348 const char *param_vuid, const char *count_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700349 bool skip_call = false;
350
351 if (count == NULL) {
352 if (countPtrRequired) {
353 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
354 kVUID_PVError_RequiredParameter, "%s: required parameter %s specified as NULL", apiName,
355 countName.get_name().c_str());
356 }
357 } else {
358 skip_call |= validate_struct_type_array(apiName, countName, arrayName, sTypeName, (*count), array, sType,
Jasper St. Pierre6c98f8c2019-01-22 15:18:03 -0800359 countValueRequired, arrayRequired, stype_vuid, param_vuid, count_required_vuid);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700360 }
361
362 return skip_call;
363 }
364
365 /**
366 * Validate a Vulkan handle.
367 *
368 * Verify that the specified handle is not VK_NULL_HANDLE.
369 *
370 * @param api_name Name of API call being validated.
371 * @param parameter_name Name of struct parameter being validated.
372 * @param value Handle to validate.
373 * @return Boolean value indicating that the call should be skipped.
374 */
375 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700376 bool validate_required_handle(const char *api_name, const ParameterName &parameter_name, T value) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700377 bool skip_call = false;
378
379 if (value == VK_NULL_HANDLE) {
380 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
381 kVUID_PVError_RequiredParameter, "%s: required parameter %s specified as VK_NULL_HANDLE", api_name,
382 parameter_name.get_name().c_str());
383 }
384
385 return skip_call;
386 }
387
388 /**
389 * Validate an array of Vulkan handles.
390 *
391 * Verify that required count and array parameters are not NULL. If count
392 * is not NULL and its value is not optional, verify that it is not 0.
393 * If the array contains 1 or more handles, verify that no handle is set to
394 * VK_NULL_HANDLE.
395 *
396 * @note This function is only intended to validate arrays of handles when none
397 * of the handles are allowed to be VK_NULL_HANDLE. For arrays of handles
398 * that are allowed to contain VK_NULL_HANDLE, use validate_array() instead.
399 *
400 * @param api_name Name of API call being validated.
401 * @param count_name Name of count parameter.
402 * @param array_name Name of array parameter.
403 * @param count Number of elements in the array.
404 * @param array Array to validate.
405 * @param count_required The 'count' parameter may not be 0 when true.
406 * @param array_required The 'array' parameter may not be NULL when true.
407 * @return Boolean value indicating that the call should be skipped.
408 */
409 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700410 bool validate_handle_array(const char *api_name, const ParameterName &count_name, const ParameterName &array_name,
411 uint32_t count, const T *array, bool count_required, bool array_required) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700412 bool skip_call = false;
413
414 if ((count == 0) || (array == NULL)) {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700415 skip_call |= validate_array(api_name, count_name, array_name, count, &array, count_required, array_required,
416 kVUIDUndefined, kVUIDUndefined);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700417 } else {
418 // Verify that no handles in the array are VK_NULL_HANDLE
419 for (uint32_t i = 0; i < count; ++i) {
420 if (array[i] == VK_NULL_HANDLE) {
421 skip_call |=
422 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
423 kVUID_PVError_RequiredParameter, "%s: required parameter %s[%d] specified as VK_NULL_HANDLE",
424 api_name, array_name.get_name().c_str(), i);
425 }
426 }
427 }
428
429 return skip_call;
430 }
431
432 /**
433 * Validate string array count and content.
434 *
435 * Verify that required count and array parameters are not 0 or NULL. If the
436 * count parameter is not optional, verify that it is not 0. If the array
437 * parameter is NULL, and it is not optional, verify that count is 0. If the
438 * array parameter is not NULL, verify that none of the strings are NULL.
439 *
440 * @param apiName Name of API call being validated.
441 * @param countName Name of count parameter.
442 * @param arrayName Name of array parameter.
443 * @param count Number of strings in the array.
444 * @param array Array of strings to validate.
445 * @param countRequired The 'count' parameter may not be 0 when true.
446 * @param arrayRequired The 'array' parameter may not be NULL when true.
447 * @return Boolean value indicating that the call should be skipped.
448 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700449 bool validate_string_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName, uint32_t count,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600450 const char *const *array, bool countRequired, bool arrayRequired, const char *count_required_vuid,
451 const char *array_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700452 bool skip_call = false;
453
454 if ((count == 0) || (array == NULL)) {
455 skip_call |= validate_array(apiName, countName, arrayName, count, &array, countRequired, arrayRequired,
456 count_required_vuid, array_required_vuid);
457 } else {
458 // Verify that strings in the array are not NULL
459 for (uint32_t i = 0; i < count; ++i) {
460 if (array[i] == NULL) {
461 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
462 kVUID_PVError_RequiredParameter, "%s: required parameter %s[%d] specified as NULL",
463 apiName, arrayName.get_name().c_str(), i);
464 }
465 }
466 }
467
468 return skip_call;
469 }
470
471 // Forward declaration for pNext validation
Lockefbdd1af2019-04-16 15:07:23 -0600472 bool ValidatePnextStructContents(const char *api_name, const ParameterName &parameter_name, const VkBaseOutStructure *header);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700473
474 /**
475 * Validate a structure's pNext member.
476 *
477 * Verify that the specified pNext value points to the head of a list of
478 * allowed extension structures. If no extension structures are allowed,
479 * verify that pNext is null.
480 *
481 * @param api_name Name of API call being validated.
482 * @param parameter_name Name of parameter being validated.
483 * @param allowed_struct_names Names of allowed structs.
484 * @param next Pointer to validate.
485 * @param allowed_type_count Total number of allowed structure types.
486 * @param allowed_types Array of structure types allowed for pNext.
487 * @param header_version Version of header defining the pNext validation rules.
488 * @return Boolean value indicating that the call should be skipped.
489 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700490 bool validate_struct_pnext(const char *api_name, const ParameterName &parameter_name, const char *allowed_struct_names,
491 const void *next, size_t allowed_type_count, const VkStructureType *allowed_types,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600492 uint32_t header_version, const char *vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700493 bool skip_call = false;
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700494
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700495 // TODO: The valid pNext structure types are not recursive. Each structure has its own list of valid sTypes for pNext.
496 // Codegen a map of vectors containing the allowable pNext types for each struct and use that here -- also simplifies parms.
497 if (next != NULL) {
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600498 std::unordered_set<const void *> cycle_check;
499 std::unordered_set<VkStructureType, std::hash<int>> unique_stype_check;
500
Jeff Bolz6d3beaa2019-02-09 21:00:05 -0600501 const char *disclaimer =
502 "This warning is based on the Valid Usage documentation for version %d of the Vulkan header. It is possible that "
503 "you "
504 "are "
505 "using a struct from a private extension or an extension that was added to a later version of the Vulkan header, "
506 "in "
507 "which "
508 "case your use of %s is perfectly valid but is not guaranteed to work correctly with validation enabled";
509
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700510 if (allowed_type_count == 0) {
511 std::string message = "%s: value of %s must be NULL. ";
512 message += disclaimer;
513 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
514 message.c_str(), api_name, parameter_name.get_name().c_str(), header_version,
515 parameter_name.get_name().c_str());
516 } else {
517 const VkStructureType *start = allowed_types;
518 const VkStructureType *end = allowed_types + allowed_type_count;
Lockefbdd1af2019-04-16 15:07:23 -0600519 const VkBaseOutStructure *current = reinterpret_cast<const VkBaseOutStructure *>(next);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700520
521 cycle_check.insert(next);
522
523 while (current != NULL) {
524 if (((strncmp(api_name, "vkCreateInstance", strlen(api_name)) != 0) ||
525 (current->sType != VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO)) &&
526 ((strncmp(api_name, "vkCreateDevice", strlen(api_name)) != 0) ||
527 (current->sType != VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO))) {
528 if (cycle_check.find(current->pNext) != cycle_check.end()) {
529 std::string message = "%s: %s chain contains a cycle -- pNext pointer " PRIx64 " is repeated.";
530 skip_call |=
531 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
532 kVUID_PVError_InvalidStructPNext, message.c_str(), api_name,
533 parameter_name.get_name().c_str(), reinterpret_cast<uint64_t>(next));
534 break;
535 } else {
536 cycle_check.insert(current->pNext);
537 }
538
539 std::string type_name = string_VkStructureType(current->sType);
540 if (unique_stype_check.find(current->sType) != unique_stype_check.end()) {
541 std::string message = "%s: %s chain contains duplicate structure types: %s appears multiple times.";
542 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
543 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, kVUID_PVError_InvalidStructPNext,
544 message.c_str(), api_name, parameter_name.get_name().c_str(), type_name.c_str());
545 } else {
546 unique_stype_check.insert(current->sType);
547 }
548
549 if (std::find(start, end, current->sType) == end) {
550 if (type_name == UnsupportedStructureTypeString) {
551 std::string message =
552 "%s: %s chain includes a structure with unknown VkStructureType (%d); Allowed structures are "
553 "[%s]. ";
554 message += disclaimer;
555 skip_call |=
556 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
557 0, vuid, message.c_str(), api_name, parameter_name.get_name().c_str(), current->sType,
558 allowed_struct_names, header_version, parameter_name.get_name().c_str());
559 } else {
560 std::string message =
561 "%s: %s chain includes a structure with unexpected VkStructureType %s; Allowed structures are "
562 "[%s]. ";
563 message += disclaimer;
564 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
565 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, message.c_str(), api_name,
566 parameter_name.get_name().c_str(), type_name.c_str(), allowed_struct_names,
567 header_version, parameter_name.get_name().c_str());
568 }
569 }
570 skip_call |= ValidatePnextStructContents(api_name, parameter_name, current);
571 }
Lockefbdd1af2019-04-16 15:07:23 -0600572 current = reinterpret_cast<const VkBaseOutStructure *>(current->pNext);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700573 }
574 }
575 }
576
577 return skip_call;
578 }
579
580 /**
581 * Validate a VkBool32 value.
582 *
583 * Generate a warning if a VkBool32 value is neither VK_TRUE nor VK_FALSE.
584 *
585 * @param apiName Name of API call being validated.
586 * @param parameterName Name of parameter being validated.
587 * @param value Boolean value to validate.
588 * @return Boolean value indicating that the call should be skipped.
589 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700590 bool validate_bool32(const char *apiName, const ParameterName &parameterName, VkBool32 value) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700591 bool skip_call = false;
592
593 if ((value != VK_TRUE) && (value != VK_FALSE)) {
594 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
595 kVUID_PVError_UnrecognizedValue, "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName,
596 parameterName.get_name().c_str(), value);
597 }
598
599 return skip_call;
600 }
601
602 /**
603 * Validate a Vulkan enumeration value.
604 *
605 * Generate a warning if an enumeration token value does not fall within the core enumeration
606 * begin and end token values, and was not added to the enumeration by an extension. Extension
607 * provided enumerations use the equation specified in Appendix C.10 of the Vulkan specification,
608 * with 1,000,000,000 as the base token value.
609 *
610 * @note This function does not expect to process enumerations defining bitmask flag bits.
611 *
612 * @param apiName Name of API call being validated.
613 * @param parameterName Name of parameter being validated.
614 * @param enumName Name of the enumeration being validated.
615 * @param valid_values The list of valid values for the enumeration.
616 * @param value Enumeration value to validate.
617 * @return Boolean value indicating that the call should be skipped.
618 */
619 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700620 bool validate_ranged_enum(const char *apiName, const ParameterName &parameterName, const char *enumName,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600621 const std::vector<T> &valid_values, T value, const char *vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700622 bool skip = false;
623
624 if (std::find(valid_values.begin(), valid_values.end(), value) == valid_values.end()) {
625 skip |=
626 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
627 "%s: value of %s (%d) does not fall within the begin..end range of the core %s enumeration tokens and is "
628 "not an extension added token.",
629 apiName, parameterName.get_name().c_str(), value, enumName);
630 }
631
632 return skip;
633 }
634
635 /**
636 * Validate an array of Vulkan enumeration value.
637 *
638 * Process all enumeration token values in the specified array and generate a warning if a value
639 * does not fall within the core enumeration begin and end token values, and was not added to
640 * the enumeration by an extension. Extension provided enumerations use the equation specified
641 * in Appendix C.10 of the Vulkan specification, with 1,000,000,000 as the base token value.
642 *
643 * @note This function does not expect to process enumerations defining bitmask flag bits.
644 *
645 * @param apiName Name of API call being validated.
646 * @param countName Name of count parameter.
647 * @param arrayName Name of array parameter.
648 * @param enumName Name of the enumeration being validated.
649 * @param valid_values The list of valid values for the enumeration.
650 * @param count Number of enumeration values in the array.
651 * @param array Array of enumeration values to validate.
652 * @param countRequired The 'count' parameter may not be 0 when true.
653 * @param arrayRequired The 'array' parameter may not be NULL when true.
654 * @return Boolean value indicating that the call should be skipped.
655 */
656 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700657 bool validate_ranged_enum_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName,
658 const char *enumName, const std::vector<T> &valid_values, uint32_t count, const T *array,
659 bool countRequired, bool arrayRequired) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700660 bool skip_call = false;
661
662 if ((count == 0) || (array == NULL)) {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700663 skip_call |= validate_array(apiName, countName, arrayName, count, &array, countRequired, arrayRequired, kVUIDUndefined,
664 kVUIDUndefined);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700665 } else {
666 for (uint32_t i = 0; i < count; ++i) {
667 if (std::find(valid_values.begin(), valid_values.end(), array[i]) == valid_values.end()) {
668 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
669 kVUID_PVError_UnrecognizedValue,
670 "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s "
671 "enumeration tokens and is not an extension added token",
672 apiName, arrayName.get_name().c_str(), i, array[i], enumName);
673 }
674 }
675 }
676
677 return skip_call;
678 }
679
680 /**
681 * Verify that a reserved VkFlags value is zero.
682 *
683 * Verify that the specified value is zero, to check VkFlags values that are reserved for
684 * future use.
685 *
686 * @param api_name Name of API call being validated.
687 * @param parameter_name Name of parameter being validated.
688 * @param value Value to validate.
689 * @return Boolean value indicating that the call should be skipped.
690 */
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600691 bool validate_reserved_flags(const char *api_name, const ParameterName &parameter_name, VkFlags value, const char *vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700692 bool skip_call = false;
693
694 if (value != 0) {
695 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
696 "%s: parameter %s must be 0.", api_name, parameter_name.get_name().c_str());
697 }
698
699 return skip_call;
700 }
701
702 /**
703 * Validate a Vulkan bitmask value.
704 *
705 * Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
706 * for that type.
707 *
708 * @param api_name Name of API call being validated.
709 * @param parameter_name Name of parameter being validated.
710 * @param flag_bits_name Name of the VkFlags type being validated.
711 * @param all_flags A bit mask combining all valid flag bits for the VkFlags type being validated.
712 * @param value VkFlags value to validate.
713 * @param flags_required The 'value' parameter may not be 0 when true.
714 * @param singleFlag The 'value' parameter may not contain more than one bit from all_flags.
715 * @return Boolean value indicating that the call should be skipped.
716 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700717 bool validate_flags(const char *api_name, const ParameterName &parameter_name, const char *flag_bits_name, VkFlags all_flags,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600718 VkFlags value, bool flags_required, bool singleFlag, const char *vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700719 bool skip_call = false;
720
721 if (value == 0) {
722 if (flags_required) {
723 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
724 "%s: value of %s must not be 0.", api_name, parameter_name.get_name().c_str());
725 }
726 } else if ((value & (~all_flags)) != 0) {
727 skip_call |=
728 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
729 kVUID_PVError_UnrecognizedValue, "%s: value of %s contains flag bits that are not recognized members of %s",
730 api_name, parameter_name.get_name().c_str(), flag_bits_name);
731 } else if (singleFlag && (std::bitset<sizeof(VkFlags) * 8>(value).count() > 1)) {
732 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
733 kVUID_PVError_UnrecognizedValue,
734 "%s: value of %s contains multiple members of %s when only a single value is allowed", api_name,
735 parameter_name.get_name().c_str(), flag_bits_name);
736 }
737
738 return skip_call;
739 }
740
741 /**
742 * Validate an array of Vulkan bitmask values.
743 *
744 * Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
745 * for that type.
746 *
747 * @param api_name Name of API call being validated.
748 * @param count_name Name of parameter being validated.
749 * @param array_name Name of parameter being validated.
750 * @param flag_bits_name Name of the VkFlags type being validated.
751 * @param all_flags A bitmask combining all valid flag bits for the VkFlags type being validated.
752 * @param count Number of VkFlags values in the array.
753 * @param array Array of VkFlags value to validate.
754 * @param count_required The 'count' parameter may not be 0 when true.
755 * @param array_required The 'array' parameter may not be NULL when true.
756 * @return Boolean value indicating that the call should be skipped.
757 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700758 bool validate_flags_array(const char *api_name, const ParameterName &count_name, const ParameterName &array_name,
759 const char *flag_bits_name, VkFlags all_flags, uint32_t count, const VkFlags *array,
760 bool count_required, bool array_required) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700761 bool skip_call = false;
762
763 if ((count == 0) || (array == NULL)) {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700764 skip_call |= validate_array(api_name, count_name, array_name, count, &array, count_required, array_required,
765 kVUIDUndefined, kVUIDUndefined);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700766 } else {
767 // Verify that all VkFlags values in the array
768 for (uint32_t i = 0; i < count; ++i) {
769 if (array[i] == 0) {
770 // Current XML registry logic for validity generation uses the array parameter's optional tag to determine if
771 // elements in the array are allowed be 0
772 if (array_required) {
773 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
774 kVUID_PVError_RequiredParameter, "%s: value of %s[%d] must not be 0", api_name,
775 array_name.get_name().c_str(), i);
776 }
777 } else if ((array[i] & (~all_flags)) != 0) {
778 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
779 kVUID_PVError_UnrecognizedValue,
780 "%s: value of %s[%d] contains flag bits that are not recognized members of %s", api_name,
781 array_name.get_name().c_str(), i, flag_bits_name);
782 }
783 }
784 }
785
786 return skip_call;
787 }
788
789 template <typename ExtensionState>
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600790 bool validate_extension_reqs(const ExtensionState &extensions, const char *vuid, const char *extension_type,
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700791 const char *extension_name) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700792 bool skip = false;
793 if (!extension_name) {
794 return skip; // Robust to invalid char *
795 }
796 auto info = ExtensionState::get_info(extension_name);
797
798 if (!info.state) {
799 return skip; // Unknown extensions cannot be checked so report OK
800 }
801
802 // Check against the required list in the info
803 std::vector<const char *> missing;
804 for (const auto &req : info.requires) {
805 if (!(extensions.*(req.enabled))) {
806 missing.push_back(req.name);
807 }
808 }
809
810 // Report any missing requirements
811 if (missing.size()) {
812 std::string missing_joined_list = string_join(", ", missing);
813 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700814 HandleToUint64(instance), vuid, "Missing extension%s required by the %s extension %s: %s.",
815 ((missing.size() > 1) ? "s" : ""), extension_type, extension_name, missing_joined_list.c_str());
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700816 }
817 return skip;
818 }
819
820 enum RenderPassCreateVersion { RENDER_PASS_VERSION_1 = 0, RENDER_PASS_VERSION_2 = 1 };
821
822 template <typename RenderPassCreateInfoGeneric>
823 bool CreateRenderPassGeneric(VkDevice device, const RenderPassCreateInfoGeneric *pCreateInfo,
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700824 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
825 RenderPassCreateVersion rp_version) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700826 bool skip = false;
827 uint32_t max_color_attachments = device_limits.maxColorAttachments;
828 bool use_rp2 = (rp_version == RENDER_PASS_VERSION_2);
829 const char *vuid;
830
831 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
832 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
833 std::stringstream ss;
834 ss << (use_rp2 ? "vkCreateRenderPass2KHR" : "vkCreateRenderPass") << ": pCreateInfo->pAttachments[" << i
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700835 << "].format is VK_FORMAT_UNDEFINED. ";
836 vuid =
837 use_rp2 ? "VUID-VkAttachmentDescription2KHR-format-parameter" : "VUID-VkAttachmentDescription-format-parameter";
838 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
839 "%s", ss.str().c_str());
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700840 }
841 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
842 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700843 vuid = use_rp2 ? "VUID-VkAttachmentDescription2KHR-finalLayout-03061"
844 : "VUID-VkAttachmentDescription-finalLayout-00843";
845 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
846 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
847 "VK_IMAGE_LAYOUT_PREINITIALIZED.",
848 i);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700849 }
850 }
851
852 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
853 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
854 vuid = use_rp2 ? "VUID-VkSubpassDescription2KHR-colorAttachmentCount-03063"
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700855 : "VUID-VkSubpassDescription-colorAttachmentCount-00845";
856 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
857 "Cannot create a render pass with %d color attachments. Max is %d.",
858 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700859 }
860 }
861 return skip;
862 }
863
864 template <typename T>
865 void RecordRenderPass(VkRenderPass renderPass, const T *pCreateInfo) {
Mark Lobodzinskif27a6bc2019-02-04 13:00:49 -0700866 std::unique_lock<std::mutex> lock(renderpass_map_mutex);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700867 auto &renderpass_state = renderpasses_states[renderPass];
Mark Lobodzinskif27a6bc2019-02-04 13:00:49 -0700868 lock.unlock();
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700869
870 for (uint32_t subpass = 0; subpass < pCreateInfo->subpassCount; ++subpass) {
871 bool uses_color = false;
872 for (uint32_t i = 0; i < pCreateInfo->pSubpasses[subpass].colorAttachmentCount && !uses_color; ++i)
873 if (pCreateInfo->pSubpasses[subpass].pColorAttachments[i].attachment != VK_ATTACHMENT_UNUSED) uses_color = true;
874
875 bool uses_depthstencil = false;
876 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment)
877 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)
878 uses_depthstencil = true;
879
880 if (uses_color) renderpass_state.subpasses_using_color_attachment.insert(subpass);
881 if (uses_depthstencil) renderpass_state.subpasses_using_depthstencil_attachment.insert(subpass);
882 }
883 }
884
885 bool require_device_extension(bool flag, char const *function_name, char const *extension_name);
886
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700887 bool validate_instance_extensions(const VkInstanceCreateInfo *pCreateInfo);
888
889 bool validate_api_version(uint32_t api_version, uint32_t effective_api_version);
890
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700891 bool validate_string(const char *apiName, const ParameterName &stringName, const std::string &vuid, const char *validateString);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700892
893 bool ValidateCoarseSampleOrderCustomNV(const VkCoarseSampleOrderCustomNV *order);
894
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700895 bool ValidateQueueFamilies(uint32_t queue_family_count, const uint32_t *queue_families, const char *cmd_name,
896 const char *array_parameter_name, const std::string &unique_error_code,
897 const std::string &valid_error_code, bool optional);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700898
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700899 bool ValidateDeviceQueueFamily(uint32_t queue_family, const char *cmd_name, const char *parameter_name,
900 const std::string &error_code, bool optional);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700901
902 bool OutputExtensionError(const std::string &api_name, const std::string &extension_name);
903
904 void PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700905 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, VkResult result);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700906 void PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700907 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, VkResult result);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700908 void PostCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator);
909 void PostCallRecordCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700910 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700911
912 void PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700913 VkInstance *pInstance, VkResult result);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700914
915 bool manual_PreCallValidateCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
916 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool);
917
918 bool manual_PreCallValidateCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
919 VkInstance *pInstance);
920
921 bool manual_PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
922 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
923
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700924 bool manual_PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
925 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer);
926
927 bool manual_PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
928 const VkAllocationCallbacks *pAllocator, VkImage *pImage);
929
930 bool manual_PreCallValidateCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
931 const VkAllocationCallbacks *pAllocator, VkImageView *pView);
932
Jeff Bolz6d3beaa2019-02-09 21:00:05 -0600933 bool manual_PreCallValidateViewport(const VkViewport &viewport, const char *fn_name, const ParameterName &parameter_name,
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700934 VkDebugReportObjectTypeEXT object_type, uint64_t object);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700935
936 bool manual_PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
937 const VkGraphicsPipelineCreateInfo *pCreateInfos,
938 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines);
939 bool manual_PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
940 const VkComputePipelineCreateInfo *pCreateInfos,
941 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines);
942
943 bool manual_PreCallValidateCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
944 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler);
945 bool manual_PreCallValidateCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700946 const VkAllocationCallbacks *pAllocator,
947 VkDescriptorSetLayout *pSetLayout);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700948
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700949 bool manual_PreCallValidateUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
950 const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
951 const VkCopyDescriptorSet *pDescriptorCopies);
952 ;
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700953 bool manual_PreCallValidateFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
954 const VkDescriptorSet *pDescriptorSets);
955
956 bool manual_PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
957 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
958
959 bool manual_PreCallValidateCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo,
960 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
961
962 bool manual_PreCallValidateFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
963 const VkCommandBuffer *pCommandBuffers);
964
965 bool manual_PreCallValidateBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo);
966
967 bool manual_PreCallValidateCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
968 const VkViewport *pViewports);
969
970 bool manual_PreCallValidateCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
971 const VkRect2D *pScissors);
972 bool manual_PreCallValidateCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth);
973
974 bool manual_PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
975 uint32_t firstVertex, uint32_t firstInstance);
976
977 bool manual_PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
978 uint32_t stride);
979
980 bool manual_PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
981 uint32_t count, uint32_t stride);
982
Mark Lobodzinskif77a4ac2019-06-27 15:30:51 -0600983 bool manual_PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
984 const VkClearAttachment *pAttachments, uint32_t rectCount,
985 const VkClearRect *pRects);
986
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700987 bool manual_PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
988 VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount,
989 const VkImageCopy *pRegions);
990
991 bool manual_PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
992 VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount,
993 const VkImageBlit *pRegions, VkFilter filter);
994
995 bool manual_PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
996 VkImageLayout dstImageLayout, uint32_t regionCount,
997 const VkBufferImageCopy *pRegions);
998
999 bool manual_PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
1000 VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions);
1001
1002 bool manual_PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
1003 VkDeviceSize dataSize, const void *pData);
1004
1005 bool manual_PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
1006 VkDeviceSize size, uint32_t data);
1007
1008 bool manual_PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
1009 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain);
1010 bool manual_PreCallValidateQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo);
1011
1012#ifdef VK_USE_PLATFORM_WIN32_KHR
1013 bool manual_PreCallValidateCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
1014 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface);
1015#endif // VK_USE_PLATFORM_WIN32_KHR
1016
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -07001017 bool manual_PreCallValidateCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
1018 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool);
1019 bool manual_PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY,
1020 uint32_t groupCountZ);
1021
1022 bool manual_PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset);
1023
1024 bool manual_PreCallValidateCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY,
1025 uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY,
1026 uint32_t groupCountZ);
1027 bool manual_PreCallValidateCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
1028 uint32_t exclusiveScissorCount, const VkRect2D *pExclusiveScissors);
1029 bool manual_PreCallValidateCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
1030 uint32_t viewportCount,
1031 const VkShadingRatePaletteNV *pShadingRatePalettes);
1032
1033 bool manual_PreCallValidateCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer, VkCoarseSampleOrderTypeNV sampleOrderType,
1034 uint32_t customSampleOrderCount,
1035 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders);
1036
1037 bool manual_PreCallValidateCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, uint32_t firstTask);
1038 bool manual_PreCallValidateCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
1039 uint32_t drawCount, uint32_t stride);
1040
1041 bool manual_PreCallValidateCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
1042 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
1043 uint32_t maxDrawCount, uint32_t stride);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -07001044
1045 bool manual_PreCallValidateEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
1046 uint32_t *pPropertyCount, VkExtensionProperties *pProperties);
Jeff Bolz7e7e6e02019-01-11 22:53:41 -06001047 bool manual_PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1048 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory);
Ricardo Garciaa4935972019-02-21 17:43:18 +01001049
1050 bool manual_PreCallValidateCreateAccelerationStructureNV(VkDevice device,
1051 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
1052 const VkAllocationCallbacks *pAllocator,
1053 VkAccelerationStructureNV *pAccelerationStructure);
Peter Chen85366392019-05-14 15:20:11 -04001054 bool manual_PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1055 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
1056 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines);
Mike Schuchardt21638df2019-03-16 10:52:02 -07001057
1058#ifdef VK_USE_PLATFORM_WIN32_KHR
1059 bool PreCallValidateGetDeviceGroupSurfacePresentModes2EXT(VkDevice device, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
1060 VkDeviceGroupPresentModeFlagsKHR *pModes);
1061#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -07001062#include "parameter_validation.h"
1063}; // Class StatelessValidation