Skip to content

Commit 97b0b1a

Browse files
authored
Fix Dynamic Resources when used with -Od (#3499)
- SROA was not skipping handle type, now present with dynamic resources changes, or ConstantBuffer<> / TextureBuffer<> types, as it should. - Updated unit tests to add combinations of -Od and -Zi.
1 parent 4a8b91e commit 97b0b1a

9 files changed

Lines changed: 98 additions & 27 deletions

File tree

lib/DXIL/DxilUtil.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,12 @@ std::pair<bool, DxilResourceProperties> GetHLSLResourceProperties(llvm::Type *Ty
668668
if (name == "RaytracingAccelerationStructure")
669669
return RetType(true, MakeResourceProperties(hlsl::DXIL::ResourceKind::RTAccelerationStructure, false, false, false));
670670

671+
if (name.startswith("ConstantBuffer<"))
672+
return RetType(true, MakeResourceProperties(hlsl::DXIL::ResourceKind::CBuffer, false, false, false));
673+
674+
if (name.startswith("TextureBuffer<"))
675+
return RetType(true, MakeResourceProperties(hlsl::DXIL::ResourceKind::TBuffer, false, false, false));
676+
671677
if (ConsumePrefix(name, "FeedbackTexture2D")) {
672678
hlsl::DXIL::ResourceKind kind = hlsl::DXIL::ResourceKind::Invalid;
673679
if (ConsumePrefix(name, "Array"))
@@ -677,6 +683,8 @@ std::pair<bool, DxilResourceProperties> GetHLSLResourceProperties(llvm::Type *Ty
677683

678684
if (name.startswith("<"))
679685
return RetType(true, MakeResourceProperties(kind, false, false, false));
686+
687+
return FalseRet;
680688
}
681689

682690
bool ROV = ConsumePrefix(name, "RasterizerOrdered");
@@ -735,6 +743,9 @@ bool IsHLSLObjectType(llvm::Type *Ty) {
735743
if (name.startswith("dx.types.wave_t"))
736744
return true;
737745

746+
if (name.compare("dx.types.Handle") == 0)
747+
return true;
748+
738749
if (name.endswith("_slice_type"))
739750
return false;
740751

tools/clang/test/HLSLFileCheck/hlsl/intrinsics/createHandleFromHeap/NonUniformDynamic.hlsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// RUN: %dxc -T cs_6_6 %s | %FileCheck %s
2+
// RUN: %dxc -T cs_6_6 -Od %s | %FileCheck %s
3+
// RUN: %dxc -T cs_6_6 -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKOD
4+
// RUN: %dxc -T cs_6_6 -Od -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKOD
25

36
// Make sure nonUniformIndex is true.
47
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 %{{[0-9]+}}, i1 false, i1 true)
@@ -18,4 +21,7 @@ void write(uint ID, float f) {
1821
void main( uint2 ID : SV_DispatchThreadID) {
1922
float v = read(ID.x);
2023
write(ID.y, v);
21-
}
24+
}
25+
26+
// Exclude quoted source file (see readme)
27+
// CHECKOD-LABEL: {{!"[^"]*\\0A[^"]*"}}
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
// RUN: %dxc -T ps_6_6 %s | %FileCheck %s
2+
// RUN: %dxc -T ps_6_6 -Od %s | %FileCheck %s
3+
// RUN: %dxc -T ps_6_6 -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
4+
// RUN: %dxc -T ps_6_6 -Zi -Od %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
25

36
// Make sure generate createHandleFromBinding for sm6.6.
4-
// CHECK:call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind zeroinitializer, i32 0, i1 false) ; CreateHandleFromBinding(bind,index,nonUniformIndex)
5-
// CHECK:call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 0, i32 0, i8 3 }, i32 0, i1 false) ; CreateHandleFromBinding(bind,index,nonUniformIndex)
7+
// CHECK:call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind zeroinitializer, i32 0, i1 false)
8+
// CHECK:call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 0, i32 0, i8 3 }, i32 0, i1 false)
69
// Make sure sampler and texture get correct annotateHandle.
710

8-
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 2, i32 1033 }) ; AnnotateHandle(res,props) resource: Texture2D<F32>
9-
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 14, i32 0 }) ; AnnotateHandle(res,props) resource: SamplerState
11+
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 2, i32 1033 })
12+
// CHECK-SAME: resource: Texture2D<F32>
13+
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 14, i32 0 })
14+
// CHECK-SAME: resource: SamplerState
1015

1116
SamplerState samplers : register(s0);
1217
SamplerState foo() { return samplers; }
@@ -15,4 +20,7 @@ Texture2D t0 : register(t0);
1520
float4 main( float2 uv : TEXCOORD ) : SV_TARGET {
1621
float4 val = t0.Sample(foo(), uv);
1722
return val;
18-
}
23+
}
24+
25+
// Exclude quoted source file (see readme)
26+
// CHECKZI-LABEL: {{!"[^"]*\\0A[^"]*"}}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
// RUN: %dxc -T ps_6_6 %s | %FileCheck %s
2-
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 %{{.*}}, i1 false, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
3-
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 10, i32 265 }) ; AnnotateHandle(res,props) resource: TypedBuffer<F32>
2+
// RUN: %dxc -T ps_6_6 -Od %s | %FileCheck %s
3+
// RUN: %dxc -T ps_6_6 -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
4+
// RUN: %dxc -T ps_6_6 -Od -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
5+
6+
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 %{{.*}}, i1 false, i1 false)
7+
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 10, i32 265 })
8+
// CHECK-SAME: resource: TypedBuffer<F32>
49

510
uint ID;
611
float main(uint i:I): SV_Target {
712
Buffer<float> buf = ResourceDescriptorHeap[ID];
813
return buf[i];
9-
}
14+
}
15+
16+
// Exclude quoted source file (see readme)
17+
// CHECKZI-LABEL: {{!"[^"]*\\0A[^"]*"}}

tools/clang/test/HLSLFileCheck/hlsl/intrinsics/createHandleFromHeap/createFromHeap2.hlsl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
// RUN: %dxc -T ps_6_6 %s | %FileCheck %s
2+
// RUN: %dxc -T ps_6_6 -Od %s | %FileCheck %s
3+
// RUN: %dxc -T ps_6_6 -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
4+
// RUN: %dxc -T ps_6_6 -Od -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
25

36
// Make sure snorm/unorm and globallycoherent works.
47
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218
5-
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 4106, i32 270 }) ; AnnotateHandle(res,props) resource: RWTypedBuffer<UNormF32>
8+
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 4106, i32 270 })
9+
// CHECK-SAME: resource: RWTypedBuffer<UNormF32>
610
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218
7-
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 20490, i32 269 }) ; AnnotateHandle(res,props) resource: globallycoherent RWTypedBuffer<SNormF32>
11+
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 20490, i32 269 })
12+
// CHECK-SAME: resource: globallycoherent RWTypedBuffer<SNormF32>
813
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218
9-
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 20490, i32 269 }) ; AnnotateHandle(res,props) resource: globallycoherent RWTypedBuffer<SNormF32>
14+
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 20490, i32 269 })
15+
// CHECK-SAME: resource: globallycoherent RWTypedBuffer<SNormF32>
1016

1117

1218
struct S {
@@ -21,4 +27,7 @@ float main(uint i:I): SV_Target {
2127
s.buf1[0] = ResourceDescriptorHeap[ID+1];
2228
s.buf1[1] = ResourceDescriptorHeap[ID+2];
2329
return s.buf[i] + s.buf1[0][i] + s.buf1[1][i];
24-
}
30+
}
31+
32+
// Exclude quoted source file (see readme)
33+
// CHECKZI-LABEL: {{!"[^"]*\\0A[^"]*"}}
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// RUN: %dxc -T ps_6_6 %s | %FileCheck %s
2+
// RUN: %dxc -T ps_6_6 -Od %s | %FileCheck %s
3+
// RUN: %dxc -T ps_6_6 -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
4+
// RUN: %dxc -T ps_6_6 -Od -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
25

3-
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 0, i1 false, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
4-
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 2, i32 1033 }) ; AnnotateHandle(res,props) resource: Texture2D<F32>
5-
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 0, i1 true, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
6-
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 14, i32 0 }) ; AnnotateHandle(res,props) resource: SamplerState
6+
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 0, i1 false, i1 false)
7+
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 2, i32 1033 })
8+
//CHECK-SAME: resource: Texture2D<F32>
9+
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 0, i1 true, i1 false)
10+
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 14, i32 0 })
11+
//CHECK-SAME: resource: SamplerState
712

813

914
[RootSignature("RootFlags(CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED|SAMPLER_HEAP_DIRECTLY_INDEXED)")]
@@ -13,4 +18,7 @@ float4 main(float2 c:C) : SV_Target {
1318
SamplerState s = SamplerDescriptorHeap[0];
1419
return t.Sample(s, c);
1520

16-
}
21+
}
22+
23+
// Exclude quoted source file (see readme)
24+
// CHECKZI-LABEL: {{!"[^"]*\\0A[^"]*"}}
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
// RUN: %dxc -T ps_6_6 %s | %FileCheck %s
2+
// RUN: %dxc -T ps_6_6 -Od %s | %FileCheck %s
3+
// RUN: %dxc -T ps_6_6 -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
4+
// RUN: %dxc -T ps_6_6 -Od -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
5+
6+
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 0, i1 false, i1 false)
7+
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 13, i32 4 })
8+
//CHECK-SAME: resource: CBuffer
9+
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 1, i1 false, i1 false)
10+
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 15, i32 4 })
11+
//CHECK-SAME: resource: TBuffer
12+
//CHECK:call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %{{.*}}, i32 0)
13+
//CHECK:call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %{{.*}}, i32 0, i32 undef)
214

3-
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 0, i1 false, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
4-
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 13, i32 4 }) ; AnnotateHandle(res,props) resource: CBuffer
5-
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 1, i1 false, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
6-
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 15, i32 4 }) ; AnnotateHandle(res,props) resource: TBuffer
7-
//CHECK:call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %{{.*}}, i32 0) ; CBufferLoadLegacy(handle,regIndex)
8-
//CHECK:call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %{{.*}}, i32 0, i32 undef) ; BufferLoad(srv,index,wot)
915
struct A {
1016
float a;
1117
};
@@ -18,4 +24,7 @@ TextureBuffer<A> T= ResourceDescriptorHeap[1];
1824

1925
return C.a * T.a;
2026

21-
}
27+
}
28+
29+
// Exclude quoted source file (see readme)
30+
// CHECKZI-LABEL: {{!"[^"]*\\0A[^"]*"}}

tools/clang/test/HLSLFileCheck/hlsl/intrinsics/createHandleFromHeap/dynamic_res_global_for_lib.hlsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// RUN: %dxc -T lib_6_6 %s | %FileCheck %s
2+
// RUN: %dxc -T lib_6_6 -Od %s | %FileCheck %s
3+
// RUN: %dxc -T lib_6_6 -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
4+
// RUN: %dxc -T lib_6_6 -Od -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
25

36
// Make sure each entry get 2 createHandleFromHeap.
47
// CHECK:define void
@@ -32,4 +35,7 @@ export float foo(uint i) {
3235
void csmain2(uint ix : SV_GroupIndex)
3336
{
3437
g_result[ix] = g_rawBuf.Load<float>(ix+ID);
35-
}
38+
}
39+
40+
// Exclude quoted source file (see readme)
41+
// CHECKZI-LABEL: {{!"[^"]*\\0A[^"]*"}}

tools/clang/test/HLSLFileCheck/hlsl/intrinsics/createHandleFromHeap/dynamic_res_global_for_lib2.hlsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// RUN: %dxc -T lib_6_6 %s | %FileCheck %s
2+
// RUN: %dxc -T lib_6_6 -Od %s | %FileCheck %s
3+
// RUN: %dxc -T lib_6_6 -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
4+
// RUN: %dxc -T lib_6_6 -Od -Zi %s | %FileCheck %s -check-prefixes=CHECK,CHECKZI
25

36
// Make sure each entry get 2 createHandleFromHeap.
47
// CHECK:define void
@@ -41,4 +44,7 @@ void csmain2(uint ix : SV_GroupIndex)
4144
void RayGeneration()
4245
{
4346
g_result[0] = g_rawBuf.Load<float>(1);
44-
}
47+
}
48+
49+
// Exclude quoted source file (see readme)
50+
// CHECKZI-LABEL: {{!"[^"]*\\0A[^"]*"}}

0 commit comments

Comments
 (0)