microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.11k stars 698 forks source link

cbuffer assert when using -fspv-debug=vulkan-with-source #5080

Open webez opened 1 year ago

webez commented 1 year ago

Hi, I am trying to generate debug info with -fspv-debug=vulkan-with-source but when the shader has a cbuffer, dxc.exe throws an assert in LowerTypeVisitor::visitInstruction

 assert(isa<SpirvDebugGlobalVariable>(debugInstruction) &&
             isa<HybridType>(debugSpirvType));

DebugSpirvType is clang::spirv::SpirvPointerType*

Code to reproduce:

cbuffer scene : register(b1) {
  const uint var;
}

void ps_main() {
}

Line arguments: -spirv -fspv-target-env=vulkan1.3 -T ps_6_2 -E ps_main -fvk-use-dx-layout -fspv-debug=vulkan-with-source

s-perron commented 1 year ago

For some reason DXC assumes that the internal representation of the type of the cbuffer is either a qualtype or a hybrid type. This is not true for the cbuffer.

I do not know how big a fix this will be. I don't know if the problem is the cbuffer type is being lowered to a spir-v type too early or if more cases need to be handled in DXC. I suspect more cases, but it is hard to say how wide spread the assumption goes.

s-perron commented 1 year ago

The test case passes if you remove -fvk-use-dx-layout.

Goshido commented 1 year ago

@s-perron do you have any insides when this issue could be fixed. Is it serious and requires big DXC refactoring?

Goshido commented 1 year ago

I tried DirectX Shader Compiler 1.7.2308.10004 a5b0488bc5b20659662bdfdad134c13cb376189b.

The compile error still exists:

Compiling: D:\Development\DXC-builds\Release-2023-08-03\bin\dxc.exe -HV 2021 -spirv -fvk-use-dx-layout -fspv-reduce-load-size -fspv-target-env=vulkan1.1 -enable-16bit-types -WX -I .\..\..\..\hlsl -I .\..\..\..\cpp\include\pbr -Od -fspv-debug=vulkan-with-source -E VS -T vs_6_7 -Fo .\..\..\..\assets\shaders\common_opaque.vs.spv .\..\..\..\hlsl\common_opaque.vs
Internal compiler error: access violation. Attempted to read from address 0x0000000000000000

Any progress?

s-perron commented 1 year ago

We have very few people working on DXC, and debug related bugs are not our highest priorities. However, you can feel free to contribute a fix. From what I saw in the initial investigation, the problem is that part of spirv emitter assumes the type of an instruction is not a spir-v type. It is expecting either a QualType or HybridType. When debug info is requested, the type is lowered to a spir-v type early, and causes the problem.

The fix should be to update the code to handle a spir-v type, and the rest of the down stream code to do the same. It is unclear how much code will have to be updated.

You can identify the location for the change by building DXC with assert enabled, and an assert will be triggered.

Goshido commented 1 year ago

Same issue in DXC v1.7.2308.10061, 1a3c179775b40906147e414d2ca5bf1dd5a40d3b

jeremy-lunarg commented 1 year ago

However, you can feel free to contribute a fix.

I'm investigating this to see how much work needs to be done. Thanks.