Skip to content

Commit c31ea79

Browse files
authored
Fix failing test and DxilMutateResourceToHandle case hit by updated test (microsoft#4694)
DxilMutateResourceToHandle would skip GEP if result type does not need to be mutated. But then the GEP would not have setSourceElementType called with the new source type leaving invalid IR. The fix makes sure the GEP is added to MutateValSet when skipping recursion.
1 parent 25307b4 commit c31ea79

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/HLSL/DxilPromoteResourcePasses.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,11 @@ void DxilMutateResourceToHandle::collectCandidates(Module &M) {
547547
// If result type of GEP not related to resource type, skip.
548548
Type *Ty = GEP->getType();
549549
Type *MTy = mutateToHandleTy(Ty);
550-
if (MTy == Ty)
550+
if (MTy == Ty) {
551+
// Don't recurse, but still need to mutate GEP.
552+
MutateValSet.insert(GEP);
551553
continue;
554+
}
552555
newCandidates.emplace_back(GEP);
553556
} else if (PHINode *Phi = dyn_cast<PHINode>(U)) {
554557
// Propagate all operands.

tools/clang/test/HLSLFileCheck/hlsl/resource_binding/resource-in-struct.hlsl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
2-
// RUN: %dxc -T lib_6_7 -validator-version 1.7 %s | FileCheck %s -check-prefixes=CHECKTYPE,CHECKNORP
3-
// RUN: %dxc -T lib_6_8 %s | FileCheck %s -check-prefixes=CHECKTYPE,CHECKRP
42
// RUN: %dxc -T lib_6_x %s | FileCheck %s -check-prefixes=CHECKTYPE,CHECKRP
53

4+
// For now: No scenario here should produce the type annotation, since that
5+
// should be unused in final DXIL, and thus eliminated. Uncomment when a
6+
// scenario is crafted out that should produce the annotation.
7+
// xUN: %dxc -T lib_6_7 -validator-version 1.7 %s | FileCheck %s -check-prefixes=CHECKTYPE,CHECKNORP
8+
// xUN: %dxc -T lib_6_8 %s | FileCheck %s -check-prefixes=CHECKTYPE,CHECKRP
9+
610
// CHECK: res.Tex1
711

812
// Make sure ResourceProperties are emitted.
@@ -26,9 +30,14 @@ struct Resources
2630
float4 foo;
2731
};
2832

29-
Resources res;
33+
Resources g_res;
3034

35+
float4 foo(Resources res, float4 coord) {
36+
return res.Tex1.Sample(Samp, coord.xy) * res.foo;
37+
}
38+
39+
[shader("pixel")]
3140
float4 main(int4 a : A, float4 coord : TEXCOORD) : SV_TARGET
3241
{
33-
return res.Tex1.Sample(Samp, coord.xy) * res.foo;
42+
return foo(g_res, coord);
3443
}

0 commit comments

Comments
 (0)