Fix coverage bing used to init dx.ishelper when only discard is used (#3589)

This commit is contained in:
Tex Riddell 2021-03-16 08:26:56 -07:00 коммит произвёл GitHub
Родитель 92fa2508c4
Коммит 3f6589a30b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 25 добавлений и 4 удалений

Просмотреть файл

@ -516,9 +516,11 @@ public:
}
}
GlobalVariable *GetIsHelperGV(Module &M) {
return M.getGlobalVariable(DXIL::kDxIsHelperGlobalName, /*AllowLocal*/ true);
}
GlobalVariable *GetOrCreateIsHelperGV(Module &M, hlsl::OP *hlslOP) {
GlobalVariable *GV =
M.getGlobalVariable(DXIL::kDxIsHelperGlobalName, /*AllowLocal*/ true);
GlobalVariable *GV = GetIsHelperGV(M);
if (GV)
return GV;
DxilModule &DM = M.GetDxilModule();
@ -593,7 +595,11 @@ public:
for (auto uit = F->user_begin(); uit != F->user_end();) {
CallInst *CI = cast<CallInst>(*(uit++));
if (!GV)
GV = GetOrCreateIsHelperGV(*F->getParent(), hlslOP);
GV = GetIsHelperGV(*F->getParent());
// If we don't already have a global for this,
// we didn't have any IsHelper() calls, so no need to add one now.
if (!GV)
return;
IRBuilder<> Builder(CI);
Value *Cond =
Builder.CreateZExt(DxilInst_Discard(CI).get_condition(), I32Ty);
@ -618,7 +624,7 @@ public:
// in an exported function linked to a PS in another library in this case.
// But it won't pass validation otherwise.
if (pSM->IsLib() && DXIL::CompareVersions(ValMajor, ValMinor, 1, 6) < 1) {
if (GlobalVariable *GV = M.getGlobalVariable(DXIL::kDxIsHelperGlobalName, /*AllowLocal*/ true)) {
if (GlobalVariable *GV = GetIsHelperGV(M)) {
GV->setLinkage(GlobalValue::InternalLinkage);
}
}

Просмотреть файл

@ -0,0 +1,15 @@
// RUN: %dxc -E ps -T ps_6_0 %s | FileCheck %s
// Make sure we don't initialize @dx.ishelper with coverage when IsHelperLane is not used, but discard is.
// CHECK-NOT: call i32 @dx.op.coverage.i32
float4 a;
[shader("pixel")]
float4 ps(float f : IN): SV_Target
{
if (f < 0.0)
discard;
float4 result = a;
return ddx(result);
}