Validation¶
What it is¶
A validation build is a build where extra checking is compiled in: the native
validation layers of Vulkan and D3D12 and RI's own checks. It is controlled by a
compile-time switch, EQUINE_VALIDATION, rather than a runtime option. When EQUINE_VALIDATION is off, none of these
checks run and they add no runtime cost.
Turning it on¶
Each CMake preset sets EQUINE_VALIDATION explicitly: ON for the debug presets
(clang-debug, clangcl-debug), and OFF for the release and bench presets (as well as
by default when configuring without a preset). To override a preset's setting:
The switch is exposed to your code as the preprocessor macro EQUINE_VALIDATION (0 or
1), defined for every target that links EquineRI.
What a validation build turns on¶
RI enables validation automatically when you call createDevice; there is no separate
setup function to call.
- The backend's native validation layer is enabled (see the Vulkan and D3D12 tabs).
- Native validation errors go to the error channel as programmer errors. Under today's error-channel policy, the program prints the message and aborts on the first error; warnings are printed to standard error and execution continues.
- RI's own checks are active (see below).
- The device's
VkInstanceloadsVK_LAYER_KHRONOS_validation. If the layer is not installed,createDevicereports aneUnsupportederror telling you to install the Vulkan SDK or your distribution's validation-layers package. - A debug messenger receives warnings and errors. Errors of the validation type go to
the error channel as programmer errors; all other messages
(warnings, performance messages, and non-validation errors such as loader errors from a
stale driver manifest) are printed to standard error with an
[EquineRI] Vulkan warning:or[EquineRI] Vulkan error:prefix instead of aborting. VK_EXT_device_faultis enabled when the GPU supports it, for GPU crash diagnostics.- Layer settings enable GPU-assisted validation (
gpuav_enable, unless disabled viaEQUINE_GPU_VALIDATION=0) and shaderprintf(printf_enableandprintf_to_stdout, printed to standard output): see Debugging. listGpusnever loads the validation layer: it uses a short-lived instance with no layers.
Canonical Vulkan: enable the layer when you create the instance.
const VkApplicationInfo appInfo{
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pApplicationName = "my toy renderer",
.apiVersion = VK_API_VERSION_1_3, // the highest version this program uses
};
#ifndef NDEBUG
// Debug builds: the validation layer (installed with the Vulkan SDK).
const char *const layers[] = {"VK_LAYER_KHRONOS_validation"};
const uint32_t layerCount = 1;
#else
const char *const *layers = nullptr;
const uint32_t layerCount = 0;
#endif
const VkInstanceCreateInfo instanceInfo{
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pApplicationInfo = &appInfo,
.enabledLayerCount = layerCount,
.ppEnabledLayerNames = layers,
};
VkInstance instance = VK_NULL_HANDLE;
if (vkCreateInstance(&instanceInfo, nullptr, &instance) != VK_SUCCESS) {
return 1;
}
- The D3D12 debug layer, GPU-based validation (unless disabled via
EQUINE_GPU_VALIDATION=0), and DRED (GPU crash breadcrumbs and page-fault reports; see Debugging) are enabled once per process, before the first device is created. If the debug layer is missing,createDevicereports aneUnsupportederror asking you to check that the Agility SDK runtime (D3D12\d3d12SDKLayers.dll) is next to the executable. - Debug-layer error and corruption messages go to the error channel
through
ID3D12InfoQueue1as programmer errors; warnings are printed to standard error. IfID3D12InfoQueue1is unavailable, RI prints a notice to standard error and debug messages reach only the debugger output. - The DXGI debug factory (
DXGI_CREATE_FACTORY_DEBUG) is not used because it requires Windows' optional Graphics Tools.
Canonical D3D12: enable the debug layer before creating the device.
What RI checks itself¶
The native layers already check the underlying API thoroughly, and GPU-assisted validation checks shader accesses. RI does not duplicate those checks. Instead, it checks only what the native layers cannot see: RI's own rules. Examples include:
- using an object after it was destroyed (RI objects are copyable value structs, so the
native layer cannot tell which copy is stale). When the object was given a name at creation
or with
setName, the error message includes that name for the last 4,096 named objects destroyed; - using a texture placed over aliased memory before calling
cmdDiscard; - passing root data whose size does not match the shader's declared size, writing a descriptor slot past the heap's count, reusing or destroying a command list before the GPU has finished its last submission, or calling a device-thread function from another thread.
destroyDevice on a device that was never created or was already destroyed is always checked
and reported as a programmer error in every build, whether validation is enabled or not.
How a check works¶
This section is for readers of RI's source code, or anyone writing checks for their own helpers in the same style.
- A check is a plain function in
src/RI/Validation/that returns aCheckResult(std::optional<std::string>): empty when the rule holds, or an error message when it fails. A check never callsreportErroritself, so GPU-free unit tests can call it directly in any build configuration. - Backend functions run checks with
EQ_VALIDATE(check(...));. WhenEQUINE_VALIDATIONis on, a failed check is reported as a programmer error. WhenEQUINE_VALIDATIONis off,EQ_VALIDATEexpands to((void)0)and its argument is not evaluated, so a check can safely do non-trivial work. - Use-after-destroy detection uses an
ObjectTrackerowned by each device in validation builds: every created object receives a unique ID from a process-wide counter, destroying any copy marks that ID dead for all copies, and IDs are never reused (so an object from another device or a default-constructed object with ID0is also caught).
Because reportError captures std::source_location::current() at the EQ_VALIDATE call
site, the reported location is the RI backend function that ran the check, not your call
site.