Skip to content

Commit

Permalink
Added unused output target warning and moved usage mask fill location (
Browse files Browse the repository at this point in the history
…#3947)

* Moved usage mask fill location
Added unused output target warning and test

* Updated for readability
  • Loading branch information
gracejennings authored Sep 14, 2021
1 parent 7914122 commit 5fba0c3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lib/HLSL/DxilPreparePasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,6 @@ class DxilFinalizeModule : public ModulePass {
if (DXIL::CompareVersions(ValMajor, ValMinor, 1, 1) <= 0) {
patchValidation_1_1(M);
}

// Set used masks for signature elements
MarkUsedSignatureElements(DM.GetEntryFunction(), DM);
if (DM.GetShaderModel()->IsHS())
MarkUsedSignatureElements(DM.GetPatchConstantFunction(), DM);
}

// Replace lifetime intrinsics if requested or necessary.
Expand All @@ -742,6 +737,28 @@ class DxilFinalizeModule : public ModulePass {
// Remove store undef output.
RemoveStoreUndefOutput(M, hlslOP);

if (!IsLib) {
// Set used masks for signature elements
MarkUsedSignatureElements(DM.GetEntryFunction(), DM);
if (DM.GetShaderModel()->IsHS())
MarkUsedSignatureElements(DM.GetPatchConstantFunction(), DM);
}

// Adding warning for pixel shader with unassigned target
if (DM.GetShaderModel()->IsPS()) {
DxilSignature &sig = DM.GetOutputSignature();
for (auto &Elt : sig.GetElements()) {
if (Elt->GetKind() == Semantic::Kind::Target &&
Elt->GetUsageMask() != Elt->GetColsAsMask()) {
dxilutil::EmitWarningOnContext(
M.getContext(),
"Declared output " + llvm::Twine(Elt->GetName()) +
llvm::Twine(Elt->GetSemanticStartIndex()) +
" not fully written in shader.");
}
}
}

// Turn dx.break() conditional into global
LowerDxBreak(M);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %dxc -T ps_6_0 %s | FileCheck -input=stderr %s

// CHECK-NOT: warning: Declared output SV_Target0 not fully written in shader.
// CHECK: warning: Declared output SV_Target1 not fully written in shader.
// CHECK: warning: Declared output SV_Target2 not fully written in shader.
// CHECK: warning: Declared output SV_Target3 not fully written in shader.

void main(out float4 outRT0 : SV_Target0,
out float4 outRT1 : SV_Target1,
out float4 outRT2 : SV_Target2,
out float4 outRT3 : SV_Target3) {

outRT0 = 0.0f;
outRT1.x = 0.0f;
outRT2.zw = 0.0f;
// outRT3 = 0.0f;
}

0 comments on commit 5fba0c3

Please sign in to comment.