Skip to content

Commit

Permalink
Fix coverage bing used to init dx.ishelper when only discard is used (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tex3d authored Mar 16, 2021
1 parent 92fa250 commit 3f6589a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/HLSL/DxilPreparePasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,11 @@ class DxilFinalizeModule : public ModulePass {
}
}

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();
Expand Down Expand Up @@ -593,7 +595,11 @@ class DxilFinalizeModule : public ModulePass {
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);
Expand All @@ -618,7 +624,7 @@ class DxilFinalizeModule : public ModulePass {
// 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 3f6589a

Please sign in to comment.