microsoft / DirectXShaderCompiler

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

Implicit cast from float1 to inout float3 hits an assert for DXIL #6796

Open Keenuts opened 1 month ago

Keenuts commented 1 month ago

Hello!

void bar(inout float3 param) {
}

[numthreads(1, 1, 1)]
void main() {
  float1 a = 0;
  bar(a);
}
$ dxc -T cs_6_6 -E main repro.hlsl
EmitNumericConversion can only cast between scalars or vectors of matching sizesdxc: DirectXShaderCompiler/tools/clang/lib/CodeGen/CGHLSLMS.cpp:4328: llvm::Value* ConvertScalarOrVector(clang::CodeGen::CGBuilderTy&, clang::CodeGen::CodeGenTypes&, llvm::Value*, clang::QualType, clang::QualType): Assertion `false && "EmitNumericConversion can only cast between scalars or vectors of " "matching sizes"' failed.
Aborted (core dumped)

This however is allowed and just warns for the implicit truncation.

void bar(inout float3 param) {
}

[numthreads(1, 1, 1)]
void main() {
  float a = 0;
  bar(a);
}

On the SPIR-V side, we accept this.

damyanp commented 1 month ago

@Keenuts: We don't think that float1 should implicitly extend to float3. Going forward, we expect that clang will reject this case.

In fact, we also have questions about whether or not the scalar case should be allowed. We haven't bottomed out yet on whether or not this case will be accepted in clang.

Moving to the HLSL 202x milestone - this is something we should tighten up in DXC to ensure that it is more closely aligned to the behavior in clang.