Skip to content

Commit f65abd9

Browse files
authored
Merge branch 'main' into create_DxcDllExtValidationSupport
2 parents 15fceac + a47537f commit f65abd9

File tree

67 files changed

+2695
-1340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2695
-1340
lines changed

lib/DXIL/DxilOperations.cpp

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -113,32 +113,32 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
113113
"isSpecialFloat",
114114
Attribute::ReadNone,
115115
1,
116-
{{0x3}},
117-
{{0x0}}}, // Overloads: hf
116+
{{0x403}},
117+
{{0x3}}}, // Overloads: hf<hf
118118
{OC::IsInf,
119119
"IsInf",
120120
OCC::IsSpecialFloat,
121121
"isSpecialFloat",
122122
Attribute::ReadNone,
123123
1,
124-
{{0x3}},
125-
{{0x0}}}, // Overloads: hf
124+
{{0x403}},
125+
{{0x3}}}, // Overloads: hf<hf
126126
{OC::IsFinite,
127127
"IsFinite",
128128
OCC::IsSpecialFloat,
129129
"isSpecialFloat",
130130
Attribute::ReadNone,
131131
1,
132-
{{0x3}},
133-
{{0x0}}}, // Overloads: hf
132+
{{0x403}},
133+
{{0x3}}}, // Overloads: hf<hf
134134
{OC::IsNormal,
135135
"IsNormal",
136136
OCC::IsSpecialFloat,
137137
"isSpecialFloat",
138138
Attribute::ReadNone,
139139
1,
140-
{{0x3}},
141-
{{0x0}}}, // Overloads: hf
140+
{{0x403}},
141+
{{0x3}}}, // Overloads: hf<hf
142142
{OC::Cos,
143143
"Cos",
144144
OCC::Unary,
@@ -301,16 +301,16 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
301301
"unaryBits",
302302
Attribute::ReadNone,
303303
1,
304-
{{0xe0}},
305-
{{0x0}}}, // Overloads: wil
304+
{{0x4e0}},
305+
{{0xe0}}}, // Overloads: wil<wil
306306
{OC::FirstbitLo,
307307
"FirstbitLo",
308308
OCC::UnaryBits,
309309
"unaryBits",
310310
Attribute::ReadNone,
311311
1,
312-
{{0xe0}},
313-
{{0x0}}}, // Overloads: wil
312+
{{0x4e0}},
313+
{{0xe0}}}, // Overloads: wil<wil
314314

315315
// Unary uint
316316
{OC::FirstbitHi,
@@ -319,8 +319,8 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
319319
"unaryBits",
320320
Attribute::ReadNone,
321321
1,
322-
{{0xe0}},
323-
{{0x0}}}, // Overloads: wil
322+
{{0x4e0}},
323+
{{0xe0}}}, // Overloads: wil<wil
324324

325325
// Unary int
326326
{OC::FirstbitSHi,
@@ -329,8 +329,8 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
329329
"unaryBits",
330330
Attribute::ReadNone,
331331
1,
332-
{{0xe0}},
333-
{{0x0}}}, // Overloads: wil
332+
{{0x4e0}},
333+
{{0xe0}}}, // Overloads: wil<wil
334334

335335
// Binary float
336336
{OC::FMax,
@@ -765,32 +765,32 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
765765
"unary",
766766
Attribute::ReadNone,
767767
1,
768-
{{0x3}},
769-
{{0x0}}}, // Overloads: hf
768+
{{0x403}},
769+
{{0x3}}}, // Overloads: hf<hf
770770
{OC::DerivCoarseY,
771771
"DerivCoarseY",
772772
OCC::Unary,
773773
"unary",
774774
Attribute::ReadNone,
775775
1,
776-
{{0x3}},
777-
{{0x0}}}, // Overloads: hf
776+
{{0x403}},
777+
{{0x3}}}, // Overloads: hf<hf
778778
{OC::DerivFineX,
779779
"DerivFineX",
780780
OCC::Unary,
781781
"unary",
782782
Attribute::ReadNone,
783783
1,
784-
{{0x3}},
785-
{{0x0}}}, // Overloads: hf
784+
{{0x403}},
785+
{{0x3}}}, // Overloads: hf<hf
786786
{OC::DerivFineY,
787787
"DerivFineY",
788788
OCC::Unary,
789789
"unary",
790790
Attribute::ReadNone,
791791
1,
792-
{{0x3}},
793-
{{0x0}}}, // Overloads: hf
792+
{{0x403}},
793+
{{0x3}}}, // Overloads: hf<hf
794794

795795
// Pixel shader
796796
{OC::EvalSnapped,
@@ -3787,9 +3787,17 @@ Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
37873787
Type *pPos = GetSamplePosType();
37883788
Type *pV = Type::getVoidTy(m_Ctx);
37893789
Type *pI1 = Type::getInt1Ty(m_Ctx);
3790+
Type *pOlTplI1 = Type::getInt1Ty(m_Ctx);
37903791
Type *pI8 = Type::getInt8Ty(m_Ctx);
37913792
Type *pI16 = Type::getInt16Ty(m_Ctx);
37923793
Type *pI32 = Type::getInt32Ty(m_Ctx);
3794+
Type *pOlTplI32 = Type::getInt32Ty(m_Ctx);
3795+
if (pOverloadType->isVectorTy()) {
3796+
pOlTplI32 =
3797+
VectorType::get(pOlTplI32, pOverloadType->getVectorNumElements());
3798+
pOlTplI1 = VectorType::get(pOlTplI1, pOverloadType->getVectorNumElements());
3799+
}
3800+
37933801
Type *pPI32 = Type::getInt32PtrTy(m_Ctx);
37943802
(void)(pPI32); // Currently unused.
37953803
Type *pI64 = Type::getInt64Ty(m_Ctx);
@@ -3878,22 +3886,22 @@ Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
38783886
A(pETy);
38793887
break;
38803888
case OpCode::IsNaN:
3881-
A(pI1);
3889+
A(pOlTplI1);
38823890
A(pI32);
38833891
A(pETy);
38843892
break;
38853893
case OpCode::IsInf:
3886-
A(pI1);
3894+
A(pOlTplI1);
38873895
A(pI32);
38883896
A(pETy);
38893897
break;
38903898
case OpCode::IsFinite:
3891-
A(pI1);
3899+
A(pOlTplI1);
38923900
A(pI32);
38933901
A(pETy);
38943902
break;
38953903
case OpCode::IsNormal:
3896-
A(pI1);
3904+
A(pOlTplI1);
38973905
A(pI32);
38983906
A(pETy);
38993907
break;
@@ -3997,26 +4005,26 @@ Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
39974005
A(pETy);
39984006
break;
39994007
case OpCode::Countbits:
4000-
A(pI32);
4008+
A(pOlTplI32);
40014009
A(pI32);
40024010
A(pETy);
40034011
break;
40044012
case OpCode::FirstbitLo:
4005-
A(pI32);
4013+
A(pOlTplI32);
40064014
A(pI32);
40074015
A(pETy);
40084016
break;
40094017

40104018
// Unary uint
40114019
case OpCode::FirstbitHi:
4012-
A(pI32);
4020+
A(pOlTplI32);
40134021
A(pI32);
40144022
A(pETy);
40154023
break;
40164024

40174025
// Unary int
40184026
case OpCode::FirstbitSHi:
4019-
A(pI32);
4027+
A(pOlTplI32);
40204028
A(pI32);
40214029
A(pETy);
40224030
break;
@@ -4661,7 +4669,7 @@ Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
46614669
A(pI1);
46624670
break;
46634671
case OpCode::WaveActiveAllEqual:
4664-
A(pI1);
4672+
A(pOlTplI1);
46654673
A(pI32);
46664674
A(pETy);
46674675
break;
@@ -5397,7 +5405,7 @@ Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
53975405

53985406
// Quad Wave Ops
53995407
case OpCode::QuadVote:
5400-
A(pI1);
5408+
A(pOlTplI1);
54015409
A(pI32);
54025410
A(pI1);
54035411
A(pI8);

lib/HLSL/DxilConvergent.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ class DxilConvergentMark : public ModulePass {
3838
public:
3939
static char ID; // Pass identification, replacement for typeid
4040
explicit DxilConvergentMark() : ModulePass(ID) {}
41+
bool SupportsVectors = false;
4142

4243
StringRef getPassName() const override { return "DxilConvergentMark"; }
4344

4445
bool runOnModule(Module &M) override {
45-
if (M.HasHLModule()) {
46-
const ShaderModel *SM = M.GetHLModule().GetShaderModel();
47-
if (!SM->IsPS() && !SM->IsLib() &&
48-
(!SM->IsSM66Plus() || (!SM->IsCS() && !SM->IsMS() && !SM->IsAS())))
49-
return false;
50-
}
46+
const ShaderModel *SM = M.GetOrCreateHLModule().GetShaderModel();
47+
// Can skip if in a shader and version that doesn't support derivatives.
48+
if (!SM->IsPS() && !SM->IsLib() &&
49+
(!SM->IsSM66Plus() || (!SM->IsCS() && !SM->IsMS() && !SM->IsAS())))
50+
return false;
51+
SupportsVectors = SM->IsSM69Plus();
52+
5153
bool bUpdated = false;
5254

5355
for (Function &F : M.functions()) {
@@ -87,7 +89,14 @@ char DxilConvergentMark::ID = 0;
8789

8890
void DxilConvergentMark::MarkConvergent(Value *V, IRBuilder<> &Builder,
8991
Module &M) {
90-
Type *Ty = V->getType()->getScalarType();
92+
Type *Ty = V->getType();
93+
bool NeedVectorExpansion = false;
94+
VectorType *VTy = dyn_cast<VectorType>(Ty);
95+
if (VTy && (!SupportsVectors || VTy->getNumElements() == 1)) {
96+
Ty = Ty->getScalarType();
97+
NeedVectorExpansion = true;
98+
}
99+
91100
// Only work on vector/scalar types.
92101
if (Ty->isAggregateType() || Ty->isPointerTy())
93102
return;
@@ -98,7 +107,8 @@ void DxilConvergentMark::MarkConvergent(Value *V, IRBuilder<> &Builder,
98107
os.flush();
99108
Function *ConvF = cast<Function>(M.getOrInsertFunction(str, FT));
100109
ConvF->addFnAttr(Attribute::AttrKind::Convergent);
101-
if (VectorType *VT = dyn_cast<VectorType>(V->getType())) {
110+
if (NeedVectorExpansion) {
111+
VectorType *VT = cast<VectorType>(V->getType());
102112
Value *ConvV = UndefValue::get(V->getType());
103113
std::vector<ExtractElementInst *> extractList(VT->getNumElements());
104114
for (unsigned i = 0; i < VT->getNumElements(); i++) {

lib/HLSL/HLOperationLower.cpp

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,42 +2083,58 @@ Value *TranslateFirstbitHi(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
20832083
HLOperationLowerHelper &helper,
20842084
HLObjectOperationLowerHelper *pObjHelper,
20852085
bool &Translated) {
2086-
Value *firstbitHi =
2087-
TrivialUnaryOperationRet(CI, IOP, opcode, helper, pObjHelper, Translated);
2088-
// firstbitHi == -1? -1 : (bitWidth-1 -firstbitHi);
2086+
hlsl::OP *OP = &helper.hlslOP;
20892087
IRBuilder<> Builder(CI);
2090-
Constant *neg1 = Builder.getInt32(-1);
2091-
Value *src = CI->getArgOperand(HLOperandIndex::kUnaryOpSrc0Idx);
2088+
Value *Src = CI->getArgOperand(HLOperandIndex::kUnaryOpSrc0Idx);
2089+
2090+
Type *Ty = Src->getType();
2091+
Type *RetTy = Type::getInt32Ty(CI->getContext());
2092+
unsigned NumElements = 0;
2093+
if (Ty->isVectorTy()) {
2094+
NumElements = Ty->getVectorNumElements();
2095+
RetTy = VectorType::get(RetTy, NumElements);
2096+
}
2097+
2098+
Constant *OpArg = OP->GetU32Const((unsigned)opcode);
2099+
Value *Args[] = {OpArg, Src};
2100+
2101+
Value *FirstbitHi =
2102+
TrivialDxilOperation(opcode, Args, Ty, RetTy, OP, Builder);
20922103

2093-
Type *Ty = src->getType();
20942104
IntegerType *EltTy = cast<IntegerType>(Ty->getScalarType());
2095-
Constant *bitWidth = Builder.getInt32(EltTy->getBitWidth() - 1);
2105+
Constant *Neg1 = Builder.getInt32(-1);
2106+
Constant *BitWidth = Builder.getInt32(EltTy->getBitWidth() - 1);
20962107

2097-
if (Ty == Ty->getScalarType()) {
2098-
Value *sub = Builder.CreateSub(bitWidth, firstbitHi);
2099-
Value *cond = Builder.CreateICmpEQ(neg1, firstbitHi);
2100-
return Builder.CreateSelect(cond, neg1, sub);
2101-
} else {
2102-
Value *result = UndefValue::get(CI->getType());
2103-
unsigned vecSize = Ty->getVectorNumElements();
2104-
for (unsigned i = 0; i < vecSize; i++) {
2105-
Value *EltFirstBit = Builder.CreateExtractElement(firstbitHi, i);
2106-
Value *sub = Builder.CreateSub(bitWidth, EltFirstBit);
2107-
Value *cond = Builder.CreateICmpEQ(neg1, EltFirstBit);
2108-
Value *Elt = Builder.CreateSelect(cond, neg1, sub);
2109-
result = Builder.CreateInsertElement(result, Elt, i);
2110-
}
2111-
return result;
2108+
if (NumElements > 0) {
2109+
Neg1 = ConstantVector::getSplat(NumElements, Neg1);
2110+
BitWidth = ConstantVector::getSplat(NumElements, BitWidth);
21122111
}
2112+
2113+
Value *Sub = Builder.CreateSub(BitWidth, FirstbitHi);
2114+
Value *Cond = Builder.CreateICmpEQ(Neg1, FirstbitHi);
2115+
return Builder.CreateSelect(Cond, Neg1, Sub);
21132116
}
21142117

21152118
Value *TranslateFirstbitLo(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
21162119
HLOperationLowerHelper &helper,
21172120
HLObjectOperationLowerHelper *pObjHelper,
21182121
bool &Translated) {
2119-
Value *firstbitLo =
2120-
TrivialUnaryOperationRet(CI, IOP, opcode, helper, pObjHelper, Translated);
2121-
return firstbitLo;
2122+
hlsl::OP *OP = &helper.hlslOP;
2123+
IRBuilder<> Builder(CI);
2124+
Value *Src = CI->getArgOperand(HLOperandIndex::kUnaryOpSrc0Idx);
2125+
2126+
Type *Ty = Src->getType();
2127+
Type *RetTy = Type::getInt32Ty(CI->getContext());
2128+
if (Ty->isVectorTy())
2129+
RetTy = VectorType::get(RetTy, Ty->getVectorNumElements());
2130+
2131+
Constant *OpArg = OP->GetU32Const((unsigned)opcode);
2132+
Value *Args[] = {OpArg, Src};
2133+
2134+
Value *FirstbitLo =
2135+
TrivialDxilOperation(opcode, Args, Ty, RetTy, OP, Builder);
2136+
2137+
return FirstbitLo;
21222138
}
21232139

21242140
Value *TranslateLit(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
@@ -6981,17 +6997,15 @@ IntrinsicLower gLowerTable[] = {
69816997
{IntrinsicOp::IOP_countbits, TrivialUnaryOperationRet,
69826998
DXIL::OpCode::Countbits},
69836999
{IntrinsicOp::IOP_cross, TranslateCross, DXIL::OpCode::NumOpCodes},
6984-
{IntrinsicOp::IOP_ddx, TrivialUnaryOperationRet,
6985-
DXIL::OpCode::DerivCoarseX},
6986-
{IntrinsicOp::IOP_ddx_coarse, TrivialUnaryOperationRet,
7000+
{IntrinsicOp::IOP_ddx, TrivialUnaryOperation, DXIL::OpCode::DerivCoarseX},
7001+
{IntrinsicOp::IOP_ddx_coarse, TrivialUnaryOperation,
69877002
DXIL::OpCode::DerivCoarseX},
6988-
{IntrinsicOp::IOP_ddx_fine, TrivialUnaryOperationRet,
7003+
{IntrinsicOp::IOP_ddx_fine, TrivialUnaryOperation,
69897004
DXIL::OpCode::DerivFineX},
6990-
{IntrinsicOp::IOP_ddy, TrivialUnaryOperationRet,
6991-
DXIL::OpCode::DerivCoarseY},
6992-
{IntrinsicOp::IOP_ddy_coarse, TrivialUnaryOperationRet,
7005+
{IntrinsicOp::IOP_ddy, TrivialUnaryOperation, DXIL::OpCode::DerivCoarseY},
7006+
{IntrinsicOp::IOP_ddy_coarse, TrivialUnaryOperation,
69937007
DXIL::OpCode::DerivCoarseY},
6994-
{IntrinsicOp::IOP_ddy_fine, TrivialUnaryOperationRet,
7008+
{IntrinsicOp::IOP_ddy_fine, TrivialUnaryOperation,
69957009
DXIL::OpCode::DerivFineY},
69967010
{IntrinsicOp::IOP_degrees, TranslateDegrees, DXIL::OpCode::NumOpCodes},
69977011
{IntrinsicOp::IOP_determinant, EmptyLower, DXIL::OpCode::NumOpCodes},

tools/clang/include/clang/Basic/Attr.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,18 @@ def HLSLCXXOverload : InheritableAttr {
945945
let Documentation = [Undocumented];
946946
}
947947

948+
// This attribute means something subtly different from the HLSLIntrinsic
949+
// attribute. Prior to this being introduced a subset of the HLSL intrinsics
950+
// were placed in the `hlsl` namespace, but not in a way that actually qualified
951+
// their name lookup. The presence of the namespace as the declcontext was then
952+
// sused in CGExpr to determine how to emit the call. This attribute replaces
953+
// the namespace in that context.
954+
def HLSLBuiltinCall : InheritableAttr {
955+
let Spellings = [];
956+
let Subjects = SubjectList<[Function]>;
957+
let Documentation = [Undocumented];
958+
}
959+
948960
def HLSLVector : InheritableAttr {
949961
let Spellings = []; // No spellings!
950962
let Subjects = SubjectList<[CXXRecord]>;

0 commit comments

Comments
 (0)