Ver código fonte

[spirv] handle this param alias case (#2274)

Fixes #2238
Jaebaek Seo 6 anos atrás
pai
commit
cc600b1739

+ 4 - 0
tools/clang/lib/SPIRV/SpirvEmitter.cpp

@@ -1038,6 +1038,10 @@ void SpirvEmitter::doFunctionDecl(const FunctionDecl *decl) {
     // CXXThisExpr correctly.
     curThis = spvBuilder.addFnParam(paramTypes[0], /*isPrecise*/ false,
                                     /*SourceLocation*/ {}, "param.this");
+    if (isOrContainsAKindOfStructuredOrByteBuffer(paramTypes[0])) {
+      curThis->setContainsAliasComponent(true);
+      needsLegalization = true;
+    }
   }
 
   // Create all parameters.

+ 38 - 0
tools/clang/test/CodeGenSPIRV/oo.struct.this.alias.hlsl

@@ -0,0 +1,38 @@
+// Run: %dxc -T ps_6_0 -E main
+
+struct S {
+  ByteAddressBuffer foo;
+  uint bar;
+
+  void AccessMember() {
+//CHECK:      [[foo:%\d+]] = OpAccessChain %_ptr_Function__ptr_Uniform_type_ByteAddressBuffer %param_this %int_0
+//CHECK-NEXT:                OpLoad %_ptr_Uniform_type_ByteAddressBuffer [[foo]]
+    foo.Load(0);
+  }
+};
+
+struct T {
+  S first;
+  uint second;
+
+  void AccessMemberRecursive() {
+//CHECK:      [[foo:%\d+]] = OpAccessChain %_ptr_Function__ptr_Uniform_type_ByteAddressBuffer %param_this_0 %int_0 %int_0
+//CHECK-NEXT:                OpLoad %_ptr_Uniform_type_ByteAddressBuffer [[foo]]
+    first.foo.Load(0);
+  }
+};
+
+void AccessParam(S input) {
+//CHECK:      [[foo:%\d+]] = OpAccessChain %_ptr_Function__ptr_Uniform_type_ByteAddressBuffer %input %int_0
+//CHECK-NEXT:                OpLoad %_ptr_Uniform_type_ByteAddressBuffer [[foo]]
+  input.foo.Load(0);
+}
+
+void main() {
+  S a;
+  T b;
+
+  a.AccessMember();
+  b.AccessMemberRecursive();
+  AccessParam(a);
+}

+ 4 - 0
tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

@@ -534,6 +534,10 @@ TEST_F(FileTest, StructMethodCall) {
   setBeforeHLSLLegalization();
   runFileTest("oo.struct.method.hlsl");
 }
+TEST_F(FileTest, StructThisAlias) {
+  setBeforeHLSLLegalization();
+  runFileTest("oo.struct.this.alias.hlsl");
+}
 TEST_F(FileTest, ClassMethodCall) {
   setBeforeHLSLLegalization();
   runFileTest("oo.class.method.hlsl");