Ver código fonte

Fix array operator access to a buffer resource vector member (#1501)

Fixes #1353
Helena Kotas 7 anos atrás
pai
commit
d0470046d6

+ 16 - 0
lib/HLSL/HLOperationLower.cpp

@@ -6265,6 +6265,22 @@ void TranslateDefaultSubscript(CallInst *CI, HLOperationLowerHelper &helper,  HL
           SI->eraseFromParent();
           continue;
         }
+        if (LoadInst *LI = dyn_cast<LoadInst>(GEPUser)) {
+          IRBuilder<> LdBuilder(LI);
+
+          // Generate tmp vector load with vector type & translate it
+          LoadInst *tmpLd = LdBuilder.CreateLoad(CI);
+
+          Value *ldVal = TranslateTypedBufLoad(CI, RK, RC, handle, tmpLd, LdBuilder,
+            hlslOP, helper.dataLayout);
+
+          // get the single element
+          ldVal = LdBuilder.CreateExtractElement(ldVal, EltIdx);
+
+          LI->replaceAllUsesWith(ldVal);
+          LI->eraseFromParent();
+          continue;
+        }
         if (!isa<CallInst>(GEPUser)) {
           // Invalid operations.
           Translated = false;

+ 1 - 1
tools/clang/lib/CodeGen/CGExprCXX.cpp

@@ -219,7 +219,7 @@ RValue CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(
       if (Base->getValueKind() != ExprValueKind::VK_RValue) {
         LValue LV = EmitLValue(Base);
         if (LV.isSimple()) {
-          This = EmitLValue(Base).getAddress();
+          This = LV.getAddress();
           if (isa<ExtMatrixElementExpr>(Base)) {
             llvm::Value *Val = Builder.CreateLoad(This);
             This = Builder.CreateAlloca(Val->getType());

+ 26 - 0
tools/clang/test/CodeGenHLSL/quick-test/typedbuf_dblsubstript.hlsl

@@ -0,0 +1,26 @@
+// RUN: %dxc -T vs_6_0 -E main %s | FileCheck %s
+
+// CHECK: @dx.op.bufferLoad.i32
+// CHECK: extractvalue %dx.types.ResRet.i32 %BufferLoad, 2
+// CHECK-NOT: dx.hl.subscript.[]
+
+struct SMeshVertex
+{
+    float4 position                 : ATTR0;
+};
+
+Buffer< uint4 > Elements;
+
+struct SVertexToPixel
+{
+    float projectedPosition : POSITION0;
+};
+
+SVertexToPixel main( in SMeshVertex inputRaw )
+{
+    SVertexToPixel output = (SVertexToPixel)0;
+
+    output.projectedPosition.x = Elements[1][2];
+    
+    return output;
+}