Skip to content

Commit 3d5e8b9

Browse files
authored
Merge fixes to release branch (#3611)
Cherry-pick changes to release branch: cd3ef21 Roll back llvm::ArrayRef dependency in ExecutionTest (#3613) 2791c51 Generate descriptions for resources with no names (#3598) 22fa209 Fix LifetimeIntrinsicTest issues (#3609) 2039610 Fix Dxil validator compat and test issues (#3610) 220e884 Rename payload qualifier field to not match type (#3607) 0e89206 Correct exception handler sprintf for 32-bit (#3608) 9b475a7 Add dxc exception handler (#3604) e8372b9 Fixed arg pairs not correct for old source in module pdbs (#3599) 2bda44f Add constant evaluation for clamp() (#3581) 640c9af Added way for caller to replace args in PDB utils (#3595) de00b01 Fix const error check for object subscript operator (#3580)
2 parents 6b8d715 + 1725482 commit 3d5e8b9

39 files changed

Lines changed: 912 additions & 306 deletions

include/dxc/Support/FileIOHelper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ HRESULT DxcCreateBlobWithEncodingFromPinned(
190190
_In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,
191191
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) throw();
192192

193+
HRESULT DxcCreateBlobFromPinned(
194+
_In_bytecount_(size) LPCVOID pText, UINT32 size,
195+
_COM_Outptr_ IDxcBlob **pBlob) throw();
196+
193197
HRESULT
194198
DxcCreateBlobWithEncodingFromStream(
195199
IStream *pStream, bool newInstanceAlways, UINT32 codePage,

include/dxc/Support/HLSLOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ class DxcOpts {
201201

202202
bool PrintAfterAll; // OPT_print_after_all
203203
bool EnablePayloadQualifiers = false; // OPT_enable_payload_qualifiers
204+
bool HandleExceptions = false; // OPT_disable_exception_handling
204205

205206
// Rewriter Options
206207
RewriterOpts RWOpt;

include/dxc/Support/HLSLOptions.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ def enable_payload_qualifiers : Flag<["-", "/"], "enable-payload-qualifiers">, G
281281
HelpText<"Enables support for payload access qualifiers for raytracing payloads in SM 6.6.">;
282282
def disable_payload_qualifiers : Flag<["-", "/"], "disable-payload-qualifiers">, Group<hlslcomp_Group>, Flags<[CoreOption, RewriteOption, DriverOption]>,
283283
HelpText<"Disables support for payload access qualifiers for raytracing payloads in SM 6.7.">;
284+
def disable_exception_handling : Flag<["-", "/"], "disable-exception-handling">, Group<hlslcomp_Group>, Flags<[DriverOption, HelpHidden]>,
285+
HelpText<"Disable dxc handling of exceptions">;
284286

285287
// Used with API only
286288
def skip_serialization : Flag<["-", "/"], "skip-serialization">, Group<hlslcore_Group>, Flags<[CoreOption, HelpHidden]>,

include/dxc/dxcapi.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,11 @@ struct IDxcVersionInfo3 : public IUnknown {
582582
) = 0;
583583
};
584584

585+
struct DxcArgPair {
586+
const WCHAR *pName;
587+
const WCHAR *pValue;
588+
};
589+
585590
CROSS_PLATFORM_UUIDOF(IDxcPdbUtils, "E6C9647E-9D6A-4C3B-B94C-524B5A6C343D")
586591
struct IDxcPdbUtils : public IUnknown {
587592
virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pPdbOrDxil) = 0;
@@ -616,6 +621,8 @@ struct IDxcPdbUtils : public IUnknown {
616621

617622
virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) = 0;
618623
virtual HRESULT STDMETHODCALLTYPE CompileForFullPDB(_COM_Outptr_ IDxcResult **ppResult) = 0;
624+
virtual HRESULT STDMETHODCALLTYPE OverrideArgs(_In_ DxcArgPair *pArgPairs, UINT32 uNumArgPairs) = 0;
625+
virtual HRESULT STDMETHODCALLTYPE OverrideRootSignature(_In_ const WCHAR *pRootSignature) = 0;
619626
};
620627

621628
// Note: __declspec(selectany) requires 'extern'

include/llvm/Support/ErrorHandling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ namespace llvm {
9797
#ifndef NDEBUG
9898
#define llvm_unreachable(msg) \
9999
::llvm::llvm_unreachable_internal(msg, __FILE__, __LINE__)
100-
#elif defined(LLVM_BUILTIN_UNREACHABLE)
101-
#define llvm_unreachable(msg) LLVM_BUILTIN_UNREACHABLE
100+
//#elif defined(LLVM_BUILTIN_UNREACHABLE) // HLSL Change - always throw exception for unreachable
101+
//#define llvm_unreachable(msg) LLVM_BUILTIN_UNREACHABLE
102102
#else
103103
#define llvm_unreachable(msg) ::llvm::llvm_unreachable_internal()
104104
#endif

lib/DXIL/DxilShaderFlags.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
373373
M->GetValidatorVersion(valMajor, valMinor);
374374
bool hasMulticomponentUAVLoadsBackCompat = valMajor == 1 && valMinor == 0;
375375
bool hasViewportOrRTArrayIndexBackCombat = valMajor == 1 && valMinor < 4;
376+
bool hasBarycentricsBackCompat = valMajor == 1 && valMinor < 6;
376377

377378
Type *int16Ty = Type::getInt16Ty(F->getContext());
378379
Type *int64Ty = Type::getInt64Ty(F->getContext());
@@ -630,7 +631,7 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
630631
flag.SetViewID(hasViewID);
631632
flag.SetViewportAndRTArrayIndex(hasViewportOrRTArrayIndex);
632633
flag.SetShadingRate(hasShadingRate);
633-
flag.SetBarycentrics(hasBarycentrics);
634+
flag.SetBarycentrics(hasBarycentricsBackCompat ? false : hasBarycentrics);
634635
flag.SetSamplerFeedback(hasSamplerFeedback);
635636
flag.SetRaytracingTier1_1(hasRaytracingTier1_1);
636637
flag.SetAtomicInt64OnTypedResource(hasAtomicInt64OnTypedResource);

lib/DxcSupport/FileIOHelper.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,14 @@ HRESULT DxcCreateBlobWithEncodingFromPinned(LPCVOID pText, UINT32 size,
778778
return DxcCreateBlob(pText, size, true, false, true, codePage, nullptr, pBlobEncoding);
779779
}
780780

781+
HRESULT DxcCreateBlobFromPinned(
782+
_In_bytecount_(size) LPCVOID pText, UINT32 size,
783+
_COM_Outptr_ IDxcBlob **pBlob) throw() {
784+
CComPtr<IDxcBlobEncoding> pBlobEncoding;
785+
DxcCreateBlob(pText, size, true, false, false, CP_ACP, nullptr, &pBlobEncoding);
786+
return pBlobEncoding.QueryInterface(pBlob);
787+
}
788+
781789
_Use_decl_annotations_
782790
HRESULT
783791
DxcCreateBlobWithEncodingFromStream(IStream *pStream, bool newInstanceAlways,

lib/DxcSupport/HLSLOptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,8 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
663663
return 1;
664664
}
665665

666+
opts.HandleExceptions = !Args.hasFlag(OPT_disable_exception_handling, OPT_INVALID, false);
667+
666668
if (opts.DefaultColMajor && opts.DefaultRowMajor) {
667669
errors << "Cannot specify /Zpr and /Zpc together, use /? to get usage information";
668670
return 1;

lib/HLSL/DxilValidation.cpp

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -687,16 +687,57 @@ struct ValidationContext {
687687
Failed = true;
688688
}
689689

690+
// Use this instead of DxilResourceBase::GetGlobalName
691+
std::string GetResourceName(const hlsl::DxilResourceBase *Res) {
692+
if (!Res)
693+
return "nullptr";
694+
std::string resName = Res->GetGlobalName();
695+
if (!resName.empty())
696+
return resName;
697+
if (pDebugModule) {
698+
DxilModule &DM = pDebugModule->GetOrCreateDxilModule();
699+
switch (Res->GetClass()) {
700+
case DXIL::ResourceClass::CBuffer: return DM.GetCBuffer(Res->GetID()).GetGlobalName();
701+
case DXIL::ResourceClass::Sampler: return DM.GetSampler(Res->GetID()).GetGlobalName();
702+
case DXIL::ResourceClass::SRV: return DM.GetSRV(Res->GetID()).GetGlobalName();
703+
case DXIL::ResourceClass::UAV: return DM.GetUAV(Res->GetID()).GetGlobalName();
704+
default: return "Invalid Resource";
705+
}
706+
}
707+
// When names have been stripped, use class and binding location to
708+
// identify the resource. Format is roughly:
709+
// Allocated: (CB|T|U|S)<ID>: <ResourceKind> ((cb|t|u|s)<LB>[<RangeSize>] space<SpaceID>)
710+
// Unallocated: (CB|T|U|S)<ID>: <ResourceKind> (no bind location)
711+
// Example: U0: TypedBuffer (u5[2] space1)
712+
// [<RangeSize>] and space<SpaceID> skipped if 1 and 0 respectively.
713+
return (Twine(Res->GetResIDPrefix()) + Twine(Res->GetID()) + ": " +
714+
Twine(Res->GetResKindName()) +
715+
(Res->IsAllocated()
716+
? (" (" + Twine(Res->GetResBindPrefix()) +
717+
Twine(Res->GetLowerBound()) +
718+
(Res->IsUnbounded()
719+
? Twine("[unbounded]")
720+
: (Res->GetRangeSize() != 1)
721+
? "[" + Twine(Res->GetRangeSize()) + "]"
722+
: Twine()) +
723+
((Res->GetSpaceID() != 0)
724+
? " space" + Twine(Res->GetSpaceID())
725+
: Twine()) +
726+
")")
727+
: Twine(" (no bind location)")))
728+
.str();
729+
}
730+
690731
void EmitResourceError(const hlsl::DxilResourceBase *Res, ValidationRule rule) {
691-
std::string QuotedRes = " '" + Res->GetGlobalName() + "'";
732+
std::string QuotedRes = " '" + GetResourceName(Res) + "'";
692733
dxilutil::EmitErrorOnContext(M.getContext(), GetValidationRuleText(rule) + QuotedRes);
693734
Failed = true;
694735
}
695736

696737
void EmitResourceFormatError(const hlsl::DxilResourceBase *Res,
697738
ValidationRule rule,
698739
ArrayRef<StringRef> args) {
699-
std::string QuotedRes = " '" + Res->GetGlobalName() + "'";
740+
std::string QuotedRes = " '" + GetResourceName(Res) + "'";
700741
std::string ruleText = GetValidationRuleText(rule);
701742
FormatRuleText(ruleText, args);
702743
dxilutil::EmitErrorOnContext(M.getContext(), ruleText + QuotedRes);
@@ -3996,7 +4037,7 @@ static void ValidateResourceOverlap(
39964037
if (conflictRes) {
39974038
ValCtx.EmitFormatError(
39984039
ValidationRule::SmResourceRangeOverlap,
3999-
{res.GetGlobalName(), std::to_string(base),
4040+
{ValCtx.GetResourceName(&res), std::to_string(base),
40004041
std::to_string(size),
40014042
std::to_string(conflictRes->GetLowerBound()),
40024043
std::to_string(conflictRes->GetRangeSize()),
@@ -4208,7 +4249,7 @@ static void ValidateCBuffer(DxilCBuffer &cb, ValidationContext &ValCtx) {
42084249
DXIL::kMaxCBufferSize << 4);
42094250
CollectCBufferRanges(annotation, constAllocator,
42104251
0, typeSys,
4211-
cb.GetGlobalName(), ValCtx);
4252+
ValCtx.GetResourceName(&cb), ValCtx);
42124253
}
42134254

42144255
static void ValidateResources(ValidationContext &ValCtx) {
@@ -4240,7 +4281,7 @@ static void ValidateResources(ValidationContext &ValCtx) {
42404281
if (uav->HasCounter() && uav->IsGloballyCoherent())
42414282
ValCtx.EmitResourceFormatError(uav.get(),
42424283
ValidationRule::MetaGlcNotOnAppendConsume,
4243-
{uav.get()->GetGlobalName()});
4284+
{ValCtx.GetResourceName(uav.get())});
42444285

42454286
ValidateResource(*uav, ValCtx);
42464287
ValidateResourceOverlap(*uav, uavAllocator, ValCtx);

tools/clang/lib/CodeGen/CGHLSLMSFinishCodeGen.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,10 @@ typedef APInt(__cdecl *IntBinaryEvalFuncType)(const APInt &, const APInt &);
14601460
typedef float(__cdecl *FloatBinaryEvalFuncType)(float, float);
14611461
typedef double(__cdecl *DoubleBinaryEvalFuncType)(double, double);
14621462

1463+
typedef APInt(__cdecl *IntTernaryEvalFuncType)(const APInt &, const APInt &, const APInt &);
1464+
typedef float(__cdecl *FloatTernaryEvalFuncType)(float, float, float);
1465+
typedef double(__cdecl *DoubleTernaryEvalFuncType)(double, double, double);
1466+
14631467
Value *EvalUnaryIntrinsic(ConstantFP *fpV, FloatUnaryEvalFuncType floatEvalFunc,
14641468
DoubleUnaryEvalFuncType doubleEvalFunc) {
14651469
llvm::Type *Ty = fpV->getType();
@@ -1510,6 +1514,45 @@ Value *EvalBinaryIntrinsic(Constant *cV0, Constant *cV1,
15101514
return Result;
15111515
}
15121516

1517+
Value *EvalTernaryIntrinsic(Constant *cV0, Constant *cV1, Constant *cV2,
1518+
FloatTernaryEvalFuncType floatEvalFunc,
1519+
DoubleTernaryEvalFuncType doubleEvalFunc,
1520+
IntTernaryEvalFuncType intEvalFunc) {
1521+
llvm::Type *Ty = cV0->getType();
1522+
Value *Result = nullptr;
1523+
if (Ty->isDoubleTy()) {
1524+
ConstantFP *fpV0 = cast<ConstantFP>(cV0);
1525+
ConstantFP *fpV1 = cast<ConstantFP>(cV1);
1526+
ConstantFP *fpV2 = cast<ConstantFP>(cV2);
1527+
double dV0 = fpV0->getValueAPF().convertToDouble();
1528+
double dV1 = fpV1->getValueAPF().convertToDouble();
1529+
double dV2 = fpV2->getValueAPF().convertToDouble();
1530+
Value *dResult = ConstantFP::get(Ty, doubleEvalFunc(dV0, dV1, dV2));
1531+
Result = dResult;
1532+
} else if (Ty->isFloatTy()) {
1533+
ConstantFP *fpV0 = cast<ConstantFP>(cV0);
1534+
ConstantFP *fpV1 = cast<ConstantFP>(cV1);
1535+
ConstantFP *fpV2 = cast<ConstantFP>(cV2);
1536+
float fV0 = fpV0->getValueAPF().convertToFloat();
1537+
float fV1 = fpV1->getValueAPF().convertToFloat();
1538+
float fV2 = fpV2->getValueAPF().convertToFloat();
1539+
Value *dResult = ConstantFP::get(Ty, floatEvalFunc(fV0, fV1, fV2));
1540+
Result = dResult;
1541+
} else {
1542+
DXASSERT_NOMSG(Ty->isIntegerTy());
1543+
DXASSERT_NOMSG(intEvalFunc);
1544+
ConstantInt *ciV0 = cast<ConstantInt>(cV0);
1545+
ConstantInt *ciV1 = cast<ConstantInt>(cV1);
1546+
ConstantInt *ciV2 = cast<ConstantInt>(cV2);
1547+
const APInt &iV0 = ciV0->getValue();
1548+
const APInt &iV1 = ciV1->getValue();
1549+
const APInt &iV2 = ciV2->getValue();
1550+
Value *dResult = ConstantInt::get(Ty, intEvalFunc(iV0, iV1, iV2));
1551+
Result = dResult;
1552+
}
1553+
return Result;
1554+
}
1555+
15131556
Value *EvalUnaryIntrinsic(CallInst *CI, FloatUnaryEvalFuncType floatEvalFunc,
15141557
DoubleUnaryEvalFuncType doubleEvalFunc) {
15151558
Value *V = CI->getArgOperand(0);
@@ -1566,6 +1609,43 @@ Value *EvalBinaryIntrinsic(CallInst *CI, FloatBinaryEvalFuncType floatEvalFunc,
15661609
return Result;
15671610
}
15681611

1612+
Value *EvalTernaryIntrinsic(CallInst *CI, FloatTernaryEvalFuncType floatEvalFunc,
1613+
DoubleTernaryEvalFuncType doubleEvalFunc,
1614+
IntTernaryEvalFuncType intEvalFunc = nullptr) {
1615+
Value *V0 = CI->getArgOperand(0);
1616+
Value *V1 = CI->getArgOperand(1);
1617+
Value *V2 = CI->getArgOperand(2);
1618+
llvm::Type *Ty = CI->getType();
1619+
Value *Result = nullptr;
1620+
if (llvm::VectorType *VT = dyn_cast<llvm::VectorType>(Ty)) {
1621+
Result = UndefValue::get(Ty);
1622+
Constant *CV0 = cast<Constant>(V0);
1623+
Constant *CV1 = cast<Constant>(V1);
1624+
Constant *CV2 = cast<Constant>(V2);
1625+
IRBuilder<> Builder(CI);
1626+
for (unsigned i = 0; i < VT->getNumElements(); i++) {
1627+
Constant *cV0 = cast<Constant>(CV0->getAggregateElement(i));
1628+
Constant *cV1 = cast<Constant>(CV1->getAggregateElement(i));
1629+
Constant *cV2 = cast<Constant>(CV2->getAggregateElement(i));
1630+
Value *EltResult = EvalTernaryIntrinsic(cV0, cV1, cV2, floatEvalFunc,
1631+
doubleEvalFunc, intEvalFunc);
1632+
Result = Builder.CreateInsertElement(Result, EltResult, i);
1633+
}
1634+
} else {
1635+
Constant *cV0 = cast<Constant>(V0);
1636+
Constant *cV1 = cast<Constant>(V1);
1637+
Constant *cV2 = cast<Constant>(V2);
1638+
Result = EvalTernaryIntrinsic(cV0, cV1, cV2, floatEvalFunc, doubleEvalFunc,
1639+
intEvalFunc);
1640+
}
1641+
CI->replaceAllUsesWith(Result);
1642+
CI->eraseFromParent();
1643+
return Result;
1644+
1645+
CI->eraseFromParent();
1646+
return Result;
1647+
}
1648+
15691649
void SimpleTransformForHLDXIRInst(Instruction *I, SmallInstSet &deadInsts) {
15701650

15711651
unsigned opcode = I->getOpcode();
@@ -1789,6 +1869,18 @@ Value *TryEvalIntrinsic(CallInst *CI, IntrinsicOp intriOp,
17891869
CI->eraseFromParent();
17901870
return cNan;
17911871
} break;
1872+
case IntrinsicOp::IOP_clamp: {
1873+
auto clampF = [](float a, float b, float c) {
1874+
return a < b ? b : a > c ? c : a;
1875+
};
1876+
auto clampD = [](double a, double b, double c) {
1877+
return a < b ? b : a > c ? c : a;
1878+
};
1879+
auto clampI = [](const APInt &a, const APInt &b, const APInt &c) -> APInt {
1880+
return a.slt(b) ? b : a.sgt(c) ? c : a;
1881+
};
1882+
return EvalTernaryIntrinsic(CI, clampF, clampD, clampI);
1883+
} break;
17921884
default:
17931885
return nullptr;
17941886
}

0 commit comments

Comments
 (0)