Skip to content

Commit 8eb39fb

Browse files
Cleanup Validation Overview chapter (#297)
1 parent 69f1fd3 commit 8eb39fb

File tree

1 file changed

+25
-57
lines changed

1 file changed

+25
-57
lines changed

chapters/validation_overview.adoc

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019-2022 The Khronos Group, Inc.
1+
// Copyright 2019-2025 The Khronos Group, Inc.
22
// SPDX-License-Identifier: CC-BY-4.0
33

44
// Required for both single-page and combined guide xrefs to work
@@ -32,12 +32,35 @@ When an application supplies invalid input, according to the valid usages in the
3232

3333
**VERY IMPORTANT**: While undefined behavior might seem to work on one implementation, there is a good chance it will fail on another.
3434

35+
=== Undefined Value
36+
37+
There are few spots that will be __undefined value__. These are situation where it is not invalid to do something, but the value returned from the hardware might be garbage. Imagine the following code
38+
39+
[source,cpp]
40+
----
41+
int x;
42+
print(x)
43+
----
44+
45+
It will never crash, but the value can be anything and relying on the undefined value to be something like `0` is dangerous.
46+
3547
== Valid Usage ID (VUID)
3648

3749
A `VUID` is an unique ID given to each valid usage. This allows a way to point to a valid usage in the spec easily.
3850

3951
Using `VUID-vkBindImageMemory-memoryOffset-01046` as an example, it is as simple as adding the VUID to an anchor in the HTML version of the spec (link:https://docs.vulkan.org/spec/latest/chapters/resources.html#VUID-vkBindImageMemory-memoryOffset-01046[vkspec.html#VUID-vkBindImageMemory-memoryOffset-01046]) and it will jump right to the VUID.
4052

53+
=== Implicit vs Explicit
54+
55+
__Implicit Validation__ is the validation that is generated from the `vk.xml`. It will be the "obvious" things such as "`device` must be a valid `VkDevice` handle".
56+
57+
__Explicit Validation__ are the handwritten VUs found everywhere else
58+
59+
Simple way to detect which is which is by looking for a number in the VUID
60+
61+
- `VUID-vkBindImageMemory-image-01044` is explicit
62+
- `VUID-vkBindImageMemory-memory-parameter` is implicit
63+
4164
[[khronos-validation-layer]]
4265
== Khronos Validation Layer
4366

@@ -59,62 +82,7 @@ The Validation Layers are constantly being updated and improved so it is always
5982

6083
== Breaking Down a Validation Error Message
6184

62-
The Validation Layers attempt to supply as much useful information as possible when an error occurs. The following examples are to help show how to get the most information out of the Validation Layers
63-
64-
=== Example 1 - Implicit Valid Usage
65-
66-
This example shows a case where an link:https://docs.vulkan.org/spec/latest/chapters/fundamentals.html#fundamentals-implicit-validity[implicit VU] is triggered. There will not be a number at the end of the VUID.
67-
68-
[source]
69-
----
70-
Validation Error: [ VUID-vkBindBufferMemory-memory-parameter ] Object 0: handle =
71-
0x20c8650, type = VK_OBJECT_TYPE_INSTANCE; | MessageID = 0xe9199965 | Invalid
72-
VkDeviceMemory Object 0x60000000006. The Vulkan spec states: memory must be a valid
73-
VkDeviceMemory handle (https://docs.vulkan.org/spec/latest/chapters/resources.html#VUID-vkBindBufferMemory-memory-parameter))
74-
----
75-
76-
* The first thing to notice is the VUID is listed first in the message (`VUID-vkBindBufferMemory-memory-parameter`)
77-
** There is also a link at the end of the message to the VUID in the spec
78-
* `The Vulkan spec states:` is the quoted VUID from the spec.
79-
* The `VK_OBJECT_TYPE_INSTANCE` is the link:https://docs.vulkan.org/spec/latest/chapters/debugging.html#VkObjectType[VkObjectType]
80-
* `Invalid VkDeviceMemory Object 0x60000000006` is the link:https://docs.vulkan.org/spec/latest/chapters/fundamentals.html#fundamentals-objectmodel-overview[Dispatchable Handle] to help show which `VkDeviceMemory` handle was the cause of the error.
81-
82-
=== Example 2 - Explicit Valid Usage
83-
84-
This example shows an error where some `VkImage` is trying to be bound to 2 different `VkDeviceMemory` objects
85-
86-
[source]
87-
----
88-
Validation Error: [ VUID-vkBindImageMemory-image-01044 ] Object 0: handle =
89-
0x90000000009, name = myTextureMemory, type = VK_OBJECT_TYPE_DEVICE_MEMORY; Object 1:
90-
handle = 0x70000000007, type = VK_OBJECT_TYPE_IMAGE; Object 2: handle = 0x90000000006,
91-
name = myIconMemory, type = VK_OBJECT_TYPE_DEVICE_MEMORY; | MessageID = 0x6f3eac96 |
92-
In vkBindImageMemory(), attempting to bind VkDeviceMemory 0x90000000009[myTextureMemory]
93-
to VkImage 0x70000000007[] which has already been bound to VkDeviceMemory
94-
0x90000000006[myIconMemory]. The Vulkan spec states: image must not already be
95-
backed by a memory object (https://docs.vulkan.org/spec/latest/chapters/resources.html#VUID-vkBindImageMemory-image-01044)
96-
----
97-
98-
* Example 2 is about the same as Example 1 with the exception that the `name` that was attached to the object (`name = myTextureMemory`). This was done using the link:https://www.lunarg.com/new-tutorial-for-vulkan-debug-utilities-extension/[VK_EXT_debug_util] extension (link:https://github.com/KhronosGroup/Vulkan-Samples/tree/main/samples/extensions/debug_utils[Sample of how to use the extension]). Note that the old way of using link:https://www.saschawillems.de/blog/2016/05/28/tutorial-on-using-vulkans-vk_ext_debug_marker-with-renderdoc/[VK_EXT_debug_report] might be needed on legacy devices that don't support `VK_EXT_debug_util`.
99-
* There were 3 objects involved in causing this error.
100-
** Object 0 is a `VkDeviceMemory` named `myTextureMemory`
101-
** Object 1 is a `VkImage` with no name
102-
** Object 2 is a `VkDeviceMemory` named `myIconMemory`
103-
* With the names it is easy to see "`In `vkBindImageMemory()`, the `myTextureMemory` memory was attempting to bind to an image already been bound to the `myIconMemory` memory`".
104-
105-
Each error message contains a uniform logging pattern. This allows information to be easily found in any error. The pattern is as followed:
106-
107-
* Log status (ex. `Error:`, `Warning:`, etc)
108-
* The VUID
109-
* Array of objects involved
110-
** Index of array
111-
** Dispatch Handle value
112-
** Optional name
113-
** Object Type
114-
* Function or struct error occurred in
115-
* Message the layer has created to help describe the issue
116-
* The full Valid Usage from the spec
117-
* Link to the Valid Usage
85+
This information can be found in the link:https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/main/docs/error_messages.md[Validation Layers documentation].
11886

11987
== Special Usage Tags
12088

0 commit comments

Comments
 (0)