Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ vvl_sources = [
"layers/error_message/spirv_logging.cpp",
"layers/error_message/spirv_logging.h",
"layers/external/inplace_function.h",
"layers/external/shader_abort/shader_abort_message.cpp",
"layers/external/shader_abort/shader_abort_message.h",
"layers/external/vma/vk_mem_alloc.h",
"layers/external/vma/vma.cpp",
"layers/external/vma/vma.h",
Expand Down
26 changes: 26 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,32 @@ FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

===========================================================================================
File: layers/external/shader_abort/shader_abort_message.h
File: layers/external/shader_abort/shader_abort_message.cpp

MIT License

Copyright (c) 2026 Spencer Fricke

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

===========================================================================================
File: layers/external/xxhash.h

Expand Down
9 changes: 9 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ path = "layers/external/vma/**"
SPDX-FileCopyrightText = "2017-2024 Advanced Micro Devices, Inc."
SPDX-License-Identifier = "MIT"

# ---------------------------------------------------------------------------
# External: ShaderAbortTools — MIT, Spencer Fricke
# ---------------------------------------------------------------------------

[[annotations]]
path = "layers/external/shader_abort/**"
SPDX-FileCopyrightText = "2026 Spencer Fricke"
SPDX-License-Identifier = "MIT"

# ---------------------------------------------------------------------------
# External: xxhash — BSD-2-Clause, Yann Collet
# ---------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This directory contains more detailed information about how each part of the Val
- [GPU-AV Development](./gpu_av_development.md)
- [Scoped GPU-AV](./gpu_av_scoped.md)
- [Shader Instrumentation](./gpu_av_shader_instrumentation.md)
- [Shader Abort](./gpu_av_shader_abort.md)
- [Internal Descriptor](./gpu_av_internal_descriptor.md)
- [Descriptor Indexing](./gpu_av_descriptor_indexing.md)
- [Descriptor Buffer](./gpu_av_descriptor_buffer.md)
Expand Down
62 changes: 62 additions & 0 deletions docs/gpu_av_shader_abort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# GPU-AV Shader Abort

The `Shader Abort` setting (`gpuav_shader_abort`) uses [VK_KHR_shader_abort](https://docs.vulkan.org/refpages/latest/refpages/source/VK_KHR_shader_abort.html) to stop the shader at the **first** error found by [shader instrumentation](./gpu_av_shader_instrumentation.md).
Comment thread
spencer-lunarg marked this conversation as resolved.
Resolved

Because abort **will** cause a device lost when an error is detected. This option was designed for those who want something like "safe mode", but more agressive to ensure they can have the error message reported back.

## How the shader is instrumented

`gpuav_shader_abort` is separate from `gpuav_safe_mode` and is **off** by default.

Internally, `Shader Abort` reuses the Safe Mode control flow, the only difference is what happens in the "invalid" block. Using descriptor indexing as an example

```glsl
// Unsafe Mode
inst_descriptor_indexing_oob(/*...*/); // writes error_payload if invalid
value = texture(tex[index], uv);

// Safe Mode
if (inst_descriptor_indexing_oob(/*...*/)) {
value = texture(tex[index], uv);
} else {
value = vec4(0.0); // the result is an OpPhi of the 2 paths
}

// Shader Abort
if (inst_descriptor_indexing_oob(/*...*/)) {
value = texture(tex[index], uv);
} else {
abort(inst_abort_message(stage_info)); // OpAbortKHR
}
```

Since the abort block never reaches the merge block, there is no need for a "null" value or `OpPhi`, the valid block is the only path to the merge block.

The SPIR-V looks like

```swift
%valid = OpFunctionCall %bool %inst_descriptor_indexing_oob ...
OpSelectionMerge %merge None
OpBranchConditional %valid %valid_block %abort_block

%valid_block = OpLabel
; original instruction
OpBranch %merge

%abort_block = OpLabel
%message = OpFunctionCall %AbortMessage %inst_abort_message %stage_info
OpAbortKHR %AbortMessageLayout %message

%merge = OpLabel
; rest of the original block
```

## The abort message

Nothing written to memory before `OpAbortKHR` is guaranteed to be readable after the device is lost, so the error buffer can't be trusted. Instead, everything needed to report the error goes into the abort message.

The 3 things we need inside the abort message are

1. an "abort magic value" so we can ignore messages from the app's own `OpAbortKHR`
2. a "command buffer id" because at `vkGetDeviceFaultDebugInfoKHR` time multiple command buffers might be in flight and we need to know which one produced the error.
3. The error record, which is the exact same layout in the buffer as a normal error message
2 changes: 2 additions & 0 deletions layers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ target_sources(vvl_core PRIVATE
error_message/unimplementable_validation.h
external/vma/vma.h
external/vma/vma.cpp
external/shader_abort/shader_abort_message.h
external/shader_abort/shader_abort_message.cpp
${API_TYPE}/generated/best_practices.cpp
${API_TYPE}/generated/best_practices_device_methods.h
${API_TYPE}/generated/best_practices_instance_methods.h
Expand Down
13 changes: 13 additions & 0 deletions layers/VkLayer_khronos_validation.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,19 @@
]
}
},
{
"key": "gpuav_shader_abort",
"label": "Shader Abort",
"description": "Uses VK_KHR_shader_abort to report first faulty instruction found by shader instrumentation, and stops the corresponding GPU command execution. Shader abort deliberately causes a device loss (VK_ERROR_DEVICE_LOST).",
"type": "BOOL",
"default": false,
"dependence": {
"mode": "ALL",
"settings": [
{ "key": "gpuav_enable", "value": true }
]
}
},
{
"key": "gpuav_force_on_robustness",
"label": "Force on robustness features",
Expand Down
Loading
Loading