Skip to content

Commit 8266d38

Browse files
authored
Not init undef when recover init value for patch constant function. (#3141)
* Not init undef when recover init value for patch constant function. Also lower ConstantAggregateZero directly when lower matrix.
1 parent 7e92bbc commit 8266d38

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

lib/HLSL/HLMatrixLowerPass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ Value* HLMatrixLowerPass::getLoweredByValOperand(Value *Val, IRBuilder<> &Builde
370370
return LoweredVal;
371371
}
372372
}
373+
// Lower mat 0 to vec 0.
374+
if (isa<ConstantAggregateZero>(Val))
375+
return ConstantAggregateZero::get(LoweredTy);
373376

374377
// Return a mat-to-vec translation stub
375378
FunctionType *TranslationStubTy = FunctionType::get(LoweredTy, { Ty }, /* isVarArg */ false);

tools/clang/lib/CodeGen/CGHLSLMS.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,8 @@ void CGMSHLSLRuntime::FinishCodeGen() {
33533353
if (GV.getName() == "llvm.global_ctors")
33543354
continue;
33553355
Value *V = GV.getInitializer();
3356+
if (isa<UndefValue>(V))
3357+
continue;
33563358
B.CreateStore(V, &GV);
33573359
}
33583360
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// RUN: %dxc -E main -T hs_6_0 %s | FileCheck %s
2+
3+
// Make sure not crash.
4+
// CHECK:define void @"\01?patchConstantF@@YA?AUPatchConstantOutput@@V?$OutputPatch@UHsOutput@@$02@@@Z"()
5+
// CHECK:define void @main()
6+
struct ST
7+
{
8+
float4x4 m;
9+
10+
};
11+
12+
cbuffer S : register (b1)
13+
{
14+
float4x4 m;
15+
};
16+
17+
static const struct {
18+
19+
float4x4 m;
20+
} M = {m};
21+
22+
static ST staticST;
23+
24+
ST GetM()
25+
{
26+
ST Result;
27+
Result.m= M.m;
28+
return Result;
29+
}
30+
31+
ST GetST()
32+
{
33+
return GetM();
34+
}
35+
36+
struct HsInput
37+
{
38+
float4x4 mat : MAT;
39+
float4 Position : SV_Position;
40+
};
41+
42+
struct HsOutput
43+
{
44+
float4x4 mat : MAT;
45+
float4 Position : SV_Position;
46+
};
47+
48+
struct PatchConstantOutput
49+
{
50+
51+
float TessFactor[3] : SV_TessFactor;
52+
float InsideTessFactor : SV_InsideTessFactor;
53+
float4 m : M;
54+
};
55+
56+
PatchConstantOutput patchConstantF( const OutputPatch<HsOutput, 3 > I )
57+
{
58+
PatchConstantOutput O = (PatchConstantOutput)0;
59+
60+
staticST = GetST();
61+
O.m = mul (staticST.m, float4(1,3,2,3));
62+
return O;
63+
}
64+
65+
[domain("tri")]
66+
[patchconstantfunc("patchConstantF")]
67+
[outputcontrolpoints( 3 )]
68+
[maxtessfactor(12)]
69+
[partitioning("fractional_even")][outputtopology("triangle_cw")]
70+
HsOutput main( InputPatch< HsInput , 12 > I, uint ControlPointID : SV_OutputControlPointID )
71+
{
72+
73+
staticST = GetST();
74+
75+
HsOutput O = (HsOutput) 0;
76+
O.mat = staticST.m;
77+
return O;
78+
}

0 commit comments

Comments
 (0)