Skip to content
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

[SPIRV] Invalid shader crashes compiler #3045

Closed
Jasper-Bekkers opened this issue Jul 21, 2020 · 2 comments · Fixed by #3064
Closed

[SPIRV] Invalid shader crashes compiler #3045

Jasper-Bekkers opened this issue Jul 21, 2020 · 2 comments · Fixed by #3064
Assignees
Labels
spirv Work related to SPIR-V

Comments

@Jasper-Bekkers
Copy link

Repro:

struct Jasper {
    float4 asdf;
};

StructuredBuffer<uint> g_input : register(t0, space0);
RWStructuredBuffer<uint> g_output : register(u1, space0);
ConstantBuffer<Jasper> g_constant : register(b2, space0);
StructuredBuffer<uint> g_bindlessInput[] : register(t0, space1);
Texture2D<uint> g_texture2d : register(t0, space2);
RWTexture2D<uint> g_rwtexture2d : register(u1, space3);


[numthreads(64, 1, 1)]
void main(int threadId: SV_DispatchThreadID)
{
    g_output[threadId] = g_input[threadId] + g_constant.asdf + g_bindlessInput[threadId][threadId] + g_texture2d.Load(0, 0) + g_rwtexture2d.Load(0, 0);
}

Invoking the compiler with like this outputs an error:

> dxc -Tcs_6_3 repro.hlsl
repro.hlsl:16:24: warning: implicit truncation of vector type [-Wconversion]
    g_output[threadId] = g_input[threadId] + g_constant.asdf + g_bindlessInput[threadId][threadId] + g_texture2d.Load(0, 0) + g_rwtexture2d.Load(0, 0);
                       ^
repro.hlsl:16:149: error: cannot compile this unexpected cast lvalue yet
    g_output[threadId] = g_input[threadId] + g_constant.asdf + g_bindlessInput[threadId][threadId] + g_texture2d.Load(0, 0) + g_rwtexture2d.Load(0, 0);

However, adding -spirv crashes the compiler; instead yielding no output:

> dxc -Tcs_6_3 -spirv repro.hlsl

Relevant callstack:

>	[Inline Frame] dxcompiler.dll!spvtools::opt::Instruction::opcode() Line 219	C++
 	dxcompiler.dll!spvtools::opt::Instruction::GetBaseAddress() Line 228	C++
 	[Inline Frame] dxcompiler.dll!spvtools::opt::MemPass::GetPtr(unsigned int) Line 108	C++
 	dxcompiler.dll!spvtools::opt::MemPass::GetPtr(spvtools::opt::Instruction * ip, unsigned int * varId) Line 132	C++
 	dxcompiler.dll!spvtools::opt::AggressiveDCEPass::AggressiveDCE(spvtools::opt::Function * func) Line 364	C++
 	[Inline Frame] dxcompiler.dll!std::_Func_class<bool,spvtools::opt::Function *>::operator()(spvtools::opt::Function * <_Args_0>) Line 899	C++
 	dxcompiler.dll!spvtools::opt::IRContext::ProcessCallTreeFromRoots(std::function<bool __cdecl(spvtools::opt::Function *)> & pfn, std::queue<unsigned int,std::deque<unsigned int,std::allocator<unsigned int>>> * roots) Line 899	C++
 	dxcompiler.dll!spvtools::opt::IRContext::ProcessEntryPointCallTree(std::function<bool __cdecl(spvtools::opt::Function *)> & pfn) Line 854	C++
 	dxcompiler.dll!spvtools::opt::AggressiveDCEPass::ProcessImpl() Line 655	C++
 	dxcompiler.dll!spvtools::opt::Pass::Run(spvtools::opt::IRContext * ctx) Line 41	C++
 	dxcompiler.dll!spvtools::opt::PassManager::Run(spvtools::opt::IRContext * context) Line 51	C++
 	dxcompiler.dll!spvtools::Optimizer::Run(const unsigned int * original_binary, const unsigned __int64 original_binary_size, std::vector<unsigned int,std::allocator<unsigned int>> * optimized_binary, spv_optimizer_options_t * const opt_options) Line 576	C++
 	dxcompiler.dll!clang::spirv::SpirvEmitter::spirvToolsOptimize(std::vector<unsigned int,std::allocator<unsigned int>> * mod, std::string * messages) Line 11661	C++
 	dxcompiler.dll!clang::spirv::SpirvEmitter::HandleTranslationUnit(clang::ASTContext & context) Line 603	C++
 	dxcompiler.dll!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 162	C++
 	dxcompiler.dll!clang::ASTFrontendAction::ExecuteAction() Line 554	C++
 	dxcompiler.dll!clang::FrontendAction::Execute() Line 469	C++
 	dxcompiler.dll!DxcCompiler::Compile(const DxcBuffer * pSource, const wchar_t * * pArguments, unsigned int argCount, IDxcIncludeHandler * pIncludeHandler, const _GUID & riid, void * * ppResult) Line 736	C++
 	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 1376	C++
 	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 1282	C++
 	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	C++
 	dxc.exe!DxcContext::Compile() Line 810	C++
 	dxc.exe!dxc::main(int argc, const wchar_t * * argv_) Line 1264	C++
 	[Inline Frame] dxc.exe!invoke_main() Line 90	C++
 	dxc.exe!__scrt_common_main_seh() Line 288	C++
 	kernel32.dll!00007ffb002d7bd4()	Unknown
 	ntdll.dll!00007ffb00a2ce51()	Unknown
@Jasper-Bekkers
Copy link
Author

Another one for @ehsannas to triage through I suppose 😊

@ehsannas ehsannas added the spirv Work related to SPIR-V label Jul 23, 2020
@ehsannas
Copy link
Contributor

Thanks for reporting @Jasper-Bekkers

ehsannas added a commit to ehsannas/DirectXShaderCompiler that referenced this issue Aug 4, 2020
@ehsannas ehsannas self-assigned this Aug 4, 2020
ehsannas added a commit that referenced this issue Aug 20, 2020
* [spirv] Handle invalid arg for residency code.

Fixes #3045

* add comments about residencyCode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spirv Work related to SPIR-V
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants