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

Array as parameter of function #1702

Open
siliconvoodoo opened this issue Nov 13, 2018 · 3 comments
Open

Array as parameter of function #1702

siliconvoodoo opened this issue Nov 13, 2018 · 3 comments
Assignees
Labels
bug Bug, regression, crash shader-linking Bugs related to library targets and linking
Milestone

Comments

@siliconvoodoo
Copy link

siliconvoodoo commented Nov 13, 2018

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.

@tristanlabelle
Copy link
Contributor

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.

@vcsharma
Copy link
Contributor

@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..

@tristanlabelle tristanlabelle added the bug Bug, regression, crash label Feb 26, 2019
@llvm-beanz llvm-beanz added this to the Dormant milestone May 29, 2024
@llvm-beanz
Copy link
Collaborator

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: #5249, but we're unlikely to ever land that in DXC.

@llvm-beanz llvm-beanz added the shader-linking Bugs related to library targets and linking label May 29, 2024
@llvm-beanz llvm-beanz moved this to Triaged in HLSL Triage May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash shader-linking Bugs related to library targets and linking
Projects
Status: Triaged
Development

No branches or pull requests

4 participants