-
Notifications
You must be signed in to change notification settings - Fork 827
Description
Title
[SPIR-V] Silent crash when using any WaveMultiPrefix* intrinsic with first arg of type uint*
Minimal repro steps
- Compile repro_shader.txt with
dxc.exe -E main -T ps_6_5 -spirv repro_shader.txt
StructuredBuffer<uint4> g_mask;
uint4 main(uint input : ATTR0) : SV_Target {
uint4 mask = g_mask[0];
uint4 res = uint4(0,0,0,0);
res += WaveMultiPrefixBitAnd(input, mask);
res += WaveMultiPrefixBitOr(input, mask);
res += WaveMultiPrefixBitXor(input, mask);
res += WaveMultiPrefixProduct(input, mask);
res += WaveMultiPrefixSum(input, mask);
//res += WaveMultiPrefixBitAnd((int4)input, mask); // error: WaveMultiPrefixBitAnd intrinsic function unimplemented
//res += WaveMultiPrefixBitOr((int4)input, mask); // error: WaveMultiPrefixBitOr intrinsic function unimplemented
//res += WaveMultiPrefixBitXor((int4), mask); // error: WaveMultiPrefixBitXor intrinsic function unimplemented
//res += WaveMultiPrefixProduct((int4)input, mask); // error: WaveMultiPrefixProduct intrinsic function unimplemented
//res += WaveMultiPrefixSum((int4)input, mask); // error: WaveMultiPrefixSum intrinsic function unimplemented
return res;
}
Expected result
Output is generated successfully as when using the DXIL backend. If certain wave ops are not yet supported in the SPIR-V backend - error messages explaining lack of wave intrinsic support are printed for the user.
Actual result
Compiler crashes with nothing printed to stdout. Running with a debugger attached the crash is caused by a NULL ptr dereference at:
dxcompiler.dll!clang::spirv::SpirvInstruction::isRelaxedPrecision() Line 165
at c:\repos\dxc\tools\clang\include\clang\spirv\spirvinstruction.h(165)
dxcompiler.dll!clang::spirv::SpirvEmitter::processBinaryOp(const clang::Expr * lhs, const clang::Expr * rhs, clang::BinaryOperatorKind opcode, clang::QualType computationType, clang::QualType resultType, clang::SourceRange sourceRange, clang::SourceLocation loc, clang::spirv::SpirvInstruction * * lhsInfo, spv::Op mandateGenOpcode) Line 5495
at c:\repos\dxc\tools\clang\lib\spirv\spirvemitter.cpp(5495)
dxcompiler.dll!clang::spirv::SpirvEmitter::doCompoundAssignOperator(const clang::CompoundAssignOperator * expr) Line 2740
at c:\repos\dxc\tools\clang\lib\spirv\spirvemitter.cpp(2740)
dxcompiler.dll!clang::spirv::SpirvEmitter::doExpr(const clang::Expr * expr) Line 819
at c:\repos\dxc\tools\clang\lib\spirv\spirvemitter.cpp(819)
dxcompiler.dll!clang::spirv::SpirvEmitter::doStmt(const clang::Stmt * stmt, llvm::ArrayRef<clang::Attr const *> attrs) Line 781
at c:\repos\dxc\tools\clang\lib\spirv\spirvemitter.cpp(781)
dxcompiler.dll!clang::spirv::SpirvEmitter::doStmt(const clang::Stmt * stmt, llvm::ArrayRef<clang::Attr const *> attrs) Line 752
at c:\repos\dxc\tools\clang\lib\spirv\spirvemitter.cpp(752)
dxcompiler.dll!clang::spirv::SpirvEmitter::doFunctionDecl(const clang::FunctionDecl * decl) Line 1071
at c:\repos\dxc\tools\clang\lib\spirv\spirvemitter.cpp(1071)
dxcompiler.dll!clang::spirv::SpirvEmitter::doDecl(const clang::Decl * decl) Line 735
at c:\repos\dxc\tools\clang\lib\spirv\spirvemitter.cpp(735)
dxcompiler.dll!clang::spirv::SpirvEmitter::HandleTranslationUnit(clang::ASTContext & context) Line 617
at c:\repos\dxc\tools\clang\lib\spirv\spirvemitter.cpp(617)
dxcompiler.dll!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 162
at c:\repos\dxc\tools\clang\lib\parse\parseast.cpp(162)
dxcompiler.dll!clang::ASTFrontendAction::ExecuteAction() Line 556
at c:\repos\dxc\tools\clang\lib\frontend\frontendaction.cpp(556)
dxcompiler.dll!clang::FrontendAction::Execute() Line 468
at c:\repos\dxc\tools\clang\lib\frontend\frontendaction.cpp(468)
dxcompiler.dll!DxcCompiler::Compile(const DxcBuffer * pSource, const wchar_t * * pArguments, unsigned int argCount, IDxcIncludeHandler * pIncludeHandler, const _GUID & riid, void * * ppResult) Line 754
at c:\repos\dxc\tools\clang\tools\dxcompiler\dxcompilerobj.cpp(754)
dxcompiler.dll!hlsl::DxcCompilerAdapter::WrapCompile(int bPreprocess, IDxcBlob * pSource, const wchar_t * pSourceName, const wchar_t * pEntryPoint, const wchar_t * pTargetProfile, const wchar_t * * pArguments, unsigned int argCount, const DxcDefine * pDefines, unsigned int defineCount, IDxcIncludeHandler * pIncludeHandler, IDxcOperationResult * * ppResult, wchar_t * * ppDebugBlobName, IDxcBlob * * ppDebugBlob) Line 1389
at c:\repos\dxc\tools\clang\tools\dxcompiler\dxcompilerobj.cpp(1389)
dxcompiler.dll!hlsl::DxcCompilerAdapter::CompileWithDebug(IDxcBlob * pSource, const wchar_t * pSourceName, const wchar_t * pEntryPoint, const wchar_t * pTargetProfile, const wchar_t * * pArguments, unsigned int argCount, const DxcDefine * pDefines, unsigned int defineCount, IDxcIncludeHandler * pIncludeHandler, IDxcOperationResult * * ppResult, wchar_t * * ppDebugBlobName, IDxcBlob * * ppDebugBlob) Line 1303
at c:\repos\dxc\tools\clang\tools\dxcompiler\dxcompilerobj.cpp(1303)
dxcompiler.dll!hlsl::DxcCompilerAdapter::Compile(IDxcBlob * pSource, const wchar_t * pSourceName, const wchar_t * pEntryPoint, const wchar_t * pTargetProfile, const wchar_t * * pArguments, unsigned int argCount, const DxcDefine * pDefines, unsigned int defineCount, IDxcIncludeHandler * pIncludeHandler, IDxcOperationResult * * ppResult) Line 72
at c:\repos\dxc\tools\clang\tools\dxcompiler\dxcompileradapter.h(72)
dxc.exe!DxcContext::Compile() Line 802
at c:\repos\dxc\tools\clang\tools\dxclib\dxc.cpp(802)
dxc.exe!dxc::main(int argc, const wchar_t * * argv_) Line 1262
at c:\repos\dxc\tools\clang\tools\dxclib\dxc.cpp(1262)
dxc.exe!wmain(int argc, const wchar_t * * argv_) Line 22
at c:\repos\dxc\tools\clang\tools\dxc\dxcmain.cpp(22)
dxc.exe!invoke_main() Line 91
at d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(91)
dxc.exe!__scrt_common_main_seh() Line 288
at d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(288)
dxc.exe!__scrt_common_main() Line 331
at d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(331)
dxc.exe!wmainCRTStartup() Line 17
at d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_wmain.cpp(17)
kernel32.dll!00007ffbb5ab7974()
ntdll.dll!00007ffbb733a271()
Further technical details
Seems that only unit scalars and vectors passed as first arguments to these wave intrinsic will trigger the crash e.g. casting with (int4) as seen in the comments will print errors as expected but if any of the uncommented lines are not removed first - the crash will silence the error message.
The repro shader is based on sm_6_5_wave.hlsl from the DXC repo so this issue might be known internally I but couldn't find a bug report for it.
some lines which don't trigger the crash by themselves were removed, however, the crash still happens on the original file.