Browse Source

Revert lying about resource sizes in debug info. (#2114)

Pull request #2086 lies about the size of resources to ensure that backends can always expect 32 bits in the debug info. However, this causes warnings/errors in code containing structs of a resource type and a numerical type, because SROA uses the LLVM size rather than the clang size, and those are expected to be in sync. So the dwarf is going to say that the resource is 32 bits, but LLVM will think it is 64 bits (given our current definition of the struct).
Tristan Labelle 6 years ago
parent
commit
cb51784fe2

+ 1 - 8
tools/clang/lib/AST/ASTContext.cpp

@@ -1513,17 +1513,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
   bool AlignIsRequired = false;
   // HLSL Change Starts
   if (getLangOpts().HLSL) {
-    QualType QualTy(T, 0);
     if (const ExtVectorType *Ty =
-            hlsl::ConvertHLSLVecMatTypeToExtVectorType(*this, QualTy)) {
+            hlsl::ConvertHLSLVecMatTypeToExtVectorType(*this, QualType(T, 0))) {
       T = Ty;
     }
-    else if (hlsl::IsHLSLResourceType(QualTy) || hlsl::IsHLSLStreamOutputType(QualTy)) {
-      // Lie that those are pointer-sized.
-      // We don't know how big they will be on the target architecture.
-      // And the fields we stuff into those structures are irrelevant.
-      T = getIntPtrType().getTypePtr();
-    }
   }
   // HLSL Change Ends
   switch (T->getTypeClass()) {

+ 17 - 0
tools/clang/test/CodeGenHLSL/debug/types/resource_no_members.hlsl

@@ -0,0 +1,17 @@
+// RUN: %dxc -T vs_6_0 -E main -Zi %s | FileCheck %s
+
+// Test that the debug info for resources does not expose internal fields.
+// Does not test the size of resources.
+
+// CHECK-DAG: ![[empty:.*]] = !{}
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_class_type, name: "Texture1D<float>", {{.*}}, elements: ![[empty]]
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_class_type, name: "Buffer<float>", {{.*}}, elements: ![[empty]]
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_class_type, name: "RWStructuredBuffer<float>", {{.*}}, elements: ![[empty]]
+
+// Exclude quoted source file (see readme)
+// CHECK-LABEL: {{!"[^"]*\\0A[^"]*"}}
+
+Texture1D<float> tex;
+Buffer<float> buf;
+RWStructuredBuffer<float> rwstructbuf;
+float main() : OUT { return tex.Load(0) + buf[0] + rwstructbuf[0]; }

+ 0 - 26
tools/clang/test/CodeGenHLSL/debug/types/resources.hlsl

@@ -1,26 +0,0 @@
-// RUN: %dxc -T ps_6_0 -E main -Zi %s | FileCheck %s
-
-// Test the definitions for resource types in debug metadata.
-// Resource types should be pointer-sized and not contain members.
-
-// CHECK-DAG: ![[empty:.*]] = !{}
-// CHECK-DAG: !DICompositeType(tag: DW_TAG_class_type, name: "Texture2D<vector<float, 2> >",{{.*}} size: 32, align: 32, elements: ![[empty]]
-// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "SamplerState",{{.*}} size: 32, align: 32, elements: ![[empty]]
-// CHECK-DAG: !DICompositeType(tag: DW_TAG_class_type, name: "Buffer<vector<float, 2> >",{{.*}} size: 32, align: 32, elements: ![[empty]]
-// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "ByteAddressBuffer",{{.*}} size: 32, align: 32, elements: ![[empty]]
-// CHECK-DAG: !DICompositeType(tag: DW_TAG_class_type, name: "StructuredBuffer<vector<float, 2> >",{{.*}} size: 32, align: 32, elements: ![[empty]]
-
-// Exclude quoted source file (see readme)
-// CHECK-LABEL: {{!"[^"]*\\0A[^"]*"}}
-
-Texture2D<float2> tex;
-SamplerState samp;
-Buffer<float2> buf;
-ByteAddressBuffer bytebuf;
-StructuredBuffer<float2> structbuf;
-
-float main() : SV_Target
-{
-  // Use every resource so it makes it to the debug info
-  return tex.Sample(samp, 0).x + buf[0] + bytebuf.Load(0) + structbuf[0].x;
-}

+ 27 - 0
tools/clang/test/CodeGenHLSL/debug/types/struct_resource_numerical.hlsl

@@ -0,0 +1,27 @@
+// RUN: %dxc -T vs_6_0 -E main -Zi %s | FileCheck %s
+
+// Test that the debug offset of a numerical type in
+// an SROA'd struct is consistent with the reported
+// size of a preceding resource-typed field.
+
+// Exclude quoted source file (see readme)
+// CHECK-LABEL: {{!"[^"]*\\0A[^"]*"}}
+
+// Texture types are currently 64 bits due to an implementation detail.
+// If this changes, this test can be safely updated.
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "TexAndCoord", {{.*}}, size: 96, align: 32
+// CHECK-DAG: !DIDerivedType(tag: DW_TAG_member, name: "tex", scope: !53, {{.*}}, size: 64, align: 32
+// CHECK-DAG: !DIDerivedType(tag: DW_TAG_member, name: "u", scope: !53, {{.*}}, size: 32, align: 32, offset: 64
+
+// The bit_piece for 'tc.u' should be right after the texture.
+// CHECK-DAG: !DIExpression(DW_OP_bit_piece, 64, 32)
+
+struct TexAndCoord { Texture1D<float> tex; float u; };
+
+Texture1D<float> g_tex;
+float g_u;
+float main() : OUT
+{
+    TexAndCoord tc = { g_tex, g_u };
+    return tc.tex.Load(tc.u);
+}