DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

Array as parameter of function

Open siliconvoodoo opened this issue 7 years ago • 3 comments

There is what seems to me like a bug in support for non-dimension specific array passing to a function. Consider this code:

float4 Func(float4 a[])
{
    return a[0];
}

float4 main() : SV_Target0
{
    float4 a[] = {float4(1,1,1,1), float4(1,1,1,1)};
    return Func(a);
}

fxc gives a nice

error X3072: 'a': array dimensions of function parameters must be explicit

but dxc does naught. no error no output, no code production no nothing. If you put a dimension then you get a reasonable output of

; ; Input signature: ; ; Name Index Mask Register SysValue Format Used ; -------------------- ----- ------ -------- -------- ------- ------ ; no parameters ; ; Output signature: ; ; Name Index Mask Register SysValue Format Used ; -------------------- ----- ------ -------- -------- ------- ------ ; SV_Target 0 xyzw 0 TARGET float xyzw ; ; ; Pipeline Runtime Information: ; ; Pixel Shader ; DepthOutput=0 ; SampleFrequency=0 ; ; ; Output signature: ; ; Name Index InterpMode DynIdx ; -------------------- ----- ---------------------- ------ ; SV_Target 0 ; ; Buffer Definitions: ; ; ; Resource Bindings: ; ; Name Type Format Dim ID HLSL Bind Count ; ------------------------------ ---------- ------- ----------- ------- -------------- ------ ; ; ; ViewId state: ; ; Number of inputs: 0, outputs: 4 ; Outputs dependent on ViewId: { } ; Inputs contributing to computation of Outputs: ; target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64" target triple = "dxil-ms-dx"

define void @main() { entry: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 0, float 1.000000e+00) ; StoreOutput(outputSigId,rowIndex,colIndex,value) call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 1, float 1.000000e+00) ; StoreOutput(outputSigId,rowIndex,colIndex,value) call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 2, float 1.000000e+00) ; StoreOutput(outputSigId,rowIndex,colIndex,value) call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 3, float 1.000000e+00) ; StoreOutput(outputSigId,rowIndex,colIndex,value) ret void }

; Function Attrs: nounwind declare void @dx.op.storeOutput.f32(i32, i32, i32, i8, float) #0

attributes #0 = { nounwind }

!llvm.ident = !{!0} !dx.version = !{!1} !dx.valver = !{!2} !dx.shaderModel = !{!3} !dx.typeAnnotations = !{!4} !dx.viewIdState = !{!8} !dx.entryPoints = !{!9}

!0 = !{!"clang version 3.7 (tags/RELEASE_370/final)"} !1 = !{i32 1, i32 0} !2 = !{i32 1, i32 3} !3 = !{!"ps", i32 6, i32 0} !4 = !{i32 1, void ()* @main, !5} !5 = !{!6} !6 = !{i32 0, !7, !7} !7 = !{} !8 = !{[2 x i32] [i32 0, i32 4]} !9 = !{void ()* @main, !"main", !10, null, null} !10 = !{null, !11, null} !11 = !{!12} !12 = !{i32 0, !"SV_Target", i8 9, i8 16, !13, i8 0, i32 1, i8 4, i32 0, i8 0, null} !13 = !{i32 0}

even though that's much bloated comapred to fxc's nice 4 little lines with color, but it's orthogonal.

siliconvoodoo avatar Nov 13 '18 10:11 siliconvoodoo

Thanks for reporting! The compiler is crashing on:

 	KernelBase.dll!00007fff0f555c69()	Unknown
 	dxcompiler.dll!llvm_assert(const char * _Message, const char * _File, unsigned int _Line, const char * _Function) Line 23	C++
>	dxcompiler.dll!`anonymous namespace'::SROA_Helper::RewriteBitCast(llvm::BitCastInst * BCI) Line 3112	C++
 	dxcompiler.dll!`anonymous namespace'::SROA_Helper::RewriteForScalarRepl(llvm::Value * V, llvm::IRBuilder<1,llvm::ConstantFolder,llvm::IRBuilderDefaultInserter<1> > & Builder) Line 3329	C++
 	dxcompiler.dll!`anonymous namespace'::SROA_Helper::DoScalarReplacement(llvm::Value * V, std::vector<llvm::Value *,std::allocator<llvm::Value *> > & Elts, llvm::IRBuilder<1,llvm::ConstantFolder,llvm::IRBuilderDefaultInserter<1> > & Builder, bool bFlatVector, bool hasPrecise, hlsl::DxilTypeSystem & typeSys, const llvm::DataLayout & DL, llvm::SmallVector<llvm::Value *,32> & DeadInsts) Line 3475	C++
 	dxcompiler.dll!`anonymous namespace'::SROA_HLSL::performScalarRepl(llvm::Function & F, hlsl::DxilTypeSystem & typeSys) Line 1615	C++
 	dxcompiler.dll!`anonymous namespace'::SROA_HLSL::runOnFunction(llvm::Function & F) Line 1078	C++
 	dxcompiler.dll!llvm::FPPassManager::runOnFunction(llvm::Function & F) Line 1548	C++
 	dxcompiler.dll!llvm::FPPassManager::runOnModule(llvm::Module & M) Line 1568	C++

Which makes this issue at least related to, if not a dupe of #1560 , which crashes in the same code.

tristanlabelle avatar Nov 13 '18 16:11 tristanlabelle

@MrTrillian while the symptom of this bug looks similar to #1560, this would likely need a different fix. Specifically, we should look to augment the error diagnostic of DXC (to match it with FXC in this case) which would mean that this would fail compilation much earlier instead of allowing it to go through later optimization passes..

vcsharma avatar Nov 16 '18 09:11 vcsharma

This is a bug, and still reproduces: https://godbolt.org/z/GvYeEb95d

This probably can't be fixed without larger fixes to parameter passing, it will likely be addressed in Clang. The DXC draft PR is: https://github.com/microsoft/DirectXShaderCompiler/pull/5249, but we're unlikely to ever land that in DXC.

llvm-beanz avatar May 29 '24 17:05 llvm-beanz