Repository navigation
gpuav: Add ShaderAbort support #13756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
spencer-lunarg
wants to merge
1
commit into
KhronosGroup:main
Choose a base branch
from
spencer-lunarg:spencer-lunarg-abort
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). | ||
|
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.