Kaynağa Gözat

Fixes missing dxil annotation from types used in shared memory (#2292)

John Porto 6 yıl önce
ebeveyn
işleme
a2bb514bb2

+ 3 - 0
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -2157,6 +2157,9 @@ void CGMSHLSLRuntime::addResource(Decl *D) {
 
     if (D->hasAttr<HLSLGroupSharedAttr>()) {
       GlobalVariable *GV = cast<GlobalVariable>(CGM.GetAddrOfGlobalVar(VD));
+      DxilTypeSystem &dxilTypeSys = m_pHLModule->GetTypeSystem();
+      unsigned arraySize = 0;
+      AddTypeAnnotation(VD->getType(), dxilTypeSys, arraySize);
       m_pHLModule->AddGroupSharedVariable(GV);
       return;
     }

+ 21 - 0
tools/clang/test/CodeGenHLSL/batch/misc/shared-mem-type-annotation.hlsl

@@ -0,0 +1,21 @@
+// RUN: %dxc -E cs_main -T cs_6_0 %s | FileCheck %s
+
+// Regression test for crashing due to usage of structs as shared
+// memory elements.
+
+// CHECK: @cs_main
+
+struct Struct
+{
+    uint4 A;
+    float B;
+};
+
+groupshared Struct g_struct[2];
+
+[RootSignature("")]
+[numthreads(1, 1, 1)]
+void cs_main()
+{
+    g_struct[0] = g_struct[1];
+}