pub enum ShaderPanicStrategy {
SilentExit,
DebugPrintfThenExit {
print_inputs: bool,
print_backtrace: bool,
},
UNSOUND_DO_NOT_USE_UndefinedBehaviorViaUnreachable,
}
Expand description
Strategy used to handle Rust panic!
s in shaders compiled to SPIR-V.
Variants§
SilentExit
Return from shader entry-point with no side-effects (default).
While similar to the standard SPIR-V OpTerminateInvocation
, this is
not limited to fragment shaders, and instead supports all shaders
(as it’s handled via control-flow rewriting, instead of SPIR-V features).
DebugPrintfThenExit
Like SilentExit
, but also using debugPrintf
to report the panic in
a way that can reach the user, before returning from the entry-point.
Will automatically require the SPV_KHR_non_semantic_info
extension,
as debugPrintf
uses a “non-semantic extended instruction set”.
If you have multiple entry-points, you may need to also enable the
multimodule
node (see https://github.com/KhronosGroup/SPIRV-Tools/issues/4892).
Note: actually obtaining the debugPrintf
output requires:
- Vulkan Validation Layers (from e.g. the Vulkan SDK)
- (they contain the
debugPrintf
implementation, a SPIR-V -> SPIR-V translation) - set the
VK_LOADER_LAYERS_ENABLE=VK_LAYER_KHRONOS_validation
environment variable to easily enable them without any code changes - alternatively,
"VK_LAYER_KHRONOS_validation"
can be passed during instance creation, to enable them programmatically
- (they contain the
- Validation Layers’
debugPrintf
support:- set the
VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT
environment variable to easily enable thedebugPrintf
support - alternatively,
VkValidationFeaturesEXT
during instance creation, or thekhronos_validation.enables
field invk_layer_settings.txt
, can be used to enableVK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT
(see also https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/main/docs/debug_printf.md)
- set the
- for outputting the
debugPrintf
messages sent back from the GPU:- set the
DEBUG_PRINTF_TO_STDOUT=1
environment variable if you don’t plan on customizing the reporting (see below for alternatives)
- set the
- for
wgpu
:- required:
wgpu::Features::SPIRV_SHADER_PASSTHROUGH
(Naga lacksdebugPrintf
) - optional: building in debug mode (and/or with debug-assertions enabled),
to enable
wgpu
logging/debug support- (the debug assertions requirement may be lifted in future
wgpu
versions) - this uses
VK_EXT_debug_utils
internally, and is a better-integrated alternative to just settingDEBUG_PRINTF_TO_STDOUT=1
RUST_LOG=wgpu_hal::vulkan=info
(or equivalent) will enable said output (asdebugPrintf
messages have the “info” level)RUST_LOG
controlsenv_logger
, which isn’t itself required, but somelog
/tracing
subscriber is needed to get any output
- (the debug assertions requirement may be lifted in future
- required:
- for Vulkan (e.g. via
ash
):- required: enabling the
VK_KHR_shader_non_semantic_info
Vulkan Device extension - optional: as described above, enabling the Validation Layers and
their
debugPrintf
support can be done during instance creation - optional: integrating
VK_EXT_debug_utils
allows more reporting flexibility thanDEBUG_PRINTF_TO_STDOUT=1
)
- required: enabling the
Fields
print_inputs: bool
Whether to also print the entry-point inputs (excluding buffers/resources), which should uniquely identify the panicking shader invocation.
print_backtrace: bool
Whether to also print a “backtrace” (i.e. the chain of function calls
that led to the panic!
).
As there is no way to dynamically compute this information, the string
containing the full backtrace of each panic!
is statically generated,
meaning this option could significantly increase binary size.
UNSOUND_DO_NOT_USE_UndefinedBehaviorViaUnreachable
Warning: this is unsound (i.e. adds Undefined Behavior to safe Rust code)
This option only exists for testing (hence the unfriendly name it has),
and more specifically testing whether conditional panics are responsible
for performance differences when upgrading from older Rust-GPU versions
(which used infinite loops for panics, that spirv-opt
/drivers could’ve
sometimes treated as UB, and optimized as if they were impossible to reach).
Unlike those infinite loops, however, this uses OpUnreachable
, so it
forces the old worst-case (all panic!
s become UB and are optimized out).
Trait Implementations§
source§impl Clone for ShaderPanicStrategy
impl Clone for ShaderPanicStrategy
source§fn clone(&self) -> ShaderPanicStrategy
fn clone(&self) -> ShaderPanicStrategy
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ShaderPanicStrategy
impl Debug for ShaderPanicStrategy
source§impl PartialEq for ShaderPanicStrategy
impl PartialEq for ShaderPanicStrategy
source§fn eq(&self, other: &ShaderPanicStrategy) -> bool
fn eq(&self, other: &ShaderPanicStrategy) -> bool
self
and other
values to be equal, and is used
by ==
.