Vulkan: defer DebugValue/Declare when curScope is NULL#3845
Open
fengshanglantian wants to merge 1 commit into
Open
Vulkan: defer DebugValue/Declare when curScope is NULL#3845fengshanglantian wants to merge 1 commit into
fengshanglantian wants to merge 1 commit into
Conversation
curScope is explicitly cleared after every block-terminator opcode
(OpBranch/OpKill/OpReturn/...) further down in RegisterOp(). When the
SPIR-V stream interleaves NonSemantic.Shader.DebugInfo.100 DebugValue
or DebugDeclare in the gap between a block terminator and the next
OpDebugScope, the original code dereferenced NULL curScope -> SIGSEGV
with fault addr 0x8 (the parent field offset within ScopeData).
The else branch below already pushes the mapping into pendingMappings,
which is exactly the deferred path the comment above describes ('we
defer it hoping that we will encounter a scope later that's valid for
it'). Just guard the call.
Reproduced on RenderDoc 1.45 Release (Android arm64) after replacing
a Vulkan SM5 PS shader via ReplaceResource with a SPIR-V compiled by
dxc 1.8.2403 with -fspv-debug=vulkan-with-source, then clicking
Debug Pixel:
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8
#00 rdcspv::ScopeData::HasAncestor spirv_debug.h:639
baldurk#1 rdcspv::Debugger::RegisterOp spirv_debug_setup.cpp:4696
baldurk#2 rdcspv::Processor::Parse spirv_processor.cpp:483
baldurk#3 VulkanReplay::DebugPixel vk_shaderdebug.cpp:6253
baldurk#4 ReplayProxy::Proxied_DebugPixel replay_proxy.cpp:1645
e68f41a to
5347fd1
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Vulkan: defer DebugValue/Declare when curScope is NULL
Summary
The SPIR-V debugger setup pass has a NULL-deref hazard in
Debugger::RegisterOpwhen the SPIR-V stream interleavesNonSemantic.Shader.DebugInfo.100DebugValue/DebugDeclareinstructions between a block terminator and the next
OpDebugScope.This crashes Debug Pixel against any such shader. Add a one-line
NULL-check that routes the offending instruction to the existing
deferred-mapping fallback path.
Repro
Compile a small HLSL pixel shader with debug info embedded:
(any recent dxc —
1.8.2403reproduces; older versions also possible)In a Vulkan capture, replace the pixel shader's resource with the
SPV via
ReplayController::ReplaceResource(e.g. through thePython Shell), then select the affected drawcall and click
Debug Pixel.
The replay process crashes:
The fault address
0x8is the offset of theparentfield withinScopeData:Root cause
m_DebugInfo.curScopeis explicitly set to NULL after everyblock-terminator opcode (
spirv_debug_setup.cpp:4866in the sameRegisterOp):The
ShaderDbg::Declare/ShaderDbg::Valuecase (atspirv_debug_setup.cpp:4685) does:…with no NULL check, so any
DebugValue/DebugDeclarethat lands inthat gap dereferences NULL.
Fix
The pre-existing comment on these lines already describes the desired
behaviour for the "no valid scope" case:
…and the existing
elsebranch already implements the deferral viam_DebugInfo.pendingMappings.push_back(...). So the fix is just toguard the call:
NULL
curScopenow flows into the existingpendingMappingsdeferpath instead of crashing.
Tested
Pixel 9 Pro XL (Android 16, Tensor G4 / Mali GPU). Same Vulkan
capture + replacement SPV that reproduced the crash now reaches
Break Mode in the Debug Pixel view; F10/F11 step over/into the HLSL
source.
exists on PC. Crash also reproduces on PC Release build with the
same dxc-built SPV; the fix resolves it there too.
No existing test exercises this code path that I could find — the
debug instructions involved come from external shader compilers and
the project's existing
Debuggertests don't driveNonSemantic.Shader.DebugInfo.100 SPIR-V end-to-end. Happy to add a
small unit test if you can point at a good fixture pattern.
Scope
Single one-line behaviour change with surrounding comment update; no
API change, no behaviour change for the non-NULL case.