blob: 7f0bd5784358cd008ac76c60dfbf97d86ba96124 [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;
Jason Macnak5c954952019-07-09 15:46:12 -0700100 VkPhysicalDeviceRayTracingPropertiesNV ray_tracing_props;
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700101 };
102 DeviceExtensionProperties phys_dev_ext_props = {};
103
104 struct SubpassesUsageStates {
105 std::unordered_set<uint32_t> subpasses_using_color_attachment;
106 std::unordered_set<uint32_t> subpasses_using_depthstencil_attachment;
107 };
108
Mark Lobodzinskif27a6bc2019-02-04 13:00:49 -0700109 // Though this validation object is predominantly statless, the Framebuffer checks are greatly simplified by creating and
110 // updating a map of the renderpass usage states, and these accesses need thread protection. Use a mutex separate from the
111 // parent object's to maintain that functionality.
112 std::mutex renderpass_map_mutex;
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700113 std::unordered_map<VkRenderPass, SubpassesUsageStates> renderpasses_states;
114
115 // Constructor for stateles validation tracking
116 // StatelessValidation() : {}
117 /**
118 * Validate a minimum value.
119 *
120 * Verify that the specified value is greater than the specified lower bound.
121 *
122 * @param api_name Name of API call being validated.
123 * @param parameter_name Name of parameter being validated.
124 * @param value Value to validate.
125 * @param lower_bound Lower bound value to use for validation.
126 * @return Boolean value indicating that the call should be skipped.
127 */
128 template <typename T>
129 bool ValidateGreaterThan(const T value, const T lower_bound, const ParameterName &parameter_name, const std::string &vuid,
130 const LogMiscParams &misc) {
131 bool skip_call = false;
132
133 if (value <= lower_bound) {
134 std::ostringstream ss;
135 ss << misc.api_name << ": parameter " << parameter_name.get_name() << " (= " << value << ") is greater than "
136 << lower_bound;
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700137 skip_call |=
138 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 -0700139 }
140
141 return skip_call;
142 }
143
144 template <typename T>
145 bool ValidateGreaterThanZero(const T value, const ParameterName &parameter_name, const std::string &vuid,
146 const LogMiscParams &misc) {
147 return ValidateGreaterThan(value, T{0}, parameter_name, vuid, misc);
148 }
149 /**
150 * Validate a required pointer.
151 *
152 * Verify that a required pointer is not NULL.
153 *
154 * @param apiName Name of API call being validated.
155 * @param parameterName Name of parameter being validated.
156 * @param value Pointer to validate.
157 * @return Boolean value indicating that the call should be skipped.
158 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700159 bool validate_required_pointer(const char *apiName, const ParameterName &parameterName, const void *value,
160 const std::string &vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700161 bool skip_call = false;
162
163 if (value == NULL) {
164 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
165 "%s: required parameter %s specified as NULL.", apiName, parameterName.get_name().c_str());
166 }
167
168 return skip_call;
169 }
170
171 /**
172 * Validate array count and pointer to array.
173 *
174 * Verify that required count and array parameters are not 0 or NULL. If the
175 * count parameter is not optional, verify that it is not 0. If the array
176 * parameter is NULL, and it is not optional, verify that count is 0.
177 *
178 * @param apiName Name of API call being validated.
179 * @param countName Name of count parameter.
180 * @param arrayName Name of array parameter.
181 * @param count Number of elements in the array.
182 * @param array Array to validate.
183 * @param countRequired The 'count' parameter may not be 0 when true.
184 * @param arrayRequired The 'array' parameter may not be NULL when true.
185 * @return Boolean value indicating that the call should be skipped.
186 */
187 template <typename T1, typename T2>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700188 bool validate_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName, T1 count,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600189 const T2 *array, bool countRequired, bool arrayRequired, const char *count_required_vuid,
190 const char *array_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700191 bool skip_call = false;
192
193 // Count parameters not tagged as optional cannot be 0
194 if (countRequired && (count == 0)) {
195 skip_call |=
196 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, count_required_vuid,
197 "%s: parameter %s must be greater than 0.", apiName, countName.get_name().c_str());
198 }
199
200 // Array parameters not tagged as optional cannot be NULL, unless the count is 0
201 if (arrayRequired && (count != 0) && (*array == NULL)) {
202 skip_call |=
203 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, array_required_vuid,
204 "%s: required parameter %s specified as NULL.", apiName, arrayName.get_name().c_str());
205 }
206
207 return skip_call;
208 }
209
210 /**
211 * Validate pointer to array count and pointer to array.
212 *
213 * Verify that required count and array parameters are not NULL. If count
214 * is not NULL and its value is not optional, verify that it is not 0. If the
215 * array parameter is NULL, and it is not optional, verify that count is 0.
216 * The array parameter will typically be optional for this case (where count is
217 * a pointer), allowing the caller to retrieve the available count.
218 *
219 * @param apiName Name of API call being validated.
220 * @param countName Name of count parameter.
221 * @param arrayName Name of array parameter.
222 * @param count Pointer to the number of elements in the array.
223 * @param array Array to validate.
224 * @param countPtrRequired The 'count' parameter may not be NULL when true.
225 * @param countValueRequired The '*count' value may not be 0 when true.
226 * @param arrayRequired The 'array' parameter may not be NULL when true.
227 * @return Boolean value indicating that the call should be skipped.
228 */
229 template <typename T1, typename T2>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700230 bool validate_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName, const T1 *count,
231 const T2 *array, bool countPtrRequired, bool countValueRequired, bool arrayRequired,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600232 const char *count_required_vuid, const char *array_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700233 bool skip_call = false;
234
235 if (count == NULL) {
236 if (countPtrRequired) {
237 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
238 kVUID_PVError_RequiredParameter, "%s: required parameter %s specified as NULL", apiName,
239 countName.get_name().c_str());
240 }
241 } else {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700242 skip_call |= validate_array(apiName, countName, arrayName, *array ? (*count) : 0, &array, countValueRequired,
243 arrayRequired, count_required_vuid, array_required_vuid);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700244 }
245
246 return skip_call;
247 }
248
249 /**
250 * Validate a pointer to a Vulkan structure.
251 *
252 * Verify that a required pointer to a structure is not NULL. If the pointer is
253 * not NULL, verify that each structure's sType field is set to the correct
254 * VkStructureType value.
255 *
256 * @param apiName Name of API call being validated.
257 * @param parameterName Name of struct parameter being validated.
258 * @param sTypeName Name of expected VkStructureType value.
259 * @param value Pointer to the struct to validate.
260 * @param sType VkStructureType for structure validation.
261 * @param required The parameter may not be NULL when true.
262 * @return Boolean value indicating that the call should be skipped.
263 */
264 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700265 bool validate_struct_type(const char *apiName, const ParameterName &parameterName, const char *sTypeName, const T *value,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600266 VkStructureType sType, bool required, const char *struct_vuid, const char *stype_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700267 bool skip_call = false;
268
269 if (value == NULL) {
270 if (required) {
271 skip_call |=
272 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, struct_vuid,
273 "%s: required parameter %s specified as NULL", apiName, parameterName.get_name().c_str());
274 }
275 } else if (value->sType != sType) {
276 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, stype_vuid,
277 "%s: parameter %s->sType must be %s.", apiName, parameterName.get_name().c_str(), sTypeName);
278 }
279
280 return skip_call;
281 }
282
283 /**
284 * Validate an array of Vulkan structures
285 *
286 * Verify that required count and array parameters are not 0 or NULL. If
287 * the array contains 1 or more structures, verify that each structure's
288 * sType field is set to the correct VkStructureType value.
289 *
290 * @param apiName Name of API call being validated.
291 * @param countName Name of count parameter.
292 * @param arrayName Name of array parameter.
293 * @param sTypeName Name of expected VkStructureType value.
294 * @param count Number of elements in the array.
295 * @param array Array to validate.
296 * @param sType VkStructureType for structure validation.
297 * @param countRequired The 'count' parameter may not be 0 when true.
298 * @param arrayRequired The 'array' parameter may not be NULL when true.
299 * @return Boolean value indicating that the call should be skipped.
300 */
301 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700302 bool validate_struct_type_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName,
303 const char *sTypeName, uint32_t count, const T *array, VkStructureType sType,
Jasper St. Pierre6c98f8c2019-01-22 15:18:03 -0800304 bool countRequired, bool arrayRequired, const char *stype_vuid, const char *param_vuid,
305 const char *count_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700306 bool skip_call = false;
307
308 if ((count == 0) || (array == NULL)) {
Jasper St. Pierre6c98f8c2019-01-22 15:18:03 -0800309 skip_call |= validate_array(apiName, countName, arrayName, count, &array, countRequired, arrayRequired,
310 count_required_vuid, param_vuid);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700311 } else {
312 // Verify that all structs in the array have the correct type
313 for (uint32_t i = 0; i < count; ++i) {
314 if (array[i].sType != sType) {
315 skip_call |=
316 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, stype_vuid,
317 "%s: parameter %s[%d].sType must be %s", apiName, arrayName.get_name().c_str(), i, sTypeName);
318 }
319 }
320 }
321
322 return skip_call;
323 }
324
325 /**
326 * Validate an array of Vulkan structures.
327 *
328 * Verify that required count and array parameters are not NULL. If count
329 * is not NULL and its value is not optional, verify that it is not 0.
330 * If the array contains 1 or more structures, verify that each structure's
331 * sType field is set to the correct VkStructureType value.
332 *
333 * @param apiName Name of API call being validated.
334 * @param countName Name of count parameter.
335 * @param arrayName Name of array parameter.
336 * @param sTypeName Name of expected VkStructureType value.
337 * @param count Pointer to the number of elements in the array.
338 * @param array Array to validate.
339 * @param sType VkStructureType for structure validation.
340 * @param countPtrRequired The 'count' parameter may not be NULL when true.
341 * @param countValueRequired The '*count' value may not be 0 when true.
342 * @param arrayRequired The 'array' parameter may not be NULL when true.
343 * @return Boolean value indicating that the call should be skipped.
344 */
345 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700346 bool validate_struct_type_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName,
347 const char *sTypeName, uint32_t *count, const T *array, VkStructureType sType,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600348 bool countPtrRequired, bool countValueRequired, bool arrayRequired, const char *stype_vuid,
Jasper St. Pierre6c98f8c2019-01-22 15:18:03 -0800349 const char *param_vuid, const char *count_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700350 bool skip_call = false;
351
352 if (count == NULL) {
353 if (countPtrRequired) {
354 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
355 kVUID_PVError_RequiredParameter, "%s: required parameter %s specified as NULL", apiName,
356 countName.get_name().c_str());
357 }
358 } else {
359 skip_call |= validate_struct_type_array(apiName, countName, arrayName, sTypeName, (*count), array, sType,
Jasper St. Pierre6c98f8c2019-01-22 15:18:03 -0800360 countValueRequired, arrayRequired, stype_vuid, param_vuid, count_required_vuid);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700361 }
362
363 return skip_call;
364 }
365
366 /**
367 * Validate a Vulkan handle.
368 *
369 * Verify that the specified handle is not VK_NULL_HANDLE.
370 *
371 * @param api_name Name of API call being validated.
372 * @param parameter_name Name of struct parameter being validated.
373 * @param value Handle to validate.
374 * @return Boolean value indicating that the call should be skipped.
375 */
376 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700377 bool validate_required_handle(const char *api_name, const ParameterName &parameter_name, T value) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700378 bool skip_call = false;
379
380 if (value == VK_NULL_HANDLE) {
381 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
382 kVUID_PVError_RequiredParameter, "%s: required parameter %s specified as VK_NULL_HANDLE", api_name,
383 parameter_name.get_name().c_str());
384 }
385
386 return skip_call;
387 }
388
389 /**
390 * Validate an array of Vulkan handles.
391 *
392 * Verify that required count and array parameters are not NULL. If count
393 * is not NULL and its value is not optional, verify that it is not 0.
394 * If the array contains 1 or more handles, verify that no handle is set to
395 * VK_NULL_HANDLE.
396 *
397 * @note This function is only intended to validate arrays of handles when none
398 * of the handles are allowed to be VK_NULL_HANDLE. For arrays of handles
399 * that are allowed to contain VK_NULL_HANDLE, use validate_array() instead.
400 *
401 * @param api_name Name of API call being validated.
402 * @param count_name Name of count parameter.
403 * @param array_name Name of array parameter.
404 * @param count Number of elements in the array.
405 * @param array Array to validate.
406 * @param count_required The 'count' parameter may not be 0 when true.
407 * @param array_required The 'array' parameter may not be NULL when true.
408 * @return Boolean value indicating that the call should be skipped.
409 */
410 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700411 bool validate_handle_array(const char *api_name, const ParameterName &count_name, const ParameterName &array_name,
412 uint32_t count, const T *array, bool count_required, bool array_required) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700413 bool skip_call = false;
414
415 if ((count == 0) || (array == NULL)) {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700416 skip_call |= validate_array(api_name, count_name, array_name, count, &array, count_required, array_required,
417 kVUIDUndefined, kVUIDUndefined);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700418 } else {
419 // Verify that no handles in the array are VK_NULL_HANDLE
420 for (uint32_t i = 0; i < count; ++i) {
421 if (array[i] == VK_NULL_HANDLE) {
422 skip_call |=
423 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
424 kVUID_PVError_RequiredParameter, "%s: required parameter %s[%d] specified as VK_NULL_HANDLE",
425 api_name, array_name.get_name().c_str(), i);
426 }
427 }
428 }
429
430 return skip_call;
431 }
432
433 /**
434 * Validate string array count and content.
435 *
436 * Verify that required count and array parameters are not 0 or NULL. If the
437 * count parameter is not optional, verify that it is not 0. If the array
438 * parameter is NULL, and it is not optional, verify that count is 0. If the
439 * array parameter is not NULL, verify that none of the strings are NULL.
440 *
441 * @param apiName Name of API call being validated.
442 * @param countName Name of count parameter.
443 * @param arrayName Name of array parameter.
444 * @param count Number of strings in the array.
445 * @param array Array of strings to validate.
446 * @param countRequired The 'count' parameter may not be 0 when true.
447 * @param arrayRequired The 'array' parameter may not be NULL when true.
448 * @return Boolean value indicating that the call should be skipped.
449 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700450 bool validate_string_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName, uint32_t count,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600451 const char *const *array, bool countRequired, bool arrayRequired, const char *count_required_vuid,
452 const char *array_required_vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700453 bool skip_call = false;
454
455 if ((count == 0) || (array == NULL)) {
456 skip_call |= validate_array(apiName, countName, arrayName, count, &array, countRequired, arrayRequired,
457 count_required_vuid, array_required_vuid);
458 } else {
459 // Verify that strings in the array are not NULL
460 for (uint32_t i = 0; i < count; ++i) {
461 if (array[i] == NULL) {
462 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
463 kVUID_PVError_RequiredParameter, "%s: required parameter %s[%d] specified as NULL",
464 apiName, arrayName.get_name().c_str(), i);
465 }
466 }
467 }
468
469 return skip_call;
470 }
471
472 // Forward declaration for pNext validation
Lockefbdd1af2019-04-16 15:07:23 -0600473 bool ValidatePnextStructContents(const char *api_name, const ParameterName &parameter_name, const VkBaseOutStructure *header);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700474
475 /**
476 * Validate a structure's pNext member.
477 *
478 * Verify that the specified pNext value points to the head of a list of
479 * allowed extension structures. If no extension structures are allowed,
480 * verify that pNext is null.
481 *
482 * @param api_name Name of API call being validated.
483 * @param parameter_name Name of parameter being validated.
484 * @param allowed_struct_names Names of allowed structs.
485 * @param next Pointer to validate.
486 * @param allowed_type_count Total number of allowed structure types.
487 * @param allowed_types Array of structure types allowed for pNext.
488 * @param header_version Version of header defining the pNext validation rules.
489 * @return Boolean value indicating that the call should be skipped.
490 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700491 bool validate_struct_pnext(const char *api_name, const ParameterName &parameter_name, const char *allowed_struct_names,
492 const void *next, size_t allowed_type_count, const VkStructureType *allowed_types,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600493 uint32_t header_version, const char *vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700494 bool skip_call = false;
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700495
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700496 // TODO: The valid pNext structure types are not recursive. Each structure has its own list of valid sTypes for pNext.
497 // Codegen a map of vectors containing the allowable pNext types for each struct and use that here -- also simplifies parms.
498 if (next != NULL) {
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600499 std::unordered_set<const void *> cycle_check;
500 std::unordered_set<VkStructureType, std::hash<int>> unique_stype_check;
501
Jeff Bolz6d3beaa2019-02-09 21:00:05 -0600502 const char *disclaimer =
503 "This warning is based on the Valid Usage documentation for version %d of the Vulkan header. It is possible that "
504 "you "
505 "are "
506 "using a struct from a private extension or an extension that was added to a later version of the Vulkan header, "
507 "in "
508 "which "
509 "case your use of %s is perfectly valid but is not guaranteed to work correctly with validation enabled";
510
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700511 if (allowed_type_count == 0) {
512 std::string message = "%s: value of %s must be NULL. ";
513 message += disclaimer;
514 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
515 message.c_str(), api_name, parameter_name.get_name().c_str(), header_version,
516 parameter_name.get_name().c_str());
517 } else {
518 const VkStructureType *start = allowed_types;
519 const VkStructureType *end = allowed_types + allowed_type_count;
Lockefbdd1af2019-04-16 15:07:23 -0600520 const VkBaseOutStructure *current = reinterpret_cast<const VkBaseOutStructure *>(next);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700521
522 cycle_check.insert(next);
523
524 while (current != NULL) {
525 if (((strncmp(api_name, "vkCreateInstance", strlen(api_name)) != 0) ||
526 (current->sType != VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO)) &&
527 ((strncmp(api_name, "vkCreateDevice", strlen(api_name)) != 0) ||
528 (current->sType != VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO))) {
529 if (cycle_check.find(current->pNext) != cycle_check.end()) {
530 std::string message = "%s: %s chain contains a cycle -- pNext pointer " PRIx64 " is repeated.";
531 skip_call |=
532 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
533 kVUID_PVError_InvalidStructPNext, message.c_str(), api_name,
534 parameter_name.get_name().c_str(), reinterpret_cast<uint64_t>(next));
535 break;
536 } else {
537 cycle_check.insert(current->pNext);
538 }
539
540 std::string type_name = string_VkStructureType(current->sType);
541 if (unique_stype_check.find(current->sType) != unique_stype_check.end()) {
542 std::string message = "%s: %s chain contains duplicate structure types: %s appears multiple times.";
543 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
544 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, kVUID_PVError_InvalidStructPNext,
545 message.c_str(), api_name, parameter_name.get_name().c_str(), type_name.c_str());
546 } else {
547 unique_stype_check.insert(current->sType);
548 }
549
550 if (std::find(start, end, current->sType) == end) {
551 if (type_name == UnsupportedStructureTypeString) {
552 std::string message =
553 "%s: %s chain includes a structure with unknown VkStructureType (%d); Allowed structures are "
554 "[%s]. ";
555 message += disclaimer;
556 skip_call |=
557 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
558 0, vuid, message.c_str(), api_name, parameter_name.get_name().c_str(), current->sType,
559 allowed_struct_names, header_version, parameter_name.get_name().c_str());
560 } else {
561 std::string message =
562 "%s: %s chain includes a structure with unexpected VkStructureType %s; Allowed structures are "
563 "[%s]. ";
564 message += disclaimer;
565 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
566 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, message.c_str(), api_name,
567 parameter_name.get_name().c_str(), type_name.c_str(), allowed_struct_names,
568 header_version, parameter_name.get_name().c_str());
569 }
570 }
571 skip_call |= ValidatePnextStructContents(api_name, parameter_name, current);
572 }
Lockefbdd1af2019-04-16 15:07:23 -0600573 current = reinterpret_cast<const VkBaseOutStructure *>(current->pNext);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700574 }
575 }
576 }
577
578 return skip_call;
579 }
580
581 /**
582 * Validate a VkBool32 value.
583 *
584 * Generate a warning if a VkBool32 value is neither VK_TRUE nor VK_FALSE.
585 *
586 * @param apiName Name of API call being validated.
587 * @param parameterName Name of parameter being validated.
588 * @param value Boolean value to validate.
589 * @return Boolean value indicating that the call should be skipped.
590 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700591 bool validate_bool32(const char *apiName, const ParameterName &parameterName, VkBool32 value) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700592 bool skip_call = false;
593
594 if ((value != VK_TRUE) && (value != VK_FALSE)) {
595 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
596 kVUID_PVError_UnrecognizedValue, "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName,
597 parameterName.get_name().c_str(), value);
598 }
599
600 return skip_call;
601 }
602
603 /**
604 * Validate a Vulkan enumeration value.
605 *
606 * Generate a warning if an enumeration token value does not fall within the core enumeration
607 * begin and end token values, and was not added to the enumeration by an extension. Extension
608 * provided enumerations use the equation specified in Appendix C.10 of the Vulkan specification,
609 * with 1,000,000,000 as the base token value.
610 *
611 * @note This function does not expect to process enumerations defining bitmask flag bits.
612 *
613 * @param apiName Name of API call being validated.
614 * @param parameterName Name of parameter being validated.
615 * @param enumName Name of the enumeration being validated.
616 * @param valid_values The list of valid values for the enumeration.
617 * @param value Enumeration value to validate.
618 * @return Boolean value indicating that the call should be skipped.
619 */
620 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700621 bool validate_ranged_enum(const char *apiName, const ParameterName &parameterName, const char *enumName,
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600622 const std::vector<T> &valid_values, T value, const char *vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700623 bool skip = false;
624
625 if (std::find(valid_values.begin(), valid_values.end(), value) == valid_values.end()) {
626 skip |=
627 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
628 "%s: value of %s (%d) does not fall within the begin..end range of the core %s enumeration tokens and is "
629 "not an extension added token.",
630 apiName, parameterName.get_name().c_str(), value, enumName);
631 }
632
633 return skip;
634 }
635
636 /**
637 * Validate an array of Vulkan enumeration value.
638 *
639 * Process all enumeration token values in the specified array and generate a warning if a value
640 * does not fall within the core enumeration begin and end token values, and was not added to
641 * the enumeration by an extension. Extension provided enumerations use the equation specified
642 * in Appendix C.10 of the Vulkan specification, with 1,000,000,000 as the base token value.
643 *
644 * @note This function does not expect to process enumerations defining bitmask flag bits.
645 *
646 * @param apiName Name of API call being validated.
647 * @param countName Name of count parameter.
648 * @param arrayName Name of array parameter.
649 * @param enumName Name of the enumeration being validated.
650 * @param valid_values The list of valid values for the enumeration.
651 * @param count Number of enumeration values in the array.
652 * @param array Array of enumeration values to validate.
653 * @param countRequired The 'count' parameter may not be 0 when true.
654 * @param arrayRequired The 'array' parameter may not be NULL when true.
655 * @return Boolean value indicating that the call should be skipped.
656 */
657 template <typename T>
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700658 bool validate_ranged_enum_array(const char *apiName, const ParameterName &countName, const ParameterName &arrayName,
659 const char *enumName, const std::vector<T> &valid_values, uint32_t count, const T *array,
660 bool countRequired, bool arrayRequired) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700661 bool skip_call = false;
662
663 if ((count == 0) || (array == NULL)) {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700664 skip_call |= validate_array(apiName, countName, arrayName, count, &array, countRequired, arrayRequired, kVUIDUndefined,
665 kVUIDUndefined);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700666 } else {
667 for (uint32_t i = 0; i < count; ++i) {
668 if (std::find(valid_values.begin(), valid_values.end(), array[i]) == valid_values.end()) {
669 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
670 kVUID_PVError_UnrecognizedValue,
671 "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s "
672 "enumeration tokens and is not an extension added token",
673 apiName, arrayName.get_name().c_str(), i, array[i], enumName);
674 }
675 }
676 }
677
678 return skip_call;
679 }
680
681 /**
682 * Verify that a reserved VkFlags value is zero.
683 *
684 * Verify that the specified value is zero, to check VkFlags values that are reserved for
685 * future use.
686 *
687 * @param api_name Name of API call being validated.
688 * @param parameter_name Name of parameter being validated.
689 * @param value Value to validate.
690 * @return Boolean value indicating that the call should be skipped.
691 */
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600692 bool validate_reserved_flags(const char *api_name, const ParameterName &parameter_name, VkFlags value, const char *vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700693 bool skip_call = false;
694
695 if (value != 0) {
696 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
697 "%s: parameter %s must be 0.", api_name, parameter_name.get_name().c_str());
698 }
699
700 return skip_call;
701 }
702
703 /**
704 * Validate a Vulkan bitmask value.
705 *
706 * Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
707 * for that type.
708 *
709 * @param api_name Name of API call being validated.
710 * @param parameter_name Name of parameter being validated.
711 * @param flag_bits_name Name of the VkFlags type being validated.
712 * @param all_flags A bit mask combining all valid flag bits for the VkFlags type being validated.
713 * @param value VkFlags value to validate.
714 * @param flags_required The 'value' parameter may not be 0 when true.
715 * @param singleFlag The 'value' parameter may not contain more than one bit from all_flags.
716 * @return Boolean value indicating that the call should be skipped.
717 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700718 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 -0600719 VkFlags value, bool flags_required, bool singleFlag, const char *vuid) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700720 bool skip_call = false;
721
722 if (value == 0) {
723 if (flags_required) {
724 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
725 "%s: value of %s must not be 0.", api_name, parameter_name.get_name().c_str());
726 }
727 } else if ((value & (~all_flags)) != 0) {
728 skip_call |=
729 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
730 kVUID_PVError_UnrecognizedValue, "%s: value of %s contains flag bits that are not recognized members of %s",
731 api_name, parameter_name.get_name().c_str(), flag_bits_name);
732 } else if (singleFlag && (std::bitset<sizeof(VkFlags) * 8>(value).count() > 1)) {
733 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
734 kVUID_PVError_UnrecognizedValue,
735 "%s: value of %s contains multiple members of %s when only a single value is allowed", api_name,
736 parameter_name.get_name().c_str(), flag_bits_name);
737 }
738
739 return skip_call;
740 }
741
742 /**
743 * Validate an array of Vulkan bitmask values.
744 *
745 * Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
746 * for that type.
747 *
748 * @param api_name Name of API call being validated.
749 * @param count_name Name of parameter being validated.
750 * @param array_name Name of parameter being validated.
751 * @param flag_bits_name Name of the VkFlags type being validated.
752 * @param all_flags A bitmask combining all valid flag bits for the VkFlags type being validated.
753 * @param count Number of VkFlags values in the array.
754 * @param array Array of VkFlags value to validate.
755 * @param count_required The 'count' parameter may not be 0 when true.
756 * @param array_required The 'array' parameter may not be NULL when true.
757 * @return Boolean value indicating that the call should be skipped.
758 */
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700759 bool validate_flags_array(const char *api_name, const ParameterName &count_name, const ParameterName &array_name,
760 const char *flag_bits_name, VkFlags all_flags, uint32_t count, const VkFlags *array,
761 bool count_required, bool array_required) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700762 bool skip_call = false;
763
764 if ((count == 0) || (array == NULL)) {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700765 skip_call |= validate_array(api_name, count_name, array_name, count, &array, count_required, array_required,
766 kVUIDUndefined, kVUIDUndefined);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700767 } else {
768 // Verify that all VkFlags values in the array
769 for (uint32_t i = 0; i < count; ++i) {
770 if (array[i] == 0) {
771 // Current XML registry logic for validity generation uses the array parameter's optional tag to determine if
772 // elements in the array are allowed be 0
773 if (array_required) {
774 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
775 kVUID_PVError_RequiredParameter, "%s: value of %s[%d] must not be 0", api_name,
776 array_name.get_name().c_str(), i);
777 }
778 } else if ((array[i] & (~all_flags)) != 0) {
779 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
780 kVUID_PVError_UnrecognizedValue,
781 "%s: value of %s[%d] contains flag bits that are not recognized members of %s", api_name,
782 array_name.get_name().c_str(), i, flag_bits_name);
783 }
784 }
785 }
786
787 return skip_call;
788 }
789
790 template <typename ExtensionState>
Jeff Bolzfdd0d852019-02-03 21:55:12 -0600791 bool validate_extension_reqs(const ExtensionState &extensions, const char *vuid, const char *extension_type,
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700792 const char *extension_name) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700793 bool skip = false;
794 if (!extension_name) {
795 return skip; // Robust to invalid char *
796 }
797 auto info = ExtensionState::get_info(extension_name);
798
799 if (!info.state) {
800 return skip; // Unknown extensions cannot be checked so report OK
801 }
802
803 // Check against the required list in the info
804 std::vector<const char *> missing;
805 for (const auto &req : info.requires) {
806 if (!(extensions.*(req.enabled))) {
807 missing.push_back(req.name);
808 }
809 }
810
811 // Report any missing requirements
812 if (missing.size()) {
813 std::string missing_joined_list = string_join(", ", missing);
814 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 -0700815 HandleToUint64(instance), vuid, "Missing extension%s required by the %s extension %s: %s.",
816 ((missing.size() > 1) ? "s" : ""), extension_type, extension_name, missing_joined_list.c_str());
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700817 }
818 return skip;
819 }
820
821 enum RenderPassCreateVersion { RENDER_PASS_VERSION_1 = 0, RENDER_PASS_VERSION_2 = 1 };
822
823 template <typename RenderPassCreateInfoGeneric>
824 bool CreateRenderPassGeneric(VkDevice device, const RenderPassCreateInfoGeneric *pCreateInfo,
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700825 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
826 RenderPassCreateVersion rp_version) {
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700827 bool skip = false;
828 uint32_t max_color_attachments = device_limits.maxColorAttachments;
829 bool use_rp2 = (rp_version == RENDER_PASS_VERSION_2);
830 const char *vuid;
831
832 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
833 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
834 std::stringstream ss;
835 ss << (use_rp2 ? "vkCreateRenderPass2KHR" : "vkCreateRenderPass") << ": pCreateInfo->pAttachments[" << i
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700836 << "].format is VK_FORMAT_UNDEFINED. ";
837 vuid =
838 use_rp2 ? "VUID-VkAttachmentDescription2KHR-format-parameter" : "VUID-VkAttachmentDescription-format-parameter";
839 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
840 "%s", ss.str().c_str());
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700841 }
842 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
843 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700844 vuid = use_rp2 ? "VUID-VkAttachmentDescription2KHR-finalLayout-03061"
845 : "VUID-VkAttachmentDescription-finalLayout-00843";
846 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
847 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
848 "VK_IMAGE_LAYOUT_PREINITIALIZED.",
849 i);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700850 }
851 }
852
853 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
854 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
855 vuid = use_rp2 ? "VUID-VkSubpassDescription2KHR-colorAttachmentCount-03063"
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700856 : "VUID-VkSubpassDescription-colorAttachmentCount-00845";
857 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid,
858 "Cannot create a render pass with %d color attachments. Max is %d.",
859 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700860 }
861 }
862 return skip;
863 }
864
865 template <typename T>
866 void RecordRenderPass(VkRenderPass renderPass, const T *pCreateInfo) {
Mark Lobodzinskif27a6bc2019-02-04 13:00:49 -0700867 std::unique_lock<std::mutex> lock(renderpass_map_mutex);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700868 auto &renderpass_state = renderpasses_states[renderPass];
Mark Lobodzinskif27a6bc2019-02-04 13:00:49 -0700869 lock.unlock();
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700870
871 for (uint32_t subpass = 0; subpass < pCreateInfo->subpassCount; ++subpass) {
872 bool uses_color = false;
873 for (uint32_t i = 0; i < pCreateInfo->pSubpasses[subpass].colorAttachmentCount && !uses_color; ++i)
874 if (pCreateInfo->pSubpasses[subpass].pColorAttachments[i].attachment != VK_ATTACHMENT_UNUSED) uses_color = true;
875
876 bool uses_depthstencil = false;
877 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment)
878 if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)
879 uses_depthstencil = true;
880
881 if (uses_color) renderpass_state.subpasses_using_color_attachment.insert(subpass);
882 if (uses_depthstencil) renderpass_state.subpasses_using_depthstencil_attachment.insert(subpass);
883 }
884 }
885
886 bool require_device_extension(bool flag, char const *function_name, char const *extension_name);
887
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700888 bool validate_instance_extensions(const VkInstanceCreateInfo *pCreateInfo);
889
890 bool validate_api_version(uint32_t api_version, uint32_t effective_api_version);
891
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700892 bool validate_string(const char *apiName, const ParameterName &stringName, const std::string &vuid, const char *validateString);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700893
894 bool ValidateCoarseSampleOrderCustomNV(const VkCoarseSampleOrderCustomNV *order);
895
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700896 bool ValidateQueueFamilies(uint32_t queue_family_count, const uint32_t *queue_families, const char *cmd_name,
897 const char *array_parameter_name, const std::string &unique_error_code,
898 const std::string &valid_error_code, bool optional);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700899
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700900 bool ValidateDeviceQueueFamily(uint32_t queue_family, const char *cmd_name, const char *parameter_name,
901 const std::string &error_code, bool optional);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700902
Jason Macnak5c954952019-07-09 15:46:12 -0700903 bool ValidateAccelerationStructureInfoNV(const VkAccelerationStructureInfoNV &info);
904
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700905 bool OutputExtensionError(const std::string &api_name, const std::string &extension_name);
906
907 void PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700908 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, VkResult result);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700909 void PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700910 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, VkResult result);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700911 void PostCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator);
912 void PostCallRecordCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700913 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700914
915 void PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700916 VkInstance *pInstance, VkResult result);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700917
918 bool manual_PreCallValidateCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
919 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool);
920
921 bool manual_PreCallValidateCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
922 VkInstance *pInstance);
923
924 bool manual_PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
925 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
926
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700927 bool manual_PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
928 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer);
929
930 bool manual_PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
931 const VkAllocationCallbacks *pAllocator, VkImage *pImage);
932
933 bool manual_PreCallValidateCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
934 const VkAllocationCallbacks *pAllocator, VkImageView *pView);
935
Jeff Bolz6d3beaa2019-02-09 21:00:05 -0600936 bool manual_PreCallValidateViewport(const VkViewport &viewport, const char *fn_name, const ParameterName &parameter_name,
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700937 VkDebugReportObjectTypeEXT object_type, uint64_t object);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700938
939 bool manual_PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
940 const VkGraphicsPipelineCreateInfo *pCreateInfos,
941 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines);
942 bool manual_PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
943 const VkComputePipelineCreateInfo *pCreateInfos,
944 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines);
945
946 bool manual_PreCallValidateCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
947 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler);
948 bool manual_PreCallValidateCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700949 const VkAllocationCallbacks *pAllocator,
950 VkDescriptorSetLayout *pSetLayout);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700951
Mark Lobodzinskibf599b92018-12-31 12:15:55 -0700952 bool manual_PreCallValidateUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
953 const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
954 const VkCopyDescriptorSet *pDescriptorCopies);
Jason Macnak5c954952019-07-09 15:46:12 -0700955
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700956 bool manual_PreCallValidateFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
957 const VkDescriptorSet *pDescriptorSets);
958
959 bool manual_PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
960 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
961
962 bool manual_PreCallValidateCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo,
963 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass);
964
965 bool manual_PreCallValidateFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
966 const VkCommandBuffer *pCommandBuffers);
967
968 bool manual_PreCallValidateBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo);
969
970 bool manual_PreCallValidateCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
971 const VkViewport *pViewports);
972
973 bool manual_PreCallValidateCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
974 const VkRect2D *pScissors);
975 bool manual_PreCallValidateCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth);
976
977 bool manual_PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
978 uint32_t firstVertex, uint32_t firstInstance);
979
980 bool manual_PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
981 uint32_t stride);
982
983 bool manual_PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
984 uint32_t count, uint32_t stride);
985
Mark Lobodzinskif77a4ac2019-06-27 15:30:51 -0600986 bool manual_PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
987 const VkClearAttachment *pAttachments, uint32_t rectCount,
988 const VkClearRect *pRects);
989
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -0700990 bool manual_PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
991 VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount,
992 const VkImageCopy *pRegions);
993
994 bool manual_PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
995 VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount,
996 const VkImageBlit *pRegions, VkFilter filter);
997
998 bool manual_PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
999 VkImageLayout dstImageLayout, uint32_t regionCount,
1000 const VkBufferImageCopy *pRegions);
1001
1002 bool manual_PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
1003 VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions);
1004
1005 bool manual_PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
1006 VkDeviceSize dataSize, const void *pData);
1007
1008 bool manual_PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
1009 VkDeviceSize size, uint32_t data);
1010
1011 bool manual_PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
1012 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain);
1013 bool manual_PreCallValidateQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo);
1014
1015#ifdef VK_USE_PLATFORM_WIN32_KHR
1016 bool manual_PreCallValidateCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
1017 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface);
1018#endif // VK_USE_PLATFORM_WIN32_KHR
1019
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -07001020 bool manual_PreCallValidateCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
1021 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool);
1022 bool manual_PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY,
1023 uint32_t groupCountZ);
1024
1025 bool manual_PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset);
1026
1027 bool manual_PreCallValidateCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY,
1028 uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY,
1029 uint32_t groupCountZ);
1030 bool manual_PreCallValidateCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
1031 uint32_t exclusiveScissorCount, const VkRect2D *pExclusiveScissors);
1032 bool manual_PreCallValidateCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
1033 uint32_t viewportCount,
1034 const VkShadingRatePaletteNV *pShadingRatePalettes);
1035
1036 bool manual_PreCallValidateCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer, VkCoarseSampleOrderTypeNV sampleOrderType,
1037 uint32_t customSampleOrderCount,
1038 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders);
1039
1040 bool manual_PreCallValidateCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, uint32_t firstTask);
1041 bool manual_PreCallValidateCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
1042 uint32_t drawCount, uint32_t stride);
1043
1044 bool manual_PreCallValidateCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
1045 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
1046 uint32_t maxDrawCount, uint32_t stride);
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -07001047
1048 bool manual_PreCallValidateEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
1049 uint32_t *pPropertyCount, VkExtensionProperties *pProperties);
Jeff Bolz7e7e6e02019-01-11 22:53:41 -06001050 bool manual_PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1051 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory);
Ricardo Garciaa4935972019-02-21 17:43:18 +01001052
1053 bool manual_PreCallValidateCreateAccelerationStructureNV(VkDevice device,
1054 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
1055 const VkAllocationCallbacks *pAllocator,
1056 VkAccelerationStructureNV *pAccelerationStructure);
Jason Macnak5c954952019-07-09 15:46:12 -07001057 bool manual_PreCallValidateCmdBuildAccelerationStructureNV(VkCommandBuffer commandBuffer,
1058 const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData,
1059 VkDeviceSize instanceOffset, VkBool32 update,
1060 VkAccelerationStructureNV dst, VkAccelerationStructureNV src,
1061 VkBuffer scratch, VkDeviceSize scratchOffset);
1062 bool manual_PreCallValidateGetAccelerationStructureHandleNV(VkDevice device, VkAccelerationStructureNV accelerationStructure,
1063 size_t dataSize, void *pData);
Peter Chen85366392019-05-14 15:20:11 -04001064 bool manual_PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1065 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
1066 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines);
Mike Schuchardt21638df2019-03-16 10:52:02 -07001067
1068#ifdef VK_USE_PLATFORM_WIN32_KHR
1069 bool PreCallValidateGetDeviceGroupSurfacePresentModes2EXT(VkDevice device, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
1070 VkDeviceGroupPresentModeFlagsKHR *pModes);
1071#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskiaf7c0382018-12-18 11:55:55 -07001072#include "parameter_validation.h"
1073}; // Class StatelessValidation